Commit Graph

406 Commits

Author SHA1 Message Date
Steve Naroff 2f55b98725 Tweak RewriteInterfaceDecl() to generate a typedef (if one hasn't already been generated).
llvm-svn: 43600
2007-11-01 03:35:41 +00:00
Fariborz Jahanian d822d68b74 More infrastructure to recognize objective-c's type qualifiers (in,inout, etc.)
llvm-svn: 43580
2007-10-31 21:59:43 +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
Steve Naroff 37e011ce43 Add some plumbing to help cope with rewriting "id<p>", "Class<p>*".
llvm-svn: 43543
2007-10-31 04:38:33 +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
Fariborz Jahanian 509d8d6fc6 Added type encoding for 'id' type.
llvm-svn: 43504
2007-10-30 17:06:23 +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
Fariborz Jahanian 797f24cd7e Encoding for objectiive-c methods.
llvm-svn: 43481
2007-10-29 22:57:28 +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
Anders Carlsson 18acd44514 Address Chris's comments.
llvm-svn: 43445
2007-10-29 06:33:42 +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
Fariborz Jahanian 801b63525d Path to synthesize 'instance' size field of _objc_class metadata.
llvm-svn: 43409
2007-10-26 23:09:28 +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
Ted Kremenek 5749aaedd9 Added DeclSerialization.cpp to XCode project.
llvm-svn: 43362
2007-10-25 21:39:10 +00:00
Fariborz Jahanian 51f2182338 Refactored several meta data for reusability.
Changed the entire rewrite of metadata to write to std::string
object instead of stdout.

llvm-svn: 43360
2007-10-25 20:55:25 +00:00
Chris Lattner 211f8b8352 Convert one type of metadata to use std::string instead of
printf as an example.

llvm-svn: 43346
2007-10-25 17:07:24 +00:00
Ted Kremenek bd8497b011 Added SourceLocation.cpp to XCode project.
llvm-svn: 43344
2007-10-25 16:03:53 +00:00
Chris Lattner 35e564ed09 Add a new ChooseExpr::isConditionTrue method to unify
some code.

llvm-svn: 43322
2007-10-25 00:29:32 +00:00
Fariborz Jahanian b2f525dabc Refactord instance and class metadata emission. Refactored protocols metadata emission.
Implemented emission of category metadata,

llvm-svn: 43308
2007-10-24 19:23:36 +00:00
Steve Naroff db1ab1c2b0 Add some plumbing to rewrite message expressions (still under construction).
llvm-svn: 43274
2007-10-23 23:50:29 +00:00
Steve Naroff e670dbb9e6 - Add rewrite rule for @class.
- Add setter/getter to ObjcClassDecl.
- Predefined key runtime functions.

llvm-svn: 43257
2007-10-23 20:20:08 +00:00
Fariborz Jahanian 6eafb030f0 This patch generates protocol metadata and all its sub-metadata.
llvm-svn: 43233
2007-10-22 21:41:37 +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
Ted Kremenek 0f39de13a0 Added StmtIterator.cpp and StmtIterator.h to the XCode project.
llvm-svn: 43139
2007-10-18 18:22:01 +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
Ted Kremenek 970217fae9 Added Driver/SerializationTest.cpp to the XCode project.
llvm-svn: 43054
2007-10-16 23:40:12 +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
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
Chris Lattner 0bd1c97293 Push the rewriter forward a bit more. Now it rewrites
#import to #include's as a test.

llvm-svn: 43041
2007-10-16 21:07:07 +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 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
Fariborz Jahanian 76a9427783 Patch to parse @selector expressions.
llvm-svn: 43022
2007-10-15 23:39:13 +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 cbfc4b8824 Add support for Pascal strings.
llvm-svn: 42974
2007-10-15 02:50:23 +00:00
Chris Lattner 58bad341bc Woo, tab deletion now works. Next lets see if we can
insert stuff.

llvm-svn: 42941
2007-10-13 00:17:04 +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
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
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
Chris Lattner 168d63b289 add RewriterTest.cpp to xcode project.
llvm-svn: 42863
2007-10-11 16:34:20 +00:00
Fariborz Jahanian 70e8f1024a Patch to create protocol conforming class types.
llvm-svn: 42856
2007-10-11 00:55:41 +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
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
Chris Lattner ed2a9eb820 resolve a fixme, by moving __builtin_va_list to a more logical
place and making it correctly parameterized on the target.

llvm-svn: 42830
2007-10-10 17:48:53 +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 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 feb00b6e12 switch more code to use Token::is/isNot where possible.
llvm-svn: 42797
2007-10-09 17:41:39 +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 da6c012ee7 Added a new class for Interfaces qualified by protocol list.
Protocols are now sorted and made unique in the list.
Enhanced pretty printer for @interface (So, I can see the protocol list).

llvm-svn: 42776
2007-10-08 23:06:41 +00:00
Steve Naroff b163154c2d Removed unused instance variable from FieldDecl.
llvm-svn: 42773
2007-10-08 21:56:47 +00:00
Chris Lattner 6776a8d359 Move identifierTable.h to the right folder.
llvm-svn: 42770
2007-10-08 21:35:59 +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 092e34d15b Removed unnecessary base class from some of objective-c classes:
ObjcProtocolDecl is now derived from ScopedDecl. ObjcForwardProtocolDecl from Decl.
ObjcImplementationDecl fom NamedDecl.

llvm-svn: 42756
2007-10-08 17:35:11 +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 d1cdee7d1f Rename ASTStreamers.* -> ASTConsumers.*
llvm-svn: 42718
2007-10-07 06:04:32 +00:00
Chris Lattner b5fc6fbcfc speed up clang startup time by about 23% by avoiding lots of
stringmap operations when there are no secondary targets.

llvm-svn: 42688
2007-10-06 06:29:41 +00:00
Ted Kremenek 8a7bf82206 Modifications to XCode project:
- Added include/Analysis/ExprDeclBitVector.h
- Added include/Analysis/ProgramEdge.h
- Removed include/Analysis/Visitors/DataflowStmtVisitor.h

llvm-svn: 42663
2007-10-05 23:32:54 +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
Steve Naroff e61bfa8bb4 Layering refinements for selectors (suggested by Chris). Specifics...
- Add SelectorTable, which enables us to remove MultiKeywordSelector from the public header.
- Remove FoldingSet from IdentifierInfo.h and Preprocessor.h.
- Remove Parser::ObjcGetUnarySelector and Parser::ObjcGetKeywordSelector, they are subsumed by SelectorTable.
- Add MultiKeywordSelector to IdentifierInfo.cpp.
- Move a bunch of selector related methods from ParseObjC.cpp to IdentifierInfo.cpp.
- Added some comments.

llvm-svn: 42643
2007-10-05 18:42:47 +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 76aff36d64 More tab removal activity.
llvm-svn: 42608
2007-10-04 17:06:28 +00:00
Chris Lattner 01d7f489a9 minor cleanups, make code more defensive, less branchy in Selector ctor.
llvm-svn: 42603
2007-10-04 05:21:22 +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
Chris Lattner 02cbd095dd move DeclObjc.h down to be alphabetically organized
llvm-svn: 42594
2007-10-03 21:56:39 +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 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 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 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 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 e6d9ca5443 objc messages have side effects, return true from hasLocalSideEffect,
fixing:

VoidMethod.m:14:5: warning: expression result unused
    [Greeter hello];
    ^~~~~~~~~~~~~~~

llvm-svn: 42380
2007-09-26 22:06:30 +00:00
Ted Kremenek a88f7bcea3 Updated XCode project to reflect that DataflowValues.h and DataflowSolver.h have
moved to include/clang/Analysis/FlowSensitive.

llvm-svn: 42327
2007-09-25 22:45:38 +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 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
Ted Kremenek 8483a4ab05 Updated XCode project with locations of "Analysis" visitor header files.
llvm-svn: 42176
2007-09-20 21:47:32 +00:00
Ted Kremenek 66d130a584 Added support to clang driver to view ASTs using GraphViz. This
functionality is still preliminary.

llvm-svn: 42152
2007-09-19 21:29:43 +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
Ted Kremenek 1abd5c9d8f Re-added UninitializedValues.cpp to the XCode project because the file was renamed.
llvm-svn: 42057
2007-09-17 20:52:52 +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
Ted Kremenek 186a669014 Added ASTConsumer.h to XCode project.
llvm-svn: 42030
2007-09-17 16:09:32 +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 7ea6ca70f5 switch the llvm emitter to ASTConsumer interface.
llvm-svn: 42013
2007-09-16 19:46:59 +00:00
Chris Lattner e27d865e36 Initial checkin of rewriter interface. It is just stubbed out for now.
llvm-svn: 41990
2007-09-15 22:21:22 +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
Ted Kremenek 15d3b38ff2 Added several files to XCode project file...
Analysis/DataflowSolver.h
    Analysis/UnintializedValues.cpp
    include/clang/Analysis/CFGVarDeclVisitor.h
    include/clang/Analysis/DataflowValues.h
    include/clang/Analysis/UninitializedValues.h

llvm-svn: 41974
2007-09-14 23:13:28 +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
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
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 3aa4efbdee Add ASTContext::StringMap<char> to unique selector names.
llvm-svn: 41894
2007-09-12 23:08:22 +00:00
Ted Kremenek 439b19928f Added files CFGStmtVisitor and DataflowStmtVisitor to XCode project.
llvm-svn: 41886
2007-09-12 19:12:02 +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
Fariborz Jahanian cfc3e4d346 Change ObjcMethodDecl class derivation.
llvm-svn: 41860
2007-09-11 18:45:55 +00:00
Steve Naroff acb1e7478f Some small tweaks to the recent Objc support...
llvm-svn: 41803
2007-09-10 20:51:04 +00:00
Ted Kremenek 6dc7b11d32 Added "Dead Stores", a flow-sensitive checker that checks for stores
to variables that are no longer live.  This analysis is built on top
of CFGs and the LiveVariables analysis.

changes to driver:
 added driver option "-check-dead-stores" to run the analysis

llvm-svn: 41754
2007-09-06 23:00:42 +00:00
Ted Kremenek b56a990955 Added an early implementation of Live-Variables analysis built on
source-level CFGs.  This code may change significantly in the near
future as we explore different means to implement dataflow analyses.

Added a driver option, -dump-live-variables, to view the output of
live variable analysis.  This output is very ALPHA; it will be improved shortly.

llvm-svn: 41737
2007-09-06 00:17:54 +00:00
Steve Naroff ca85d1dc07 Start implementing Actions interface for ObjC classes, instance variables, and methods.
Lot's of small changes to the parser.

llvm-svn: 41732
2007-09-05 23:30:30 +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
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
Ted Kremenek 04f3cee11f Added "PrinterHelper" interface (include/AST/PrinterHelper) that can
be passed as an (optional) argument to StmtPrinter to customize
printing of AST nodes.

Used new PrinterHelper interface to enhance printing and visualization
of CFGs.  The CFGs now illustrate the semantic connectives between
statements and terminators, wheras in the previous printing certain
expressions would (visible) be printed multiple times to reflect which
expressions used the results of other expressions.

The end result is that the CFG is easier to read for flow of
expression values (following principles similar to the LLVM IR).

llvm-svn: 41651
2007-08-31 21:30:12 +00:00
Chris Lattner 11e30d355e Teach the stmtdumper to dump location/range info when a SourceMgr is available.
For example, -parse-ast-dump now prints:

static inline int __inline_isinff(float __x)
(CompoundStmt 0x2409a20
  (ReturnStmt 0x2409a10
    (BinaryOperator 0x24099f0 'int' <///usr/include/architecture/i386/math.h:183:63, col:102> '=='
      (CallExpr 0x24098f0 'float' <col:63, col:82>
        (ImplicitCastExpr 0x24098e0 'float (*)(float)' <col:63>
          (DeclRefExpr 0x2409880 'float (float)' <col:63> Decl='__builtin_fabsf' 0x2409840))
        (DeclRefExpr 0x24098a0 'float' <col:79> Decl='__x' 0x2409810))
      (CallExpr 0x24099c0 'float' <col:87, col:102>
        (ImplicitCastExpr 0x2409870 'float (*)(void)' <col:87>
          (DeclRefExpr 0x2409980 'float (void)' <col:87> Decl='__builtin_inff' 0x2409940))))))

where it only prints filename/line# if it changes from the previous value.  We 
really need loc info on stmts though, like we have on exprs.

llvm-svn: 41602
2007-08-30 06:17:34 +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
Steve Naroff 5f90ca9904 Fix bogus warnings (noticed by Chris) with array-constraints.c.
Remove bogus type conversions in Sema::GetTypeForDeclarator(). This commit
only deals with the array types (DeclaratorCheck::Array), though the
rest of this routine should be reviewed. Given the complexity of C declarators,
I don't want to change the entire routine now (will discuss with Chris tomorrow).

llvm-svn: 41443
2007-08-26 14:38:38 +00:00
Chris Lattner 1c20a170c0 add a new ImaginaryLiteral AST node that is used to
represent imaginary literals:

float _Complex A;
void foo() {
  A = 1.0iF;
}

generates:

  (BinaryOperator 0x2305ec0 '_Complex float' '='
    (DeclRefExpr 0x2305e60 '_Complex float' Decl='A' 0x2305cf0)
    (ImaginaryLiteral 0x2305f40 '_Complex float'
      (FloatingLiteral 0x2305ea0 'float' 1.000000))))

llvm-svn: 41413
2007-08-26 03:42:43 +00:00
Chris Lattner a5235173bc refactor enough of the top-level parsing logic to parse and
ignore 'namespace foo {}'

llvm-svn: 41400
2007-08-25 06:57:03 +00:00
Chris Lattner 3d966d6556 Teach emit-llvm for scalars to properly handle compound assignment
operators in all their glory :)

llvm-svn: 41373
2007-08-24 21:00:35 +00:00
Ted Kremenek 485b13f397 Added ExprCXX.cpp
llvm-svn: 41370
2007-08-24 20:24:16 +00:00
Chris Lattner 2da04b3322 completely refactor codegen of scalar expressions out into its own CGExprScalar.cpp file.
This patch temporarily breaks compound assignment operators, but greatly simplifies many
things.

llvm-svn: 41355
2007-08-24 05:35:26 +00:00
Chris Lattner 11e0de5193 rename two files.
llvm-svn: 41350
2007-08-24 02:22:53 +00:00
Chris Lattner f81460f99c detect and diagnose empty case ranges:
switch.c:16:8: warning: empty case range specified
  case 100 ... 99: ;  // expected-warning {{empty case range}}
       ^~~~~~~~~~

llvm-svn: 41328
2007-08-23 17:48:14 +00:00
Anders Carlsson e01493d47b Parse ObjC @protocol expressions.
llvm-svn: 41320
2007-08-23 15:25:28 +00:00
Chris Lattner ce8f75bd5b add cfg.h/cfg.cpp to the xcode project at Ted's request.
llvm-svn: 41253
2007-08-21 21:44:59 +00:00
Chris Lattner d614e7a553 minor nicities.
llvm-svn: 41244
2007-08-21 18:51:13 +00:00
Anders Carlsson 76f4a902d7 Implement parsing and code generation of Objective-C string literals.
llvm-svn: 41238
2007-08-21 17:43:55 +00:00
Chris Lattner cbfc73b26c Split complex arithmetic codegen out from aggregate codegen.
This means that we get rid of tons of intermediate allocas.  For
example:

void foo(double _Complex a, double _Complex b) {
   a = b+a+a;
}

this used to have 4 temporary allocas, now it has zero of them.
This also simplifies the individual visitor methods because they
now can all operate on real/imag pairs instead of having to 
load/store all over the place.

llvm-svn: 41217
2007-08-21 05:54:00 +00:00
Chris Lattner 62249a6299 Switch StmtVisitor from using dynamic to static dispatch. This makes it
significantly faster and actually reduces the amount of code in the system.
This also allows for future visitor changes.

llvm-svn: 41211
2007-08-21 04:04:25 +00:00
Anders Carlsson b04ea61b79 Implement code generation for constant CFStrings.
llvm-svn: 41206
2007-08-21 00:21:21 +00:00
Chris Lattner b87b1b36ee initial support for checking format strings, patch by Ted Kremenek:
"I've coded up some support in clang to flag warnings for non-constant format strings used in calls to printf-like functions (all the functions listed in "man fprintf").  Non-constant format strings are a source of many security exploits in C/C++ programs, and I believe are currently detected by gcc using the flag -Wformat-nonliteral."

llvm-svn: 41003
2007-08-10 20:18:51 +00:00
Chris Lattner d79671fdf2 New file, just a placeholder for now.
llvm-svn: 41002
2007-08-10 20:13:28 +00:00
Chris Lattner cbe4f77c9e add a new AST dumper interface (E->dump()). This dumps out
the AST in a structural, non-pretty, form useful for understanding
the AST.  It isn't quite done yet, but is already somewhat useful.

For this example:

int test(short X, long long Y) {
  return X < ((100));
}

we get (with -parse-ast-dump):

int test(short X, long long Y)
(CompoundStmt 0x2905ce0
  (ReturnStmt 0x2905cd0
    (BinaryOperator 0x2905cb0 '<'
      (ImplicitCastExpr 0x2905ca0
        (DeclRefExpr 0x2905c20 Decl='X' 0x2905bb0))
      (ParenExpr 0x2905c80
        (ParenExpr 0x2905c60
          (IntegerLiteral 0x2905c40 100))))))

llvm-svn: 40954
2007-08-08 22:51:59 +00:00
Chris Lattner 81a9688e93 Implement codegen for __builtin_choose_expr. For example:
struct X { int A; };

void foo() {
  struct X s;
  int i;
  i = __builtin_choose_expr(0, s, i);
}

compiles to:

        %tmp = load i32* %i             ; <i32> [#uses=1]
        store i32 %tmp, i32* %i

wow :)

llvm-svn: 40801
2007-08-04 00:20:15 +00:00
Steve Naroff 7d451d614c Add a test case to validate code gen for typeof/builtin_types_compatible.
This test case currently generates the following unexpected warnings (when compared with gcc).

[dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check builtin_types_compatible.c
Warnings seen but not expected:
  Line 28: expression result unused
  Line 29: expression result unused
  Line 30: expression result unused
  Line 31: expression result unused
  Line 32: expression result unused
  Line 33: expression result unused

llvm-svn: 40789
2007-08-03 18:38:22 +00:00
Chris Lattner ba32aed8a9 add internals manual to project
llvm-svn: 40645
2007-07-31 18:57:09 +00:00
Chris Lattner ea23d287b5 add two missing files to the xcode project.
llvm-svn: 40643
2007-07-31 18:43:04 +00:00
Chris Lattner c996b176e8 make isPointerType() a pure predicate, rename the
existing one to getAsPointerType()

llvm-svn: 40639
2007-07-31 16:53:04 +00:00
Steve Naroff ad373bdcfe Add parsing and AST support for GNU "typeof".
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.

llvm-svn: 40631
2007-07-31 12:34:36 +00:00
Steve Naroff 44fd8ff400 Fix Sema::ParseCallExpr()...it wasn't doing the default array/function promotions on it's argument types.
This resulted in the following errors when compiling promote_types_in_proto.c test...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang test/Parser/promote_types_in_proto.c 
test/Parser/promote_types_in_proto.c:7:24: error: incompatible types passing 'char *[]' to function expecting 'char *const []'
        arrayPromotion(argv);
        ~~~~~~~~~~~~~~ ^~~~
test/Parser/promote_types_in_proto.c:8:27: error: incompatible types passing 'void (char *const [])' to function expecting 'void (char *const [])'
        functionPromotion(arrayPromotion);
        ~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~
2 diagnostics generated.

When fixing this, noticed that both ParseCallExpr() and ParseReturnStmt() were prematurely comparing types for
equivalence. This is incorrect (since the expr. promotions haven't been done yet). To fix this, I moved the
check "down" to Sema::CheckAssignmentConstraints().

I also converted Type::isArrayType() to the modern API (since I needed it). Still more Type predicates to 
convert.

llvm-svn: 40475
2007-07-24 21:46:40 +00:00
Chris Lattner 8996ffffe5 Add a cache to SourceManager to accellerate line # lookup. This is a
bottleneck for -E computation, because every token that starts a line needs
to determine *which* line it is on (so -E mode can insert the appropriate 
vertical whitespace).  This optimization improves this common case where
it is striding through the line # table.

This speeds up -E on xalancbmk by 3.2%

llvm-svn: 40459
2007-07-24 05:57:19 +00:00
Chris Lattner 9c724c48ea Fix a really subtle bug in the macro expander caching code, where
redefinition of a macro could cause invalid memory to be deleted.
Found preprocessing 253.perlbmk.

llvm-svn: 40380
2007-07-22 01:16:55 +00:00
Steve Naroff a12a6c986a Minor simplification to Expr::isLvalue().
llvm-svn: 40375
2007-07-21 13:32:03 +00:00
Chris Lattner f14d03f515 Update project for LexerToken.h -> Token.h
llvm-svn: 40106
2007-07-20 17:01:09 +00:00
Chris Lattner 53cfe80407 initial layout support for structures and unions. This isn't actually
hooked up to anything, so it's not very useful yet.

llvm-svn: 40006
2007-07-18 17:52:12 +00:00
Steve Naroff 3109001c19 Change DefaultFunctionArrayConversions and UsualUnaryConversions to return void. The caller
needs to query the expression for the type. Since both these functions guarantee the expression 
contains a valid type, removed old/vacuous asserts (from code calling both of these routines).

llvm-svn: 39930
2007-07-16 21:54:35 +00:00
Chris Lattner bb1b44f004 Make octal constant lexing use AdvanceToTokenCharacter to give more
accurate diagnostics.  For test/Lexer/comments.c we now emit:

int x = 000000080;  /* expected-error {{invalid digit}} */
               ^
constants.c:7:4: error: invalid digit '8' in octal constant
00080;             /* expected-error {{invalid digit}} */
   ^


The last line is due to an escaped newline.  The full line looks like:

int y = 0000\
00080;             /* expected-error {{invalid digit}} */


Previously, we emitted:
constants.c:4:9: error: invalid digit '8' in octal constant
int x = 000000080;  /* expected-error {{invalid digit}} */
        ^
constants.c:6:9: error: invalid digit '8' in octal constant
int y = 0000\
        ^

which isn't too bad, but the new way is better for the user,
regardless of whether there is an escaped newline or not.

All the other lexer-related diagnostics should switch over 
to using AdvanceToTokenCharacter where appropriate.  Help
wanted :).

This implements test/Lexer/constants.c.

llvm-svn: 39906
2007-07-16 06:55:01 +00:00
Chris Lattner fc7634f2ab "Someone typed "PtrToInt" where they meant "IntToPtr".
I've added a tests/CodeGen directory, and a test for this case that
used to fail and now passes."

Patch by Keith Bauer

llvm-svn: 39794
2007-07-13 03:25:53 +00:00
Steve Naroff 1c8b7d36e6 Two changes...
- Teach all the integer/float predicates on Type about Vectors.
- Disallow bitwise compliment on float vectors. For example...

typedef float __attribute__(( vector_size(16) )) float4;

float4 float4_return()
{
    float4 xx;

    return ~xx;
}

...now emits the following diagnostic...

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang bug.c
bug.c:8:12: error: invalid argument type to unary expression 'float4'
    return ~xx;
           ^
1 diagnostic generated.

llvm-svn: 39791
2007-07-12 21:46:55 +00:00
Steve Naroff b207d6bed7 Bug #:
Submitted by:
Reviewed by:
Removed Attr.[h,cpp]...they didn't have any useful content.

When more (GCC) attributes are added, we might want to create a file
of this ilk. For now, it's better to remove them (to eliminate any confusion).

I also update the Xcode project file...

llvm-svn: 39729
2007-07-11 00:42:37 +00:00
Chris Lattner ea035b5fb8 remove diagchecker.h, add more missing files.
llvm-svn: 39702
2007-06-28 04:42:53 +00:00
Chris Lattner 76148a9ded add diag checker to xcode proj
llvm-svn: 39691
2007-06-27 17:25:13 +00:00
Chris Lattner 3e3a1e9cda implement lowering of complex types
llvm-svn: 39668
2007-06-22 18:15:26 +00:00
Chris Lattner 1fde0b345b implement codegen of the relational operations
One major FIXME though.

llvm-svn: 39666
2007-06-20 18:30:55 +00:00
Chris Lattner b3fef07a30 add new files to xcode project
llvm-svn: 39662
2007-06-16 00:17:33 +00:00
Chris Lattner 23cff88741 Update the xcode project for bill
llvm-svn: 39651
2007-06-13 20:14:12 +00:00
Steve Naroff 6d26a892d4 Bug #:
Submitted by:
Reviewed by:
Move Attr.h to the correct group in the Xcode project file...

llvm-svn: 39630
2007-06-09 03:59:22 +00:00
Steve Naroff b309644a35 Bug #:
Submitted by:
Reviewed by:
Lot's of attribute scaffolding.
Modernized ParseArraySubscriptExpr...call DefaultFunctionArrayConversion (which
simplified the logic considerably) and upgrade Diags to use the range support.

llvm-svn: 39628
2007-06-09 03:47:53 +00:00
Chris Lattner 2c1720681f add a new text file for low-prio QOI todos
llvm-svn: 39606
2007-06-08 17:15:31 +00:00
Chris Lattner 328fa5c913 Emit better diagnostics for out of range digits:
diag.c:1:9: error: invalid digit '8' in octal constant
int x = 000080;
        ^
diag.c:2:9: error: invalid digit 'A' in decimal constant
int z = 1000080ABC;
        ^

instead of:

diag.c:1:9: error: invalid suffix '80' on integer constant
int x = 000080;
        ^
diag.c:2:9: error: invalid suffix 'ABC' on integer constant
int z = 1000080ABC;
        ^

llvm-svn: 39605
2007-06-08 17:12:06 +00:00
Bill Wendling 37b1ddecf6 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Separated out the diagnostic client from the clang driver. This is in
  preparation for creating a diagnostic client that will be used to check
  error and warning messages.

llvm-svn: 39603
2007-06-07 09:34:54 +00:00
Steve Naroff 98cf3e95ce Bug #:
Submitted by:
Reviewed by:

The following code illustrates a bug in the semantic analysis for assignments:

int func() {
  int *P;
  char *x;
  P = x; // type of this assignment expression should be "int *", NOT "char *".
}

While the type checking/diagnostics are correct, the type of the assignment
expression is incorrect (which shows up during code gen).  With the fix,
the llvm code looks correct...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang cast.c -emit-llvm
cast.c:4:5: warning: incompatible pointer types assigning 'char *' to 'int *'
  P = x; // type of assignment expression is "int *", NOT "char *".
  ~ ^ ~
; ModuleID = 'foo'

define i32 @func() {
entry:
        %P = alloca i32*                ; <i32**> [#uses=1]
        %x = alloca i8*         ; <i8**> [#uses=1]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
        %tmp = load i8** %x             ; <i8*> [#uses=1]
        %conv = bitcast i8* %tmp to i32*                ; <i32*> [#uses=1]
        store i32* %conv, i32** %P
        ret i32 undef
}

Even though the fix was simple, I decided to rename/refactor the surrounding code
to make a clearer distinction between constraint checking and conversion.

- Renamed AssignmentConversionResult -> AssignmentCheckResult.
- Renamed UsualAssignmentConversions -> CheckAssignmentConstraints.
- Changed the return type of CheckAssignmentConstraints and CheckPointerTypesForAssignment
from QualType -> AssignmentCheckResult. These routines no longer take a reference to the result (obviously).
- Changed CheckAssignmentOperands to return the correct type (with spec annotations).

llvm-svn: 39601
2007-06-06 18:38:38 +00:00
Chris Lattner cf106ab42a implement support for casts to/from pointers.
llvm-svn: 39595
2007-06-06 04:05:39 +00:00
Chris Lattner 6563712933 xcode randomly changed the project, who knows what this does
llvm-svn: 39594
2007-06-05 20:53:44 +00:00
Steve Naroff 6d9de3dd74 Bug #:
Submitted by:
Reviewed by:
Touch up a couple comments (one was incorrect/out-of-date).

llvm-svn: 39589
2007-06-05 19:14:28 +00:00
Chris Lattner 946aa31f02 implement codegen of while stmts and lvalue evaluation of paren exprs :)
llvm-svn: 39582
2007-06-05 03:59:43 +00:00
Steve Naroff c27f89ebb3 Bug #:
Submitted by:
Reviewed by:
Apply UsualUnaryConversion() to statement conditions that expect scalars.
UsualUnaryConversion() converts function/arrays to pointers.

This fixes the following...

int func() {
  int A[10];
  while (A) {
  }
  if (A) ;
  for (; A; ) ;
}

llvm-svn: 39580
2007-06-03 18:23:48 +00:00
Chris Lattner d7f58867e5 Implement scaffolding for lvalues. Implement block vardecl lvalues.
This allows us to translate:

int func() {
  register int X;
  {
    int Y;
    return 1+X+Y;
  }
}

into:

define i32 @func() {
entry:
        %X = alloca i32         ; <i32*> [#uses=1]
        %Y = alloca i32         ; <i32*> [#uses=1]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
        %tmp = load i32* %X             ; <i32> [#uses=1]
        %tmp1 = add i32 1, %tmp         ; <i32> [#uses=1]
        %tmp2 = load i32* %Y            ; <i32> [#uses=1]
        %tmp3 = add i32 %tmp1, %tmp2            ; <i32> [#uses=1]
        ret i32 %tmp3
                ; No predecessors!
        ret i32 undef
}

llvm-svn: 39555
2007-06-02 05:24:33 +00:00
Chris Lattner 5e1f32a16f reorder files alphabetically
llvm-svn: 39551
2007-06-02 04:47:52 +00:00
Chris Lattner 3e450f947b add new files.
llvm-svn: 39544
2007-06-02 00:01:41 +00:00
Steve Naroff 0f2fe17ff1 Bug #:
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.

- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.

Still to do...hook up to the Decl...

llvm-svn: 39539
2007-06-01 17:11:19 +00:00
Chris Lattner d1af2d2956 Implement conversion of clang ast types to LLVM types, at least for some trivial
cases.

llvm-svn: 39519
2007-05-29 23:17:50 +00:00
Steve Naroff 8563f65042 Bug #:
Submitted by:
Reviewed by:
Refine Sema::ParseCallExpr() diags (range support, add types).

Before:

func-assign.c:27:11: warning: passing argument 1 from incompatible pointer type
  pintFunc(&FOO);
          ^
func-assign.c:28:12: error: incompatible type for argument 1
  floatFunc(&FOO);
           ^
func-assign.c:29:12: error: too many arguments to function
  floatFunc(1,2,3);
           ^
After:

func-assign.c:27:11: warning: passing incompatible pointer 'struct foo *' to function expecting 'int *'
  pintFunc(&FOO);
  ~~~~~~~~^~~~~
func-assign.c:28:12: error: passing incompatible type 'struct foo *' to function expecting 'float'
  floatFunc(&FOO);
  ~~~~~~~~~^~~~~
func-assign.c:29:12: error: too many arguments to function
  floatFunc(1,2,3);
  ~~~~~~~~~^  ~

llvm-svn: 39513
2007-05-28 19:25:56 +00:00
Chris Lattner eefa10e78a implement full sema support for the GCC address-of-label extension.
llvm-svn: 39510
2007-05-28 06:56:27 +00:00
Chris Lattner bed314465a Reorganize codegen files.
llvm-svn: 39504
2007-05-28 01:07:47 +00:00
Steve Naroff 9358c715da Bug #:
Submitted by:
Reviewed by:
- Added type checking to Sema::ParseReturnStmt (still under construction).
- Improved Expr::isLvalue() and Expr::isModifiableLvalue() to return more
info. Used the info in Sema::CheckAssignmentOperands() to produce more
descriptive diagnostics. Added FIXME to other clients of isLvalue()/etc.
- Added a SourceLocation slot to MemberExpr...changed the implementation
of getSourceRange().
- Added getResultType() helper to FunctionDecl.
- Changed many Diag calls to use the SourceRange support (now that it's
a big hit...we better milk it:-).

llvm-svn: 39501
2007-05-27 23:58:33 +00:00
Chris Lattner f97fe38cb5 Initial scaffolding for an -emit-llvm mode. This requires the LLVM VMCore
library to be built for the driver to link.

llvm-svn: 39495
2007-05-24 06:29:05 +00:00
Chris Lattner c31f4545d1 add ParseExprCXX.cpp to project.
llvm-svn: 39491
2007-05-24 01:09:15 +00:00
Chris Lattner f95211394a implement printer support for C++ bool literals
llvm-svn: 39489
2007-05-24 00:50:25 +00:00
Steve Naroff 7fd6893333 Bug #:
Submitted by:
Reviewed by:
One bug compiling "Carbon.h" on Leopard, one diagnostic tweak.
- CheckIndirectionOperand wasn't operating on the canonical type (so it
was complaining about typedef names).
- The diagnostic was less than great. Here's what is was:

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.c
t.c:4:3: error: invalid argument type to unary expression 'int'
 *p;
 ^~

And here's what I changed it to...

snaroff:clang naroff$ ../../Debug/bin/clang bug.c
bug.c:5:3: error: indirection requires a pointer ('int' operand invalid)
  *p;
  ^~

llvm-svn: 39481
2007-05-22 18:27:41 +00:00
Chris Lattner a8a2c82f55 Move ASTStreamer.h into "clang/Sema/ASTStreamer.h"
llvm-svn: 39478
2007-05-21 17:38:36 +00:00
Chris Lattner d1654ef0ed Split the AST library into two libraries: libast and libsema.
llvm-svn: 39477
2007-05-21 17:34:19 +00:00
Chris Lattner 67ca9252f8 Implement Sema::ParseNumericConstant for integer constants in terms of APInt
and correctly in terms of C99 6.4.4.1p5.

llvm-svn: 39473
2007-05-21 01:08:44 +00:00
Steve Naroff ada7d4298b Bug #:
Submitted by:
Reviewed by:
Fix two bugs...

- Sema::CheckConditionalOperands(). Needed to move the check for
null pointer constants up to the clause dealing with two pointers types.
The previous code would never get executed.
- Expr::isNullPointerConstant(). This predicate was much too naive...it
should have had a FIXME (my bad). It now deals with "void *" cast expressions.
It still has one major bug...it needs to evaluate the expression to correctly
determine if it is a null pointer constant (e.g. 7-7 should pass).

llvm-svn: 39464
2007-05-20 17:54:12 +00:00
Chris Lattner ebd1b33477 Use the new source ranges tracking feature to highlight the important pieces
of a subexpression when emitting a diagnostic.  Consider this example:

struct A { int X; };

void test1(void *P, int C) {
  return ((C*40) + *P) / 42+P;
}

void test2(struct A friendlystruct, int C) {
  return (C     *40) + friendlystruct;
}

void test3(struct A friendlystruct, int C) {
  return friendlystruct + test2(friendlystruct
                               , C);
}


clang now produces this output:

t.c:4:18: error: invalid operands to binary expression ('int' and 'void')
  return ((C*40) + *P) / 42+P;
          ~~~~~~ ^ ~~

This shows the important pieces of a nested (and potentially very complex)
expression.


t.c:8:18: error: invalid operands to binary expression ('int' and 'struct A')
  return (C     *40) + friendlystruct;
         ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~

This shows that tabs in source files (after the 'C') and multichar tokens
(friendlystruct) are handled correctly.



t.c:12:25: error: invalid operands to binary expression ('struct A' and 'void')
  return friendlystruct + test2(friendlystruct
         ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~

This shows how multiline ranges are printed.  Any part of the range that is
not on the same line as the carat is just ignored.  This also shows that
trailing spaces on the line aren't highlighted.

llvm-svn: 39459
2007-05-19 08:06:14 +00:00
Steve Naroff e845e272ba Bug #:
Submitted by:
Reviewed by:
More tweaks to error diagnostics (adding types, using the new hooks on expr).
Still more to do...

llvm-svn: 39455
2007-05-18 01:06:45 +00:00
Steve Naroff a78fe7e3ed Bug #:
Submitted by:
Reviewed by:
- Implement type checking for Sema::CheckConditionalOperands.
- Fixed crasher in Sema::UsualUnaryConversion (incorrect use of cast<>).
- Added a few diagnostics and started passing 2 args! (Thanks Chris!).

Here's some diagnostic output that is much nicer than gcc...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang cond.c
cond.c:12:14: error: used type 'struct foo' where arithmetic or pointer type is required
  result = s ? 1 : 2;
             ^
cond.c:13:14: error: incompatible operand types ('struct foo' and 'struct bar')
  result = a ? s : s2;
             ^
cond.c:14:14: warning: pointer type mismatch ('struct foo *' and 'struct bar *')
  result = a ? ps : ps2;
             ^
cond.c:14:10: warning: assignment makes integer from pointer without a cast
  result = a ? ps : ps2;
         ^
cond.c:15:14: error: incompatible operand types ('struct foo *' and 'struct foo')
  result = a ? ps : s;
             ^
cond.c:16:14: warning: pointer type mismatch ('void (*)(int)' and 'void (*)(int, int)')
  result = a ? func : func2;
             ^
cond.c:16:10: warning: assignment makes integer from pointer without a cast
  result = a ? func : func2;
         ^
7 diagnostics generated.
[dylan:~/llvm/tools/clang] admin% cc -c cond.c
cond.c: In function 'main':
cond.c:12: error: used struct type value where scalar is required
cond.c:13: error: type mismatch in conditional expression
cond.c:14: warning: pointer type mismatch in conditional expression
cond.c:14: warning: assignment makes integer from pointer without a cast
cond.c:15: error: type mismatch in conditional expression
cond.c:16: warning: pointer type mismatch in conditional expression
cond.c:16: warning: assignment makes integer from pointer without a cast

llvm-svn: 39451
2007-05-16 19:47:19 +00:00
Chris Lattner 36982e4367 Add support for inserting up to 10 strings in a diagnostic, with %0, %1, %2,
etc.

llvm-svn: 39447
2007-05-16 17:49:37 +00:00
Steve Naroff 475cca0d1a Bug #:
Submitted by:
Reviewed by:
Fixed a bug in Sema::CheckAddressOfOperand(). It was (incorrectly) using
isModifiableLvalue() instead of isLvalue(). This motivated me to (finally)
cleanup methods surrounding lsLvalue/isModifiableLvalue. Cleanup involved:
- adding Expr::isLvalue().
- modified Expr::isModifiableLvalue() to use Expr::isLvalue().
- removed Type::isLvalue(), Type::isModifiableLvalue(), and
QualType::isModifiableLvalue(). They were confusing...the respective logic
is now a part of the Expr member functions...
- also added some comments and spec references, since these methods are
so central to expressions working properly.

llvm-svn: 39443
2007-05-14 17:19:29 +00:00
Steve Naroff 38a9dae33f Bug #:
Submitted by:
Reviewed by:
- implement Type::functionTypesAreCompatible().
- fix bug in Sema::CheckAssignmentOperands(). Spec allows any pointer type
to be assigned to _Bool.

llvm-svn: 39428
2007-05-02 19:22:16 +00:00
Chris Lattner 739e739b81 Remove the clang::SourceBuffer class, switch to the llvm::MemoryBuffer class.
llvm-svn: 39426
2007-04-29 07:12:06 +00:00
Steve Naroff 4750051ebb Bug #:
Submitted by:
Reviewed by:
Continue working on type checking for unary operators. Added:

- Two 3 private functions to Sema: CheckAddressOfOperand(), CheckIndirectionOperand(),
and getDecl().
- Added Expr::isLvalue() - it was needed for CheckAddressOfOperand(). It will
also be needed for ++/-- and the assignment operators.
- Added a couple diagnostics for invalid lvalues (for & of).

llvm-svn: 39408
2007-04-19 23:00:49 +00:00
Chris Lattner 86054a9634 Diagnostics relating to computation of values should only be produced if an
expression is live.  For example:
#if 0 ? 124/0 : 42

should cause no error.

This implements test/Preprocessor/expr_liveness.c

llvm-svn: 39397
2007-04-10 05:26:38 +00:00
Steve Naroff d50c88e489 Bug #:
Submitted by:
Reviewed by:
Fix "FIXME: does this lose qualifiers from the typedef??" in ASTContext::getTypedefType().

This change was fairly pervasive...nevertheless, here are the highlights:
- Change the type of Type::CanonicalType to TypeRef (was "Type *").
- Change the implementation of TypeRef::getCanonicalType() to work for typedefs.
- Make the implementation of Type::getCanonicalType private (only TypeRef should access). This
will force clients to use TypeRef::getCanonicalType (the correct version of the function). Since
TypeRef overloads "->", it was very easy to fall into this bug...
- Changed many references of "Type *" to "TypeRef"...when the raw type pointer is required, use t.getTypePtr().
- Changed all the *Type classes to take a TypeRef.
- Made the Type constructor protected (cleanup).
- Removed function Expr::getType().
- Convert functions in SemaExpr to use the above support. This fixed the "const" bug I was originally investigating.

I will follow this check-in up with a rename of TypeRef->QualType. I will also make sure the constructor does not default to 0 (which can lead to broken code...).

llvm-svn: 39394
2007-04-05 21:15:20 +00:00
Chris Lattner ef8743b4f6 Move LiteralSupport files to their alphabetic position.
llvm-svn: 39384
2007-04-04 06:45:50 +00:00
Steve Naroff ef2ab6a572 Bug #:
Submitted by:
Reviewed by:
Add three new classes to Decl.h: BlockVarDecl, FileVarDecl, and ParmVarDecl.

Made the constructor to VarDecl protected, to indicate it is "abstract".

Reorganized the Decl::Kind enum to allow us to add ObjectDecls/TypeDecls with
minimal breakage.  In the process, realized the isa support for ObjectDecl was already broken (so
the reorg paid for itself already:-) The range check should also be more efficient...

llvm-svn: 39373
2007-04-02 20:50:54 +00:00
Steve Naroff fc49d67add Bug #:
Submitted by:
Reviewed by:
- Finished up incomplete type analysis for varibles (in Sema::ParseDeclarator()).
- Added many spec refs, since this area is confusing (for top level decls
in particular).
- Added a FIXME to MergeVarDecl()...it needs to be taught about tentative
definitions. As a result, we currently issue some bogus diagnostics.

llvm-svn: 39372
2007-04-01 21:27:45 +00:00
Steve Naroff 09ef474197 Bug #:
Submitted by:
Reviewed by:
Moved numeric literal support from SemaExpr.cpp to LiteralSupport.[h,cpp]
in Lex. This will allow it to be used by both Sema and Preprocessor (and
should be the last major refactoring of this sub-system).. Over
time, it will be reused by anyone implementing an actions module (i.e.
any subclass of llvm::clang::Action. Minor changes to IntegerLiteral in Expr.h.
More to come...

llvm-svn: 39351
2007-03-09 23:16:33 +00:00
Steve Naroff 8160ea2072 Bug #:
Submitted by:
Reviewed by:
More code to parse numeric constants. This checkin includes:
- Feedback from Chris.
- Support for parsing floating point constants.
- Moved the code to "Sema". Changed API in Action.
- More/better error diagnostics.

At this point, the parsing support should be largely complete. Next step
is to work on filling in sensible values (in IntegerLiteral/FloatLiteral).

llvm-svn: 39349
2007-03-06 01:09:46 +00:00
Steve Naroff 1fb30c5e99 Bug #:
Submitted by:
Reviewed by:
First phase of parsing IntegerConstants. At the moment, all processing
is done in the Parser, not Sema. If necessary, this is easy to move.
Next steps:
- Convert well for strings to actual values (need to look @ APInt.h)
- Design the API between the Parser and Sema. Sema shouldn't have to be
concerned with any parsing issues...

llvm-svn: 39348
2007-03-03 00:02:57 +00:00
Steve Naroff 7f890eb790 More changes to complete the dynamic type support for Stmt/Expr.
This set of changes includes:
- convert ExprCXX.h and add to the Xcode project file.
-- required adding CXXBoolLiteralExpr to StmtNodes.def.
-- required adding visitor support (decl/defn).
- make the class codes in StmtNodes.def explicit (to enable range checking).
-- this required changing all clients of the STMT macro.
- declare the instance data const.

llvm-svn: 39344
2007-02-27 02:53:10 +00:00
Steve Naroff ab62488ae3 rename IntegerConstant->IntegerLiteral
rename FloatingConstant->FloatingLiteral
rename StringExpr->StringLiteral

llvm-svn: 39341
2007-02-21 22:05:47 +00:00
Chris Lattner 10a5b387cc Add support for target-specific builtins, including detecting nonportability
of source code.  For example:

$ clang INPUTS/carbon_h.c -arch i386 -arch ppc
prints:
...
/usr/lib/gcc/i686-apple-darwin8/4.0.1/include/mmintrin.h:51:3: note: use of a target-specific builtin function, source is not 'portable'
  __builtin_ia32_emms ();
  ^

because carbon.h pulls in xmmintrin.h, and __builtin_ia32_emms isn't a builtin on ppc.

Though clang now supports target-specific builtins, the full table isn't implemented yet.

llvm-svn: 39328
2007-01-29 05:24:35 +00:00
Chris Lattner 9561a0b3e7 Add support for target-independent builtin functions (like __builtin_abs),
whose decl objects are lazily created the first time they are referenced.
Builtin functions are described by the clang/AST/Builtins.def file, which
makes it easy to add new ones.

This is missing two important pieces:
1. Support for the rest of the gcc builtins.
2. Support for target-specific builtins (e.g. __builtin_ia32_emms).

Just adding this builtins reduces the number of implicit function definitions
by 6, reducing the # diagnostics from 550 to 544 when parsing carbon.h.

I need to add all the i386-specific ones to eliminate several hundred more.
ugh.

llvm-svn: 39327
2007-01-28 08:20:04 +00:00
Chris Lattner 4194315681 Save the member list of a struct/union in the RecordDecl for the struct.
llvm-svn: 39297
2007-01-25 04:52:46 +00:00
Chris Lattner 7b9ace672b simplify structure body parsing code. Reorganize how tags are processed.
Diagnose redefintion of tag types, e.g.:

t.c:7:8: error: redefinition of 'blah'
struct blah {};
       ^
t.c:1:8: error: previous definition is here
struct blah {
       ^
2 diagnostics generated.

llvm-svn: 39286
2007-01-23 20:11:08 +00:00
Chris Lattner b8d6d5a81d Formalize preprocessor callbacks together into a PPCallbacks structure, instead
of having a loose collection of function pointers.  This also allows clients to
maintain state, and reduces the size of the Preprocessor.h interface.

llvm-svn: 39203
2006-11-21 04:09:30 +00:00