Commit Graph

106 Commits

Author SHA1 Message Date
Chris Lattner 1cbaacc4a0 Migrate some stuff from NamedDecl::getName() to
NamedDecl::getNameAsString() to make it more explicit.

llvm-svn: 59937
2008-11-24 04:00:27 +00:00
Chris Lattner 9b1f2792ba simplify this code.
llvm-svn: 59935
2008-11-24 03:52:59 +00:00
Chris Lattner e4b95698df Rename Selector::getName() to Selector::getAsString(), and add
a new NamedDecl::getAsString() method.

Change uses of Selector::getName() to just pass in a Selector 
where possible (e.g. to diagnostics) instead of going through
an std::string.

This also adds new formatters for objcinstance and objcclass
as described in the dox.

llvm-svn: 59933
2008-11-24 03:33:13 +00:00
Chris Lattner 230fc3d17d formatting
llvm-svn: 59599
2008-11-19 07:24:05 +00:00
Douglas Gregor 77324f3854 Introduction the DeclarationName class, as a single, general method of
representing the names of declarations in the C family of
languages. DeclarationName is used in NamedDecl to store the name of
the declaration (naturally), and ObjCMethodDecl is now a NamedDecl.

llvm-svn: 59441
2008-11-17 14:58:09 +00:00
Daniel Dunbar e27d7b5530 Fix Release-Asserts warning.
llvm-svn: 59013
2008-11-11 01:16:00 +00:00
Daniel Dunbar bbc0af7e37 Support getTypeInfo, getTypeAlign, getTypeSize on const Type*s.
- Size/align are not effected by CVR qualifiers.

Support getCanonicalType: const Type* -> const Type*.

llvm-svn: 58891
2008-11-08 05:48:37 +00:00
Douglas Gregor ab13857072 Eliminate header dependency ASTContext -> TargetInfo
llvm-svn: 58613
2008-11-03 15:57:00 +00:00
Douglas Gregor 8af6e6d415 Connect ASTContext to TargetInfo when determining the size_t, ptrdiff_t, and wchar_t types. Fixes recent breakage on Linux.
llvm-svn: 58609
2008-11-03 14:12:49 +00:00
Argyrios Kyrtzidis 22a3735398 Don't give a default argument to ASTContext::getFunctionType for the TypeQuals parameter, it causes subtle bugs where TypeQuals, while necessary, are omitted from the call.
-Remove the default argument.
-Update all call sites of ASTContext::getFunctionType.

llvm-svn: 58187
2008-10-26 16:43:14 +00:00
Argyrios Kyrtzidis 22c40fa285 -Add support for cv-qualifiers after function declarators.
-Add withConst/withVolatile/withRestrict methods to QualType class, that return the QualType plus the respective qualifier.

llvm-svn: 58120
2008-10-24 21:46:40 +00:00
Steve Naroff 5cfa5af630 Fix <rdar://problem/6257645> clang static analyzer crashes when encountering blocks as objects
ASTContext::isObjCObjectPointerType() needs to consider blocks as objects.

Note: My previous commit was done in the test directory...as a result, this commit was necessary.
llvm-svn: 57914
2008-10-21 18:24:04 +00:00
Douglas Gregor 5251f1b283 Preliminary support for function overloading
llvm-svn: 57909
2008-10-21 16:13:35 +00:00
Steve Naroff ea54d9ef72 Sema::CheckCompareOperands() and ASTContext::mergeTypes(): Change handling of ObjC qualified id types to be consistent with gcc. This changes a handful of test case errors into warnings (diff will tell you which cases have changed).
llvm-svn: 57841
2008-10-20 18:19:10 +00:00
Daniel Dunbar fc1066db81 Remove unneeded EncodingRecordTypes argument to getObjCEncodingForType.
llvm-svn: 57716
2008-10-17 20:21:44 +00:00
Daniel Dunbar ff3c6747ef More Obj-C type encoding improvements.
- Encode unions and bit-fields correctly.
 - Accept option to name record fields (used for NeXT runtime).

llvm-svn: 57685
2008-10-17 16:17:37 +00:00
Daniel Dunbar 3cd9a29c64 Fix bug in Obj-C type encoding for structures.
- Mechanism for detecting if a structure should be expanded wasn't
   reliable. Simplified by just keeping track of what we should be
   expanding.

 - This fixes a bug in using NSInvocation to invoke a method which
   returned a structure, which in used by Key Value Observing, which
   in the end, caused a miscompile in poor little Sketch.

llvm-svn: 57675
2008-10-17 07:30:50 +00:00
Daniel Dunbar 40cac777b9 Anonymous structures print as '?=' in Obj-C type encoding.
llvm-svn: 57674
2008-10-17 06:22:57 +00:00
Argyrios Kyrtzidis 89656d2298 Using dyn_cast_or_null here is redundant, use dyn_cast instead.
llvm-svn: 57642
2008-10-16 16:50:47 +00:00
Daniel Dunbar 4290d46bd4 Implement #pragma pack use in structure packing. The general approach
is to encode the state of the #pragma pack stack as an attribute when
the structure is declared. 

 - Extend PackedAttr to take an alignment (in bits), and reuse for
   both __attribute__((packed)) (which takes no argument, instead
   packing tightly (to "minimize the memory required") and for #pragma
   pack (which allows specification of the maximum alignment in
   bytes). __attribute__((packed)) is just encoded as Alignment=1.

   This conflates two related but different mechanisms, but it didn't
   seem worth another attribute.

 - I have attempted to follow the MSVC semantics as opposed to the gcc
   ones, since if I understand correctly #pragma pack originated with
   MSVC. The semantics are generally equivalent except when the stack
   is altered during the definition of a structure; its not clear if
   anyone does this in practice. See testcase if curious.

llvm-svn: 57623
2008-10-16 02:34:03 +00:00
Chris Lattner e05f534628 silence a bunch of warnings in a release-assert build.
llvm-svn: 57390
2008-10-12 00:26:57 +00:00
Chris Lattner 465fa32cd5 Wrap long lines and other minor cleanups, no functionality change.
llvm-svn: 57119
2008-10-05 17:34:18 +00:00
Daniel Dunbar 4d601119c3 Pass postfix attributes to ActOnFields (mismarked a file).
llvm-svn: 56993
2008-10-03 02:05:12 +00:00
Daniel Dunbar 15619c7e4b Pass postfix attributes to ActOnFields.
llvm-svn: 56992
2008-10-03 02:03:53 +00:00
Daniel Dunbar 2c793a2ecd Add # of block pointer types to -print-stats.
llvm-svn: 56638
2008-09-26 03:23:00 +00:00
Steve Naroff 921a45c6d6 Extend ASTContext::getTypeInfo() and ASTContext::getObjCEncodingForType() for BlockTypes.
This fixes <rdar://problem/6240616> clang: Assertion failed when using typedef and Blocks.

llvm-svn: 56554
2008-09-24 15:05:44 +00:00
Steve Naroff 44cfcb6fb1 Tweak implementation for allowing ObjC builtin type redefinitions.
- Replace string comparisons with pre-defined idents.
- Avoid calling isBuiltinObjCType() to avoid two checks. 
- Remove isBuiltinObjCType(), since it was only used in Sema::MergeTypeDefDecl().
- Have Sema::MergeTypeDefDecl() set the new type.

This is a moidified version of an patch by David Chisnall.

llvm-svn: 55990
2008-09-09 14:32:20 +00:00
Steve Naroff 58d5ea7ac9 Simplify typesAreBlockCompatible().
llvm-svn: 55989
2008-09-09 13:47:19 +00:00
Steve Naroff 8de9c3affe More type checking for blocks. Still incomplete (will hopefully finish up this weekend).
llvm-svn: 55862
2008-09-05 22:11:13 +00:00
Ted Kremenek 2147570258 Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).

The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.

- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
  addition of DeclGroups.

Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
  referenced by the AST.  For example:

    typedef struct { ... } x;  

  The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
  refer to it.  This will be solved with DeclGroups.
  
- This patch also (temporarily) breaks CodeGen.  More below.

High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it.  When
  a struct/union/class is first referenced, a RecordType and RecordDecl are
  created for it, and the RecordType refers to that RecordDecl.  Later, if
  a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
  updated to point to the RecordDecl that defines the struct/union/class.

- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
  TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
  enum/struct/class/union. This is useful from going from a RecordDecl* that
  defines a forward declaration to the RecordDecl* that provides the actual
  definition. Note that this also works for EnumDecls, except that in this case
  there is no distinction between forward declarations and definitions (yet).

- Clients should no longer assume that 'isDefinition()' returns true from a
  RecordDecl if the corresponding struct/union/class has been defined.
  isDefinition() only returns true if a particular RecordDecl is the defining
  Decl. Use 'getDefinition()' instead to determine if a struct has been defined.

- The main changes to Sema happen in ActOnTag. To make the changes more
  incremental, I split off the processing of enums and structs et al into two
  code paths. Enums use the original code path (which is in ActOnTag) and
  structs use the ActOnTagStruct. Eventually the two code paths will be merged,
  but the idea was to preserve the original logic both for comparison and not to
  change the logic for both enums and structs all at once.

- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
  that correspond to the same type simply have a pointer to that type. If we
  need to figure out what are all the RecordDecls for a given type we can build
  a backmap.

- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
  changes to RecordDecl. For some reason 'svn' marks the entire file as changed.

Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
  RecordType*. This was true before because we only created one RecordDecl* for
  a given RecordType*, but it is no longer true. I believe this shouldn't be too
  hard to change, but the patch was big enough as it is.
  
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).  

llvm-svn: 55839
2008-09-05 17:16:31 +00:00
Ted Kremenek 47923c7e59 Remove "NextDecl" from RecordDecl. This change touches many files that where RecordDecl or CXXRecordDecl was constructed, always with an argument of 'NULL' for the previous declaration.
The motivation behind this change is that chaining the RecordDecls is simply unnecessary.  Once we create multiple RecordDecls for the same struct/union/class, clients that care about all the declarations of the same struct can build a back map by seeing which Decls refer to the same RecordType.

llvm-svn: 55821
2008-09-05 01:34:33 +00:00
Steve Naroff 991e99d980 Fix a handful of typos (closure->block) to avoid confusion.
llvm-svn: 55768
2008-09-04 15:31:07 +00:00
Steve Naroff 081c7422b2 Add type checking for blocks.
llvm-svn: 55767
2008-09-04 15:10:53 +00:00
Anders Carlsson d89ba7d058 Add code to create the fast enumeration state type
llvm-svn: 55572
2008-08-30 19:34:46 +00:00
Steve Naroff 0ac012835f Add parser/action support for block literal expressions.
Parser support for blocks is almost complete...just need to add support for the __block() storage class qualifier.

llvm-svn: 55495
2008-08-28 19:20:44 +00:00
Daniel Dunbar 4932b36f54 NeXT: Emit mostly-correct property type encoding.
- Added ASTContext::getObjCEncodingForPropertyDecl.

llvm-svn: 55461
2008-08-28 04:38:10 +00:00
Steve Naroff ec33ed9ced First wave of changes to support "blocks" (an extension to C).
This commit adds the declaration syntax (and associated type).

llvm-svn: 55417
2008-08-27 16:04:49 +00:00
Eli Friedman 3e62c21c49 Fix some issues with array type merging. (No visible difference,
because nothing uses the merged types yet.)

llvm-svn: 55161
2008-08-22 01:48:21 +00:00
Eli Friedman 777a6bb582 Minor const cleanup.
llvm-svn: 55160
2008-08-22 00:59:49 +00:00
Eli Friedman 47f7711e4b Rewrite type compatibility testing to do type merging rather than just
testing compatibility.  This is necessary for some constructs, like merging
redeclarations.

Also, there are some ObjC changes to make sure that 
typesAreCompatible(a,b) == typesAreCompatible(b,a).  I don't have any 
ObjC code beyond the testsuite, so please tell me if there are any cases 
where this doesn't behave as expected.

llvm-svn: 55158
2008-08-22 00:56:42 +00:00
Steve Naroff 40471b3ba8 Fix ASTContext::getObjCEncodingForType() to limit the type info for structure bodies (mimics gcc's adhoc rules).
This fixes <rdar://problem/6140902> clang ObjC rewriter: If a class contains a struct ivar with a lot of members, ... 

llvm-svn: 54777
2008-08-14 15:00:38 +00:00
Daniel Dunbar 7da1b82f56 Update some isIntegerConstantExpr uses to use
getIntegerConstantExprValue where appropriate.

llvm-svn: 54771
2008-08-13 23:47:13 +00:00
Daniel Dunbar 56fdb6ae69 More #include cleaning
- Kill unnecessary #includes in .cpp files. This is an automatic
   sweep so some things removed are actually used, but happen to be
   included by a previous header. I tried to get rid of the obvious
   examples and this was the easiest way to trim the #includes in one
   fell swoop.
 - We now return to regularly scheduled development.

llvm-svn: 54632
2008-08-11 06:23:49 +00:00
Daniel Dunbar 221fa94e40 More #include cleaning
- Drop Expr.h,RecordLayout.h from ASTContext.h (for DeclBase.h and
   SourceLocation.h)
 - Move ASTContext constructor into implementation

llvm-svn: 54627
2008-08-11 04:54:23 +00:00
Chris Lattner 572100b648 Fix PR2400 by more graceful handling of invalid decls. Don't try to layout
an invalid struct decl.  Thanks to Martin Doucha for the 
isIncompleteArrayType part of this patch.

llvm-svn: 54592
2008-08-09 21:35:13 +00:00
Argyrios Kyrtzidis cbad725bf4 Change 'Wchar' to 'WChar' casing, for consistency.
No functionality change.

llvm-svn: 54588
2008-08-09 17:20:01 +00:00
Argyrios Kyrtzidis 40e9e4828f Implement support for the 'wchar_t' C++ type.
llvm-svn: 54585
2008-08-09 16:51:54 +00:00
Argyrios Kyrtzidis faf0876cab Add CXXRecordType class.
llvm-svn: 54488
2008-08-07 20:55:28 +00:00
Chris Lattner 7adf076088 Finally fix PR2189. This makes a fairly invasive but important change to
move getAsArrayType into ASTContext instead of being a method on type.
This is required because getAsArrayType(const AT), where AT is a typedef
for "int[10]" needs to return ArrayType(const int, 10).

Fixing this greatly simplifies getArrayDecayedType, which is a good sign.

llvm-svn: 54317
2008-08-04 07:31:14 +00:00
Chris Lattner 6731544be7 convert more code to use ASTContext to get canonical types instead
of doing it directly.  This is required for PR2189.

llvm-svn: 54102
2008-07-26 21:30:36 +00:00