summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add a new attribute 'enable_if' which can be used to control overload ↵Nick Lewycky2014-01-111-7/+24
| | | | | | resolution based on the values of the function arguments at the call site. llvm-svn: 198996
* TryConsume parser cleanupsAlp Toker2014-01-101-11/+3
| | | | | | Also move some comments into the block they were meant to describe. llvm-svn: 198935
* Attempting to appease the build bots on systems with ansi escape sequences.Aaron Ballman2014-01-091-5/+8
| | | | llvm-svn: 198887
* Removing a bit of custom parsing functionality used by the thread safety ↵Aaron Ballman2014-01-091-55/+13
| | | | | | analysis APIs. Now using tablegen to determine whether an attribute's arguments should be parsed in an unevaluated context instead of relying on a separate, hard-coded list of attributes. llvm-svn: 198883
* PR18234: Mark a tag definition as invalid early if it appears in aRichard Smith2014-01-081-7/+9
| | | | | | | | type-specifier in C++. Some checks will assert in this case otherwise (in particular, the access specifier may be missing if this happens inside a class definition, due to a violation of an AST invariant). llvm-svn: 198721
* Parse: Token consumption modernization and loop de-nestingAlp Toker2014-01-051-41/+42
| | | | | | 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-17/+16
| | | | | | | | | | | | | | 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
* Recover from errors in enum definitionSerge Pavlov2013-12-311-5/+29
| | | | | | | | | | Previously any error in enum definition body stopped parsing it. With this change parser tries to recover from errors. The patch fixes PR10982. Differential Revision: http://llvm-reviews.chandlerc.com/D2018 llvm-svn: 198259
* Support and use token kinds as diagnostic argumentsAlp Toker2013-12-241-15/+14
| | | | | | | | | | | | | | | | | | | 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
* Remove OpenCL-specific type keywords and specifiersAlp Toker2013-12-181-62/+0
| | | | | | | | | | | | | | | This commit kills off custom type specifier and keyword handling of OpenCL C data types. Although the OpenCL spec describes them as keywords, we can handle them more elegantly as predefined types. This should provide better error correction and code completion as well as simplifying the implementation. The primary intention is however to simplify the C/C++ parser and save some packed bits on AST structures that had been extended in r170432 just for OpenCL. llvm-svn: 197578
* Move some more test-and-consumes over to TryConsumeToken()Alp Toker2013-12-171-36/+20
| | | | llvm-svn: 197537
* Bring order to the OpenCL keywordsAlp Toker2013-12-171-19/+1
| | | | | | | | | | | | Avoid the gratuitous repurposing of C++ keyword 'private' by using a keyword alias. Also attempt to document the OpenCL keywords based on scraps of information found online. The purpose of this commit is to reduce impact on the C++ parser. llvm-svn: 197511
* Refactor and micro-optimize ConsumeToken()Alp Toker2013-12-171-46/+30
| | | | | | | | | | | | 1) Introduce TryConsumeToken() to handle the common test-and-consume pattern. This brings about readability improvements in the parser and optimizes to avoid redundant checks in the common case. 2) Eliminate the ConsumeCodeCompletionTok special case from ConsumeToken(). This was used by only one caller which has been switched over to the more appropriate ConsumeCodeCompletionToken() function. llvm-svn: 197497
* Avoid extra error messages if method definition is inside function.Serge Pavlov2013-12-091-1/+2
| | | | llvm-svn: 196757
* ObjectiveC - Introducing objc_bridge_related attribute Fariborz Jahanian2013-12-041-0/+90
| | | | | | | | which specifies couple of (optional) method selectors for bridging a CFobject to or from an ObjectiveC object. This is wip. // rdsr://15499111 llvm-svn: 196408
* When parsing ignored attribute arguments, presuming the first argument is an ↵Aaron Ballman2013-12-041-1/+2
| | | | | | unresolved identifier the same way that we do for unknown arguments. This resolves PR18075, where we regressed the handling of OpenBSD's bounded attribute. llvm-svn: 196387
* Emit an extension warning when changing system header tokensAlp Toker2013-12-031-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove a whole lot of unused variablesAlp Toker2013-11-271-1/+0
| | | | | | | There are about 30 removed in this patch, generated by a new FixIt I haven't got round to submitting yet. llvm-svn: 195814
* Unbreak -fms-extensions with GNU libc headersAlp Toker2013-11-261-3/+12
| | | | | | | | | | | | | GNU libc uses '__uptr' as a member name in C mode, conflicting with the eponymous MSVC pointer modifier keyword. Detect and mark the token as an identifier when these specific conditions are met. __uptr will continue to work as a keyword for the remainder of the translation unit. Fixes PR17824. llvm-svn: 195710
* Generate a marker token when entering or leaving a submodule when building aRichard Smith2013-11-231-1/+4
| | | | | | | | | 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
* Fix new check for missing semicolon after struct definition to deal with theRichard Smith2013-11-201-43/+55
| | | | | | | case where the type in the following declaration is specified as a template-id, and refactor for clarity. llvm-svn: 195280
* PR9547: If we're parsing a simple-declaration that contains a tag definition,Richard Smith2013-11-191-2/+108
| | | | | | | | 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
* Replaced bool parameters in SkipUntil function with single bit-based parameter.Alexey Bataev2013-11-181-41/+46
| | | | llvm-svn: 194994
* Warn on duplicate function specifierSerge Pavlov2013-11-131-5/+5
| | | | | | | | | This patch fixes PR8264. Duplicate qualifiers already are diagnozed, now the same diagnostics is issued for duplicate function specifiers. Differential Revision: http://llvm-reviews.chandlerc.com/D2025 llvm-svn: 194559
* Attributes which accept a type as their sole argument are no longer hard ↵Aaron Ballman2013-11-041-7/+17
| | | | | | coded into the parser. Instead, they are automatically listed through tablegen. llvm-svn: 193989
* Factor out custom parsing for iboutletcollection and vec_type_hint attributesRichard Smith2013-10-311-94/+47
| | | | | | | | | into a separate "parse an attribute that takes a type argument" codepath. This results in both codepaths being a lot cleaner and simpler, and fixes some bugs where the type argument handling bled into the expression argument handling and caused us to both accept invalid and reject valid attribute arguments. llvm-svn: 193731
* PR17666: Instead of allowing an initial identifier argument in any attributeRichard Smith2013-10-241-21/+38
| | | | | | | | | | | | which we don't think can't have one, only allow it in the tiny number of attributes which opts into this weird parse rule. I've manually checked that the handlers for all these attributes can in fact cope with an identifier as the argument. This is still somewhat terrible; we should move more fully towards picking the parsing rules based on the attribute, and make the Parse -> Sema interface more type-safe. llvm-svn: 193295
* PR17567: Improve diagnostic for a mistyped constructor name. If we see somethingRichard Smith2013-10-151-15/+32
| | | | | | | | | | | that looks like a function declaration, except that it's missing a return type, try typo-correcting it to the relevant constructor name. In passing, fix a bug where the missing-type-specifier recovery codepath would drop a preceding scope specifier on the floor, leading to follow-on diagnostics and incorrect recovery for the auto-in-c++98 hack. llvm-svn: 192644
* Don't get confused by a virt-specifier after a trailing-return-type - it's notRichard Smith2013-10-131-5/+10
| | | | | | an accidentally-included name for the declarator. llvm-svn: 192559
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-09-261-15/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, the following features are not included in this commit: - any sort of capturing within generic lambdas - generic lambdas within template functions and nested within other generic lambdas - conversion operator for captureless lambdas - ensuring all visitors are generic lambda aware (Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit) As an example of what compiles through this commit: 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. This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics). Some implementation notes: - Add a new Declarator context => LambdaExprParameterContext to clang::Declarator to allow the use of 'auto' in declaring generic lambda parameters - 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 SemaType.cpp::ConvertDeclSpecToType may use it to immediately generate a template-parameter-type when 'auto' is parsed in a generic lambda parameter context. (i.e we do NOT use AutoType deduced to a template parameter type - Richard seemed ok with this approach). We encode that this template type was generated from an auto by simply adding $auto to the name which can be used for better diagnostics if needed. - 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. - various tests were added - but much more will be needed. There is obviously more work to be done, and both Richard (weakly) and Doug (strongly) have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData in a future patch which is forthcoming. A greatful thanks to all reviewers including Eli Friedman, James Dennett, and especially the two gracious wizards (Richard Smith and Doug Gregor) who spent hours providing feedback (in person in Chicago and on the mailing lists). 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: 191453
* Remove a bogus diagnostic preventing static data member templates from beingRichard Smith2013-09-181-5/+0
| | | | | | defined with no initializer. llvm-svn: 190970
* As Aaron pointed out it's simpler to reject wide string availability attr ↵Benjamin Kramer2013-09-131-1/+1
| | | | | | messages in the parser. llvm-svn: 190706
* PR13657 (and duplicates):Richard Smith2013-09-121-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a comma occurs in a default argument or default initializer within a class, disambiguate whether it is part of the initializer or whether it ends the initializer. The way this works (which I will be proposing for standardization) is to treat the comma as ending the default argument or default initializer if the following token sequence matches the syntactic constraints of a parameter-declaration-clause or init-declarator-list (respectively). This is both consistent with the disambiguation rules elsewhere (where entities are treated as declarations if they can be), and should have no regressions over our old behavior. I think it might also disambiguate all cases correctly, but I don't have a proof of that. There is an annoyance here: because we're performing a tentative parse in a situation where we may not have seen declarations of all relevant entities (if the comma is part of the initializer, lookup may find entites declared later in the class), we need to turn off typo-correction and diagnostics during the tentative parse, and in the rare case that we decide the comma is part of the initializer, we need to revert all token annotations we performed while disambiguating. Any diagnostics that occur outside of the immediate context of the tentative parse (for instance, if we trigger the implicit instantiation of a class template) are *not* suppressed, mirroring the usual rules for a SFINAE context. llvm-svn: 190639
* C++11 attributes after 'constructor-name (' unambiguously signal that we have aRichard Smith2013-09-061-0/+9
| | | | | | constructor. llvm-svn: 190111
* For "expected unqualified-id" errors after a double colon, and the double colonRichard Trieu2013-09-051-2/+9
| | | | | | | | is at the end of the line, point to the location after the double colon instead of at the next token. There is more context to be given this way. In addition, the next token can be several lines later. llvm-svn: 190029
* Update GCC attribute argument parsing comment to better reflect what's going onRichard Smith2013-09-031-12/+15
| | | | | | here. llvm-svn: 189838
* Factor out parsing and allocation of IdentifierLoc objects.Richard Smith2013-09-031-12/+12
| | | | llvm-svn: 189833
* Possibly appeasing the build bots from r189711Aaron Ballman2013-08-311-0/+1
| | | | llvm-svn: 189712
* Consolidating the notion of a GNU attribute parameter with the attribute ↵Aaron Ballman2013-08-311-48/+47
| | | | | | argument list. llvm-svn: 189711
* Revert "Implement a rudimentary form of generic lambdas."Manuel Klimek2013-08-221-20/+15
| | | | | | This reverts commit 606f5d7a99b11957e057e4cd1f55f931f66a42c7. llvm-svn: 189004
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-08-221-15/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix for dependent contexts in alias templates.Eli Friedman2013-08-151-2/+2
| | | | | | | | | | When we are parsing a type for an alias template, we are not entering the context, so we can't look into dependent classes. Make sure the parser handles this correctly. PR16904. llvm-svn: 188510
* A bit of clean up based on peer's feedback...Larisse Voufo2013-08-061-2/+1
| | | | llvm-svn: 187784
* Moved diagnosis of forward declarations of variable templates from Parser to ↵Larisse Voufo2013-08-061-12/+2
| | | | | | Sema. llvm-svn: 187768
* Started implementing variable templates. Top level declarations should be ↵Larisse Voufo2013-08-061-10/+56
| | | | | | 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
* PR5066: If a declarator cannot have an identifier, and cannot possibly beRichard Smith2013-07-111-0/+6
| | | | | | | | | followed by an identifier, then diagnose an identifier as being a bogus part of the declarator instead of tripping over it. Improves diagnostics for cases like std::vector<const int *p> my_vec; llvm-svn: 186061
* ArrayRef'ize Sema::FinalizeDeclaratorGroup, Sema::BuildDeclaratorGroup andRafael Espindola2013-07-091-4/+2
| | | | | | | | Sema::ActOnDocumentableDecls. Patch by Robert Wilhelm. llvm-svn: 185931
* Use SmallVectorImpl& for function arguments instead of SmallVector.Craig Topper2013-07-051-2/+2
| | | | llvm-svn: 185715
* "bool" should be a context-sensitive keyword in Altivec mode.Bill Schmidt2013-07-031-0/+12
| | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud