[cfe-commits] r38838 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp include/clang/Parse/DeclSpec.h include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:04 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:04 2007
New Revision: 38838
URL: http://llvm.org/viewvc/llvm-project?rev=38838&view=rev
Log:
Capture function information, provide a place to validate Declarator information.
Modified:
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38838&r1=38837&r2=38838&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:04 2007
@@ -286,7 +286,20 @@
}
}
-/// ParseDeclarator
+
+/// ParseDeclarator - Parse and verify a newly-initialized declarator.
+///
+void Parser::ParseDeclarator(Declarator &D) {
+ /// This implements the 'declarator' production in the C grammar, then checks
+ /// for well-formedness and issues diagnostics.
+ ParseDeclaratorInternal(D);
+
+ // FIXME: validate D.
+
+
+}
+
+/// ParseDeclaratorInternal
/// declarator: [C99 6.7.5]
/// pointer[opt] direct-declarator
///
@@ -294,7 +307,7 @@
/// '*' type-qualifier-list[opt]
/// '*' type-qualifier-list[opt] pointer
///
-void Parser::ParseDeclarator(Declarator &D) {
+void Parser::ParseDeclaratorInternal(Declarator &D) {
if (Tok.getKind() != tok::star)
return ParseDirectDeclarator(D);
@@ -305,7 +318,7 @@
ParseTypeQualifierListOpt(DS);
// Recursively parse the declarator.
- ParseDeclarator(D);
+ ParseDeclaratorInternal(D);
// Remember that we parsed a pointer type, and remember the type-quals.
D.AddTypeInfo(DeclaratorTypeInfo::getPointer(DS.TypeQualifiers, Loc));
@@ -387,7 +400,7 @@
/// identifier-list ',' identifier
///
void Parser::ParseParenDeclarator(Declarator &D) {
- SourceLocation LParenLoc = Tok.getLocation();
+ SourceLocation StartLoc = Tok.getLocation();
ConsumeParen();
// If we haven't past the identifier yet (or where the identifier would be
@@ -416,13 +429,13 @@
// direct-declarator: '(' declarator ')'
// direct-declarator: '(' attributes declarator ')' [TODO]
if (isGrouping) {
- ParseDeclarator(D);
+ ParseDeclaratorInternal(D);
if (Tok.getKind() == tok::r_paren) {
ConsumeParen();
} else {
// expected ')': skip until we find ')'.
Diag(Tok, diag::err_expected_rparen);
- Diag(LParenLoc, diag::err_matching);
+ Diag(StartLoc, diag::err_matching);
SkipUntil(tok::r_paren);
}
return;
@@ -441,13 +454,13 @@
// FIXME: enter function-declaration scope, limiting any declarators for
// arguments to the function scope.
// NOTE: better to only create a scope if not '()'
- bool isVariadic;
+ bool IsVariadic;
bool HasPrototype;
bool ErrorEmitted = false;
if (Tok.getKind() == tok::r_paren) {
// int() -> no prototype, no '...'.
- isVariadic = false;
+ IsVariadic = false;
HasPrototype = false;
} else if (Tok.getKind() == tok::identifier &&
0/*TODO: !isatypedefname(Tok.getIdentifierInfo())*/) {
@@ -481,22 +494,22 @@
}
// K&R 'prototype'.
- isVariadic = false;
+ IsVariadic = false;
HasPrototype = false;
} else {
- isVariadic = false;
+ IsVariadic = false;
bool ReadArg = false;
// Finally, a normal, non-empty parameter type list.
while (1) {
if (Tok.getKind() == tok::ellipsis) {
- isVariadic = true;
+ IsVariadic = true;
// Check to see if this is "void(...)" which is not allowed.
if (!ReadArg) {
// Otherwise, parse parameter type list. If it starts with an
// ellipsis, diagnose the malformed function.
Diag(Tok, diag::err_ellipsis_first_arg);
- isVariadic = false; // Treat this like 'void()'.
+ IsVariadic = false; // Treat this like 'void()'.
}
// Consume the ellipsis.
@@ -528,8 +541,13 @@
}
// FIXME: pop the scope.
+
+ // FIXME: capture argument info.
+
+ // Remember that we parsed a function type, and remember the attributes.
+ D.AddTypeInfo(DeclaratorTypeInfo::getFunction(HasPrototype, IsVariadic,
+ StartLoc));
- // FIXME: Add the function declarator.
// If we have the closing ')', eat it and we're done.
if (Tok.getKind() == tok::r_paren) {
Modified: cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=38838&r1=38837&r2=38838&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:25:04 2007
@@ -153,19 +153,25 @@
unsigned TypeQuals : 3;
/// True if this dimension included the 'static' keyword.
- bool Static : 1;
+ bool hasStatic : 1;
/// True if this dimension was [*]. In this case, NumElts is null.
- bool Star : 1;
+ bool isStar : 1;
/// This is the size of the array, or null if [] or [*] was specified.
/// FIXME: make this be an expression* when we have expressions.
void *NumElts;
};
+ struct FunctionTypeInfo {
+ bool hasPrototype : 1;
+ bool isVariadic : 1;
+ // TODO: capture argument info.
+ };
union {
PointerTypeInfo Ptr;
ArrayTypeInfo Arr;
+ FunctionTypeInfo Fun;
};
@@ -178,6 +184,7 @@
I.Ptr.TypeQuals = TypeQuals;
return I;
}
+
/// getArray - Return a DeclaratorTypeInfo for an array.
///
static DeclaratorTypeInfo getArray(unsigned TypeQuals, bool isStatic,
@@ -187,11 +194,23 @@
I.Kind = Array;
I.Loc = Loc;
I.Arr.TypeQuals = TypeQuals;
- I.Arr.Static = isStatic;
- I.Arr.Star = isStar;
+ I.Arr.hasStatic = isStatic;
+ I.Arr.isStar = isStar;
I.Arr.NumElts = NumElts;
return I;
}
+
+ /// getFunction - Return a DeclaratorTypeInfo for a function.
+ ///
+ static DeclaratorTypeInfo getFunction(bool hasProto, bool isVariadic,
+ SourceLocation Loc) {
+ DeclaratorTypeInfo I;
+ I.Kind = Function;
+ I.Loc = Loc;
+ I.Fun.hasPrototype = hasProto;
+ I.Fun.isVariadic = isVariadic;
+ return I;
+ }
};
Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38838&r1=38837&r2=38838&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:04 2007
@@ -161,7 +161,9 @@
void ParseDeclarationSpecifiers(DeclSpec &DS);
bool isDeclarationSpecifier() const;
+ /// ParseDeclarator - Parse and verify a newly-initialized declarator.
void ParseDeclarator(Declarator &D);
+ void ParseDeclaratorInternal(Declarator &D);
void ParseTypeQualifierListOpt(DeclSpec &DS);
void ParseDirectDeclarator(Declarator &D);
void ParseParenDeclarator(Declarator &D);
More information about the cfe-commits
mailing list