summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PrintPreprocessedOutput.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-1/+1
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
* [PragmaHandler] Expose `#pragma` locationJoel E. Denny2019-05-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Currently, a pragma AST node's recorded location starts at the namespace token (such as `omp` in the case of OpenMP) after the `#pragma` token, and the `#pragma` location isn't available. However, the `#pragma` location can be useful when, for example, rewriting a directive using Clang's Rewrite facility. This patch makes `#pragma` locations available in any `PragmaHandler` but it doesn't yet make use of them. This patch also uses the new `struct PragmaIntroducer` to simplify `Preprocessor::HandlePragmaDirective`. It doesn't do the same for `PPCallbacks::PragmaDirective` because that changes the API documented in `clang-tools-extra/docs/pp-trace.rst`, and I'm not sure about backward compatibility guarantees there. Reviewed By: ABataev, lebedev.ri, aaron.ballman Differential Revision: https://reviews.llvm.org/D61643 llvm-svn: 361335
* [Lex] Allow to consume tokens while preprocessingIlya Biryukov2019-05-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: By adding a hook to consume all tokens produced by the preprocessor. The intention of this change is to make it possible to consume the expanded tokens without re-runnig the preprocessor with minimal changes to the preprocessor and minimal performance penalty when preprocessing without recording the tokens. The added hook is very low-level and reconstructing the expanded token stream requires more work in the client code, the actual algorithm to collect the tokens using this hook can be found in the follow-up change. Reviewers: rsmith Reviewed By: rsmith Subscribers: eraman, nemanjai, kbarton, jsji, riccibruno, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59885 llvm-svn: 361007
* [C++20] Implement context-sensitive header-name lexing and pp-import parsing ↵Richard Smith2019-04-111-2/+11
| | | | | | in the preprocessor. llvm-svn: 358231
* Add PragmaHandler for MSVC pragma execution_character_setReid Kleckner2019-03-141-0/+20
| | | | | | | | | | | | __pragma(execution_character_set(push, "UTF-8")) is used in TraceLoggingProvider.h. This commit implements a no-op handler for compatability, similar to how the flag -fexec_charset is handled. Patch by Matt Gardner! Differential Revision: https://reviews.llvm.org/D58530 llvm-svn: 356185
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Fix combining pragma __debug dump & parser_crash with -EDavid Blaikie2018-11-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | Previously these would be transformed into annotation tokens and the preprocessor would then assume they were real tokens with source locations and assert/UB. Other pragmas that produce annotation tokens aren't a problem because they aren't handled if the parser isn't hooked up - ParsePragma.cpp registers those handlers & isn't run for pure preprocessing. So they're treated as unknown pragmas & printed verbatim by the preprocessor. Perhaps these pragmas should be treated the same way? But they got mixed in with other __debug pragmas that do need to be handled during preprocessing. The third __debug pragma that produces an annotation token is 'captured' - which had its own fix for this issue - by not inserting the annotation token in the first place if it detected that it was in preprocessing mode. I've removed that fix (from Lex/Pragma.cpp) in favor of the more general one in Frontend/PrintPreprocessedOutput.cpp. llvm-svn: 346928
* Remove trailing spaceFangrui Song2018-07-301-6/+6
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* Reland '[clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective'Julie Hockett2018-05-101-10/+13
| | | | | | | | | | | | | | This commit relands r331904. Adding a SrcMgr::CharacteristicKind parameter to the InclusionDirective in PPCallbacks, and updating calls to that function. This will be useful in https://reviews.llvm.org/D43778 to determine which includes are system headers. Differential Revision: https://reviews.llvm.org/D46614 llvm-svn: 332021
* Revert "[clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective"Julie Hockett2018-05-091-13/+10
| | | | | | This reverts commit r331904 because of a memory leak. llvm-svn: 331932
* [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirectiveJulie Hockett2018-05-091-10/+13
| | | | | | | | | | | Adding a SrcMgr::CharacteristicKind parameter to the InclusionDirective in PPCallbacks, and updating calls to that function. This will be useful in https://reviews.llvm.org/D43778 to determine which includes are system headers. Differential Revision: https://reviews.llvm.org/D46614 llvm-svn: 331904
* Calculate size of buffer instead of using a magic value.Paul Robinson2018-01-031-1/+1
| | | | | | | | Patch by Matthew Davis! Differential Revision: https://reviews.llvm.org/D41421 llvm-svn: 321757
* Don't print end-of-directive tokens in -E outputReid Kleckner2017-10-161-0/+6
| | | | | | | | | | This comes up when pre-processing standalone .s files containing hash-prefixed comments. The pre-processor should skip the unknown directive and not emit an extra newline as we were doing. Fixes PR34950 llvm-svn: 315953
* [Preprocessor] Preserve #pragma clang assume_nonnull in preprocessed outputEli Friedman2017-09-271-0/+18
| | | | | | | | Patch by Zbigniew Sarbinowski! Differential Revision: https://reviews.llvm.org/D37861 llvm-svn: 314364
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-171-2/+2
| | | | | | | | | | | | | | | | | rename Arguments to Parameters in Macro Definitions. - Extracted the reading of the tokens out into a separate function. - Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation). This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible. I will also directly update some extra clang tooling that is broken by the change from Argument to Parameter. Hopefully the bots will stay appeased. Thanks! llvm-svn: 308190
* Revert changes from my previous refactoring - will need to fix dependencies ↵Faisal Vali2017-07-171-2/+2
| | | | | | | | in clang's extra tooling (such as clang-tidy etc.). Sorry about that. llvm-svn: 308158
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-171-2/+2
| | | | | | | | | | | | | | rename Arguments to Parameters in Macro Definitions. - Extracted the reading of the tokens out into a separate function. - Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation). This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible. Thanks! llvm-svn: 308157
* Support non-identifier module names when preprocessing modules.Richard Smith2017-06-191-3/+3
| | | | llvm-svn: 305758
* Add #pragma clang module begin/end pragmas and generate them when ↵Richard Smith2017-05-041-3/+34
| | | | | | | | | | | | | | preprocessing a module. These pragmas are intended to simulate the effect of entering or leaving a file with an associated module. This is not completely implemented yet: declarations between the pragmas will not be attributed to the correct module, but macro visibility is already functional. Modules named by #pragma clang module begin must already be known to clang (in some module map that's either loaded or on the search path). llvm-svn: 302098
* Add pragma to perform module import and use it in -E output.Richard Smith2017-04-291-30/+37
| | | | | | | | | | | | | | | | | | | | | Many of our supported configurations support modules but do not have any first-class syntax to perform a module import. This leaves us with a problem: there is no way to represent the expansion of a #include that imports a module in the -E output for such languages. (We don't want to just leave it as a #include because that requires the consumer of the preprocessed source to have the same file system layout and include paths as the creator.) This patch adds a new pragma: #pragma clang module import MODULE.NAME.HERE that imports a module, and changes -E and -frewrite-includes to use it when rewriting a #include that maps to a module import. We don't make any attempt to use a native language syntax import if one exists, to get more consistent output. (If in the future, @import and #include have different semantics in some way, the pragma will track the #include semantics.) llvm-svn: 301725
* Remove leaking UnknownPragmaHandlers right after we are done with them.Vassil Vassilev2017-04-271-13/+27
| | | | | | | | | | | | | | | | The UnknownPragmaHandlers added by DoPrintPreprocessedInput conflict with the real PragmaHandlers from clang::Parser because they try to handle the same #pragma directives. This makes it impossible to use a Preprocessor (that was previously passed to DoPrintPreprocessedInput), as an Preprocessor for a clang::Parser instance which is what we currently do in cling. This patch removes the added UnknownPragmaHandler to avoid conflicts these conflicts and leave the PragmaHandlers of the Preprocessors in a the same state as before calling DoPrintPreprocessedInput. Patch by Raphael Isemann (D32486)! llvm-svn: 301563
* Revert "Revert "PPCallbacks::MacroUndefined, change signature and add test.""Vedant Kumar2017-04-261-2/+4
| | | | | | | This reverts commit r301469. It isn't needed with r301470, which fixes the API break introduced in the original commit. llvm-svn: 301472
* Revert "PPCallbacks::MacroUndefined, change signature and add test."Vedant Kumar2017-04-261-4/+2
| | | | | | | | This reverts commit r301449. It breaks the build with: MacroPPCallbacks.h:114:50: error: non-virtual member function marked 'override' hides virtual member function llvm-svn: 301469
* PPCallbacks::MacroUndefined, change signature and add test.Frederich Munch2017-04-261-2/+4
| | | | | | | | | | | | | | | | Summary: The PPCallbacks::MacroUndefined callback is currently insufficient for clients that need to track the MacroDirectives. This patch adds an additional argument to PPCallbacks::MacroUndefined that is the undef MacroDirective. Reviewers: bruno, manmanren Reviewed By: bruno Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D29923 llvm-svn: 301449
* [Preprocessor] Support for '-dI' flagBruno Cardoso Lopes2016-11-171-8/+26
| | | | | | | | | | | | | | | | | Re-introduce r285411. Implement the -dI as supported by GCC: Output ‘#include’ directives in addition to the result of preprocessing. This change aims to add this option, pass it through to the preprocessor via the options class, and when inclusions occur we output some information (+ test cases). Patch by Steve O'Brien! Differential Revision: https://reviews.llvm.org/D26089 llvm-svn: 287275
* Revert "[Preprocessor] Support for '-dI' flag"Bruno Cardoso Lopes2016-10-281-26/+8
| | | | | | | This reverts r285411. Tests failing on http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/141 llvm-svn: 285416
* [Preprocessor] Support for '-dI' flagBruno Cardoso Lopes2016-10-281-8/+26
| | | | | | | | | | | | | | | Implement the -dI as supported by GCC: Output ‘#include’ directives in addition to the result of preprocessing. This change aims to add this option, pass it through to the preprocessor via the options class, and when inclusions occur we output some information (+ test cases). Patch by Steve O'Brien! Differential Revision: https://reviews.llvm.org/D25153 llvm-svn: 285411
* [modules] Add a comment to explain why -E leaves some #includes in the ↵Richard Smith2016-04-081-1/+3
| | | | | | preprocessed output. llvm-svn: 265766
* [modules] Don't write @import in -E output if the current language mode doesn'tRichard Smith2016-04-081-2/+12
| | | | | | support @import; use the form as written instead. llvm-svn: 265756
* Remove use of builtin comma operator.Richard Trieu2016-02-181-2/+4
| | | | | | Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
* Reduce the number of implicit StringRef->std::string conversions by ↵Benjamin Kramer2016-02-131-12/+10
| | | | | | | | threading StringRef through more APIs. No functionality change intended. llvm-svn: 260815
* Simplify EnterTokenStream API to make it more robust for memory managementDavid Blaikie2016-02-091-4/+3
| | | | | | | | | | | | | | | While this won't help fix things like the bug that r260219 addressed, it seems like good tidy up to have anyway. (it might be nice if "makeArrayRef" always produced a MutableArrayRef & let it decay to an ArrayRef when needed - then I'd use that for the MutableArrayRefs in this patch) If we had std::dynarray I'd use that instead of unique_ptr+size_t, ideally (but then it'd have to be threaded down through the Preprocessor all the way - no idea how painful that would be) llvm-svn: 260246
* Fix possible OOB access found by buildbotAlexey Bataev2016-02-091-7/+8
| | | | llvm-svn: 260219
* Fixed preprocessed output of the first token for pragmas.Alexey Bataev2016-02-091-0/+9
| | | | | | | Clang did not expanded macros in the very first token of the pragmas during preprocessed output llvm-svn: 260211
* According to the OpenMP spec, all the preprocessor macros should be Samuel Antao2015-06-151-10/+42
| | | | | | expanded in OpenMP pragmas. This patch adds support for that in -E. llvm-svn: 239784
* Replace a few std::string& with StringRef. NFC.Rafael Espindola2015-06-011-3/+3
| | | | | | Patch by Косов Евгений! llvm-svn: 238774
* Refactor MacroInfo so range for loops can be used to iterate its tokens.Daniel Marjamaki2015-05-111-4/+3
| | | | | | Differential Revision: http://reviews.llvm.org/D9079 llvm-svn: 236975
* Switch PPCallbacks to take the new MacroDefinition instead of ↵Richard Smith2015-05-041-2/+2
| | | | | | MacroDirective*, in order to preserve full information on module macro expansion. llvm-svn: 236404
* [modules] Stop trying to fake up a linear MacroDirective history.Richard Smith2015-04-291-3/+3
| | | | | | | | | | | | | | Modules builds fundamentally have a non-linear macro history. In the interest of better source fidelity, represent the macro definition information faithfully: we have a linear macro directive history within each module, and at any point we have a unique "latest" local macro directive and a collection of visible imported directives. This also removes the attendent complexity of attempting to create a correct MacroDirective history (which we got wrong in the general case). No functionality change intended. llvm-svn: 236176
* [modules] Determine the set of macros exported by a submodule at the end of ↵Richard Smith2015-04-231-1/+2
| | | | | | | | | | | that submodule. Previously we'd defer this determination until writing the AST, which doesn't allow us to use this information when building other submodules of the same module. This change also allows us to use a uniform mechanism for writing module macro records, independent of whether they are local or imported. llvm-svn: 235614
* Add -fuse-line-directive flag to control usage of #line with -EReid Kleckner2015-02-261-13/+9
| | | | | | | | | | | | | | | | | | Currently -fms-extensions controls this behavior, which doesn't make much sense. It means we can't identify what is and isn't a system header when compiling our own preprocessed output, because #line doesn't represent this information. If someone is feeding Clang's preprocessed output to another compiler, they can use this flag. Fixes PR20553. Reviewers: rsmith Differential Revision: http://reviews.llvm.org/D5217 llvm-svn: 230587
* Avoid a couple of assertions when preprocessing with modulesBen Langmuir2014-09-101-0/+3
| | | | | | | | | | | | | | | | 1. We were hitting the NextIsPrevious assertion because we were trying to merge decl chains that were independent of each other because we had no Sema object to allow them to find existing decls. This is fixed by delaying loading the "preloaded" decls until Sema is available. 2. We were trying to get identifier info from an annotation token, which asserts. The fix is to special-case the module annotations in the preprocessed output printer. Fixed in a single commit because when you hit 1 you almost invariably hit 2 as well. llvm-svn: 217550
* Unique_ptrify PPCallbacks ownership.Craig Topper2014-09-101-1/+1
| | | | | | Unique_ptr creation stil needs to be moved earlier at some of the call sites. llvm-svn: 217474
* Complete the switch from mappings to declarative diagnostic severitiesAlp Toker2014-06-121-5/+5
| | | | | | | | | This begins to address cognitive dissonance caused by treating the Note diagnostic level as a severity in the diagnostic engine. No change in functionality. llvm-svn: 210758
* Improve diagnostic mapping terminologyAlp Toker2014-06-101-4/+5
| | | | | | | | | | | | Diagnostic mappings are used to calculate the final severity of diagnostic instances. Detangle the implementation to reflect the terminology used in documentation and bindings. No change in functionality. llvm-svn: 210518
* [C++11] Use 'nullptr'. Frontend edition.Craig Topper2014-05-221-2/+3
| | | | llvm-svn: 209389
* do not warn about unknown pragmas in modes that do not handle them (pr9537)Lubos Lunak2014-05-011-1/+1
| | | | | | | And refactor to have just one place in code that sets up the empty pragma handlers. llvm-svn: 207758
* Remove unreachable PragmaCaptured method. It's not a real PPCallback.Craig Topper2014-03-131-10/+0
| | | | llvm-svn: 203759
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-131-31/+27
| | | | | | class. llvm-svn: 203758
* [C++11] Revert uses of lambdas with array_pod_sort.Benjamin Kramer2014-03-071-5/+6
| | | | | | Looks like GCC implements the lambda->function pointer conversion differently. llvm-svn: 203293
OpenPOWER on IntegriCloud