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
This commit is contained in:
Chris Lattner 2006-08-12 18:25:42 +00:00
parent 0c6c034c48
commit 9fab3b9486
1 changed files with 21 additions and 16 deletions

View File

@ -159,6 +159,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
// specifiers. First verify that DeclSpec's are consistent. // specifiers. First verify that DeclSpec's are consistent.
DS.Finish(StartLoc, Diags, getLang()); DS.Finish(StartLoc, Diags, getLang());
return; return;
// FIXME: Handle struct/union/enum tags.
// storage-class-specifier // storage-class-specifier
case tok::kw_typedef: case tok::kw_typedef:
@ -423,7 +424,7 @@ void Parser::ParseDeclarator(Declarator &D) {
/// for well-formedness and issues diagnostics. /// for well-formedness and issues diagnostics.
ParseDeclaratorInternal(D); ParseDeclaratorInternal(D);
// FIXME: validate D. // TODO: validate D.
} }
@ -574,7 +575,7 @@ void Parser::ParseParenDeclarator(Declarator &D) {
// Okay, this is the parameter list of a function definition, or it is an // Okay, this is the parameter list of a function definition, or it is an
// identifier list of a K&R-style function. // identifier list of a K&R-style function.
// FIXME: enter function-declaration scope, limiting any declarators for // TODO: enter function-declaration scope, limiting any declarators for
// arguments to the function scope. // arguments to the function scope.
// NOTE: better to only create a scope if not '()' // NOTE: better to only create a scope if not '()'
bool IsVariadic; bool IsVariadic;
@ -600,7 +601,7 @@ void Parser::ParseParenDeclarator(Declarator &D) {
if (!D.getIdentifier()) if (!D.getIdentifier())
Diag(Tok, diag::ext_ident_list_in_param); Diag(Tok, diag::ext_ident_list_in_param);
// FIXME: Remember token. // TODO: Remember token.
ConsumeToken(); ConsumeToken();
while (Tok.getKind() == tok::comma) { while (Tok.getKind() == tok::comma) {
// Eat the comma. // Eat the comma.
@ -614,7 +615,7 @@ void Parser::ParseParenDeclarator(Declarator &D) {
} }
// Eat the id. // Eat the id.
// FIXME: remember it! // TODO: remember it!
ConsumeToken(); ConsumeToken();
} }
@ -665,9 +666,9 @@ void Parser::ParseParenDeclarator(Declarator &D) {
HasPrototype = true; HasPrototype = true;
} }
// FIXME: pop the scope. // TODO: pop the scope.
// FIXME: capture argument info. // TODO: capture argument info.
// Remember that we parsed a function type, and remember the attributes. // Remember that we parsed a function type, and remember the attributes.
D.AddTypeInfo(DeclaratorTypeInfo::getFunction(HasPrototype, IsVariadic, D.AddTypeInfo(DeclaratorTypeInfo::getFunction(HasPrototype, IsVariadic,
@ -716,6 +717,7 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
// Handle "direct-declarator [ type-qual-list[opt] * ]". // Handle "direct-declarator [ type-qual-list[opt] * ]".
bool isStar = false; bool isStar = false;
void *NumElts = 0;
if (Tok.getKind() == tok::star) { if (Tok.getKind() == tok::star) {
// Remember the '*' token, in case we have to un-get it. // Remember the '*' token, in case we have to un-get it.
LexerToken StarTok = Tok; LexerToken StarTok = Tok;
@ -730,24 +732,27 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
isStar = true; isStar = true;
} else { } else {
// Otherwise, the * must have been some expression (such as '*ptr') that // Otherwise, the * must have been some expression (such as '*ptr') that
// started an assign-expr. We already consumed the token, but now we need // started an assignment-expr. We already consumed the token, but now we
// to reparse it. // need to reparse it.
// FIXME: We must push 'StarTok' and Tok back into the preprocessor as a // FIXME: We must push 'StarTok' and Tok back into the preprocessor as a
// macro expansion context, so they will be read again. It is basically // macro expansion context, so they will be read again. It is basically
// impossible to refudge the * in otherwise, due to cases like X[*p + 4]. // impossible to refudge the * in otherwise, due to cases like X[*p + 4].
assert(0 && "FIXME: int X[*p] unimplemented"); assert(0 && "FIXME: int X[*p] unimplemented");
} }
} } else if (Tok.getKind() != tok::r_square) {
void *NumElts = 0;
if (!isStar && Tok.getKind() != tok::r_square) {
// Parse the assignment-expression now. // Parse the assignment-expression now.
NumElts = /*FIXME: parse array size expr*/0; ExprResult Res = ParseAssignmentExpression();
assert(0 && "expr parsing not impl yet!"); if (Res.isInvalid) {
// If the expression was invalid, skip it.
SkipUntil(tok::r_square);
return;
}
NumElts = /*TODO: parse array size expr*/0;
} }
ConsumeBracket(); MatchRHSPunctuation(tok::r_square, StartLoc, "[", diag::err_expected_rsquare);
// If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if // If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if
// it was not a constant expression. // it was not a constant expression.
if (!getLang().C99) { if (!getLang().C99) {