summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Decl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement the notions of the "current instantiation" and "unknownDouglas Gregor2009-05-111-3/+4
| | | | | | | | | | | | | | | | | | specialization" within a C++ template, and permit name lookup into the current instantiation. For example, given: template<typename T, typename U> struct X { typedef T type; X* x1; // current instantiation X<T, U> *x2; // current instantiation X<U, T> *x3; // not current instantiation ::X<type, U> *x4; // current instantiation X<typename X<type, U>::type, U>: *x5; // current instantiation }; llvm-svn: 71471
* Implement the semantics of the injected-class-name within a classDouglas Gregor2009-05-101-0/+13
| | | | | | | | | | | | | | | | | | template. The injected-class-name is either a type or a template, depending on whether a '<' follows it. As a type, the injected-class-name's template argument list contains its template parameters in declaration order. As part of this, add logic for canonicalizing declarations, and be sure to canonicalize declarations used in template names and template arguments. A TagType is dependent if the declaration it references is dependent. I'm not happy about the rather complicated protocol needed to use ASTContext::getTemplateSpecializationType. llvm-svn: 71408
* Improve compatibility with GCC regarding inline semantics in GNU89Douglas Gregor2009-04-281-0/+24
| | | | | | | | | | | mode and in the presence of __gnu_inline__ attributes. This should fix both PR3989 and PR4069. As part of this, we now keep track of all of the attributes attached to each declaration even after we've performed declaration merging. This fixes PR3264. llvm-svn: 70292
* Implement function-try-blocks. However, there's a very subtle bug that I ↵Sebastian Redl2009-04-261-5/+5
| | | | | | can't track down. llvm-svn: 70155
* fix PR4049, a crash on invalid, by making sema install the right number of Chris Lattner2009-04-251-3/+2
| | | | | | | | | | | | | | | | | | | | | parameters in a functiondecl, even if the decl is invalid and has a confusing Declarator. On the testcase, we now emit one beautiful diagnostic: t.c:2:1: error: unknown type name 'unknown_type' unknown_type f(void*) ^ GCC 4.0 produces: t.c:2: error: syntax error before ‘f’ t.c: In function ‘f’: t.c:2: error: parameter name omitted and GCC 4.2: t.c:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘f’ llvm-svn: 70016
* rename getNumParmVarDeclsFromType back to getNumParams(),Chris Lattner2009-04-251-13/+5
| | | | | | | | | remove a special case that was apparently for typeof() and generalize the code in SemaDecl that handles typedefs to handle any sugar type (including typedef, typeof, etc). Improve comment to make it more clear what is going on. llvm-svn: 70015
* add a new helper function to FunctionDecl instead of it beingChris Lattner2009-04-251-5/+8
| | | | | | static in Decl.cpp. llvm-svn: 70014
* Explictly track tentative definitions within Sema, then hand thoseDouglas Gregor2009-04-211-1/+2
| | | | | | | | | | | | | | | tentative definitions off to the ASTConsumer at the end of the translation unit. Eliminate CodeGen's internal tracking of tentative definitions, and instead hook into ASTConsumer::CompleteTentativeDefinition. Also, tweak the definition-deferal logic for C++, where there are no tentative definitions. Fixes <rdar://problem/6808352>, and will make it much easier for precompiled headers to cope with tentative definitions in the future. llvm-svn: 69681
* Lazy deserialization of function bodies for PCH files. For the CarbonDouglas Gregor2009-04-181-5/+6
| | | | | | | | | | "Hello, World!", this takes us from deserializing 6469 statements/expressions down to deserializing 1 statement/expression. It only translated into a 1% improvement on the Carbon-prefixed 403.gcc, but (a) it's the right thing to do, and (b) we expect this to matter more once we lazily deserialize identifiers. llvm-svn: 69407
* FunctionDecl::getBody() is getting an ASTContext argument for use inDouglas Gregor2009-04-181-1/+11
| | | | | | | | lazy PCH deserialization. Propagate that argument wherever it needs to be. No functionality change, except that I've tightened up a few PCH tests in preparation. llvm-svn: 69406
* Add VarDecl::getStorageClassSpecifierString (StorageClass -> const char*).Daniel Dunbar2009-04-141-0/+14
| | | | | | - No functionality change. llvm-svn: 69019
* Implement -Wmissing-prototypes. Fixes PR3911.Douglas Gregor2009-03-311-0/+20
| | | | llvm-svn: 68110
* Predicate to detect when a RecordDecl is really the injected-class-nameDouglas Gregor2009-03-251-0/+5
| | | | llvm-svn: 67687
* Fix <rdar://problem/6704086> by allowing the format string checking in Sema toTed Kremenek2009-03-201-1/+1
| | | | | | | | allow non-literal format strings that are variables that (a) permanently bind to a string constant and (b) whose string constants are resolvable within the same translation unit. llvm-svn: 67404
* BlockDecl::Destroy now deallocates BlockDecl's array of ParmVarDecl*.Ted Kremenek2009-03-131-1/+2
| | | | llvm-svn: 66979
* Fix <rdar://problem/6675489> BlockDecl should not use llvm::smallvector.Steve Naroff2009-03-131-0/+17
| | | | | | Also changed BlockDecl API to be more consistent (wrt FunctionDecl). llvm-svn: 66904
* API fix: All "bodies" for functions, Objective-C methods, blocks, are assumed toTed Kremenek2009-03-121-2/+2
| | | | | | | | be CompoundStmts. I think this is a valid assumption, and felt that the API should reflect it. Others please validate this assumption to make sure I didn't break anything. llvm-svn: 66814
* Add type checking for tentative definitions at the end of theDouglas Gregor2009-03-101-0/+16
| | | | | | | | | translation unit. Thread the various declarations of variables via VarDecl::getPreviousDeclaration. llvm-svn: 66601
* Switch attributes to be allocated from the declcontext bump pointer just likeChris Lattner2009-03-041-0/+11
| | | | | | | decls. This reduces the number of calls to malloc on cocoa.h with pth and -disable-free from 15958 to 12444 times (down ~3500). llvm-svn: 66023
* Rework the way we find locally-scoped external declarations when weDouglas Gregor2009-03-021-0/+41
| | | | | | | | | | | need them to evaluate redeclarations or call a function that hasn't already been declared. We now keep a DenseMap of these locally-scoped declarations so that they are not visible but can be quickly found, e.g., when we're looking for previous declarations or before we go ahead and implicitly declare a function that's being called. Fixes PR3672. llvm-svn: 65792
* Create a new TypeNodes.def file that enumerates all of the types,Douglas Gregor2009-02-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | giving them rough classifications (normal types, never-canonical types, always-dependent types, abstract type representations) and making it far easier to make sure that we've hit all of the cases when decoding types. Switched some switch() statements on the type class over to using this mechanism, and filtering out those things we don't care about. For example, CodeGen should never see always-dependent or non-canonical types, while debug info generation should never see always-dependent types. More switch() statements on the type class need to be moved over to using this approach, so that we'll get warnings when we add a new type then fail to account for it somewhere in the compiler. As part of this, some types have been renamed: TypeOfExpr -> TypeOfExprType FunctionTypeProto -> FunctionProtoType FunctionTypeNoProto -> FunctionNoProtoType There shouldn't be any functionality change... llvm-svn: 65591
* Make the type associated with a ClassTemplateSpecializationDecl be aDouglas Gregor2009-02-261-6/+8
| | | | | | | | nicely sugared type that shows how the user wrote the actual specialization. This sugared type won't actually show up until we start doing instantiations. llvm-svn: 65577
* C99 DR #316 implies that the function parameter types that are knownDouglas Gregor2009-02-251-2/+6
| | | | | | | | | | only from a function definition (that does not have a prototype) are only used to determine the compatible with other declarations of that same function. In particular, when referencing the function we pretend as if it does not have a prototype. Implement this behavior, which fixes PR3626. llvm-svn: 65460
* When we're declaring an object or function with linkage, teach nameDouglas Gregor2009-02-241-0/+9
| | | | | | | lookup to skip over names without linkage. This finishes <rdar://problem/6127293>. llvm-svn: 65386
* Improve merging of function declarations. Specifically:Douglas Gregor2009-02-241-0/+5
| | | | | | | | | | | | | | | | - When we are declaring a function in local scope, we can merge with a visible declaration from an outer scope if that declaration refers to an entity with linkage. This behavior now works in C++ and properly ignores entities without linkage. - Diagnose the use of "static" on a function declaration in local scope. - Diagnose the declaration of a static function after a non-static declaration of the same function. - Propagate the storage specifier to a function declaration from a prior declaration (PR3425) - Don't name-mangle "main" llvm-svn: 65360
* Contains the following (related to problems found while investigting ↵Steve Naroff2009-02-221-0/+5
| | | | | | | | | | <rdar://problem/6497631> Message lookup is sometimes different than gcc's). - Implement instance/class overloading in ObjCContainerDecl (removing a FIXME). This involved hacking NamedDecl::declarationReplaces(), which took awhile to figure out (didn't realize replace was the default). - Changed Sema::ActOnInstanceMessage() to remove redundant warnings when dealing with protocols. For now, I've omitted the "protocol" term in the diagnostic. It simplifies the code flow and wan't always 100% accurate (e.g. "Foo<Prot>" looks in the class interface, not just the protocol). - Changed several test cases to jive with the above changes. llvm-svn: 65292
* Static variables and functions won't collide with standard libraryDouglas Gregor2009-02-171-0/+4
| | | | | | | functions, so if we're declaring a static we should implicitly declare a library function by the same name (e.g., malloc, strdup). Fixes PR3592. llvm-svn: 64736
* Add hook to add attributes to function declarations that we knowDouglas Gregor2009-02-141-9/+27
| | | | | | | | | | | | | | | | about, whether they are builtins or not. Use this to add the appropriate "format" attribute to NSLog, NSLogv, asprintf, and vasprintf, and to translate builtin attributes (from Builtins.def) into actual attributes on the function declaration. Use the "printf" format attribute on function declarations to determine whether we should do format string checking, rather than looking at an ad hoc list of builtins and "known" function names. Be a bit more careful about when we consider a function a "builtin" in C++. llvm-svn: 64561
* Implicitly declare certain C library functions (malloc, strcpy, memmove,Douglas Gregor2009-02-131-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | etc.) when we perform name lookup on them. This ensures that we produce the correct signature for these functions, which has two practical impacts: 1) When we're supporting the "implicit function declaration" feature of C99, these functions will be implicitly declared with the right signature rather than as a function returning "int" with no prototype. See PR3541 for the reason why this is important (hint: GCC always predeclares these functions). 2) If users attempt to redeclare one of these library functions with an incompatible signature, we produce a hard error. This patch does a little bit of work to give reasonable error messages. For example, when we hit case #1 we complain that we're implicitly declaring this function with a specific signature, and then we give a note that asks the user to include the appropriate header (e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In case #2, we show the type of the implicit builtin that was incorrectly declared, so the user can see the problem. We could do better here: for example, when displaying this latter error message we say something like: 'strcpy' was implicitly declared here with type 'char *(char *, char const *)' but we should really print out a fake code line showing the declaration, like this: 'strcpy' was implicitly declared here as: char *strcpy(char *, char const *) This would also be good for printing built-in candidates with C++ operator overloading. The set of C library functions supported by this patch includes all functions from the C99 specification's <stdlib.h> and <string.h> that (a) are predefined by GCC and (b) have signatures that could cause codegen issues if they are treated as functions with no prototype returning and int. Future work could extend this set of functions to other C library functions that we know about. llvm-svn: 64504
* Fix the symptom of the regression, by having the CXXConditionDeclExpr not ↵Sebastian Redl2009-02-051-1/+3
| | | | | | | | destroy its Decl. However, the cause still remains: the Decl is linked into the chain of its DeclContext and remains there despite being deleted. llvm-svn: 63868
* Some name-lookup-related fixes, from Piotr Rak!Douglas Gregor2009-02-041-0/+36
| | | | | | | | | | | | | - Changes Lookup*Name functions to return NamedDecls, instead of Decls. Unfortunately my recent statement that it will simplify lot of code, was not quite right, but it simplifies some... - Makes MergeLookupResult SmallPtrSet instead of vector, following Douglas suggestions. - Adds %qN format for printing qualified names to Diagnostic. - Avoids searching for using-directives in Scopes, which are not DeclScope, during unqualified name lookup. llvm-svn: 63739
* Semantic analysis, ASTs, and unqualified name lookup support for C++Douglas Gregor2009-02-031-0/+8
| | | | | | using directives, from Piotr Rak! llvm-svn: 63646
* Add a macro-based enumeration of all of the Decl nodes (like we doDouglas Gregor2009-02-021-4/+4
| | | | | | | with Stmt/Expr nodes), and convert some of the more mundane switch-on-all-decl-kinds uses over to use this new file. llvm-svn: 63570
* Finish making AST BumpPtrAllocation runtime configurable (based on ↵Steve Naroff2009-01-271-3/+2
| | | | | | | | | | | -disable-free). snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m 0.179u 0.051s 0:00.23 95.6% 0+0k 0+0io 0pf+0w snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m -disable-free 0.169u 0.052s 0:00.22 95.4% 0+0k 0+0io 0pf+0w llvm-svn: 63153
* Remove many references to ASTContext::getAllocator(), replacing them with ↵Steve Naroff2009-01-271-29/+16
| | | | | | | | calls to the recently added placement new (which uses ASTContext's allocator for memory). Also added ASTContext::Deallocate(). This will simplify runtime replacement of ASTContext's allocator. Keeping the allocator private (and removing getAllocator() entirely) is also goodness. llvm-svn: 63135
* Remove the TopLevelDecls from TranslationUnit, since all of those decls are ↵Douglas Gregor2009-01-201-1/+0
| | | | | | owned by the ASTContext's TranslationUnitDecl. There are definitely some leaking Decls now that I'll tackle tomorrow llvm-svn: 62568
* Remove ScopedDecl, collapsing all of its functionality into Decl, soDouglas Gregor2009-01-201-54/+23
| | | | | | | | | | | | | | | | that every declaration lives inside a DeclContext. Moved several things that don't have names but were ScopedDecls (and, therefore, NamedDecls) to inherit from Decl rather than NamedDecl, including ObjCImplementationDecl and LinkageSpecDecl. Now, we don't store empty DeclarationNames for these things, nor do we try to insert them into DeclContext's lookup structure. The serialization tests are temporarily disabled. We'll re-enable them once we've sorted out the remaining ownership/serialiazation issues between DeclContexts and TranslationUnion, DeclGroups, etc. llvm-svn: 62562
* fix deallocation of FunctionDecl::ParamInfoNuno Lopes2009-01-181-5/+3
| | | | llvm-svn: 62469
* Teach DeclContext how to find the primary declaration for any TagDeclDouglas Gregor2009-01-171-12/+16
| | | | | | | | | | | | | even when we are still defining the TagDecl. This is required so that qualified name lookup of a class name within its definition works (see the new bits in test/SemaCXX/qualified-id-lookup.cpp). As part of this, move the nested redefinition checking code into ActOnTag. This gives us diagnostics earlier (when we try to perform the nested redefinition, rather than when we try to complete the 2nd definition) and removes some code duplication. llvm-svn: 62386
* FunctionDecl::setParams() now uses the allocator associated with ASTContext ↵Ted Kremenek2009-01-141-2/+4
| | | | | | to allocate the array of ParmVarDecl*'s. llvm-svn: 62203
* Make sure that ScopedDecls passed to DeclContext::addDecl are added into ↵Douglas Gregor2009-01-091-0/+7
| | | | | | their lexical context llvm-svn: 61998
* Unify the code for defining tags in C and C++, so that we alwaysDouglas Gregor2009-01-081-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Finished semantic analysis of anonymous unions in C++.Douglas Gregor2009-01-071-0/+9
| | | | | | | | | 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
* Initial implementation of anonymous unions (and, as a GNU extension,Douglas Gregor2009-01-071-1/+2
| | | | | | | | | | | | 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
* Don't push OverloadedFunctionDecls onto the chain of declarationsDouglas Gregor2008-12-231-0/+13
| | | | | | | | 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
* Finish up saving original parameter type andFariborz Jahanian2008-12-201-1/+8
| | | | | | using it in ObjC's method parameter encoding. llvm-svn: 61293
* introducing ParmVarWithOriginalTypeDecl class toFariborz Jahanian2008-12-201-0/+10
| | | | | | | keep track of the original parameter decl. types. This is work in progress. llvm-svn: 61286
* fix leakage of var's initializersNuno Lopes2008-12-171-9/+23
| | | | llvm-svn: 61171
* Make sure that enumerators show up within the enumeration declaration. ↵Douglas Gregor2008-12-171-1/+0
| | | | | | Fixes. PR clang/3220 llvm-svn: 61116
* Create new EnumDecl nodes for redeclarations of enums, linking themDouglas Gregor2008-12-151-2/+4
| | | | | | | | | | together in the same way that we link RecordDecl/CXXRecordDecl nodes. Unify ActOnTag and ActOnTagStruct. Fixes PR clang/2753. llvm-svn: 61034
OpenPOWER on IntegriCloud