| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_LEX_PPCALLBACKS_H |
| 15 | #define LLVM_CLANG_LEX_PPCALLBACKS_H |
| 16 | |
| 17 | #include "clang/Basic/DiagnosticIDs.h" |
| 18 | #include "clang/Basic/SourceLocation.h" |
| 19 | #include "clang/Basic/SourceManager.h" |
| 20 | #include "clang/Lex/ModuleLoader.h" |
| 21 | #include "clang/Lex/Pragma.h" |
| 22 | #include "llvm/ADT/StringRef.h" |
| 23 | |
| 24 | namespace clang { |
| 25 | class Token; |
| 26 | class IdentifierInfo; |
| 27 | class MacroDefinition; |
| 28 | class MacroDirective; |
| 29 | class MacroArgs; |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | class PPCallbacks { |
| 36 | public: |
| 37 | virtual ~PPCallbacks(); |
| 38 | |
| 39 | enum FileChangeReason { |
| 40 | EnterFile, ExitFile, , RenameFile |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, |
| 48 | SrcMgr::CharacteristicKind FileType, |
| 49 | FileID PrevFID = FileID()) { |
| 50 | } |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | virtual void FileSkipped(const FileEntry &SkippedFile, |
| 61 | const Token &FilenameTok, |
| 62 | SrcMgr::CharacteristicKind FileType) { |
| 63 | } |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | virtual bool FileNotFound(StringRef FileName, |
| 78 | SmallVectorImpl<char> &RecoveryPath) { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | virtual void InclusionDirective(SourceLocation HashLoc, |
| 124 | const Token &IncludeTok, |
| 125 | StringRef FileName, |
| 126 | bool IsAngled, |
| 127 | CharSourceRange FilenameRange, |
| 128 | const FileEntry *File, |
| 129 | StringRef SearchPath, |
| 130 | StringRef RelativePath, |
| 131 | const Module *Imported, |
| 132 | SrcMgr::CharacteristicKind FileType) { |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | virtual void moduleImport(SourceLocation ImportLoc, |
| 146 | ModuleIdPath Path, |
| 147 | const Module *Imported) { |
| 148 | } |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | virtual void EndOfMainFile() { |
| 154 | } |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | virtual void Ident(SourceLocation Loc, StringRef str) { |
| 161 | } |
| 162 | |
| 163 | |
| 164 | virtual void PragmaDirective(SourceLocation Loc, |
| 165 | PragmaIntroducerKind Introducer) { |
| 166 | } |
| 167 | |
| 168 | |
| 169 | virtual void (SourceLocation Loc, const IdentifierInfo *Kind, |
| 170 | StringRef Str) { |
| 171 | } |
| 172 | |
| 173 | |
| 174 | |
| 175 | virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
| 176 | StringRef Value) { |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) { |
| 183 | } |
| 184 | |
| 185 | |
| 186 | enum PragmaMessageKind { |
| 187 | |
| 188 | PMK_Message, |
| 189 | |
| 190 | |
| 191 | PMK_Warning, |
| 192 | |
| 193 | |
| 194 | PMK_Error |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, |
| 203 | PragmaMessageKind Kind, StringRef Str) { |
| 204 | } |
| 205 | |
| 206 | |
| 207 | |
| 208 | virtual void PragmaDiagnosticPush(SourceLocation Loc, |
| 209 | StringRef Namespace) { |
| 210 | } |
| 211 | |
| 212 | |
| 213 | |
| 214 | virtual void PragmaDiagnosticPop(SourceLocation Loc, |
| 215 | StringRef Namespace) { |
| 216 | } |
| 217 | |
| 218 | |
| 219 | virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, |
| 220 | diag::Severity mapping, StringRef Str) {} |
| 221 | |
| 222 | |
| 223 | |
| 224 | virtual void PragmaOpenCLExtension(SourceLocation NameLoc, |
| 225 | const IdentifierInfo *Name, |
| 226 | SourceLocation StateLoc, unsigned State) { |
| 227 | } |
| 228 | |
| 229 | |
| 230 | virtual void PragmaWarning(SourceLocation Loc, StringRef WarningSpec, |
| 231 | ArrayRef<int> Ids) { |
| 232 | } |
| 233 | |
| 234 | |
| 235 | virtual void PragmaWarningPush(SourceLocation Loc, int Level) { |
| 236 | } |
| 237 | |
| 238 | |
| 239 | virtual void PragmaWarningPop(SourceLocation Loc) { |
| 240 | } |
| 241 | |
| 242 | |
| 243 | |
| 244 | virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) {} |
| 245 | |
| 246 | |
| 247 | |
| 248 | virtual void PragmaExecCharsetPop(SourceLocation Loc) {} |
| 249 | |
| 250 | |
| 251 | |
| 252 | virtual void PragmaAssumeNonNullBegin(SourceLocation Loc) {} |
| 253 | |
| 254 | |
| 255 | |
| 256 | virtual void PragmaAssumeNonNullEnd(SourceLocation Loc) {} |
| 257 | |
| 258 | |
| 259 | |
| 260 | virtual void MacroExpands(const Token &MacroNameTok, |
| 261 | const MacroDefinition &MD, SourceRange Range, |
| 262 | const MacroArgs *Args) {} |
| 263 | |
| 264 | |
| 265 | virtual void MacroDefined(const Token &MacroNameTok, |
| 266 | const MacroDirective *MD) { |
| 267 | } |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | virtual void MacroUndefined(const Token &MacroNameTok, |
| 276 | const MacroDefinition &MD, |
| 277 | const MacroDirective *Undef) { |
| 278 | } |
| 279 | |
| 280 | |
| 281 | |
| 282 | virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD, |
| 283 | SourceRange Range) { |
| 284 | } |
| 285 | |
| 286 | |
| 287 | |
| 288 | virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, |
| 289 | const FileEntry *File, |
| 290 | SrcMgr::CharacteristicKind FileType) {} |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) { |
| 299 | } |
| 300 | |
| 301 | enum ConditionValueKind { |
| 302 | CVK_NotEvaluated, CVK_False, CVK_True |
| 303 | }; |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | virtual void If(SourceLocation Loc, SourceRange ConditionRange, |
| 312 | ConditionValueKind ConditionValue) { |
| 313 | } |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, |
| 322 | ConditionValueKind ConditionValue, SourceLocation IfLoc) { |
| 323 | } |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, |
| 330 | const MacroDefinition &MD) { |
| 331 | } |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, |
| 338 | const MacroDefinition &MD) { |
| 339 | } |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | virtual void Else(SourceLocation Loc, SourceLocation IfLoc) { |
| 345 | } |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) { |
| 351 | } |
| 352 | }; |
| 353 | |
| 354 | |
| 355 | class PPChainedCallbacks : public PPCallbacks { |
| 356 | virtual void anchor(); |
| 357 | std::unique_ptr<PPCallbacks> First, Second; |
| 358 | |
| 359 | public: |
| 360 | PPChainedCallbacks(std::unique_ptr<PPCallbacks> _First, |
| 361 | std::unique_ptr<PPCallbacks> _Second) |
| 362 | : First(std::move(_First)), Second(std::move(_Second)) {} |
| 363 | |
| 364 | void FileChanged(SourceLocation Loc, FileChangeReason Reason, |
| 365 | SrcMgr::CharacteristicKind FileType, |
| 366 | FileID PrevFID) override { |
| 367 | First->FileChanged(Loc, Reason, FileType, PrevFID); |
| 368 | Second->FileChanged(Loc, Reason, FileType, PrevFID); |
| 369 | } |
| 370 | |
| 371 | void FileSkipped(const FileEntry &SkippedFile, |
| 372 | const Token &FilenameTok, |
| 373 | SrcMgr::CharacteristicKind FileType) override { |
| 374 | First->FileSkipped(SkippedFile, FilenameTok, FileType); |
| 375 | Second->FileSkipped(SkippedFile, FilenameTok, FileType); |
| 376 | } |
| 377 | |
| 378 | bool FileNotFound(StringRef FileName, |
| 379 | SmallVectorImpl<char> &RecoveryPath) override { |
| 380 | return First->FileNotFound(FileName, RecoveryPath) || |
| 381 | Second->FileNotFound(FileName, RecoveryPath); |
| 382 | } |
| 383 | |
| 384 | void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, |
| 385 | StringRef FileName, bool IsAngled, |
| 386 | CharSourceRange FilenameRange, const FileEntry *File, |
| 387 | StringRef SearchPath, StringRef RelativePath, |
| 388 | const Module *Imported, |
| 389 | SrcMgr::CharacteristicKind FileType) override { |
| 390 | First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, |
| 391 | FilenameRange, File, SearchPath, RelativePath, |
| 392 | Imported, FileType); |
| 393 | Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, |
| 394 | FilenameRange, File, SearchPath, RelativePath, |
| 395 | Imported, FileType); |
| 396 | } |
| 397 | |
| 398 | void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, |
| 399 | const Module *Imported) override { |
| 400 | First->moduleImport(ImportLoc, Path, Imported); |
| 401 | Second->moduleImport(ImportLoc, Path, Imported); |
| 402 | } |
| 403 | |
| 404 | void EndOfMainFile() override { |
| 405 | First->EndOfMainFile(); |
| 406 | Second->EndOfMainFile(); |
| 407 | } |
| 408 | |
| 409 | void Ident(SourceLocation Loc, StringRef str) override { |
| 410 | First->Ident(Loc, str); |
| 411 | Second->Ident(Loc, str); |
| 412 | } |
| 413 | |
| 414 | void PragmaDirective(SourceLocation Loc, |
| 415 | PragmaIntroducerKind Introducer) override { |
| 416 | First->PragmaDirective(Loc, Introducer); |
| 417 | Second->PragmaDirective(Loc, Introducer); |
| 418 | } |
| 419 | |
| 420 | void (SourceLocation Loc, const IdentifierInfo *Kind, |
| 421 | StringRef Str) override { |
| 422 | First->PragmaComment(Loc, Kind, Str); |
| 423 | Second->PragmaComment(Loc, Kind, Str); |
| 424 | } |
| 425 | |
| 426 | void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
| 427 | StringRef Value) override { |
| 428 | First->PragmaDetectMismatch(Loc, Name, Value); |
| 429 | Second->PragmaDetectMismatch(Loc, Name, Value); |
| 430 | } |
| 431 | |
| 432 | void PragmaDebug(SourceLocation Loc, StringRef DebugType) override { |
| 433 | First->PragmaDebug(Loc, DebugType); |
| 434 | Second->PragmaDebug(Loc, DebugType); |
| 435 | } |
| 436 | |
| 437 | void PragmaMessage(SourceLocation Loc, StringRef Namespace, |
| 438 | PragmaMessageKind Kind, StringRef Str) override { |
| 439 | First->PragmaMessage(Loc, Namespace, Kind, Str); |
| 440 | Second->PragmaMessage(Loc, Namespace, Kind, Str); |
| 441 | } |
| 442 | |
| 443 | void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override { |
| 444 | First->PragmaDiagnosticPush(Loc, Namespace); |
| 445 | Second->PragmaDiagnosticPush(Loc, Namespace); |
| 446 | } |
| 447 | |
| 448 | void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override { |
| 449 | First->PragmaDiagnosticPop(Loc, Namespace); |
| 450 | Second->PragmaDiagnosticPop(Loc, Namespace); |
| 451 | } |
| 452 | |
| 453 | void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, |
| 454 | diag::Severity mapping, StringRef Str) override { |
| 455 | First->PragmaDiagnostic(Loc, Namespace, mapping, Str); |
| 456 | Second->PragmaDiagnostic(Loc, Namespace, mapping, Str); |
| 457 | } |
| 458 | |
| 459 | void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, |
| 460 | const FileEntry *File, |
| 461 | SrcMgr::CharacteristicKind FileType) override { |
| 462 | First->HasInclude(Loc, FileName, IsAngled, File, FileType); |
| 463 | Second->HasInclude(Loc, FileName, IsAngled, File, FileType); |
| 464 | } |
| 465 | |
| 466 | void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, |
| 467 | SourceLocation StateLoc, unsigned State) override { |
| 468 | First->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State); |
| 469 | Second->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State); |
| 470 | } |
| 471 | |
| 472 | void PragmaWarning(SourceLocation Loc, StringRef WarningSpec, |
| 473 | ArrayRef<int> Ids) override { |
| 474 | First->PragmaWarning(Loc, WarningSpec, Ids); |
| 475 | Second->PragmaWarning(Loc, WarningSpec, Ids); |
| 476 | } |
| 477 | |
| 478 | void PragmaWarningPush(SourceLocation Loc, int Level) override { |
| 479 | First->PragmaWarningPush(Loc, Level); |
| 480 | Second->PragmaWarningPush(Loc, Level); |
| 481 | } |
| 482 | |
| 483 | void PragmaWarningPop(SourceLocation Loc) override { |
| 484 | First->PragmaWarningPop(Loc); |
| 485 | Second->PragmaWarningPop(Loc); |
| 486 | } |
| 487 | |
| 488 | void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override { |
| 489 | First->PragmaExecCharsetPush(Loc, Str); |
| 490 | Second->PragmaExecCharsetPush(Loc, Str); |
| 491 | } |
| 492 | |
| 493 | void PragmaExecCharsetPop(SourceLocation Loc) override { |
| 494 | First->PragmaExecCharsetPop(Loc); |
| 495 | Second->PragmaExecCharsetPop(Loc); |
| 496 | } |
| 497 | |
| 498 | void PragmaAssumeNonNullBegin(SourceLocation Loc) override { |
| 499 | First->PragmaAssumeNonNullBegin(Loc); |
| 500 | Second->PragmaAssumeNonNullBegin(Loc); |
| 501 | } |
| 502 | |
| 503 | void PragmaAssumeNonNullEnd(SourceLocation Loc) override { |
| 504 | First->PragmaAssumeNonNullEnd(Loc); |
| 505 | Second->PragmaAssumeNonNullEnd(Loc); |
| 506 | } |
| 507 | |
| 508 | void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, |
| 509 | SourceRange Range, const MacroArgs *Args) override { |
| 510 | First->MacroExpands(MacroNameTok, MD, Range, Args); |
| 511 | Second->MacroExpands(MacroNameTok, MD, Range, Args); |
| 512 | } |
| 513 | |
| 514 | void MacroDefined(const Token &MacroNameTok, |
| 515 | const MacroDirective *MD) override { |
| 516 | First->MacroDefined(MacroNameTok, MD); |
| 517 | Second->MacroDefined(MacroNameTok, MD); |
| 518 | } |
| 519 | |
| 520 | void MacroUndefined(const Token &MacroNameTok, |
| 521 | const MacroDefinition &MD, |
| 522 | const MacroDirective *Undef) override { |
| 523 | First->MacroUndefined(MacroNameTok, MD, Undef); |
| 524 | Second->MacroUndefined(MacroNameTok, MD, Undef); |
| 525 | } |
| 526 | |
| 527 | void Defined(const Token &MacroNameTok, const MacroDefinition &MD, |
| 528 | SourceRange Range) override { |
| 529 | First->Defined(MacroNameTok, MD, Range); |
| 530 | Second->Defined(MacroNameTok, MD, Range); |
| 531 | } |
| 532 | |
| 533 | void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override { |
| 534 | First->SourceRangeSkipped(Range, EndifLoc); |
| 535 | Second->SourceRangeSkipped(Range, EndifLoc); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | void If(SourceLocation Loc, SourceRange ConditionRange, |
| 540 | ConditionValueKind ConditionValue) override { |
| 541 | First->If(Loc, ConditionRange, ConditionValue); |
| 542 | Second->If(Loc, ConditionRange, ConditionValue); |
| 543 | } |
| 544 | |
| 545 | |
| 546 | void Elif(SourceLocation Loc, SourceRange ConditionRange, |
| 547 | ConditionValueKind ConditionValue, SourceLocation IfLoc) override { |
| 548 | First->Elif(Loc, ConditionRange, ConditionValue, IfLoc); |
| 549 | Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc); |
| 550 | } |
| 551 | |
| 552 | |
| 553 | void Ifdef(SourceLocation Loc, const Token &MacroNameTok, |
| 554 | const MacroDefinition &MD) override { |
| 555 | First->Ifdef(Loc, MacroNameTok, MD); |
| 556 | Second->Ifdef(Loc, MacroNameTok, MD); |
| 557 | } |
| 558 | |
| 559 | |
| 560 | void Ifndef(SourceLocation Loc, const Token &MacroNameTok, |
| 561 | const MacroDefinition &MD) override { |
| 562 | First->Ifndef(Loc, MacroNameTok, MD); |
| 563 | Second->Ifndef(Loc, MacroNameTok, MD); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | void Else(SourceLocation Loc, SourceLocation IfLoc) override { |
| 568 | First->Else(Loc, IfLoc); |
| 569 | Second->Else(Loc, IfLoc); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | void Endif(SourceLocation Loc, SourceLocation IfLoc) override { |
| 574 | First->Endif(Loc, IfLoc); |
| 575 | Second->Endif(Loc, IfLoc); |
| 576 | } |
| 577 | }; |
| 578 | |
| 579 | } |
| 580 | |
| 581 | #endif |
| 582 | |