diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-14 14:58:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-14 14:58:24 -0700 |
| commit | c7d7a965c14318c07bd5b8ec60b960c2e95dfebd (patch) | |
| tree | a8ba4c59576863fd6e3bc869f34fa3a431a818dc | |
| parent | f5f0740be8102b4d719575d97b00dbd21b54ffbe (diff) | |
Support `#include` with angle brackets. (#3773)
| -rw-r--r-- | source/slang/slang-preprocessor.cpp | 23 | ||||
| -rw-r--r-- | tests/preprocessor/include-angle-bracket.slang | 8 | ||||
| -rw-r--r-- | tests/preprocessor/include/include-pragma-once-c.h | 2 |
3 files changed, 28 insertions, 5 deletions
diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp index 9586088a1..b0986f64c 100644 --- a/source/slang/slang-preprocessor.cpp +++ b/source/slang/slang-preprocessor.cpp @@ -2994,10 +2994,25 @@ static void HandleIncludeDirective(PreprocessorDirectiveContext* context) AdvanceRawToken(context); Token pathToken; - if(!Expect(context, TokenType::StringLiteral, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken)) - return; - - String path = getFileNameTokenValue(pathToken); + String path; + if (PeekRawTokenType(context) == TokenType::OpLess) + { + StringBuilder pathSB; + Expect(context, TokenType::OpLess, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken); + while (PeekRawTokenType(context) != TokenType::OpGreater && + PeekRawTokenType(context) != TokenType::EndOfFile) + { + pathSB << AdvanceRawToken(context).getContent(); + } + if (!Expect(context, TokenType::OpGreater, Diagnostics::expectedTokenInPreprocessorDirective)) + return; + path = pathSB.produceString(); + } + else + { + Expect(context, TokenType::StringLiteral, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken); + path = getFileNameTokenValue(pathToken); + } auto directiveLoc = GetDirectiveLoc(context); diff --git a/tests/preprocessor/include-angle-bracket.slang b/tests/preprocessor/include-angle-bracket.slang new file mode 100644 index 000000000..4b89387d4 --- /dev/null +++ b/tests/preprocessor/include-angle-bracket.slang @@ -0,0 +1,8 @@ +//TEST:SIMPLE: +// #include support + +int foo() { return 0; } + +#include <include-a.slang.h> + +int baz() { return bar(); }
\ No newline at end of file diff --git a/tests/preprocessor/include/include-pragma-once-c.h b/tests/preprocessor/include/include-pragma-once-c.h index 5c07d2846..2577591fc 100644 --- a/tests/preprocessor/include/include-pragma-once-c.h +++ b/tests/preprocessor/include/include-pragma-once-c.h @@ -2,4 +2,4 @@ #pragma once -#include "pragma-once-c.h"
\ No newline at end of file +#include "pragma-once-c.h" |
