Commit Graph

163 Commits

Author SHA1 Message Date
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 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 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
Douglas Gregor 9507d46d62 Remove the capture, serialization, and deserialization of comment
ranges as part of the ASTContext. This code is not and was never used,
but contributes ~250k to the size of the Cocoa.h precompiled
header.

llvm-svn: 99007
2010-03-19 22:13:20 +00:00
Douglas Gregor ea99b5d736 Unbreak the build
llvm-svn: 97519
2010-03-01 23:31:19 +00:00
Douglas Gregor 9a28e84b32 Keep an explicit stack of function and block scopes, each element of
which has the label map, switch statement stack, etc. Previously, we
had a single set of maps in Sema (for the function) along with a stack
of block scopes. However, this lead to funky behavior with nested
functions, e.g., in the member functions of local classes.

The explicit-stack approach is far cleaner, and we retain a 1-element
cache so that we're not malloc/free'ing every time we enter a
function. Fixes PR6382.

Also, tweaked the unused-variable warning suppression logic to look at
errors within a given Scope rather than within a given function. The
prior code wasn't looking at the right number-of-errors count when
dealing with blocks, since the block's count would be deallocated
before we got to ActOnPopScope. This approach works with nested
blocks/functions, and gives tighter error recovery.

llvm-svn: 97518
2010-03-01 23:15:13 +00:00
John McCall 1f476a1783 Fix an assertion-on-error during tentative constructor parsing by
propagating error conditions out of the various annotate-me-a-snowflake
routines.  Generally (but not universally) removes redundant diagnostics
as well as, you know, not crashing on bad code.  On the other hand,
I have just signed myself up to fix fiddly parser errors for the next
week.  Again.

llvm-svn: 97221
2010-02-26 08:45:28 +00:00
Richard Pennington 14cc983d86 Retain attributes for K&R style parameter declarations.
llvm-svn: 96941
2010-02-23 12:22:13 +00:00
Ted Kremenek c162e8e193 Clean up ownership of 'AttributeList' objects in Parser. Apparently
we would just leak them all over the place, with no clear ownership of
these objects at all.  AttributeList objects would get leaked on both
error and non-error paths.

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

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

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

llvm-svn: 95847
2010-02-11 02:19:13 +00:00
Sebastian Redl b0e3e1bf67 When placing an annotation token over an existing annotation token, make sure that the new token's range extends to the end of the old token. Assert that in AnnotateCachedTokens. Fixes PR6248.
llvm-svn: 95555
2010-02-08 19:35:18 +00:00
Douglas Gregor b65a913c35 Fix assertion failure when parsing linkage specifications (PR5921),
from Keir Mierle!

llvm-svn: 95516
2010-02-07 08:38:28 +00:00
John Thompson 2233460de6 First stage of adding AltiVec support
llvm-svn: 95335
2010-02-05 00:12:22 +00:00
John McCall 5cb5287467 Fixit to remove 'volatile' in file-scope 'asm volatile'.
llvm-svn: 94466
2010-01-25 23:12:50 +00:00
John McCall 9dfb16210e Warn on top-level 'asm volatile' (instead of misparsing it).
"Fixes" rdar://problem/7574870

llvm-svn: 94458
2010-01-25 22:27:48 +00:00
Chris Lattner 87d0208c41 allow the HandlerComment callback to push tokens into the
preprocessor.  This could be used by an OpenMP implementation
or something.  Patch by Abramo Bagnara!

llvm-svn: 93795
2010-01-18 22:35:47 +00:00
Douglas Gregor f193416359 Whenever completing ordinary names for an Objective-C source, also
provide completions for @ keywords. Previously, we only provided
@-completions after an @ was actually typed, which is useful but
probably not the common case.

Also, make sure a few Objective-C 2.0 completions only show up when
Objective-C 2.0 support is enabled (the default).

llvm-svn: 93354
2010-01-13 21:24:21 +00:00
Douglas Gregor 9de54ea41b Reimplement constructor declarator parsing to cope with template-ids
that name constructors, the endless joys of out-of-line constructor
definitions, and various other corner cases that the previous hack
never imagined. Fixes PR5688 and tightens up semantic analysis for
constructor names.

Additionally, fixed a problem where we wouldn't properly enter the
declarator scope of a parenthesized declarator. We were entering the
scope, then leaving it when we saw the ")"; now, we re-enter the
declarator scope before parsing the parameter list.

Note that we are forced to perform some tentative parsing within a
class (call it C) to tell the difference between

  C(int); // constructor

and

  C (f)(int); // member function

which is rather unfortunate. And, although it isn't necessary for
correctness, we use the same tentative-parsing mechanism for
out-of-line constructors to improve diagnostics in icky cases like:

  C::C C::f(int); // error: C::C refers to the constructor name, but
                  // we complain nicely and recover by treating it as
                  // a type.

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

  static_cast<type>(expr)

when we can have an expression, or

  using namespace identifier;

when we can have a using directive.

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

llvm-svn: 93134
2010-01-10 23:08:15 +00:00
John McCall e2ade289be Teach TryAnnotateTypeOrScopeToken to deal with already-annotated
scope specifiers.  Fix a tentative parsing bug that came up in LLVM.
Incidentally fixes some random FIXMEs in an existing testcase.

llvm-svn: 91734
2009-12-19 00:35:18 +00:00
Chris Lattner d5c1c9d0ae refactor the 'ColonIsSacred' argument to ParseOptionalCXXScopeSpecifier
to be a bool in Parser that is twiddled by the ColonProtectionRAIIObject
class.  No functionality change.

llvm-svn: 91014
2009-12-10 00:32:41 +00:00
Chris Lattner 8a9a97a660 rename ExtensionRAIIObject.h -> RAIIObjectsForParser.h
llvm-svn: 91008
2009-12-10 00:21:05 +00:00
Fariborz Jahanian 26de2e594b Fixes a bogus error when declaring an extern "C" array.
(fixes radar 7457109).

llvm-svn: 90986
2009-12-09 21:39:38 +00:00
Chris Lattner 045cbffb65 fix a crash on invalid I found when working on something unrelated.
llvm-svn: 90729
2009-12-07 00:48:47 +00:00
Chris Lattner 8c56c49fe0 simplify logic.
llvm-svn: 90712
2009-12-06 18:34:27 +00:00
Chris Lattner 3c7b86f4ee remove some extraneous syntax: sourceloc implicitly converts to sourcerange.
llvm-svn: 90710
2009-12-06 17:36:05 +00:00
Alexis Hunt 96d5c76498 Added rudimentary C++0x attribute support.
The following attributes are currently supported in C++0x attribute
lists (and in GNU ones as well):
 - align() - semantics believed to be conformant to n3000, except for
   redeclarations and what entities it may apply to
 - final - semantics believed to be conformant to CWG issue 817's proposed
   wording, except for redeclarations
 - noreturn - semantics believed to be conformant to n3000, except for
   redeclarations
 - carries_dependency - currently ignored (this is an optimization hint)

llvm-svn: 89543
2009-11-21 08:43:09 +00:00
Douglas Gregor b53edfb8dc Improve parsing of template arguments to lay the foundation for
handling template template parameters properly. This refactoring:

  - Parses template template arguments as id-expressions, representing
    the result of the parse as a template name (Action::TemplateTy)
    rather than as an expression (lame!).

  - Represents all parsed template arguments via a new parser-specific
    type, ParsedTemplateArgument, which stores the kind of template
    argument (type, non-type, template) along with all of the source
    information about the template argument. This replaces an ad hoc
    set of 3 vectors (one for a void*, which was either a type or an
    expression; one for a bit telling whether the first was a type or
    an expression; and one for a single source location pointing at
    the template argument).

  - Moves TemplateIdAnnotation into the new Parse/Template.h. It never
    belonged in the Basic library anyway.

llvm-svn: 86708
2009-11-10 19:49:08 +00:00
John McCall 28a6aeab7e Change our basic strategy for avoiding deprecation warnings when the decl use
appears in a deprecated context.  In the new strategy, we emit the warnings
as usual unless we're currently parsing a declaration, where "declaration" is
restricted to mean a decl group or a few special cases in Objective C.  If
we *are* parsing a declaration, we queue up the deprecation warnings until
the declaration has been completely parsed, and then emit them only if the
decl is not deprecated.
We also standardize the bookkeeping for deprecation so as to avoid special cases.

llvm-svn: 85998
2009-11-04 02:18:39 +00:00
Douglas Gregor 71395fa1d5 Implement support for parsing dependent template-ids that refer to
overloaded operators, e.g.,

  p->template operator+<T>()

llvm-svn: 85989
2009-11-04 00:56:37 +00:00
Douglas Gregor 3cf81317e4 Parsing and semantic analysis for template-ids that name overloaded
operators, e.g., 

  operator+<int>

which now works in declarators, id-expressions, and member access
expressions. This commit only implements the non-dependent case, where
we can resolve the template-id to an actual declaration.

llvm-svn: 85966
2009-11-03 23:16:33 +00:00
John McCall 37958aa864 Silence a warning by giving Parser::FieldCallback a virtual destructor, and
anchor the vtable to Parser.cpp for good measure.

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

llvm-svn: 85924
2009-11-03 19:26:08 +00:00
Daniel Dunbar 68d9d7b319 Don't crash when dumping pretty stack traces, if the current tok is an
annotation token.
 - I'm not sure what the best thing to print is, for now we just print the token
   location and 'at annotation token'.

llvm-svn: 84312
2009-10-17 06:13:04 +00:00
Douglas Gregor 9d64c5e3a5 Code completion for ordinary names when we're starting a declaration, expression, or statement
llvm-svn: 82481
2009-09-21 20:51:25 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +00:00
Douglas Gregor 43e75176ec Parse extern templates, pass that information all the way to Sema,
then drop it on the floor.

llvm-svn: 80989
2009-09-04 06:33:52 +00:00
Douglas Gregor b7bfe79412 Rewrite of our handling of name lookup in C++ member access expressions, e.g.,
x->Base::f

We no longer try to "enter" the context of the type that "x" points
to. Instead, we drag that object type through the parser and pass it
into the Sema routines that need to know how to perform lookup within
member access expressions.

We now implement most of the crazy name lookup rules in C++
[basic.lookup.classref] for non-templated code, including performing
lookup both in the context of the type referred to by the member
access and in the scope of the member access itself and then detecting
ambiguities when the two lookups collide (p1 and p4; p3 and p7 are
still TODO). This change also corrects our handling of name lookup
within template arguments of template-ids inside the
nested-name-specifier (p6; we used to look into the scope of the
object expression for them) and fixes PR4703.

I have disabled some tests that involve member access expressions
where the object expression has dependent type, because we don't yet
have the ability to describe dependent nested-name-specifiers starting
with an identifier.

llvm-svn: 80843
2009-09-02 22:59:36 +00:00
Douglas Gregor e861bac059 Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.

To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,

  template<typename X> template<typename Y>
  X Outer<X>::Inner1<Y>::foo(Y) {
    return X();
  }

we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.

Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.

llvm-svn: 80044
2009-08-25 22:51:20 +00:00
Douglas Gregor 9d01b5b40c Eliminate a GCC warning
llvm-svn: 79962
2009-08-25 00:17:23 +00:00
Douglas Gregor a3dff8e37a Keep track of the template parameter depth properly when we have
member templates declared inside other templates. This allows us to
match out-of-line definitions of member function templates within
class templates to the declarations within the class template. We
still can't handle out-of-line definitions for member class templates,
however.

llvm-svn: 79955
2009-08-24 23:03:25 +00:00
Douglas Gregor 8b9575f27e Top-level semicolons are allowed in C++0x. Fixes PR4755.
llvm-svn: 79912
2009-08-24 12:17:54 +00:00
John McCall 49bfce4227 Refactor methods on DeclSpec to take a diagnostic& parameter, and reflect this
elsewhere.  Very slightly decouples DeclSpec users from knowing the exact
diagnostics to report, and makes it easier to provide different diagnostics in
some places.

llvm-svn: 77990
2009-08-03 20:12:06 +00:00
John McCall ef50e99783 sp.
llvm-svn: 77656
2009-07-31 02:20:35 +00:00
Fariborz Jahanian aee31ac316 Patch to accomodate Doug's comment on default
destruction of base/members for each destructor AST.

llvm-svn: 76663
2009-07-21 22:36:06 +00:00
Fariborz Jahanian 16094c2467 Added ASTs to destructor decl AST for default destruction of object's
base/members.

llvm-svn: 75849
2009-07-15 22:34:08 +00:00
Fariborz Jahanian 06b2374504 Build AST for default ctor-initializer when constructor has
out of line definition.

llvm-svn: 75668
2009-07-14 20:06:22 +00:00
Douglas Gregor c6d5edd2ed Add support for retrieving the Doxygen comment associated with a given
declaration in the AST. 

The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment, 
which may be composed of several comment blocks.

Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).

Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile). 

The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.

Some notes:
  - We don't actually attempt to parse the comment blocks themselves,
  beyond identifying them as Doxygen comment blocks to associate them
  with a declaration.
  - We won't find comment blocks that aren't adjacent to the
  declaration, because we start our search based on the location of
  the declaration.
  - We don't go through the necessary hops to find, for example,
  whether some redeclaration of a declaration has comments when our
  current declaration does not. Similarly, we don't attempt to
  associate a \param Foo marker in a function body comment with the
  parameter named Foo (although that is certainly possible).
  - Verification of my "no performance impact" claims is still "to be
  done".

llvm-svn: 74704
2009-07-02 17:08:52 +00:00
Eli Friedman d95e1cda9e Fix screwup with my previous patch which broke tests. (The patch is
making sure we return true when annotating a function template with 
explicit template arguments, but not when we don't annotate anything.)

llvm-svn: 74383
2009-06-27 08:17:02 +00:00