Commit Graph

816 Commits

Author SHA1 Message Date
Steve Naroff 49effdefef Tweak Sema::ActOnInstanceMessage() to treat the built-in "Class" type the same as "id".
llvm-svn: 43996
2007-11-11 17:52:25 +00:00
Steve Naroff cac26f4f5f This is the last 5% of the solution to teaching Sema::ActOnInstanceMessage() about private methods (r43989).
While the diff is large, the idea is very simple. When we parse method definitions (in an @implementation), we need to add them incrementally (rather than wait until the @end).

Other details...

- Renamed Sema::ActOnAddMethodsToObjcDecl() to Sema::ActOnAtEnd(). The methods are now optional arguments.
- Removed Parser::AllImplMethods (a nice cleanup).
- Added location info to ObjcImplementationDecl (since we will need it very soon:-)
- Modified message.m test to no longer allow the bogus diagnostic.

llvm-svn: 43995
2007-11-11 17:19:15 +00:00
Steve Naroff 5f9ae64f6e Make sure Sema::CheckIncrementDecrementOperand() removes typedefs when doing it's analysis.
Thanks to Seo Sanghyeon for his excellent (first) bug fix!

llvm-svn: 43994
2007-11-11 14:15:57 +00:00
Steve Naroff 22e078e013 Teach Sema::ActOnInstanceMessage() about private methods. That is, methods declared in an implementation (but not listed in the interface).
This commit is only 95% of the bug fix. The last piece to this puzzle is to add the method decls to the implementation incrementally (as we encounter them). At the moment, the methods aren't added until we see an @end (which is too late).

I will complete this later...

llvm-svn: 43989
2007-11-11 00:10:47 +00:00
Fariborz Jahanian 0bd56b7727 Fixed a bug which exposed the internally built type to user code.
llvm-svn: 43987
2007-11-10 22:00:55 +00:00
Steve Naroff 257b4a2467 Fix a basic bug (having to do with typedefs) in Sema::UsualArithmeticConversions().
This resuled in the following crash below.

Also modified the usual-float.c test case to capture this case.

[steve-naroffs-imac:clang/test/Sema] snaroff% ../../../../Debug/bin/clang usual-float.c
Assertion failed: (0 && "Sema::UsualArithmeticConversions(): illegal float comparison"), function UsualArithmeticConversions, file SemaExpr.cpp, line 960.
0   clang                               0x001ef9b9 _ZN40_GLOBAL__N_Signals.cpp_00000000_4E6DAF8315PrintStackTraceEv + 45
1   clang                               0x001efd5f _ZN40_GLOBAL__N_Signals.cpp_00000000_4E6DAF8313SignalHandlerEi + 323
2   libSystem.B.dylib                   0x90c6297b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   libSystem.B.dylib                   0x90cdb782 raise + 26
5   libSystem.B.dylib                   0x90cead3f abort + 73
6   libSystem.B.dylib                   0x90cdc923 __assert_rtn + 101
7   clang                               0x00077316 _ZN5clang4Sema26UsualArithmeticConversionsERPNS_4ExprES3_b + 1004
8   clang                               0x000803cf _ZN5clang4Sema27CheckMultiplyDivideOperandsERPNS_4ExprES3_NS_14SourceLocationEb + 181
9   clang                               0x0007a8e8 _ZN5clang4Sema10ActOnBinOpENS_14SourceLocationENS_3tok9TokenKindEPvS4_ + 472
10  clang                               0x000cf058 _ZN5clang6Parser26ParseRHSOfBinaryExpressionENS_6Action12ActionResultILj0EEEj + 1286
11  clang                               0x000cf2de _ZN5clang6Parser25ParseAssignmentExpressionEv + 86

llvm-svn: 43985
2007-11-10 19:45:54 +00:00
Fariborz Jahanian 6aafd4130b Minor code clean up in method def area.
llvm-svn: 43980
2007-11-10 17:40:57 +00:00
Fariborz Jahanian 85e1d0d807 Represent method definitions as separate AST nodes. Pretty print will come next.
llvm-svn: 43979
2007-11-10 16:31:34 +00:00
Fariborz Jahanian 7a017215eb Some code clean up in the form of name changes for functions which
process method definitions.

llvm-svn: 43967
2007-11-09 22:27:59 +00:00
Fariborz Jahanian b5605179c4 Added class context to method declarations. Provide "interface *" type
to 'self' method of instance methods.

llvm-svn: 43957
2007-11-09 19:52:12 +00:00
Fariborz Jahanian 19d4dbd217 Insert invisble arguments to method definition header.
llvm-svn: 43948
2007-11-09 17:18:29 +00:00
Fariborz Jahanian 56ff146ec4 First patch toward rewriting of method definitions. This is work in progress.
llvm-svn: 43915
2007-11-08 23:49:49 +00:00
Fariborz Jahanian adfbbc3330 AST for objective-c's @throw statement and its pretty-printing.
llvm-svn: 43802
2007-11-07 02:00:49 +00:00
Fariborz Jahanian f76f2b0c1c Patch for objc2's property ASTs, as well as pretty-priting the ASTs.
llvm-svn: 43778
2007-11-06 22:01:00 +00:00
Chris Lattner 45d561ad99 improve decl merging logic to be more correct with
functions.  Patch contributed by Nuno Lopes, thanks!

llvm-svn: 43757
2007-11-06 06:07:26 +00:00
Chris Lattner 3209725c68 Add better validation for array types when merging decls. Patch
contributed by Oliver Hunt, thanks!

llvm-svn: 43750
2007-11-06 04:28:31 +00:00
Steve Naroff 96d20616c4 Sema::ActOnClassMessage()...if a class method isn't found, lookup an instance method. Since all classes are also instances, this is appropriate.
llvm-svn: 43708
2007-11-05 15:27:52 +00:00
Steve Naroff 66697aa72f Add a method prototype slot/getter to the ObjCMessageExpr AST.
llvm-svn: 43666
2007-11-03 16:37:59 +00:00
Steve Naroff a397efd915 Implement rewrite rules for ObjC string constants.
llvm-svn: 43665
2007-11-03 11:27:19 +00:00
Chris Lattner 376cdaf50b Fix ownership model of ParseAST to allow the dtor of
ASTConsumer to process the AST before it is destroyed.
This allows elimination of HandleObjcMetaDataEmission.

llvm-svn: 43659
2007-11-03 06:24:16 +00:00
Fariborz Jahanian f859ef293c AST for @try statement.
llvm-svn: 43640
2007-11-02 15:39:31 +00:00
Fariborz Jahanian 71234d8a9e AST for @finally statement.
llvm-svn: 43629
2007-11-02 00:18:53 +00:00
Fariborz Jahanian 9e63b98de7 AST build for @catch clause (this is work in progress).
llvm-svn: 43628
2007-11-01 23:59:59 +00:00
Fariborz Jahanian ac73ff8868 Remaining work to collect objective-c's type qualifiers and use them to encode
method types.

llvm-svn: 43617
2007-11-01 17:18:37 +00:00
Devang Patel 32714064b1 Propagate bitfield info.
llvm-svn: 43613
2007-11-01 16:29:56 +00:00
Fariborz Jahanian 7a9c47480d 1) More additions for objective-c's qualifier type.
2) Fixed a test failure (which should have failed all along!).

llvm-svn: 43589
2007-10-31 23:53:01 +00:00
Fariborz Jahanian 95b6076c77 Fixed problem with rewriting stand-alone @implementation (with no matching @interface).
A new test case added.

llvm-svn: 43568
2007-10-31 18:48:14 +00:00
Steve Naroff 6d40db0dde Implement a more sensible strategy for ObjC built-in types (addressing a long standing FIXME in Sema::GetObjcIdType()).
This removes several gross hacks to work around the previous "lazy" behavior.

Two notes:
- MinimalActions still needs to be taught about the built-in types (This breaks one of the -noop test cases). I started this, then added a FIXME.
- I didn't convert Sema::GetObjcProtoType() yet.

llvm-svn: 43567
2007-10-31 18:42:27 +00:00
Fariborz Jahanian d728e949bb After Anders check-in, we can now encode 'Class' type.
llvm-svn: 43556
2007-10-31 16:00:13 +00:00
Anders Carlsson f56a7aee2f Encode Class, SEL and Objective-C objects.
llvm-svn: 43540
2007-10-31 02:53:19 +00:00
Fariborz Jahanian ca5338196f Added new type and bitfield fields in some decl types in preparation for objective-c's type qualifiers.
Added initialization of Class/SEMA types.

llvm-svn: 43534
2007-10-31 00:12:35 +00:00
Steve Naroff 5cdcd9b61c Stop pre-defining objc_msgSend/objc_getClass in the preprocessor. Instead, I generate these declaration on the fly when rewriting a message expression.
llvm-svn: 43529
2007-10-30 23:14:51 +00:00
Ted Kremenek 78036cdd5c Tightened IgnoreParen.
llvm-svn: 43517
2007-10-30 21:03:09 +00:00
Chris Lattner 0b11172e8c minor tweaks
llvm-svn: 43515
2007-10-30 20:57:56 +00:00
Fariborz Jahanian 18d7b30241 Revisited my last patch to be able to do encoding of ivar types with 'id'.
llvm-svn: 43507
2007-10-30 18:27:03 +00:00
Fariborz Jahanian 509d8d6fc6 Added type encoding for 'id' type.
llvm-svn: 43504
2007-10-30 17:06:23 +00:00
Steve Naroff 5448cf6d61 - Add location info to category/protocol AST's
- Rewrite categories.

llvm-svn: 43501
2007-10-30 13:30:57 +00:00
Steve Naroff 4cd61acc33 Remove a couple FIXME's for rewriting ObjC interfaces (which are now being rewritten properly).
llvm-svn: 43494
2007-10-30 03:43:13 +00:00
Steve Naroff c54840433f More support for rewriting ObjC intefaces. Still some edge cases to handle...
llvm-svn: 43493
2007-10-30 02:23:23 +00:00
Steve Naroff 33a1e80dd1 This commit contains lot's of small tweaks to how we pass around and store SourceLocation's for interfaces/protocols/categories/implementations.
llvm-svn: 43475
2007-10-29 21:38:07 +00:00
Ted Kremenek e2763b0948 Added some comments.
Moved a dependent predicate in an if statement to be an assertion
within the if statement body.

llvm-svn: 43453
2007-10-29 17:13:39 +00:00
Ted Kremenek e451eae8d7 For non-floating point types, added check for expressions of the form
"x == x" and "x != x".  We emit a warning for these since they always evaluate
to a constant value and often indicate a logical error.

Added test case for this check.

llvm-svn: 43450
2007-10-29 16:58:49 +00:00
Ted Kremenek fa907b8168 For floating point equality check, we now ignore parentheses. e.g.:
(x) == x  is the treated the same as x == x.

llvm-svn: 43448
2007-10-29 16:45:23 +00:00
Ted Kremenek d4ecc6da67 For checking for floating point comparison using == or !=, we now suppress
errors for cases such as "x == x".

Added test case to test this feature.

llvm-svn: 43447
2007-10-29 16:40:01 +00:00
Chris Lattner b104d31bd9 when checking for type equality, ignore typedefs.
llvm-svn: 43441
2007-10-29 05:15:40 +00:00
Chris Lattner 3bc4d20862 casting to void is ok for structs (C99 6.5.4p2), this fixes
one bogus error on PR1750.

llvm-svn: 43436
2007-10-29 04:26:44 +00:00
Chris Lattner 73c56c0735 Implement *skeletal* support for representing GNU inline asm stmts in the AST,
resolving a crash on a .i file in PR1750.  We now generate 49 errors on the
.i file in that bug.

llvm-svn: 43433
2007-10-29 04:04:16 +00:00
Steve Naroff 161a92b976 Start rewriting ObjC interfaces. As a start, we comment out all the methods. This involved refining how the parser/AST passes/manages SourceLocations for ObjcMethodDecl's.
llvm-svn: 43404
2007-10-26 20:53:56 +00:00
Fariborz Jahanian 3339d0d14e This patch allows synthesis generation of ivar offset for legacy objective-c @implementation
decl without an @interface decl.

llvm-svn: 43403
2007-10-26 20:50:24 +00:00
Fariborz Jahanian 99e96b0f11 Patch to synthesize computation of Ivar offset in rewritten c file.
Thanks to Steve N. to point out using of offsetof for this.

llvm-svn: 43391
2007-10-26 19:46:17 +00:00
Chris Lattner 8beb9dee0e Fix a crash on test/Sema/invalid-decl.c
llvm-svn: 43188
2007-10-19 20:10:30 +00:00
Steve Naroff 684dc4107f Fix the previous (short lived:-) FIXME.
I didn't realize that GCC considers this a hard error (I thought it was built-in).

Since it's not, we should simply emit an error.

[dylan:~/llvm/tools/clang] admin% cc -c trivial.m
trivial.m:6: error: cannot find interface declaration for 'NSConstantString'

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang trivial.m 
trivial.m:6:16: error: cannot find interface declaration for 'NSConstantString'
NSString *s = @"123";
               ^
1 diagnostic generated.

llvm-svn: 43157
2007-10-18 23:53:51 +00:00
Fariborz Jahanian e183a8259d Check for Nullness of value built in GetObjcProtoType.
llvm-svn: 43155
2007-10-18 22:59:23 +00:00
Steve Naroff eee59ebb15 Add a FIXME to an assert.
Change a dyn_cast_or_null back to cast (which is more efficient).

llvm-svn: 43152
2007-10-18 22:17:45 +00:00
Fariborz Jahanian c34409c281 Patch to rewrite ivar tables metadata for classes defined.
llvm-svn: 43151
2007-10-18 22:09:03 +00:00
Steve Naroff 1bb21df47f Tweak a recent fix to UsualArithmeticConversions (made by Chris - r43113). The benefit of this tweak is it guarantees the entire routine operates on unqualified types (which I believe is a bit clearer).
llvm-svn: 43142
2007-10-18 18:55:53 +00:00
Steve Naroff a78c464c9e Fix a bug in Sema::CheckConditionalOperands(). When mixing pointers and null pointer constants, we need to promote the null pointer constant (which is an integer) to the pointer type. Test case is self explanatory.
This surfaced yesterday, when compiling test/Sema/cocoa.m on Leopard. Since this has nothing to do with ObjC, it's kind of bizarre this hasn't shown up before. I imagine Cocoa.h on Leopard may have changed recently? 

Thanks to Ted for localizing the bug and giving me a useful AST dump...

llvm-svn: 43114
2007-10-18 05:13:08 +00:00
Chris Lattner fac7ac4130 UsualArithmeticConversions is crashing with an assert
when comparing "float" and "const float".  This "fixes" the
issue, but may not be the right fix.  Steve, please review.

Testcase here: test/Sema/usual-float.c

llvm-svn: 43113
2007-10-18 03:50:33 +00:00
Steve Naroff 8569d77349 Fix the following bug...
unsigned char asso_values[] = { 34 };
int legal2() { 
  return asso_values[0]; 
}

The code that creates the new constant array type was operating on the original type.

As a result, the constant type being generated was "unsigned char [1][]" (which is wrong).

The fix is to operate on the element type - in this case, the correct type is "unsigned char [1]"

I added this case to array-init.c, which clearly didn't catch this bogosity...

llvm-svn: 43112
2007-10-18 03:27:23 +00:00
Fariborz Jahanian a32aaefadc Implementation of AST for @protocol expression.
llvm-svn: 43075
2007-10-17 16:58:11 +00:00
Anders Carlsson f94cd1ffe6 Generate code for static variables that don't have initializers. Also, report an error if a static initializer is not constant.
llvm-svn: 43058
2007-10-17 00:52:43 +00:00
Fariborz Jahanian 6bd1d612ac Fix location processing of @selector: the range should include the @ sign.
llvm-svn: 43051
2007-10-16 23:21:02 +00:00
Steve Naroff 077c83bddb Add Sema::CheckMessageArgumentTypes()...
llvm-svn: 43050
2007-10-16 23:12:48 +00:00
Chris Lattner 37390bed4d Fix location processing of @encode: the range should include the @ sign.
@selector probably gets this wrong also.

llvm-svn: 43048
2007-10-16 22:51:17 +00:00
Chris Lattner a7c19feca2 Add a new Rewriter::getRangeSize method.
Rename SourceRange::Begin()/End() to getBegin()/getEnd() for
consistency with other code.
Start building the rewriter towards handling @encode.

llvm-svn: 43047
2007-10-16 22:36:42 +00:00
Fariborz Jahanian ebac2cb235 Patch to diagnose duplicate method implementations.
llvm-svn: 43046
2007-10-16 21:52:23 +00:00
Steve Naroff d275426449 Remove ObjcMethodDecl::getNumMethodParams/getMethodParamDecl, they aren't used/needed.
Change ObjcMethodDecl::getMethodType to getResultType, to match FunctionDecl.

llvm-svn: 43045
2007-10-16 21:36:54 +00:00
Fariborz Jahanian 4bef462a3e Patch to implement AST generation for objective-c's @selector expression.
llvm-svn: 43038
2007-10-16 20:40:23 +00:00
Steve Naroff 55f52da24c Emit diagnostics for methods not found.
llvm-svn: 43037
2007-10-16 20:39:36 +00:00
Chris Lattner e6dcd505d0 initialization of references should not do default fn/array promotions.
This fixes a bug Anders noticed.

llvm-svn: 43024
2007-10-16 02:55:40 +00:00
Steve Naroff 698495522d Bad cast...need to use dyn_cast_or_null. Also changed Sema::InitBuiltinVaListType (which had the same bug).
llvm-svn: 43023
2007-10-16 00:00:18 +00:00
Steve Naroff f73b784a5e Change the type of ObjCStringLiteral from "struct __builtin_CFString *" to "NSConstantString *".
This makes the typecheck much happier. Without this change, the type checker would have to special case "struct __builtin_CFString *". This change does assume the interface for NSConstantString is declared in the translation unit.

I left ASTContext::getCFConstantStringType() around for now (with a comment that says it is currently unused).

llvm-svn: 43021
2007-10-15 23:35:17 +00:00
Steve Naroff 32e44c0032 Move type compatibility predicates from Type to ASTContext. In addition, the predicates are now instance methods (they were previously static class methods on Type).
This allowed me to fix the following hack from this weekend...

// FIXME: Devise a way to do this without using strcmp.
// Would like to say..."return getAsStructureType() == IdStructType;", but
// we don't have a pointer to ASTContext.
bool Type::isObjcIdType() const {
  if (const RecordType *RT = getAsStructureType())
    return !strcmp(RT->getDecl()->getName(), "objc_object");
  return false;
}

...which is now...

bool isObjcIdType(QualType T) const {
  return T->getAsStructureType() == IdStructType;
}

Side notes:

- I had to remove a convenience function from the TypesCompatibleExpr class.

int typesAreCompatible() const {return Type::typesAreCompatible(Type1,Type2);}

Which required a couple clients get a little more verbose...

-    Result = TCE->typesAreCompatible();
+    Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());

Overall, I think this change also makes sense for a couple reasons...

1) Since ASTContext vends types, it makes sense for the type compatibility API to be there.
2) This allows the type compatibility predeciates to refer to data not strictly present in the AST (which I have found problematic on several occasions).

llvm-svn: 43009
2007-10-15 20:41:53 +00:00
Anders Carlsson 7e13ab88a2 Add code generation and sema checking for __builtin_va_arg.
llvm-svn: 43006
2007-10-15 20:28:48 +00:00
Fariborz Jahanian d4b3015dd7 Several name lookup conflict detection fixes involving objective-c names.
llvm-svn: 43000
2007-10-15 19:16:57 +00:00
Steve Naroff 66e9f331ba Added ASTContext::setObjcIdType/getObjcIdType(), set by Sema.
Also noticed ASTContext::BuiltinVaListType wasn't being initialized to the null type (so I set it).

llvm-svn: 42983
2007-10-15 14:41:52 +00:00
Anders Carlsson cbfc4b8824 Add support for Pascal strings.
llvm-svn: 42974
2007-10-15 02:50:23 +00:00
Steve Naroff 5d15254496 - Teach ObjcInterfaceDecl::lookupInstance/ClassMethod to look through protocols.
- Start looking up methods in the global method pools (for "id").
- Start integrating interface types into the type system.

llvm-svn: 42971
2007-10-14 23:13:51 +00:00
Steve Naroff ca0ecfe048 Add category lookup (removing a couple FIXME's).
Changed ObjcInterfaceDecl::ListCategories->CategoryList.

llvm-svn: 42968
2007-10-14 18:27:41 +00:00
Steve Naroff 5811baf1a0 - Added Sema::AddFactoryMethodToGlobalPool and Sema::AddInstanceMethodToGlobalPool and DenseMaps. This will allow us to efficiently lookup a method from a selector given no type information (for the "id" data type).
- Fixed some funky "}
                    else {" indentation in Sema::ActOnAddMethodsToObjcDecl(). I'd prefer we stay away from this style...it wastes space and isn't any easier to read (from my perspective, at least:-)

- Changed Parser::ParseObjCInterfaceDeclList() to only call Action::ActOnAddMethodsToObjcDecl() when it actually has methods to add (since most interface have methods, this is a very minor cleanup).

llvm-svn: 42957
2007-10-14 00:58:41 +00:00
Anders Carlsson 24ebce6fca Generate code for va_start and va_end.
llvm-svn: 42939
2007-10-12 23:56:29 +00:00
Fariborz Jahanian fd0312ed79 Patch to check for duplicate method decls in protocols.
llvm-svn: 42938
2007-10-12 23:43:31 +00:00
Fariborz Jahanian ecfe4f1453 Check and diagnose that objective-c objects may not be statically allocated.
llvm-svn: 42936
2007-10-12 22:10:42 +00:00
Ted Kremenek 41362cea7b Added notion of '*' specified format width/specifiers when checking
printf format strings.  Added type checking to see if the matching
width/precision argument was of type 'int'.

Thanks to Anders Carlsson for reporting this missing feature.

llvm-svn: 42933
2007-10-12 20:51:52 +00:00
Fariborz Jahanian 02fbb68e85 Fixed typo in comment.
llvm-svn: 42928
2007-10-12 19:53:08 +00:00
Fariborz Jahanian c7afeebb12 Fixed a @compatible_alias bug. In the process, discovered unnecessary 2ndry lookup
ok class names and streamlined this logic to do the lookup once.

llvm-svn: 42926
2007-10-12 19:38:20 +00:00
Steve Naroff b915146a5d Replace one FIXME with another. We handle protocols just fine now. The ObjC decl will only be 0 when we have an error on the ObjC decl. I would prefer we pass in a decl that is marked as invalid. I don't think this is critical to fix now, however I'd like us to be consistent. There are currently many places that don't mark the decl as invalid (which need to be fixed)...
llvm-svn: 42923
2007-10-12 18:49:25 +00:00
Anders Carlsson 431ef632cb Add some more diagnostics for va_start, fix tests so they pass with these new diags.
llvm-svn: 42917
2007-10-12 17:48:41 +00:00
Fariborz Jahanian d52cd41630 Fixed a bug whereby, struct tag name matches a typedef/objc-class name
and hid them.

llvm-svn: 42915
2007-10-12 16:34:10 +00:00
Ted Kremenek 6a6c08c319 Printf argument checking now supports dynamically-passed precision
specifiers.

llvm-svn: 42886
2007-10-12 00:11:27 +00:00
Fariborz Jahanian 49c6425ee6 This patch implementa objective-c's @compatibilty-alias declaration.
llvm-svn: 42883
2007-10-11 23:42:27 +00:00
Anders Carlsson 87c149bf51 Add __builtin_va_start to the list of builtins, make __builtin_va_list available to builtin functions.
llvm-svn: 42857
2007-10-11 01:00:40 +00:00
Fariborz Jahanian 70e8f1024a Patch to create protocol conforming class types.
llvm-svn: 42856
2007-10-11 00:55:41 +00:00
Chris Lattner 9c7a0361c0 Fix 80 col violations.
llvm-svn: 42849
2007-10-10 23:42:28 +00:00
Steve Naroff 783a7a0698 Refinements to Sema::GetObjcIdType()...
- Cache the typedef, not the type (avoids importing AST/Type.h).
- Emit an error if "id" cannot be found.
- Comment the routine and add a FIXME to reconsider how we emulate GCC's new fangled behavior. This isn't a priority for now, since almost no code depends on having "id" built-in.
- Add a test.

llvm-svn: 42845
2007-10-10 23:24:43 +00:00
Steve Naroff 7f549f1897 - Make sure default return/argument types (for methods) default to "id".
- Cache the "id" type in Sema...initialize ObjcIdType and TUScope (oops).
- Fix ActOnInstanceMessage to allow for "id" type receivers...still work to do (next).

llvm-svn: 42842
2007-10-10 21:53:07 +00:00
Anders Carlsson db83d77c78 Emit a warning when the body of an if block is a NullStmt.
llvm-svn: 42840
2007-10-10 20:50:11 +00:00
Steve Naroff 93eb5f1438 Remove Scope argument from ObjC actions that either don't need it or can now use TUScope.
Also improve a recently added comment.

llvm-svn: 42826
2007-10-10 17:32:04 +00:00
Chris Lattner 1f1b0dbc28 Make a significant change to invert the control flow handling
predefined macros.  Previously, these were handled by the driver,
now they are handled by the preprocessor.

Some fallout of this:

1. Instead of preprocessing two buffers (the predefines, then the 
   main source file)  we now start preprocessing the main source 
   file and inject the predefines as a "psuedo #include" from the
   main source file.
2. #1 allows us to nuke the Lexer::IsMainFile flag and simplify
   Preprocessor::isInPrimaryFile.
3. The driver doesn't have to know about standard #defines, the
   preprocessor knows, which is nice for people wanting to define
   their own drivers.
4. This allows us to put normal tokens in the predefine buffer,
   for example a definition for __builtin_va_list that is 
   target-specific, and a typedef for id in objc.

llvm-svn: 42818
2007-10-09 22:10:18 +00:00
Steve Naroff c62adb6d1a Make sure methods with no return type default to "id".
This fixes a crasher in Sema::MatchTwoMethodDeclarations(), identified by selector-overload.m (just added).

Added Action::ActOnTranslationUnitScope() and renamed Action::PopScope to ActOnPopScope.

Added a Translation Unit Scope instance variable to Sema (will be very useful to ObjC-related actions, since ObjC declarations are always file-scoped).

llvm-svn: 42817
2007-10-09 22:01:59 +00:00
Fariborz Jahanian c8e7a93b02 Minor code clean up to make it more readable.
llvm-svn: 42803
2007-10-09 18:22:59 +00:00
Chris Lattner 516ca70f5d Update DeclKind enums to reflect ObjcProtocolDecl's inheritance change.
llvm-svn: 42802
2007-10-09 18:18:24 +00:00
Fariborz Jahanian 06f84f5f84 Remove addition of protocol names to declaration scopes, use a separate
DenseMap to keep track of such declarations and derive ObjcProtocolDecl
directyly from NamedScope.

llvm-svn: 42801
2007-10-09 18:03:53 +00:00
Chris Lattner a55a2cc25c rename some "Parse" actions to "ActOn". Move code around in
ParseFunctionDefinition so that ActOnFunctionDefBody is always
called if ActOnStartOfFunctionDef is called.  This fixes a crash
reported by Nuno Lopes.

llvm-svn: 42793
2007-10-09 17:14:05 +00:00
Fariborz Jahanian cb995d8981 Prevent memory leak by not creating a category object when there is a
fatal error of category's undefined interface.

llvm-svn: 42790
2007-10-09 17:05:22 +00:00
Steve Naroff 71c3c1c715 Convert Selector Maps/Sets to use stronger typing (now that we have DenseMapInfo in IdentifierTable.h).
llvm-svn: 42767
2007-10-08 21:05:34 +00:00
Fariborz Jahanian 4b2113c281 Return NULL on invalid protocol.
llvm-svn: 42754
2007-10-08 16:07:03 +00:00
Chris Lattner ef6b136781 move IdentifierTable.h from liblex to libbasic.
llvm-svn: 42730
2007-10-07 08:58:51 +00:00
Chris Lattner 65cc87ffc2 The identifier shouldn't be added to the scope, the decl should.
This fixes strange assertions that just started triggering.

llvm-svn: 42721
2007-10-07 07:05:08 +00:00
Chris Lattner f7f34d09e4 simplify some Selector interfaces.
llvm-svn: 42715
2007-10-07 01:33:16 +00:00
Chris Lattner ee2d84133c move ImplementationClassInfo out of ASTContext into Sema.
llvm-svn: 42714
2007-10-07 01:13:46 +00:00
Chris Lattner 6a2b09ecd9 switch ObjcCategoryImplDecl over to being a NamedDecl, remove dead ctor argument.
llvm-svn: 42711
2007-10-06 23:12:31 +00:00
Chris Lattner a4016555d2 introduce a new NamedDecl class, switch a couple of things over to using it.
NamedDecl is a Decl that has an IdentifierInfo (for example, ScopedDecl), 
but not ObjcMethodDecl.

Simplify some code in ActOnAddMethodsToObjcDecl, by doing the cast from 
DeclTy to Decl at the start of the method.

llvm-svn: 42710
2007-10-06 22:53:46 +00:00
Chris Lattner ae0ec1d09f simplify the interface to create ObjcClassDecl's.
llvm-svn: 42706
2007-10-06 20:08:36 +00:00
Chris Lattner 11eca782a3 simplify the interface for creating ObjcForwardProtocolDecl
llvm-svn: 42705
2007-10-06 20:05:59 +00:00
Fariborz Jahanian ea7a98d8d6 This is the first patch toward supporting protocol conforming
objective-c types. It also removes use of Scope* parameter in
getObjCProtocolDecl.

llvm-svn: 42649
2007-10-05 21:01:53 +00:00
Chris Lattner dadc762ac5 Implement DenseMapInfo for Selector, allowing use of DenseMap/DenseSet of
Selector's instead of requiring void* to be used.  I converted one use of
DenseSet<void*> over to use DenseSet<Selector> but the others should change
as well.

llvm-svn: 42645
2007-10-05 20:15:24 +00:00
Fariborz Jahanian 458f7114db Patch for 1) Checking for duplicate methods decls in intterface and category.
2) Use of the new DenseSet<t> abstractions instead of DenseMap<t,char>.

llvm-svn: 42641
2007-10-05 18:00:57 +00:00
Fariborz Jahanian 9081457cbf this patch accomodates clattner's comments on expression processing in @try-statement.
llvm-svn: 42611
2007-10-04 20:19:06 +00:00
Fariborz Jahanian 673414067b Fixed tabs in couple of sources.
llvm-svn: 42601
2007-10-04 00:45:27 +00:00
Fariborz Jahanian c9cd8a185d Fixed all my recent test cases to have the RUN command and
fixed consequence of these changes in clang.

llvm-svn: 42600
2007-10-04 00:22:33 +00:00
Steve Naroff 4810c3a1d6 Finish renaming ObjC declaration actions.
Add comments.
Switch to new indentation style for the Action class. Since many actions take many arguments, the new style will...
- make it easier to add/remove arguments without messing up the indentation...
- make it easier to add comments to each argument (see ActOnMethodDeclaration for an example)...
- in general, just makes it easier to see what is being passed.

The rest of Actions will be converted "lazily"...there is no immediate need to hack all the existing methods.

llvm-svn: 42587
2007-10-03 21:00:46 +00:00
Fariborz Jahanian 6cc3803f0b Renamed getCatLoc() to getLocation() to be consistant for such
getter names.

llvm-svn: 42577
2007-10-03 16:23:52 +00:00
Steve Naroff 0c37b0cb5a Rename several ObjC action methods to use the "ActOn" prefix (still a few more to do).
Remove Action::ObjCStartCategoryInterface/ObjCFinishInterface - they are unused.
.

llvm-svn: 42559
2007-10-02 22:39:18 +00:00
Fariborz Jahanian b8d9e088a7 Unified such names as protocol references, instance methods and class methods
and their accessors in a variety of objective-c classes.

llvm-svn: 42555
2007-10-02 22:05:16 +00:00
Steve Naroff d174155204 Remove Action::ActOnImpleIvarVsClassIvars(), it is only called by Sema (not Parser).
Add Sema::CheckImplementationIvars() to replace the previous action.

llvm-svn: 42553
2007-10-02 21:43:37 +00:00
Steve Naroff f5a55c5a9f Rename ObjcInterfaceDecl::getIsForwardDecl() to isForwardDecl().
Rename ObjcProtocolDecl::getIsForwardProtoDecl() to isForwardDecl().
Rename ObjcInterfaceDecl::setIsForwardDecl() to setForwardDecl().
Rename ObjcProtocolDecl::setIsForwardProtoDecl() to setForwardDecl().

Two reasons:

#1: boolean predicates should start with "is".
#2: Since these two sets of methods represent the same concept, they should be named the same (polymorphism is good:-)

llvm-svn: 42545
2007-10-02 20:26:23 +00:00
Fariborz Jahanian adf84f3f3c Previously, I warned those methods not implemented in implementation class/category.
Now, I also warn those class/categories which are incomplete because of this.

llvm-svn: 42544
2007-10-02 20:06:01 +00:00
Steve Naroff c6814ea670 - Add ObjcInterfaceDecl::lookupInstanceMethod(), lookupClassMethod().
- Add ObjcMessageExpr::getSelector(), getClassName().
- Change Sema::getObjCInterfaceDecl() to simply take an IdentifierInfo (no Scope needed).
- Remove FIXME for printing ObjCMessageExpr's.

llvm-svn: 42543
2007-10-02 20:01:56 +00:00
Fariborz Jahanian 19d765fa6c ObjcCategoryDecl Does not subclass from ScopedDecl any more.
Ted may want to take a look at the change I made at 
FGRecStmtDeclVisitor.h.

llvm-svn: 42535
2007-10-02 17:36:55 +00:00
Fariborz Jahanian 89b8ef92be This patch introduces the ObjcCategoryImplDecl class and does the checking related to
unimplemented methods in category implementation.

llvm-svn: 42531
2007-10-02 16:38:50 +00:00
Steve Naroff 67391b8a54 Move ObjC decls to DeclObjC.h, a new AST header.
Update clients and add to project file.

llvm-svn: 42494
2007-10-01 19:00:59 +00:00
Fariborz Jahanian f26702eb54 Took care of clatter's suggestions, dated.
September 30, 2007 12:36:58 AM PDT and
September 30, 2007 12:50:05 AM PDT

llvm-svn: 42490
2007-10-01 16:53:59 +00:00
Chris Lattner 6c44b9f145 Fix a bug I just introduced.
llvm-svn: 42479
2007-09-30 08:31:00 +00:00
Chris Lattner 4730430bd8 simplify an expression
llvm-svn: 42477
2007-09-30 08:01:04 +00:00
Fariborz Jahanian 0886d252d7 This patch fixes all issues mentioned in clattner's feedback of
September 28, 2007 4:39:24 PM PDT
Please let me know if I missed anything.

llvm-svn: 42473
2007-09-29 18:24:58 +00:00
Fariborz Jahanian ec7b3333e1 Code clean up. Moved couple of static functions to be private members of Sema class.
Avoiding passing a Sema object to these utility functions.

llvm-svn: 42472
2007-09-29 17:14:55 +00:00
Fariborz Jahanian fa0667b547 Patch to remove use of has table for protocol name lookup. This patch mirrors my
previous patch to do the same for class name lookup using a hash table.

llvm-svn: 42471
2007-09-29 17:04:06 +00:00
Fariborz Jahanian 343f7098db Removed use of hash table for class decls and do a name look up directly.
There is still an issue if doing ScopedLookup is an overkill and we can
just access the decl using the identifier.

llvm-svn: 42463
2007-09-29 00:54:24 +00:00
Steve Naroff 8017506d9c Yesterday I discovered that 78% of all selectors in "Cocoa.h" take 0/1 argument.
This motivated implementing a devious clattner inspired solution:-)

This approach uses a small value "Selector" class to point to an IdentifierInfo for the 0/1 case. For multi-keyword selectors, we instantiate a MultiKeywordSelector object (previously known as SelectorInfo). Now, the incremental cost for selectors is only 24,800 for Cocoa.h! This saves 156,592 bytes, or 86%!! The size reduction is also the result of getting rid of the AST slot, which was not strictly necessary (we will associate a selector with it's method using another table...most likely in Sema).

This change was critical to make now, before we have too many clients.

I still need to add some comments to the Selector class...will likely add later today/tomorrow.

llvm-svn: 42452
2007-09-28 22:22:11 +00:00
Fariborz Jahanian b75db4cc8c Patch to warn on umimplemented methods coming from class's
protocols.

llvm-svn: 42436
2007-09-28 17:40:07 +00:00
Fariborz Jahanian f6546b38b2 Patch for method implementation. It populates ObjcImplementationDecl object with method implementation declarations .
It checks and warns on those methods declared in class interface and not implemented.

llvm-svn: 42412
2007-09-27 18:57:03 +00:00
Chris Lattner cc61bf5e0c Fix some use of uninit variables issues, reported by Anton.
llvm-svn: 42396
2007-09-27 15:15:46 +00:00
Steve Naroff f73590dbb1 Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.

#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.

#3: It results in many API simplifications. Here are some highlights:

- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).

I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.

Thanks to Chris for talking this through with me and suggesting this approach. 

llvm-svn: 42395
2007-09-27 14:38:14 +00:00
Fariborz Jahanian 2a4dd316a0 This patch inserts ivars declared in @implementation in its object and verifies
that they conform(in type, name and numbers) to those declared in @interface. 
Test case highlights kind of checking we do here.

llvm-svn: 42360
2007-09-26 18:27:25 +00:00
Fariborz Jahanian e2017c1d1d Patch to make ObjcImplementationDecl derived from TypeDecl and supprt legacy
objective-c code with no @interface declaration.

llvm-svn: 42319
2007-09-25 21:00:20 +00:00
Fariborz Jahanian bfe13c566c This patch introduces a new class to keep track of class implementation info. It also adds more
semantic checks for class and protocol declarations. Test cases are good indications of kind of 
checking being done in this patch.

llvm-svn: 42311
2007-09-25 18:38:09 +00:00
Chris Lattner ec0a6d9be5 Use APFloat for the representation of FP immediates, ask the target
for *which* apfloat to use for a particular type.

llvm-svn: 42234
2007-09-22 18:29:59 +00:00
Fariborz Jahanian 7e5d533098 This patch adds to new things to clang:
1. Handles saving and checking on protocols used in an @interface declaration
2. Checks and saves class's super class.
3. Adds semantic check to category declarations.

llvm-svn: 42218
2007-09-22 00:01:35 +00:00
Chris Lattner 4b2ff02f72 Make case sorting deterministic by not depending on pointer
values.  Patch mostly by Gabor Greif for PR1682.

llvm-svn: 42203
2007-09-21 18:15:22 +00:00
Fariborz Jahanian 876e27dafa This patch instantiates objects for forward protocols and in general handles use of
protocols referenced in @protocol declarations.

llvm-svn: 42191
2007-09-21 15:40:54 +00:00
Fariborz Jahanian 397d8de9ed Handle forward declaration of classes and prevent re-instantiation of
ObjcInterfaceClass Objects.

llvm-svn: 42172
2007-09-20 20:26:44 +00:00
Fariborz Jahanian a8bbc63c1f Match to do some semantic analysis on objective-c class decl.
1. Detect used of undeclared/forward declared super class.
2. Detect duplicate definition of a class.

llvm-svn: 42168
2007-09-20 17:54:07 +00:00
Steve Naroff 2cd263ff71 Remove SelectorTable/SelectorInfo, simply store all selectors in the central IdentifierTable.
Rationale:

We currently have a separate table to unique ObjC selectors. Since I don't need all the instance data in IdentifierInfo, I thought this would save space (and make more sense conceptually).

It turns out the cost of having duplicate entries for unary selectors (i.e. names without colons) outweighs the cost difference between the IdentifierInfo & SelectorInfo structures. Here is the data:

Two tables:

*** Selector/Identifier Stats:
# Selectors/Identifiers: 51635 
Bytes allocated:         1999824

One table:

*** Identifier Table Stats:
# Identifiers:   49500
Bytes allocated: 1990316

llvm-svn: 42139
2007-09-19 16:18:46 +00:00
Steve Naroff 59155be0b2 Remove #include of config.h, it is no longer needed.
llvm-svn: 42126
2007-09-19 03:01:22 +00:00
Steve Naroff 467e619a65 Remove alloca import...
llvm-svn: 42117
2007-09-18 23:56:42 +00:00
Steve Naroff d54978ba8b Progress on message expressions...
- Add ObjcMessageExpr AST node and associated constructors.
- Add SourceLocation's to ActOnKeywordMessage/ActOnUnaryMessage API.
- Instantiate message expressions...
- Replace alloca usage with SmallString.

Next step, installing a correct type, among other tweaks...

llvm-svn: 42116
2007-09-18 23:55:05 +00:00
Fariborz Jahanian 867a7eb5cb Patch for object creation and handling of category declarations.
llvm-svn: 42104
2007-09-18 20:26:58 +00:00
Hartmut Kaiser ae27fdc0f4 alloca.h doesn't exist on Windows.
llvm-svn: 42089
2007-09-18 12:16:59 +00:00
Gabor Greif 56c83140c1 alloca.h is needed on Solaris
llvm-svn: 42088
2007-09-18 11:01:25 +00:00
Fariborz Jahanian 0c74e9d161 Uses more description name for method implementation kind argument.
Moves such argument as the last argument and uses defaul value.

llvm-svn: 42073
2007-09-18 00:25:23 +00:00
Fariborz Jahanian cfacdae9a8 Patch to remove ObjcProtoMethodDecl and use ObjcMethodDecl
instead for @protocol method decls.

llvm-svn: 42070
2007-09-17 22:36:42 +00:00
Fariborz Jahanian 39d641f526 Patch to add objective-c's @protocl type declaration.
llvm-svn: 42060
2007-09-17 21:07:36 +00:00
Steve Naroff f0f2afce5a Finish defining Action API for message expressions.
llvm-svn: 42059
2007-09-17 21:01:15 +00:00
Steve Naroff 486760aee3 - Refactored ObjcKeywordInfo into ObjcKeywordInfo, ObjcKeywordDecl, and ObjcKeywordMessage.
- Removed helper ObjcGetSelectorInfo(), moving the code directly into ObjcBuildMethodDeclaration().
- Many refinements to ParseObjCMessageExpression().
- Add ActOnMessageExpression().

Next step, finish the message actions and (finally) create/instantiate an ObjcMessageExpr AST.

llvm-svn: 42050
2007-09-17 20:25:27 +00:00
Steve Naroff 73d534a2e0 Add support for ObjC keyword selectors.
- Add SelectorInfo/SelectorTable classes, modeled after IdentifierInfo/IdentifierTable.
- Add SelectorTable instance to ASTContext, created lazily through ASTContext::getSelectorInfo().
- Add SelectorInfo slot to ObjcMethodDecl.
- Add helper function to derive a SelectorInfo from ObjcKeywordInfo.

Misc: Got the Decl stats stuff up and running again...it was missing support for ObjC AST's.
llvm-svn: 42023
2007-09-17 14:16:13 +00:00
Chris Lattner 93c7f855e5 remove some obsolete interfaces.
llvm-svn: 42014
2007-09-16 19:47:56 +00:00
Steve Naroff 2f742085f5 Fixes/tweaks that prevent "defaults-i.m" from compiling.
- Allow classnames as the receiver (removing a FIXME from ParseObjCMessageExpression).
- Added a FIXME to ParseObjCMessageExpression()...we need to return a message expr AST node!

llvm-svn: 42001
2007-09-16 16:16:00 +00:00
Steve Naroff 66356bda5d Rename statement actions (from Parse-prefix to ActOn-prefix).
llvm-svn: 42000
2007-09-16 14:56:35 +00:00
Steve Naroff 83895f7888 Rename expression actions (from Parse-prefix to ActOn-prefix).
llvm-svn: 41997
2007-09-16 03:34:24 +00:00
Hartmut Kaiser 0a6b11db24 Updated VC++ build system.
Silenced a couple of VC++ warnings.

llvm-svn: 41994
2007-09-16 00:04:22 +00:00
Chris Lattner 75e0c8cf4c add a new ASTConsumer consumer to simplify stuff in the driver.
Switch -parse-ast over to it.

llvm-svn: 41991
2007-09-15 22:56:56 +00:00
Steve Naroff 30d242c99f Start converting Action methods from Parse-prefix to ActOn-prefix.
The previous naming scheme was confusing, since it resulted in both the Parser and Action modules having methods with the same name. In addition, the Action module never does any parsing...

llvm-svn: 41986
2007-09-15 18:49:24 +00:00
Steve Naroff 2e688fde14 Rename Action::ParseRecordBody() to ProcessFieldDecls(), and add a visibility argument.
Remove Action::ObjcAddVisibilityToIvars(). No need for an extra API when it is trivial to add this info to the previous hook.

In general, I want to start migrating away from having Actions prefixed with "Parse" (which is confusing, since the Action API doesn't do any parsing, per se).

llvm-svn: 41973
2007-09-14 23:09:53 +00:00
Steve Naroff db47ee203a Several improvement to Sema::ParseRecordBody()...
- Adding a safer prologue. The previous prologue would accept a null and therefore assume we had an interface (which was incorrect).
- Fixed FieldDecl's classof method. This allowed me to simplify some unnecessary casting.
- When diagnosing errors, make sure the FieldDecl/EnclosingDecl are marked as invalid. In addition, don't delete the field...rather, add all fields to the enclosing decl. Memory management can/should be done elsewhere. This code was never "upgraded" to the recently added invalid decl strategy.

llvm-svn: 41964
2007-09-14 22:20:54 +00:00
Fariborz Jahanian f3287bf871 Patch to store ivars into interface class object.
llvm-svn: 41961
2007-09-14 21:08:27 +00:00
Fariborz Jahanian aefb23092c Semantic analysis for objective-c ivars.
llvm-svn: 41954
2007-09-14 16:27:55 +00:00
Steve Naroff 1d4b5eaeab Now that the dust has settled on the Decl refactoring, I noticed FieldDecl didn't need NextDeclarator. As a result, I'm removing it.
Removing both slots (NextDeclarator/Next) end up reducing the size of fields/ivars by 40%.

llvm-svn: 41948
2007-09-14 02:20:46 +00:00
Steve Naroff a23cc79654 Move Decl::NextDeclarator (w/ setters/getters) down to ScopedDecl/FieldDecl.
Decl is now svelte:-)

llvm-svn: 41935
2007-09-13 23:52:58 +00:00
Steve Naroff 9def2b15c1 Phase 2 of making the Decl class more lightweight...
Move Identifier/Loc instance variables (and associated getters/setters) down from Decl to ScopedDecl/FieldDecl.

Objc AST's can now inherit from Decl without getting instance variables and types that are C specific. For now, I am keeping NextDeclarator, since I believe it may be useful to ObjC. If not, it can be moved later.

llvm-svn: 41934
2007-09-13 21:41:19 +00:00
Fariborz Jahanian 6812cbb230 Patch for collecting ivars before running action on them.
llvm-svn: 41932
2007-09-13 20:56:13 +00:00
Steve Naroff 9324db12b2 Add "ScopedDecl" AST, used by ValueDecl and TypeDecl.
This allows us to sink the "Next" field, which isn't used by FieldDecl and ObjcIvarDecl.

llvm-svn: 41931
2007-09-13 18:10:37 +00:00
Steve Naroff 437b4d8bda Remove a FIXME. Replace a couple asserts with an appropriate error
diagnostic for illegal initializers.

llvm-svn: 41889
2007-09-12 20:13:48 +00:00
Fariborz Jahanian cfb31fab5e Patch for building method declaration nodes. Also fixed a segfault in cocoa.m due
to use of @property.

llvm-svn: 41880
2007-09-12 18:23:47 +00:00
Steve Naroff 6109140b00 Fix the following bug submitted by Ted Kremenek:
void func() {
int xx = xx; // incorrectly diagnosed 'xx' as an undeclared identifier.
}

This smallish bug resulted in a largish fix. Here are some highlights:

- Needed to make sure ParseDeclarator is called *before* parsing any
initializer. Removed the "Init" argument to ParseDeclarator.
- Added AddInitializerToDecl() to the Action & Sema classes.
In Sema, this hook is responsible for validating the initializer and
installing it into the respective decl.
- Moved several semantic checks from ParseDeclarator() to 
FinalizeDeclaratorGroup(). Previously, this hook was only responsible for 
reversing a list. Now it plays a much larger semantic role. 

All of the above changes ended up simplifying ParseDeclarator(), which
is goodness...

llvm-svn: 41877
2007-09-12 14:07:44 +00:00
Steve Naroff f2fb4ad08e - Add an ObjcIvarDecl AST node (a subclass of FieldDecl).
- Instantiate the node in Sema::ParseField(), based on the type of the TagDecl.
- Add Sema::ObjcAddInstanceVariable(), responsible for adorning/adding the ObjcIvarDecl.

llvm-svn: 41864
2007-09-11 21:17:26 +00:00
Steve Naroff 4292bde14f Fix the following bug submitted by Justin Handville.
int main(int argc, char* argv[])
{
  return 0;
}

After speaking briefly with Chris, we decided this should be a front-end fix.

The fix...have Sema::GetTypeForDeclarator() do the default function/array conversion, as
I outlined in the 9/9 email on this topic.

Since this conversion is done before Sema::ParseParamDeclarator(), I thought I could
remove the conversion from Sema::ParseParamDeclarator(). Unfortunately, this didn't work.
The conversion apparently needs to be done in both places (which doesn't make sense to me).

Will investigate.

llvm-svn: 41811
2007-09-10 22:17:00 +00:00
Steve Naroff acb1e7478f Some small tweaks to the recent Objc support...
llvm-svn: 41803
2007-09-10 20:51:04 +00:00
Fariborz Jahanian 33d037441e Early patch to collect objective-c methods inserts them in
class object.

llvm-svn: 41801
2007-09-10 20:33:04 +00:00
Steve Naroff 09bf815f89 The goal of this commit is to get just enough Sema support to recognize Objective-C classes
as types. That said, the AST nodes ObjcInterfaceDecl, ObjcInterfaceType, and ObjcClassDecl are *very*
preliminary.

The good news is we no longer need -parse-noop (aka MinimalActions) to parse cocoa.m.

llvm-svn: 41752
2007-09-06 21:24:23 +00:00
Ted Kremenek 73c18e0362 Added LabelLoc to GotoStmt to record the source location of the label token
in the actual GotoStmt.

Fixed bug where GotoStmt::getSourceRange incorrectly used the target LabelStmt
to compute its extent.

llvm-svn: 41745
2007-09-06 17:11:52 +00:00
Steve Naroff 67ae443954 Simplified initializer semantic analysis by adding the following 2 methods:
- ArrayType::getBaseType(), and 
- ConstantArrayType::getMaximumElements().

Wanted to do this cleanup before adding structure support, which will add more complexity.

llvm-svn: 41715
2007-09-04 21:13:33 +00:00
Steve Naroff 77b97002e9 Make sure initializer type promotions get propagated.
This fixes a recent regression with Codegen/mandel.c.

llvm-svn: 41696
2007-09-04 14:36:54 +00:00
Chris Lattner 9cf21c5a2c Silence VC++ warnings, patch by Hartmut Kaiser
llvm-svn: 41693
2007-09-04 02:45:27 +00:00
Steve Naroff ac074b4df4 More fun with initializers!
- Fixed many bugs, enhanced test case considerably, added a diagnostic, etc.
- Refactored CheckInitList() into CheckVariableInitList()/CheckConstantInitList().
- Added CheckInitExpr().
- Support for multi-dimensional arrays looking good.

llvm-svn: 41690
2007-09-04 02:20:04 +00:00
Chris Lattner 1463cca1cc Add a method required by the VC++ STL, patch by Hartmut Kaiser!
llvm-svn: 41687
2007-09-03 18:31:57 +00:00
Steve Naroff 7d2c5ed92e Finish getting "array-init.c" to work properly.
Array scalar initialization is now is reasonable shape.

Next step, structure and array of structure initializers.

llvm-svn: 41681
2007-09-03 01:24:23 +00:00
Steve Naroff b03f5940d1 More progress on array initializers.
- Added Expr::isConstantExpr().
- Added type checking for InitListExpr elements.
- Added diagnostic for trying to initialize a variable sized object.

llvm-svn: 41674
2007-09-02 20:30:18 +00:00
Steve Naroff f33527a1aa More semantic analysis of initializers.
Added 2 errors and one warning, updated test case.

llvm-svn: 41672
2007-09-02 15:34:30 +00:00
Steve Naroff 2fea13926f Start implementing semantic analysis for C initializers.
Step 1: Start instantiating InitListExpr's.
Step 2: Call newly added function Sema::CheckInitializer() from Sema::ParseDeclarator().
Step 3: Give InitListExpr's a preliminary type.
Step 4: Start emitting diagnostics for simple assignments.

Note:

As a result of step 1, the CodeGen/mandel.c test asserts "Unimplemented agg expr!", which is expected.

As a result of step 4, the test below now fails. This isn't expected and needs to be investigated (it appears type checking for C++ references is flawed in some way).

******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************
Command: 
 clang -fsyntax-only Sema/cxx-references.cpp
Output:
Sema/cxx-references.cpp:8:12: warning: incompatible pointer types assigning 'int &*' to 'int *'
  int *p = &r;
           ^~
Sema/cxx-references.cpp:10:20: error: incompatible types assigning 'int (int)' to 'int (&)(int)'
  int (&rg)(int) = g;
                   ^
Sema/cxx-references.cpp:13:18: error: incompatible types assigning 'int [3]' to 'int (&)[3]'
  int (&ra)[3] = a;
                 ^
Sema/cxx-references.cpp:16:14: error: incompatible types assigning 'int *' to 'int *&'
  int *& P = Q;
             ^
4 diagnostics generated.
******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************

llvm-svn: 41671
2007-09-02 02:04:30 +00:00
Steve Naroff 42a350a18a Finish converting SwitchStmt AST to source ranges.
Move DumpSourceRange() to DumpStmt().

Now -parse-ast-dump will display source range info for all stmts/exprs.

One day we should implement the source range protocol for Decls.

llvm-svn: 41670
2007-09-01 21:08:38 +00:00
Steve Naroff dc9f36e6c4 Convert more statments over to SourceRanges...
llvm-svn: 41666
2007-08-31 23:49:30 +00:00
Steve Naroff 33f3d05081 Move SourceRange protocol from Expr->Stmt.
Converted many of the statements over. Still a hanful left...

llvm-svn: 41663
2007-08-31 23:28:33 +00:00
Chris Lattner cac27a5478 Fix a bug/missing-feature Ted noticed: the 'unused' warning should not
warn about the last stmt in a stmtexpr, f.e. there should be no warning for:

int maxval_stmt_expr(int x, int y) {
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

llvm-svn: 41655
2007-08-31 21:49:55 +00:00
Chris Lattner 78502cf4c9 diagnose extended uses of offsetof
llvm-svn: 41653
2007-08-31 21:49:13 +00:00
Steve Naroff 096dd942cf Removed Sema::VerifyConstantArrayType(). With the new Array/ConstantArray/VariableArray nodes, this
routine was causing more trouble than it was worth. Anders/Chris noticed that it could return an error code
without emiting a diagnostic (which results in an silent invalid decl, which should *never* happen). In addition,
this routine didn't work well for typedefs and field decls. Lastly, it didn't consider that initializers aren't
in place yet.

Added Type::getAsConstantArrayType(), Type::getAsVariableArrayType(), Type::getAsVariablyModifiedType(),
and Type::isVariablyModifiedType();

Modified Sema::ParseDeclarator() and Sema::ParseField() to use the new predicates. Also added a FIXME for
the initializer omission. Also added a missing test for "static" @ file scope.

llvm-svn: 41647
2007-08-31 17:20:07 +00:00
Anders Carlsson 4692db0e7e Add InitListExpr class.
llvm-svn: 41636
2007-08-31 04:56:16 +00:00
Chris Lattner 57c523f50c add actions for deleting expr/stmt nodes.
llvm-svn: 41635
2007-08-31 04:53:24 +00:00
Steve Naroff 43b8f7fa4f Sema::ParseCastExpr() missing call to UsualUnaryConversions().
The following case now works...

void empty(void * a ) {}

void test()
{
    unsigned char A[4]; 
    empty( (void *) A); 
}

Thanks to Patrick Flannery for finding this...

llvm-svn: 41630
2007-08-31 00:32:44 +00:00
Steve Naroff d57fa94148 Final phase of array cleanup (for now), removing a FIXME from yesterday.
Moved several array constraints checks from Sema::VerifyConstantArrayType() to
Sema::GetTypeForDeclarator(). VerifyConstantArrayType() is now very simple, and
could be removed eventually.

Now, we get the following (correct) messages for BlockVarDecls:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -pedantic
x.c:4:20: error: size of array has non-integer type 'float'
  int size_not_int[f];
                   ^
x.c:5:21: error: array size is negative
  int negative_size[1-2];
                    ^~~
x.c:6:17: warning: zero size arrays are an extension
  int zero_size[0];
                ^
3 diagnostics generated.

llvm-svn: 41624
2007-08-30 22:35:45 +00:00
Steve Naroff 90dfdd5774 Polish yesterday's Array/ConstantArray/VariableArray rewrite, removing a couple FIXME's.
Refactored Array/VariableArray, moving SizeModifier/IndexTypeQuals back up to Array. These
attributes are not specific to VLA's. Most of them are specific to array parameter types.

llvm-svn: 41616
2007-08-30 18:10:14 +00:00
Chris Lattner 98dbf0a3b8 implement pretty printing of offsetof
llvm-svn: 41615
2007-08-30 17:59:59 +00:00
Chris Lattner f17bd423c2 implement initial sema support for __builtin_offsetof
llvm-svn: 41613
2007-08-30 17:45:32 +00:00
Chris Lattner 55343038f4 Fix 80 col violations.
llvm-svn: 41611
2007-08-30 17:08:17 +00:00
Chris Lattner 270228599d Fix a regression on test/Sema/unused-expr.c by fixing the type predicates
to test for the right type class.

llvm-svn: 41601
2007-08-30 06:10:41 +00:00
Steve Naroff 5c13180a27 Fix the following redefinition errors submitted by Keith Bauer...
[dylan:~/llvm/tools/clang] admin% cat tentative_decls.c 
// incorrectly generates redefinition error
extern int array[3];
int array[3];

// incorrectly generates a redefinition error
extern void nup(int a[3]);
void nup(int a[3]) {}

It turns out that this exposed a fairly major flaw in the type system,
array types were never getting uniqued! This is because all array types
contained an expression, which aren't unique.

To solve this, we now have 2 array types, ConstantArrayType and
VariableArrayType. ConstantArrayType's are unique, VAT's aren't.

This is a fairly extensive set of fundamental changes. Fortunately,
all the tests pass. Nevertheless, there may be some collateral damage:-)
If so, let me know!

llvm-svn: 41592
2007-08-30 01:06:46 +00:00
Neil Booth 4a1ee0562d Spaces not tabs.
llvm-svn: 41582
2007-08-29 22:13:52 +00:00
Neil Booth ac582c5ecb Ensure we diagnose long long literals in C90 mode.
llvm-svn: 41581
2007-08-29 22:00:19 +00:00
Ted Kremenek 5ccf0d832d Added checking (during parsing) of comparison of floating point values using == or !=.
This is the same functionality gcc provides via --Wfloat-equal.

llvm-svn: 41574
2007-08-29 18:06:12 +00:00
Chris Lattner 3a370bf33f Implement GCC-compatible layout and typing of enum constants and enum decl.
A small bit of codegen work is still pending.

llvm-svn: 41571
2007-08-29 17:31:48 +00:00
Chris Lattner c92bc4ce2f Fix a null dereference Neil ran into
llvm-svn: 41564
2007-08-29 16:03:41 +00:00
Steve Naroff 0b66158248 Implement default argument promotions (for old-style function calls and variable argument lists).
[dylan:~/llvm/tools/clang] admin% cat x.c

int printf(const char *, ...);

int oldschool();

void foo() {
  float f; 
  short i;
  printf("foo %f", 1.0f);

  oldschool(f,i);
}

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -parse-ast-dump

int printf(char const *, ...);

int oldschool();

void foo()
(CompoundStmt 0x3105f00
  (DeclStmt 0x3105ba0
    0x3105ce0 "float f")
  (DeclStmt 0x3105c90
    0x3105d10 "short i")
  (CallExpr 0x3105df0 'int'
    (ImplicitCastExpr 0x3105dc0 'int (*)(char const *, ...)'
      (DeclRefExpr 0x3105c20 'int (char const *, ...)' Decl='printf' 0x3105bd0))
    (ImplicitCastExpr 0x3105dd0 'char const *'
      (StringLiteral 0x3105d60 'char *' "foo %f"))
    (ImplicitCastExpr 0x3105de0 'double'
      (FloatingLiteral 0x3105d80 'float' 1.000000)))
  (CallExpr 0x3105ed0 'int'
    (ImplicitCastExpr 0x3105ea0 'int (*)()'
      (DeclRefExpr 0x3105e20 'int ()' Decl='oldschool' 0x3105c40))
    (ImplicitCastExpr 0x3105eb0 'double'
      (DeclRefExpr 0x3105e40 'float' Decl='f' 0x3105ce0))
    (ImplicitCastExpr 0x3105ec0 'int'
      (DeclRefExpr 0x3105e60 'short' Decl='i' 0x3105d10))))

llvm-svn: 41558
2007-08-28 23:30:39 +00:00
Steve Naroff f93b6726b1 Finish converting decls over to the new invalid decl API.
Also removed an old FIXME (FIXME: "auto func();" passes through...).

llvm-svn: 41555
2007-08-28 20:14:24 +00:00
Steve Naroff cf871f59bf Move the "invalid decl" idiom up to Decl (where we have some bits to steal:-)
Converted ParmVarDecl, FileVarDecl, BlockVarDecl, and Sema::ParseIdentifierExpr() to use the idiom.

Updated array-constraint.c to make sure we no longer get "undeclared identifier" errors:-)

llvm-svn: 41552
2007-08-28 18:45:29 +00:00
Chris Lattner 24b51ff752 Emit a slightly better warning for unused values for unary and binary operators:
t2.c:3:18: warning: expression result unused
     x = ++x, ++y, y+2;
     ~~~~~~~~~~~~^ ~~~

llvm-svn: 41551
2007-08-28 18:40:30 +00:00
Chris Lattner c11005faa1 add a sourcelocation to binary operator to keep track of the location of the operator.
llvm-svn: 41550
2007-08-28 18:36:55 +00:00
Chris Lattner 1c1f932433 Change EnumDecl to store its corresponding integer type
directly in it.  Remove TargetInfo::getEnumPolicy, as there is only
one policy that we support right now.

llvm-svn: 41548
2007-08-28 18:24:31 +00:00
Ted Kremenek e07a8cd7ff Fixed return-of-stack-address checker to correctly handle stack/global
variables that have a pointer type, or arrays that contain pointers.

This fixes a crash on the following code:

int *h[3];

int **foo(int i)
{
   return &(h[i]);
}

This bug was reported by Keith Bauer (thanks!).

llvm-svn: 41546
2007-08-28 17:02:55 +00:00
Chris Lattner 35da3e29dd extwarn about VLAs in C89 mode.
llvm-svn: 41545
2007-08-28 16:54:00 +00:00
Chris Lattner 8ed218afb9 c++'0x has long long also.
llvm-svn: 41544
2007-08-28 16:41:29 +00:00
Chris Lattner f2c338b7d1 warn about long long when in c89 mode.
llvm-svn: 41543
2007-08-28 16:40:32 +00:00
Chris Lattner c4f6d0c5cf fix 80 col violation
llvm-svn: 41533
2007-08-28 06:17:15 +00:00
Chris Lattner b8a501ccf1 compute the required destination type for an enum, emitting various warnings.
TODO: update the types of the constants and the enum.
llvm-svn: 41532
2007-08-28 06:15:15 +00:00
Chris Lattner bf478cbef2 add a diagnostic:
t.c:1:12: warning: ISO C restricts enumerator values to range of 'int' (180388626432 is too large)
enum e {A, B = 42LL << 32, C = -4, D = 12456 };
           ^

llvm-svn: 41530
2007-08-28 05:27:00 +00:00
Chris Lattner 67933c0aae move a todo
llvm-svn: 41528
2007-08-28 05:10:31 +00:00
Chris Lattner 39f920f35b now that all the infrastructure is in place, enforce C99 6.8.5p3.
Note the FIXME: we need some way to mark a decl erroneous :)

llvm-svn: 41524
2007-08-28 05:03:08 +00:00
Chris Lattner 773c0596b8 If the condition of a for statement is promoted, make sure the
implicit cast gets linked back into the AST.

llvm-svn: 41523
2007-08-28 04:55:47 +00:00
Steve Naroff 7e6f7c25bf Implement more thoughful error recovery when dealing with bogus declarator types.
For example, the following code was resulting in spurious warnings. This was the result of
Sema::GetTypeForDeclarator() synthesizing a type to hand back to the caller (in this case,
"int []", instead of "struct s[]", which is invalid).

struct s; 
struct s* t (struct s z[]) {   // expected-error {{array has incomplete element type}}
  return z;
}

Strategy: Flag the error in Declarator/DeclaratorChunk. This info is later stored in 
the ParmVarDecl. If the decl is referenced, Sema::ParseIdentifierExpr() will check if 
the type is invalid. If so, it quietly returns "true", without instantiating a DeclRefExpr.

This seems to work nicely. If Chris is happy with the approach, I will generalize this to
all VarDecls.

llvm-svn: 41521
2007-08-28 03:03:08 +00:00
Steve Naroff a042db2b80 Some minor aesthetic changes to the control flow.
llvm-svn: 41517
2007-08-27 21:43:43 +00:00
Steve Naroff e31313d792 Fix remaining bugs with complex/float promotions.
llvm-svn: 41515
2007-08-27 21:32:55 +00:00
Chris Lattner 0515e4b26a Fix a few enum-related fixme's
llvm-svn: 41513
2007-08-27 21:16:18 +00:00
Chris Lattner f283a37179 better error recovery for non-i-c-e enum constants.
llvm-svn: 41499
2007-08-27 17:37:24 +00:00
Ted Kremenek d11e460810 Updated checker for "return of address of stack variable" to look for
implicit casts from T to T& at the topmost part of the return-value expression.

This checking may be needed within EvalAddr later on.  We'll wait until
test cases show this kind of logic is necessary (as more C++ features are
implemented in clang).

llvm-svn: 41493
2007-08-27 16:39:17 +00:00
Steve Naroff 7af82d462a Replaced ASTContext::maxFloatingType() with ASTContext::compareFloatingType().
Changed Sema::UsualArithmeticConversions to use the new API.

This fixes the following case...

_Complex double X;
double y;

void foo() {
  X = X + y;
}

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang complex.c -parse-ast-dump
Read top-level variable decl: 'X'
Read top-level variable decl: 'y'

void foo()
(CompoundStmt 0x2605cc0
  (BinaryOperator 0x2605ca0 '_Complex double' '='
    (DeclRefExpr 0x2605c10 '_Complex double' Decl='X' 0x2605ab0)
    (BinaryOperator 0x2605c80 '_Complex double' '+'
      (DeclRefExpr 0x2605c30 '_Complex double' Decl='X' 0x2605ab0)
      (ImplicitCastExpr 0x2605c70 '_Complex double'
        (DeclRefExpr 0x2605c50 'double' Decl='y' 0x2605ae0)))))

llvm-svn: 41483
2007-08-27 15:30:22 +00:00
Chris Lattner d864daf5c6 extwarn about decls intermixed with code in c89 mode.
llvm-svn: 41477
2007-08-27 04:29:41 +00:00
Steve Naroff 808eb8fe88 Add Type::getAsBuiltinType() and Type::builtinTypesAreCompatible().
Modified Type::typesAreCompatible() to use the above.

This fixes the following bug submitted by Keith Bauer (thanks!).

int equal(char *a, const char *b)
{
    return a == b;
}

Also tweaked Sema::CheckCompareOperands() to ignore the qualifiers when
comparing two pointer types (though it doesn't relate directly to this bug).

llvm-svn: 41476
2007-08-27 04:08:11 +00:00
Steve Naroff 9091ef703c Replaced ASTContext::maxComplexType() with ASTContext::getFloatingTypeOfSizeWithinDomain().
Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions, 
using maxFloatingType() with getFloatingTypeOfSizeWithinDomain().

llvm-svn: 41474
2007-08-27 01:27:54 +00:00
Chris Lattner dfaf9f8c2f implement a fixme: __extension__ marker on decls in compound stmts.
llvm-svn: 41473
2007-08-27 01:01:57 +00:00
Chris Lattner 0c6aad373f Fix %p format checking, patch by Keith Bauer.
llvm-svn: 41454
2007-08-26 17:39:38 +00:00
Chris Lattner 0d850bfed8 For warnings like this:
t.c:3:9: warning: invalid conversion '%B'
printf("%B\a\n", p);
~~~~~~  ^

Don't beep the console or print the newline.

llvm-svn: 41453
2007-08-26 17:38:22 +00:00