Commit Graph

137 Commits

Author SHA1 Message Date
Chris Lattner 67521df9a8 Switch pointers over to using a FoldingSet to unique them instead of
"obviously braindead" linear searches.  reduces the number of slow
type lookups from 10K to 883 on carbon.h, speeding up parsing from 3.5 to
1.26s.

llvm-svn: 39312
2007-01-27 01:29:36 +00:00
Chris Lattner fd4de79d2b Eliminate "obviously braindead" canonicalization of function types, using
a foldingset instead.  This reduces the number of slow type lookups from
32K to 10K, which speeds up parsing of carbon.h from 11s to 3.5s.

llvm-svn: 39311
2007-01-27 01:15:32 +00:00
Chris Lattner 6668fc60be Use a cache in TypedefDecl to make ASTContext::getTypedefType trivial.
This speeds up parsing carbon.h from 16.0s to 11.3s, reducing slow
lookups from 63K to 32K.

llvm-svn: 39308
2007-01-26 02:07:07 +00:00
Chris Lattner 32d920b8dc rename some classes, no functionality changes.
llvm-svn: 39307
2007-01-26 02:01:53 +00:00
Chris Lattner 733067d20a TagDecl now holds a cache for the type corresponding to it. This speeds up
ASTContext::getTagDeclType by not having to do a linear search.  With this,
parse time for carbon.h drops from 21.8s to 16.0s and # slow lookups drop from
83K to 63K.

llvm-svn: 39306
2007-01-26 01:42:24 +00:00
Chris Lattner 4eb445d2a1 start gather stats on types processed. carbon.h currently yields:
*** AST Context Stats:
  30594 types total.
    19 builtin types
    3929 pointer types
    308 array types
    18883 function types with proto
    8 function types with no proto
    2988 typename (typedef) types
    4459 tagged types
      1476 struct types
      80 union types
      0 class types
      2903 enum types
  83298 slow type lookups

Next up, making type canonicalization not trivially silly.

llvm-svn: 39305
2007-01-26 01:27:23 +00:00
Chris Lattner 01a7c5364f Don't crash if GetTypeForDeclarator can't grok a type.
llvm-svn: 39304
2007-01-25 23:09:03 +00:00
Chris Lattner e5a6656b62 Reject:
struct q { int a, a; };

with:

t.c:3:19: error: duplicate member 'a'
struct q { int a, a; };
                  ^
t.c:3:16: error: previous definition is here
struct q { int a, a; };
               ^

llvm-svn: 39303
2007-01-25 22:48:42 +00:00
Chris Lattner 8116d1b5e4 Register enumconstantdecls in their appropriate scope and check for conflicts.
This emits these diagnostics:

t.c:4:14: error: redefinition of 'a'
enum foo22 { a, b };
             ^
t.c:3:5: error: previous definition is here
int a;
    ^
t.c:8:17: error: redefinition of enumerator 'b'
enum foo23 { c, b };
                ^
t.c:4:17: error: previous definition is here
enum foo22 { a, b };
                ^
4 diagnostics generated.


for:

int a;
enum foo22 { a, b };
enum foo23 { c, b };

llvm-svn: 39302
2007-01-25 22:38:29 +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 5f521506aa Add EnumDecl, warn about forward references to enums:
t.c:2:6: warning: ISO C forbids forward references to 'enum' types
enum foo22* X;
     ^

llvm-svn: 39299
2007-01-25 06:27:24 +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 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 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 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 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 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 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 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 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 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 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 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 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 0d89d5a638 Enforce C99 6.7.5.3p3, rejecting code like:
void foo(void (*q)(a,b,c)) {}

llvm-svn: 39240
2006-12-03 07:14:39 +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 53e776c1e4 reject int(const void).
llvm-svn: 39238
2006-12-03 03:07:05 +00:00
Chris Lattner 726f97b435 implement a fixme: make BuiltinType have an enum, specifying which type it is,
instead of having a string.

llvm-svn: 39237
2006-12-03 02:57:32 +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 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 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 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