aboutsummaryrefslogtreecommitdiff
path: root/AST/Expr.cpp
AgeCommit message (Collapse)Author
2007-11-12Now that we can refer to instance variables, make sure they are considered ↵Steve Naroff
lvalues. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44017 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-12Implement instance variable references.Steve Naroff
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44016 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09Recognize ObjCStringLiteral as a constant expression.Steve Naroff
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43946 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-08Fix backwards assert.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43894 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-03Add a method prototype slot/getter to the ObjCMessageExpr AST.Steve Naroff
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43666 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-01Implement test/Sema/init.c by treating functions as constants.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43599 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-30__real__ and __imag__ can be lvalues. Add support to ast and codegen for them.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43525 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-25Add a new ChooseExpr::isConditionTrue method to unifyChris Lattner
some code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43322 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-18Fixed DeclStmt::child_begin() to actually create an iterator thatTed Kremenek
visits its decls, rather than just creating an "end()" iterator. Fixed child_end() for statements and expressions to use child_iterator() to create the end() iterator, rather than just returning NULL. Fixed bug in StmtIterator where we did not correctly detect if we had marched off the end of the ScopedDecls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43156 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-18Make control flow in Expr::isConstantExpr more simple andChris Lattner
local, making the code easier to read. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43104 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-17Implementation of AST for @protocol expression.Fariborz Jahanian
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43075 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-17Generate code for static variables that don't have initializers. Also, ↵Anders Carlsson
report an error if a static initializer is not constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43058 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-16Patch to implement AST generation for objective-c's @selector expression.Fariborz Jahanian
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43038 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-15Move type compatibility predicates from Type to ASTContext. In addition, the ↵Steve Naroff
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43009 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-15Add code generation and sema checking for __builtin_va_arg.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43006 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-07move IdentifierTable.h from liblex to libbasic.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42730 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-28Yesterday I discovered that 78% of all selectors in "Cocoa.h" take 0/1 argument.Steve Naroff
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42452 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-27Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference ↵Steve Naroff
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42395 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-26objc messages have side effects, return true from hasLocalSideEffect,Chris Lattner
fixing: VoidMethod.m:14:5: warning: expression result unused [Greeter hello]; ^~~~~~~~~~~~~~~ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42380 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-26Handle (int)1.0e40 as an i-c-e.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42334 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-25use the right rounding mode.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42291 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-22Use the APFloat routines to evaluate FP immediates as Chris Lattner
integer constant expressions. The only questionable thing is that we now reject: void foo() { switch (1) { case (int)1.0e10000: ; } } with: t.c:5:13: error: case label does not reduce to an integer constant case (int)1.0e10000: ~~~~~^~~~~~~~~ GCC accepts this, emitting the pedwarn: t.c:5: warning: floating constant exceeds range of 'double' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42238 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-22further apfloat'ize the front-end, allowing codegen to pass Chris Lattner
APFloat straight through to LLVM now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42236 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-19Remove SelectorTable/SelectorInfo, simply store all selectors in the central ↵Steve Naroff
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42139 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-18Progress on message expressions...Steve Naroff
- 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... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42116 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-16Silenced a VC++ warning.Hartmut Kaiser
Updated VC++ project files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42015 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-04Silence VC++ warnings, patch by Hartmut KaiserChris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41693 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-02More progress on array initializers.Steve Naroff
- Added Expr::isConstantExpr(). - Added type checking for InitListExpr elements. - Added diagnostic for trying to initialize a variable sized object. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41674 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31Add InitListExpr class.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41636 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-30implement initial sema support for __builtin_offsetofChris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41613 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-29Re-teach Expr::isNullPointerConstant() about ImplicitCastExpr:-)Steve Naroff
This fixes the following bug submitted by Neil... const char *f (void) { return 0; } ...which would incorrectly warn with -pedantic enabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41559 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-28Teach Expr::isNullPointerConstant() about ImplicitCastExpr's.Steve Naroff
This fixes the following (recent) regression noticed by Keith Bauer (thanks!). void func(void *a); main() { void *p; p = 0; func(0); } ...which now works as you would expect. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41557 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-27Fixed bug in child_begin/child_end for CallExpr where we incorrectly ↵Ted Kremenek
calculated a Stmt** pointer based on an offset within SubExprs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41512 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-26add a new ImaginaryLiteral AST node that is used toChris Lattner
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)))) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41413 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-25Surpress the UsualUnaryConversions for compound assignment operators. This ↵Steve Naroff
change eliminates the possibility that the left hand expression is an ImplicitCastExpr. As a result, I removed the check for ImplicitCastExpr in Expr::isLvalue(). This results in the following AST's... [dylan:~/llvm/tools/clang] admin% cat fix.c short x; void test4(char c) { x += c; x = x + c; } [dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang fix.c -parse-ast-dump Read top-level variable decl: 'x' void test4(char c) (CompoundStmt 0x2605d30 (CompoundAssignOperator 0x2605c40 'short' '+=' (DeclRefExpr 0x2605c00 'short' Decl='x' 0x2605a80) (DeclRefExpr 0x2605c20 'char' Decl='c' 0x2605bc0)) (BinaryOperator 0x2605d10 'short' '=' (DeclRefExpr 0x2605c60 'short' Decl='x' 0x2605a80) (ImplicitCastExpr 0x2605d00 'short' (BinaryOperator 0x2605ce0 'int' '+' (ImplicitCastExpr 0x2605cc0 'int' (DeclRefExpr 0x2605c80 'short' Decl='x' 0x2605a80)) (ImplicitCastExpr 0x2605cd0 'int' (DeclRefExpr 0x2605ca0 'char' Decl='c' 0x2605bc0)))))) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41404 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-25Change Expr::isLvalue() to properly deal with ImplicitCastExpr's.Steve Naroff
This fixes the following bug... t.c:1:31: error: expression is not assignable short x; void foo(char c) { x += c; } This case, among others are now captured in implicit-casts.c. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41402 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-25Split the ASTNode out for compound assignments out from binary operators. NowChris Lattner
they show up in dumps etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41393 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-25fix off-by-one errorChris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41392 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-24Finished adding child_begin/child_end to all subclasses of Stmt in Expr.h.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41366 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-24Began implementing "child iterator" interface for Stmts and Exprs. EachTed Kremenek
subclass of Stmt will implement child_begin() and child_end(), which will be used to iterate over all the children (subexpressions/substatements) of a Stmt object. This will provide for easy traversal over the AST, which is useful for a variety of purposes. None of the interfaces to subclasses of Stmt will be changed (other than adding the child_begin and child_end methods). The only caveat is that the implementation of subclasses of Stmt will require colocating all substatements (subexpressions) in an array. This is because we define child_iterator as Stmt**. All accessor methods to subexpressions will need to be altered to reflect this new implementation. This patch includes the typedefs for child_iterator, as well the implementation for child_begin/child_end for the primary expressions and some postfix expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41363 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-23sizeof(x) doesn't require x to be an i-c-e for sizeof to be an i-c-e. ↵Chris Lattner
Thanks to Neil for pointing this out. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41338 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-08Finish implementing __builtin_classify_type()...Steve Naroff
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40951 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-03Rename AddrLabel and OCUVectorComponent -> AddrLabelExpr and ↵Chris Lattner
OCUVectorElementExpr respectively. This is for consistency with other expr nodes end with *Expr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40785 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-03add OCUVectorComponent::getNumComponents()Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40778 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-02Add support for encoding a OCUVectorComponent into a single integer.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40768 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-02rename some helpers, have them return the idx of the field being accessed.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40764 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-02Use static methods, which don't require an instance of OCUVectorTypeChris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40763 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-02Minor comment improvements.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40760 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-02Tweak to Expr::isIntegerConstantExpr...make sure the result is appropriately ↵Steve Naroff
size for TypesCompatibleExpr's. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40716 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-02Hack Expr::isConstantExpr() to allow for __builtin_types_compatible_p.Steve Naroff
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40705 91177308-0d34-0410-b5e6-96231b3b80d8