summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
* PR3330: given an enum like this:Chris Lattner2009-01-151-2/+3
| | | | | | | | | | | enum E { A = 1U, B }; Don't make an implicit cast expr of null for B. llvm-svn: 62274
* add support for initializing static vars with a cast to union (gcc extension)Nuno Lopes2009-01-151-1/+8
| | | | llvm-svn: 62261
* Initial implementation of member name lookupDouglas Gregor2009-01-151-5/+21
| | | | llvm-svn: 62247
* Refactor name lookup.Douglas Gregor2009-01-141-191/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change refactors and cleans up our handling of name lookup with LookupDecl. There are several aspects to this refactoring: - The criteria for name lookup is now encapsulated into the class LookupCriteria, which replaces the hideous set of boolean values that LookupDecl currently has. - The results of name lookup are returned in a new class LookupResult, which can lazily build OverloadedFunctionDecls for overloaded function sets (and, eventually, eliminate the need to allocate member for OverloadedFunctionDecls) and contains a placeholder for handling ambiguous name lookup (for C++). - The primary entry points for name lookup are now LookupName (for unqualified name lookup) and LookupQualifiedName (for qualified name lookup). There is also a convenience function LookupParsedName that handles qualified/unqualified name lookup when given a scope specifier. Together, these routines are meant to gradually replace the kludgy LookupDecl, but this won't happen until after we have base class lookup (which forces us to cope with ambiguities). - Documented the heck out of name lookup. Experimenting a little with using Doxygen's member groups to make some sense of the Sema class. Feedback welcome! - Fixes some lingering issues with name lookup for nested-name-specifiers, which now goes through LookupName/LookupQualifiedName. llvm-svn: 62245
* Introduce support for C++0x explicit conversion operators (N2437)Douglas Gregor2009-01-141-9/+27
| | | | | | | | | | Small cleanup in the handling of user-defined conversions. Also, implement an optimization when constructing a call. We avoid recomputing implicit conversion sequences and instead use those conversion sequences that we computed as part of overload resolution. llvm-svn: 62231
* FunctionDecl::setParams() now uses the allocator associated with ASTContext ↵Ted Kremenek2009-01-141-3/+3
| | | | | | to allocate the array of ParmVarDecl*'s. llvm-svn: 62203
* Permitting typedefs without a name is a Microsoft/GNU extensionDouglas Gregor2009-01-131-0/+8
| | | | llvm-svn: 62192
* Cleanup DeclContext::addDecl and DeclContext::insert interface, from Piotr RakDouglas Gregor2009-01-121-5/+5
| | | | llvm-svn: 62122
* Implement support for anonymous structs and unions in C. Both C andDouglas Gregor2009-01-121-20/+31
| | | | | | | | | | | | | | C++ handle anonymous structs/unions in the same way. Addresses several bugs: <rdar://problem/6259534> <rdar://problem/6481130> <rdar://problem/6483159> The test case in PR clang/1750 now passes with -fsyntax-only, but CodeGen for inline assembler still fails. llvm-svn: 62112
* Properly set the scope of non-fields declared within a struct, union,Douglas Gregor2009-01-121-7/+37
| | | | | | | | | | | | | | | | | | | or enum to be outside that struct, union, or enum. Fixes several regressions: <rdar://problem/6487662> <rdar://problem/6487669> <rdar://problem/6487684> <rdar://problem/6487702> PR clang/3305 PR clang/3312 There is still some work to do in Objective-C++, but this requires that each of the Objective-C entities (interfaces, implementations, etc.) to be introduced into the context stack with PushDeclContext/PopDeclContext. This will be a separate fix, later. llvm-svn: 62091
* Fix operator precedence.Sebastian Redl2009-01-111-1/+1
| | | | llvm-svn: 62038
* Don't bother setting NextDeclarator for EnumConstantDecls. It isn't usedDouglas Gregor2009-01-091-4/+0
| | | | llvm-svn: 62016
* When we see a reference to a struct, class, or union like "struct X"Douglas Gregor2009-01-091-3/+44
| | | | | | | | | | | | | | | | that is neither a definition nor a forward declaration and where X has not yet been declared as a tag, introduce a declaration into the appropriate scope (which is likely *not* to be the current scope). The rules for the placement of the declaration differ slightly in C and C++, so we implement both and test the various corner cases. This implementation isn't 100% correct due to some lingering issues with the function prototype scope (for a function parameter list) not being the same scope as the scope of the function definition. Testcase is FIXME'd; this probably isn't an important issue. Addresses <rdar://problem/6484805>. llvm-svn: 62014
* Replace DeclContext's vector of ScopedDecl pointers with a linked listDouglas Gregor2009-01-091-2/+3
| | | | | | | | | | | | | | | | | | of ScopedDecls (using the new ScopedDecl::NextDeclInScope pointer). Performance-wise: - It's a net win in memory utilization, since DeclContext is now one pointer smaller than it used to be (std::vectors are typically 3 pointers; we now use 2 pointers) and - Parsing Cocoa.h with -fsyntax-only (with a Release-Asserts Clang) is about 1.9% faster than before, most likely because we no longer have the memory allocations and copying associated with the std::vector. I'll re-enable serialization of DeclContexts once I've sorted out the NextDeclarator/NextDeclInScope question. llvm-svn: 62001
* Make sure that ScopedDecls passed to DeclContext::addDecl are added into ↵Douglas Gregor2009-01-091-0/+8
| | | | | | their lexical context llvm-svn: 61998
* Remove double-insertion of EnumConstantDecls. Thanks to Zhongxing Xu for ↵Douglas Gregor2009-01-081-5/+0
| | | | | | pointing this out llvm-svn: 61942
* Unify the code for defining tags in C and C++, so that we alwaysDouglas Gregor2009-01-081-79/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | introduce a Scope for the body of a tag. This reduces the number of semantic differences between C and C++ structs and unions, and will help with other features (e.g., anonymous unions) in C. Some important points: - Fields are now in the "member" namespace (IDNS_Member), to keep them separate from tags and ordinary names in C. See the new test in Sema/member-reference.c for an example of why this matters. In C++, ordinary and member name lookup will find members in both the ordinary and member namespace, so the difference between IDNS_Member and IDNS_Ordinary is erased by Sema::LookupDecl (but only in C++!). - We always introduce a Scope and push a DeclContext when we're defining a tag, in both C and C++. Previously, we had different actions and different Scope/CurContext behavior for enums, C structs/unions, and C++ structs/unions/classes. Now, it's one pair of actions. (Yay!) There's still some fuzziness in the handling of struct/union/enum definitions within other struct/union/enum definitions in C. We'll need to do some more cleanup to eliminate some reliance on CurContext before we can solve this issue for real. What we want is for something like this: struct X { struct T { int x; } t; }; to introduce T into translation unit scope (placing it at the appropriate point in the IdentifierResolver chain, too), but it should still have struct X as its lexical declaration context. PushOnScopeChains isn't smart enough to do that yet, though, so there's a FIXME test in nested-redef.c llvm-svn: 61940
* This is a large/messy diff that unifies the ObjC AST's with DeclContext.Steve Naroff2009-01-081-2/+2
| | | | | | | | | | | | | | | - ObjCContainerDecl's (ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl), ObjCCategoryImpl, & ObjCImplementation are all DeclContexts. - ObjCMethodDecl is now a ScopedDecl (so it can play nicely with DeclContext). - ObjCContainerDecl now does iteration/lookup using DeclContext infrastructure (no more linear search:-) - Removed ASTContext argument to DeclContext::lookup(). It wasn't being used and complicated it's use from an ObjC AST perspective. - Added Sema::ProcessPropertyDecl() and removed Sema::diagnosePropertySetterGetterMismatch(). - Simplified Sema::ActOnAtEnd() considerably. Still more work to do. - Fixed an incorrect casting assumption in Sema::getCurFunctionOrMethodDecl(), now that ObjCMethodDecl is a ScopedDecl. - Removed addPropertyMethods from ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl. This passes all the tests on my machine. Since many of the changes are central to the way ObjC finds it's methods, I expect some fallout (and there are still a handful of FIXME's). Nevertheless, this should be a step in the right direction. llvm-svn: 61929
* Fix PR clang/3291Douglas Gregor2009-01-071-3/+3
| | | | llvm-svn: 61886
* Finished semantic analysis of anonymous unions in C++.Douglas Gregor2009-01-071-15/+88
| | | | | | | | | Duplicate-member checking within classes is still a little messy, and anonymous unions are still completely broken in C. We'll need to unify the handling of fields in C and C++ to make this code applicable in both languages. llvm-svn: 61878
* Use DeclContext::getLookupContext wherever necessary to ensure that we look ↵Douglas Gregor2009-01-071-2/+3
| | | | | | through transparent contexts llvm-svn: 61861
* Initial implementation of anonymous unions (and, as a GNU extension,Douglas Gregor2009-01-071-9/+193
| | | | | | | | | | | | structures and classes) in C++. Covers name lookup and the synthesis and member access for the unnamed objects/fields associated with anonymous unions. Some C++ semantic checks are still missing (anonymous unions can't have function members, static data members, etc.), and there is no support for anonymous structs or unions in C. llvm-svn: 61840
* Allow Objective-C entities to be declared within a transparent contextDouglas Gregor2009-01-061-3/+1
| | | | | | nested in the translation unit. This fixes <rdar://problem/6476070>. llvm-svn: 61832
* simplify some code using 'continue' and the new 'isInIdentifierNamespace' ↵Chris Lattner2009-01-061-25/+25
| | | | | | predicate. llvm-svn: 61799
* Minor tweaks to the transparent declcontext patchDouglas Gregor2009-01-061-5/+3
| | | | llvm-svn: 61798
* Add QualifiedDeclRefExpr, which retains additional source-locationDouglas Gregor2009-01-061-2/+4
| | | | | | | | | | | | | | | | | | | information for declarations that were referenced via a qualified-id, e.g., N::C::value. We keep track of the location of the start of the nested-name-specifier. Note that the difference between QualifiedDeclRefExpr and DeclRefExpr does have an effect on the semantics of function calls in two ways: 1) The use of a qualified-id instead of an unqualified-id suppresses argument-dependent lookup 2) If the name refers to a virtual function, the qualified-id version will call the function determined statically while the unqualified-id version will call the function determined dynamically (by looking up the appropriate function in the vtable). Neither of these features is implemented yet, but we do print out qualified names for QualifiedDeclRefExprs as part of the AST printing. llvm-svn: 61789
* PODness and Type TraitsSebastian Redl2009-01-051-7/+15
| | | | | | | | | | | | | | | Make C++ classes track the POD property (C++ [class]p4) Track the existence of a copy assignment operator. Implicitly declare the copy assignment operator if none is provided. Implement most of the parsing job for the G++ type traits extension. Fully implement the low-hanging fruit of the type traits: __is_pod: Whether a type is a POD. __is_class: Whether a type is a (non-union) class. __is_union: Whether a type is a union. __is_enum: Whether a type is an enum. __is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1). llvm-svn: 61746
* Introduce support for "transparent" DeclContexts, which areDouglas Gregor2009-01-051-15/+38
| | | | | | | | | | | | | | | | | | | | | | DeclContexts whose members are visible from enclosing DeclContexts up to (and including) the innermost enclosing non-transparent DeclContexts. Transparent DeclContexts unify the mechanism to be used for various language features, including C enumerations, anonymous unions, C++0x inline namespaces, and C++ linkage specifications. Please refer to the documentation in the Clang internals manual for more information. Only enumerations and linkage specifications currently use transparent DeclContexts. Still to do: use transparent DeclContexts to implement anonymous unions and GCC's anonymous structs extension, and, later, the C++0x features. We also need to tighten up the DeclContext/ScopedDecl link to ensure that every ScopedDecl is in a single DeclContext, which will ensure that we can then enforce ownership and reduce the memory footprint of DeclContext. llvm-svn: 61735
* Parser support for C++ using directives, from Piotr RakDouglas Gregor2008-12-301-17/+33
| | | | llvm-svn: 61486
* Diagnose declarations that don't declare anything, and fix PR3020.Sebastian Redl2008-12-281-4/+11
| | | | | | | | Examples: int; typedef int; llvm-svn: 61454
* Add support for out-of-line definitions of conversion functions and member ↵Douglas Gregor2008-12-261-2/+1
| | | | | | operators llvm-svn: 61442
* Add full dllimport / dllexport support: both sema checks and codegen.Anton Korobeynikov2008-12-261-4/+24
| | | | | | Patch by Ilya Okonsky llvm-svn: 61437
* Keep track of template arguments when we parse them. Right now, we don't ↵Douglas Gregor2008-12-241-1/+2
| | | | | | actually do anything with the template arguments, but they'll be used to create template declarations llvm-svn: 61413
* Correct the order in which we cope with end-of-class-definitionDouglas Gregor2008-12-241-3/+8
| | | | | | | | | | | | | | | | | | | | | | semantics and improve our handling of default arguments. Specifically, we follow this order: - As soon as the see the '}' in the class definition, the class is complete and we add any implicit declarations (default constructor, copy constructor, etc.) to the class. - If there are any default function arguments, parse them - If there were any inline member function definitions, parse them As part of this change, we now keep track of the the fact that we've seen unparsed default function arguments within the AST. See the new ParmVarDecl::hasUnparsedDefaultArg member. This allows us to properly cope with calls inside default function arguments to other functions where we're making use of the default arguments. Made some C++ error messages regarding failed initializations more specific. llvm-svn: 61406
* Don't push OverloadedFunctionDecls onto the chain of declarationsDouglas Gregor2008-12-231-117/+89
| | | | | | | | attached to an identifier. Instead, all overloaded functions will be pushed into scope, and we'll synthesize an OverloadedFunctionDecl on the fly when we need it. llvm-svn: 61386
* Don't explicitly represent OverloadedFunctionDecls withinDouglas Gregor2008-12-231-52/+87
| | | | | | | | | | | | | | | | | | | | | | | | DeclContext. Instead, just keep the list of currently-active declarations and only build the OverloadedFunctionDecl when we absolutely need it. This is a half-step toward eliminating the need to explicitly build OverloadedFunctionDecls that store sets of overloaded functions. This was suggested by Argiris a while back, and it's a good thing for several reasons: first, it eliminates the messy logic that currently tries to keep the OverloadedFunctionDecl in sync with the declarations that are being added. Second, it will (eventually) eliminate the need to allocate memory for overload sets, which could help performance. Finally, it helps set us up for when name lookup can return multiple (possibly ambiguous) results, as can happen with lookup of class members in C++. Next steps: make the IdentifierResolver store overloads as separate entries in its list rather than replacing them with an OverloadedFunctionDecl now, then see how far we can go toward eliminating OverloadedFunctionDecl entirely. llvm-svn: 61357
* Handle typedefs to VLAs (Emit the size expr when we encounter the typedefAnders Carlsson2008-12-201-2/+1
| | | | llvm-svn: 61290
* Get rid of the old Expr::Evaluate variant.Anders Carlsson2008-12-191-7/+8
| | | | llvm-svn: 61260
* Allow downcasts of pointers to Objective-C interfaces, with aDouglas Gregor2008-12-191-2/+5
| | | | | | | warning. This matches GCC's behavior and addresses <rdar://problem/6458293>. llvm-svn: 61246
* Don't check initializers when there are dependent types or type-dependent ↵Douglas Gregor2008-12-181-0/+3
| | | | | | expressions involved llvm-svn: 61212
* Patch to re-implement duplicate ivar checkingFariborz Jahanian2008-12-171-17/+10
| | | | | | (which will pass duplicate-ivar-check.m test again). llvm-svn: 61161
* This patch will build the Records lazily per Steve's comments.Fariborz Jahanian2008-12-171-1/+2
| | | | | | | Note that one test duplicate-ivar-check.m will fail because I need to re-implement duplicate ivar checking. llvm-svn: 61154
* diagnose C99 6.9.1p5, C arguments in definitions that are lackingChris Lattner2008-12-171-0/+5
| | | | | | a name. This implements PR3208. llvm-svn: 61127
* Move the other Sema::ActOnLinkageSpec to SemaDeclCXX.Chris Lattner2008-12-171-73/+1
| | | | | | Move Sema::ActOnDefs to SemaDeclObjC llvm-svn: 61126
* Move Sema::ActOnLinkageSpec to SemaDeclCXX.Chris Lattner2008-12-171-18/+0
| | | | llvm-svn: 61125
* Make sure that enumerators show up within the enumeration declaration. ↵Douglas Gregor2008-12-171-0/+6
| | | | | | Fixes. PR clang/3220 llvm-svn: 61116
* Make linkage-specifications hold on to all of their declarationsDouglas Gregor2008-12-161-0/+23
| | | | llvm-svn: 61110
* Delay parsing of default arguments of member functions until the classDouglas Gregor2008-12-161-24/+5
| | | | | | | | | | is completely defined (C++ [class.mem]p2). Reverse the order in which we process the definitions of member functions specified inline. This way, we'll get diagnostics in the order in which the member functions were declared in the class. llvm-svn: 61103
* Diagnose that ivars in current and super class may notFariborz Jahanian2008-12-161-0/+19
| | | | | | be duplicates and a test case. llvm-svn: 61068
* Make name lookup when we're inside a declarator's scope, such as ↵Douglas Gregor2008-12-161-1/+1
| | | | | | ClassName::func, work with the new unqualified name lookup code. Test it with default arguments in out-of-line member definitions llvm-svn: 61060
OpenPOWER on IntegriCloud