-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add support for simple object-like macros #6326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for simple object-like macros #6326
Conversation
| // CHECK:STDERR: let b: f32 = Cpp.n; | ||
| // CHECK:STDERR: ^~~~~ | ||
| // CHECK:STDERR: | ||
| let b: f32 = Cpp.n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually allow an implicit conversion from i32 to f32, at which point I think this test won't test that the macro is being selected. How about something like:
| let b: f32 = Cpp.n; | |
| var b: array(f32, Cpp.n) = (1.0,); |
... to test that it's being treated as an integer constant with value 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sg, thanks for the suggestion.
| return macro_info->second; | ||
|
|
||
| clang::Preprocessor& preprocessor = context.clang_sema().getPreprocessor(); | ||
| clang::IdentifierInfo* identifier_info = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to do this identifier lookup only once, rather than once here and once in ClangLookupName. I'd be happy with a TODO if you'd like to get this landed to unblock further macro work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a TODO.
Adds support for object-like macros with a single replacement numeric-literal kind token. Only macros that evaluate to an integer constant are supported for now. When detected at name lookup, they are imported as a constant integer value in Carbon.
Demo:
$ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link main.o \--output=demo_carbon $ ./demo_carbon 2Part of #6303