pass designators into sema. This completes parser-level designator

support as far as I know.

llvm-svn: 58217
This commit is contained in:
Chris Lattner 2008-10-26 23:35:51 +00:00
parent 9a53fdc23e
commit 248388e313
6 changed files with 30 additions and 11 deletions

View File

@ -485,6 +485,7 @@ namespace {
}
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
ExprTy **InitList, unsigned NumInit,
InitListDesignations &Designators,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return 0;

View File

@ -459,6 +459,7 @@ public:
}
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
ExprTy **InitList, unsigned NumInit,
InitListDesignations &Designators,
SourceLocation RParenLoc) {
return 0;
}

View File

@ -208,6 +208,19 @@ public:
return Designations.back();
}
/// getDesignationForInitializer - If there is a designator for the specified
/// initializer, return it, otherwise return null.
const Designation *getDesignationForInitializer(unsigned Idx) const {
// The common case is no designators.
if (!hasAnyDesignators()) return 0;
// FIXME: This should do a binary search, not a linear one.
for (unsigned i = 0, e = Designations.size(); i != e; ++i)
if (Designations[i].InitIndex == Idx)
return &Designations[i];
return 0;
}
};
} // end namespace clang

View File

@ -236,14 +236,6 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
Parser::ExprResult Parser::ParseBraceInitializer() {
SourceLocation LBraceLoc = ConsumeBrace();
// We support empty initializers, but tell the user that they aren't using
// C99-clean code.
if (Tok.is(tok::r_brace)) {
Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
// Match the '}'.
return Actions.ActOnInitList(LBraceLoc, 0, 0, ConsumeBrace());
}
/// InitExprs - This is the actual list of expressions contained in the
/// initializer.
llvm::SmallVector<ExprTy*, 8> InitExprs;
@ -252,6 +244,15 @@ Parser::ExprResult Parser::ParseBraceInitializer() {
/// was specified for it, if any.
InitListDesignations InitExprDesignations(Actions);
// We support empty initializers, but tell the user that they aren't using
// C99-clean code.
if (Tok.is(tok::r_brace)) {
Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
// Match the '}'.
return Actions.ActOnInitList(LBraceLoc, 0, 0, InitExprDesignations,
ConsumeBrace());
}
bool InitExprsOk = true;
while (1) {
@ -293,8 +294,8 @@ Parser::ExprResult Parser::ParseBraceInitializer() {
if (Tok.is(tok::r_brace)) break;
}
if (InitExprsOk && Tok.is(tok::r_brace))
return Actions.ActOnInitList(LBraceLoc, &InitExprs[0], InitExprs.size(),
ConsumeBrace());
return Actions.ActOnInitList(LBraceLoc, &InitExprs[0], InitExprs.size(),
InitExprDesignations, ConsumeBrace());
// On error, delete any parsed subexpressions.
for (unsigned i = 0, e = InitExprs.size(); i != e; ++i)

View File

@ -614,6 +614,7 @@ public:
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
ExprTy **InitList, unsigned NumInit,
InitListDesignations &Designators,
SourceLocation RParenLoc);
virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,

View File

@ -1247,11 +1247,13 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
if (CheckForConstantInitializer(literalExpr, literalType))
return true;
}
return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr, isFileScope);
return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr,
isFileScope);
}
Action::ExprResult Sema::
ActOnInitList(SourceLocation LBraceLoc, ExprTy **initlist, unsigned NumInit,
InitListDesignations &Designators,
SourceLocation RBraceLoc) {
Expr **InitList = reinterpret_cast<Expr**>(initlist);