Commit Graph

140 Commits

Author SHA1 Message Date
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 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 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 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 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 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 7ad0fbe1f2 rename a bunch of files for better consistency
llvm-svn: 39126
2006-11-05 07:46:30 +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 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 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 e550a4ea12 Build CastExpr AST nodes
llvm-svn: 38950
2006-08-24 06:37:51 +00:00
Chris Lattner 5646b3e21c Fix test/Parser/types.c
llvm-svn: 38928
2006-08-15 05:12:01 +00:00
Chris Lattner 04f8019616 Make MatchRHSPunctuation smarter, allowing its clients to be simpler.
llvm-svn: 38926
2006-08-15 04:55:54 +00:00
Chris Lattner e37e2336b4 Parse attributes in all places allowed.
llvm-svn: 38925
2006-08-15 04:50:22 +00:00
Chris Lattner b8cd5c2260 Parse (and ignore) attributes on global decls.
llvm-svn: 38924
2006-08-15 04:10:46 +00:00
Chris Lattner 6d7e634399 Parse asm specifiers on init declarators. Add __builtin_va_list to the
symbol table at startup time.

llvm-svn: 38922
2006-08-15 03:41:14 +00:00
Chris Lattner 8a3e918e33 Correctly implement the check for a typedef name
llvm-svn: 38921
2006-08-14 15:44:00 +00:00
Chris Lattner 0fb8b36808 "enum x" really is a type specifier
llvm-svn: 38920
2006-08-14 01:30:12 +00:00
Chris Lattner 3b4fdda3d8 Fix the last remaining FIXME's in the parser by asking the actions module
whether or not an identifier is a typedef name.

llvm-svn: 38915
2006-08-14 00:45:39 +00:00
Chris Lattner f0f3baa12e Inform actions about parsed declarators.
llvm-svn: 38910
2006-08-14 00:15:20 +00:00
Chris Lattner b8bbad7fd1 Set TypeSpecType on 'struct x' with no body.
llvm-svn: 38904
2006-08-13 22:21:02 +00:00
Chris Lattner da72c82e8e Recognize struct/union/enum as TypeSpecType's
llvm-svn: 38903
2006-08-13 22:16:42 +00:00
Chris Lattner 476c3adb69 implement the GNU case-range extension. Add todo's for other missing gnu extensions.
llvm-svn: 38902
2006-08-13 22:09:58 +00:00
Chris Lattner 0e89462b08 Parse things like 'struct X;'
llvm-svn: 38898
2006-08-13 19:58:17 +00:00
Chris Lattner 1890ac8b03 Parse struct/union specifiers.
llvm-svn: 38897
2006-08-13 01:16:23 +00:00
Chris Lattner 3b561a3b39 Implement parsing of enum-specifiers.
llvm-svn: 38896
2006-08-13 00:12:11 +00:00
Chris Lattner 0be454e182 Use ExpectAndConsume more
llvm-svn: 38895
2006-08-12 19:30:51 +00:00
Chris Lattner 6259172911 Implement parsing of array declarators like:
int Array[*(int*)P+A];

llvm-svn: 38890
2006-08-12 18:40:58 +00:00
Chris Lattner 9fab3b9486 Implement parsing of 'int A[X];' by tying into the expression parsing code.
Turn a bunch of fixme's into todo's.

llvm-svn: 38888
2006-08-12 18:25:42 +00:00
Chris Lattner f5fbd7963d Implement type-name parsing, and simple compound initializer parsing.
llvm-svn: 38865
2006-08-10 23:56:11 +00:00
Chris Lattner 4564bc1123 Factor some code into the new Parser::MatchRHSPunctuation method.
llvm-svn: 38864
2006-08-10 23:14:52 +00:00
Chris Lattner c2dd85ac9e Implement most of unary-expression parsing.
llvm-svn: 38862
2006-08-10 22:57:16 +00:00
Chris Lattner c5e0d4a6ae stub out some entry points for the expr parsing code.
llvm-svn: 38858
2006-08-10 19:06:03 +00:00
Chris Lattner eb8a28f7b7 Rename some files
llvm-svn: 38855
2006-08-10 18:43:39 +00:00
Chris Lattner 2f9980ef14 Implement Parser/statements.c:test5: parsing decls that start with identifiers
in blocks.

llvm-svn: 38854
2006-08-10 18:39:24 +00:00
Chris Lattner 53361ac130 Refactor init-declarator-list parsing code to allow for-statements to have
initializers in them.

llvm-svn: 38847
2006-08-10 05:19:57 +00:00
Chris Lattner 0ccd51ebe2 Start parsing statements and function bodies. This implements
Parser/statements.c:test1.

llvm-svn: 38842
2006-08-09 05:47:47 +00:00
Chris Lattner fff824fe14 Simplify and fill out parsing of function bodies.
llvm-svn: 38841
2006-08-07 06:31:38 +00:00
Chris Lattner bf320c84a5 better comments, infrastructure for parsing function bodies.
llvm-svn: 38839
2006-08-07 05:05:30 +00:00
Chris Lattner d5d0a6c2b5 Capture function information, provide a place to validate Declarator information.
llvm-svn: 38838
2006-08-07 00:58:14 +00:00
Chris Lattner a350722189 comment cleanup
llvm-svn: 38837
2006-08-07 00:33:37 +00:00
Chris Lattner 6c7416c382 Start capturing pointer and array declarator info.
llvm-svn: 38836
2006-08-07 00:19:33 +00:00
Chris Lattner 14776b9501 Implement some more error recovery
llvm-svn: 38835
2006-08-06 22:27:40 +00:00
Chris Lattner eec40f9990 Start implementing error recovery, this implements test/Parser/recovery-1.c
llvm-svn: 38833
2006-08-06 21:55:29 +00:00
Chris Lattner 1906f8087d Improve handling of [*]
llvm-svn: 38831
2006-08-06 19:14:46 +00:00
Chris Lattner 8a39edc931 Warn for c99-specific array use
llvm-svn: 38830
2006-08-06 18:33:32 +00:00
Chris Lattner e8074e65dd Parse array declarators, tested by Parser/declarators.c
llvm-svn: 38828
2006-08-06 18:30:15 +00:00
Chris Lattner acd58a3c33 Parse parenthesized and function declarators now, allowing us to parse things
like: "void (*signal(int, void (*)(int)))(int);"

llvm-svn: 38824
2006-08-06 17:24:14 +00:00
Chris Lattner 15356a7065 Start capturing declarator information in a new Declarator object.
llvm-svn: 38823
2006-08-06 00:02:28 +00:00
Chris Lattner d9c3c59fc0 Continue work on declspecs and declarations
llvm-svn: 38818
2006-08-05 06:26:47 +00:00
Chris Lattner 8e90ef6ccc add some notes
llvm-svn: 38817
2006-08-05 03:30:45 +00:00
Chris Lattner f63f89acc2 Handle __thread and storage-class-specifiers
llvm-svn: 38816
2006-08-05 03:28:50 +00:00
Chris Lattner 839713c085 Emit diagnostics for things like 'signed _Bool' and 'short float'
llvm-svn: 38811
2006-08-04 06:15:52 +00:00
Chris Lattner da48a8e66b Parse and validate cvr type-qualifiers
llvm-svn: 38807
2006-08-04 05:25:55 +00:00
Chris Lattner b9093cd1d0 Add an initial cut at a datastructure for holding declspec's.
llvm-svn: 38805
2006-08-04 04:39:53 +00:00
Chris Lattner c0acd3d621 Split declaration parsing out into Declarations.cpp
llvm-svn: 38804
2006-07-31 05:13:43 +00:00