Commit Graph

103 Commits

Author SHA1 Message Date
Douglas Gregor 12cc7eeb82 Fixed DISABLE_SMART_POINTERS breakage
llvm-svn: 103198
2010-05-06 21:39:56 +00:00
Douglas Gregor e60e41add9 Rework our handling of temporary objects within the conditions of
if/switch/while/do/for statements. Previously, we would end up either:

  (1) Forgetting to destroy temporaries created in the condition (!),
  (2) Destroying the temporaries created in the condition *before*
  converting the condition to a boolean value (or, in the case of a
  switch statement, to an integral or enumeral value), or
  (3) In a for statement, destroying the condition's temporaries at
  the end of the increment expression (!).

We now destroy temporaries in conditions at the right times. This
required some tweaking of the Parse/Sema interaction, since the parser
was building full expressions too early in many places.

Fixes PR7067.

llvm-svn: 103187
2010-05-06 17:25:47 +00:00
Chris Lattner df74264787 change Scope::WithinElse to be a normal scope flag, widen the
fields to two 16-bit values instead of using bitfields.

llvm-svn: 101020
2010-04-12 06:12:50 +00:00
Chris Lattner 005fc1bbcf fix PR6782, an accept invalid. We weren't emitting the diagnostic
returned by SetTypeSpecType.

llvm-svn: 100443
2010-04-05 18:18:31 +00:00
Argyrios Kyrtzidis 90ab3b7779 Don't skip past the '}' if an expression has error and is not followed by ';'.
llvm-svn: 99972
2010-03-31 00:37:59 +00:00
Ted Kremenek c162e8e193 Clean up ownership of 'AttributeList' objects in Parser. Apparently
we would just leak them all over the place, with no clear ownership of
these objects at all.  AttributeList objects would get leaked on both
error and non-error paths.

Note: I introduced the usage of llvm::OwningPtr<AttributeList> to
manage these objects, which is particularly useful for methods with
multiple return sites.  In at least one method I used them even when
they weren't strictly necessary because it clarified the ownership
semantics and made the code easier to read.  Should the excessive
'take()' and 'reset()' calls become a performance issue we can always
re-evaluate.

Note+1: I believe I have not introduced any double-frees, but it would
be nice for someone to review this.

This fixes <rdar://problem/7635046>.

llvm-svn: 95847
2010-02-11 02:19:13 +00:00
Anders Carlsson 9a020f9a3a Use IdentifierInfo * instead of std::string for the AsmStmt names.
llvm-svn: 94925
2010-01-30 22:25:16 +00:00
Chris Lattner 8fd2d01118 fix PR6034, a crash on invalid where the switch stack would get
unbalanced.

llvm-svn: 94347
2010-01-24 01:50:29 +00:00
Douglas Gregor 504a6ae83e Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for

  static_cast<type>(expr)

when we can have an expression, or

  using namespace identifier;

when we can have a using directive.

Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.

llvm-svn: 93134
2010-01-10 23:08:15 +00:00
Mike Stump 90be58afce Remember if the AsmStmt came from Microsoft-style inline assembly code.
llvm-svn: 92526
2010-01-04 22:37:17 +00:00
Chris Lattner 1576850a76 fix PR5500: clang fails to parse inline asm with :: in C++ mode
llvm-svn: 91802
2009-12-20 23:08:04 +00:00
Chris Lattner bf5fff5fbb refactor asm stmt parsing to avoid nesting as much, and
pull ':' eating out of ParseAsmOperandsOpt.

llvm-svn: 91801
2009-12-20 23:00:41 +00:00
Anders Carlsson afb2dade0c Check in a rudimentary FullExpr class that isn't used anywhere yet. Rename Action::FullExpr to Action::MakeFullExpr to avoid name clashes.
llvm-svn: 91494
2009-12-16 02:09:40 +00:00
Mike Stump 6da5d75449 Implement just a bit more of inline assembly.
llvm-svn: 91079
2009-12-11 00:04:56 +00:00
Chris Lattner 125c0ee5c7 fix PR5740: a colon is sacred when parsing case statement expressions!
llvm-svn: 91016
2009-12-10 00:38:54 +00:00
Chris Lattner 8a9a97a660 rename ExtensionRAIIObject.h -> RAIIObjectsForParser.h
llvm-svn: 91008
2009-12-10 00:21:05 +00:00
Douglas Gregor 3ff3af4ff9 When the condition of a switch() statement is semantically invalid,
still parse the body of the switch to try to avoid spurious
diagnostics. Fixes PR5606.

llvm-svn: 89847
2009-11-25 06:20:02 +00:00
Douglas Gregor 7bab5ff8e7 Eliminate CXXConditionDeclExpr with extreme prejudice.
All statements that involve conditions can now hold on to a separate
condition declaration (a VarDecl), and will use a DeclRefExpr
referring to that VarDecl for the condition expression. ForStmts now
have such a VarDecl (I'd missed those in previous commits).

Also, since this change reworks the Action interface for
if/while/switch/for, use FullExprArg for the full expressions in those
expressions, to ensure that we're emitting

Note that we are (still) not generating the right cleanups for
condition variables in for statements. That will be a follow-on
commit.

llvm-svn: 89817
2009-11-25 00:27:52 +00:00
Douglas Gregor 7f800f9d50 "Do" loops cannot have condition variables, so don't parse them.
llvm-svn: 89801
2009-11-24 21:34:32 +00:00
Alexis Hunt 96d5c76498 Added rudimentary C++0x attribute support.
The following attributes are currently supported in C++0x attribute
lists (and in GNU ones as well):
 - align() - semantics believed to be conformant to n3000, except for
   redeclarations and what entities it may apply to
 - final - semantics believed to be conformant to CWG issue 817's proposed
   wording, except for redeclarations
 - noreturn - semantics believed to be conformant to n3000, except for
   redeclarations
 - carries_dependency - currently ignored (this is an optimization hint)

llvm-svn: 89543
2009-11-21 08:43:09 +00:00
Fariborz Jahanian e774fa6412 Don't issue spurious diagnostic with Obj-C fast enumeration.
(radar 7409165).

llvm-svn: 89400
2009-11-19 22:12:37 +00:00
John McCall d5a36321b9 Reorganize the parsing of decl groups / function definitions so that
declarators are parsed primarily within a single function (at least for
these cases).  Remove some excess diagnostics arising during parse failures.

llvm-svn: 85924
2009-11-03 19:26:08 +00:00
Daniel Dunbar 07d0785dbb PR5218: Replace IdentifierInfo::getName with StringRef version, now that clients
are updated.

llvm-svn: 84447
2009-10-18 21:17:35 +00:00
Daniel Dunbar 70e7eadd15 Move misc clients to IdentifierInfo StringRef API.
- strcmp -> ==
 - OS.write(II->getName() ...) -> OS << II->getNameStr()
 - Avoid std::string concatenation
 - Use getNameStr().str() when an std::string is really needed.

llvm-svn: 84437
2009-10-18 20:26:27 +00:00
Douglas Gregor 9d64c5e3a5 Code completion for ordinary names when we're starting a declaration, expression, or statement
llvm-svn: 82481
2009-09-21 20:51:25 +00:00
Douglas Gregor d328d57c39 Code completion for "case" statements within a switch on an expression
of enumeration type, providing the various unused enumerators as options.

llvm-svn: 82467
2009-09-21 18:10:23 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +00:00
Anders Carlsson a192947509 Change ActOnReturnStmt to not take a FullExprArg. Instead, Sema will wrap the return expr inside a CXXExprWithTemporaries if needed.
llvm-svn: 79342
2009-08-18 16:11:00 +00:00
Chris Lattner 8e3eed0890 change ParseStatementOrDeclaration to emit the 'missing ;' with
ExpectAndConsume instead of custom diag logic.  This gets us an
insertion hint and positions the ; at the end of the line 
instead of on the next token.  Before:

t.c:5:1: error: expected ';' after return statement
}
^

after:

t.c:4:11: error: expected ';' after return statement
  return 4
          ^
          ;

llvm-svn: 73315
2009-06-14 00:23:56 +00:00
Chris Lattner 34a9566c8c improve localizability by not passing english phrases into
diagnostics in some cases.

llvm-svn: 73314
2009-06-14 00:07:48 +00:00
Chris Lattner 815b70efcd add the location of the ')' in a do/while statement to DoStmt.
This fixes a source range problem reported by Olaf Krzikalla.

llvm-svn: 73266
2009-06-12 23:04:47 +00:00
Anders Carlsson 8936009a91 Make sure to call FullExpr before parsing anything else.
llvm-svn: 72834
2009-06-04 02:18:15 +00:00
Anders Carlsson 5de832ecfa ActOnReturnStmt should also take a FullExprArg.
llvm-svn: 72641
2009-05-30 21:42:34 +00:00
Douglas Gregor 269f0b1b69 Merge the ASTVector and ASTOwningVector templates, since they offered
redundant functionality. The result (ASTOwningVector) lives in
clang/Parse/Ownership.h and is used by both the parser and semantic
analysis. No intended functionality change.

llvm-svn: 72214
2009-05-21 16:25:11 +00:00
Jay Foad 7d0479f2c2 Use v.data() instead of &v[0] when SmallVector v might be empty.
llvm-svn: 72210
2009-05-21 09:52:38 +00:00
Anders Carlsson ee13926fbe Make ActOnWhileStmt take a FullExprArg for the condition expr.
llvm-svn: 71990
2009-05-17 21:22:26 +00:00
Anders Carlsson 24824e5009 Make ActOnExprStmt take a FullExprArg.
llvm-svn: 71989
2009-05-17 21:11:30 +00:00
Anders Carlsson 5262746c28 Add the FullExprArg wrapper and use it for if statement conditions.
llvm-svn: 71982
2009-05-17 18:26:53 +00:00
Eli Friedman 15af3ee6a9 Make the RAII extension warning silencing for __extension__ a bit
narrower, so it doesn't catch expresions that aren't sub-expressions of
__extension__ operator.

llvm-svn: 71967
2009-05-16 23:40:44 +00:00
Eli Friedman 47e785783c Don't insert an extra ParenExpr around asm operands.
llvm-svn: 70673
2009-05-03 07:49:42 +00:00
Eli Friedman 5d72d41189 Get rid of some useless uses of NoExtensions. The philosophy here is
that if we're going to print an extension warning anyway, 
there's no point to changing behavior based on NoExtensions: it will 
only make error recovery worse.

Note that this doesn't cause any behavior change because NoExtensions 
isn't used by the current front-end.  I'm still considering what to do about
the remaining use of NoExtensions in IdentifierTable.cpp.

llvm-svn: 70273
2009-04-28 00:51:18 +00:00
Sebastian Redl d98ecd615f The mysterious bug turns out to be an incredibly bone-headed mistake.
llvm-svn: 70160
2009-04-26 21:08:36 +00:00
Sebastian Redl a7b98a772c Implement function-try-blocks. However, there's a very subtle bug that I can't track down.
llvm-svn: 70155
2009-04-26 20:35:05 +00:00
Chris Lattner 934074cd5f Fix a problem with objc foreach loop. It turns out that objc mode changes
for scoping to match C99 even when in C89 mode.  This patch fixes this 
(eliminating a "redefinition of thisKey" error), and also prevents non-sensical
diagnostics in -pedantic mode like this:

t.m:7:8: warning: variable declaration in for loop is a C99-specific feature
  for (id thisKey in keys) ;
       ^

llvm-svn: 69760
2009-04-22 00:54:41 +00:00
Chris Lattner 49836b448e fix a FIXME, providing accurate source range info for DeclStmt's. The end
of the range is now the ';' location.  For something like this:

$ cat t2.c 

#define bool int
void f(int x, int y) {
bool b = !x && y;
}

We used to produce:
$ clang-cc t2.c -ast-dump 
typedef char *__builtin_va_list;

void f(int x, int y)
(CompoundStmt 0x2201f10 <t2.c:3:22, line:5:1>
  (DeclStmt 0x2201ef0 <line:2:14>                   <----
    0x2201a20 "int b =
      (BinaryOperator 0x2201ed0 <line:4:10, col:16> 'int' '&&'
        (UnaryOperator 0x2201e90 <col:10, col:11> 'int' prefix '!'
          (DeclRefExpr 0x2201c90 <col:11> 'int' ParmVar='x' 0x2201a50))
        (DeclRefExpr 0x2201eb0 <col:16> 'int' ParmVar='y' 0x2201e10))")


Now we produce:

$ clang-cc t2.c -ast-dump
typedef char *__builtin_va_list;

void f(int x, int y)
(CompoundStmt 0x2201f10 <t2.c:3:22, line:5:1>
  (DeclStmt 0x2201ef0 <line:2:14, line:4:17>         <------
    0x2201a20 "int b =
      (BinaryOperator 0x2201ed0 <col:10, col:16> 'int' '&&'
        (UnaryOperator 0x2201e90 <col:10, col:11> 'int' prefix '!'
          (DeclRefExpr 0x2201c90 <col:11> 'int' ParmVar='x' 0x2201a50))
        (DeclRefExpr 0x2201eb0 <col:16> 'int' ParmVar='y' 0x2201e10))")

llvm-svn: 68288
2009-04-02 04:16:50 +00:00
Chris Lattner be36eb0570 minor simplification
llvm-svn: 68011
2009-03-29 17:29:28 +00:00
Chris Lattner 32dc41c445 hoist some code for handling objc foreach construct out of Declaration processing
into ParseForStatement.  Merge two tests into one.

llvm-svn: 68010
2009-03-29 17:27:48 +00:00
Chris Lattner 5bbb3c8ad9 Push DeclGroup much farther throughout the compiler. Now the various
productions (except the already broken ObjC cases like @class X,Y;) in 
the parser that can produce more than one Decl return a DeclGroup instead
of a Decl, etc.

This allows elimination of the Decl::NextDeclarator field, and exposes
various clients that should look at all decls in a group, but which were
only looking at one (such as the dumper, printer, etc).  These have been
fixed.

Still TODO:

1) there are some FIXME's in the code about potentially using
DeclGroup for better location info.
2) ParseObjCAtDirectives should return a DeclGroup due to @class etc.
3) I'm not sure what is going on with StmtIterator.cpp, or if it can
   be radically simplified now.
4) I put a truly horrible hack in ParseTemplate.cpp.

I plan to bring up #3/4 on the mailing list, but don't plan to tackle
#1/2 in the short term.

llvm-svn: 68002
2009-03-29 16:50:03 +00:00
Chris Lattner 83f095cc7e Introduce a new OpaquePtr<N> struct type, which is a simple POD wrapper for a
pointer.  Its purpose in life is to be a glorified void*, but which does not
implicitly convert to void* or other OpaquePtr's with a different UID.

Introduce Action::DeclPtrTy which is a typedef for OpaquePtr<0>.  Change the 
entire parser/sema interface to use DeclPtrTy instead of DeclTy*.  This
makes the C++ compiler enforce that these aren't convertible to other opaque
types.

We should also convert ExprTy, StmtTy, TypeTy, AttrTy, BaseTy, etc,
but I don't plan to do that in the short term.

The one outstanding known problem with this patch is that we lose the 
bitmangling optimization where ActionResult<DeclPtrTy> doesn't know how to
bitmangle the success bit into the low bit of DeclPtrTy.  I will rectify
this with a subsequent patch.

llvm-svn: 67952
2009-03-28 19:18:32 +00:00
Chris Lattner 803802d4d6 random cleanups.
llvm-svn: 67624
2009-03-24 17:04:48 +00:00