Commit Graph

78 Commits

Author SHA1 Message Date
Chris Lattner 51ce02d264 change another PointerIntPair into a PointerUnion.
llvm-svn: 67991
2009-03-29 06:43:22 +00:00
Chris Lattner b81eb052f2 switch DeclBase::DeclCtx to the new happy and type-safe
llvm::PointerUnion class.

llvm-svn: 67988
2009-03-29 06:06:59 +00:00
Chris Lattner 20d79aa1c2 adjust to llvm mainline changes.
llvm-svn: 67980
2009-03-29 04:32:54 +00:00
Anders Carlsson f03bb51a00 Let getIdentifierNamespaceForKind know about aliases and have it treat them just like namespace decls.
llvm-svn: 67963
2009-03-28 23:02:53 +00:00
Chris Lattner fcd33a68e4 rename NextDeclInScope to NextDeclInContext, since the pointer
points within contexts not scopes.

llvm-svn: 67919
2009-03-28 06:04:26 +00:00
Chris Lattner 8e097198fc minor cleanups: make getIdentifierNamespace() be a single load
instead of a load + large inlined switch.

llvm-svn: 67864
2009-03-27 20:18:19 +00:00
Chris Lattner 17a1bfa9d8 reduce # const_casts, no functionality change.
llvm-svn: 67861
2009-03-27 19:19:59 +00:00
Chris Lattner 586c66d5ba change Decl::DeclCtx to use a PointerIntPair instead of hand bitmangling.
llvm-svn: 67858
2009-03-27 18:46:15 +00:00
Anders Carlsson a28908d575 Tighten the setAccess assert. We now allow AS_none if the decl contex is not a C++ record decl.
Also, fix fallout from the change.

llvm-svn: 67717
2009-03-25 23:38:06 +00:00
Chris Lattner c2d987425d partially inline getAttrs() to speed up PR3810 (and lots of
other code presumably) by 4.3%

llvm-svn: 67430
2009-03-21 06:27:31 +00:00
Chris Lattner eae6cb6154 rename PrettyStackTraceDecl -> PrettyStackTraceActionsDecl.
Introduce a new PrettyStackTraceDecl.
Use it to add the top level LLVM IR generation stuff in 
Backend.cpp to stack traces.  We now get crashes like:

Stack dump:
0.	Program arguments: clang t.c -emit-llvm 
1.	<eof> parser at end of file
2.	t.c:1:5: LLVM IR generation of declaration 'a'
Abort

for IR generation crashes.

llvm-svn: 66153
2009-03-05 08:00:35 +00:00
Chris Lattner 9a2d50e7fd add an a Attr::Destroy method and force clients to go through it. As part of
this, make DeclBase::Destroy destroy attributes instead of the DeclBase dtor.

llvm-svn: 66020
2009-03-04 06:05:19 +00:00
Chris Lattner c25d8a7e30 improve compatibility with GCC 4.4, patch by Michel Salim (PR3697)
llvm-svn: 65884
2009-03-02 22:20:04 +00:00
Douglas Gregor d56a91e8f6 Make the type associated with a ClassTemplateSpecializationDecl be a
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
2009-02-26 22:19:44 +00:00
Douglas Gregor 8d0921617e Use RecordFirst/RecordLast range checks in DeclContext
llvm-svn: 65489
2009-02-26 00:02:51 +00:00
Douglas Gregor f47b911f6e Perform additional semantic checking of class template
specializations. In particular:

  - Make sure class template specializations have a "template<>"
    header, and complain if they don't.
  - Make sure class template specializations are declared/defined
    within a valid context. (e.g., you can't declare a specialization
    std::vector<MyType> in the global namespace).

llvm-svn: 65476
2009-02-25 22:02:03 +00:00
Chris Lattner e7a0a63a16 Add copy assignment operator, caught by doug.
llvm-svn: 65331
2009-02-23 18:17:44 +00:00
Chris Lattner caae716837 optimize the 'StoredDeclsMap' for the common case where there is
exactly one decl with a specific name in a specific context.  This
avoids a bunch of malloc traffic and shrinks StoredDeclsMap to hold
one pointer instead of 3 words (for a std::vector).

This speeds up -fsyntax-only on cocoa.h with PTH by ~7.3%.

llvm-svn: 65103
2009-02-20 01:44:05 +00:00
Chris Lattner 29578f3f41 make the redeclaration case faster for the common instance of a redeclaration
where there is exactly one existing declaration.  This is common.

this speeds up clang about 3% on cocoa.h for me 0.165 -> 0.160s

llvm-svn: 65096
2009-02-20 01:10:07 +00:00
Chris Lattner 33f219d1a9 80 cols
llvm-svn: 65095
2009-02-20 00:56:18 +00:00
Chris Lattner 24e24d51a1 slight code simplifications.
llvm-svn: 65094
2009-02-20 00:55:03 +00:00
Chris Lattner 124bb197a7 only do one DenseMap lookup instead of two (one to find out if there is
already an entry and one to insert).

llvm-svn: 65030
2009-02-19 07:05:16 +00:00
Chris Lattner 74c04eb99e minor simplification.
llvm-svn: 65029
2009-02-19 07:02:09 +00:00
Chris Lattner dfd6b3d190 use early exit to reduce indentation.
llvm-svn: 65028
2009-02-19 07:00:44 +00:00
Douglas Gregor 67a6564091 Implement basic parsing and semantic analysis for explicit
specialization of class templates, e.g.,

  template<typename T> class X;

  template<> class X<int> { /* blah */ };

Each specialization is a different *Decl node (naturally), and can
have different members. We keep track of forward declarations and
definitions as for other class/struct/union types.

This is only the basic framework: we still have to deal with checking
the template headers properly, improving recovery when there are
failures, handling nested name specifiers, etc.

llvm-svn: 64848
2009-02-17 23:15:12 +00:00
Argyrios Kyrtzidis 84d8fae3be Move DeclContext::getParent and getLexicalParent in-line.
llvm-svn: 64806
2009-02-17 20:26:05 +00:00
Argyrios Kyrtzidis 50c0ff1f43 Currently all DeclContexts are Decls as well; use cast<Decl> instead of dyn_cast.
llvm-svn: 64805
2009-02-17 20:24:53 +00:00
Argyrios Kyrtzidis afe24c8818 DeclContext had its "casting machinery" inside the class definition so that if a new declaration context Decl appeared, the necessary changes
would be in one place. Since, now, only DeclNodes.def needs to be modified, move things out-of-line and simplify the DeclContext class.

llvm-svn: 64630
2009-02-16 14:29:28 +00:00
Argyrios Kyrtzidis ac152f1a1a Make DeclContexts maintenance a bit easier.
-In DeclNodes.def, only mark as DeclContexts the top classes that directly derive from DeclContext. If the Decl has subclasses,
 it should be marked with DECL_CONTEXT_BASE.

-Use DeclNodes.def to automate the DeclContext::classof and DeclContext::CastTo definitions.

llvm-svn: 64629
2009-02-16 14:28:33 +00:00
Douglas Gregor ded2d7b021 Basic representation of C++ class templates, from Andrew Sutton.
llvm-svn: 63750
2009-02-04 19:02:06 +00:00
Douglas Gregor 889ceb752d Semantic analysis, ASTs, and unqualified name lookup support for C++
using directives, from Piotr Rak!

llvm-svn: 63646
2009-02-03 19:21:40 +00:00
Douglas Gregor 8bd3c2ebac Add a macro-based enumeration of all of the Decl nodes (like we do
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
2009-02-02 23:39:07 +00:00
Steve Naroff 13ae6f47cd Remove many references to ASTContext::getAllocator(), replacing them with 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
2009-01-27 21:25:57 +00:00
Steve Naroff 5faaef7692 Allocate expresssions through ASTContext (still more work to do).
Add debug hook to DeclContext.

llvm-svn: 62605
2009-01-20 19:53:53 +00:00
Douglas Gregor 0da5ac8499 Rename DeclContext::insert to DeclContext::makeDeclVisibleInContext and document both it and DeclContext::addDecl properly
llvm-svn: 62581
2009-01-20 16:54:50 +00:00
Douglas Gregor 00447933f6 Remove the TopLevelDecls from TranslationUnit, since all of those decls are owned by the ASTContext's TranslationUnitDecl. There are definitely some leaking Decls now that I'll tackle tomorrow
llvm-svn: 62568
2009-01-20 04:25:11 +00:00
Douglas Gregor 6e6ad602e5 Remove ScopedDecl, collapsing all of its functionality into Decl, so
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
2009-01-20 01:17:11 +00:00
Douglas Gregor dee1be8e95 Teach DeclContext how to find the primary declaration for any TagDecl
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
2009-01-17 00:42:38 +00:00
Steve Naroff 5de9b58bd2 Fix a subtle bug in DeclContext::DestroyDecls().
llvm-svn: 62205
2009-01-14 01:27:31 +00:00
Douglas Gregor 89100920d6 Turn off some Destroy calls that are currenly causing double-destruction of ScopedDecls. We will re-enable this later, when we have time to fully solve the ownership issue.
llvm-svn: 62175
2009-01-13 19:47:12 +00:00
Douglas Gregor b3730b50c7 Cleanup DeclContext::addDecl and DeclContext::insert interface, from Piotr Rak
llvm-svn: 62122
2009-01-12 23:27:07 +00:00
Douglas Gregor 020713e308 Replace DeclContext's vector of ScopedDecl pointers with a linked list
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
2009-01-09 19:42:16 +00:00
Douglas Gregor c72e645fd6 Make sure that ScopedDecls passed to DeclContext::addDecl are added into their lexical context
llvm-svn: 61998
2009-01-09 18:51:29 +00:00
Steve Naroff b3a8798253 Move property API's up to ObjCContainerDecl (removing a lot of duplicate code).
Add isa/cast/dyncast support for ObjCContainerDecl.
Renamed classprop_iterator/begin/end to prop_iterator/begin/end (the class prefix was confusing).
More simplifications to Sema::ActOnAtEnd()...
Added/changed some FIXME's as a result of the above work.

llvm-svn: 61988
2009-01-09 15:36:25 +00:00
Douglas Gregor 82ac25e4a7 Unify the code for defining tags in C and C++, so that we always
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
2009-01-08 20:45:30 +00:00
Steve Naroff 35c62ae632 This is a large/messy diff that unifies the ObjC AST's with DeclContext.
- 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
2009-01-08 17:28:14 +00:00
Douglas Gregor 8d973111a8 When determining whether a variable is a file-scoped variable, check
out its lookup context (to see through linkage
specifications). Addresses <rdar://problem/6477142>.

llvm-svn: 61848
2009-01-07 02:48:43 +00:00
Douglas Gregor 9ac7a0707d Initial implementation of anonymous unions (and, as a GNU extension,
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
2009-01-07 00:43:41 +00:00
Douglas Gregor 6ad0ef5091 Allow Objective-C entities to be declared within a transparent context
nested in the translation unit. This fixes <rdar://problem/6476070>.

llvm-svn: 61832
2009-01-06 23:51:29 +00:00
Douglas Gregor d05cb418fd Minor tweaks to the transparent declcontext patch
llvm-svn: 61798
2009-01-06 07:17:58 +00:00