Commit Graph

303 Commits

Author SHA1 Message Date
Douglas Gregor c741fb15a5 Better way to free NestedNameSpecifiers. Thanks, Chris
llvm-svn: 67880
2009-03-27 23:54:10 +00:00
Douglas Gregor 6fcec66525 Perform a very, very ugly song-and-dance number to free the
NestedNameSpecifiers without causing problems for the FoldingSet that
contains them.

llvm-svn: 67877
2009-03-27 23:25:45 +00:00
Douglas Gregor 333489bba3 Initial implementation of parsing, semantic analysis, and template
instantiation for C++ typename-specifiers such as

  typename T::type

The parsing of typename-specifiers is relatively easy thanks to
annotation tokens. When we see the "typename", we parse the
typename-specifier and produce a typename annotation token. There are
only a few places where we need to handle this. We currently parse the
typename-specifier form that terminates in an identifier, but not the
simple-template-id form, e.g.,

  typename T::template apply<U, V>

Parsing of nested-name-specifiers has a similar problem, since at this
point we don't have any representation of a class template
specialization whose template-name is unknown.

Semantic analysis is only partially complete, with some support for
template instantiation that works for simple examples. 

llvm-svn: 67875
2009-03-27 23:10:48 +00:00
Eli Friedman 6ecb5afcd6 Fix test failures caused by reading memory after freeing it. My fix is
rather nasty, but I can't think of a better fix off the top of my head.

llvm-svn: 67867
2009-03-27 20:56:17 +00:00
Douglas Gregor f21eb49a04 Revamp our representation of C++ nested-name-specifiers. We now have a
uniqued representation that should both save some memory and make it
far easier to properly build canonical types for types involving
dependent nested-name-specifiers, e.g., "typename T::Nested::type".

This approach will greatly simplify the representation of
CXXScopeSpec. That'll be next.

llvm-svn: 67799
2009-03-26 23:50:42 +00:00
Eli Friedman 7fa3faa417 Fix code to mark block variables as const to actually work. Fix
isObjCObjectPointerType to work with qualified types.  Adjust test for 
changes.

If the SemaExpr changes are wrong or break existing code, feel free to 
delete the "ExprTy.addConst();" line and revert my changes to 
test/Sema/block-literal.c.

llvm-svn: 67489
2009-03-22 23:00:19 +00:00
Douglas Gregor 5253768ada Introduce a representation for types that we referred to via a
qualified name, e.g., 

  foo::x

so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.

The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
 
  ::foo::bar::x

The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled). 

The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).

Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.

llvm-svn: 67265
2009-03-19 00:18:19 +00:00
Sebastian Redl 0f8b23f71f Almost complete implementation of rvalue references. One bug, and a few unclear areas. Maybe Doug can shed some light on some of the fixmes.
llvm-svn: 67059
2009-03-16 23:22:08 +00:00
Chris Lattner c890aa2802 wire up a new -fno-builtin option, make it control things like simplifylibcalls,
etc and make freestanding imply it.

llvm-svn: 66972
2009-03-13 22:38:49 +00:00
Douglas Gregor c40290e452 Implement template instantiation for ClassTemplateSpecializationTypes,
such as replacing 'T' in vector<T>. There are a few aspects to this:

  - Extend TemplateArgument to allow arbitrary expressions (an
    Expr*), and switch ClassTemplateSpecializationType to store
    TemplateArguments rather than it's own type-or-expression
    representation.

  - ClassTemplateSpecializationType can now store dependent types. In
    that case, the canonical type is another
    ClassTemplateSpecializationType (with default template arguments
    expanded) rather than a declaration (we don't build Decls for
    dependent types).

  - Split ActOnClassTemplateId into ActOnClassTemplateId (called from
    the parser) and CheckClassTemplateId (called from
    ActOnClassTemplateId and InstantiateType). They're smart enough to
    handle dependent types, now.

llvm-svn: 66509
2009-03-09 23:48:35 +00:00
Fariborz Jahanian 631c5818ab Moved CollectObjCIvars to more commonly available place
for future use.

llvm-svn: 66184
2009-03-05 20:08:48 +00:00
Steve Naroff 114aecb26b Fix <rdar://problem/6619539> incompatible pointer types sending 'XCElementSpacer *', expected 'XCElement *' (not handling protocol signatures correctly?).
- Reworked ASTContext::canAssignObjCInterfaces().
- Added ObjCProtocolDecl::lookupProtocolNamed().

llvm-svn: 65773
2009-03-01 16:12:44 +00:00
Douglas Gregor 89ee6822d8 Eliminate CXXRecordType
llvm-svn: 65671
2009-02-28 01:32:25 +00:00
Eli Friedman cad9638bd9 Fix enumeration in switch warnings, plus misc comment changes. No
behavior change.

llvm-svn: 65658
2009-02-27 23:04:43 +00:00
Mike Stump 5b9a3d54b6 Silence warnings.
llvm-svn: 65644
2009-02-27 18:32:39 +00:00
Douglas Gregor deaad8cc34 Create a new TypeNodes.def file that enumerates all of the types,
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
2009-02-26 23:50:07 +00:00
Chris Lattner 007cb026c9 make ASTContext::WCharTy a bit more sensical. In C++, it is a disctint type,
but in C99 it is just another int type.

llvm-svn: 65590
2009-02-26 23:43:47 +00:00
Chris Lattner 7ec0bb6bc0 ok, not as broken as I thought, just confusing. This allows
initialization of wchar_t arrays with wide strings, and generalizes
wchar_size.c to work on all targets.

llvm-svn: 65586
2009-02-26 23:36:02 +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
Steve Naroff 91362dd011 Revert http://llvm.org/viewvc/llvm-project?view=rev&revision=65244.
Remove support for "Class<P>". Will be making this an error.

llvm-svn: 65332
2009-02-23 18:36:16 +00:00
Eli Friedman f837924faf Enhance Evaluate to handle ObjC qualified id and class types; as far as
I know, these follow the exact same rules as pointers, so I just made 
them use the same codepath.  Someone more familiar with ObjC should 
double-check this, though.

llvm-svn: 65261
2009-02-22 04:02:33 +00:00
Eli Friedman 19a546c15b Improvements to ASTContext::getDeclAlignInBytes; fixes the testcase in
PR3254 and part of PR3433.

The isICE changes are necessary to keep the computed results 
consistent with Evaluate.

llvm-svn: 65258
2009-02-22 02:56:25 +00:00
Anders Carlsson d05f44b5ca Correctly encode incomplete and variable length arrays. Fixes PR3639.
llvm-svn: 65255
2009-02-22 01:38:57 +00:00
Steve Naroff 8487e3e541 More work to integrate newly added ObjCQualifiedClassType into the type system.
This is necessary 'plumbing' to fix <rdar://problem/6497631> Message lookup is sometimes different than gcc's.

llvm-svn: 65248
2009-02-21 21:17:01 +00:00
Steve Naroff 670e72ddc7 Add support for GCC ObjC extension "Class<protocol>". Sigh.
Found while researching <rdar://problem/6497631> Message lookup is sometimes different than gcc's.

Will never be seen in user code. Needed to pass dejagnu testsuite.

llvm-svn: 65244
2009-02-21 20:17:11 +00:00
Fariborz Jahanian ccfd554024 Fixed an ICE in meta-data generation of __weak/__strong ivars.
llvm-svn: 65235
2009-02-21 18:23:24 +00:00
Cedric Venet 4fc88b779e Fix build on windows.
Should clang have a config.h or should we use the config.h of llvm or using the preprocessor is OK?  I did a quick fix here, but having a guideline on how to handle non portable function would be great (or ask ted to stop breaking the windows build :)).

llvm-svn: 65233
2009-02-21 17:14:49 +00:00
Steve Naroff 7a7814c32b This fixes <rdar://problem/6497650> More type mismatches issues with clang.
Move two key ObjC typechecks from Sema::CheckPointerTypesForAssignment() to ASTContext::mergeTypes().

This allows us to take advantage of the recursion in ASTContext::mergeTypes(), removing some bogus warnings.

This test case I've added includes an example where we still warn (and GCC doesn't). Need to talk with folks and decide what to do. At this point, the major bogosities should be fixed.

llvm-svn: 65231
2009-02-21 16:18:07 +00:00
Chris Lattner a499715c83 remove some more methods from objc decls, using the iterator
interfaces more consistently.

llvm-svn: 65138
2009-02-20 18:43:26 +00:00
Fariborz Jahanian 0f466c746f More objc's gc ir-gen stuff.
llvm-svn: 65077
2009-02-19 23:36:06 +00:00
Chris Lattner 780b46fd50 Fix PR3619 by properly considering size modifiers and type quals when
uniquing array types.

llvm-svn: 65046
2009-02-19 17:31:02 +00:00
Chris Lattner d60183d29f fix some subtle bugs handling the mix of cvr qualifiers, addr spaces,
and gc attrs.  Add an assert to check that we never 
get ExtQualType(ExtQualType(T)).

llvm-svn: 64970
2009-02-18 22:53:11 +00:00
Fariborz Jahanian 9620769901 Some refactoring and simplificaiotn of objc's gc
ir gen.

llvm-svn: 64954
2009-02-18 21:49:28 +00:00
Daniel Dunbar b1c22fe9b7 Add Type::isSpecificBuiltinType as a shortcut.
llvm-svn: 64946
2009-02-18 19:59:32 +00:00
Fariborz Jahanian e27e934d45 Representation of objc gc's attribute using ExtQualType.
Note that one test attr-objc-gc.m fails. I will fix this
after removing these attributes from the Decl nodes.

llvm-svn: 64889
2009-02-18 05:09:49 +00:00
Daniel Dunbar 43a5d9e409 Eek! getDeclAlign sometimes returned alignment in bits.
- Renamed to getDeclAlignInBytes since most other query functions
   work in bits.

 - Fun to track down as isIntegerConstantExpr was getting it right,
   but Evaluate() was getting it wrong. Maybe we should assert they
   compute the same thing when they succeed?

llvm-svn: 64828
2009-02-17 22:16:19 +00:00
Fariborz Jahanian 37b43cd89c Simplified ExtQualType per Chris's feedback.
llvm-svn: 64820
2009-02-17 21:45:36 +00:00
Fariborz Jahanian 19c44508a1 Added support for objc's gc attribute in ExtQualType.
llvm-svn: 64800
2009-02-17 20:16:45 +00:00
Fariborz Jahanian ece8582ca2 Renamed ASQualType to ExtQualType to reflect its more
general use; as for, objc2's gc type attributes. No
change in functionality.

llvm-svn: 64778
2009-02-17 18:27:45 +00:00
Fariborz Jahanian f95039cd58 Use isa<...> instead of dyn_cast<...> where result is not needed.
llvm-svn: 64680
2009-02-16 22:09:26 +00:00
Fariborz Jahanian 1dd6094517 Fixes a bug in property type encoding.
llvm-svn: 64672
2009-02-16 21:41:04 +00:00
Chris Lattner 641f1eab77 fix build on systems where uint64_t != unsigned long long
llvm-svn: 64605
2009-02-15 21:20:13 +00:00
Douglas Gregor 69c7951c8e Add -ffreestanding to suppress the implicit declaration of library builtins like printf and malloc. Fixes PR3586
llvm-svn: 64566
2009-02-14 20:49:29 +00:00
Fariborz Jahanian 99bed6fd21 Fixed a problem caused by foreward @class use
which consequently caused a Seg fault. during meta-data
generation. It also addresses an issue related to
late binding of newly synthesize ivars (when we support it).

llvm-svn: 64563
2009-02-14 20:13:28 +00:00
Eli Friedman 1efaaeaa69 Initial implementation of arbitrary fixed-width integer types.
Currently only used for 128-bit integers.

Note that we can't use the fixed-width integer types for other integer 
modes without other changes because glibc headers redefines (u)int*_t 
and friends using the mode attribute.  For example, this means that uint64_t
has to be compatible with unsigned __attribute((mode(DI))), and 
uint64_t is currently defined to long long.  And I have a feeling we'll 
run into issues if we try to define uint64_t as something which isn't 
either long or long long.

This doesn't get the alignment right in most cases, including 
the 128-bit integer case; I'll file a PR shortly.  The gist of the issue 
is that the targets don't really expose the information necessary to 
figure out the alignment outside of the target description, so there's a 
non-trivial amount of work involved in getting it working right.  That 
said, the alignment used is conservative, so the only issue with the 
current implementation is ABI compatibility.

This makes it trivial to add some sort of "bitwidth" attribute to make 
arbitrary-width integers; I'll do that in a followup.

We could also use this for stuff like the following for compatibility 
with gcc, but I have a feeling it would be a better idea for clang to be 
consistent between C and C++ modes rather than follow gcc's example for 
C mode.
struct {unsigned long long x : 33;} x;
unsigned long long a(void) {return x.x+1;}

llvm-svn: 64434
2009-02-13 02:31:07 +00:00
Steve Naroff b76051534c Several cleanups:
- rename isObjCIdType/isObjCClassType -> isObjCIdStructType/isObjCClassStructType. The previous name didn't do what you would expect.
- add back isObjCIdType/isObjCClassType to do what you would expect. Not currently used, however many of the isObjCIdStructType/isObjCClassStructType clients could be converted over time.
- move static Sema function areComparableObjCInterfaces to ASTContext (renamed to areComparableObjCPointerTypes, since it now operates on pointer types).

llvm-svn: 64385
2009-02-12 17:52:19 +00:00
Fariborz Jahanian 77b6b5d6d8 Last @encode'ing fix for objc2's nonfragile abi.
All relevant dejagnu enocding tests pass in this mode.

llvm-svn: 64341
2009-02-11 23:59:18 +00:00
Fariborz Jahanian 1f0a9ebf72 Patch to fix encoding in 64bit abi. With this patch
all but one dejagnu encoding tests for darwin
pass in nonfragile abi mode.

llvm-svn: 64334
2009-02-11 22:31:45 +00:00
Douglas Gregor 8bf4205c70 Start processing template-ids as types when the template-name refers
to a class template. For example, the template-id 'vector<int>' now
has a nice, sugary type in the type system. What we can do now:

  - Parse template-ids like 'vector<int>' (where 'vector' names a
    class template) and form proper types for them in the type system.
  - Parse icky template-ids like 'A<5>' and 'A<(5 > 0)>' properly,
    using (sadly) a bool in the parser to tell it whether '>' should
    be treated as an operator or not.

This is a baby-step, with major problems and limitations:
  - There are currently two ways that we handle template arguments
  (whether they are types or expressions). These will be merged, and,
  most likely, TemplateArg will disappear.
  - We don't have any notion of the declaration of class template
  specializations or of template instantiations, so all template-ids
  are fancy names for 'int' :)

llvm-svn: 64153
2009-02-09 18:46:07 +00:00
Douglas Gregor eff93e0401 Improve the representation of template type parameters. We now
canonicalize by template parameter depth, index, and name, and the
unnamed version of a template parameter serves as the canonical.

TemplateTypeParmDecl no longer needs to inherit from
TemplateParmPosition, since depth and index information is present
within the type.

llvm-svn: 63899
2009-02-05 23:33:38 +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
Steve Naroff 49140cb544 Change the ObjC type encoding for block pointer types to "@?" (for consistency with GCC).
This fixes <rdar://problem/6538564> clang ObjC rewriter: Wrong encoding emitted for methods with Block parameters.

llvm-svn: 63534
2009-02-02 18:24:29 +00:00
Daniel Dunbar 804c0441c2 Handle complex types in ASTContext::mergeTypes
llvm-svn: 63238
2009-01-28 21:22:12 +00:00
Steve Naroff 99c0cdf899 Finish making AST BumpPtrAllocation runtime configurable (based on -disable-free).
snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m
0.179u 0.051s 0:00.23 95.6%	0+0k 0+0io 0pf+0w
snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m -disable-free
0.169u 0.052s 0:00.22 95.4%	0+0k 0+0io 0pf+0w

llvm-svn: 63153
2009-01-27 23:20:32 +00:00
Steve Naroff 096bab711e Convert types over to placement new() that takes an ASTContext.
Also changed FunctionTypeProto to be allocated with 8-byte alignment (noticed by Doug). I couldn't think of any reason to allocate on 16-byte boundaries. If anyone remembers why we were doing this, let me know!

llvm-svn: 63137
2009-01-27 22:08:43 +00:00
Fariborz Jahanian 7ec8851c89 Fixed a typo in getPreferredTypeAlign method.
llvm-svn: 63116
2009-01-27 18:55:00 +00:00
Chris Lattner a3402cd524 add a new "getPreferredTypeAlign" method to return the preferred alignment
of a type.  The implementation is currently something of a hack, but is 
sufficient for now and allows clients to be built on it.

llvm-svn: 63108
2009-01-27 18:08:34 +00:00
Sebastian Redl c6d52f5dfb Make tentative parsing of pointer-to-member decls work, and fix other stuff pointed out by Doug.
llvm-svn: 62944
2009-01-24 23:29:36 +00:00
Chris Lattner 6806131c6b add initial support for the gcc "alignof(decl) is the alignment of the decl
not the type" semantics.  This can definitely be improved, but is better than
what we had.

llvm-svn: 62939
2009-01-24 21:53:27 +00:00
Sebastian Redl 9ed6efdd75 Add support for declaring pointers to members.
Add serialization support for ReferenceType.

llvm-svn: 62934
2009-01-24 21:16:55 +00:00
Douglas Gregor 82c1fe1cfc Use the ASTContext's allocator for FunctionTypeNoProto and TypeOfExpr
llvm-svn: 62611
2009-01-20 21:02:13 +00:00
Fariborz Jahanian 2f85a6450a Detailed documentation for encoding of properties and a test
case.

llvm-svn: 62607
2009-01-20 20:04:12 +00:00
Fariborz Jahanian 218c630171 Improving on encoding of objective-c's property types. More to come.
llvm-svn: 62601
2009-01-20 19:14:18 +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
Steve Naroff d21d7226b1 Make sure all types are allocated with 8-byte alignment.
The QualType smart pointer assumes we have 3 flag bits available.

llvm-svn: 62540
2009-01-19 22:45:10 +00:00
Ted Kremenek 721e239f2b Allocate Types using ASTContext's 'Allocator' object.
llvm-svn: 62530
2009-01-19 21:31:22 +00:00
Nate Begeman b699c9bf57 Vector codegen improvements
llvm-svn: 62458
2009-01-18 06:42:49 +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
Fariborz Jahanian 1778f4bf6d Don't ICE on user redeclaration of objc's built-in types.
Issue diagnostics instead if types do not match.

llvm-svn: 62349
2009-01-16 19:58:32 +00:00
Chris Lattner 3c91971b33 rename "virtual location" of a macro to "instantiation location".
llvm-svn: 62315
2009-01-16 07:15:35 +00:00
Fariborz Jahanian 255c0958dd Implemenent objective-c's NSObject attribute as a way of ddeclaraing c-type
objects as an objective-c object.

llvm-svn: 62197
2009-01-13 23:34:40 +00:00
Fariborz Jahanian 5c76772f49 Patch to fix encoding of Enum bitfields in ObjC.
llvm-svn: 62135
2009-01-13 01:18:13 +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 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
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
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
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
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
Anders Carlsson e0808df4a5 Add ASTContext::getBaseElementType and use it in CodeGenFunction::EmitArraySubscriptExpr.
llvm-svn: 61303
2008-12-21 03:44:36 +00:00
Fariborz Jahanian a0befc0a6f Finish up saving original parameter type and
using it in ObjC's method parameter encoding.

llvm-svn: 61293
2008-12-20 23:29:59 +00:00
Fariborz Jahanian 7acf0749d4 Strangely enough, name of ObjC class is not encoded into the
full encoding of the class which has an ivar of pointer to this
class. Its name is encoded in the type for the ivar in the
ivar-list metadata. This patch conforms to the above rule.

llvm-svn: 61282
2008-12-20 19:17:01 +00:00
Fariborz Jahanian 1d35f12e6b More encoding support. This time for
@encode of classes and bitfields.

llvm-svn: 61268
2008-12-19 23:34:38 +00:00
Fariborz Jahanian 781c5c879c Several@encode bug fixes for ObjC.
llvm-svn: 61231
2008-12-19 00:14:49 +00:00
Fariborz Jahanian f8f0c6b1bc Removed a slot in ObjCMemRegExpr used in
code gen which did not belong there.

llvm-svn: 61203
2008-12-18 17:29:46 +00:00
Nuno Lopes e013c7f6c1 fix a few more memory leaks: clean the ASTRecordLayouts, ASTObjCInterfaces and ASTRecordForInterface maps
llvm-svn: 61163
2008-12-17 22:30:25 +00:00
Fariborz Jahanian f327e89dab This patch will build the Records lazily per Steve's comments.
Note that one test duplicate-ivar-check.m will fail because I 
need to re-implement duplicate ivar checking.

llvm-svn: 61154
2008-12-17 21:40:49 +00:00
Douglas Gregor c811d8f055 Create new EnumDecl nodes for redeclarations of enums, linking them
together in the same way that we link RecordDecl/CXXRecordDecl nodes. 

Unify ActOnTag and ActOnTagStruct.

Fixes PR clang/2753.

llvm-svn: 61034
2008-12-15 16:32:14 +00:00
Douglas Gregor 7a4fad1b0b Address some comments on the name lookup/DeclContext patch from Chris
llvm-svn: 60897
2008-12-11 20:41:00 +00:00
Douglas Gregor e029561346 Actually distinguish between RecordDecl::field_iterator and RecordDecl::field_const_iterator, propagating the constness down to the FieldDecls.
llvm-svn: 60883
2008-12-11 17:59:21 +00:00
Douglas Gregor 91f84216f7 Unifies the name-lookup mechanisms used in various parts of the AST
and separates lexical name lookup from qualified name lookup. In
particular:
  * Make DeclContext the central data structure for storing and
    looking up declarations within existing declarations, e.g., members
    of structs/unions/classes, enumerators in C++0x enums, members of
    C++ namespaces, and (later) members of Objective-C
    interfaces/implementations. DeclContext uses a lazily-constructed
    data structure optimized for fast lookup (array for small contexts,
    hash table for larger contexts). 

  * Implement C++ qualified name lookup in terms of lookup into
    DeclContext.

  * Implement C++ unqualified name lookup in terms of
    qualified+unqualified name lookup (since unqualified lookup is not
    purely lexical in C++!)

  * Limit the use of the chains of declarations stored in
    IdentifierInfo to those names declared lexically.

  * Eliminate CXXFieldDecl, collapsing its behavior into
    FieldDecl. (FieldDecl is now a ScopedDecl).

  * Make RecordDecl into a DeclContext and eliminates its
    Members/NumMembers fields (since one can just iterate through the
    DeclContext to get the fields).

llvm-svn: 60878
2008-12-11 16:49:14 +00:00
Steve Naroff c68cfcfd03 The "real" fix for <rdar://problem/6424347> clang on xcode: Assertion failed: (0 && "unexpected type"), function mergeTypes,
Commit r60845 was premature.

llvm-svn: 60852
2008-12-10 22:14:21 +00:00
Douglas Gregor 872ffce257 Some cleanups to the dependent-types commit, as suggested by Sebastian
llvm-svn: 60848
2008-12-10 20:57:37 +00:00
Steve Naroff 13ac125edf Fix <rdar://problem/6424347> clang on xcode: Assertion failed: (0 && "unexpected type"), function mergeTypes,
llvm-svn: 60845
2008-12-10 20:07:25 +00:00
Steve Naroff 68e167df8e Fix <rdar://problem/6418623> Bogus block type compatibility warning.
llvm-svn: 60842
2008-12-10 17:49:55 +00:00
Douglas Gregor 4619e439b6 Introduce basic support for dependent types, type-dependent
expressions, and value-dependent expressions. This permits us to parse
some template definitions.

This is not a complete solution; we're missing type- and
value-dependent computations for most of the expression types, and
we're missing checks for dependent types and type-dependent
expressions throughout Sema.

llvm-svn: 60615
2008-12-05 23:32:09 +00:00
Douglas Gregor 5101c24f60 Representation of template type parameters and non-type template
parameters, with some semantic analysis:
  - Template parameters are introduced into template parameter scope
  - Complain about template parameter shadowing (except in Microsoft mode)

Note that we leak template parameter declarations like crazy, a
problem we'll remedy once we actually create proper declarations for
templates. 

Next up: dependent types and value-dependent/type-dependent
expressions.

llvm-svn: 60597
2008-12-05 18:15:24 +00:00
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
Chris Lattner a075e63bbc fix several problems with the protocol qualified id handling where id was implicit.
First, fix canonical type handling of these, since protocol qualified id's are always
canonical.  Next, enhance SemaType to actually make these when used (instead of int)
allowing them to actually be used when appropriate.  Finally remove a bunch of logic
relating to the mishandling of canonical types with protocol-qual id's.  This fixes
rdar://5986251

llvm-svn: 54083
2008-07-26 00:46:50 +00:00
Ted Kremenek 77c51b2aa3 Move isObjCObjectPointerType() from Sema to ASTContext.
llvm-svn: 53998
2008-07-24 23:58:27 +00:00
Chris Lattner 9a8d1d9e56 Make a few related changes:
1) add a new ASTContext::getFloatTypeSemantics method.
2) Use it from SemaExpr.cpp, CodeGenTypes.cpp and other places.
3) Change the TargetInfo.h get*Format methods to return their 
   fltSemantics byref instead of by pointer.
4) Change CodeGenFunction::EmitBuiltinExpr to allow builtins which
   sometimes expand specially and othertimes fall back to libm.
5) Add support for __builtin_nan("") to codegen, cases that don't pass
   in an empty string are currently lowered to libm calls.
6) Fix codegen of __builtin_infl.

llvm-svn: 52914
2008-06-30 18:32:54 +00:00