Commit Graph

34186 Commits

Author SHA1 Message Date
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 47955dee04 Eliminate the last of the slow lookups, by making non-prototyped function types
use the folding set.  This eliminates 359 slow lookups from carbon.h (the
rest) but doesn't substantially speed up parse.

llvm-svn: 39320
2007-01-27 08:37:20 +00:00
Chris Lattner 36f8e65eef Switch arraytypes over to using a FoldingSet instead of a stupid linear
search.  This reduces 'dumb' lookups from 1225 to 359, speeding up parse
of carbon.h from 0.173 to 0.156s (10%).

llvm-svn: 39319
2007-01-27 08:31:04 +00:00
Chris Lattner 25fe86af2b minor cleanup
llvm-svn: 39318
2007-01-27 08:29:39 +00:00
Chris Lattner 80c114ae7e Switch scopes from keeping decls in SmallSet to keeping them in the new
SmallPtrSet data structure.  This datastructure handles the 'nonsmall' case
quite gracefully, with an efficient exponentially probed hashtable.  This is
important for handling global scope, which gets many thousands of decls (e.g.
every function and enum value).  Of course the typical inner scopes are still
as efficient as ever.

On my mac pro, this speeds up parsing carbon.h from 0.59s to 0.168s (3.5x),
and there is still low hanging fruit :).

For reference, GCC on the same system takes 0.33s for -fsyntax-only.

llvm-svn: 39317
2007-01-27 07:16:01 +00:00
Chris Lattner 38047f9e23 Fix test/Parser/argument_qualified.c
llvm-svn: 39316
2007-01-27 06:24:01 +00:00
Chris Lattner a4792c1e64 new testcase that crashed clang
llvm-svn: 39315
2007-01-27 06:23:34 +00:00
Chris Lattner 739fa67f19 Revert accidental commit
llvm-svn: 39314
2007-01-27 02:20:41 +00:00
Chris Lattner baf33665fb adjust to change in SmallSet interface
llvm-svn: 39313
2007-01-27 02:14:08 +00:00
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 4f6a75809c fix printing of unprototyped function decls.
llvm-svn: 39310
2007-01-26 21:19:14 +00:00
Chris Lattner 0659f48467 add a new TypeDecl class, which shares commonality between TypedefDecl and TagDecl instances.
llvm-svn: 39309
2007-01-26 02:12:16 +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 41175f40a3 random testcase
llvm-svn: 39301
2007-01-25 07:42:11 +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 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