Commit Graph

161 Commits

Author SHA1 Message Date
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 efb0f111f1 hoist checks for ; and in out of ParseInitDeclaratorListAfterFirstDeclarator
into ParseSimpleDeclaration, and improve a diagnostic.

llvm-svn: 68009
2009-03-29 17:18:04 +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 2f14ce0a74 tidy whitespace.
llvm-svn: 67920
2009-03-28 06:13:37 +00:00
Douglas Gregor 333489bba3 Initial implementation of parsing, semantic analysis, and template
instantiation for C++ typename-specifiers such as

  typename T::type

The parsing of typename-specifiers is relatively easy thanks to
annotation tokens. When we see the "typename", we parse the
typename-specifier and produce a typename annotation token. There are
only a few places where we need to handle this. We currently parse the
typename-specifier form that terminates in an identifier, but not the
simple-template-id form, e.g.,

  typename T::template apply<U, V>

Parsing of nested-name-specifiers has a similar problem, since at this
point we don't have any representation of a class template
specialization whose template-name is unknown.

Semantic analysis is only partially complete, with some support for
template instantiation that works for simple examples. 

llvm-svn: 67875
2009-03-27 23:10:48 +00:00
Chris Lattner 9eac931b5f Fix rdar://6719156 - clang should emit a better error when blocks are disabled but are used anyway
by changing blocks from being disabled in the parser to being disabled
in Sema.

llvm-svn: 67816
2009-03-27 04:18:06 +00:00
Douglas Gregor c23500ebb3 Simplify CXXScopeSpec a lot. No more weird SmallVector-like hacks here
llvm-svn: 67800
2009-03-26 23:56:24 +00:00
Douglas Gregor 6c2adff380 Pass access specifiers through to member classes and member enums.
llvm-svn: 67710
2009-03-25 22:00:53 +00:00
Douglas Gregor 167fa625f3 Fix parsing of template classes prefixed by nested-name-specifiers
llvm-svn: 67685
2009-03-25 15:40:00 +00:00
Sebastian Redl f769df5ef9 Parse deleted function definitions and hook them up to Doug's machinery.
llvm-svn: 67653
2009-03-24 22:27:57 +00:00
Chris Lattner 803802d4d6 random cleanups.
llvm-svn: 67624
2009-03-24 17:04:48 +00:00
Sebastian Redl 3b27be6ceb Recognize rvalue references in C++03, but complain about them. This leads to far better error recovery.
llvm-svn: 67495
2009-03-23 00:00:23 +00:00
Douglas Gregor 5253768ada Introduce a representation for types that we referred to via a
qualified name, e.g., 

  foo::x

so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.

The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
 
  ::foo::bar::x

The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled). 

The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).

Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.

llvm-svn: 67265
2009-03-19 00:18:19 +00:00
Sebastian Redl ed0f3b021e Parser support for rvalue references.
llvm-svn: 67033
2009-03-15 22:02:01 +00:00
Sebastian Redl 6d4256c3c1 Convert a bunch of actions to smart pointers, and also bring PrintParserCallbacks a bit more in line with reality.
llvm-svn: 67029
2009-03-15 17:47:39 +00:00
Anders Carlsson f24fcff65e Add parser support for static_assert.
llvm-svn: 66661
2009-03-11 16:27:10 +00:00
Steve Naroff 9527bbfc08 Implement property '.' notation on Factory/Class objects. Parser changes aren't very pretty:-(
This fixes <rdar://problem/6496506> Implement class setter/getter for properties.

llvm-svn: 66465
2009-03-09 21:12:44 +00:00
Douglas Gregor d9f92e2a06 Clean up some error messages with anonymous structs/unions and member declaration parsing. Fixes PR3680
llvm-svn: 66305
2009-03-06 23:28:18 +00:00
Chris Lattner eae6cb6154 rename PrettyStackTraceDecl -> PrettyStackTraceActionsDecl.
Introduce a new PrettyStackTraceDecl.
Use it to add the top level LLVM IR generation stuff in 
Backend.cpp to stack traces.  We now get crashes like:

Stack dump:
0.	Program arguments: clang t.c -emit-llvm 
1.	<eof> parser at end of file
2.	t.c:1:5: LLVM IR generation of declaration 'a'
Abort

for IR generation crashes.

llvm-svn: 66153
2009-03-05 08:00:35 +00:00
Chris Lattner 477f990ac5 Include struct context info for parser/sema crashes. This
gives us:

Stack dump:
0.	using-directive.cpp:26:16: in compound statement ('{}')
1.	using-directive.cpp:26:16: parsing function body 'A::K1::foo'
2.	using-directive.cpp:25:3: parsing struct/union/class body 'A::K1'
3.	using-directive.cpp:5:1: parsing namespace 'A'
4.	clang using-directive.cpp 
Abort

for code like:

namespace A {
...
  class K1 {
    void foo() { <<crash>>

llvm-svn: 66124
2009-03-05 02:25:03 +00:00
Chris Lattner bd61a95481 Include information about compound statements when crashing in sema or the
parser.  For example, we now print out:

0.	t.c:5:10: in compound statement {}
1.	t.c:3:12: in compound statement {}
2.	clang t.c -fsyntax-only

llvm-svn: 66108
2009-03-05 00:00:31 +00:00
Chris Lattner de39c3efcb cleanup
llvm-svn: 65646
2009-02-27 18:38:20 +00:00
Douglas Gregor d54dfb8718 Implementing parsing of template-ids as class-names, so that we can
derive from a class template specialization, e.g.,

  class B : public A<int> { };

llvm-svn: 65488
2009-02-25 23:52:28 +00:00
Douglas Gregor 7f74112756 Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type

When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:

  template<> class Outer::Inner<int> { ... };

We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.

Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.

llvm-svn: 65467
2009-02-25 19:37:18 +00:00
Douglas Gregor 220cac5e89 Update Parser::ParseTypeName to return a TypeResult, which also tells
us whether there was an error in trying to parse a type-name (type-id
in C++). This allows propagation of errors further in the compiler,
suppressing more bogus error messages.

llvm-svn: 64922
2009-02-18 17:45:20 +00:00
Douglas Gregor 94349fd8cb Allow "overloadable" functions in C to be declared as variadic without
any named parameters, e.g., this is accepted in C:

  void f(...) __attribute__((overloadable));

although this would be rejected:

  void f(...);

To do this, moved the checking of the "ellipsis without any named
arguments" condition from the parser into Sema (where it belongs anyway).

llvm-svn: 64902
2009-02-18 07:07:28 +00:00
Douglas Gregor 67a6564091 Implement basic parsing and semantic analysis for explicit
specialization of class templates, e.g.,

  template<typename T> class X;

  template<> class X<int> { /* blah */ };

Each specialization is a different *Decl node (naturally), and can
have different members. We keep track of forward declarations and
definitions as for other class/struct/union types.

This is only the basic framework: we still have to deal with checking
the template headers properly, improving recovery when there are
failures, handling nested name specifiers, etc.

llvm-svn: 64848
2009-02-17 23:15:12 +00:00
Douglas Gregor 8bf4205c70 Start processing template-ids as types when the template-name refers
to a class template. For example, the template-id 'vector<int>' now
has a nice, sugary type in the type system. What we can do now:

  - Parse template-ids like 'vector<int>' (where 'vector' names a
    class template) and form proper types for them in the type system.
  - Parse icky template-ids like 'A<5>' and 'A<(5 > 0)>' properly,
    using (sadly) a bool in the parser to tell it whether '>' should
    be treated as an operator or not.

This is a baby-step, with major problems and limitations:
  - There are currently two ways that we handle template arguments
  (whether they are types or expressions). These will be merged, and,
  most likely, TemplateArg will disappear.
  - We don't have any notion of the declaration of class template
  specializations or of template instantiations, so all template-ids
  are fancy names for 'int' :)

llvm-svn: 64153
2009-02-09 18:46:07 +00:00
Sebastian Redl f6591ca6d9 Implement Declarator::getSourceRange().
llvm-svn: 64151
2009-02-09 18:23:29 +00:00
Douglas Gregor 9817f4a717 Make Sema::getTypeName return the opaque pointer of a QualType rather
than a Decl, which gives us some more flexibility to express the
results with the type system. There are no clients using this
flexibility yet, but it's meant to be able to describe qualified names
as written in the source (e.g., "foo::type") or template-ids that name
a class template specialization (e.g., "std::vector<INT>").

DeclSpec's TST_typedef has become TST_typename, to reflect its use to
describe types found by name (that may or may not be typedefs). The
type representation of a DeclSpec with TST_typename is an opaque
QualType pointer. All users of TST_typedef, both direct and indirect,
have been updated for these changes.

llvm-svn: 64141
2009-02-09 15:09:02 +00:00
Douglas Gregor cd72ba97e7 Semantic checking for class template declarations and
redeclarations. For example, checks that a class template
redeclaration has the same template parameters as previous
declarations.

Detangled class-template checking from ActOnTag, whose logic was
getting rather convoluted because it tried to handle C, C++, and C++
template semantics in one shot.

Made some inroads toward eliminating extraneous "declaration does not
declare anything" errors by adding an "error" type specifier.

llvm-svn: 63973
2009-02-06 22:42:48 +00:00
Sebastian Redl 726a0d9524 Put the invalid flag of OwningResult into the Action pointer.
This shrinks OwningResult by one pointer. Since it is no longer larger than OwningPtr, merge the two.
This leads to simpler client code and speeds up my benchmark by 2.7%.
For some reason, this exposes a previously hidden bug, causing a regression in SemaCXX/condition.cpp.

llvm-svn: 63867
2009-02-05 15:02:23 +00:00
Douglas Gregor ded2d7b021 Basic representation of C++ class templates, from Andrew Sutton.
llvm-svn: 63750
2009-02-04 19:02:06 +00:00
Douglas Gregor 8a6be5ec64 Diagnose ambiguities in getTypeName. Fixes http://llvm.org/bugs/show_bug.cgi?id=3475
llvm-svn: 63737
2009-02-04 17:00:24 +00:00
Steve Naroff 3b6a4bd891 Simplify/cleanup r63219 (based on Chris review).
llvm-svn: 63393
2009-01-30 14:23:32 +00:00
Chris Lattner 60f36223a9 move library-specific diagnostic headers into library private dirs. Reduce
redundant #includes.  Patch by Anders Johnsen!

llvm-svn: 63271
2009-01-29 05:15:15 +00:00
Steve Naroff 16c8e598ae Name change (isTypeName->getTypeName).
Since it doesn't return a bool, is shouldn't be prefixed with 'is'.

llvm-svn: 63226
2009-01-28 19:39:02 +00:00
Steve Naroff b04867265c Change Parser::ParseFunctionDeclarator() to annotate typename tokens.
This removes ~10% of the calls to Sema::isTypeName(), which amount to a little less than a 1% reduction in usertime (for Cocoa.h).

llvm-svn: 63219
2009-01-28 19:16:40 +00:00
Chris Lattner 7368d581c1 Split the single monolithic DiagnosticKinds.def file into one
.def file for each library.  This means that adding a diagnostic
to sema doesn't require all the other libraries to be rebuilt.

Patch by Anders Johnsen!

llvm-svn: 63111
2009-01-27 18:30:58 +00:00
Douglas Gregor f829825d04 Some micro-optimizations for DISABLE_SMART_POINTERS:
- When it's safe, ActionResult uses the low bit of the pointer for
  the "invalid" flag rather than a separate "bool" value. This keeps
  GCC from generating some truly awful code, for a > 3x speedup in the
  result-passing microbenchmark.
  - When DISABLE_SMART_POINTERS is defined, store an ActionResult
  within ASTOwningResult rather than an ASTOwningPtr. Brings the
  performance benefits of the above to smart pointers with
  DISABLE_SMART_POINTERS defined.

Sadly, these micro-benchmark performance improvements don't seem to
make much of a difference on Cocoa.h right now. However, they're
harmless and might help with future optimizations.

llvm-svn: 63061
2009-01-26 22:44:13 +00:00
Sebastian Redl 9ed6efdd75 Add support for declaring pointers to members.
Add serialization support for ReferenceType.

llvm-svn: 62934
2009-01-24 21:16:55 +00:00
Chris Lattner e387d9ed5b Inline ParseOptionalTypeSpecifier into ParseDeclarationSpecifiers.
This avoids call overhead and extraneous switches when parsing
very simple declspecs like "int" "void" etc, which are pretty common :)

llvm-svn: 62711
2009-01-21 19:48:37 +00:00
Chris Lattner 78ecd4f61e ParseOptionalTypeSpecifier should consume a token if it returns true.
llvm-svn: 62704
2009-01-21 19:19:26 +00:00
Chris Lattner 1ce41edd8d Optimize Declarator to avoid malloc/free traffic for the argument list of a
function DeclaratorChunk in common cases.  This uses a fixed array in 
Declarator when it is small enough for the first function declarator chunk
in a declarator.

This eliminates all malloc/free traffic from DeclaratorChunk::getFunction
when running on Cocoa.h except for five functions: signal/bsd_signal/sigset,
which have multiple Function DeclChunk's, and 
CFUUIDCreateWithBytes/CFUUIDGetConstantUUIDWithBytes, which take more than
16 arguments.

This patch was pair programmed with Steve.

llvm-svn: 62599
2009-01-20 19:11:22 +00:00
Sebastian Redl ffbcf96d1c Convert a few expression actions to smart pointers.
These actions are extremely widely used (identifier expressions and literals); still no performance regression.

llvm-svn: 62468
2009-01-18 18:53:16 +00:00
Sebastian Redl c2edafbdff Rename move_convert to move_arg and move_res. The new names are less misleading (and shorter).
llvm-svn: 62466
2009-01-18 18:03:53 +00:00
Fariborz Jahanian 94234ea63e Catch a foreach parse error.
llvm-svn: 62382
2009-01-17 00:00:40 +00:00
Douglas Gregor c6f58fe266 Implement support for anonymous structs and unions in C. Both C and
C++ handle anonymous structs/unions in the same way. Addresses several
bugs:

  <rdar://problem/6259534>
  <rdar://problem/6481130>
  <rdar://problem/6483159>

The test case in PR clang/1750 now passes with -fsyntax-only, but
CodeGen for inline assembler still fails.

llvm-svn: 62112
2009-01-12 22:49:06 +00:00
Douglas Gregor b37080a969 Allow multiple Microsoft calling-convention keywords. Fixes rdar://problem/6486133
llvm-svn: 62018
2009-01-10 00:48:18 +00:00