Commit Graph

762 Commits

Author SHA1 Message Date
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 4194315681 Save the member list of a struct/union in the RecordDecl for the struct.
llvm-svn: 39297
2007-01-25 04:52:46 +00:00
Chris Lattner 720a054994 Enforce the rest of C99 6.7.2.1p2, emitting diagnostics like:
t.c:10:15: warning: 'bonk' may not be nested in a struct due to flexible array member
  struct bink bonk;
              ^
t.c:13:14: error: 'struct bink' may not be used as an array element due to flexible array member
struct bink A[123];
             ^
for:

struct bink {
  struct bink *a;
  int X[];  // ok.
};

struct foo {
  int A;
  struct bink bonk;
};

struct bink A[123];

llvm-svn: 39296
2007-01-25 00:44:24 +00:00
Chris Lattner 8262560b8b Compile:
struct bork {
  int X[];
};

struct bink {
  struct bink a;
  int X[];  // ok.
};

to:
t.c:3:7: error: flexible array 'X' not allowed in otherwise empty struct
  int X[];
      ^
t.c:7:15: error: field 'a' has incomplete type
  struct bink a;
              ^

llvm-svn: 39295
2007-01-24 02:26:21 +00:00
Chris Lattner bdf8b8d251 Enforce C99 6.7.2.1p2:
t.c:5:8: error: field 'foo' declared as a function
  void foo();
       ^

llvm-svn: 39294
2007-01-24 02:11:17 +00:00
Chris Lattner ce3a702f4b implement classof for FieldDecl
llvm-svn: 39293
2007-01-24 02:10:37 +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 6531c1075c Diagnose invalid sizeof/alignof operands.
llvm-svn: 39291
2007-01-23 22:29:49 +00:00
Chris Lattner 367b019f79 add callback for fields.
llvm-svn: 39290
2007-01-23 22:29:13 +00:00
Chris Lattner c0cb43e518 Add Type::isIncompleteType, which implements the algorithm described in
C99 6.2.5.

llvm-svn: 39289
2007-01-23 21:58:16 +00:00
Chris Lattner d68e129e87 structure bodies can't get scopes.
llvm-svn: 39288
2007-01-23 21:57:45 +00:00
Chris Lattner 8eaca54d76 new testcase
llvm-svn: 39287
2007-01-23 20:16:22 +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 3e30f7c70f add a testcase for c++ casting operators, by Bill
llvm-svn: 39285
2007-01-23 06:12:15 +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 c284e9b905 fix some incorrect assertions
llvm-svn: 39283
2007-01-23 05:14:32 +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 5f7f4e43fb clean up scope iteration support
llvm-svn: 39276
2007-01-23 03:43:34 +00:00
Chris Lattner 7e783a1a08 Diagnose mixing of tags. For example, for:
struct blah * P;
union blah *P2;

we now emit:

t.c:2:1: error: redefinition of 'blah' with tag that does not match previous use
union blah *P2;
^
t.c:1:8: error: previous use is here
struct blah * P;
       ^

llvm-svn: 39275
2007-01-23 02:05:42 +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 3e29d0efd5 Switch Scope to use a SmallSet instead of a SmallVector to make isDeclScope
queries more natural.

llvm-svn: 39273
2007-01-23 01:35:19 +00:00
Chris Lattner ff65b6bc85 Unstack identifiers more carefully when poping scope. Add assertion to catch the bad
case and handle identifiers in the same namespace correctly.  This implements
test/Parser/c-namespace.c

llvm-svn: 39272
2007-01-23 01:33:16 +00:00
Chris Lattner 23f2e9e687 new testcase
llvm-svn: 39271
2007-01-23 01:32:33 +00:00
Chris Lattner ad9ac94d08 LLVM now has SmallSet, use it.
llvm-svn: 39270
2007-01-23 01:14:52 +00:00
Chris Lattner 371f154c4f adjust to api change
llvm-svn: 39269
2007-01-22 07:41:51 +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 28743e219b - Add struct/union/class/enum kinds.
- Add support for getting the namespace of a decl.
 - Move type down the inheritance hierarchy, it doesn't make sense for a struct
   to have a type, and typedef's use types in different ways than variables do.
 - Add initial TagDecl/RecordDecl classes.

llvm-svn: 39267
2007-01-22 07:41:08 +00:00
Chris Lattner d0ee402a43 Make name lookup properly obey C namespaces, simplify decl construction byeliminating the 'next' pointer from the ctor, and add initial support forparsing struct/union tags.
llvm-svn: 39266
2007-01-22 07:39:30 +00:00
Chris Lattner 18b196282f Make name lookup properly obey C namespaces, simplify decl construction by
eliminating the 'next' pointer from the ctor, and add initial support for
parsing struct/union tags.

llvm-svn: 39265
2007-01-22 07:39:13 +00:00
Chris Lattner c1618c452f add an action for parsing struct/union tags
llvm-svn: 39264
2007-01-22 07:37:38 +00:00
Chris Lattner 20ae9f6622 pretty print ... as well
llvm-svn: 39263
2007-01-21 23:48:06 +00:00
Chris Lattner 7f24b2abb8 Pretty print function prototypes as well.
llvm-svn: 39262
2007-01-21 23:46:27 +00:00
Chris Lattner ef1387808f Pretty print the function prototype. For example, print:
void (*signal(int arga, void (*argb)(double Y)))(void* Z) {}

as:

void (*signal(int arga, void (*argb)(double)))(void *) {
}

go C :)

llvm-svn: 39261
2007-01-21 23:11:09 +00:00
Chris Lattner ec040b1d89 make Decl::getName() not crash if the decl is unnamed (e.g. an unnamed argument)
llvm-svn: 39260
2007-01-21 23:09:50 +00:00
Chris Lattner 2e89ebbcc8 add accessor
llvm-svn: 39259
2007-01-21 23:09:17 +00:00
Chris Lattner 3a386e2fa8 Implement llvm::simplify_type, allowing dyn_cast<FunctionType>(typeref).
llvm-svn: 39258
2007-01-21 22:52:48 +00:00
Chris Lattner 99d3177103 Change scopes to maintain decls, not identifiers.
Detect and emit errors when names are redefined in the same scope, e.g.
test/Parser/argument_redef.c, which now emits:

argument_redef.c:4:22: error: redefinition of 'A'
int foo(int A) { int A; }
                     ^
argument_redef.c:4:13: error: previous definition is here
int foo(int A) { int A; }
            ^

llvm-svn: 39257
2007-01-21 22:37:37 +00:00
Chris Lattner f61c8a805d Handle C99 6.7.5.3p10, fixing test/Parser/attributes.c
llvm-svn: 39256
2007-01-21 19:04:43 +00:00
Chris Lattner 8f5bf2f233 avoid allocating memory for empty arg lists
llvm-svn: 39255
2007-01-21 19:04:10 +00:00
Chris Lattner 30b4b5cad8 default to -fsyntax-only
llvm-svn: 39254
2007-01-21 19:03:55 +00:00
Chris Lattner c5cdf4d092 Next big step in function parsing: create decl objects for parameters,
inserting them into the function body scope and registering them with the
corresponding FunctionDecl.

llvm-svn: 39253
2007-01-21 07:42:07 +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 ac71608b17 new testcase
llvm-svn: 39251
2007-01-21 06:56:08 +00:00
Chris Lattner 3bdee8c053 cleanup code to make it more obvious and extensible
llvm-svn: 39250
2007-01-21 06:52:45 +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