Commit Graph

1156 Commits

Author SHA1 Message Date
Douglas Gregor 99fa264a67 Provide code completion results for the context-sensitive Objective-C
keywords "in", "out", "inout", "byref", "bycopy", and "oneway".

llvm-svn: 111884
2010-08-24 01:06:58 +00:00
John McCall b268a282a4 Kill off ExprArg (now just Expr*) and StmtArg (now just Stmt*).
llvm-svn: 111863
2010-08-23 23:25:46 +00:00
Fariborz Jahanian 616d3e71c2 Handling remaining rule for synthesize bitfields in
class extensions (nonfragile-abi2).For every class @interface and class
extension @interface, if the last ivar is a bitfield of any type,
then add an implicit `char :0` ivar to the end of that interface.

llvm-svn: 111857
2010-08-23 22:46:52 +00:00
Douglas Gregor 68762e7852 Introduce a code-completion hook for the Objective-C collection
argument in a for-each statement (e.g., "for (id x in <blah>)"), which
restricts the expression completions provided to Objective-C types (or
class types in C++).

llvm-svn: 111843
2010-08-23 21:17:50 +00:00
Douglas Gregor c49f5b2f11 Introduce a new code-completion point when we're parsing a
declarator. Here, we can only see a few things (e.g., cvr-qualifiers,
nested name specifiers) and we do not want to provide other non-macro
completions. Previously, we would end up in recovery mode and would
provide a large number of non-relevant completions.

llvm-svn: 111818
2010-08-23 18:23:48 +00:00
Douglas Gregor a05f5aba9a When complaining about a duplicate declspec, provide a Fix-It that
removes the copy. Patch from Eelis van der Weegen, tweaked/updated by
me.

llvm-svn: 111807
2010-08-23 14:34:43 +00:00
John McCall 3e56fd4d22 Push DeclGroupRefs and TemplateNames in an opaque but type-safe way
through the parser.

llvm-svn: 111800
2010-08-23 07:28:44 +00:00
John McCall 572ccbc2c2 Kill off Parser::TemplateParameterList to avoid misparses.
llvm-svn: 111796
2010-08-23 06:53:58 +00:00
John McCall 37ad551a25 Sundry incremental steps towards killing off Action.
llvm-svn: 111795
2010-08-23 06:44:23 +00:00
John McCall 4887165193 DeclPtrTy -> Decl *
llvm-svn: 111733
2010-08-21 09:40:31 +00:00
John McCall 8b0666cf79 Another step in the process of making the parser depend on Sema:
- move DeclSpec &c into the Sema library
  - move ParseAST into the Parse library
Reflect this change in a thousand different includes.
Reflect this change in the link orders.

llvm-svn: 111667
2010-08-20 18:27:03 +00:00
Fariborz Jahanian 358acd5dff Get rid of extra nesting when checking for invalid type,
per Doug's comment.

llvm-svn: 111328
2010-08-17 23:50:37 +00:00
Fariborz Jahanian 9d7d3d84ac Diagnose if type of iboutletcollection attribute is a builtin type.
llvm-svn: 111324
2010-08-17 23:19:16 +00:00
Chris Lattner d28e6cc554 Add a slightly better hack for microsoft style inline asm,
patch by Per Linden!

llvm-svn: 111235
2010-08-17 16:00:12 +00:00
Fariborz Jahanian 055068df4a Fix a crash when parsing malformed out-of-line member function
definition. radar 8307865.

llvm-svn: 111163
2010-08-16 17:58:53 +00:00
Argyrios Kyrtzidis 3084a61e98 -Make TokenID of IdentifierInfo read-only, remove setTokenID().
-There are 2 instances that change the TokenID for GNU libstdc++ 4.2 compatibility.
  To handler those cases introduce a RevertedTokenID bitfield, RevertTokenIDToIdentifier() and hasRevertedTokenIDToIdentifier() methods.
  Store the bitfield in PCH.

llvm-svn: 110868
2010-08-11 22:55:12 +00:00
Douglas Gregor 00c37ef021 Once code completion has completed, pass a "completion context" on to
the code-completion consumer. The consumer can use this information to
augument, filter, or display the code-completion results.

llvm-svn: 110858
2010-08-11 21:23:17 +00:00
John Thompson cdb847ba16 Added vecreturn attribute parsing.
llvm-svn: 110609
2010-08-09 21:53:52 +00:00
Argyrios Kyrtzidis c0dc36b213 Change warning about incomplete parsing of C++ default arg to error and provide a test case; thanks Doug!
llvm-svn: 110603
2010-08-09 21:08:13 +00:00
Argyrios Kyrtzidis 773894ccec Replace a parser assertion with a warning, suggestion by Doug.
llvm-svn: 110568
2010-08-09 10:54:26 +00:00
Douglas Gregor a49ccfeeb2 The pre-increment/pre-decrement grammar in C++ differs from that in C,
but we were parsing the C grammar. Handle the C++ grammar
appropriately. Fixes PR7794.

llvm-svn: 110445
2010-08-06 14:50:36 +00:00
Abramo Bagnara 7c5dee4280 Template keyword should not be ignored building a QualifiedTemplateName.
llvm-svn: 110441
2010-08-06 12:11:11 +00:00
Argyrios Kyrtzidis 249179cd73 Introduce a new token kind 'cxx_defaultarg_end' to mark the end of C++ default arguments that were part of
lexed method declarations.

This avoid interference with tokens coming after the point where the default arg tokens were 'injected', e.g. for

typedef struct Inst {
  void m(int x=0);
} *InstPtr;

when parsing '0' the next token would be '*' and things would be messed up.

llvm-svn: 110436
2010-08-06 09:47:24 +00:00
Nick Lewycky 2667f1d409 Remove ElseScope which is also dead code now.
llvm-svn: 110433
2010-08-06 06:50:17 +00:00
John McCall 0f8ccc4938 Allow multiple __declspec attributes after a class-key.
Patch by Francois Pichet!

llvm-svn: 110344
2010-08-05 17:13:11 +00:00
Eli Friedman 570024a8d9 Implement #pragma GCC visibility.
llvm-svn: 110315
2010-08-05 06:57:20 +00:00
Daniel Dunbar cb82acb884 Parser: Add support for #pragma align, which is just another spelling of #pragma
options align.

llvm-svn: 109952
2010-07-31 19:17:07 +00:00
Ted Kremenek d21139a34f After a lengthy design discussion, add support for "ownership attributes" for malloc/free checking. Patch by Andrew McGregor!
llvm-svn: 109939
2010-07-31 01:52:11 +00:00
Abramo Bagnara ed5b6899ab Fixed typedef inside extern "C".
llvm-svn: 109865
2010-07-30 16:47:02 +00:00
John McCall 413021a8c7 Improve error recovery when presented with an ill-formed template-id
(e.g. due to a broken template argument) following template parameters.

Fixes rdar://problem/8254267

llvm-svn: 109853
2010-07-30 06:26:29 +00:00
Douglas Gregor da2955ed74 Reword the empty struct/union warning in C to note that such structs and unions have size 0 in C, size 1 in C++. Put this warning under -Wc++-compat.
llvm-svn: 109748
2010-07-29 14:29:34 +00:00
Douglas Gregor 5dc055350e The grammar for GNU typeof in C requires an expression to be
parenthesized, unlike in C++, e.g.,

  C has: typeof ( expression) 
  C++ has: typeof unary-expression

So, once we've parsed a parenthesized expression after typeof, we
should only go on to parse the postfix expression suffix if we're in
C++. Fixes <rdar://problem/8237491>.

llvm-svn: 109606
2010-07-28 18:22:12 +00:00
Nick Lewycky 19b9f958e1 Add source location information to C++ base specifiers.
llvm-svn: 109396
2010-07-26 16:56:01 +00:00
Douglas Gregor 67ca40c419 Eliminate the "minimal" and printing parser actions, which only ever
worked for C anyway. Also kills the -cc1 options -parse-noop and
-parse-print-callbacks.

llvm-svn: 109392
2010-07-26 04:08:02 +00:00
Fariborz Jahanian 6e7e8cc19d atch for implementation of objective-c's -Wselector
warning flag in clang. Little more to do
for a PCH issue. Radar 6507158.

llvm-svn: 109129
2010-07-22 18:24:20 +00:00
Chandler Carruth 3c31aa3a44 Fix PR7673 by allowing an empty clobbers section in an ASM statement.
llvm-svn: 109087
2010-07-22 07:11:21 +00:00
Chris Lattner 8d72f2aa3a tidy up comment.
llvm-svn: 108676
2010-07-19 05:07:24 +00:00
Chris Lattner ad4f38b1a9 BUILD_ARCHIVE is the default for libraries, no need to set it.
llvm-svn: 108633
2010-07-18 00:14:47 +00:00
John McCall 796c2a52a9 Treat template parameters as part of the declaration-specifiers for the
purpose of access control.  Fixes PR7644.

I can't actually find anything directly justifying this, but it seems obvious.

llvm-svn: 108521
2010-07-16 08:13:16 +00:00
Douglas Gregor dc9361876c When we're performing tentative parsing to determine whether the
parser is looking at a declaration or an expression, use a '=' to
conclude that we are parsing a declaration.

This is wrong. However, our previous approach of finding a comma after
the '=' is also wrong, because the ',' could be part of a
template-argument-list. So, for now we're going to use the same wrong
heuristic as GCC and Visual C++, because less real-world code is
likely to be broken this way. I've opened PR7655 to keep track of our
wrongness; note also the XFAIL'd test.

Fixes <rdar://problem/8193163>.

llvm-svn: 108459
2010-07-15 21:05:01 +00:00
Douglas Gregor f2753b3b4e Downgrade the "when type is in parentheses, array cannot have dynamic
size" error for code like 

  new (int [size])

to a warning, add a Fix-It to remove the parentheses, and make this
diagnostic work properly when it occurs in a template
instantiation. <rdar://problem/8018245>.

llvm-svn: 108242
2010-07-13 15:54:32 +00:00
Argyrios Kyrtzidis 36745fda34 Modify the pragma handlers to accept and use StringRefs instead of IdentifierInfos.
When loading the PCH, IdentifierInfos that are associated with pragmas cause declarations that use these identifiers to be deserialized (e.g. the "clang" pragma causes the "clang" namespace to be loaded).
We can avoid this if we just use StringRefs for the pragmas.

As a bonus, since we don't have to create and pass IdentifierInfos, the pragma interfaces get a bit more simplified.

llvm-svn: 108237
2010-07-13 09:07:17 +00:00
Chris Lattner 0931644922 revert a hunk of code that Argiris added in r106213, which is the
root cause of PR7481 and probably more, and has no apparent 
testcases.  I don't understand the logic here so I can't repair it.

llvm-svn: 108119
2010-07-12 01:48:28 +00:00
Chris Lattner 1390134c18 Fix PR7617 by not entering ParseFunctionDefinition when
a function prototype is followed by a declarator if we
aren't parsing a K&R style identifier list.

Also, avoid skipping randomly after a declaration if a
semicolon is missing.  Before we'd get:

t.c:3:1: error: expected function body after function declarator
void bar();
^

Now we get:

t.c:1:11: error: invalid token after top level declarator
void foo()
          ^
          ;

llvm-svn: 108105
2010-07-11 22:42:07 +00:00
Chris Lattner dbb1e93a9f add a const qualifier, refactor some code.
llvm-svn: 108104
2010-07-11 22:24:20 +00:00
Douglas Gregor 4587969555 Support code completion for parameter names in Objective-C method
declarations.

llvm-svn: 107933
2010-07-08 23:37:41 +00:00
Douglas Gregor 95887f9c5b Introduce a new code-completion point prior to an identifier in the
selector of an Objective-C method declaration, e.g., given

  - (int)first:(int)x second:(int)y;

this code completion point triggers at the location of "second". It
will provide completions that fill out the method declaration for any
known method, anywhere in the translation unit.

llvm-svn: 107929
2010-07-08 23:20:03 +00:00
Douglas Gregor 0be31a2eb7 Move the "current scope" state from the Parser into Action. This
allows Sema some limited access to the current scope, which we only
use in one way: when Sema is performing some kind of declaration that
is not directly driven by the parser (e.g., due to template
instantiatio or lazy declaration of a member), we can find the Scope
associated with a DeclContext, if that DeclContext is still in the
process of being parsed. 

Use this to make the implicit declaration of special member functions
in a C++ class more "scope-less", rather than using the NULL Scope hack.

llvm-svn: 107491
2010-07-02 17:43:08 +00:00
Douglas Gregor dc13ded606 Implement C++ DR481, which clarifies that the scope of template
parameters starts at the end of the template-parameter rather than at
the point where the template parameter name is encounted. For example,
given:

  typedef unsigned char T;
  template<typename T = T> struct X0 { };

The "T" in the default argument refers to the typedef of "unsigned
char", rather than referring to the newly-introduced template type
parameter 'T'. 

Addresses <rdar://problem/8122812>.

llvm-svn: 107354
2010-07-01 00:00:45 +00:00
Chandler Carruth 2d69ec7a72 Partial fix for PR7267 based on comments by John McCall on an earlier patch.
This is more targeted, as it simply provides toggle actions for the parser to
turn access checking on and off. We then use these to suppress access checking
only while we parse the template-id (included scope specifier) of an explicit
instantiation and explicit specialization of a class template. The
specialization behavior is an extension, as it seems likely a defect that the
standard did not exempt them as it does explicit instantiations.

This allows the very common practice of specializing trait classes to work for
private, internal types. This doesn't address instantiating or specializing
function templates, although those apparently already partially work.

The naming and style for the Action layer isn't my favorite, comments and
suggestions would be appreciated there.

llvm-svn: 106993
2010-06-28 08:39:25 +00:00
Duncan Sands d3e231eb3c Add parentheses suggested by gcc.
llvm-svn: 106668
2010-06-23 19:34:52 +00:00
Chris Lattner 37141f4fb4 improve altivec vector bool/pixel support, patch by Anton Yartsev
with several tweaks by me.

llvm-svn: 106619
2010-06-23 06:00:24 +00:00
Argyrios Kyrtzidis 75000b6814 Fix PR7180.
For

void f( a:🅱️:c );

we would cache the tokens "a:🅱️:" but then we would try to annotate them using the range "a::".
Before annotating them with the (invalid) C++ scope spec, set it to the range of "a:🅱️:".

llvm-svn: 106536
2010-06-22 11:30:04 +00:00
Douglas Gregor 9377c8230b When semantic analysis fail to introduce a class or class template,
just skip over the body of the class or class template: it's a
semantic disaster that's likely to cause invariants to break. Fixes
part of <rdar://problem/8104754>.

llvm-svn: 106496
2010-06-21 22:31:09 +00:00
Argyrios Kyrtzidis e1224c8aba Cure for Doug's insomnia.
llvm-svn: 106394
2010-06-19 19:58:34 +00:00
Fariborz Jahanian ef5f621215 Implements Sema part of init_priority(priority) attribute
(radar 8076356) - wip.

llvm-svn: 106322
2010-06-18 21:44:06 +00:00
Argyrios Kyrtzidis e9b76afe4f Make sure the caching mechanism in Parser::ParseLexedMethodDefs is robust against the parser reading too few tokens.
llvm-svn: 106214
2010-06-17 10:52:22 +00:00
Argyrios Kyrtzidis 355094ef06 Make sure parens/braces/brackets are correctly balanced.
In a line like:

(;

the semicolon leaves Parser:ParenCount unbalanced (it's 1 even though we stopped looking for a right paren).
This may affect later parsing and result in bad recovery for parsing errors.

llvm-svn: 106213
2010-06-17 10:52:18 +00:00
Ted Kremenek 24c8e4f245 Per conversation with Doug, remove two assertions in ParseLexedMethodDefs() that
didn't indicate violated invariants but that we weren't recovering well.

llvm-svn: 106195
2010-06-17 00:59:17 +00:00
Alexis Hunt c675ec09f0 Update CMake build for new attribute changes.
llvm-svn: 106188
2010-06-17 00:37:02 +00:00
Douglas Gregor 428119e39a When parsing cached C++ method declarations/definitions, save the
"previous token" location at the end of the class definition. This
eliminates a badly-placed error + Fix-It when the ';' following a
class definition is missing. Fixes <rdar://problem/8066414>.

llvm-svn: 106175
2010-06-16 23:45:56 +00:00
Douglas Gregor 13d0568ecc Make the "extra ';' inside a struct or union" diagnostic more
precise. Fixes PR7336.

llvm-svn: 106170
2010-06-16 23:08:59 +00:00
Douglas Gregor bb1196534c When we see a 'template' disambiguator that marks the next identifier
(or operator-function-id) as a template, but the context is actually
non-dependent or the current instantiation, allow us to use knowledge
of what kind of template it is, e.g., type template vs. function
template, for further syntactic disambiguation. This allows us to
parse properly in the presence of stray "template" keywords, which is
necessary in C++0x and it's good recovery in C++98/03.

llvm-svn: 106167
2010-06-16 23:00:59 +00:00
Douglas Gregor f7d7771812 Fix the recently-added warning about 'typename' and 'template'
disambiguation keywords outside of templates in C++98/03. Previously,
the warning would fire when the associated nested-name-specifier was
not dependent, but that was a misreading of the C++98/03 standard:
now, we complain only when we're outside of any template.

llvm-svn: 106161
2010-06-16 22:31:08 +00:00
Douglas Gregor 9938e3b11b Add some missing parentheses, from Anton Yartsev
llvm-svn: 106101
2010-06-16 15:28:57 +00:00
Chris Lattner f3d3b36870 Allow an asm label specifier on C++ methods, like GCC does.
Patch by David Majnemer!

llvm-svn: 105909
2010-06-13 05:34:18 +00:00
Daniel Dunbar ee6b692551 Makefiles: Set Clang CPP compiler flags in a single location, instead of scattered throughout the project Makefiles.
llvm-svn: 105638
2010-06-08 20:44:43 +00:00
Daniel Dunbar e6c1daa8fd Makefile: Switch Clang Makefiles to always include the top-level Clang Makefile.
- This eliminates most dependencies on how Clang is installed relative to LLVM.

llvm-svn: 105637
2010-06-08 20:34:18 +00:00
Abramo Bagnara d73405829b Added AccessSpecDecl node.
llvm-svn: 105525
2010-06-05 05:09:32 +00:00
Douglas Gregor 71b209dea6 Properly disambiguate between an elaborated-type-specifier and a
type-parameter within a template parameter list. Found by inspection. 

llvm-svn: 105462
2010-06-04 07:30:15 +00:00
Daniel Dunbar 6906b04457 Fix compiler warning about to false -> pointer conversion; patch by Dimitry Andric!
llvm-svn: 105328
2010-06-02 15:47:03 +00:00
Chris Lattner 47054fbbe9 Minor tweaks on doug's objc recovery patch: the caller
of isSimpleObjCMessageExpression checks the language,
so change a dynamic check into an assert.

isSimpleObjCMessageExpression is expensive, so only do it
in the common case when it is likely to matter: when the [
of the postfix expr starts on a new line.  This should avoid
doing lookahead for every array expression.

llvm-svn: 105229
2010-05-31 18:18:22 +00:00
Douglas Gregor 990ccace5b When we see the a '[' in a postfix expression in Objective-C, perform
a simple, quick check to determine whether the expression starting
with '[' can only be an Objective-C message send. If so, don't parse
it as an array subscript expression. This improves recovery for, e.g.,

  [a method1]
  [a method2]

so that we now produce

  t.m:10:13: error: expected ';' after expression
  [a method]
            ^

instead of some mess about expecting ']'.

llvm-svn: 105221
2010-05-31 14:40:22 +00:00
Douglas Gregor d5a479cbb5 Don't try to parse class template specializations in C. It can only
lead to heartache. Fixes <rdar://problem/8044088>.

llvm-svn: 105178
2010-05-30 22:30:21 +00:00
Douglas Gregor 2683c28ff6 Improve parser recovery when we try to parse a call expression but the
called function itself is invalid (e.g., because of a semantic error
referring to that declaration). Fixes <rdar://problem/8044142>.

llvm-svn: 105175
2010-05-30 22:23:08 +00:00
Douglas Gregor 7aa6b229fe Teach code completion to adjust its completion priorities based on the
type that we expect to see at a given point in the grammar, e.g., when
initializing a variable, returning a result, or calling a function. We
don't prune the candidate set at all, just adjust priorities to favor
things that should type-check, using an ultra-simplified type system.

llvm-svn: 105128
2010-05-30 01:49:25 +00:00
Fariborz Jahanian 6e81492151 Empty enum in c is now error to match gcc's behavior.
(radar 8040068).

llvm-svn: 105011
2010-05-28 22:23:22 +00:00
John McCall 61d8258fa3 Roll back r104941.
llvm-svn: 104990
2010-05-28 18:25:28 +00:00
John McCall 2177a9b65a Add a new attribute on records, __attribute__((adl_invisible)), and define
the x86-64 __va_list_tag with this attribute.  The attribute causes the
affected type to behave like a fundamental type when considered by ADL.

(x86-64 is the only target we currently provide with a struct-based
__builtin_va_list)

Fixes PR6762.

llvm-svn: 104941
2010-05-28 08:20:36 +00:00
John McCall 08bede4c7b Don't just skip over the entire tag definition if the parser action didn't
give us a decl back.  Makes -cc1 -parse-noop handle a substantially larger
amount of the C++ grammar.

llvm-svn: 104940
2010-05-28 08:11:17 +00:00
Douglas Gregor f4c33349b5 Make -code-completion-patterns only cover multi-line code
completions. Plus, tweak a few completion patterns to better reflect
the language grammar.

llvm-svn: 104905
2010-05-28 00:22:41 +00:00
Douglas Gregor a817a19bc6 Implement a code-completion hook for the receiver of an Objective-C
message. This completion gives better results than just using the
"expression" completion, which is effectively what happened before.

llvm-svn: 104895
2010-05-27 23:06:34 +00:00
Daniel Dunbar 9c84d4a8a0 Parse/Sema: Add support for '#pragma options align=packed', which, it should be
noted, is not the same as __attribute__((packed)). That would be ridiculous!

llvm-svn: 104865
2010-05-27 18:42:17 +00:00
Daniel Dunbar 663e8094ae Parse/Sema: Add support for '#pragma options align=native'.
llvm-svn: 104864
2010-05-27 18:42:09 +00:00
Douglas Gregor 205a361413 When we've parsed a nested-name-specifier in a member access
expression, "forget" about the object type; only the
nested-name-specifier matters for name lookup purposes. Fixes PR7239.

llvm-svn: 104834
2010-05-27 15:25:59 +00:00
Daniel Dunbar 75c9be7e80 Parse: Add support for '#pragma options align'.
Also, fix a source location bug with the rparen in #pragma pack.

llvm-svn: 104784
2010-05-26 23:29:06 +00:00
Douglas Gregor 6da3db4af3 Improve code completion in failure cases in two ways:
1) Suppress diagnostics as soon as we form the code-completion
  token, so we don't get any error/warning spew from the early
  end-of-file.
  2) If we consume a code-completion token when we weren't expecting
  one, go into a code-completion recovery path that produces the best
  results it can based on the context that the parser is in.

llvm-svn: 104585
2010-05-25 05:58:43 +00:00
Chris Lattner fb58515bc3 improve the fixit for the missing : error when parsing ?:. When
there are already two spaces before the token where the : was expected,
put the : in between the spaces.  This means we get it right in both
of these cases:

t.c:2:17: error: expected ':'
  return a ? b  c;
                ^
               :
t.c:3:16: error: expected ':'
  return a ? b c;
               ^
               : 

In the later case, the diagnostic says to insert ": ", in the former
case it says to insert ":" between the spaces.  This fixes rdar://8007231

llvm-svn: 104569
2010-05-24 22:31:37 +00:00
Douglas Gregor 20c38a7c58 Improve recovery when we see a dependent template name that is missing
the required "template" keyword, using the same heuristics we do for
dependent template names in member access expressions, e.g.,

test/SemaTemplate/dependent-template-recover.cpp:11:8: error: use 'template'
      keyword to treat 'getAs' as a dependent template name
    T::getAs<U>();
       ^
       template 

Fixes PR5404.

llvm-svn: 104409
2010-05-21 23:43:39 +00:00
Douglas Gregor 786123dc48 Improve parser recovery when we encounter a dependent template name
that is missing the 'template' keyword, e.g., 

  t->getAs<T>()

where getAs is a member of an unknown specialization. C++ requires
that we treat "getAs" as a value, but that would fail to parse since T
is the name of a type. We would then fail at the '>', since a type
cannot be followed by a '>'.

This is a very common error for C++ programmers to make, especially
since GCC occasionally allows it when it shouldn't (as does Visual
C++). So, when we are in this case, we use tentative parsing to see if
the tokens starting at "<" can only be parsed as a template argument
list. If so, we produce a diagnostic with a fix-it that states that
the 'template' keyword is needed:

test/SemaTemplate/dependent-template-recover.cpp:5:8: error: 'template' keyword
      is required to treat 'getAs' as a dependent template name
    t->getAs<T>();
       ^
       template 

This is just a start of this patch; I'd like to apply the same
approach to everywhere that a template-id with dependent template name
can be parsed.

llvm-svn: 104406
2010-05-21 23:18:07 +00:00
John McCall b54367d2f8 Propagate access specifiers to anonymous union members nested within classes.
Fixes <rdar://problem/7987650>.

llvm-svn: 104376
2010-05-21 20:45:30 +00:00
Douglas Gregor 4abc32d033 Improve parser recovery when a switch condition is invalid; fixes
<rdar://problem/7971948>.

llvm-svn: 104291
2010-05-20 23:20:59 +00:00
Abramo Bagnara d754848f10 Added basic source locations to Elaborated and DependentName types.
llvm-svn: 104169
2010-05-19 21:37:53 +00:00
Ted Kremenek 26bde774df Add clang support for IBOutletCollection.
llvm-svn: 104135
2010-05-19 17:38:06 +00:00
Douglas Gregor a941dcae16 Add support for Microsoft's __thiscall, from Steven Watanabe!
llvm-svn: 104026
2010-05-18 16:57:00 +00:00
Douglas Gregor c9a99c5e5c mutable is a storage class that can follow a class/struct/union definition. Fixes PR7153
llvm-svn: 103954
2010-05-17 18:19:56 +00:00
Chris Lattner ff895c140c Improve error recovery in C/ObjC when the first argument of a function
declarator is incorrect.  Not being a typename causes the parser to 
dive down into the K&R identifier list handling stuff, which is almost
never the right thing to do.

Before:

r.c:3:17: error: expected ')'
void bar(intptr y);
                ^
r.c:3:9: note: to match this '('
void bar(intptr y);
        ^
r.c:3:10: error: a parameter list without types is only allowed in a function definition
void bar(intptr y);
         ^

After:

r.c:3:10: error: unknown type name 'intptr'; did you mean 'intptr_t'?
void bar(intptr y);
         ^~~~~~
         intptr_t
r.c:1:13: note: 'intptr_t' declared here
typedef int intptr_t;
            ^

This fixes rdar://7980651 - poor recovery for bad type in the first arg of a C function

llvm-svn: 103783
2010-05-14 17:44:56 +00:00
Chris Lattner 9453ab8c9c Refactor ParseFunctionDeclaratorIdentifierList to have the first
identifier in the identifier list consumed before it is called.
No functionality change.

llvm-svn: 103781
2010-05-14 17:23:36 +00:00
Douglas Gregor 05cfc295f4 Namespaces can only be defined at global or namespace scope. Fixes PR6596.
llvm-svn: 103767
2010-05-14 05:08:22 +00:00
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
Fariborz Jahanian 25491a22af This patch deals with Sema Part of Setter/Getter synthesis
of properties which are of C++ objects. Code Gen to follow
(Radar 7468090).

llvm-svn: 103123
2010-05-05 21:52:17 +00:00
Douglas Gregor b22ee88652 Support for 'template' as a disambiguator (PR7030)
ParseOptionalCXXScopeSpecifier() only annotates the subset of
    template-ids which are not subject to lexical ambiguity. Add support
    for the more general case in ParseUnqualifiedId() to handle cases
    such as A::template B().

    Also improve some diagnostic locations.

Fixes PR7030, from Alp Toker!

llvm-svn: 103081
2010-05-05 05:58:24 +00:00
Douglas Gregor cbbf3e3b4a It's okay to reference an enum in a template definition, even though
it's ill-formed to form an enum template. Fixes <rdar://problem/7933063>.

llvm-svn: 102926
2010-05-03 17:48:54 +00:00
Benjamin Kramer bebee84281 Replace a char*/size pair with stringref.
llvm-svn: 102902
2010-05-03 13:08:54 +00:00
Abramo Bagnara 5009937f47 Add calling convention related attributes to related declaration. Mark attributes invalid on type related checking so to add them to declarations only when everything is ok.
llvm-svn: 102710
2010-04-30 13:10:51 +00:00
John McCall e7db86ddb0 Fix a tentative-parse error with unqualified template ids in cast expressions.
Also resolve a long-working FIXME in the test case I modified.

llvm-svn: 102688
2010-04-30 03:11:01 +00:00
Fariborz Jahanian 65654df92c Cleanup error recovery for a missing '-'|'+'
on a method declaration (radar 7822196).

llvm-svn: 102383
2010-04-26 21:18:08 +00:00
Douglas Gregor ba41d01b59 Be more careful around dependent nested-name-specifiers, complaining
when they are not complete (since we could not match them up to
anything) and ensuring that enum parsing can cope with dependent
elaborated-type-specifiers. Fixes PR6915 and PR6649.

llvm-svn: 102247
2010-04-24 16:38:41 +00:00
Douglas Gregor e11ee11068 Rework Parser-Sema interface for Objective-C @catch exception object
arguments. Rather than having the parser call ActOnParamDeclarator
(which is a bit of a hack), call a new ActOnObjCExceptionDecl
action. We'll be moving more functionality into this handler to
perform earlier checking of @catch.

llvm-svn: 102222
2010-04-23 23:01:43 +00:00
Douglas Gregor 96c79498fb Improve the AST representation of Objective-C @try/@catch/@finally
statements. Instead of the @try having a single @catch, where all of
the @catch's were chained (using an O(n^2) algorithm nonetheless),
@try just holds an array of its @catch blocks. The resulting AST is
slightly more compact (not important) and better represents the actual
language semantics (good).

llvm-svn: 102221
2010-04-23 22:50:49 +00:00
Argyrios Kyrtzidis 8d7bdba08c Make Parser::ConsumeAndStoreUntil() more consistent with Parser::SkipUntil().
ConsumeAndStoreUntil would stop at tok::unknown when caching an inline method
definition while SkipUntil would go past it while parsing the method.

Fixes PR 6903.

llvm-svn: 102214
2010-04-23 21:20:12 +00:00
Douglas Gregor 2c4a7501ee When parsing a cast-expression that starts with a scope annotation,
try to annotate as a type first to determine whether we have a
functional-style cast. Patch by Eli Friedman, fixes PR6830.

llvm-svn: 102161
2010-04-23 02:08:13 +00:00
Douglas Gregor 8d4de67e1d Implement parsing for message sends in Objective-C++. Message sends in
Objective-C++ have a more complex grammar than in Objective-C
(surprise!), because

  (1) The receiver of an instance message can be a qualified name such
  as ::I or identity<I>::type.
  (2) Expressions in C++ can start with a type.

The receiver grammar isn't actually ambiguous; it just takes a bit of
work to parse past the type before deciding whether we have a type or
expression. We do this in two places within the grammar: once for
message sends and once when we're determining whether a []'d clause in
an initializer list is a message send or a C99 designated initializer.

This implementation of Objective-C++ message sends contains one known
extension beyond GCC's implementation, which is to permit a
typename-specifier as the receiver type for a class message, e.g.,

  [typename compute_receiver_type<T>::type method];

Note that the same effect can be achieved in GCC by way of a typedef,
e.g.,

  typedef typename computed_receiver_type<T>::type Computed;
  [Computed method];

so this is merely a convenience.

Note also that message sends still cannot involve dependent types or
values.

llvm-svn: 102031
2010-04-21 22:36:40 +00:00
Douglas Gregor e5798dcb41 Migrate the responsibility for turning the receiver name in an
Objective-C class message expression into a type from the parser
(which was doing so in two places) to Action::getObjCMessageKind()
which, in the case of Sema, reduces the number of name lookups we need
to perform.

llvm-svn: 102026
2010-04-21 20:38:13 +00:00
Douglas Gregor 0c78ad9665 Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:

  - Expanded the interface from two actions (ActOnInstanceMessage,
    ActOnClassMessage), where ActOnClassMessage also handled sends to
    "super" by checking whether the identifier was "super", to three
    actions (ActOnInstanceMessage, ActOnClassMessage,
    ActOnSuperMessage). Code completion has the same changes.
  - The parser now resolves the type to which we are sending a class
    message, so ActOnClassMessage now accepts a TypeTy* (rather than
    an IdentifierInfo *). This opens the door to more interesting
    types (for Objective-C++ support).
  - Split ActOnInstanceMessage and ActOnClassMessage into parser
    action functions (with their original names) and semantic
    functions (BuildInstanceMessage and BuildClassMessage,
    respectively). At present, this split is onyl used by
    ActOnSuperMessage, which decides which kind of super message it
    has and forwards to the appropriate Build*Message. In the future,
    Build*Message will be used by template instantiation.
  - Use getObjCMessageKind() within the disambiguation of Objective-C
    message sends vs. array designators.

Two notes about substandard bits in this patch:
  - There is some redundancy in the code in ParseObjCMessageExpr and
  ParseInitializerWithPotentialDesignator; this will be addressed
  shortly by centralizing the mapping from identifiers to type names
  for the message receiver.
  - There is some #if 0'd code that won't likely ever be used---it
  handles the use of 'super' in methods whose class does not have a
  superclass---but could be used to model GCC's behavior more
  closely. This code will die in my next check-in, but I want it in
  Subversion.

llvm-svn: 102021
2010-04-21 19:57:20 +00:00
Chris Lattner 0151b7edb7 fix the ?: fixit that ted added to recover properly.
llvm-svn: 101943
2010-04-20 21:33:39 +00:00
Ted Kremenek 15a81e59ca Fix crash on invalid code where a @throw statement is not followed by a ';'
llvm-svn: 101941
2010-04-20 21:21:51 +00:00
Douglas Gregor c4df407604 Keep track of the actual storage specifier written on a variable or
function declaration, since it may end up being changed (e.g.,
"extern" can become "static" if a prior declaration was static). Patch
by Enea Zaffanella and Paolo Bolzoni.

llvm-svn: 101826
2010-04-19 22:54:31 +00:00
Douglas Gregor b8eaf2944b Audit uses of Sema::LookupSingleName for those lookups that are
intended for redeclarations, fixing those that need it. Fixes PR6831.

This uncovered an issue where the C++ type-specifier-seq parsing logic
would try to perform name lookup on an identifier after it already had
a type-specifier, which could also lead to spurious ambiguity errors
(as in PR6831, but with a different test case).

llvm-svn: 101419
2010-04-15 23:40:53 +00:00
Douglas Gregor b2ccf010fb Feed proper source-location information into Sema::LookupSingleResult,
in case it ends up doing something that might trigger diagnostics
(template instantiation, ambiguity reporting, access
reporting). Noticed while working on PR6831.

llvm-svn: 101412
2010-04-15 22:33:43 +00:00
Alexis Hunt 1deb972b55 Fix 80-cols violtaions
llvm-svn: 101311
2010-04-14 23:07:37 +00:00
Fariborz Jahanian b5795c01c4 Fix a -pedantic spurious warning involving @dynamic.
llvm-svn: 101284
2010-04-14 20:52:42 +00:00
Douglas Gregor a148a1d40e Introduce a parsing action to distinguish between class, instance, and
super message sends in Objective-C. No actual functionality change
here, but it provides a hook so that Sema can typo-correct the
receiver in some cases.

llvm-svn: 101207
2010-04-14 02:22:16 +00:00
John McCall b7c5c278bf Parse friend template ids as types instead of ending up in
ActOnClassTemplateSpecialization and being very confused.
Fixes PR6514 (for non-templated-scope friends).

llvm-svn: 101198
2010-04-14 00:24:33 +00:00
John McCall 84821e7143 Parse constructor names in friend declarations. Part of the fix for
PR6207.

llvm-svn: 101119
2010-04-13 06:39:49 +00:00
Ted Kremenek e601365de9 Add fixit hint for missing ':' in ternary expressions.
llvm-svn: 101073
2010-04-12 22:10:35 +00:00
Chris Lattner 5ff40fc7ab tighten the check for cast of super to avoid rejecting valid code,
rdar://7853261

llvm-svn: 101048
2010-04-12 17:09:27 +00:00
Chris Lattner 3adb17d44f fix a bug I noticed by inspection, correcting two reject-valid bugs.
llvm-svn: 101026
2010-04-12 06:36:00 +00:00
Chris Lattner 3ab8ca2894 fix a rejects-valid bug that I introduced, pointed out
by David Chisnall

llvm-svn: 101024
2010-04-12 06:27:57 +00:00
Chris Lattner 1447136553 use pointer comparison instead of isStr
llvm-svn: 101022
2010-04-12 06:22:50 +00:00
Chris Lattner cd963185f0 fix a rejects-valid testcase involving super that I dreamt up.
This also fixes cases where super is used in a block in a
method which isn't valid.

llvm-svn: 101021
2010-04-12 06:20:33 +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 c2ebb03297 Have the parser decide whether a message to super is a variable or
type, instead of having sema do it.

llvm-svn: 101016
2010-04-12 05:38:43 +00:00
Chris Lattner a9396af5f2 other half of r101005
llvm-svn: 101006
2010-04-12 02:18:49 +00:00
Chris Lattner a36ec4243b fix PR6811 by not parsing 'super' as a magic expression in
LookupInObjCMethod.  Doing so allows all sorts of invalid code
to slip through to codegen.  This patch does not change the 
AST representation of super, though that would now be a natural
thing to do since it can only be in the receiver position and
in the base of a ObjCPropertyRefExpr.

There are still several ugly areas handling super in the parser,
but this is definitely a step in the right direction.

llvm-svn: 100959
2010-04-11 08:28:14 +00:00
John McCall bb7b658ab5 Diagnose misordered initializers in constructor templates immediately instead of
when they're instantiated.  Merge the note into the -Wreorder warning;  it
doesn't really contribute much, and it was splitting a thought across diagnostics
anyway.  Don't crash in the parser when a constructor's initializers end in a
comma and there's no body;  the recovery here is still terrible, but anything's
better than a crash.

llvm-svn: 100922
2010-04-10 07:37:23 +00:00
Jeffrey Yasskin c76498d409 Make CXXScopeSpec invalid when incomplete, and propagate that into any
Declarator that depends on it.  This fixes several redundant errors and bad
recoveries.

llvm-svn: 100779
2010-04-08 16:38:48 +00:00
Fariborz Jahanian 60462098d4 Patch to implement gcc's cstyle arguments in objc
methods. wip.

llvm-svn: 100734
2010-04-08 00:30:06 +00:00
Jeffrey Yasskin 4e150f8d35 Fix some redundant errors by changing CXXScopeSpec::isSet calls into
isNotEmpty calls.

llvm-svn: 100722
2010-04-07 23:29:58 +00:00
Douglas Gregor 636a61e0d2 Implement code completion for Objective-C method declarations and
definitions, e.g., after 

  -

or

  - (id)

we'll find all of the "likely" instance methods that one would want to
declare or define at this point. In the latter case, we only produce
results whose return types match "id".

llvm-svn: 100587
2010-04-07 00:21:17 +00:00
Fariborz Jahanian 6a0a2e0ccc Patch to not build ivar ASTs when they are ilegally
declared in categories.

llvm-svn: 100577
2010-04-06 22:43:48 +00:00
Douglas Gregor be9ea80abf Perform code-completion within ParseCastExpression, which handles,
e.g., the right-hand side of binary expressions.

llvm-svn: 100526
2010-04-06 15:09:27 +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
Fariborz Jahanian d077f719be Improve diagnosing when a method type does not start with '-'|'+'
when parsing. Fixes radar 7822196.

llvm-svn: 100248
2010-04-02 23:15:40 +00:00
Fariborz Jahanian 083712fbb7 Issue better syntax error when objc's messaging
ares are not separated by ':' (radar 7030268).

llvm-svn: 100040
2010-03-31 20:22:35 +00:00
Douglas Gregor a771f46c82 Reinstate my CodeModificationHint -> FixItHint renaming patch, without
the C-only "optimization".

llvm-svn: 100022
2010-03-31 17:46:05 +00:00
Douglas Gregor 30e631862f Revert r100008, which inexplicably breaks the clang-i686-darwin10 builder
llvm-svn: 100018
2010-03-31 17:25:35 +00:00
Douglas Gregor 3baad0d4f7 Rename CodeModificationHint to FixItHint, since we've been using the
term "fix-it" everywhere and even *I* get tired of long names
sometimes. No functionality change.

llvm-svn: 100008
2010-03-31 15:31:50 +00:00
Argyrios Kyrtzidis 0204197d53 Add a few asserts to be on the safe side.
llvm-svn: 99973
2010-03-31 00:38:09 +00:00