MCPcopy Create free account
hub / github.com/csyonghe/Spire / HandleLineDirective

Function HandleLineDirective

Source/SpireCore/Preprocessor.cpp:1509–1558  ·  view source on GitHub ↗

Handle a `#line` directive

Source from the content-addressed store, hash-verified

1507
1508// Handle a `#line` directive
1509static void HandleLineDirective(PreprocessorDirectiveContext* context)
1510{
1511 int line = 0;
1512 if (PeekTokenType(context) == TokenType::IntLiterial)
1513 {
1514 line = StringToInt(AdvanceToken(context).Content);
1515 }
1516 else if (PeekTokenType(context) == TokenType::Identifier
1517 && PeekToken(context).Content == "default")
1518 {
1519 AdvanceToken(context);
1520
1521 // TODO(tfoley): reset line numbering here
1522 return;
1523 }
1524 else
1525 {
1526 GetSink(context)->diagnose(PeekLoc(context), Diagnostics::expected2TokensInPreprocessorDirective,
1527 TokenType::IntLiterial,
1528 "default",
1529 GetDirectiveName(context));
1530 context->parseError = true;
1531 return;
1532 }
1533
1534 if (PeekTokenType(context) == TokenType::EndOfFile)
1535 {
1536 // TODO(tfoley): set line number, but not file
1537 return;
1538 }
1539
1540 String file;
1541 if (PeekTokenType(context) == TokenType::StringLiterial)
1542 {
1543 file = AdvanceToken(context).Content;
1544 }
1545 else if (PeekTokenType(context) == TokenType::IntLiterial)
1546 {
1547 // Note(tfoley): GLSL allows the "source string" to be indicated by an integer
1548 // TODO(tfoley): Figure out a better way to handle this, if it matters
1549 file = AdvanceToken(context).Content;
1550 }
1551 else
1552 {
1553 Expect(context, TokenType::StringLiterial, Diagnostics::expectedTokenInPreprocessorDirective);
1554 return;
1555 }
1556
1557 // TODO(tfoley): set line number and file here
1558}
1559
1560// Handle a `#pragma` directive
1561static void HandlePragmaDirective(PreprocessorDirectiveContext* context)

Callers

nothing calls this directly

Calls 8

PeekTokenTypeFunction · 0.85
StringToIntFunction · 0.85
AdvanceTokenFunction · 0.85
PeekTokenFunction · 0.85
GetSinkFunction · 0.85
PeekLocFunction · 0.85
ExpectFunction · 0.85
diagnoseMethod · 0.80

Tested by

no test coverage detected