summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Decl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* -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
* 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
OpenPOWER on IntegriCloud