-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preprocessor: prevent usage of unsupported macros
- Loading branch information
1 parent
41d3ad5
commit 06fe031
Showing
8 changed files
with
73 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::sync::Arc; | ||
|
||
use hemtt_workspace::reporting::{Code, Token}; | ||
|
||
use crate::Error; | ||
|
||
#[allow(unused)] | ||
/// Built-in macro is not supported by HEMTT | ||
pub struct BuiltInNotSupported { | ||
/// The [`Token`] of the built-in macro | ||
token: Box<Token>, | ||
} | ||
|
||
impl Code for BuiltInNotSupported { | ||
fn ident(&self) -> &'static str { | ||
"PE26" | ||
} | ||
|
||
fn token(&self) -> Option<&Token> { | ||
Some(&self.token) | ||
} | ||
|
||
fn message(&self) -> String { | ||
format!("built-in macro `{}` is not supported by HEMTT", self.token.symbol()) | ||
} | ||
|
||
fn note(&self) -> Option<String> { | ||
Some("certain built-in macros can not be rapified at build time\nHEMTT does not support them to prevent unexpected behaviour".to_string()) | ||
} | ||
} | ||
|
||
impl BuiltInNotSupported { | ||
#[must_use] | ||
pub const fn new(token: Box<Token>) -> Self { | ||
Self { token } | ||
} | ||
|
||
#[must_use] | ||
pub fn code(token: Token) -> Error { | ||
Error::Code(Arc::new(Self::new(Box::new(token)))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
libs/preprocessor/tests/errors/pe26_unsupported_builtin/source.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Date { | ||
day = __DAY__; | ||
}; |
9 changes: 9 additions & 0 deletions
9
libs/preprocessor/tests/errors/pe26_unsupported_builtin/stderr.ansi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[0m[1m[38;5;9merror[PE26][0m[1m: built-in macro `__DAY__` is not supported by HEMTT[0m | ||
[0m[36m┌─[0m source.hpp:2:11 | ||
[0m[36m│[0m | ||
[0m[36m2[0m [0m[36m│[0m day = [0m[31m__DAY__[0m; | ||
[0m[36m│[0m [0m[31m^^^^^^^[0m [0m[31mbuilt-in macro `__DAY__` is not supported by HEMTT[0m | ||
[0m[36m│[0m | ||
[0m[36m=[0m [36mnote[0m: certain built-in macros can not be rapified at build time | ||
HEMTT does not support them to prevent unexpected behaviour | ||
|