Commit Graph

444 Commits

Author SHA1 Message Date
Fariborz Jahanian 53cacaec46 Patch to parse @implementation prologue, method definitions,
objc2's @synthesize and @dynamic.

llvm-svn: 41667
2007-09-01 00:26:16 +00:00
Chris Lattner cac27a5478 Fix a bug/missing-feature Ted noticed: the 'unused' warning should not
warn about the last stmt in a stmtexpr, f.e. there should be no warning for:

int maxval_stmt_expr(int x, int y) {
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

llvm-svn: 41655
2007-08-31 21:49:55 +00:00
Fariborz Jahanian 9fca6dfad3 Author: F. Jahanian
Log:
Implement parsing of objective-c's new @property declaration.

Modified:
include/clang/Basic/DiagnosticKinds.def
include/clang/Parse/Parser.h
Parse/ParseObjc.cpp
Parse/Parser.cpp

llvm-svn: 41644
2007-08-31 16:11:31 +00:00
Chris Lattner 319079c003 don't turn semantic errors into parse errors.
llvm-svn: 41638
2007-08-31 05:01:50 +00:00
Chris Lattner c6c66c461f fix some memory leaks when recovering.
llvm-svn: 41637
2007-08-31 04:58:34 +00:00
Chris Lattner e4ee2dfcf5 Pass the location of the type.
llvm-svn: 41612
2007-08-30 17:08:45 +00:00
Chris Lattner 5ad4f46fd6 make sure to parse postfix expression suffixes after builtin
primary expressions.

llvm-svn: 41607
2007-08-30 15:52:49 +00:00
Chris Lattner 687d609f04 add an action callback for __builtin_offsetof
llvm-svn: 41606
2007-08-30 15:51:11 +00:00
Chris Lattner 6678284a73 cleanup context-sensitive objc keyword recognition. Patch by Fariborz Jahanian.
llvm-svn: 41583
2007-08-29 22:54:08 +00:00
Steve Naroff 4ca5d5a9e8 Tweak declaration...
llvm-svn: 41542
2007-08-28 16:31:47 +00:00
Steve Naroff 7e6f7c25bf Implement more thoughful error recovery when dealing with bogus declarator types.
For example, the following code was resulting in spurious warnings. This was the result of
Sema::GetTypeForDeclarator() synthesizing a type to hand back to the caller (in this case,
"int []", instead of "struct s[]", which is invalid).

struct s; 
struct s* t (struct s z[]) {   // expected-error {{array has incomplete element type}}
  return z;
}

Strategy: Flag the error in Declarator/DeclaratorChunk. This info is later stored in 
the ParmVarDecl. If the decl is referenced, Sema::ParseIdentifierExpr() will check if 
the type is invalid. If so, it quietly returns "true", without instantiating a DeclRefExpr.

This seems to work nicely. If Chris is happy with the approach, I will generalize this to
all VarDecls.

llvm-svn: 41521
2007-08-28 03:03:08 +00:00
Chris Lattner 37256fbdec C++ allows empty enum list.
llvm-svn: 41498
2007-08-27 17:24:30 +00:00
Chris Lattner d864daf5c6 extwarn about decls intermixed with code in c89 mode.
llvm-svn: 41477
2007-08-27 04:29:41 +00:00
Chris Lattner dfaf9f8c2f implement a fixme: __extension__ marker on decls in compound stmts.
llvm-svn: 41473
2007-08-27 01:01:57 +00:00
Chris Lattner 2dd1b72bde Fix test/Parser/if-scope-*.c. Patch by Neil Booth!
llvm-svn: 41471
2007-08-26 23:08:06 +00:00
Chris Lattner 1a76a3c970 Break the assumption that any sort of scope (e.g. a loop scope) can
hold declarations.  Instead, introduce a new "DeclScope" scope type that
holds them explicitly.  For now, all scopes have this bit, but in the 
future we can use them to fix some issues Neil noticed.

llvm-svn: 41431
2007-08-26 06:24:45 +00:00
Chris Lattner 479ed3aab8 read and ignore the body of a namespace.
llvm-svn: 41403
2007-08-25 18:15:16 +00:00
Chris Lattner a5235173bc refactor enough of the top-level parsing logic to parse and
ignore 'namespace foo {}'

llvm-svn: 41400
2007-08-25 06:57:03 +00:00
Chris Lattner 66b67efa61 C++ explicitly allows an empty source file.
llvm-svn: 41399
2007-08-25 05:47:03 +00:00
Steve Naroff 4e1f80d255 - Cleanup "hack" comment and fix typos.
- Use getLang().ObjC2 when appropriate.

llvm-svn: 41333
2007-08-23 19:56:30 +00:00
Steve Naroff 7c34817902 Add helper functions Token::isObjCAtKeyword() and Token::getObjCKeywordID().
Convert all clients to the new cleaner, more robust API.

llvm-svn: 41330
2007-08-23 18:16:40 +00:00
Anders Carlsson cb8f832c26 As suggested by Chris, use MatchRHSPunctuation instead of manually looking for a right parenthesis when parsing @encode() and @protocol().
llvm-svn: 41321
2007-08-23 15:31:37 +00:00
Anders Carlsson e01493d47b Parse ObjC @protocol expressions.
llvm-svn: 41320
2007-08-23 15:25:28 +00:00
Steve Naroff 7e901fdf86 With this commit, we now successfully parse "Cocoa.h"!
llvm-svn: 41303
2007-08-22 23:18:22 +00:00
Steve Naroff 0b6a01a449 Add support for parsing protocols.
Now we can parse quite a bit of "Foundation.h" (a couple bugs remain).

llvm-svn: 41300
2007-08-22 22:17:26 +00:00
Steve Naroff f1bc45b1d1 Finish up method prototype parsing.
Next step...starting installing class names into the type namespace (so we can start parsing Cocoa headers).

llvm-svn: 41283
2007-08-22 18:35:33 +00:00
Steve Naroff 99264b4b04 Add support for parsing method prototypes (and other stuff required by @interface).
Still need to finish Parser::ParseObjCMethodDecl(). Before I do, I need to do a minor
refactoring of ParseDeclarationOrFunctionDefinition(), to disallow function definitions.
At the moment, @inteface allows function defs (which is incorrect).

llvm-svn: 41275
2007-08-22 16:35:03 +00:00
Anders Carlsson c5a81ebb1f Parse @encode expressions.
llvm-svn: 41273
2007-08-22 15:14:15 +00:00
Chris Lattner f265939ebc update todo markers
llvm-svn: 41267
2007-08-22 06:06:56 +00:00
Chris Lattner 8f44d20d69 optimize scope push/pop to avoid work in the common case.
llvm-svn: 41265
2007-08-22 05:33:11 +00:00
Chris Lattner 8fb2625b40 Fix the scoping issue Neil pointed out for the rest of
the selection statements and iteration statements.  Add
spec citations.

llvm-svn: 41264
2007-08-22 05:28:50 +00:00
Chris Lattner 37e54f454a Fix a nasty C99 scope issue that Neil pointed out (for ifs)
This fixes test/Parser/control-scope.c

llvm-svn: 41263
2007-08-22 05:16:28 +00:00
Steve Naroff 00433d3d37 Implement parsing for objc instance variables.
Next step, method...

llvm-svn: 41251
2007-08-21 21:17:12 +00:00
Anders Carlsson 77621351dd Don't remove the grammar construct, just the TODO.
llvm-svn: 41245
2007-08-21 19:18:49 +00:00
Chris Lattner 43ba25187b Tweak error recovery for missing semicolon after decl. For this:
void foo() {
  int x
  if (x) {
  }
}

We now emit:

a.c:5:3: error: parse error
  if (x) {
  ^
1 diagnostic generated.

instead of:

a.c:5:3: error: parse error
  if (x) {
  ^
a.c:9:1: error: expected '}'

^
2 diagnostics generated.

llvm-svn: 41243
2007-08-21 18:36:18 +00:00
Anders Carlsson 4f803dc6d3 Remove objc-string-literal since it's been implemented now.
llvm-svn: 41241
2007-08-21 18:14:25 +00:00
Anders Carlsson 76f4a902d7 Implement parsing and code generation of Objective-C string literals.
llvm-svn: 41238
2007-08-21 17:43:55 +00:00
Steve Naroff 9717080968 Added Parser::ParseStructDeclaration() as a result of refactoring Parser::ParseStructUnionBody().
Motivation: Objective-C can now share this rule. It also makes Parser::ParseStructUnionBody()
a bit smaller/cleaner..

llvm-svn: 41201
2007-08-20 22:28:22 +00:00
Steve Naroff 1eb1ad6c36 Start parsing ObjC classes/categories!
Next step, refactor Parser::ParseStructUnionBody() so that struct declarations can
be shared with Objective-C (for declaring instance variables).

llvm-svn: 41200
2007-08-20 21:31:48 +00:00
Chris Lattner cccc311110 add support for a top-level __extension__ marker, implementing a todo.
llvm-svn: 41004
2007-08-10 20:57:02 +00:00
Chris Lattner 599e47e6ff minor cleanups
llvm-svn: 40963
2007-08-09 17:01:07 +00:00
Chris Lattner 7b20dc769a __attribute__ starts a declspec.
llvm-svn: 40962
2007-08-09 16:40:21 +00:00
Steve Naroff 9efdabc565 Implement __builtin_choose_expr.
llvm-svn: 40794
2007-08-03 21:21:27 +00:00
Steve Naroff 4bd2f71cc7 Tidy up Parser::ParseTypeofSpecifier()...implement FIXME and minor restructure.
llvm-svn: 40713
2007-08-02 02:53:48 +00:00
Steve Naroff 788d864d6c - Finish hooking up support for __builtin_types_compatible_p().
- Fix type printing code for recently added TypeOfExpr/TypeOfType.

llvm-svn: 40700
2007-08-01 23:45:51 +00:00
Steve Naroff 7886467b35 Add AST/Sema support for __builtin_types_compatible_p (a GNU extension).
Todo...still need to call the action from the parser...

llvm-svn: 40693
2007-08-01 22:05:33 +00:00
Steve Naroff 872da803b2 Tighten up Parser::ParseTypeofSpecifier().
Add some more tests to typeof.c. Also added a couple of missing "expect" attributes that caused the test to fail.

llvm-svn: 40656
2007-07-31 23:56:32 +00:00
Steve Naroff ad373bdcfe Add parsing and AST support for GNU "typeof".
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.

llvm-svn: 40631
2007-07-31 12:34:36 +00:00
Chris Lattner 02c0439a44 Fix a couple of bugs, add some new cool stuff.
1. Fix a todo in Parser::ParseTag, to recover better.  On code like
   that in test/Sema/decl-invalid.c it causes us to return a single
   error instead of multiple.
2. Fix an error in Sema::ParseDeclarator, where it would crash if the
   declarator didn't have an identifier.  Instead, diagnose the problem.
3. Start adding infrastructure to track the range of locations covered
   by a declspec or declarator.  This is mostly implemented for declspec,
   but could be improved, it is missing for declarator.

Thanks to Neil for pointing out this crash.

llvm-svn: 40482
2007-07-25 00:24:17 +00:00
Chris Lattner 01e4b243c9 Fix a comment, patch by Kevin Andre!
llvm-svn: 40466
2007-07-24 17:03:04 +00:00
Chris Lattner 366727fca1 implement ast building and trivial semantic analysis of stmt exprs.
This implements test/Sema/stmt_exprs.c

llvm-svn: 40465
2007-07-24 16:58:17 +00:00
Anders Carlsson 51873c22d8 Refactor switch analysis to make it possible to detect duplicate case values
llvm-svn: 40388
2007-07-22 07:07:56 +00:00
Chris Lattner e34b2c298a Catch goto's with a missing identifier, patch by Neil Booth.
llvm-svn: 40381
2007-07-22 04:13:33 +00:00
Anders Carlsson 625bfc8716 Implement code generation for __func__, __FUNCTION__ and __PRETTY_FUNCTION__
llvm-svn: 40162
2007-07-21 05:21:51 +00:00
Chris Lattner 5abb82c353 improve and simplify error recovery for calls, fix a crash when diagnosing
invalid arguments.

llvm-svn: 40161
2007-07-21 05:18:12 +00:00
Chris Lattner 146762e7a4 At one point there were going to be lexer and parser tokens.
Since that point is now long gone, we should rename LexerToken to
Token, as it is the only kind of token we have.

llvm-svn: 40105
2007-07-20 16:59:19 +00:00
Steve Naroff fbd098332c Work towards fixing crasher with compound literals...
Before this commit, we crashed in ParseBinOp...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c
SemaExpr.cpp:1298: failed assertion `(rhs != 0) && "ParseBinOp(): missing right expression"'

With this commit, we still crash in the newly added action ParseCompoundLiteral (which is progress:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c
SemaExpr.cpp:478: failed assertion `(Op != 0) && "ParseCompoundLiteral(): missing expression"'

The crash go away once the actions return AST nodes. I will do this in a separate commit.

llvm-svn: 40032
2007-07-19 01:06:55 +00:00
Chris Lattner 46eeb22fec Add initial switch stmt support, patch by Anders Carlsson!
llvm-svn: 39989
2007-07-18 02:28:47 +00:00
Chris Lattner 03928c7f9a Make parser scope cache be a member of the parser instead of a global,
which makes it multithread clean.

llvm-svn: 39863
2007-07-15 00:04:39 +00:00
Chris Lattner 436806ad05 In code like this:
typedef float float4 __attribute__((vector_size (16)));
void addFloat4(float4 a, float4 b) {
    float4 temp;
}

make sure to add 'temp' to the stmt tree as a declstmt.

llvm-svn: 39722
2007-07-10 05:03:31 +00:00
Bill Wendling a69300375b Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Fix for C++ casting operators failing during parsing. Deriving the C++ cast
  expressions from CastExpr was the wrong way to go. Its constructor creates
  null QualTypes in one of its constructors. This doesn't work well with how
  the C++ casting expression class wanted to do things. Derive just from Expr
  instead.

llvm-svn: 39714
2007-06-29 18:21:34 +00:00
Bill Wendling 5c9dde08e7 Submitted by: Bill Wendling
Small cleanup. No need to assign to a variable before returning.

llvm-svn: 39697
2007-06-28 00:45:30 +00:00
Chris Lattner cd68f64551 Start bringing the exprstmt hook back.
llvm-svn: 39677
2007-06-27 01:06:29 +00:00
Chris Lattner 23b7eb677d Finally bite the bullet and make the major change: split the clang namespace
out of the llvm namespace.  This makes the clang namespace be a sibling of
llvm instead of being a child.

The good thing about this is that it makes many things unambiguous.  The
bad things is that many things in the llvm namespace (notably data structures
like smallvector) now require an llvm:: qualifier.  IMO, libsystem and libsupport
should be split out of llvm into their own namespace in the future, which will fix
this issue.

llvm-svn: 39659
2007-06-15 23:05:46 +00:00
Chris Lattner 4ef40013d7 Implement capturing of enum values and chaining of enums together.
llvm-svn: 39644
2007-06-11 01:28:17 +00:00
Steve Naroff 0f05a7ae7a Bug #:
Submitted by:
Reviewed by:
Changed the name of DeclSpec.AddAttribute and Declarator.AddAttribute to
AddAttributes(). Also added some (much needed) comments. While documenting,
realized I could simplify & tighten up Declarator.AddAttributes...

llvm-svn: 39640
2007-06-09 23:38:17 +00:00
Chris Lattner 736ed5dfb8 accept __extension__, update todo list.
llvm-svn: 39635
2007-06-09 05:59:07 +00:00
Chris Lattner 0c7e82de07 Accept horrible code like this:
2005-10-18-VariableSizedElementCrash.c:5:41: warning: expected ';' at end of declaration list
  struct bar {foo f1; int f2:3; int f3:4} *p = (struct bar *) pi;
                                        ^

llvm-svn: 39633
2007-06-09 05:54:40 +00:00
Chris Lattner 36e46a219b Add support for a little extension. ISO C does not allow extra ;'s in structs,
e.g.:

struct A {
  ;
  int X;;
  const;
};

llvm-svn: 39632
2007-06-09 05:49:55 +00:00
Steve Naroff b8371e1e6a Bug #:
Submitted by:
Reviewed by:
Add AttributeList.cpp (for "raw" attributes).

llvm-svn: 39626
2007-06-09 03:39:29 +00:00
Chris Lattner 776fac8703 Finally break down and chain together decls that are defined with common declspecs,
like: int X, Y, Z;

This is required for the code gen to get to all of the declarations in a
DeclStmt, and should simplify some other code.

llvm-svn: 39623
2007-06-09 00:53:06 +00:00
Steve Naroff 98d153c730 Bug #:
Submitted by:
Reviewed by:

Fixed a bug in the parser's handling of attributes on pointer declarators.

For example, the following code was producing a syntax error...

int *__attribute(()) foo;

attrib.c:10:25: error: expected identifier or '('
int *__attribute(()) foo;
                        ^
Changed Parser::ParseTypeQualifierListOpt to not consume the token following
an attribute declaration.

Also added LexerToken::getName() convenience method...useful when tracking
down errors like this.

llvm-svn: 39602
2007-06-06 23:19:11 +00:00
Chris Lattner 2e550fea6a When parsing an expr in stmt context, make sure to consume the semicolon
after the expr along with the expr.  If we don't do this, the semicolon
gets parsed as a nullstmt, which makes the generated AST very strange.

llvm-svn: 39600
2007-06-06 05:26:32 +00:00
Bill Wendling 93efb22993 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Update the parsing of references. We allow "restrict" but not "const"
  or "volatile".

llvm-svn: 39567
2007-06-02 23:28:54 +00:00
Steve Naroff 4555292b1e Bug #:
Submitted by:
Reviewed by:
After speaking with Chris, decided not to have GCC "attributes" inherit
from Decl. This will enable us to grow the attribute hierarchy over time
without effecting Decls.

llvm-svn: 39543
2007-06-01 21:56:17 +00:00
Steve Naroff 0f2fe17ff1 Bug #:
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.

- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.

Still to do...hook up to the Decl...

llvm-svn: 39539
2007-06-01 17:11:19 +00:00
Steve Naroff 9992bbab14 Bug #:
Submitted by:
Reviewed by:
- ParseForStatement(): Put back a test/assignment. My removal of
ParseExprStmt() was a bit over zealous:-(thanks to Chris for pointing it out)
- Add assert to VisitDeclStmt().
- Removed an out-of-date FIXME
- Added some curlies for a couple multi-line calls to Diag().

llvm-svn: 39528
2007-05-30 16:27:15 +00:00
Steve Naroff 2a8ad18e71 Bug #:
Submitted by:
Reviewed by:
Implement some FIXME's that stand in the way of fully typechecking "for"
statements. This involved:

- Adding a DeclStmt AST node (with statement visitor). The DeclStmt
printer is preliminary.
- Added a ParseDeclStmt action, called from Parser::ParseForStatement()
and Parser::ParseStatementOrDeclaration(). DID NOT add to
Parser::ParseIdentifierStatement()...probably could have, however didn't
really understand the context of this rule (will speak with Chris).
- Removed ParseExprStmt (and it's clients)...it was vestigial.

llvm-svn: 39518
2007-05-29 22:59:26 +00:00
Chris Lattner 010015a11e Add a note about an unimplemented gnu extension.
llvm-svn: 39511
2007-05-28 07:23:54 +00:00
Chris Lattner eefa10e78a implement full sema support for the GCC address-of-label extension.
llvm-svn: 39510
2007-05-28 06:56:27 +00:00
Chris Lattner ac4471c963 Improve the parsers resilience to sematic errors. This allows us to turn:
void foo() {
  if (0) break;
  abc:
  def:
  hij:
    break;

into:

void foo() {
  if ((0)')
    ;
abc:
def:
hij:
  ;

instead of dropping the if and labels (due to break not being in a loop).

llvm-svn: 39508
2007-05-28 05:38:24 +00:00
Chris Lattner 0f203a7c1c add action for null stmt, create ast node.
llvm-svn: 39506
2007-05-28 01:45:28 +00:00
Bill Wendling 3708c18559 Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Initial support for C++ references. Adding to the AST and Parser.
  Skeletal support added in the semantic analysis portion. Full semantic
  analysis is to be done soon.

llvm-svn: 39496
2007-05-27 10:15:43 +00:00
Chris Lattner 81312e7835 Remove unused #include that breaks layering
llvm-svn: 39490
2007-05-24 01:08:56 +00:00
Chris Lattner de5a472e02 Fix a problem where a semantic error confused error recovery to the point
where the parser emitted bogus diagnostics.  Before, when compiling:

  struct A { int X; } someA;

  int func(int, struct A);

  int test1(void *P, int C) {
    return func(((C*40) + *P) / 42+P, someA);
  }

we emitted:

bug3.c:7:25: error: invalid operands to binary expression ('int' and 'void')
    return func(((C*40) + *P) / 42+P, someA);
                 ~~~~~~ ^ ~~
bug3.c:7:31: error: expected ')'
    return func(((C*40) + *P) / 42+P, someA);
                              ^
bug3.c:7:16: error: to match this '('
    return func(((C*40) + *P) / 42+P, someA);
               ^

now we only emit the first.

llvm-svn: 39474
2007-05-21 05:27:47 +00:00
Chris Lattner 36982e4367 Add support for inserting up to 10 strings in a diagnostic, with %0, %1, %2,
etc.

llvm-svn: 39447
2007-05-16 17:49:37 +00:00
Chris Lattner c24278d9a0 Do not invoke objc parser actions when a top level +/- is seen, unless objc
is enabled.

llvm-svn: 39430
2007-05-02 23:45:06 +00:00
Chris Lattner da6c2ce655 Fix an error recovery bug, we were would issue:
enum {
        CSSM_FALSE = 0,
        CSSM_TRUE = !&CSSM_FALSE
};

t.c:4:15: error: invalid lvalue in address expression
        CSSM_TRUE = !&CSSM_FALSE
                     ^
t.c:6:2: error: expected '}'
};
 ^
t.c:2:6: error: to match this '{'
enum {
     ^
3 diagnostics generated.



We now issue:
t.c:4:15: error: invalid lvalue in address expression
        CSSM_TRUE = !&CSSM_FALSE
                     ^
1 diagnostics generated.

llvm-svn: 39420
2007-04-27 19:13:15 +00:00
Chris Lattner 83b94e0967 Generalize the skipping logic to allow skipping until any one of a set of
tokens is found.

llvm-svn: 39419
2007-04-27 19:12:15 +00:00
Steve Naroff ae4143ea90 Bug #:
Submitted by:
Reviewed by:
Misc. changes driven by getting "carbon.h" to compile...

- Added ParseCharacterConstant() hook to Action, Sema, etc.
- Added CheckAssignmentOperands() & CheckCommaOperands() to Sema.
- Added CharacterLiteral AST node.
- Fixed CallExpr instantiation - install the correct type.
- Install a bunch of temp types and annotate with FIXME's.

llvm-svn: 39416
2007-04-26 20:39:23 +00:00
Steve Naroff f1e53698a4 Bug #:
Submitted by:
Reviewed by:

Type Checking...round 2. This checkin "breaks" parsing carbon.h. I imagine
that this will be true for the next week or so. Nevertheless, this round of
changes includes the following:

- Hacked various Expr classes to pass the appropriate TypeRef. Still have
a few more classes to touch.
- Implement type checking for ParseArraySubscriptExpr and ParseMemberReferenceExpr.
- Added a debug hook to derive the class name for Stmt/Expr nodes. Currently a
linear search...could easily optimize if important.
- Changed the name of TaggedType->TagType. Now we have TagType and TagDecl (which
are easier to remember).
- Fixed a bug in StringLiteral conversion I did a couple weeks ago. hadError was
not initialized (oops).
- changed Sema::Diag to return true. This streamlines the type checking code
considerably.
- Added many diagnositics.

This should be it!

llvm-svn: 39361
2007-03-23 22:27:02 +00:00
Steve Naroff b7d4924eb1 Bug #:
Submitted by:
Reviewed by:
Added size expression to ArrayType. This was needed to implement
Type::isIncompleteType(). At the moment, there is no support for
determining if we have a constant expression (which won't be too
difficult now that we have support for literal parsing/ast's).
Nevertheless, the parser will allow "struct foo { int a[b]; }"
(which is illegal). There is still significant work to fully analyze
array types. The good news is "carbon.h" goes from 288 bogus errors
down to 26!

llvm-svn: 39355
2007-03-14 19:55:17 +00:00
Steve Naroff 8160ea2072 Bug #:
Submitted by:
Reviewed by:
More code to parse numeric constants. This checkin includes:
- Feedback from Chris.
- Support for parsing floating point constants.
- Moved the code to "Sema". Changed API in Action.
- More/better error diagnostics.

At this point, the parsing support should be largely complete. Next step
is to work on filling in sensible values (in IntegerLiteral/FloatLiteral).

llvm-svn: 39349
2007-03-06 01:09:46 +00:00
Steve Naroff 1fb30c5e99 Bug #:
Submitted by:
Reviewed by:
First phase of parsing IntegerConstants. At the moment, all processing
is done in the Parser, not Sema. If necessary, this is easy to move.
Next steps:
- Convert well for strings to actual values (need to look @ APInt.h)
- Design the API between the Parser and Sema. Sema shouldn't have to be
concerned with any parsing issues...

llvm-svn: 39348
2007-03-03 00:02:57 +00:00
Steve Naroff df7855bb17 Batch search/replace snafu (inadvertantly changed IntegerConstant->StringLiteral).
clang still compiled/linked/ran properly...simply a confusing name regression.
From now on I'll make sure I run "cvs diff" before committing any changes!

llvm-svn: 39342
2007-02-21 23:46:25 +00:00
Steve Naroff ab62488ae3 rename IntegerConstant->IntegerLiteral
rename FloatingConstant->FloatingLiteral
rename StringExpr->StringLiteral

llvm-svn: 39341
2007-02-21 22:05:47 +00:00
Bill Wendling 4073ed5daa C++: Added support for bool types.
llvm-svn: 39338
2007-02-13 01:51:42 +00:00
Chris Lattner 49252eb303 Implement a FIXME: when a typedef is seen at statement scope, make sure to
actually add it into the declspec for the type being parsed.  This allows us
to do correct semantic analysis on:

typedef int bar;
int foo() {
  bar a;
  return a;
}

This reduces # errors parsing carbon.h from 731 to 654.

llvm-svn: 39321
2007-01-27 19:04:39 +00:00
Chris Lattner baf33665fb adjust to change in SmallSet interface
llvm-svn: 39313
2007-01-27 02:14:08 +00:00
Chris Lattner c1915e2052 Create EnumConstantDecl objects for each enum value, and fill them into
the EnumDecl when the enum type is complete.  This allows us to detect
redefinitions of enums.

llvm-svn: 39300
2007-01-25 07:29:02 +00:00
Chris Lattner ffbc271023 refactor tag processing into a new ParseTag method. Share this between
structs and enums.

llvm-svn: 39298
2007-01-25 06:05:38 +00:00
Chris Lattner 1300fb9603 create field decl objects for the members of a struct/union. Diagnose code
like:
struct S { struct S {} X; };

with:
t.c:2:19: error: nested redefinition of 'struct'
struct S { struct S {} X; };
                  ^
t.c:2:1: error: previous definition is here
struct S { struct S {} X; };
^

llvm-svn: 39292
2007-01-23 23:42:53 +00:00
Chris Lattner 367b019f79 add callback for fields.
llvm-svn: 39290
2007-01-23 22:29:13 +00:00
Chris Lattner d68e129e87 structure bodies can't get scopes.
llvm-svn: 39288
2007-01-23 21:57:45 +00:00
Chris Lattner 7b9ace672b simplify structure body parsing code. Reorganize how tags are processed.
Diagnose redefintion of tag types, e.g.:

t.c:7:8: error: redefinition of 'blah'
struct blah {};
       ^
t.c:1:8: error: previous definition is here
struct blah {
       ^
2 diagnostics generated.

llvm-svn: 39286
2007-01-23 20:11:08 +00:00
Chris Lattner fb072463e5 Add TaggedType, which represents tagged decls as types. Create these when
converting a declspec with TST = struct/union.  Pretty print as well.

llvm-svn: 39284
2007-01-23 05:45:31 +00:00
Chris Lattner b9d572a0a8 Generalize DeclSpec::TypedefRep to allow it to hold any type representation.
Use it to hold the declaration object for a struct/union.

llvm-svn: 39282
2007-01-23 04:58:34 +00:00
Chris Lattner 90a26b0758 split the code for parsing a struct/union body out into its own method.
llvm-svn: 39281
2007-01-23 04:38:16 +00:00
Chris Lattner 7bd11febba make file-static function be a static declspec method.
llvm-svn: 39280
2007-01-23 04:35:33 +00:00
Chris Lattner 69680eabc0 Make some file-static functions be static methods in the DeclSpec class.
llvm-svn: 39279
2007-01-23 04:34:43 +00:00
Chris Lattner bf0b798b87 There is no need for the Action::TagType enum, use DeclSpec::TST instead.
llvm-svn: 39278
2007-01-23 04:27:41 +00:00
Chris Lattner f34c4da0c3 Finish tag processing. Since it can be shared with C++ Classes and enums,
rename it to ParseTag.

llvm-svn: 39277
2007-01-23 04:08:05 +00:00
Chris Lattner 8799cf202c When parsing a struct/union tag, we need to know whether the tag is a use
or a definition/declaration of a tag.  This is required to handle
C99 6.7.2.3p11 properly.

llvm-svn: 39274
2007-01-23 01:57:16 +00:00
Chris Lattner ad9ac94d08 LLVM now has SmallSet, use it.
llvm-svn: 39270
2007-01-23 01:14:52 +00:00
Chris Lattner 8c6519a6e4 invoke a new callback when starting to parse a struct/union tag
llvm-svn: 39268
2007-01-22 07:41:36 +00:00
Chris Lattner 7f58c3dfe4 Do not use ParseCompoundStatement to parse the body of a function. This causes
an extra scope stack to be pushed between the function body and arguments, which
causes the parser to incorrectly accept stuff like 'int foo(int A) { int A; }',
which is test/Parser/argument_redef.c.

llvm-svn: 39252
2007-01-21 06:56:16 +00:00
Chris Lattner f297880ff9 Split code out of ParseCompoundStatement into ParseCompoundStatementBody.
This fixes a bug where a missing } could cause the scope stacks to get
unbalanced and will be used for function body parsing.

llvm-svn: 39249
2007-01-21 06:52:16 +00:00
Chris Lattner 29375654b6 Add support for parsing and pretty printing const_cast, dynamic_cast,
reinterpret_cast, and static_cast.  Patch by Bill!

llvm-svn: 39247
2006-12-04 18:06:35 +00:00
Chris Lattner 2114d5e948 add some comments
llvm-svn: 39242
2006-12-04 07:40:24 +00:00
Chris Lattner 5c5fbccc96 Scrutinize K&R parameter declarations. This implements C99 6.9.1p6, correctly
diagnosing malformed K&R function definitions.

llvm-svn: 39241
2006-12-03 08:41:30 +00:00
Chris Lattner 969ca15b41 Diagnose errors like:
void bar(int X, int X);

void blah(X, Y, X) int X, Y; {}

llvm-svn: 39239
2006-12-03 06:29:03 +00:00
Chris Lattner c81f079d7e move void argument checking from the parser to the semantic analysis stage.
This allows us to handle typedefs of void correctly.  This implements
clang/test/Sema/void_arg.c

llvm-svn: 39236
2006-12-03 02:43:54 +00:00
Chris Lattner d2e97c1f80 Handle void correctly in the argument list for a function. For:
X = sizeof(int (void a));
  X = sizeof(int (int, void));
  X = sizeof(int (void, ...));

We now emit:

t.c:6:24: error: void argument may not have a name
  X = sizeof(int (void a));
                       ^
t.c:7:24: error: 'void' must be the first and only parameter if specified
  X = sizeof(int (int, void));
                       ^
t.c:8:19: error: 'void' must be the first and only parameter if specified
  X = sizeof(int (void, ...));
                  ^


And we pretty print this correctly (even though void isn't stored in the
arg list of the function type):
  X = sizeof(int (void));


However, this approach will have to change to handle typedefs of void.

llvm-svn: 39235
2006-12-03 02:03:33 +00:00
Chris Lattner a606ac0fe3 finesse the interface to Declarator for function declarators so that the
declarator interface handles all alloc/dealloc issues related to the argument
list.  Before the client had to alloc and Declarator did the dealloc.

llvm-svn: 39234
2006-12-02 08:05:17 +00:00
Chris Lattner c6ad8131dd implement AST representation for function types with and without a prototype.
This lets us pretty print stuff like this:

void foo() {
  int X;
  X = sizeof(void (*(*)())());
  X = sizeof(int(*)(int, float, ...));
  X = sizeof(void (*(int arga, void (*argb)(double Y)))(void* Z));

as:

  X = sizeof(void (*(*)())())
  X = sizeof(int (*)(int, float, ...))
  X = sizeof(void (*(int, void (*)(double)))(void *))

Ah the wonders of 'modern' C syntax!

llvm-svn: 39232
2006-12-02 07:52:18 +00:00
Chris Lattner 216d8654fd implement ParseParamDeclaratorType in the ast builder
llvm-svn: 39231
2006-12-02 06:47:41 +00:00
Chris Lattner cbc426d4f7 Next step of retaining information about function prototypes: actually retain
the info.  Also, call Actions.ParseParamDeclaratorType instead of
Actions.ParseDeclarator for parameter type lists: we don't want declaration
objects created when parsing a function declarator, we just want type info.

llvm-svn: 39230
2006-12-02 06:43:02 +00:00
Chris Lattner edc9e39d88 First step towards accurately retaining information about function
parameters: build an array of ParamInfo structures and pass it to the
declarator for safe keeping (it owns the list).

Next step: actually populate the arg array with useful stuff.

llvm-svn: 39229
2006-12-02 06:21:46 +00:00
Chris Lattner cd3ea0cf35 doing this makes the diagnostics too verbose for no useful gain.
llvm-svn: 39228
2006-11-28 05:36:12 +00:00
Chris Lattner b20e89449f capture sourcelocation info for type specifiers. This improves diagnostics
for things like 'short _Complex'.

llvm-svn: 39227
2006-11-28 05:30:29 +00:00
Chris Lattner 60809f5aaf record location info for const/volatile/restrict
llvm-svn: 39226
2006-11-28 05:18:46 +00:00
Chris Lattner 1b22eed03c add loc info for the inline specifier, fix some fixme's by using it.
llvm-svn: 39225
2006-11-28 05:12:07 +00:00
Chris Lattner 4d8f873b5b record accurate sourceloc info for storage class specs, so we can report
things like:

t.c:4:10: error: invalid storage class specifier in function declarator
int foo2(auto int Aaslfkasdflkj, register B);
         ^

instead of:

t.c:4:19: error: invalid storage class specifier in function declarator
int foo2(auto int Aaslfkasdflkj, register B);
                  ^

llvm-svn: 39224
2006-11-28 05:05:08 +00:00
Chris Lattner 353f5740b1 Finish converting DeclSpec to use accessors.
llvm-svn: 39223
2006-11-28 04:50:12 +00:00
Chris Lattner a925dc66e4 Convert more code to use DeclSpec accessors
llvm-svn: 39222
2006-11-28 04:33:46 +00:00
Chris Lattner f055d43211 add accessors to DeclSpec, start moving clients over to use them.
llvm-svn: 39221
2006-11-28 04:28:12 +00:00
Chris Lattner 43e956c3b7 verify C99 6.7.5.3p2
llvm-svn: 39219
2006-11-28 04:05:37 +00:00
Chris Lattner bb233fe3aa add some comments.
llvm-svn: 39217
2006-11-21 23:13:27 +00:00
Chris Lattner d8702cd845 Implement a TODO: properly invoke actions for the * in things like:
where P is a pointer.

  int A[*P];

llvm-svn: 39199
2006-11-21 03:12:15 +00:00
Chris Lattner a966bf6ebf fix a variable shadowing issue that caused us to misparse:
void B() {
  memcpy (3, 2, 1);
}

where memcpy is undeclared.

llvm-svn: 39198
2006-11-21 01:40:01 +00:00
Chris Lattner 229ce60fc9 split the ParseFunctionDefinition action into two actions, one which is
called before and one which is called after function definition parsing.

llvm-svn: 39196
2006-11-21 01:21:07 +00:00
Chris Lattner ac18be9ad2 Add support for C90 implicitly defined functions, e.g.:
int A() {
  return X();
}

llvm-svn: 39194
2006-11-20 06:49:47 +00:00
Chris Lattner 17ed487947 parse identifier expressions properly. This allows us diagnose this:
typedef int X;

int A() {
  return X;
}

int B() {
  return Y;
}

as:

/Users/sabre/test.c:5:10: error: unexpected type name 'X': expected expression
return X;
       ^
/Users/sabre/test.c:9:10: error: use of undeclared 'Y' value
return Y;
       ^

llvm-svn: 39192
2006-11-20 04:58:19 +00:00
Chris Lattner d0342e5989 Create a new TypeNameType class, which represents typedefs as types. This
allows us to handle stuff like:

typedef int G;
 ..
  X = sizeof(G);

llvm-svn: 39189
2006-11-20 04:02:15 +00:00
Chris Lattner 2ebe4bb64d when a typedef name is parsed as part of declspecs, remember the decl for the
typedef.

llvm-svn: 39188
2006-11-20 01:29:42 +00:00
Chris Lattner 200bdc3b90 add an action method for declspecs without declarators, like "struct foo;".
llvm-svn: 39184
2006-11-19 02:43:37 +00:00
Chris Lattner 94c22cd5b9 rename ParsedClassDeclaration -> ParsedObjcClassDeclaration.
llvm-svn: 39183
2006-11-19 02:35:21 +00:00
Chris Lattner 302b4be4c2 build TypedefDecl objects when parsing typedefs.
Add a parsing fastpath for when we see typedef at the top-level.

llvm-svn: 39182
2006-11-19 02:31:38 +00:00
Chris Lattner 558cb292da add an action for parsing type names.
llvm-svn: 39180
2006-11-19 01:31:06 +00:00
Chris Lattner 9dfdb3c70d rearrange the type printing code so that we can do the horrible C "inside out"
thing properly.  This allows us to print types like:
int (*A)[restrict static 4][6];

properly, in addition to representing them properly. :)

llvm-svn: 39178
2006-11-13 07:38:09 +00:00
Chris Lattner 288e86ff15 Rename SemaDeclSpec.{h|cpp} back to DeclSpec.{h|cpp} now that the distinction
between sema and parse is clear.

llvm-svn: 39167
2006-11-11 23:03:42 +00:00
Chris Lattner bd638926e2 remove diag helper that implicitly reports the diagnostic at the current
token: it is better for the code to be explicit.

llvm-svn: 39158
2006-11-10 05:19:25 +00:00
Chris Lattner eaafe122b6 move semantic analysis of break/continue out of the parser into the sema class.
llvm-svn: 39157
2006-11-10 05:17:58 +00:00
Chris Lattner 08f2791bdc update comment
llvm-svn: 39151
2006-11-09 06:34:47 +00:00
Chris Lattner 697e5d692b Change courses on how we do semantic analysis. Semantic analysis
fundamentally requires having an AST around, so move all sema to the
AST library.  This is the first step, later steps will be needed to
clean up libast.

llvm-svn: 39150
2006-11-09 06:32:27 +00:00
Chris Lattner 289ab7bb1d rename SemaDecl.cpp/h to SemaDeclSpec.cpp/h
llvm-svn: 39149
2006-11-08 06:54:53 +00:00
Chris Lattner b26b665742 rename these methods so that they read correctly.
llvm-svn: 39148
2006-11-08 06:10:32 +00:00
Chris Lattner 3503cefbba split ParseStringExpr into semantic/minimal actions
llvm-svn: 39147
2006-11-08 06:03:59 +00:00
Chris Lattner b6a0e1781f implement trivial scope caching. This reduces malloc traffic in the common
case, speeding up parsing of this contrived example:

#define A {{}}
#define B A A A A A A A A A A
#define C B B B B B B B B B B
#define D C C C C C C C C C C
#define E D D D D D D D D D D
#define F E E E E E E E E E E
#define G F F F F F F F F F F
#define H G G G G G G G G G G

void foo() {
  H
}

from 7.478s to 4.321s.  GCC requires 8.2s.

llvm-svn: 39138
2006-11-06 00:22:42 +00:00
Chris Lattner 33ad2cacc9 Make Scope keep track of the kind of scope it is. Properly scope loop and
switch statements.  Make break/continue check that they are inside of an
appropriate control-flow construct.  This implements Parser/bad-control.c.

llvm-svn: 39136
2006-11-05 23:47:55 +00:00
Chris Lattner c62b6c232f eliminate EmptyAction, merging it into MinimalAction instead.
llvm-svn: 39134
2006-11-05 18:44:26 +00:00
Chris Lattner 0663d2afd9 start factoring actions into two flavors: minimal and semantic actions.
llvm-svn: 39133
2006-11-05 18:39:59 +00:00
Chris Lattner 7ad0fbe1f2 rename a bunch of files for better consistency
llvm-svn: 39126
2006-11-05 07:46:30 +00:00
Chris Lattner 7014fb8f07 need to add scope for arguments, but now is not the right time.
llvm-svn: 39125
2006-11-05 07:36:23 +00:00
Chris Lattner da59c2f161 Move objc productions to their own .cpp file.
llvm-svn: 39124
2006-11-05 02:08:13 +00:00
Chris Lattner 40f16b5d26 improve objc comments
llvm-svn: 39123
2006-11-05 02:05:37 +00:00
Chris Lattner 301cd76b8c silence warning
llvm-svn: 39115
2006-11-04 20:32:01 +00:00
Chris Lattner 71e23ce2e1 Add AST node, AST building, actions, and printing for 'for' stmts.
llvm-svn: 39113
2006-11-04 20:18:38 +00:00
Chris Lattner eb2feefb46 implement some todo's: invoke the actions module for identifiers leading
expressions in stmt contexts.

llvm-svn: 39112
2006-11-04 19:14:32 +00:00
Chris Lattner 834618de6f replace some ugly alloca/malloc code with a couple of SmallString's.
llvm-svn: 39103
2006-11-03 07:48:41 +00:00
Chris Lattner 64b09ee57a improve comment, fit to 80 cols
llvm-svn: 39101
2006-11-03 07:35:12 +00:00
Chris Lattner 70058dda70 Emit:
test.m:2:14: error: expected ';' after @class
@ class foo  int x;
             ^

instead of silently accepting the malformed input.

llvm-svn: 39100
2006-11-03 07:32:21 +00:00
Chris Lattner aacc5af2c0 Fix case stmts to not fall through, rename methods, assert on unimplemented
pieces, emit a diagnostic like this:

test.m:4:1: error: unexpected '@' in program
@ foo;
^

llvm-svn: 39099
2006-11-03 07:21:07 +00:00
Steve Naroff b419d3a80e - Added basic structure for parsing top level Objective-C forms.
- Extended the typedef mechanism for classes, improved performance of the common case.
- Implemented @class in the parser.

llvm-svn: 39074
2006-10-27 23:18:49 +00:00
Chris Lattner 9916c5ca7e Remove GNU C++ min/max operator extension support, they have been removed
from gcc mainline.

llvm-svn: 39067
2006-10-27 05:24:37 +00:00
Chris Lattner 05646c7f0e Fix these to allow clang to be in any dir.
llvm-svn: 39055
2006-10-26 04:56:55 +00:00
Chris Lattner b19f796e97 llvm has no EH by default, no need for these flags.
llvm-svn: 39047
2006-10-25 05:09:05 +00:00
Chris Lattner ae31969ad2 Finish removing LexerToken from actions interface
llvm-svn: 39044
2006-10-25 03:49:28 +00:00
Chris Lattner 0ba3dc4ec3 Start removing LexerToken from the actions interface.
llvm-svn: 39043
2006-10-25 03:38:23 +00:00
Chris Lattner 64408c7107 Compoundstmts imply a scope, track it. This implements
test/Parser/CompoundStmtScope.c

llvm-svn: 39042
2006-10-25 03:15:33 +00:00
Chris Lattner b1072a3df5 remove empty file
llvm-svn: 39039
2006-10-25 03:07:01 +00:00
Chris Lattner 4daa077a5c accept the __extension__ prefix expr
llvm-svn: 39018
2006-10-20 05:03:44 +00:00
Chris Lattner 1f496804d5 silence a warning
llvm-svn: 39007
2006-10-18 04:02:28 +00:00
Chris Lattner b95cca0d33 fix test/Parser/attributes.c
llvm-svn: 39001
2006-10-17 03:01:08 +00:00
Chris Lattner 04132371bb Make ConsumeFoo methods return the location of the consumed token.
llvm-svn: 38995
2006-10-16 06:12:55 +00:00
Chris Lattner af63531ac3 Make ConsumeToken return the loc of the consumed token to simplify clients
llvm-svn: 38994
2006-10-16 06:06:51 +00:00
Chris Lattner 30f910e88e implement action callbacks for almost all the stmts.
llvm-svn: 38993
2006-10-16 05:52:41 +00:00
Chris Lattner 2dacc3ff2e Changes through out the parser and actions/ast interface to return top-level
declarations through the asm streamer.  For a testcase like:

int G;
int H, I, *J;
int func() {}

'clang -parse-print-ast' prints:

Read top-level decl: G
Read top-level decl: H
Read top-level decl: I
Read top-level decl: J
Read top-level decl: func

llvm-svn: 38992
2006-10-16 00:33:54 +00:00
Chris Lattner a11999d83a start creating proper ast nodes for variables and functions
llvm-svn: 38991
2006-10-15 22:34:45 +00:00
Chris Lattner 14a1b64418 create an ast node for &&label
llvm-svn: 38989
2006-10-15 22:33:58 +00:00
Chris Lattner 02dffbda3b Write up TargetInfo so that use of wchar_t strings results in a warning if
used in a target set where the size is not identical.

llvm-svn: 38975
2006-10-14 07:50:21 +00:00
Chris Lattner 8c2048710d Rename LexerToken methods to be more consistent.
llvm-svn: 38969
2006-10-14 05:19:21 +00:00
Chris Lattner b5600a6aa8 Parse ?:'s right
llvm-svn: 38961
2006-10-06 05:40:05 +00:00
Chris Lattner d3e9895b9a Initial support for semantic analysis and AST building for StringExpr nodes.
llvm-svn: 38960
2006-10-06 05:22:26 +00:00
Chris Lattner 26da7302ce Build AST's for sizeof/alignof with type operands.
llvm-svn: 38951
2006-08-24 06:49:19 +00:00
Chris Lattner e550a4ea12 Build CastExpr AST nodes
llvm-svn: 38950
2006-08-24 06:37:51 +00:00
Chris Lattner 26115acb1c Build AST's for sizeof/alignof an expr.
llvm-svn: 38949
2006-08-24 06:10:04 +00:00
Chris Lattner 6f3a117f81 switch MemberExpr to holding a field decl instead of a raw identifier.
llvm-svn: 38948
2006-08-24 05:19:28 +00:00
Chris Lattner 879b9ad083 Add initial support for simple-primary exprs, including DeclExprs.
llvm-svn: 38944
2006-08-24 04:53:44 +00:00
Chris Lattner e165d944c2 Add AST nodes for array, call, . and ->.
llvm-svn: 38943
2006-08-24 04:40:38 +00:00