summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/Parser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Tweak the parse recovery in r198540Alp Toker2014-01-051-3/+8
| | | | | | | Cover a hypothetical case when we might not have reached the final argument declaration for some reason during recovery, and split out for readability. llvm-svn: 198542
* Fix bungled parse recovery in K&R function declarationsAlp Toker2014-01-051-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | void knrNoSemi(i) int i { } Adherents of The C Programming Language unfortunate enough to miss a semicolon as above would be met with a cascade of errors spanning the remainder of the TU. This patch introduces a beautiful parse error recovery, complete with helpful FixIt to restore sanity. Before (output redacted for brevity): error: 'error' diagnostics seen but not expected: File declarators.c Line 119: declaration does not declare a parameter File declarators.c Line 123: declaration does not declare a parameter File declarators.c Line 127: parameter named 'func_E12' is missing File declarators.c Line 127: expected ';' at end of declaration File declarators.c Line 133: parameter named 'func_E13' is missing File declarators.c Line 133: expected ';' at end of declaration File declarators.c Line 139: parameter named 'func_E14' is missing File declarators.c Line 139: expected ';' at end of declaration File declarators.c Line 145: parameter named 'func_E15' is missing File declarators.c Line 145: expected ';' at end of declaration File declarators.c Line 150: expected function body after function declarator File declarators.c Line 119: declaration of 'enum E11' will not be visible outside of this function File declarators.c Line 123: declaration of 'enum E12' will not be visible outside of this function File declarators.c Line 133: ISO C forbids forward references to 'enum' types File declarators.c Line 133: declaration of 'enum E13' will not be visible outside of this function File declarators.c Line 139: ISO C forbids forward references to 'enum' types File declarators.c Line 139: declaration of 'enum E14' will not be visible outside of this function File declarators.c Line 145: ISO C forbids forward references to 'enum' types File declarators.c Line 145: declaration of 'enum E15' will not be visible outside of this function ... After: declarators.c:103:24: error: expected ';' at end of declaration void knrNoSemi(i) int i { } ^ ; Patch found in a sealed envelope dated 1978 with the message "Do not open until January 2014" llvm-svn: 198540
* Parse: Token consumption modernization and loop de-nestingAlp Toker2014-01-051-2/+1
| | | | | | Cleanup only. llvm-svn: 198539
* Using the quoted version of an attribute name for consistency with other ↵Aaron Ballman2014-01-021-1/+1
| | | | | | attribute diagnostics. llvm-svn: 198326
* ExpectAndConsume: Diagnose errors automaticallyAlp Toker2014-01-011-45/+44
| | | | | | | | | | | | | | 1) Teach ExpectAndConsume() to emit expected and expected-after diagnostics using the generic diagnostic descriptions added in r197972, eliminating another set of trivial err_expected_* variations while maintaining existing behaviour. 2) Lift SkipUntil() recovery out of ExpectAndConsume(). The Expect/Consume family of functions are primitive parser operations that now have the well-defined property of operating on single tokens. Factoring out recovery exposes opportunities for more consistent and tailored error recover at the call sites instead of just relying on a bottled SkipUntil formula. llvm-svn: 198270
* Support and use token kinds as diagnostic argumentsAlp Toker2013-12-241-17/+12
| | | | | | | | | | | | | | | | | | | Introduce proper facilities to render token spellings using the diagnostic formatter. Replaces most of the hard-coded diagnostic messages related to expected tokens, which all shared the same semantics but had to be multiply defined due to variations in token order or quote marks. The associated parser changes are largely mechanical but they expose commonality in whole chunks of the parser that can now be factored away. This commit uses C++11 typed enums along with a speculative legacy fallback until the transition is complete. Requires corresponding changes in LLVM r197895. llvm-svn: 197972
* Fix OpenMP recovery with trailing tokens following the pragmaAlp Toker2013-12-181-0/+2
| | | | | | | | The recovery was failing due to a missing case in SkipUntil(). Also add back tests from r197553 that were reverted in the previous commit. llvm-svn: 197598
* Revert "[OPENMP] Fix for parsing OpenMP directives with extra braces, ↵Alp Toker2013-12-181-38/+22
| | | | | | | | | | | brackets and parens" These parser changes were redundant. The same or better recovery can be achieved with a one-line fix to SkipUntil() due to land in the next commit. This reverts commit r197553. llvm-svn: 197597
* [OPENMP] Fix for parsing OpenMP directives with extra braces, brackets and ↵Alexey Bataev2013-12-181-22/+38
| | | | | | parens llvm-svn: 197553
* Fix indentation from r197490 plus some typosAlp Toker2013-12-171-2/+2
| | | | llvm-svn: 197507
* Simplify RevertibleTypeTraits as a form of contextual keywordAlp Toker2013-12-171-3/+21
| | | | | | | | | | | Now that we emit diagnostics for keyword-as-identifier hacks (-Wkeyword-compat) we can go ahead and simplify some of the old revertible keyword support. This commit adds a TryIdentKeywordUpgrade() function to mirror the recently added TryKeywordIdentFallback() and uses it to replace the hard-coded list of REVERTIBLE_TYPE_TRAITs. llvm-svn: 197496
* Parse: Avoid crashing on unterminated top-level asm stringsJustin Bogner2013-12-101-6/+5
| | | | | | | | | | | When parsing invalid top-level asm statements, we were ignoring the return code of the SkipUntil we used for recovery. This led to crashes when we hit the end of file and tried to continue parsing anyway. This fixes the crash and adds a couple of tests for parsing related problems. llvm-svn: 196961
* Remove redundant check.Richard Smith2013-12-041-4/+1
| | | | llvm-svn: 196338
* Fix several crash-on-invalids when using template-ids that aren'tRichard Smith2013-12-041-1/+4
| | | | | | simple-template-ids (eg, 'operator+<int>') in weird places. llvm-svn: 196333
* Emit an extension warning when changing system header tokensAlp Toker2013-12-031-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | clang converts keywords to identifiers for compatibility with various system headers such as GNU libc. Implement a -Wkeyword-compat extension warning to diagnose those cases. The warning is on by default but will generally be ignored in system headers. It can however be enabled globally to aid standards conformance testing. This also changes the __uptr keyword avoidance from r195710 to no longer special-case system headers, bringing it in line with other similar workarounds in clang. Implementation returns bool for symmetry with token annotation functions. Some examples: warning: keyword '__is_pod' will be treated as an identifier for the remainder of the translation unit [-Wkeyword-compat] struct __is_pod warning: keyword '__uptr' will be treated as an identifier here [-Wkeyword-compat] union w *__uptr; llvm-svn: 196212
* [Parser] Unbreak parsing with incremental parsing enabled and add a ↵Argyrios Kyrtzidis2013-11-241-3/+1
| | | | | | unit-test for it. llvm-svn: 195564
* Generate a marker token when entering or leaving a submodule when building aRichard Smith2013-11-231-8/+25
| | | | | | | | | module. Use the marker to diagnose cases where we try to transition between submodules when not at the top level (most likely because a closing brace was missing at the end of a header file, but is also possible if submodule headers attempt to do something fundamentally non-modular, like our .def files). llvm-svn: 195543
* PR9547: If we're parsing a simple-declaration that contains a tag definition,Richard Smith2013-11-191-0/+6
| | | | | | | | and we see an ill-formed declarator that would probably be well-formed if the tag definition were just missing a semicolon, use that as the diagnostic instead of producing some other mysterious error. llvm-svn: 195163
* Make helper function static.Benjamin Kramer2013-11-181-1/+1
| | | | llvm-svn: 195017
* Replaced bool parameters in SkipUntil function with single bit-based parameter.Alexey Bataev2013-11-181-18/+32
| | | | llvm-svn: 194994
* When we hit a #include directive that maps to a module import, emit a tokenRichard Smith2013-11-151-4/+15
| | | | | | | | | | | | representing the module import rather than making the module immediately visible. This serves two goals: * It avoids making declarations in the module visible prematurely, if we walk past the #include during a tentative parse, for instance, and * It gives a diagnostic (although, admittedly, not a very nice one) if a header with a corresponding module is included anywhere other than at the top level. llvm-svn: 194782
* Support return type deduction for templates in -fdelayed-template-parsing ↵Faisal Vali2013-11-011-1/+22
| | | | | | | | (microsoft) mode Please see http://llvm-reviews.chandlerc.com/D2053 for discussion and Richard's stamp. llvm-svn: 193849
* Parse: Disable delayed template parsing for constexpr functionsDavid Majnemer2013-10-231-3/+3
| | | | | | | | | | | | | | | Commit r191484 treated constexpr function templates as normal function templates with respect to delaying their parsing. However, this is unnecessarily restrictive because there is no compatibility concern with constexpr, MSVC doesn't support it. Instead, simply disable delayed template parsing for constexpr function templates. This largely reverts the changes made in r191484 but keeps it's unit test. This fixes PR17661. llvm-svn: 193274
* Revert r193073 and the attempt to fix it in r193170.Chandler Carruth2013-10-221-9/+0
| | | | | | | | | | This patch wasn't reviewed, and isn't correctly preserving the behaviors relied upon by QT. I don't have a direct example of fallout, but it should go through the standard code review process. For example, it should never have removed the QT test case that was added when fixing those users. llvm-svn: 193174
* Fix to PR8880 (clang dies processing a for loop).Serge Pavlov2013-10-211-0/+9
| | | | | | | | | | | | | | | | Due to statement expressions supported as GCC extension, it is possible to put 'break' or 'continue' into a loop/switch statement but outside its body, for example: for ( ; ({ if (first) { first = 0; continue; } 0; }); ) Such usage must be diagnosed as an error, GCC rejects it. To recognize this and similar patterns the flags BreakScope and ContinueScope are temporarily turned off while parsing condition expression. Differential Revision: http://llvm-reviews.chandlerc.com/D1762 llvm-svn: 193073
* [-fms-extensions] Permit 'override' in C++98 and 'sealed' as a synonym for ↵David Majnemer2013-10-181-0/+1
| | | | | | | | | | | | | | 'final' Summary: Some MS headers use these features. Reviewers: rnk, rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1948 llvm-svn: 192936
* Tidy up and improve error recovery for C++11 attributes in bad places. Based onRichard Smith2013-10-151-3/+9
| | | | | | a patch by Michael Han. llvm-svn: 192666
* Parser: support Microsoft syntax for 'typename typedef'David Majnemer2013-09-031-1/+18
| | | | | | | | | | | | | | | | | | | | | | Summary: Transform the token sequence for: typename typedef T U; to: typename T typedef U; Raise a diagnostic when this happens but only if we succeeded handling the typename. Reviewers: rsmith, rnk Reviewed By: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1433 llvm-svn: 189867
* Revert "Implement a rudimentary form of generic lambdas."Manuel Klimek2013-08-221-0/+1
| | | | | | This reverts commit 606f5d7a99b11957e057e4cd1f55f931f66a42c7. llvm-svn: 189004
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-08-221-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, the following features are not included in this commit: - any sort of capturing within generic lambdas - nested lambdas - conversion operator for captureless lambdas - ensuring all visitors are generic lambda aware As an example of what compiles: template <class F1, class F2> struct overload : F1, F2 { using F1::operator(); using F2::operator(); overload(F1 f1, F2 f2) : F1(f1), F2(f2) { } }; auto Recursive = [](auto Self, auto h, auto ... rest) { return 1 + Self(Self, rest...); }; auto Base = [](auto Self, auto h) { return 1; }; overload<decltype(Base), decltype(Recursive)> O(Base, Recursive); int num_params = O(O, 5, 3, "abc", 3.14, 'a'); Please see attached tests for more examples. Some implementation notes: - Add a new Declarator context => LambdaExprParameterContext to clang::Declarator to allow the use of 'auto' in declaring generic lambda parameters - Augment AutoType's constructor (similar to how variadic template-type-parameters ala TemplateTypeParmDecl are implemented) to accept an IsParameterPack to encode a generic lambda parameter pack. - Add various helpers to CXXRecordDecl to facilitate identifying and querying a closure class - LambdaScopeInfo (which maintains the current lambda's Sema state) was augmented to house the current depth of the template being parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth) so that Sema::ActOnLambdaAutoParameter may use it to create the appropriate list of corresponding TemplateTypeParmDecl for each auto parameter identified within the generic lambda (also stored within the current LambdaScopeInfo). Additionally, a TemplateParameterList data-member was added to hold the invented TemplateParameterList AST node which will be much more useful once we teach TreeTransform how to transform generic lambdas. - SemaLambda.h was added to hold some common lambda utility functions (this file is likely to grow ...) - Teach Sema::ActOnStartOfFunctionDef to check whether it is being called to instantiate a generic lambda's call operator, and if so, push an appropriately prepared LambdaScopeInfo object on the stack. - Teach Sema::ActOnStartOfLambdaDefinition to set the return type of a lambda without a trailing return type to 'auto' in C++1y mode, and teach the return type deduction machinery in SemaStmt.cpp to process either C++11 and C++14 lambda's correctly depending on the flag. - various tests were added - but much more will be needed. A greatful thanks to all reviewers including Eli Friedman, James Dennett and the ever illuminating Richard Smith. And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified! Thanks! llvm-svn: 188977
* PR9992: Serialize and deserialize the token sequence for a function template inRichard Smith2013-08-071-14/+5
| | | | | | -fdelayed-template-parsing mode. Patch by Will Wilson! llvm-svn: 187916
* Started implementing variable templates. Top level declarations should be ↵Larisse Voufo2013-08-061-2/+4
| | | | | | fully supported, up to some limitations documented as FIXMEs or TODO. Static data member templates work very partially. Static data member templates of class templates need particular attention... llvm-svn: 187762
* Avoid recursions when the parser finds out that it has too many brackets.Rafael Espindola2013-07-251-1/+11
| | | | | | | | | BalancedDelimiterTracker::diagnoseOverflow calls P.SkipUntil, and before this patch P.SkipUnti is recursive, causing problems on systems with small stacks. This patch fixes it by making P.SkipUnti non recursive when just looking for eof. llvm-svn: 187097
* "bool" should be a context-sensitive keyword in Altivec mode.Bill Schmidt2013-07-031-0/+1
| | | | | | | | | | | | | | | | | PR16456 reported that Clang implements a hybrid between AltiVec's "Keyword and Predefine Method" and its "Context Sensitive Keyword Method," where "bool" is always a keyword, but "vector" and "pixel" are context-sensitive keywords. This isn't permitted by the AltiVec spec. For consistency with gcc, this patch implements the Context Sensitive Keyword Method for bool, and stops treating true and false as keywords in Altivec mode. The patch removes KEYALTIVEC as a trigger for defining these keywords in include/clang/Basic/TokenKinds.def, and adds logic for "vector bool" that mirrors the existing logic for "vector pixel." The test case is taken from the bug report. llvm-svn: 185580
* Adding support for MSVC #pragma detect_mismatch functionality by emitting a ↵Aaron Ballman2013-06-041-0/+4
| | | | | | FAILIFMISMATCH linker command into the object file. llvm-svn: 183178
* [modules] If we hit a failure while loading a PCH/module, abort parsing ↵Argyrios Kyrtzidis2013-05-241-1/+7
| | | | | | | | | | instead of trying to continue in an invalid state. Also don't let libclang create a PCH with such an error. Fixes rdar://13953768 llvm-svn: 182629
* OpenMP threadprivate with qualified names.Alexey Bataev2013-05-131-2/+3
| | | | llvm-svn: 181683
* Forward #pragma comment(lib/linker) through as flags metadataReid Kleckner2013-05-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: Most of this change is wiring the pragma all the way through from the lexer, parser, and sema to codegen. I considered adding a Decl AST node for this, but it seemed too heavyweight. Mach-O already uses a metadata flag called "Linker Options" to do this kind of auto-linking. This change follows that pattern. LLVM knows how to forward the "Linker Options" metadata into the COFF .drectve section where these flags belong. ELF support is not implemented, but possible. This is related to auto-linking, which is http://llvm.org/PR13016. CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D723 llvm-svn: 181426
* Move PragmaCommentHandler to lib/Parse in preparation for calling SemaReid Kleckner2013-05-061-0/+10
| | | | | | | | | | | | | | Summary: No functionality change. The existing tests for this pragma only verify that we can preprocess it. Reviewers: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D751 llvm-svn: 181246
* Parsing support for thread_local and _Thread_local. We give them the sameRichard Smith2013-04-121-2/+2
| | | | | | semantics as __thread for now. llvm-svn: 179424
* OpenMP threadprivate directive parsing and semantic analysisAlexey Bataev2013-03-221-0/+10
| | | | llvm-svn: 177705
* [Sema] Semantic analysis for empty-declaration and attribute-declaration.Michael Han2013-02-221-8/+4
| | | | | | | | Introduce a new AST Decl node "EmptyDecl" to model empty-declaration. Have attributes from attribute-declaration appertain to the EmptyDecl node by creating the AST representations of these attributes and attach them to the EmptyDecl node so these attributes can be sema checked just as attributes attached to "normal" declarations. llvm-svn: 175900
* Add -fbracket-depth=N, analogous to -ftemplate-depth= and -fconstexpr-depth=,Richard Smith2013-02-221-1/+3
| | | | | | | | | | | to control the check for the C 5.2.4.1 / C++ [implimits] restriction on nesting levels for parentheses, brackets and braces. Some code with heavy macro use exceeds the default limit of 256, but we don't want to increase it generally to avoid stack overflow on stack-constrained systems. llvm-svn: 175855
* Process and handle attributes on conditions and for loop variables. Process andRichard Smith2013-02-201-2/+10
| | | | | | | diagnose attributes on alias declarations, using directives, and attribute declarations. llvm-svn: 175649
* Finish semantic analysis for [[carries_dependency]] attribute.Richard Smith2013-01-281-1/+2
| | | | | | | | | | This required plumbing through a new flag to determine whether a ParmVarDecl is actually a parameter of a function declaration (as opposed to a function typedef etc, where the attribute is prohibited). Weirdly, this attribute (just like [[noreturn]]) cannot be applied to a function type, just to a function declaration (and its parameters). llvm-svn: 173726
* Implement C++11 semantics for [[noreturn]] attribute. This required splittingRichard Smith2013-01-171-1/+2
| | | | | | | | it apart from [[gnu::noreturn]] / __attribute__((noreturn)), since their semantics are not equivalent (for instance, we treat [[gnu::noreturn]] as affecting the function type, whereas [[noreturn]] does not). llvm-svn: 172691
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-121-1/+1
| | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
* Remove the unused Parser::ParseTranslationUnit functionHal Finkel2013-01-091-15/+0
| | | | | | | Parser::ParseTranslationUnit is now dead because the loop over ParseTopLevelDecl is in ParseAST. llvm-svn: 172005
* s/CXX0X/CXX11/g, except for __GNU_EXPERIMENTAL_CXX0X__, and update a few ↵Richard Smith2013-01-021-2/+2
| | | | | | nearby 'C++0x' comments. llvm-svn: 171372
* s/CPlusPlus0x/CPlusPlus11/gRichard Smith2013-01-021-4/+4
| | | | llvm-svn: 171367
OpenPOWER on IntegriCloud