Commit Graph

34140 Commits

Author SHA1 Message Date
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
Chris Lattner 79ff0d4cc1 Make the clean target tidier by cleaning the test directory.
llvm-svn: 39248
2007-01-15 02:06:47 +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 1b65aaef2b improve this test to also check -fno-operator-keywords.
llvm-svn: 39246
2006-12-04 18:00:36 +00:00
Chris Lattner 3e7592ea78 Add support for -fno-operator-names, patch by Bill.
llvm-svn: 39245
2006-12-04 07:48:37 +00:00
Chris Lattner 3034f66584 add option for C++ operator names, patch by Bill.
llvm-svn: 39244
2006-12-04 07:46:15 +00:00
Chris Lattner 69c7ee2d51 allow getTokenName to work for keywords.
llvm-svn: 39243
2006-12-04 07:45:05 +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 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 784b168c92 new testcase
llvm-svn: 39233
2006-12-02 07:59: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 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