Commit Graph

402 Commits

Author SHA1 Message Date
Steve Naroff 44ac777741 Add parser support for __cdecl, __stdcall, and __fastcall.
Change preprocessor implementation of _cdecl to reference __cdecl.

llvm-svn: 61430
2008-12-25 14:16:32 +00:00
Steve Naroff 3a9b7e0cff Add explicit "fuzzy" parse support for Microsoft declspec.
Remove previous __declspec macro that would effectively erase the construct prior to parsing.

llvm-svn: 61422
2008-12-24 20:59:21 +00:00
Douglas Gregor b9bd8a994c Keep track of template arguments when we parse them. Right now, we don't actually do anything with the template arguments, but they'll be used to create template declarations
llvm-svn: 61413
2008-12-24 02:52:09 +00:00
Douglas Gregor 583540360c Correct the order in which we cope with end-of-class-definition
semantics and improve our handling of default arguments. Specifically,
we follow this order:

  - As soon as the see the '}' in the class definition, the class is
  complete and we add any implicit declarations (default constructor,
  copy constructor, etc.) to the class.
  - If there are any default function arguments, parse them
  - If there were any inline member function definitions, parse them

As part of this change, we now keep track of the the fact that we've
seen unparsed default function arguments within the AST. See the new
ParmVarDecl::hasUnparsedDefaultArg member. This allows us to properly
cope with calls inside default function arguments to other functions
where we're making use of the default arguments.

Made some C++ error messages regarding failed initializations more
specific. 

llvm-svn: 61406
2008-12-24 00:01:03 +00:00
Douglas Gregor 55297ac499 Don't explicitly represent OverloadedFunctionDecls within
DeclContext. Instead, just keep the list of currently-active
declarations and only build the OverloadedFunctionDecl when we
absolutely need it.

This is a half-step toward eliminating the need to explicitly build
OverloadedFunctionDecls that store sets of overloaded
functions. This was suggested by Argiris a while back, and it's a good
thing for several reasons: first, it eliminates the messy logic that
currently tries to keep the OverloadedFunctionDecl in sync with the 
declarations that are being added. Second, it will (eventually)
eliminate the need to allocate memory for overload sets, which could
help performance. Finally, it helps set us up for when name lookup can
return multiple (possibly ambiguous) results, as can happen with
lookup of class members in C++.

Next steps: make the IdentifierResolver store overloads as separate
entries in its list rather than replacing them with an
OverloadedFunctionDecl now, then see how far we can go toward
eliminating OverloadedFunctionDecl entirely.

llvm-svn: 61357
2008-12-23 00:26:44 +00:00
Sebastian Redl 54c04d4700 Partial AST and Sema support for C++ try-catch.
llvm-svn: 61337
2008-12-22 19:15:10 +00:00
Sebastian Redl b219c90d7b Parser support for C++ try-catch.
llvm-svn: 61312
2008-12-21 16:41:36 +00:00
Sebastian Redl 52f03bac60 Convert a few Stmt actions to smart pointers.
llvm-svn: 61309
2008-12-21 12:04:03 +00:00
Douglas Gregor 55ad91fecb Ultrasimplistic sketch for the parsing of C++ template-ids. This won't
become useful or correct until we (1) parse template arguments
correctly, (2) have some way to turn template-ids into types,
declarators, etc., and (3) have a real representation of templates.

llvm-svn: 61208
2008-12-18 19:37:40 +00:00
Chris Lattner 84a1162e4c add a simple fast-path for the common case of [] and [4] in
array size declarators.  No need to go through all the trouble
of parsing crazy things like [static const 4] when most code
doesn't need it.

llvm-svn: 61200
2008-12-18 07:27:21 +00:00
Chris Lattner cf0bab2042 disallow attributes in a few callers of ParseTypeQualifierListOpt,
these completely ignore parsed attributes anyway, so don't try
to read them.

llvm-svn: 61198
2008-12-18 07:02:59 +00:00
Chris Lattner b6ec4e75ad Clean up the C89/C++ warnings about C99 array features to not
emit duplicate diags (some in parser and some in sema) and to
warn about use of typequals in array sizes.  This implements 
PR2759.

llvm-svn: 61197
2008-12-18 06:50:14 +00:00
Chris Lattner d19c1c0d6d implement PR3177 - "__extension__ union" not supported in C++ mode
llvm-svn: 61180
2008-12-18 01:12:00 +00:00
Eli Friedman 44842d140f Do proper recovery from an invalid switch condiition. Fixes PR3229.
llvm-svn: 61160
2008-12-17 22:19:57 +00:00
Douglas Gregor ec8806e8ec Removed the warning
warning: statement was disambiguated as declaration

because it is currently firing in cases where the declaration would
not actually parse as a statement. We'd love to bring this warning
back if we can make it more accurate.

llvm-svn: 61137
2008-12-17 16:19:15 +00:00
Fariborz Jahanian 1470e9322e Semantics of @protocol attributes.
llvm-svn: 61114
2008-12-17 01:07:27 +00:00
Douglas Gregor 29ff7d0634 Make linkage-specifications hold on to all of their declarations
llvm-svn: 61110
2008-12-16 22:23:02 +00:00
Douglas Gregor 4d87df5853 Delay parsing of default arguments of member functions until the class
is completely defined (C++ [class.mem]p2).

Reverse the order in which we process the definitions of member
functions specified inline. This way, we'll get diagnostics in the
order in which the member functions were declared in the class.

llvm-svn: 61103
2008-12-16 21:30:33 +00:00
Sebastian Redl c675baba92 Some utilities for using the smart pointers in Actions, especially Sema. Convert a few functions.
llvm-svn: 60983
2008-12-13 16:23:55 +00:00
Sebastian Redl cb6e2c6156 Convert remaining expression parsers to smart pointers. Now on to the Action connection.
llvm-svn: 60982
2008-12-13 15:32:12 +00:00
Chris Lattner 6bf1db148c fix a buggy fall through that caused a crash-on-invalid. rdar://6248081
llvm-svn: 60961
2008-12-12 19:20:14 +00:00
Chris Lattner 10da53c60c use smarter error recovery for do/while.
llvm-svn: 60933
2008-12-12 06:35:28 +00:00
Chris Lattner c0081db332 apply the new error recovery smarts we have for if's to while's and switch's.
llvm-svn: 60932
2008-12-12 06:31:07 +00:00
Chris Lattner bc2d77cdf2 merge recovery-2.c into recovery-3.c.
Substantially improve error recovery after broken if conditions by
parsing the full if when we have a semantic error instead of using
parser recovery techniques to recover from a semantic error.

This fixes rdar://6094870 - spurious error after invalid 'if' condition

llvm-svn: 60929
2008-12-12 06:19:11 +00:00
Chris Lattner d8980509b3 minor refactoring of ParseParenExpression
llvm-svn: 60928
2008-12-12 06:00:12 +00:00
Sebastian Redl d65cea8dde Convert a big bunch of expression parsers to use smart pointers.
llvm-svn: 60906
2008-12-11 22:51:44 +00:00
Sebastian Redl 90893187c4 Convert some more expression parsers to use smart pointers.
llvm-svn: 60904
2008-12-11 22:33:27 +00:00
Sebastian Redl 59b5e517c7 Convert selected expression parsers to use smart pointers.
llvm-svn: 60900
2008-12-11 21:36:32 +00:00
Sebastian Redl bab9a4b5ea Convert the remaining statement parsers to smart pointers.
llvm-svn: 60895
2008-12-11 20:12:42 +00:00
Sebastian Redl b62406f6e4 Convert some more statement parsers to smart pointers.
llvm-svn: 60892
2008-12-11 19:48:14 +00:00
Sebastian Redl 042ad95d4e Convert a number of statement parsers to smart pointers.
llvm-svn: 60888
2008-12-11 19:30:53 +00:00
Douglas Gregor 91f84216f7 Unifies the name-lookup mechanisms used in various parts of the AST
and separates lexical name lookup from qualified name lookup. In
particular:
  * Make DeclContext the central data structure for storing and
    looking up declarations within existing declarations, e.g., members
    of structs/unions/classes, enumerators in C++0x enums, members of
    C++ namespaces, and (later) members of Objective-C
    interfaces/implementations. DeclContext uses a lazily-constructed
    data structure optimized for fast lookup (array for small contexts,
    hash table for larger contexts). 

  * Implement C++ qualified name lookup in terms of lookup into
    DeclContext.

  * Implement C++ unqualified name lookup in terms of
    qualified+unqualified name lookup (since unqualified lookup is not
    purely lexical in C++!)

  * Limit the use of the chains of declarations stored in
    IdentifierInfo to those names declared lexically.

  * Eliminate CXXFieldDecl, collapsing its behavior into
    FieldDecl. (FieldDecl is now a ScopedDecl).

  * Make RecordDecl into a DeclContext and eliminates its
    Members/NumMembers fields (since one can just iterate through the
    DeclContext to get the fields).

llvm-svn: 60878
2008-12-11 16:49:14 +00:00
Douglas Gregor 85970ca84c Added a warning when referencing an if's condition variable in the
"else" clause, e.g.,

  if (int X = foo()) {
  } else {
    if (X) { // warning: X is always zero in this context
    }
  }

Fixes rdar://6425550 and lets me think about something other than
DeclContext.

llvm-svn: 60858
2008-12-10 23:01:14 +00:00
Douglas Gregor 7307d6ca96 Use a scoped object to manage entry/exit from a parser scope rather than explicitly calling EnterScope/ExitScope
llvm-svn: 60830
2008-12-10 06:34:36 +00:00
Sebastian Redl d9f7b1c230 Modify the move emulation according to the excellent design of Howard Hinnant. Makes for much nicer syntax when smart pointers are used consistently. Also, start converting internal argument passing of Parser to smart pointers.
llvm-svn: 60809
2008-12-10 00:02:53 +00:00
Sebastian Redl c13f26873f Kick out the proof-of-concept ASTOwner and replace it with ASTOwningResult
llvm-svn: 60791
2008-12-09 20:22:58 +00:00
Sebastian Redl 7379577ab0 Lay the groundwork for converting the entire parser-sema chain to smart pointers.
llvm-svn: 60782
2008-12-09 19:36:21 +00:00
Sebastian Redl 17f2c7d251 Consistently use smart pointers for stmt and expr nodes in parser local variables.
llvm-svn: 60761
2008-12-09 13:15:23 +00:00
Chris Lattner 46415261ee Fix PR3172: if we see an eof or } at the top level, reject it.
This is important because ParseDeclarationOrFunctionDefinition
skips to, but does not consume, an } on error.

llvm-svn: 60719
2008-12-08 21:59:01 +00:00
Chris Lattner 3a90716f6a improve comment.
llvm-svn: 60718
2008-12-08 21:53:24 +00:00
Zhongxing Xu 8df5083bb4 fix typo.
llvm-svn: 60686
2008-12-08 05:12:38 +00:00
Douglas Gregor b0846b0f51 Add support for calls to dependent names within templates, e.g.,
template<typename T> void f(T x) {
    g(x); // g is a dependent name, so don't even bother to look it up
    g(); // error: g is not a dependent name
  }

Note that when we see "g(", we build a CXXDependentNameExpr. However,
if none of the call arguments are type-dependent, we will force the
resolution of the name "g" and replace the CXXDependentNameExpr with
its result.

GCC actually produces a nice error message when you make this
mistake, and even offers to compile your code with -fpermissive. I'll
do the former next, but I don't plan to do the latter.

llvm-svn: 60618
2008-12-06 00:22:45 +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
Sebastian Redl 538787f571 Add better comments to ::new parsing. Thanks to Doug for the review.
llvm-svn: 60423
2008-12-02 17:10:24 +00:00
Sebastian Redl db36b9b962 Make the parser handle ::new and ::delete correctly.
llvm-svn: 60421
2008-12-02 16:35:44 +00:00
Eli Friedman 39bc53593d Update cmake build; patch by Csaba Hruska.
llvm-svn: 60418
2008-12-02 16:23:30 +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
Douglas Gregor f558618fa4 A little more scaffolding for parsing templates:
- Template parameter scope to hold the template parameters
  - Template parameter context for parsing declarators
  - Actions for template type parameters and non-type template
    parameters

llvm-svn: 60387
2008-12-02 00:41:28 +00:00
Douglas Gregor eb31f39558 Basic support for parsing templates, from Andrew Sutton
llvm-svn: 60384
2008-12-01 23:54:00 +00:00
Douglas Gregor da747baa3c Improve error recovery when parsing a function definition fails
llvm-svn: 60380
2008-12-01 23:03:32 +00:00
Douglas Gregor 356513d7d0 Parse the exception-specification throw(...), a Microsoft extension
llvm-svn: 60359
2008-12-01 18:00:20 +00:00
Douglas Gregor 3be4b122d3 Implement the GNU __null extension
llvm-svn: 60235
2008-11-29 04:51:27 +00:00
Argyrios Kyrtzidis 9323b04b36 Attempt to unravel the if/else mess in Parser::ParseDirectDeclarator.
llvm-svn: 60124
2008-11-26 22:40:03 +00:00
Argyrios Kyrtzidis 0c4162a659 Add some comments.
llvm-svn: 60119
2008-11-26 21:51:07 +00:00
Argyrios Kyrtzidis ace521a1e1 Implement some suggestions by Daniel:
-Change Parser::ParseCXXScopeSpecifier to MaybeParseCXXScopeSpecifier
-Remove Parser::isTokenCXXScopeSpecifier and fold it into MaybeParseCXXScopeSpecifier
-Rename Parser::TryAnnotateScopeToken to TryAnnotateCXXScopeToken and only allow it to be called when in C++

llvm-svn: 60117
2008-11-26 21:41:52 +00:00
Fariborz Jahanian f8ef9f3dc9 Set default property attributes on each property.
Implemented anonymous category (also know as continuation class)
used to override main class's property attribute. This is work in 
propgress.

llvm-svn: 60114
2008-11-26 20:01:34 +00:00
Daniel Dunbar 762e77b55f Only call TryAnnotateScopeToken when parsing C++.
- This improves -parse-noop of Carbon.h by +2%, and I believe
   compensates for the majority of the performance regression in r58913.

llvm-svn: 60063
2008-11-25 23:05:24 +00:00
Sebastian Redl 511ed55524 Use RAII objects to ensure proper destruction of expression and statement AST nodes in the parser in most cases, even on error.
llvm-svn: 60057
2008-11-25 22:21:31 +00:00
Douglas Gregor 2afd0be069 Simple parsing of exception specifications, with no semantic analysis yet
llvm-svn: 60005
2008-11-25 03:22:00 +00:00
Sebastian Redl 198a5838df Remove an empty if and add a reminder for when we implement C++ try-catch.
llvm-svn: 59987
2008-11-24 21:45:59 +00:00
Chris Lattner 03c4041cb5 make the 'to match this' diagnostic a note.
llvm-svn: 59921
2008-11-23 23:17:07 +00:00
Chris Lattner e3d20d9545 Convert IdentifierInfo's to be printed the same as DeclarationNames
with implicit quotes around them.  This has a bunch of follow-on 
effects and requires tweaking to a whole lot of code.  This causes
a regression in two tests (xfailed) by causing it to emit things like:

  Line 10: duplicate interface declaration for category 'MyClass1' ('Category1')

instead of:

  Line 10: duplicate interface declaration for category 'MyClass1(Category1)'

I will fix this in a follow-up commit.

As part of this, I had to start switching stuff to use ->getDeclName() instead
of Decl::getName() for consistency.  This is good, but I was planning to do this
as an independent patch.  There will be several follow-on patches
to clean up some of the mess, but this patch is already too big.

llvm-svn: 59917
2008-11-23 21:45:46 +00:00
Chris Lattner 3b0f3ef97e remove some more old Diag methods, replace with a single static helper function
llvm-svn: 59868
2008-11-22 08:32:36 +00:00
Chris Lattner 399f9656ba Teach tentative parsing to handle block pointers (rdar://6394309)
llvm-svn: 59853
2008-11-22 01:15:33 +00:00
Chris Lattner 427c9c1763 Split the DiagnosticInfo class into two disjoint classes:
one for building up the diagnostic that is in flight (DiagnosticBuilder)
and one for pulling structured information out of the diagnostic when
formatting and presenting it.

There is no functionality change with this patch.

llvm-svn: 59849
2008-11-22 00:59:29 +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 15799fd210 Tiny fix to the parsing of linkage-specifications
llvm-svn: 59820
2008-11-21 16:10:08 +00:00
Chris Lattner 9b5a53424b Daniel really really likes = instead of += :)
llvm-svn: 59716
2008-11-20 07:09:32 +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
Douglas Gregor 7911b3711d Some tweaks suggested by Argiris
llvm-svn: 59661
2008-11-19 19:09:45 +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
Steve Naroff 9e4ac111f0 Fix <rdar://problem/6150376> [sema] crash on invalid message send.
The core fix in Sema::ActOnClassMessage(). All the other changes have to do with passing down the SourceLocation for the receiver (to properly position the cursor when producing an error diagnostic).

llvm-svn: 59639
2008-11-19 15:54:23 +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
Argyrios Kyrtzidis 89709ac2cc Fix this:
With this snippet:
  void f(a::b);

An assert is hit:
Assertion failed: CachedTokens[CachedLexPos-1].getLocation() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token", file ..\..\lib\Lex\PPCaching.cpp, line 98

Introduce Preprocessor::RevertCachedTokens that reverts a specific number of tokens when backtracking is enabled.

llvm-svn: 59636
2008-11-19 15:22:16 +00:00
Chris Lattner 760d19ade1 remove uses of IdentifierInfo::getName()
llvm-svn: 59607
2008-11-19 07:51:13 +00:00
Chris Lattner 406c096993 remove some uses of IdentifierInfo::getName()
llvm-svn: 59606
2008-11-19 07:49:38 +00:00
Chris Lattner 66e3877b42 Use smallstring instead of new[]'ing a string. This simplifies
the code and speeds it up.

llvm-svn: 59604
2008-11-19 07:41:27 +00:00
Chris Lattner ebad6a220f remove uses of IdentifierInfo::getName()
llvm-svn: 59603
2008-11-19 07:37:42 +00:00
Chris Lattner e05c4dfc42 Remove the last of the old-style Preprocessor::Diag methods.
llvm-svn: 59554
2008-11-18 21:48:13 +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
Chris Lattner 3d31c6c823 remove the last couple obsolete forms of Parser::Diag.
llvm-svn: 59510
2008-11-18 07:50:21 +00:00
Chris Lattner 6d29c10564 Change a couple of the Parser::Diag methods to return DiagnosticInfo
and let the clients push whatever they want into the DiagnosticInfo
instead of hard coding a few forms.  Also switch various clients to
use Diag(Tok, ...) instead of Diag(Tok.getLocation(), ...) as the
canonical form to simplify the code a bit.

llvm-svn: 59509
2008-11-18 07:48:38 +00:00
Chris Lattner 8488c8297c This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed.  In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a 
ton of random stuff.  This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.

In addition to introducing DiagnosticInfo, this also substantially changes how 
Diagnostic::Report works.  Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and 
ID) and returns a fresh DiagnosticInfo *by value*.  The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator.  When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information.  This is a somewhat tricky dance, but it means that the 
accumulated DiagnosticInfo is allowed to keep pointers to other expression 
temporaries without those pointers getting invalidated.

This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema.  For example, instead of calling:

  Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
       SourceRange(BuiltinLoc, RParenLoc));

We will soon be able to just do:

  Diag(BuiltinLoc, diag::err_overload_no_match)
      << typeNames << SourceRange(BuiltinLoc, RParenLoc));

This scales better to support arbitrary types being passed in (not just 
strings) in a type-safe way.  Go operator overloading?!

llvm-svn: 59502
2008-11-18 07:04:44 +00:00
Chris Lattner 16ba91396a Change the diagnostics interface to take an array of pointers to
strings instead of array of strings.  This reduces string copying
in some not-very-important cases, but paves the way for future 
improvements.

llvm-svn: 59494
2008-11-18 04:56:44 +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
Douglas Gregor d69246bd5b Some cleanups for C++ operator overloading
llvm-svn: 59443
2008-11-17 16:14:12 +00:00
Sebastian Redl ccdfabab35 Implement parsing and semantic checking of the 'mutable' keyword.
Thanks to Doug for the review. Actual effects of mutable to follow.

llvm-svn: 59331
2008-11-14 23:42:31 +00:00
Chris Lattner 0046de17e5 Fix a couple of suboptimalities in error recovery.
1. In the top level of ParseStatementOrDeclaration, don't eat a } if we
   just parsed a statement if it list there.  Also, don't even bother
   emitting an error about a missing semicolon if the statement had a 
   bug (an rbrace is fine).
2. In do/while parsing, don't require a 'while' to be present if the do
   body didn't parse.

This allows us to generate a clean diagnostic for this code:

t.c:1:22: error: expected expression
void foo (void) { do . while (0); }
                     ^

Thanks to Neil for pointing this out.

llvm-svn: 59256
2008-11-13 18:52:53 +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
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
Sebastian Redl c470476420 Implement C++ 'typeid' parsing and sema.
llvm-svn: 59042
2008-11-11 11:37:55 +00:00
Chris Lattner 8c5dd730ce Fix PR3031 by silencing follow-on errors in invalid declarations.
llvm-svn: 59027
2008-11-11 06:13:16 +00:00
Douglas Gregor 49de5340c0 Improve parser error recovery after a constructor initializer
llvm-svn: 58989
2008-11-10 16:59:40 +00:00
Douglas Gregor 6cf0806e75 Some cleanups to the declaration/checking of overloaded operators in C++. Thanks to Sebastian for the review
llvm-svn: 58986
2008-11-10 13:38:07 +00:00
Argyrios Kyrtzidis 32a0379575 Implement support for C++ nested-name-specifiers ('foo::bar::x') in the Parser side.
No Sema functionality change, just the signatures of the Action/Sema methods.

llvm-svn: 58913
2008-11-08 16:45:02 +00:00
Argyrios Kyrtzidis 0d9ee2eb2e Revert r58880, it breaks test/SemaCXX/constructor.cpp
llvm-svn: 58904
2008-11-08 12:02:25 +00:00
Daniel Dunbar ad0a0f9cd2 Silence a gcc warning.
llvm-svn: 58888
2008-11-08 04:28:37 +00:00
Argyrios Kyrtzidis 19b66a5e32 In a declarator, consider an identifier a constructor only if it is followed by '('.
Previously:

class C {
  int C;  // Declarator::SetConstructor was called here.
};

llvm-svn: 58880
2008-11-08 01:09:16 +00:00
Argyrios Kyrtzidis e442635c37 Changes in preparation for nested-name-specifiers.
-When parsing declarators, don't depend on "CurScope->isCXXClassScope() == true" for constructors/destructors
-For C++ member declarations, don't depend on "Declarator.getContext() == Declarator::MemberContext"

llvm-svn: 58866
2008-11-07 22:02:30 +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 56fa31bc87 Assert that Parser::MaybeParseOperatorFunctionId is called when token is kw_operator, and replace ExpectAndConsume for the 'operator' token with a ConsumeToken.
llvm-svn: 58855
2008-11-07 15:54:02 +00:00
Douglas Gregor 450c75a15f Separate the parsing of type-specifiers from other declaration specifiers, so that we can parse a C++ type-specifier-seq
llvm-svn: 58854
2008-11-07 15:42:26 +00:00
Douglas Gregor 7d5fc7e28b Initial, rudimentary implementation of operator overloading for binary
operators. For example, one can now write "x + y" where x or y is a
class or enumeration type, and Clang will perform overload resolution
for "+" based on the overloaded operators it finds.

The other kinds of overloadable operators in C++ will follow this same
approach. 

Three major issues remain:
  1) We don't find member operators
  2) Since we don't have user-defined conversion operators, we can't
  call any of the built-in overloaded operators in C++ [over.built].
  3) Once we've done the semantic checks, we drop the overloaded
  operator on the floor; it doesn't get into the AST at all.

llvm-svn: 58821
2008-11-06 23:29:22 +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 d7fc872d5c Add the remaining C++0x keywords
llvm-svn: 58802
2008-11-06 15:17:27 +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 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
Douglas Gregor 66583c5ff3 Implement C++ DR 106 and C++ DR 540, both of which deal with
reference-collapsing. 

Implement diagnostic for formation of a reference to cv void.

Drop cv-qualifiers added to a reference type when the reference type
comes from a typedef.

llvm-svn: 58612
2008-11-03 15:51:28 +00:00
Chris Lattner 8cc7be369c Fix PR3001: if we have an error parsing an initializer, make sure to remove
the designator corresponding to it, otherwise Sema and later parsing will
get confused.

llvm-svn: 58603
2008-11-03 09:28:22 +00:00
Sanjiv Gupta d79592448b Made the mechanism of defining preprocessor defs for maxint, ptrdiff_t, wchar
etc more generic. For some targets, long may not be equal to pointer size. For
example: PIC16 has int as i16, ptr as i16 but long as i32.

Also fixed a few build warnings in assert() functions in CFRefCount.cpp,
CGDecl.cpp, SemaDeclCXX.cpp and ParseDeclCXX.cpp.

llvm-svn: 58501
2008-10-31 09:52:39 +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
Daniel Dunbar f8362f9e5d "One" line fix for -parse-noop failure, "id" and several other things
were being treated as type names for non-Objective-C files.
 - Other lines are just because MinimalAction didn't have access to
   the LangOptions.

llvm-svn: 58498
2008-10-31 08:56:51 +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
Daniel Dunbar 03a3844c66 Add attribute always_inline support.
llvm-svn: 58304
2008-10-28 00:17:57 +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
Chris Lattner 248388e313 pass designators into sema. This completes parser-level designator
support as far as I know.

llvm-svn: 58217
2008-10-26 23:35:51 +00:00
Chris Lattner 9a53fdc23e implement some more FIXMEs, by rejecting more bogus stuff in
objc mode.

llvm-svn: 58216
2008-10-26 23:29:41 +00:00
Chris Lattner 46dcba6d2d add some simple designator testcases. Reject things like this:
struct foo Y[10] = {
  [4] .arr [2] 4  // expected-error {{expected '=' or another designator}}
};

because the "missing equals" extension only is valid if there 
is exactly one array designator.

llvm-svn: 58215
2008-10-26 23:22:23 +00:00
Chris Lattner 8aafd35c79 improve comments, build array and array range designator nodes,
fix an obscure memory leak.

llvm-svn: 58213
2008-10-26 23:06:54 +00:00
Chris Lattner 7243245a58 improve comments, build a Designation for field designators and
improve diagnostic for a malformed field designator.

llvm-svn: 58212
2008-10-26 22:59:19 +00:00
Chris Lattner e2b5e87f58 restructure ParseInitializerWithPotentialDesignator to make it
easier to understand and hack on, no functionality change.

llvm-svn: 58210
2008-10-26 22:49:49 +00:00
Chris Lattner dde6543731 improve MayBeDesignationStart to do the entire determination
about whether a leading identifier is a designator.

llvm-svn: 58207
2008-10-26 22:41:58 +00:00
Chris Lattner 3fa9239f41 inline the decision logic that chooses between an assign expr and brace
initializer, avoiding an extra level of calls for silly things like
'int x = 4'.

llvm-svn: 58206
2008-10-26 22:38:55 +00:00
Chris Lattner f3e58e2ebc This patch continues parser-level implementation of designators:
1. It introduces new parser level abstractions for designators
   that are used to communicate between parser and sema.
2. This fixes a FIXME where "identifier ':'" was considered to be
   a designator even if it wasn't the first in a designator list.
3. In the "identifier ':'" case, it actually builds the designator
   representation.

llvm-svn: 58205
2008-10-26 22:36:07 +00:00
Chris Lattner 0c02460038 minor cleanups
llvm-svn: 58203
2008-10-26 21:46:13 +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 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 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
Chris Lattner b795443082 some minor cleanups to ParseObjCTypeName:
1. Remove a bogus assertion, clients other than sema can return a
   null pointer from actions that result in ParseTypeName returning null.
2. Remove dead RParenLoc variable.
3. Simplify control flow handling error conditions.
4. On a major failure, we should skip until ')' not until '}'.

llvm-svn: 57949
2008-10-22 03:52:06 +00:00
Steve Naroff 90255b4f54 Fix a crasher during error recovery in Parser::ParseObjCTypeName().
Found this while fixing another unrelated radar.

llvm-svn: 57904
2008-10-21 14:15:04 +00:00
Chris Lattner 2dfde91064 eliminate ObjCPropertyAttrs an corresponding enums, just use
strcmp when needed.

llvm-svn: 57817
2008-10-20 07:43:01 +00:00
Chris Lattner 825bca174d rearrange some code.
llvm-svn: 57816
2008-10-20 07:39:53 +00:00
Chris Lattner 1db3354d89 more simplifications to error recovery in ParseObjCPropertyAttribute
llvm-svn: 57815
2008-10-20 07:37:22 +00:00
Chris Lattner 18ffde822f remove extraneous braces
llvm-svn: 57814
2008-10-20 07:36:58 +00:00
Chris Lattner beca77018a move some code around to make it fall through more, no functionality change.
llvm-svn: 57813
2008-10-20 07:24:39 +00:00
Chris Lattner 7661923999 reject properties completely in objc1 instead of emitting
weird errors about property attributes being unknown.

llvm-svn: 57812
2008-10-20 07:22:18 +00:00
Chris Lattner 64b1f2f030 More property attribute recovery improvements. Instead of this:
crash.m:8:12: error: type name requires a specifier or qualifier
@property (readonlyx, getter=isAwesome) int _awesome;
           ^
crash.m:8:29: error: expected ';' at end of declaration list
@property (readonlyx, getter=isAwesome) int _awesome;
                            ^
crash.m:8:39: error: expected identifier or '('
@property (readonlyx, getter=isAwesome) int _awesome;
                                      ^

we now get:

crash.m:8:12: error: unknown property attribute 'readonlyx'
@property (readonlyx, getter=isAwesome) int _awesome;
           ^

Also, we can eliminate isObjCPropertyAttribute now.

llvm-svn: 57811
2008-10-20 07:15:22 +00:00
Chris Lattner 43c76c38fa significantly simplify and clean up error recovery in
ParseObjCPropertyAttribute.  Before, on this code (where
a comma was forgotten):

@property (readonly getter=isAwesome) int _awesome;

we emitted:

crash.m:9:11: error: expected ')'
@property (readonly getter=isAwesome) int _awesome;
          ^
crash.m:9:37: error: type name requires a specifier or qualifier
@property (readonly getter=isAwesome) int _awesome;
                                    ^
crash.m:9:37: error: expected identifier or '('
crash.m:9:37: error: expected ';' at end of declaration list
crash.m:9:1: error: @property requires fields to be named
@property (readonly getter=isAwesome) int _awesome;
^

now we emit:

crash.m:9:21: error: expected ')'
@property (readonly getter=isAwesome) int _awesome;
                    ^
crash.m:9:11: error: to match this '('
@property (readonly getter=isAwesome) int _awesome;
          ^

llvm-svn: 57809
2008-10-20 07:00:43 +00:00
Chris Lattner 1ff6e73651 simplify some other code for __extension__ processing.
llvm-svn: 57807
2008-10-20 06:51:33 +00:00
Chris Lattner f02ef3e6d4 implement a couple fixme's by implementing __extension__ properly.
llvm-svn: 57806
2008-10-20 06:45:43 +00:00
Chris Lattner 93429b047b fix a crash on unnamed properties like:
@property (readonly) int : 4;

llvm-svn: 57805
2008-10-20 06:33:53 +00:00
Chris Lattner e0d3fe9b97 simplify some code by using ExpectAndConsume. When an error
occurs, skip to an @ or ; instead of to a } or ;.  Properties
don't necessarily live in {}'s.

llvm-svn: 57804
2008-10-20 06:15:13 +00:00
Chris Lattner da9fb15b90 refactor a bunch of code:
Check for @end in ParseObjCInterfaceDeclList instead of in each caller
Handle @required and @optional with the same code

Add some fixmes about some apparently objc2 code that is being accepted
in objc1.

llvm-svn: 57803
2008-10-20 06:10:06 +00:00
Chris Lattner bb8cc18788 fix some minor error recovery bugs in ParseObjCInterfaceDeclList
where it would reject @required in non-protocols, but then go
ahead and tag methods with required anyway.  Instead, if we see
this in something other than a protocol, just ignore the request.

Also, improve error recovery a bit when we see something bogus 
inside an interface.

llvm-svn: 57798
2008-10-20 05:57:40 +00:00
Chris Lattner 038a3e349d restructure the body of the ParseObjCInterfaceDeclList loop
to make it easier to understand.  No functionality change.

llvm-svn: 57797
2008-10-20 05:46:22 +00:00
Chris Lattner 29e6f2b674 Support attributes in *yet another* place. Is there any place you
can't stick an attributes?

llvm-svn: 57795
2008-10-20 04:57:38 +00:00
Chris Lattner 8ff2c6c9f0 Fix a parser bug where we let attributes interfere with our disambiguation
of whether a '(' was a grouping paren or the start of a function declarator.
This is PR2796.

Now we eat the attribute before deciding whether the paren is grouping or
not, then apply it to the resultant decl or to the first argument as needed.

One somewhat surprising aspect of this is that attributes interact with
implicit int in cases like this:

void a(x, y) // k&r style function
void b(__attribute__(()) x, y); // function with two implicit int arguments
void c(x, __attribute__(()) y); // error, can't have attr in identifier list.

Fun stuff.

llvm-svn: 57790
2008-10-20 02:05:46 +00:00
Chris Lattner fcc390a9df fix indentation
llvm-svn: 57788
2008-10-20 02:01:34 +00:00
Chris Lattner 409bf7d03a Remove an implemented fixme, only treat < as a type specifier
when ObjC is turned on.

llvm-svn: 57787
2008-10-20 00:25:30 +00:00