aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-08-05 01:35:17 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-08-05 01:35:17 +0000
commita80f8749f2968d19595ca2544114932bf0ca2c11 (patch)
treefb1a27a8795fa3ac5c6b965cf38d1be74bfe49dc /lib
parent820b03398fdcc8f1f6c60ace55b708e311fa8ce4 (diff)
Add more Parser/Sema support for GCC asm-label extension.
- ActOnDeclarator now takes an additional parameter which is the AsmLabel if used. Its unfortunate that this bubbles up this high, but we cannot just lump it in as an attribute without mistakenly *accepting* it as an attribute. - The actual asm-label itself is, however, encoded as an AsmLabelAttr on the FunctionDecl. - Slightly improved parser error recovery on malformed asm-labels. - CodeGen support still missing... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Parse/MinimalAction.cpp3
-rw-r--r--lib/Parse/ParseDecl.cpp16
-rw-r--r--lib/Parse/ParseObjc.cpp2
-rw-r--r--lib/Parse/Parser.cpp6
-rw-r--r--lib/Sema/Sema.h3
-rw-r--r--lib/Sema/SemaDecl.cpp14
-rw-r--r--lib/Sema/SemaDeclCXX.cpp2
7 files changed, 33 insertions, 13 deletions
diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp
index cb130c3d26..352925535d 100644
--- a/lib/Parse/MinimalAction.cpp
+++ b/lib/Parse/MinimalAction.cpp
@@ -63,7 +63,8 @@ MinimalAction::isTypeName(const IdentifierInfo &II, Scope *S) {
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
/// popped.
Action::DeclTy *
-MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) {
+MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
+ ExprTy *AsmLabel) {
IdentifierInfo *II = D.getIdentifier();
// If there is no identifier associated with this declarator, bail out.
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 81cb0ce627..33482c5700 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -256,8 +256,14 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
// rest of the init-declarator-list.
while (1) {
// If a simple-asm-expr is present, parse it.
- if (Tok.is(tok::kw_asm))
- ParseSimpleAsm();
+ ExprResult AsmLabel;
+ if (Tok.is(tok::kw_asm)) {
+ AsmLabel = ParseSimpleAsm();
+ if (AsmLabel.isInvalid) {
+ SkipUntil(tok::semi);
+ return 0;
+ }
+ }
// If attributes are present, parse them.
if (Tok.is(tok::kw___attribute))
@@ -265,13 +271,13 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
// Inform the current actions module that we just parsed this declarator.
// FIXME: pass asm & attributes.
- LastDeclInGroup = Actions.ActOnDeclarator(CurScope, D, LastDeclInGroup);
+ LastDeclInGroup = Actions.ActOnDeclarator(CurScope, D, LastDeclInGroup,
+ AsmLabel.Val);
// Parse declarator '=' initializer.
- ExprResult Init;
if (Tok.is(tok::equal)) {
ConsumeToken();
- Init = ParseInitializer();
+ ExprResult Init = ParseInitializer();
if (Init.isInvalid) {
SkipUntil(tok::semi);
return 0;
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 980105a02c..467cbd84a0 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1222,7 +1222,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
ParseDeclarator(DeclaratorInfo);
if (DeclaratorInfo.getIdentifier()) {
DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope,
- DeclaratorInfo, 0);
+ DeclaratorInfo, 0, 0);
StmtResult stmtResult =
Actions.ActOnDeclStmt(aBlockVarDecl,
DS.getSourceRange().getBegin(),
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index ef07d3f08b..9eab4fda15 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -670,7 +670,11 @@ Parser::ExprResult Parser::ParseSimpleAsm() {
ExprResult Result = ParseAsmStringLiteral();
- MatchRHSPunctuation(tok::r_paren, Loc);
+ if (Result.isInvalid) {
+ SkipUntil(tok::r_paren);
+ } else {
+ MatchRHSPunctuation(tok::r_paren, Loc);
+ }
return Result;
}
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 0fda782fcb..864b464d5f 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -211,7 +211,8 @@ private:
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
//
virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S);
- virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
+ virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
+ ExprTy *AsmLabel);
virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
virtual void ActOnParamDefaultArgument(DeclTy *param,
SourceLocation EqualLoc,
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index e9343e3989..64e62369e7 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -609,7 +609,7 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType) {
}
Sema::DeclTy *
-Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
+Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, ExprTy *AsmLabel) {
ScopedDecl *LastDeclarator = dyn_cast_or_null<ScopedDecl>((Decl *)lastDecl);
IdentifierInfo *II = D.getIdentifier();
@@ -700,6 +700,14 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
// Handle attributes.
ProcessDeclAttributes(NewFD, D);
+ // Handle GNU asm-label extension (encoded as an attribute).
+ if (Expr *E = (Expr*) AsmLabel) {
+ // The parser guarantees this is a string.
+ StringLiteral *SE = cast<StringLiteral>(E);
+ NewFD->addAttr(new AsmLabelAttr(std::string(SE->getStrData(),
+ SE->getByteLength())));
+ }
+
// Copy the parameter declarations from the declarator D to
// the function declaration NewFD, if they are available.
if (D.getNumTypeObjects() > 0 &&
@@ -1569,7 +1577,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
}
return ActOnStartOfFunctionDef(FnBodyScope,
- ActOnDeclarator(GlobalScope, D, 0));
+ ActOnDeclarator(GlobalScope, D, 0, 0));
}
Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
@@ -1661,7 +1669,7 @@ ScopedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
CurContext = Context.getTranslationUnitDecl();
FunctionDecl *FD =
- dyn_cast<FunctionDecl>(static_cast<Decl*>(ActOnDeclarator(TUScope, D, 0)));
+ dyn_cast<FunctionDecl>(static_cast<Decl*>(ActOnDeclarator(TUScope, D, 0, 0)));
FD->setImplicit();
CurContext = PrevDC;
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 9dc62dcc4a..d5603166d8 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -371,7 +371,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
if (isInstField)
Member = static_cast<Decl*>(ActOnField(S, Loc, D, BitWidth));
else
- Member = static_cast<Decl*>(ActOnDeclarator(S, D, LastInGroup));
+ Member = static_cast<Decl*>(ActOnDeclarator(S, D, LastInGroup, 0));
if (!Member) return LastInGroup;