Commit Graph

619 Commits

Author SHA1 Message Date
Steve Naroff ba3dc38840 Convert property implementation to DeclContext::addDecl().
This completes the ObjCContainerDecl AST cleanup (for now).

llvm-svn: 62037
2009-01-11 12:47:58 +00:00
Steve Naroff 0c0f5bae80 A few property related cleanups to ObjCContainerDecl AST.
llvm-svn: 62034
2009-01-11 01:06:09 +00:00
Fariborz Jahanian 8630b2d992 Explicit declaration of property setters over-ride
prohibition of 'readonly' properties in an assignment.

llvm-svn: 62028
2009-01-10 18:43:55 +00:00
Fariborz Jahanian 519976c4e9 This patch removes mergeProperties and does the property lookup
in designated protocols lazily.

llvm-svn: 62007
2009-01-09 21:04:52 +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
Douglas Gregor ffca3a21f1 Provide a new kind of iterator, the specific_decl_iterator, that
filters the decls seen by decl_iterator with two criteria: the dynamic
type of the declaration and a run-time predicate described by a member
function. This simplifies EnumDecl, RecordDecl, and ObjCContainerDecl
considerably. It has no measurable performance impact.

llvm-svn: 61994
2009-01-09 17:18:27 +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
Daniel Dunbar f4c6616d9d Fix crash on null deference when searching for readwrite properties in
categories.
 - Also, simplify nesting via early return.

llvm-svn: 61968
2009-01-09 01:04:21 +00:00
Douglas Gregor c25d7a7fe0 Addressed the issue in <rdar://problem/6479085>, where we failed to
rewrite @class declarations that showed up within linkage
specifications because those @class declarations never made it any
place where the rewriter could find them.

Moved all of the ObjC*Decl nodes over to ScopedDecls, so that they can
live in the appropriate top-level or transparent DeclContext near the
top level, e.g., TranslationUnitDecl or LinkageSpecDecl. Objective-C
declarations now show up in a traversal of the declarations in a
DeclContext (they didn't before!). This way, the rewriter finds all
Objective-C declarations within linkage specifications.

llvm-svn: 61966
2009-01-09 00:49:46 +00:00
Douglas Gregor e4b414c781 Revert my previous, failed attempt to pretty-print anonymous struct/union accesses well. Added a FIXME so we know to revisit this later
llvm-svn: 61951
2009-01-08 22:45:41 +00:00
Ted Kremenek 0667123ba1 Fix ObjCInterfaceDecl::Destroy and ObjCProtocolDecl::Destroy to iterate and destroy all contained ObjCMethodDecls in one sweep. This fixes a use-after-free error found by valgrind.
llvm-svn: 61943
2009-01-08 20:49:27 +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 e538c5f3ae Removed ObjCContainerDecl::getPropertyMethods()...doesn't belong in the AST.
Moved logic to Sema::ProcessPropertyDecl().

llvm-svn: 61936
2009-01-08 20:15:03 +00:00
Steve Naroff 11b387fee0 Remove redundant method context (now that ObjCMethodDecl isa ScopedDecl).
Convert clients to use the standard getDeclContext() API.

Doug, thanks for the review!

llvm-svn: 61935
2009-01-08 19:41:02 +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 f09c2dc8e0 Fix printing of member references to avoid displaying implicitly-generated member references, e.g., for anonymous struct/unions or implicit 'this' in member functions
llvm-svn: 61885
2009-01-07 21:26:07 +00:00
Douglas Gregor f4d332797b Finished semantic analysis of anonymous unions in C++.
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
2009-01-07 19:46:03 +00:00
Steve Naroff 639de9ccd9 ObjC AST cleanups/simplifications (phase 1).
Add ObjCContainerDecl class and have ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl inherit from it.

llvm-svn: 61866
2009-01-07 17:57:40 +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
Douglas Gregor c7acfdfe9a Add QualifiedDeclRefExpr, which retains additional source-location
information for declarations that were referenced via a qualified-id,
e.g., N::C::value. We keep track of the location of the start of the
nested-name-specifier. Note that the difference between
QualifiedDeclRefExpr and DeclRefExpr does have an effect on the
semantics of function calls in two ways:
  1) The use of a qualified-id instead of an unqualified-id suppresses
     argument-dependent lookup
  2) If the name refers to a virtual function, the qualified-id
  version will call the function determined statically while the
  unqualified-id version will call the function determined dynamically
  (by looking up the appropriate function in the vtable).

Neither of these features is implemented yet, but we do print out
qualified names for QualifiedDeclRefExprs as part of the AST printing.

llvm-svn: 61789
2009-01-06 05:10:23 +00:00
Daniel Dunbar 8f8e40a324 Back out code for handling VectorType's in getFloatingRank.
llvm-svn: 61764
2009-01-05 22:44:35 +00:00
Daniel Dunbar a1f3441d50 Implement getFloatingRank() for extended vectors.
- I'm not sure this is appropriate, but it seems reasonable to be
   able to call getFloatingRank on anything which isFloatingType().

llvm-svn: 61758
2009-01-05 22:14:37 +00:00
Sebastian Redl baad4e765f PODness and Type Traits
Make C++ classes track the POD property (C++ [class]p4)
Track the existence of a copy assignment operator.
Implicitly declare the copy assignment operator if none is provided.
Implement most of the parsing job for the G++ type traits extension.
Fully implement the low-hanging fruit of the type traits:
__is_pod: Whether a type is a POD.
__is_class: Whether a type is a (non-union) class.
__is_union: Whether a type is a union.
__is_enum: Whether a type is an enum.
__is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1).

llvm-svn: 61746
2009-01-05 20:52:13 +00:00
Douglas Gregor 07665a69e8 Introduce support for "transparent" DeclContexts, which are
DeclContexts whose members are visible from enclosing DeclContexts up
to (and including) the innermost enclosing non-transparent
DeclContexts. Transparent DeclContexts unify the mechanism to be used
for various language features, including C enumerations, anonymous
unions, C++0x inline namespaces, and C++ linkage
specifications. Please refer to the documentation in the Clang
internals manual for more information.

Only enumerations and linkage specifications currently use transparent
DeclContexts.

Still to do: use transparent DeclContexts to implement anonymous
unions and GCC's anonymous structs extension, and, later, the C++0x
features. We also need to tighten up the DeclContext/ScopedDecl link
to ensure that every ScopedDecl is in a single DeclContext, which
will ensure that we can then enforce ownership and reduce the memory
footprint of DeclContext.

llvm-svn: 61735
2009-01-05 19:45:36 +00:00
Douglas Gregor cfc7022a7b Fix an uninitialized-variable warning
llvm-svn: 61700
2009-01-05 17:18:30 +00:00
Sebastian Redl 068b13d62a Fix try statement deserialization.
llvm-svn: 61421
2008-12-24 13:02:38 +00:00
Zhongxing Xu be2d5535f6 Add serialization support for TypeOfType.
llvm-svn: 61417
2008-12-24 07:22:26 +00:00
Zhongxing Xu 329f204b1b Add serialization support for TypeOfExpr.
llvm-svn: 61416
2008-12-24 06:36:01 +00:00
Douglas Gregor b9bd8a994c Keep track of template arguments when we parse them. Right now, we don't actually do anything with the template arguments, but they'll be used to create template declarations
llvm-svn: 61413
2008-12-24 02:52:09 +00:00
Douglas Gregor 583540360c Correct the order in which we cope with end-of-class-definition
semantics and improve our handling of default arguments. Specifically,
we follow this order:

  - As soon as the see the '}' in the class definition, the class is
  complete and we add any implicit declarations (default constructor,
  copy constructor, etc.) to the class.
  - If there are any default function arguments, parse them
  - If there were any inline member function definitions, parse them

As part of this change, we now keep track of the the fact that we've
seen unparsed default function arguments within the AST. See the new
ParmVarDecl::hasUnparsedDefaultArg member. This allows us to properly
cope with calls inside default function arguments to other functions
where we're making use of the default arguments.

Made some C++ error messages regarding failed initializations more
specific. 

llvm-svn: 61406
2008-12-24 00:01:03 +00:00
Douglas Gregor 74a3444394 When determining whether a class type has a const copy constructor, be
sure to look at all of the results returned by name lookup. Fixes
<rdar://problem/6465262>

llvm-svn: 61388
2008-12-23 21:31:30 +00:00
Fariborz Jahanian 4ecf1e94db Last patch, for now, to privde ObjC's encoding of types.
We now pass all gcc's encoding compatibility tests.

llvm-svn: 61387
2008-12-23 21:30:15 +00:00
Douglas Gregor 8b9ccca5e5 Don't push OverloadedFunctionDecls onto the chain of declarations
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
2008-12-23 21:05:05 +00:00
Fariborz Jahanian 0f66a6c926 Lot more encoding work. We are closing the gap to
gcc compatibilty in all aspects of encoding now.

llvm-svn: 61383
2008-12-23 19:56:47 +00:00
Douglas Gregor 55297ac499 Don't explicitly represent OverloadedFunctionDecls within
DeclContext. Instead, just keep the list of currently-active
declarations and only build the OverloadedFunctionDecl when we
absolutely need it.

This is a half-step toward eliminating the need to explicitly build
OverloadedFunctionDecls that store sets of overloaded
functions. This was suggested by Argiris a while back, and it's a good
thing for several reasons: first, it eliminates the messy logic that
currently tries to keep the OverloadedFunctionDecl in sync with the 
declarations that are being added. Second, it will (eventually)
eliminate the need to allocate memory for overload sets, which could
help performance. Finally, it helps set us up for when name lookup can
return multiple (possibly ambiguous) results, as can happen with
lookup of class members in C++.

Next steps: make the IdentifierResolver store overloads as separate
entries in its list rather than replacing them with an
OverloadedFunctionDecl now, then see how far we can go toward
eliminating OverloadedFunctionDecl entirely.

llvm-svn: 61357
2008-12-23 00:26:44 +00:00
Fariborz Jahanian daef00bca6 More encoding support; in this case, encoding of
outer-most const of pointer types.

llvm-svn: 61355
2008-12-22 23:22:27 +00:00
Sebastian Redl 9b244a8797 Full AST support and better Sema support for C++ try-catch.
llvm-svn: 61346
2008-12-22 21:35:02 +00:00
Fariborz Jahanian 8b2d1294db Fixed a bug showed up the meta-data for protocol
instance methods by building print-class-info.m,
whose output is now identical to what gcc puts out.

llvm-svn: 61339
2008-12-22 20:41:58 +00:00
Sebastian Redl 54c04d4700 Partial AST and Sema support for C++ try-catch.
llvm-svn: 61337
2008-12-22 19:15:10 +00:00
Douglas Gregor 97fd6e24c4 Add support for calls to overloaded member functions. Things to note:
- Overloading has to cope with having both static and non-static
    member functions in the overload set.
  - The call may or may not have an implicit object argument,
    depending on the syntax (x.f() vs. f()) and the context (static
    vs. non-static member function).
  - We now generate MemberExprs for implicit member access expression.
  - We now cope with mutable whenever we're building MemberExprs.

llvm-svn: 61329
2008-12-22 05:46:06 +00:00
Anders Carlsson 39def3adc8 Add codegen support for __null
llvm-svn: 61314
2008-12-21 22:39:40 +00:00
Zhongxing Xu 7b9c57083b Correct comments.
llvm-svn: 61311
2008-12-21 13:00:52 +00:00
Zhongxing Xu d93e03b25f fix 80-col violation.
llvm-svn: 61306
2008-12-21 04:46:06 +00:00
Anders Carlsson e0808df4a5 Add ASTContext::getBaseElementType and use it in CodeGenFunction::EmitArraySubscriptExpr.
llvm-svn: 61303
2008-12-21 03:44:36 +00:00
Anders Carlsson 8e0ba05074 Did not mean to commit this.
llvm-svn: 61296
2008-12-21 00:16:32 +00:00
Anders Carlsson 3d312f8788 Handle VLA indexing
llvm-svn: 61295
2008-12-21 00:11:23 +00:00