diff options
| author | Ed Schouten <ed@FreeBSD.org> | 2009-06-06 08:21:31 +0000 |
|---|---|---|
| committer | Ed Schouten <ed@FreeBSD.org> | 2009-06-06 08:21:31 +0000 |
| commit | 37f6c480c696a4a72c1701ee54624cc807aa80ba (patch) | |
| tree | 06d57bb7679a2140aef96db7105a0bd5f16a4358 /lib/Parse | |
| parent | 2659aeb5e51fe27d24bbffad0d1851b39fed5e43 (diff) | |
Diffstat (limited to 'lib/Parse')
| -rw-r--r-- | lib/Parse/ParseObjc.cpp | 1 | ||||
| -rw-r--r-- | lib/Parse/ParsePragma.cpp | 57 | ||||
| -rw-r--r-- | lib/Parse/ParsePragma.h | 9 | ||||
| -rw-r--r-- | lib/Parse/ParseStmt.cpp | 8 | ||||
| -rw-r--r-- | lib/Parse/Parser.cpp | 6 |
5 files changed, 78 insertions, 3 deletions
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 3014f95a8482f..cb7fe58807af1 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -891,6 +891,7 @@ void Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, // Install the declarator into interfaceDecl. DeclPtrTy Field = Actions.ActOnIvar(CurScope, DS.getSourceRange().getBegin(), + interfaceDecl, FD.D, FD.BitfieldSize, visibility); AllIvarDecls.push_back(Field); } diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp index 94695e4d5694e..58c729aef29e6 100644 --- a/lib/Parse/ParsePragma.cpp +++ b/lib/Parse/ParsePragma.cpp @@ -100,6 +100,12 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP, Token &PackTok) { return; } + PP.Lex(Tok); + if (Tok.isNot(tok::eom)) { + PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack"; + return; + } + SourceLocation RParenLoc = Tok.getLocation(); Actions.ActOnPragmaPack(Kind, Name, Alignment.release(), PackLoc, LParenLoc, RParenLoc); @@ -172,7 +178,14 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) { PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_punc); return; } - + + PP.Lex(Tok); + if (Tok.isNot(tok::eom)) { + PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << + "unused"; + return; + } + // Verify that we have a location for the right parenthesis. assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'"); assert(!Ex.empty() && "Valid '#pragma unused' must have arguments"); @@ -180,3 +193,45 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) { // Perform the action to handle the pragma. Actions.ActOnPragmaUnused(&Ex[0], Ex.size(), UnusedLoc, LParenLoc, RParenLoc); } + +// #pragma weak identifier +// #pragma weak identifier '=' identifier +void PragmaWeakHandler::HandlePragma(Preprocessor &PP, Token &WeakTok) { + // FIXME: Should we be expanding macros here? My guess is no. + SourceLocation WeakLoc = WeakTok.getLocation(); + + Token Tok; + PP.Lex(Tok); + if (Tok.isNot(tok::identifier)) { + PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "weak"; + return; + } + + IdentifierInfo *WeakName = Tok.getIdentifierInfo(), *AliasName = 0; + SourceLocation WeakNameLoc = Tok.getLocation(), AliasNameLoc; + + PP.Lex(Tok); + if (Tok.is(tok::equal)) { + PP.Lex(Tok); + if (Tok.isNot(tok::identifier)) { + PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) + << "weak"; + return; + } + AliasName = Tok.getIdentifierInfo(); + AliasNameLoc = Tok.getLocation(); + PP.Lex(Tok); + } + + if (Tok.isNot(tok::eom)) { + PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "weak"; + return; + } + + if (AliasName) { + Actions.ActOnPragmaWeakAlias(WeakName, AliasName, WeakLoc, WeakNameLoc, + AliasNameLoc); + } else { + Actions.ActOnPragmaWeakID(WeakName, WeakLoc, WeakNameLoc); + } +} diff --git a/lib/Parse/ParsePragma.h b/lib/Parse/ParsePragma.h index 31b2a5f6851d5..39c86eea43b03 100644 --- a/lib/Parse/ParsePragma.h +++ b/lib/Parse/ParsePragma.h @@ -39,6 +39,15 @@ public: virtual void HandlePragma(Preprocessor &PP, Token &FirstToken); }; +class PragmaWeakHandler : public PragmaHandler { + Action &Actions; +public: + PragmaWeakHandler(const IdentifierInfo *N, Action &A) + : PragmaHandler(N), Actions(A) {} + + virtual void HandlePragma(Preprocessor &PP, Token &FirstToken); +}; + } // end namespace clang #endif diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 758b662a2392d..f041d7dfd7907 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -550,6 +550,8 @@ Parser::OwningStmtResult Parser::ParseIfStatement() { if (ParseParenExprOrCondition(CondExp)) return StmtError(); + FullExprArg FullCondExp(Actions.FullExpr(CondExp)); + // C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this // if the body isn't a compound statement to avoid push/pop in common cases. @@ -631,7 +633,7 @@ Parser::OwningStmtResult Parser::ParseIfStatement() { if (ElseStmt.isInvalid()) ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc); - return Actions.ActOnIfStmt(IfLoc, Actions.FullExpr(CondExp), move(ThenStmt), + return Actions.ActOnIfStmt(IfLoc, FullCondExp, move(ThenStmt), ElseLoc, move(ElseStmt)); } @@ -752,6 +754,8 @@ Parser::OwningStmtResult Parser::ParseWhileStatement() { if (ParseParenExprOrCondition(Cond)) return StmtError(); + FullExprArg FullCond(Actions.FullExpr(Cond)); + // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this // if the body isn't a compound statement to avoid push/pop in common cases. @@ -776,7 +780,7 @@ Parser::OwningStmtResult Parser::ParseWhileStatement() { if (Cond.isInvalid() || Body.isInvalid()) return StmtError(); - return Actions.ActOnWhileStmt(WhileLoc, Actions.FullExpr(Cond), move(Body)); + return Actions.ActOnWhileStmt(WhileLoc, FullCond, move(Body)); } /// ParseDoStatement diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 1c2e8a62e1f9d..a2a66f9255ded 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -39,6 +39,10 @@ Parser::Parser(Preprocessor &pp, Action &actions) PragmaUnusedHandler(&PP.getIdentifierTable().get("unused"), actions, *this)); PP.AddPragmaHandler(0, UnusedHandler.get()); + + WeakHandler.reset(new + PragmaWeakHandler(&PP.getIdentifierTable().get("weak"), actions)); + PP.AddPragmaHandler(0, WeakHandler.get()); } /// If a crash happens while the parser is active, print out a line indicating @@ -288,6 +292,8 @@ Parser::~Parser() { PackHandler.reset(); PP.RemovePragmaHandler(0, UnusedHandler.get()); UnusedHandler.reset(); + PP.RemovePragmaHandler(0, WeakHandler.get()); + WeakHandler.reset(); } /// Initialize - Warm up the parser. |
