Commit Graph

619 Commits

Author SHA1 Message Date
Fariborz Jahanian 9c196795e6 Fixed a comment.
llvm-svn: 60611
2008-12-05 22:36:19 +00:00
Fariborz Jahanian fbbaf6afae This test checks for duplicate implementation of the same
property. It also checks for duplicate use of the same ivar
in two different iproperty implementations. It also caught
an error for a test case used in CodeGen :).

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

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

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

llvm-svn: 60597
2008-12-05 18:15:24 +00:00
Anders Carlsson 98463cd44d This wasn't such a good idea after all as it broke some tests.
llvm-svn: 60582
2008-12-05 05:24:13 +00:00
Anders Carlsson 3bc1d7d3d3 Handle __builtin___CFStringMakeConstantString in Expr::Evaluate.
llvm-svn: 60581
2008-12-05 05:18:05 +00:00
Steve Naroff 4588d0f060 Several things...
- Implement RewritePropertySetter(). While the routine is simple, there were some tricky changes to RewriteFunctionBodyOrGlobalInitializer(), the main rewriter loop. It also required some additional instance data to distinguish setters from getters, as well as some changes to RewritePropertyGetter().

- Implement FIXME: for pretty printing ObjCPropertyRefExpr's.

- Changed ObjCPropertyRefExpr::getSourceRange() to point to the end of the property name (not the beginning). Also made a minor name change from "Loc"->"IdLoc" (to make it clear the Loc does not point to the ".").
 

llvm-svn: 60540
2008-12-04 16:24:46 +00:00
Sebastian Redl ba3fdfcbff Fix some type punning errors in SizeOfAlignOf and Typeid AST nodes. This should satisfy compilers and language lawyers alike.
llvm-svn: 60511
2008-12-03 23:17:54 +00:00
Sebastian Redl d6d55eeef5 Correct pretty printing of array new expressions.
llvm-svn: 60444
2008-12-02 22:08:59 +00:00
Sebastian Redl 351bb78a10 Handle new by passing the Declaration to the Action, not a processed type.
llvm-svn: 60413
2008-12-02 14:43:59 +00:00
Fariborz Jahanian 015a48d1db This patch corrects problem in searching for a setter/getter method for
a property. Previous scheme of seaching in interface's list of methods
would not work because this list is not yet constructed. This is in preparation
for doing semantic check on viability of setter/getter method declarations.

llvm-svn: 60386
2008-12-02 00:19:12 +00:00
Steve Naroff e1908e393e -Add several ObjC types to Decl::getDeclKindName(), a useful debug hook.
-Start adding support for rewriting @synthesize.

llvm-svn: 60368
2008-12-01 20:33:01 +00:00
Douglas Gregor 95c326d14a Use EmitInt, not Emit, to emit unsigned values
llvm-svn: 60364
2008-12-01 19:45:16 +00:00
Anders Carlsson 5b3638b6e7 Generate the correct results for the comma expression. Fixes PR3123.
llvm-svn: 60334
2008-12-01 06:44:05 +00:00
Anders Carlsson eade3ad1f1 Revert change that made isNullPointerConstant start emitting warnings. We don't want that :)
llvm-svn: 60333
2008-12-01 06:28:23 +00:00
Anders Carlsson e7c2ac4b54 Remove dead code.
llvm-svn: 60320
2008-12-01 02:25:52 +00:00
Anders Carlsson 4bb9113da4 Add a new variant of isNullConstantExpr that returns an EvalResult.
llvm-svn: 60318
2008-12-01 02:13:57 +00:00
Anders Carlsson 564730a857 Emit the correct diagnostic when a comma is in an ICE.
llvm-svn: 60316
2008-12-01 02:07:06 +00:00
Anders Carlsson b33d6c8611 Change the diagnostics that the evaluator reports to be of type NOTE.
llvm-svn: 60301
2008-11-30 18:37:00 +00:00
Anders Carlsson 5862001157 Replace the isEvaluated bool with a ShortCircuit int, making it easier to handle recursion
llvm-svn: 60300
2008-11-30 18:26:25 +00:00
Anders Carlsson 27b8c5c464 Pass the expression to the Error and Extension methods.
llvm-svn: 60299
2008-11-30 18:14:57 +00:00
Anders Carlsson 7b6f0af83f Add a new variant of Evaluate and reimplement the old Evaluate in terms of the new.
llvm-svn: 60298
2008-11-30 16:58:53 +00:00
Anders Carlsson f50de0c590 General cleanup, evaluate the RHS of a logical op even if the LHS will give us the result.
llvm-svn: 60297
2008-11-30 16:51:17 +00:00
Anders Carlsson bd1df8e866 EvalInfo now holds a reference to an EvalResult struct.
llvm-svn: 60296
2008-11-30 16:38:33 +00:00
Douglas Gregor 3be4b122d3 Implement the GNU __null extension
llvm-svn: 60235
2008-11-29 04:51:27 +00:00
Chris Lattner 9d72ff710e Switch QualType to use llvm::PointerIntPair internally to do the pointer
bitmangling.

llvm-svn: 60226
2008-11-28 23:37:31 +00:00
Nuno Lopes 615f34c719 remove debug-only assertion in the complex float evaluator as it makes some real apps crash
llvm-svn: 60069
2008-11-26 00:39:53 +00:00
Fariborz Jahanian 829b908b74 Refactored checking on readonly property into a method.
llvm-svn: 60050
2008-11-25 21:48:26 +00:00
Fariborz Jahanian 9a207ee4dc Patch to allow over-riding of readonly property to
a writable property in one of its category.

llvm-svn: 60035
2008-11-25 17:56:43 +00:00
Anders Carlsson 28a423f42e Remove more #ifdeffed code
llvm-svn: 60033
2008-11-25 17:16:39 +00:00
Ted Kremenek e03879b8ad Fix CFG bug where the 'increment' block for a 'for' statement would not be
properly reversed once constructed.

This fixes PR 3125:

http://llvm.org/bugs/show_bug.cgi?id=3125

llvm-svn: 59982
2008-11-24 20:50:24 +00:00
Anders Carlsson a7c5eb72a0 Reimplement Expr::isConstantExpr in terms of Expr::Evaluate. This fixes PR2832.
llvm-svn: 59946
2008-11-24 05:23:59 +00:00
Anders Carlsson a42ee44aab The address of a variable is only constant if the variable has global storage.
llvm-svn: 59939
2008-11-24 04:41:22 +00:00
Anders Carlsson 4c76e93507 Fix bug in the constant evaluator. Fixes PR3115.
llvm-svn: 59938
2008-11-24 04:21:33 +00:00
Chris Lattner 1cbaacc4a0 Migrate some stuff from NamedDecl::getName() to
NamedDecl::getNameAsString() to make it more explicit.

llvm-svn: 59937
2008-11-24 04:00:27 +00:00
Chris Lattner 86d7d91366 Rename NamedDecl::getIdentifierName() to ::getNameAsCString() and make it
assert if the name is not an identifier.  Update callers to do the right
thing and avoid this method in unsafe cases.  This also fixes an objc
warning that was missing a space, and migrates a couple more to taking
IdentifierInfo and QualTypes instead of std::strings.

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

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

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

llvm-svn: 59933
2008-11-24 03:33:13 +00:00
Anders Carlsson 7c282e4f3f Return false if we encounter a type we can't handle.
llvm-svn: 59889
2008-11-22 22:56:32 +00:00
Anders Carlsson 475f4bce36 Case values must be evaluated
llvm-svn: 59884
2008-11-22 21:50:49 +00:00
Anders Carlsson 59689ed764 Use Expr::Evaluate for case statements. Fixes PR2525
llvm-svn: 59881
2008-11-22 21:04:56 +00:00
Fariborz Jahanian 5118c418e6 Support for implicit property assignment. Error assigning to
'implicit' property with no 'setter'.

llvm-svn: 59878
2008-11-22 20:25:50 +00:00
Fariborz Jahanian 8a1810f06b New AST node to access "implicit" setter/getter using property dor syntax.
Issuing diagnostics when assigning to read-only properties.
This is work in progress.

llvm-svn: 59874
2008-11-22 18:39:36 +00:00
Sebastian Redl bd150f431e Implementation of new and delete parsing and sema.
This version uses VLAs to represent arrays. I'll try an alternative way next, but I want this safe first.

llvm-svn: 59835
2008-11-21 19:14:01 +00:00
Douglas Gregor 9eb16eadfb Enable some more operator overloading tests, and don't look into an identifier for functions that might not have one
llvm-svn: 59818
2008-11-21 15:30:19 +00:00
Chris Lattner 68e486804f Rename IdentifierInfo::isName to ::isStr. Use a nifty trick
from Sebastian to enforce that a literal string is passed in,
and use this to avoid having to call strlen on it.

llvm-svn: 59706
2008-11-20 04:42:34 +00:00
Oscar Fuentes 77543d9af0 CMake: Added some source files.
Patch contributed by Jay Foad!

llvm-svn: 59656
2008-11-19 18:46:39 +00:00
Argyrios Kyrtzidis 554689a3aa Make DeclContext::getLexicalParent reuse DeclContext::getParent.
llvm-svn: 59651
2008-11-19 18:07:24 +00:00
Argyrios Kyrtzidis 0d09c4944e Take care another assert:
struct A {
  struct B;
};

struct A::B {
  void m() {} // Assertion failed: getContainingDC(DC) == CurContext && "The next DeclContext should be lexically contained in the current one."
};

Introduce DeclContext::getLexicalParent which may be different from DeclContext::getParent when nested-names are involved, e.g:

   namespace A {
      struct S;
   }
   struct A::S {}; // getParent() == namespace 'A'
                   // getLexicalParent() == translation unit

llvm-svn: 59650
2008-11-19 18:01:13 +00:00
Nuno Lopes 0e33c688d5 fix folding of '*doubleArray'
llvm-svn: 59647
2008-11-19 17:44:31 +00:00
Argyrios Kyrtzidis 7768a30c37 Make the non-const DeclContext::getParent call the const version, instead of the other way around.
llvm-svn: 59646
2008-11-19 17:36:39 +00:00
Douglas Gregor 40412acc02 Support overloading of the subscript operator[], including support for
built-in operator candidates. Test overloading of '&' and ','.

In C++, a comma expression is an lvalue if its right-hand
subexpression is an lvalue. Update Expr::isLvalue accordingly.

llvm-svn: 59643
2008-11-19 17:17:41 +00:00
Douglas Gregor d08452f60a Added operator overloading for unary operators, post-increment, and
post-decrement, including support for generating all of the built-in
operator candidates for these operators. 

C++ and C have different rules for the arguments to the builtin unary
'+' and '-'. Implemented both variants in Sema::ActOnUnaryOp.

In C++, pre-increment and pre-decrement return lvalues. Update
Expr::isLvalue accordingly.

llvm-svn: 59638
2008-11-19 15:42:04 +00:00
Chris Lattner 6ef2bc4b42 simplify some code.
llvm-svn: 59608
2008-11-19 07:55:04 +00:00
Chris Lattner 230fc3d17d formatting
llvm-svn: 59599
2008-11-19 07:24:05 +00:00
Douglas Gregor 163c58502a Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.

Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.

Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.

Extended Declarator to store overloaded operator names. 
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator. 

Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.

llvm-svn: 59526
2008-11-18 14:39:36 +00:00
Sebastian Redl 8071edb297 Implement effects of 'mutable', and a few comments from Chris on its parsing.
llvm-svn: 59470
2008-11-17 23:24:37 +00:00
Douglas Gregor 92751d41a0 Eliminate all of the placeholder identifiers used for constructors,
destructors, and conversion functions. The placeholders were used to
work around the fact that the parser and some of Sema really wanted
declarators to have simple identifiers; now, the code that deals with
declarators will use DeclarationNames.

llvm-svn: 59469
2008-11-17 22:58:34 +00:00
Douglas Gregor ae2fbad373 Updated IdentifierResolver to deal with DeclarationNames. The names of
C++ constructors, destructors, and conversion functions now have a
FETokenInfo field that IdentifierResolver can access, so that these
special names are handled just like ordinary identifiers. A few other
Sema routines now use DeclarationNames instead of IdentifierInfo*'s.

To validate this design, this code also implements parsing and
semantic analysis for id-expressions that name conversion functions,
e.g.,

  return operator bool();

The new parser action ActOnConversionFunctionExpr takes the result of
parsing "operator type-id" and turning it into an expression, using
the IdentifierResolver with the DeclarationName of the conversion
function. ActOnDeclarator pushes those conversion function names into
scope so that the IdentifierResolver can find them, of course.

llvm-svn: 59462
2008-11-17 20:34:05 +00:00
Chris Lattner 9b3bbe9db7 Implement rdar://6319320: give a good diagnostic for cases where people
are trying to use the old GCC "casts as lvalue" extension.  We don't and
will hopefully never support this.

llvm-svn: 59460
2008-11-17 19:51:54 +00:00
Douglas Gregor 77324f3854 Introduction the DeclarationName class, as a single, general method of
representing the names of declarations in the C family of
languages. DeclarationName is used in NamedDecl to store the name of
the declaration (naturally), and ObjCMethodDecl is now a NamedDecl.

llvm-svn: 59441
2008-11-17 14:58:09 +00:00
Anders Carlsson 899c7050b6 Address some comments Eli had.
llvm-svn: 59430
2008-11-16 22:46:56 +00:00
Nuno Lopes 527b5a6858 use HandleConversionToBool() to check if a given cond is foldable (per Eli's comment)
llvm-svn: 59429
2008-11-16 22:06:39 +00:00
Anders Carlsson 9ddf7bedf9 More complex float evaluator support.
llvm-svn: 59428
2008-11-16 21:51:21 +00:00
Chris Lattner 67d7b9204c rename Expr::tryEvaluate to Expr::Evaluate.
llvm-svn: 59426
2008-11-16 21:24:15 +00:00
Anders Carlsson 537969c237 Add very limited support for evaluating complex floats.
llvm-svn: 59425
2008-11-16 20:27:53 +00:00
Nuno Lopes e236a48210 fix folding of comma if given a non-constant operand.
Eli please take a look, as I'm not sure if this gets the extension warning in the right place

llvm-svn: 59422
2008-11-16 20:09:07 +00:00
Nuno Lopes 420426100c make IntExprEvaluator fold the ?: operator
llvm-svn: 59421
2008-11-16 19:28:31 +00:00
Anders Carlsson 9f9e4249cc More work on the constant evaluator. Eli, it would be great if you could have a look at this.
llvm-svn: 59420
2008-11-16 19:01:22 +00:00
Chris Lattner 981f33b0b6 add dump and print methods, add operator<< for APValue.
llvm-svn: 59411
2008-11-16 07:46:48 +00:00
Anders Carlsson acc7981883 Add the ability to evaluate comparison operators with floating point numbers as operands.
llvm-svn: 59408
2008-11-16 07:17:21 +00:00
Argyrios Kyrtzidis 494d410b32 Use ReadPtr, not ReadUIntPtr through a reinterpret_cast.
Thanks to Sebastian for the suggestion.

llvm-svn: 59330
2008-11-14 23:32:45 +00:00
Douglas Gregor 993603d80d Add a new expression node, CXXOperatorCallExpr, which expresses a
function call created in response to the use of operator syntax that
resolves to an overloaded operator in C++, e.g., "str1 +
str2" that resolves to std::operator+(str1, str2)". We now build a
CXXOperatorCallExpr in C++ when we pick an overloaded operator. (But
only for binary operators, where we actually implement overloading)

I decided *not* to refactor the current CallExpr to make it abstract
(with FunctionCallExpr and CXXOperatorCallExpr as derived
classes). Doing so would allow us to make CXXOperatorCallExpr a little
bit smaller, at the cost of making the argument and callee accessors
virtual. We won't know if this is going to be a win until we can parse
lots of C++ code to determine how much memory we'll save by making
this change vs. the performance penalty due to the extra virtual
calls.

llvm-svn: 59306
2008-11-14 16:09:21 +00:00
Douglas Gregor be35ce953e Don't require us to manually number the statements and expressions in StmtNodes.def. We don't need stable numbers yet, renumbering is a pain, and LAST_STMT had the wrong value anyway.
llvm-svn: 59300
2008-11-14 12:46:07 +00:00
Ted Kremenek 5cf87ff564 Fix CFG construction for ObjCForCollectionStmt: 'element' expression can be anything that evaluates to an lvalue
llvm-svn: 59289
2008-11-14 01:57:41 +00:00
Douglas Gregor 58e008d2a6 Some cleanup for the implementation of built-in operator
candidates. Thanks to Chris for the review!

llvm-svn: 59260
2008-11-13 20:12:29 +00:00
Ted Kremenek 9f164c96bf Hook up "BodyBlock", not "Block".
llvm-svn: 59227
2008-11-13 07:01:10 +00:00
Ted Kremenek 1516dc075a Correctly connect 'continue' and 'break' statements in Objective-C fast enumeration for blocks to the appropriate basic blocks.
llvm-svn: 59226
2008-11-13 06:36:45 +00:00
Eli Friedman 5a332ea01f Fix for crash issues with comma operators with a void first operand, and
some more bullet-proofing/enhancements for tryEvaluate.  This shouldn't 
cause any behavior changes except for handling cases where we were 
crashing before and being able to evaluate a few more cases in tryEvaluate.
 
This should settle the minor mess surrounding r59196.

llvm-svn: 59224
2008-11-13 06:09:17 +00:00
Daniel Dunbar f3502dbc14 [LLVM up] Update for raw_fd_ostream change. This fixes a FIXME that
the Backend output should be done in binary mode.
 - I'd appreciate it if someone who has a Windows build could verify
   this.

llvm-svn: 59221
2008-11-13 05:09:21 +00:00
Eli Friedman 8553a98b8e Backout of r59196, plus a new ICE test. Sorry if this is a
little rude; I figure it's cleaner to just back this out now so 
it doesn't get forgotten or mixed up with other checkins.

The modification to isICE is simply wrong; I've added a test that the 
change to isICE breaks.

I'm pretty sure the modification to tryEvaluate is also wrong.  
At the very least, there's some serious miscommunication going on here, 
as this is going in exactly the opposite direction of r59105.  My 
understanding is that tryEvaluate is not supposed to care about side 
effects.  That said, a lot of the clients to tryEvaluate are 
expecting it to enforce a no-side-effects policy, so we probably need 
another method that provides that guarantee.

llvm-svn: 59212
2008-11-13 02:13:11 +00:00
Ted Kremenek ce9082ad5c Fix bug where the body block of an ObjCForCollectionStmt would not properly get expanded as a series of basic blocks.
llvm-svn: 59197
2008-11-13 00:06:59 +00:00
Daniel Dunbar c7ec5fcf24 Fix bug in constant evaluation exposed by 176.gcc.
- Evaluation of , operator used bogus assumption that LHS could be
   evaluated as an integral expression even though its type is
   unspecified.

This change is making isICE very permissive of the LHS in non-evaluated 
contexts because it is not clear what predicate we would use to reject 
code here. The standard didn't offer me any guidance; opinions?

llvm-svn: 59196
2008-11-13 00:03:19 +00:00
Douglas Gregor b6acda0f36 Don't build identifiers for C++ constructors, destructors, or
conversion functions. Instead, we just use a placeholder identifier
for these (e.g., "<constructor>") and override NamedDecl::getName() to
provide a human-readable name.

This is one potential solution to the problem; another solution would
be to replace the use of IdentifierInfo* in NamedDecl with a different
class that deals with identifiers better. I'm also prototyping that to
see how it compares, but this commit is better than what we had
previously.

llvm-svn: 59193
2008-11-12 23:21:09 +00:00
Daniel Dunbar a461e6d124 Disable some debug prints.
llvm-svn: 59174
2008-11-12 21:52:46 +00:00
Ted Kremenek 6d8b46e71d ObjCForCollectionStmts are block-level expressions.
llvm-svn: 59160
2008-11-12 21:11:49 +00:00
Douglas Gregor a11693bc37 Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin

  bool operator==(int const*, int const*)

can be used for the expression "x1 == x2" given:

  struct X {
    operator int const*();
  } x1, x2;

The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it. 

There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.

Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.

As part of this change, ImplicitCastExpr can now be an lvalue.

llvm-svn: 59148
2008-11-12 17:17:38 +00:00
Eli Friedman 9a156e5c1e Some additions to tryEvaluate I've had sitting around for a while.
This pushes it a lot closer to being able to deal with most of the stuff 
CodeGen's constant expression evaluator knows how to deal with.  This 
also fixes PR3003.

The test could possibly use some improvement, but this'll work for now.  
Test 6 is inspired by PR3003; the other tests are mostly just designed
to exercise the new code.  The reason for the funny structure of the 
tests is that type fixing for arrays inside of structs is the only place 
in Sema that calls tryEvaluate, at least for the moment.

llvm-svn: 59125
2008-11-12 09:44:48 +00:00
Chris Lattner fac05aeae5 fix a crash analyzing constants in 176.gcc/expr.c with my next patch. It was
crashing because we errors are ignored in subexpressions that are not evaluated,
but we still evaluate the result of parents.  This would cause an assertion 
because the erroneous subexpr didn't have its result value set to the right type.

llvm-svn: 59110
2008-11-12 07:43:42 +00:00
Chris Lattner aa3f951efc Teach the aggressive constant folder to fold X && 0 -> 0 and X || 1 -> 1
llvm-svn: 59105
2008-11-12 07:04:29 +00:00
Sebastian Redl 6f28289aca Introduce a single AST node SizeOfAlignOfExpr for all sizeof and alignof expressions, both of values and types.
llvm-svn: 59057
2008-11-11 17:56:53 +00:00
Ted Kremenek 9d56e64543 Add CFG support for Objective-C 2.0 fast enumeration 'for' statement:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_7_section_2.html#//apple_ref/doc/uid/TP30001163-CH18-SW3

Need to modify GRExprEngine, LiveVariables, and UninitializedValues to understand this construct.

llvm-svn: 59049
2008-11-11 17:10:00 +00:00
Sebastian Redl c470476420 Implement C++ 'typeid' parsing and sema.
llvm-svn: 59042
2008-11-11 11:37:55 +00:00
Daniel Dunbar e27d7b5530 Fix Release-Asserts warning.
llvm-svn: 59013
2008-11-11 01:16:00 +00:00
Argyrios Kyrtzidis 9e59b577d8 Introduce ScopedDecl::getLexicalDeclContext() which is different from ScopedDecl::getDeclContext() when there are nested-names.
e.g.:
  namespace A {
    void f(); // SemanticDC (getDeclContext) == LexicalDC (getLexicalDeclContext) == 'namespace A'
  }
  void A::f(); // SemanticDC == namespace 'A'
               // LexicalDC == global namespace

llvm-svn: 58948
2008-11-09 23:41:00 +00:00
Argyrios Kyrtzidis 13042a4a4a Use only one constructor for CXXMethodDecl. Keep initialization stuff into one place.
llvm-svn: 58902
2008-11-08 11:24:06 +00:00
Daniel Dunbar bbc0af7e37 Support getTypeInfo, getTypeAlign, getTypeSize on const Type*s.
- Size/align are not effected by CVR qualifiers.

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

llvm-svn: 58891
2008-11-08 05:48:37 +00:00
Douglas Gregor dbc5daf058 Parsing, ASTs, and semantic analysis for the declaration of conversion
functions in C++, e.g.,

  struct X {
    operator bool() const;
  };

Note that these conversions don't actually do anything, since we don't
yet have the ability to use them for implicit or explicit conversions.

llvm-svn: 58860
2008-11-07 20:08:42 +00:00
Argyrios Kyrtzidis 3175fa5139 Properly deserialize ParamInfo of FunctionDecl.
When allocating an array for ParamInfo, the "decl->getNumParams()" call was used, but this will return 0 since it checks ParamInfo (which isn't yet defined and is null).
The result was that ParamInfo got an array of zero length to hold the ParmVarDecls.

llvm-svn: 58850
2008-11-07 14:22:23 +00:00
Douglas Gregor 11d0c4c098 Parsing, ASTs, and semantic analysis for the declaration of overloaded
operators in C++. Overloaded operators can be called directly via
their operator-function-ids, e.g., "operator+(foo, bar)", but we don't
yet implement the semantics of operator overloading to handle, e.g.,
"foo + bar".

llvm-svn: 58817
2008-11-06 22:13:31 +00:00
Douglas Gregor 831c93f6c0 Parsing, representation, and preliminary semantic analysis of destructors.
Implicit declaration of destructors (when necessary).

Extended Declarator to store information about parsed constructors
and destructors; this will be extended to deal with declarators that
name overloaded operators (e.g., "operator +") and user-defined
conversion operators (e.g., "operator int").

llvm-svn: 58767
2008-11-05 20:51:48 +00:00
Douglas Gregor cfd8ddc6de Keep track of whether a C++ class is an aggregate. Don't allow initialization of non-aggregates with initializer lists.
llvm-svn: 58757
2008-11-05 16:20:31 +00:00
Douglas Gregor 6f5431543a Implement C++ copy-initialization for declarations. There is now some
duplication in the handling of copy-initialization by constructor,
which occurs both for initialization of a declaration and for
overloading. The initialization code is due for some refactoring.

llvm-svn: 58756
2008-11-05 15:29:30 +00:00
Douglas Gregor e8381c00eb Initial implementation of parsing, semantic analysis, and AST-building
for constructor initializations, e.g.,

  class A { };
  class B : public A { 
    int m;
  public:
    B() : A(), m(17) { };
  };

llvm-svn: 58749
2008-11-05 04:29:56 +00:00
Chris Lattner b8c18fa59a LinkageSpecDecl is c++ specific, move it to DeclCXX
llvm-svn: 58704
2008-11-04 16:51:42 +00:00
Douglas Gregor 8ea1f53420 Add a new expression class, ObjCSuperExpr, to handle the Objective-C 'super'. Remove ObjCThis from PredefinedExpr
llvm-svn: 58698
2008-11-04 14:56:14 +00:00
Douglas Gregor 97a9c81b05 Create a new expression class, CXXThisExpr, to handle the C++ 'this' primary expression. Remove CXXThis from PredefinedExpr
llvm-svn: 58695
2008-11-04 14:32:21 +00:00
Sebastian Redl 273ce56d7a Trivial style fix.
llvm-svn: 58689
2008-11-04 11:45:54 +00:00
Steve Naroff c989a7b6c0 Fix <rdar://problem/6339636> clang ObjC rewriter: Assertion failed: FileID-1 < FileIDs.size() && "Invalid FileID!", file c:\cygwin\home\Administrator\llvm\tools\clang\include\clang/Basic/SourceManager.h, line 513
llvm-svn: 58654
2008-11-03 23:29:32 +00:00
Douglas Gregor 0537942f3c Add implicitly-declared default and copy constructors to C++ classes,
when appropriate.

Conversions for class types now make use of copy constructors. I've
replaced the egregious hack allowing class-to-class conversions with a
slightly less egregious hack calling these conversions standard
conversions (for overloading reasons).

llvm-svn: 58622
2008-11-03 17:51:48 +00:00
Douglas Gregor ab13857072 Eliminate header dependency ASTContext -> TargetInfo
llvm-svn: 58613
2008-11-03 15:57:00 +00:00
Douglas Gregor 8af6e6d415 Connect ASTContext to TargetInfo when determining the size_t, ptrdiff_t, and wchar_t types. Fixes recent breakage on Linux.
llvm-svn: 58609
2008-11-03 14:12:49 +00:00
Douglas Gregor eebb5c10aa Semantic checking of constructor declarations and classification of default/copy constructors
llvm-svn: 58538
2008-10-31 20:25:05 +00:00
Douglas Gregor 26bee0b326 Implement basic support for converting constructors in user-defined
conversions.

Notes:
  - Overload resolution for converting constructors need to prohibit
    user-defined conversions (hence, the test isn't -verify safe yet).
  - We still use hacks for conversions from a class type to itself. 
    This will be the case until we start implicitly declaring the appropriate
    special member functions. (That's next on my list)

llvm-svn: 58513
2008-10-31 16:23:19 +00:00
Sebastian Redl 72b8aef613 Implement semantic checking of static_cast and dynamic_cast.
llvm-svn: 58509
2008-10-31 14:43:28 +00:00
Douglas Gregor 61956c460a Add support for parsing and representing C++ constructor declarations.
Notes:
  - Constructors are never found by name lookup, so they'll never get
    pushed into any scope. Instead, they are stored as an 
    OverloadedFunctionDecl in CXXRecordDecl for easy overloading.
  - There's a new action isCurrentClassName that determines whether an
    identifier is the name of the innermost class currently being defined;
    we use this to identify the declarator-id grammar rule that refers to 
    a type-name. 
  - MinimalAction does *not* support parsing constructors.
  - We now handle virtual and explicit function specifiers.

llvm-svn: 58499
2008-10-31 09:07:45 +00:00
Douglas Gregor ffe249f5e5 Fix arithmetic type check
llvm-svn: 58429
2008-10-30 13:47:07 +00:00
Ted Kremenek 82c1cc3d52 Fix crash reported in PR2923 where a function declared using typeof(another_function) would have FunctionDecl::getNumParams() return the number of parameters in the original function type and not the number of parameters in the actual FunctionDecl.
llvm-svn: 58392
2008-10-29 18:41:34 +00:00
Douglas Gregor 8e1cf608dc Implement initialization of a reference (C++ [dcl.init.ref]) as part
of copy initialization. Other pieces of the puzzle:

  - Try/Perform-ImplicitConversion now handles implicit conversions
    that don't involve references.
  - Try/Perform-CopyInitialization uses
    CheckSingleAssignmentConstraints for C. PerformCopyInitialization
    is now used for all argument passing and returning values from a
    function.
  - Diagnose errors with declaring references and const values without
    an initializer. (Uses a new Action callback, ActOnUninitializedDecl).
  
We do not yet have implicit conversion sequences for reference
binding, which means that we don't have any overloading support for
reference parameters yet.

llvm-svn: 58353
2008-10-29 00:13:59 +00:00
Douglas Gregor f19b2319c9 Rename ExplicitCCastExpr to CStyleCastExpr
llvm-svn: 58331
2008-10-28 15:36:24 +00:00
Douglas Gregor d984d30731 Replace a dyn_cast with a cast when we know the exact type
llvm-svn: 58330
2008-10-28 15:29:51 +00:00
Douglas Gregor 6b75484ba6 Improve our handling of (C++) references within Clang. Specifically:
- Do not allow expressions to ever have reference type
  - Extend Expr::isLvalue to handle more cases where having written a
    reference into the source implies that the expression is an lvalue
    (e.g., function calls, C++ casts).
  - Make GRExprEngine::VisitCall treat the call arguments as lvalues when
    they are being bound to a reference parameter.

llvm-svn: 58306
2008-10-28 00:22:11 +00:00
Douglas Gregor e200adc503 Refactor the expression class hierarchy for casts. Most importantly:
- CastExpr is the root of all casts
  - ImplicitCastExpr is (still) used for all explicit casts
  - ExplicitCastExpr is now the root of all *explicit* casts
  - ExplicitCCastExpr (new name needed!?) is a C-style cast in C or C++
  - CXXFunctionalCastExpr inherits from ExplicitCastExpr
  - CXXNamedCastExpr inherits from ExplicitCastExpr and is the root of all
    of the C++ named cast expression types (static_cast, dynamic_cast, etc.)
  - Added classes CXXStaticCastExpr, CXXDynamicCastExpr, 
    CXXReinterpretCastExpr, and CXXConstCastExpr to 

Also, fixed returned-stack-addr.cpp, which broke once when we fixed
reinterpret_cast to diagnose double->int* conversions and again when
we eliminated implicit conversions to reference types. The fix is in
both testcase and SemaChecking.cpp.

Most of this patch is simply support for the renaming. There's very
little actual change in semantics.

llvm-svn: 58264
2008-10-27 19:41:14 +00:00
Ted Kremenek 5778acf5e8 - Move ExprIterator to Stmt.h so that it can be used by classes defined in Stmt.h
- Implement child_begin() and child_end() for AsmStmt.  Previously these had stub implementations that did not iterate over the input/output operands of an inline assembly statement.
- Use ExprIterator for performing iteration over input/output operands.

llvm-svn: 58261
2008-10-27 18:40:21 +00:00
Douglas Gregor 89ebcb9d8d When destroying a translation unit, deallocate its owned declarations in reverse order, because there may be dependencies among the declarations.
llvm-svn: 58244
2008-10-27 12:50:38 +00:00
Chris Lattner 07d754acf1 Remember whether an initlist had a designator in the AST.
llvm-svn: 58218
2008-10-26 23:43:26 +00:00
Argyrios Kyrtzidis 22a3735398 Don't give a default argument to ASTContext::getFunctionType for the TypeQuals parameter, it causes subtle bugs where TypeQuals, while necessary, are omitted from the call.
-Remove the default argument.
-Update all call sites of ASTContext::getFunctionType.

llvm-svn: 58187
2008-10-26 16:43:14 +00:00
Oscar Fuentes 07d9f9a6ec CMake: Builds and installs clang binary and libs (no docs yet). It
must be under the `tools' subdirectory of the LLVM *source* tree.

llvm-svn: 58180
2008-10-26 00:56:18 +00:00
Argyrios Kyrtzidis 962c20e6f3 Add a quote from the standard about the type of 'this'.
llvm-svn: 58124
2008-10-24 22:28:18 +00:00
Argyrios Kyrtzidis 22c40fa285 -Add support for cv-qualifiers after function declarators.
-Add withConst/withVolatile/withRestrict methods to QualType class, that return the QualType plus the respective qualifier.

llvm-svn: 58120
2008-10-24 21:46:40 +00:00
Douglas Gregor 3dfef1f2a3 Move viewInheritance to CXXRecordDecl, and make sure it builds in Release mode, too
llvm-svn: 58105
2008-10-24 19:53:54 +00:00
Daniel Dunbar d7be95d60a PR2919: __builtin_types_compatible_p strips CRV qualifiers.
llvm-svn: 58079
2008-10-24 08:07:57 +00:00
Ted Kremenek 1507dbfbfc Use llvm::errs() instead of cerr.
llvm-svn: 58054
2008-10-23 23:55:40 +00:00
Ted Kremenek 40fcc594b8 Convert InheritanceHierarchyWriter to use llvm::raw_ostream instead of std::ostream.
llvm-svn: 58053
2008-10-23 23:51:23 +00:00
Douglas Gregor 9d6290baf1 Clean up and document the representation of C++ base classes
llvm-svn: 58040
2008-10-23 18:13:27 +00:00
Douglas Gregor 01bef3c016 If NDEBUG is set, don't include any of the code for visualizing inheritance hierarchies
llvm-svn: 58029
2008-10-23 03:52:39 +00:00
Douglas Gregor d8c7476bf3 Remove the GraphWriter-based version of the C++ class inheritance visualization, since it isn't being used and can't handle virtual bases properly
llvm-svn: 58002
2008-10-22 21:25:12 +00:00
Douglas Gregor dff6a8eeef Added GraphViz visualization of C++ inheritance hierarchies.
Factored the QualTypeOrdering predicate into its own header
(TypeOrdering.h), now that it is used in two places.

llvm-svn: 58001
2008-10-22 21:13:31 +00:00
Argyrios Kyrtzidis 2147e7d88b Now that DeclRefExpr accepts a NamedDecl, use a DeclRefExpr for when a CXXFieldDecl is referenced inside a method.
llvm-svn: 58000
2008-10-22 21:00:29 +00:00
Douglas Gregor 29a9247ec2 Add representation of base classes in the AST, and verify that we
don't have duplicated direct base classes.

Seriliazation of base class specifiers is not yet implemented.

llvm-svn: 57991
2008-10-22 17:49:05 +00:00
Douglas Gregor 4b62ec6353 QualType::isMoreQualifiedThan and isAtLeastAsQualifiedAs assert that we
aren't trying to compare with address-space qualifiers (for now).

Clean up handing of DeclRefExprs in Expr::isLvalue and refactor part
of the check into a static DeclCanBeLvalue.

llvm-svn: 57980
2008-10-22 15:04:37 +00:00
Douglas Gregor 293a3c6778 Functions can be lvalues in C++, but not modifiable lvalues
llvm-svn: 57941
2008-10-22 00:03:08 +00:00
Douglas Gregor 9a6579340f Initial step toward supporting qualification conversions (C++ 4.4).
Changes:
  - Sema::IsQualificationConversion determines whether we have a qualification
    conversion.
  - Sema::CheckSingleAssignment constraints now follows the C++ rules in C++,
    performing an implicit conversion from the right-hand side to the type of
    the left-hand side rather than checking based on the C notion of 
    "compatibility". We now rely on the implicit-conversion code to
    determine whether the conversion can happen or
    not. Sema::TryCopyInitialization has an ugly reference-related
    hack to cope with the initialization of references, for now.
  - When building DeclRefExprs, strip away the reference type, since
    there are no expressions whose type is a reference. We'll need to
    do this throughout Sema.
  - Expr::isLvalue now permits functions to be lvalues in C++ (but not
  in C).

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

Note: My previous commit was done in the test directory...as a result, this commit was necessary.
llvm-svn: 57914
2008-10-21 18:24:04 +00:00
Douglas Gregor 5251f1b283 Preliminary support for function overloading
llvm-svn: 57909
2008-10-21 16:13:35 +00:00
Steve Naroff ea54d9ef72 Sema::CheckCompareOperands() and ASTContext::mergeTypes(): Change handling of ObjC qualified id types to be consistent with gcc. This changes a handful of test case errors into warnings (diff will tell you which cases have changed).
llvm-svn: 57841
2008-10-20 18:19:10 +00:00
Ted Kremenek d36e552245 Fix incorrect release of Decl* array referenced by DeclGroup.
Patch by Timo Sirainen!

llvm-svn: 57772
2008-10-18 19:20:54 +00:00
Mon P Wang 8f477106a4 Make llvm memory barrier available as an intrinsic
llvm-svn: 57751
2008-10-18 02:49:28 +00:00
Daniel Dunbar fc1066db81 Remove unneeded EncodingRecordTypes argument to getObjCEncodingForType.
llvm-svn: 57716
2008-10-17 20:21:44 +00:00
Daniel Dunbar ff3c6747ef More Obj-C type encoding improvements.
- Encode unions and bit-fields correctly.
 - Accept option to name record fields (used for NeXT runtime).

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

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

llvm-svn: 57675
2008-10-17 07:30:50 +00:00