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

Function HandleIncludeDirective

Source/SpireCore/Preprocessor.cpp:1361–1392  ·  view source on GitHub ↗

Handle a `#include` directive

Source from the content-addressed store, hash-verified

1359
1360// Handle a `#include` directive
1361static void HandleIncludeDirective(PreprocessorDirectiveContext* context)
1362{
1363 Token pathToken;
1364 if(!Expect(context, TokenType::StringLiterial, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken))
1365 return;
1366 String path = pathToken.Content;
1367
1368 // TODO(tfoley): make this robust in presence of `#line`
1369 String pathIncludedFrom = GetDirectiveLoc(context).FileName;
1370 String foundPath;
1371 String foundSource;
1372
1373
1374 IncludeHandler* includeHandler = context->preprocessor->includeHandler;
1375 if (!includeHandler)
1376 {
1377 GetSink(context)->diagnose(pathToken.Position, Diagnostics::includeFailed, path);
1378 GetSink(context)->diagnose(pathToken.Position, Diagnostics::noIncludeHandlerSpecified);
1379 return;
1380 }
1381 if (!includeHandler->TryToFindIncludeFile(path, pathIncludedFrom, &foundPath, &foundSource))
1382 {
1383 GetSink(context)->diagnose(pathToken.Position, Diagnostics::includeFailed, path);
1384 return;
1385 }
1386
1387 // Push the new file onto our stack of input streams
1388 // TODO(tfoley): check if we have made our include stack too deep
1389 PreprocessorInputStream* inputStream = CreateInputStreamForSource(context->preprocessor, foundSource, foundPath);
1390 inputStream->parent = context->preprocessor->inputStream;
1391 context->preprocessor->inputStream = inputStream;
1392}
1393
1394// Handle a `#define` directive
1395static void HandleDefineDirective(PreprocessorDirectiveContext* context)

Callers

nothing calls this directly

Calls 5

ExpectFunction · 0.85
GetSinkFunction · 0.85
diagnoseMethod · 0.80
TryToFindIncludeFileMethod · 0.45

Tested by

no test coverage detected