summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Decl.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Make tag declarations redeclarable. This change has three purposes:Douglas Gregor2009-07-291-21/+27
| | | | | | | | | | | | | | | | 1) Allow the Index library (and any other interested client) to walk the set of declarations for a given tag (enum, union, class, whatever). At the moment, this information is not readily available. 2) Reduce our dependence on TagDecl::TypeForDecl being mapped down to a TagType (for which getDecl() will return the tag definition, if one exists). This property won't exist for class template partial specializations. 3) Make the canonical declaration of a TagDecl actually canonical, e.g., so that it does not change when the tag is defined. llvm-svn: 77523
* Change uses of:Ted Kremenek2009-07-291-6/+6
| | | | | | | | | | | | | | | | | | | | Type::getAsReferenceType() -> Type::getAs<ReferenceType>() Type::getAsRecordType() -> Type::getAs<RecordType>() Type::getAsPointerType() -> Type::getAs<PointerType>() Type::getAsBlockPointerType() -> Type::getAs<BlockPointerType>() Type::getAsLValueReferenceType() -> Type::getAs<LValueReferenceType>() Type::getAsRValueReferenceType() -> Type::getAs<RValueReferenceType>() Type::getAsMemberPointerType() -> Type::getAs<MemberPointerType>() Type::getAsReferenceType() -> Type::getAs<ReferenceType>() Type::getAsTagType() -> Type::getAs<TagType>() And remove Type::getAsReferenceType(), etc. This change is similar to one I made a couple weeks ago, but that was partly reverted pending some additional design discussion. With Doug's pending smart pointer changes for Types, it seemed natural to take this approach. llvm-svn: 77510
* Template instantiation for static data members that are defined out-of-line.Douglas Gregor2009-07-241-0/+4
| | | | | | | | Note that this also fixes a bug that affects non-template code, where we were not treating out-of-line static data members are "file-scope" variables, and therefore not checking their initializers. llvm-svn: 77002
* Add the location of the tag keyword into TagDecl. From EneaDouglas Gregor2009-07-211-7/+7
| | | | | | Zaffanella, with tweaks from Abramo Bagnara. llvm-svn: 76576
* Introduce a redecl_iterator in Decl class, so that we can do a "iterate over ↵Argyrios Kyrtzidis2009-07-181-1/+1
| | | | | | all declarations of the same decl" without knowing the exact type. llvm-svn: 76298
* Introduce the Redeclarable template class, which serves as a base type ↵Argyrios Kyrtzidis2009-07-181-42/+4
| | | | | | | | defining the common interface for Decls that can be redeclared. Make FunctionDecl and VarDecl use it. llvm-svn: 76297
* Remove getFirstDeclaration/getLatestDeclaration from FunctionDecl and VarDecl.Argyrios Kyrtzidis2009-07-181-18/+4
| | | | | | Their usefulness is questionable since redecl_iterator was introduced. llvm-svn: 76275
* Move the functionality of ASTContext::getCanonicalDecl(), into a virtual ↵Argyrios Kyrtzidis2009-07-181-4/+18
| | | | | | method Decl::getCanonicalDecl(). llvm-svn: 76273
* Per offline discussion with Steve Naroff, add back Type::getAsXXXType() methodsTed Kremenek2009-07-171-6/+6
| | | | | | | | | until Doug Gregor's Type smart pointer code lands (or more discussion occurs). These methods just call the new Type::getAs<XXX> methods, so we still have reduced implementation redundancy. Having explicit getAsXXXType() methods makes it easier to set breakpoints in the debugger. llvm-svn: 76193
* Replaced Type::getAsLValueReferenceType(), Type::getAsRValueReferenceType(), ↵Ted Kremenek2009-07-171-6/+6
| | | | | | Type::getAsMemberPointerType(), Type::getAsTagType(), and Type::getAsRecordType() with their Type::getAs<XXX> equivalents. llvm-svn: 76139
* Add a "TypeSpecStartLoc" to FieldDecl. Patch contributed by Enea Zaffanella.Steve Naroff2009-07-141-2/+2
| | | | | Note: One day, it might be useful to consider adding this info to DeclGroup (as the comments in FunctionDecl/VarDecl suggest). For now, I think this works fine. I considered moving this to ValueDecl (a common ancestor of FunctionDecl/VarDecl/FieldDecl), however this would add overhead to EnumConstantDecl (which would burn memory and isn't necessary). llvm-svn: 75635
* Introduce redecl_iterator, used for iterating over the redeclarations of a ↵Argyrios Kyrtzidis2009-07-141-19/+19
| | | | | | | | | | | | | | | | | | | | | FunctionDecl or VarDecl. It iterates over all the redeclarations, regardless of the starting point. For example: 1) int f(); 2) int f(); 3) int f(); if you have the (2) FunctionDecl and call redecls_begin/redecls_end to iterate, you'll get this sequence: (2) (1) (3) The motivation to introduce this was that, previously, if (3) was a function definition, and you called getBody() at (2), it would not return it, since getBody() iterated over the previous declarations only, so it would only check (2) and (1). llvm-svn: 75604
* Introduce FunctionDecl::getLatestDeclaration() and ↵Argyrios Kyrtzidis2009-07-141-7/+39
| | | | | | | | | | VarDecl::getLatestDeclaration(). For multiple redeclarations they return the last one. Also, add some non const versions of methods. llvm-svn: 75603
* Introduce FunctionDecl::getFirstDeclaration() and ↵Argyrios Kyrtzidis2009-07-141-10/+18
| | | | | | | | VarDecl::getFirstDeclaration(). For multiple redeclarations they return the first one. llvm-svn: 75602
* Add the SourceLocation for the right brace in TagDecl.Argyrios Kyrtzidis2009-07-141-0/+5
| | | | llvm-svn: 75590
* Implemented memmove_collectable API for Next runtimeFariborz Jahanian2009-07-081-0/+1
| | | | | | | when struct variables with GC'able members are copied into. Will provide a test case later. llvm-svn: 74984
* Introduce the virtual method Decl::getPrimaryDecl().Argyrios Kyrtzidis2009-07-051-0/+16
| | | | | | | When a Decl subclass can have multiple re-declarations in the same declaration context (like FunctionDecl), getPrimaryDecl() will return a particular Decl that all of them will point to as the "primary" declaration. llvm-svn: 74800
* Remove the ASTContext parameter from the getBody() methods of Decl and ↵Argyrios Kyrtzidis2009-06-301-3/+2
| | | | | | | | subclasses. Timings showed no significant difference before and after the commit. llvm-svn: 74504
* Remove the ASTContext parameter from the attribute-related methods of Decl.Argyrios Kyrtzidis2009-06-301-6/+6
| | | | | | | | | The implementations of these methods can Use Decl::getASTContext() to get the ASTContext. This commit touches a lot of files since call sites for these methods are everywhere. I used pre-tokenized "carbon.h" and "cocoa.h" headers to do some timings, and there was no real time difference between before the commit and after it. llvm-svn: 74501
* Key decisions about 'bool' vs '_Bool' to be based on a new flag in langoptions.Chris Lattner2009-06-301-2/+1
| | | | | | | | | | | | This is simple enough, but then I thought it would be nice to make PrintingPolicy get a LangOptions so that various things can key off "bool" and "C++" independently. This spiraled out of control. There are many fixme's, but I think things are slightly better than they were before. One thing that can be improved: CFG should probably have an ASTContext pointer in it, which would simplify its clients. llvm-svn: 74493
* Improve code generation for function template specializations:Douglas Gregor2009-06-291-2/+23
| | | | | | | | | | | | | | | | - Track implicit instantiations vs. the not-yet-supported explicit specializations - Give implicit instantiations of function templates (and member functions of class templates) linkonce_odr linkage. - Improve name mangling for function template specializations, including the template arguments of the instantiation and the return type of the function. Note that our name-mangling is improved, but not correct: we still don't mangle substitutions, although the manglings we produce can be demangled. llvm-svn: 74466
* Keep track of function template specializations, to eliminateDouglas Gregor2009-06-291-6/+19
| | | | | | | redundant, implicit instantiations of function templates and provide a place where we can hang function template specializations. llvm-svn: 74454
* -Keep a reference to the ASTContext inside the TranslationUnitDecl.Argyrios Kyrtzidis2009-06-291-1/+1
| | | | | | | | -Introduce Decl::getASTContext() which returns the reference from the TranslationUnitDecl that it is contained in. The general idea is that Decls can point to their own ASTContext so that it is no longer required to "manually" keep track and make sure that you pass the correct ASTContext to Decls' methods, e.g. methods like Decl::getAttrs should eventually not require a ASTContext parameter. llvm-svn: 74434
* Move FunctionDecl::TemplateSpecializationInfo out into its own class,Douglas Gregor2009-06-291-5/+25
| | | | | | FunctionTemplateSpecializationInfo, in DeclTemplate.h. No functionality change. llvm-svn: 74431
* Add NamedDecl::getUnderlyingDecl that can see through UsingDecl and ↵Anders Carlsson2009-06-261-0/+13
| | | | | | ObjCCompatibleAliasDecl. llvm-svn: 74279
* Implicit instantiation for function template specializations.Douglas Gregor2009-06-261-0/+18
| | | | | | | | | For a FunctionDecl that has been instantiated due to template argument deduction, we now store the primary template from which it was instantiated and the deduced template arguments. From this information, we can instantiate the body of the function template. llvm-svn: 74232
* Improved semantic analysis and AST respresentation for functionDouglas Gregor2009-06-251-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | templates. For example, this now type-checks (but does not instantiate the body of deref<int>): template<typename T> T& deref(T* t) { return *t; } void test(int *ip) { int &ir = deref(ip); } Specific changes/additions: * Template argument deduction from a call to a function template. * Instantiation of a function template specializations (just the declarations) from the template arguments deduced from a call. * FunctionTemplateDecls are stored directly in declaration contexts and found via name lookup (all forms), rather than finding the FunctionDecl and then realizing it is a template. This is responsible for most of the churn, since some of the core declaration matching and lookup code assumes that all functions are FunctionDecls. llvm-svn: 74213
* Don't use operator overload '<' for SourceLocation, it has not semantic meaning.Argyrios Kyrtzidis2009-06-231-1/+1
| | | | llvm-svn: 73932
* Add a comment.Argyrios Kyrtzidis2009-06-231-1/+2
| | | | llvm-svn: 73930
* Addressing Doug's suggestions:Argyrios Kyrtzidis2009-06-221-1/+1
| | | | | | | -Added comment for FunctionDecl::EndRangeLoc -Removed a redundant check from FunctionDecl::setBody llvm-svn: 73886
* Introduce Decl::getSourceRange() which, like Stmt::getSourceRange(), ↵Argyrios Kyrtzidis2009-06-201-0/+16
| | | | | | | | | | | represents the range that the declaration covers. Add initial support for NamespaceDecl, VarDecl, and FunctionDecl: -NamespaceDecl range is from name to '}' -VarDecl is from name to possible init expression -FunctionDecl is from name to last parameter name or to end of its function body. llvm-svn: 73821
* Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.Douglas Gregor2009-06-181-9/+10
| | | | llvm-svn: 73702
* Sink the BuiltinInfo object from ASTContext into theChris Lattner2009-06-141-0/+1
| | | | | | | | preprocessor and initialize it early in clang-cc. This ensures that __has_builtin works in all modes, not just when ASTContext is around. llvm-svn: 73319
* Make ParmVarDecl::getDefaultArg() more robust, it now asserts that the ↵Anders Carlsson2009-06-061-1/+1
| | | | | | argument is not unparsed. Add a new hasDefaultArg() and use it in places where getDefaultArg() was called when the argument was unparsed. llvm-svn: 72984
* Create a new PrintingPolicy class, which we pass down through the ASTDouglas Gregor2009-05-291-1/+5
| | | | | | | | | printing logic to help customize the output. For now, we use this rather than a special flag to suppress the "struct" when printing "struct X" and to print the Boolean type as "bool" in C++ but "_Bool" in C. llvm-svn: 72590
* Introduced DeclContext::isDependentContext, which determines whether aDouglas Gregor2009-05-281-13/+0
| | | | | | | | | | | | | | | | | | | given DeclContext is dependent on type parameters. Use this to properly determine whether a TagDecl is dependent; previously, we were missing the case where the TagDecl is a local class of a member function of a class template (phew!). Also, make sure that, when we instantiate declarations within a member function of a class template (or a function template, eventually), that we add those declarations to the "instantiated locals" map so that they can be found when instantiating declaration references. Unfortunately, I was not able to write a useful test for this change, although the assert() that fires when uncommenting the FIXME'd line in test/SemaTemplate/instantiate-declref.cpp tells the "experienced user" that we're now doing the right thing. llvm-svn: 72526
* When evaluating a VarDecl as a constant or determining whether it isDouglas Gregor2009-05-261-1/+15
| | | | | | | | an integral constant expression, maintain a cache of the value and the is-an-ICE flag within the VarDecl itself. This eliminates exponential-time behavior of the Fibonacci template metaprogram. llvm-svn: 72428
* When instantiating the definition of a member function of a classDouglas Gregor2009-05-181-1/+9
| | | | | | | | | | | | | | template, introduce that member function into the template instantiation stack. Also, add diagnostics showing the member function within the instantiation stack and clean up the qualified-name printing so that we get something like: note: in instantiation of member function 'Switch1<int, 2, 2>::f' requested here in the template instantiation backtrace. llvm-svn: 72015
* Improvements to the FunctionDecl getters/setters.Anders Carlsson2009-05-141-2/+2
| | | | llvm-svn: 71800
* 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
OpenPOWER on IntegriCloud