Skip to content

Commit

Permalink
Support #include with angle brackets. (#3773)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Mar 14, 2024
1 parent f5f0740 commit c7d7a96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
23 changes: 19 additions & 4 deletions source/slang/slang-preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions tests/preprocessor/include-angle-bracket.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//TEST:SIMPLE:
// #include support

int foo() { return 0; }

#include <include-a.slang.h>

int baz() { return bar(); }
2 changes: 1 addition & 1 deletion tests/preprocessor/include/include-pragma-once-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#pragma once

#include "pragma-once-c.h"
#include "pragma-once-c.h"

0 comments on commit c7d7a96

Please sign in to comment.