Handle a `#include` directive
| 1359 | |
| 1360 | // Handle a `#include` directive |
| 1361 | static 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 |
| 1395 | static void HandleDefineDirective(PreprocessorDirectiveContext* context) |
nothing calls this directly
no test coverage detected