Commit Graph

151 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 60ed560428 Introduce DeclaratorDecl and pass DeclaratorInfo through the Decl/Sema interfaces.
DeclaratorDecl contains a DeclaratorInfo* to keep type source info.
Subclasses of DeclaratorDecl are FieldDecl, FunctionDecl, and VarDecl.
EnumConstantDecl still inherits from ValueDecl since it has no need for DeclaratorInfo.

Decl/Sema interfaces accept a DeclaratorInfo as parameter but no DeclaratorInfo is created yet.

llvm-svn: 79392
2009-08-19 01:27:57 +00:00
Argyrios Kyrtzidis 3f79ad7405 Introduce DeclaratorInfo and TypeLoc, intended to be used for storing and reading source information for types.
DeclaratorInfo will contain a flat memory block for source information about a type that came out of a declarator.
TypeLoc and its subclasses will be used by clients as wrappers to "traverse" the memory block and read the information.

Both DeclaratorInfo and TypeLoc are not utilized in this commit.

llvm-svn: 79391
2009-08-19 01:27:32 +00:00
John McCall deb8448690 Disable all recognition of main() in -ffreestanding. Addresses bug #4720.
llvm-svn: 79070
2009-08-15 02:09:25 +00:00
Douglas Gregor 82c80a59ee There's no point in going through the getAs<TagType> stuff to find the definition of a tag, since tags rarely have more than one or two declarations
llvm-svn: 77546
2009-07-29 23:41:44 +00:00
Douglas Gregor b6b8f9e291 Make tag declarations redeclarable. This change has three purposes:
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
2009-07-29 23:36:44 +00:00
Ted Kremenek c23c7e6a51 Change uses of:
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
2009-07-29 21:53:49 +00:00
Douglas Gregor a6ef8f0813 Template instantiation for static data members that are defined out-of-line.
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
2009-07-24 20:34:43 +00:00
Douglas Gregor 82fe3e3398 Add the location of the tag keyword into TagDecl. From Enea
Zaffanella, with tweaks from Abramo Bagnara.

llvm-svn: 76576
2009-07-21 14:46:17 +00:00
Argyrios Kyrtzidis 05898da9cb Introduce a redecl_iterator in Decl class, so that we can do a "iterate over all declarations of the same decl" without knowing the exact type.
llvm-svn: 76298
2009-07-18 08:50:35 +00:00
Argyrios Kyrtzidis fad334ce5b Introduce the Redeclarable template class, which serves as a base type defining the common interface for Decls that can be redeclared.
Make FunctionDecl and VarDecl use it.

llvm-svn: 76297
2009-07-18 08:50:13 +00:00
Argyrios Kyrtzidis 91ff94d6d9 Remove getFirstDeclaration/getLatestDeclaration from FunctionDecl and VarDecl.
Their usefulness is questionable since redecl_iterator was introduced.

llvm-svn: 76275
2009-07-18 00:34:35 +00:00
Argyrios Kyrtzidis 5614aef776 Move the functionality of ASTContext::getCanonicalDecl(), into a virtual method Decl::getCanonicalDecl().
llvm-svn: 76273
2009-07-18 00:34:07 +00:00
Ted Kremenek 8a286fbdb9 Per offline discussion with Steve Naroff, add back Type::getAsXXXType() methods
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
2009-07-17 17:50:17 +00:00
Ted Kremenek b825c0ddc5 Replaced Type::getAsLValueReferenceType(), Type::getAsRValueReferenceType(), Type::getAsMemberPointerType(), Type::getAsTagType(), and Type::getAsRecordType() with their Type::getAs<XXX> equivalents.
llvm-svn: 76139
2009-07-17 01:20:38 +00:00
Steve Naroff 5ec6ff7678 Add a "TypeSpecStartLoc" to FieldDecl. Patch contributed by Enea Zaffanella.
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
2009-07-14 14:58:18 +00:00
Argyrios Kyrtzidis 1506d9bc25 Introduce redecl_iterator, used for iterating over the redeclarations of a 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
2009-07-14 03:20:21 +00:00
Argyrios Kyrtzidis 0736c5ca3b Introduce FunctionDecl::getLatestDeclaration() and VarDecl::getLatestDeclaration().
For multiple redeclarations they return the last one.

Also, add some non const versions of methods.

llvm-svn: 75603
2009-07-14 03:20:08 +00:00
Argyrios Kyrtzidis ef17c07bf6 Introduce FunctionDecl::getFirstDeclaration() and VarDecl::getFirstDeclaration().
For multiple redeclarations they return the first one.

llvm-svn: 75602
2009-07-14 03:19:57 +00:00
Argyrios Kyrtzidis 575fa05991 Add the SourceLocation for the right brace in TagDecl.
llvm-svn: 75590
2009-07-14 03:17:17 +00:00
Fariborz Jahanian 5f21d2f69a Implemented memmove_collectable API for Next runtime
when struct variables with GC'able members are copied into.
Will provide a test case later.

llvm-svn: 74984
2009-07-08 01:18:33 +00:00
Argyrios Kyrtzidis 02dd4f9389 Introduce the virtual method Decl::getPrimaryDecl().
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
2009-07-05 22:21:56 +00:00
Argyrios Kyrtzidis ddcd132a5b Remove the ASTContext parameter from the getBody() methods of Decl and subclasses.
Timings showed no significant difference before and after the commit.

llvm-svn: 74504
2009-06-30 02:35:26 +00:00
Argyrios Kyrtzidis b4b64ca752 Remove the ASTContext parameter from the attribute-related methods of Decl.
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
2009-06-30 02:34:44 +00:00
Chris Lattner c61089a6c2 Key decisions about 'bool' vs '_Bool' to be based on a new flag in langoptions.
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
2009-06-30 01:26:17 +00:00
Douglas Gregor e8925dbc1d Improve code generation for function template specializations:
- 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
2009-06-29 22:39:32 +00:00
Douglas Gregor 8f5d4423ca Keep track of function template specializations, to eliminate
redundant, implicit instantiations of function templates and provide a
place where we can hang function template specializations.

llvm-svn: 74454
2009-06-29 20:59:39 +00:00
Argyrios Kyrtzidis 743e7db794 -Keep a reference to the ASTContext inside the TranslationUnitDecl.
-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
2009-06-29 17:38:40 +00:00
Douglas Gregor 70d83e27a4 Move FunctionDecl::TemplateSpecializationInfo out into its own class,
FunctionTemplateSpecializationInfo, in DeclTemplate.h. No functionality change.

llvm-svn: 74431
2009-06-29 17:30:29 +00:00
Anders Carlsson 6915bf6158 Add NamedDecl::getUnderlyingDecl that can see through UsingDecl and ObjCCompatibleAliasDecl.
llvm-svn: 74279
2009-06-26 06:29:23 +00:00
Douglas Gregor 4adbc6d947 Implicit instantiation for function template specializations.
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
2009-06-26 00:10:03 +00:00
Douglas Gregor ad3f2fcf43 Improved semantic analysis and AST respresentation for function
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
2009-06-25 22:08:12 +00:00
Argyrios Kyrtzidis dfc5dca1e5 Don't use operator overload '<' for SourceLocation, it has not semantic meaning.
llvm-svn: 73932
2009-06-23 00:42:15 +00:00
Argyrios Kyrtzidis 53aeec3b14 Add a comment.
llvm-svn: 73930
2009-06-23 00:42:00 +00:00
Argyrios Kyrtzidis 49abd4d95b Addressing Doug's suggestions:
-Added comment for FunctionDecl::EndRangeLoc
-Removed a redundant check from FunctionDecl::setBody

llvm-svn: 73886
2009-06-22 17:13:31 +00:00
Argyrios Kyrtzidis a3aeb5a8f1 Introduce Decl::getSourceRange() which, like Stmt::getSourceRange(), 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
2009-06-20 08:09:14 +00:00
Douglas Gregor 78bd61f661 Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.
llvm-svn: 73702
2009-06-18 16:11:24 +00:00
Chris Lattner 15ba94987a Sink the BuiltinInfo object from ASTContext into the
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
2009-06-14 01:54:56 +00:00
Anders Carlsson 8544647e9c Make ParmVarDecl::getDefaultArg() more robust, it now asserts that the 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
2009-06-06 04:14:07 +00:00
Douglas Gregor 7de5966d76 Create a new PrintingPolicy class, which we pass down through the AST
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
2009-05-29 20:38:28 +00:00
Douglas Gregor 9e927abc41 Introduced DeclContext::isDependentContext, which determines whether a
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
2009-05-28 16:34:51 +00:00
Douglas Gregor 31cf12c0a6 When evaluating a VarDecl as a constant or determining whether it is
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
2009-05-26 18:54:04 +00:00
Douglas Gregor 8567358cc9 When instantiating the definition of a member function of a class
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
2009-05-18 17:01:57 +00:00
Anders Carlsson e0dd1d57b3 Improvements to the FunctionDecl getters/setters.
llvm-svn: 71800
2009-05-14 21:46:00 +00:00
Douglas Gregor c9f9b86732 Implement the notions of the "current instantiation" and "unknown
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
2009-05-11 19:58:34 +00:00
Douglas Gregor e362cea568 Implement the semantics of the injected-class-name within a class
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
2009-05-10 22:57:19 +00:00
Douglas Gregor 76fe50c654 Improve compatibility with GCC regarding inline semantics in GNU89
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
2009-04-28 06:37:30 +00:00
Sebastian Redl a7b98a772c Implement function-try-blocks. However, there's a very subtle bug that I can't track down.
llvm-svn: 70155
2009-04-26 20:35:05 +00:00
Chris Lattner 9af40c1e14 fix PR4049, a crash on invalid, by making sema install the right number of
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
2009-04-25 06:12:16 +00:00
Chris Lattner 47c0d00c3f rename getNumParmVarDeclsFromType back to getNumParams(),
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
2009-04-25 06:03:53 +00:00
Chris Lattner dfd637f204 add a new helper function to FunctionDecl instead of it being
static in Decl.cpp.

llvm-svn: 70014
2009-04-25 05:56:45 +00:00