Commit Graph

185 Commits

Author SHA1 Message Date
Douglas Gregor 60060d6f8f Treat the Microsoft/Borland keyword "__except" as a context-sensitive
keyword, because both libstdc++ and libc++ use "__except" as an
identifier. Fixes <rdar://problem/10322555>.

llvm-svn: 142636
2011-10-21 03:57:52 +00:00
Richard Smith 5d164bc5e0 Implement -Wc++98-compat warnings for the parser.
llvm-svn: 142056
2011-10-15 05:09:34 +00:00
Douglas Gregor e7a8e3b612 Introduce BalancedDelimiterTracker, to better track open/close
delimiter pairs and detect when we exceed the implementation limit for
nesting depth, from Aaron Ballman!

llvm-svn: 141782
2011-10-12 16:37:45 +00:00
NAKAMURA Takumi 93eafc6ce1 Fix "Uninitialized" warnings.
llvm-svn: 141487
2011-10-08 11:31:53 +00:00
NAKAMURA Takumi 82a351197f Whitespace
llvm-svn: 141486
2011-10-08 11:31:46 +00:00
Eli Friedman a4b02c30de Some fixes for MS-style asm parsing: specifically, add some error checking, and handle asm comments using semicolons correctly. (The comments are actually surprisingly tricky.)
llvm-svn: 140837
2011-09-30 01:13:51 +00:00
Richard Trieu 01fc001062 Changes to the name lookup have caused a regression in the digraph fix-it hint.
For instance:

template <class T> void E() {};
class F {};

void test() {
 ::E<::F>();
 E<::F>();
}

Gives the following error messages:

error: found '<::' after a template name which forms the
     digraph '<:' (aka '[') and a ':', did you mean '< ::'?
 ::E<::F>();
    ^~~
    < ::
error: expected expression
 E<::F>();
    ^
error: expected ']'
note: to match this '['
 E<::F>();

This patch adds the digraph fix-it check right before the name lookup,
moves the shared checking code to a new function, and adds new
tests to catch future regressions.

llvm-svn: 140039
2011-09-19 19:01:00 +00:00
Francois Pichet 0706d203cf Rename LangOptions::Microsoft to LangOptions::MicrosoftExt to make it clear that this flag must be used only for Microsoft extensions and not emulation; to avoid confusion with the new LangOptions::MicrosoftMode flag.
Many of the code now under LangOptions::MicrosoftExt will eventually be moved under the LangOptions::MicrosoftMode flag.

llvm-svn: 139987
2011-09-17 17:15:52 +00:00
Richard Trieu 3481fcd869 Change references to StmtTy to Stmt and removed typedefs of StmtTy. Also removed typedef of AttrTy since it is not used.
llvm-svn: 139349
2011-09-09 02:16:15 +00:00
Richard Trieu 2bd0401b04 Change all references of type ExprTy to Expr and get rid of the typedefs.
llvm-svn: 139347
2011-09-09 02:00:50 +00:00
Douglas Gregor 5ca153f112 When parsing a function-try-block that does not have a
ctor-initializer, remember to call the Sema action to generate default
ctor-initializers. What a delightful little miscompile. Fixes PR10578
/ <rdar://problem/9877267>.

llvm-svn: 139253
2011-09-07 20:36:12 +00:00
Richard Smith 58c7433709 PR10458: Finesse behaviour of C++0x features when in pre-0x mode. Accept for-range and auto with an ExtWarn, and produce a -Wc++0x-compat warning in C++98 mode when auto is used as a storage class.
llvm-svn: 139102
2011-09-04 19:54:14 +00:00
Argyrios Kyrtzidis 5cec2aea3f Support code-completion for C++ inline methods and ObjC buffering methods.
Previously we would cut off the source file buffer at the code-completion
point; this impeded code-completion inside C++ inline methods and,
recently, with buffering ObjC methods.

Have the code-completion inserted into the source buffer so that it can
be buffered along with a method body. When we actually hit the code-completion
point the cut-off lexing or parsing.

Fixes rdar://10056932&8319466

llvm-svn: 139086
2011-09-04 03:32:15 +00:00
Argyrios Kyrtzidis 43ea78b48d Don't try keeping a 'LeadingEmptyMacroLoc' in NullStmt. This fails
in the face of buffering C++/ObjC method bodies.

llvm-svn: 138972
2011-09-01 21:53:45 +00:00
Douglas Gregor 4ecb7209bf Add code completion to produce "else" blocks after an "if"
statement. Fixes <rdar://problem/9229438>.

llvm-svn: 136564
2011-07-30 08:36:53 +00:00
John McCall 538482373b Clean up the analysis of the collection operand to ObjC
for-in statements;  specifically, make sure to close over any
temporaries or cleanups it might require.  In ARC, this has
implications for the lifetime of the collection, so emit it
with a retain and release it upon exit from the loop.

rdar://problem/9817306

llvm-svn: 136204
2011-07-27 01:07:15 +00:00
Chandler Carruth d48db2115a Rename getInstantiationLineNumber to getExpansionLineNumber in both
SourceManager and FullSourceLoc.

llvm-svn: 135969
2011-07-25 21:09:52 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Chandler Carruth a88a221855 Move the rest of the preprocessor terminology from 'instantiate' and
variants to 'expand'. This changed a couple of public APIs, including
one public type "MacroInstantiation" which is now "MacroExpansion". The
rest of the codebase was updated to reflect this, especially the
libclang code. Two of the C++ (and thus easily changed) libclang APIs
were updated as well because they pertained directly to the old
MacroInstantiation class.

No functionality changed.

llvm-svn: 135139
2011-07-14 08:20:46 +00:00
Douglas Gregor 53e191ed94 Properly implement the scope restriction on the NRVO for
throw-expressions, such that we don't consider the NRVO when the
non-volatile automatic object comes from outside the innermost try
scope (C++0x [class.copymove]p13). In C++98/03, our ASTs were
incorrect but it didn't matter because IR generation doesn't actually
apply the NRVO here. In C++0x, however, we were moving from an object
when in fact we should have copied from it. Fixes PR10142 /
<rdar://problem/9714312>.

llvm-svn: 134548
2011-07-06 22:04:06 +00:00
David Majnemer c6a998712d Remove the Fix-it for missing statement in switches
llvm-svn: 132994
2011-06-14 15:24:38 +00:00
David Majnemer 0ac67fa22f Improve the diagnostics generated for switch statements missing expressions
- Move the diagnostic to the case statement instead of at the end of the switch
- Add a fix-it hint as to how to fix the compilation error

llvm-svn: 132903
2011-06-13 05:50:12 +00:00
Francois Pichet a5b3fcbc02 Add support for _if_exists and __if_not_exists at namespace/global scope.
llvm-svn: 131050
2011-05-07 17:30:27 +00:00
Francois Pichet 4a7de3eb2c Add support for Microsoft __if_exists and __if_not_exists construct inside function definition.
Allow to include or exclude code depending on if a symbol exists or not. Just like a #ifdef but for C/C++ symbols.

More doc: http://msdn.microsoft.com/en-us/library/x7wy9xh3(v=VS.100).aspx

Support at class and namespace scopes will be added later.

llvm-svn: 131014
2011-05-06 20:48:22 +00:00
Francois Pichet bfaf477a99 SEH was crashing under -fms-extensions.
llvm-svn: 130377
2011-04-28 03:14:31 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
Douglas Gregor da6c89de48 Introduce a new parser annotation token for primary expressions. When
ClassifyName() builds a primary expression, generate one of these
annotation tokens rather than jumping into the parser.

llvm-svn: 130297
2011-04-27 06:18:01 +00:00
Douglas Gregor 9b2d706e05 Clean out some cruft I introduced when adding Sema::ClassifyName()
llvm-svn: 130295
2011-04-27 05:44:51 +00:00
Douglas Gregor 19b7acff10 Simplify the parser's handling of Sema::ClassifyName() for types, by
creating a type-annotation token rather than jumping into the
declaration parsing.

llvm-svn: 130293
2011-04-27 05:41:15 +00:00
Argyrios Kyrtzidis f7620e4d49 If a null statement was preceded by an empty macro keep its instantiation source location
in NullStmt.

llvm-svn: 130289
2011-04-27 05:04:02 +00:00
Douglas Gregor 8b02cd0bea Extend Sema::ClassifyName() to support C++, ironing out a few issues
in the classification of template names and using declarations. We now
properly typo-correct the leading identifiers in statements to types,
templates, values, etc. As an added bonus, this reduces the number of
lookups required for disambiguation.

llvm-svn: 130288
2011-04-27 04:48:22 +00:00
Douglas Gregor b90f5185b6 When Sema::ClassifyName() finds an invalid ivar reference, return an
invalid expression rather than the far-more-generic "error". Fixes a
mild regression in error recovery uncovered by the GCC testsuite.

llvm-svn: 130128
2011-04-25 15:05:41 +00:00
Douglas Gregor 0e7dde535d Implement a new identifier-classification scheme where Sema
performs name lookup for an identifier and resolves it to a
type/expression/template/etc. in the same step. This scheme is
intended to improve both performance (by reducing the number of
redundant name lookups for a given identifier token) and error
recovery (by giving Sema a chance to correct type names before the
parser has decided that the identifier isn't a type name). For
example, this allows us to properly typo-correct type names at the
beginning of a statement:

t.c:6:3: error: use of undeclared identifier 'integer'; did you mean
'Integer'?
  integer *i = 0;
  ^~~~~~~
  Integer
t.c:1:13: note: 'Integer' declared here
typedef int Integer;
            ^


Previously, we wouldn't give a Fix-It because the typo correction
occurred after the parser had checked whether "integer" was a type
name (via Sema::getTypeName(), which isn't allowed to typo-correct)
and therefore decided to parse "integer * i = 0" as an expression. By
typo-correcting earlier, we typo-correct to the type name Integer and
parse this as a declaration. 

Moreover, in this context, we can also typo-correct identifiers to
keywords, e.g.,

t.c:7:3: error: use of undeclared identifier 'vid'; did you mean
'void'?
  vid *p = i;
  ^~~
  void

and recover appropriately.

Note that this is very much a work-in-progress. The new
Sema::ClassifyName is only used for expression-or-declaration
disambiguation in C at the statement level. The next steps will be to
make this work for the same disambiguation in C++ (where
functional-style casts make some trouble), then push it
further into the parser to eliminate more redundant name lookups.

Fixes <rdar://problem/7963833> for C and starts us down the path of
<rdar://problem/8172000>.

llvm-svn: 130082
2011-04-24 05:37:28 +00:00
Richard Smith d4257d847e Fix gcc warning. Add parens to this assert, incidentally reassociating it, but the condition is the same either way.
llvm-svn: 129948
2011-04-21 22:48:40 +00:00
Richard Trieu 2c850c0980 Add a fixit suggest for missing case keywords inside a switch scope. For instance, in the following code, 'case ' will be suggested before the '1:'
switch (x) {
  1: return 0;
  default: return 1;
}

llvm-svn: 129943
2011-04-21 21:44:26 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
John McCall 084e83dfe7 Insomniac refactoring: change how the parser allocates attributes so that
AttributeLists do not accumulate over the lifetime of parsing, but are
instead reused.  Also make the arguments array not require a separate
allocation, and make availability attributes store their stuff in
augmented memory, too.

llvm-svn: 128209
2011-03-24 11:26:52 +00:00
Douglas Gregor a0ff0c34a7 Make sure that we always pop a function's scope *before* we call
ActOnFinishFunctionBody/ActOnBlockStmtExpr. This way, we ensure that
we diagnose undefined labels before the jump-scope checker gets run,
since the jump-scope checker requires (as its invariant) that all of
the GotoStmts be wired up correctly.

Fixes PR9495.

llvm-svn: 127738
2011-03-16 17:05:57 +00:00
Douglas Gregor e9e27d95db Implement a hack intended to allow Clang to parse libstdc++ 4.5's
headers, which use C++0x generalized initializer lists. Per PR7069, it
appears that the only use is as the return type of a function, so this
commit enables this extension just in that narrow case. If it's enough
for libstdc++ 4.5, or if it can be trivially extended to work with
libstdc++ 4.5, we'll keep it. Otherwise, or if this breaks anything,
we'll revert and wait for the real feature.

llvm-svn: 127507
2011-03-11 23:10:44 +00:00
Abramo Bagnara 1c3af96724 Fixed LabelDecl source range and cleaned creation code.
llvm-svn: 127094
2011-03-05 18:21:20 +00:00
Chris Lattner 43e7f31f11 implement basic support for __label__. I wouldn't be shocked if there are
bugs from other clients that don't expect to see a LabelDecl in a DeclStmt,
but if so they should be easy to fix.

This implements most of PR3429 and rdar://8287027

llvm-svn: 125817
2011-02-18 02:08:43 +00:00
Chris Lattner ebb5c6c717 Switch labels over to using normal name lookup, instead of their
own weird little DenseMap.  Hey look, we now emit unused label
warnings deterministically, amazing.

llvm-svn: 125813
2011-02-18 01:27:55 +00:00
Douglas Gregor 230a7e60b1 Improve parser recovery in "for" statements, from Richard Smith!
llvm-svn: 125722
2011-02-17 03:38:46 +00:00
John McCall 0140bfeead Improve our parse recovery on 'case blah;' and 'default;'.
llvm-svn: 124025
2011-01-22 09:28:32 +00:00
Jeffrey Yasskin 8dfa5f1776 Fix warnings found by gcc-4.6, from -Wunused-but-set-variable and
-Wint-to-pointer-cast.

llvm-svn: 123719
2011-01-18 02:00:16 +00:00
Argyrios Kyrtzidis ee56962cc1 Convert "#pragma unused(...)" into tokens for the parser.
This allows us to cache a "#pragma unused" that occurs inside an inline C++ member function.
Fixes rdar://8829590&8770988.

llvm-svn: 123666
2011-01-17 18:58:44 +00:00
Argyrios Kyrtzidis bd9dfb2e29 Rename MaybeSkipFunctionBodyForCodeCompletion -> trySkippingFunctionBodyForCodeCompletion and check isCodeCompletionEnabled() before doing the call.
Suggestions by Chris.

llvm-svn: 122792
2011-01-04 00:27:27 +00:00
Argyrios Kyrtzidis d5756a609d When in code-completion, skip obj-c method bodies for speed up.
llvm-svn: 122781
2011-01-03 22:33:06 +00:00
Argyrios Kyrtzidis 76dbe8c800 Speed up code-completion by skipping function bodies.
When we are in code-completion mode, skip parsing of all function bodies except the one where the
code-completion point resides.

For big .cpp files like 'SemaExpr.cpp' the improvement makes a huge difference, in some cases cutting down
code-completion time -62% !

We don't get diagnostics for the bodies though, so modify the code-completion tests that check for errors.

See rdar://8814203.

llvm-svn: 122765
2011-01-03 19:44:02 +00:00
John McCall 53fa71476d Refactor how we collect attributes during parsing, and add slots for attributes
on array and function declarators.  This is pretty far from complete, and I'll
revisit it later if someone doesn't beat me to it.

llvm-svn: 122535
2010-12-24 02:08:15 +00:00