[cfe-commits] r130289 - in /cfe/trunk: include/clang/AST/Stmt.h include/clang/Lex/Preprocessor.h include/clang/Sema/Sema.h lib/Lex/PPMacroExpansion.cpp lib/Parse/ParseStmt.cpp lib/Sema/SemaStmt.cpp lib/Serialization/ASTReaderStmt.cpp lib/Serialization/ASTWriterStmt.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Apr 26 22:04:02 PDT 2011
Author: akirtzidis
Date: Wed Apr 27 00:04:02 2011
New Revision: 130289
URL: http://llvm.org/viewvc/llvm-project?rev=130289&view=rev
Log:
If a null statement was preceded by an empty macro keep its instantiation source location
in NullStmt.
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Apr 27 00:04:02 2011
@@ -383,14 +383,15 @@
class NullStmt : public Stmt {
SourceLocation SemiLoc;
- /// \brief Whether the null statement was preceded by an empty macro, e.g:
+ /// \brief If the null statement was preceded by an empty macro this is
+ /// its instantiation source location, e.g:
/// @code
/// #define CALL(x)
/// CALL(0);
/// @endcode
- bool LeadingEmptyMacro;
+ SourceLocation LeadingEmptyMacro;
public:
- NullStmt(SourceLocation L, bool LeadingEmptyMacro = false)
+ NullStmt(SourceLocation L, SourceLocation LeadingEmptyMacro =SourceLocation())
: Stmt(NullStmtClass), SemiLoc(L), LeadingEmptyMacro(LeadingEmptyMacro) {}
/// \brief Build an empty null statement.
@@ -399,7 +400,8 @@
SourceLocation getSemiLoc() const { return SemiLoc; }
void setSemiLoc(SourceLocation L) { SemiLoc = L; }
- bool hasLeadingEmptyMacro() const { return LeadingEmptyMacro; }
+ bool hasLeadingEmptyMacro() const { return LeadingEmptyMacro.isValid(); }
+ SourceLocation getLeadingEmptyMacroLoc() const { return LeadingEmptyMacro; }
SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Apr 27 00:04:02 2011
@@ -218,6 +218,10 @@
/// previous macro value.
llvm::DenseMap<IdentifierInfo*, std::vector<MacroInfo*> > PragmaPushMacroInfo;
+ /// \brief Instantiation source location for the last macro that expanded
+ /// to no tokens.
+ SourceLocation LastEmptyMacroInstantiationLoc;
+
// Various statistics we track for performance analysis.
unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma;
unsigned NumIf, NumElse, NumEndif;
@@ -366,6 +370,12 @@
macro_iterator macro_begin(bool IncludeExternalMacros = true) const;
macro_iterator macro_end(bool IncludeExternalMacros = true) const;
+ /// \brief Instantiation source location for the last macro that expanded
+ /// to no tokens.
+ SourceLocation getLastEmptyMacroInstantiationLoc() const {
+ return LastEmptyMacroInstantiationLoc;
+ }
+
const std::string &getPredefines() const { return Predefines; }
/// setPredefines - Set the predefines for this Preprocessor. These
/// predefines are automatically injected when parsing the main file.
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Apr 27 00:04:02 2011
@@ -1882,7 +1882,7 @@
StmtResult ActOnExprStmt(FullExprArg Expr);
StmtResult ActOnNullStmt(SourceLocation SemiLoc,
- bool LeadingEmptyMacro = false);
+ SourceLocation LeadingEmptyMacroLoc = SourceLocation());
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
MultiStmtArg Elts,
bool isStmtExpr);
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Apr 27 00:04:02 2011
@@ -227,6 +227,9 @@
// If we started lexing a macro, enter the macro expansion body.
+ // Remember where the token is instantiated.
+ SourceLocation InstantiateLoc = Identifier.getLocation();
+
// If this macro expands to no tokens, don't bother to push it onto the
// expansion stack, only to take it right back off.
if (MI->getNumTokens() == 0) {
@@ -249,6 +252,7 @@
if (HadLeadingSpace) Identifier.setFlag(Token::LeadingSpace);
}
Identifier.setFlag(Token::LeadingEmptyMacro);
+ LastEmptyMacroInstantiationLoc = InstantiateLoc;
++NumFastMacroExpanded;
return false;
@@ -267,9 +271,6 @@
bool isAtStartOfLine = Identifier.isAtStartOfLine();
bool hasLeadingSpace = Identifier.hasLeadingSpace();
- // Remember where the token is instantiated.
- SourceLocation InstantiateLoc = Identifier.getLocation();
-
// Replace the result token.
Identifier = MI->getReplacementToken(0);
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Apr 27 00:04:02 2011
@@ -276,8 +276,10 @@
case tok::l_brace: // C99 6.8.2: compound-statement
return ParseCompoundStatement(attrs);
case tok::semi: { // C99 6.8.3p3: expression[opt] ';'
- bool LeadingEmptyMacro = Tok.hasLeadingEmptyMacro();
- return Actions.ActOnNullStmt(ConsumeToken(), LeadingEmptyMacro);
+ SourceLocation LeadingEmptyMacroLoc;
+ if (Tok.hasLeadingEmptyMacro())
+ LeadingEmptyMacroLoc = PP.getLastEmptyMacroInstantiationLoc();
+ return Actions.ActOnNullStmt(ConsumeToken(), LeadingEmptyMacroLoc);
}
case tok::kw_if: // C99 6.8.4.1: if-statement
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Apr 27 00:04:02 2011
@@ -46,8 +46,9 @@
}
-StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc, bool LeadingEmptyMacro) {
- return Owned(new (Context) NullStmt(SemiLoc, LeadingEmptyMacro));
+StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc,
+ SourceLocation LeadingEmptyMacroLoc) {
+ return Owned(new (Context) NullStmt(SemiLoc, LeadingEmptyMacroLoc));
}
StmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc,
Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Wed Apr 27 00:04:02 2011
@@ -211,7 +211,7 @@
void ASTStmtReader::VisitNullStmt(NullStmt *S) {
VisitStmt(S);
S->setSemiLoc(ReadSourceLocation(Record, Idx));
- S->LeadingEmptyMacro = Record[Idx++];
+ S->LeadingEmptyMacro = ReadSourceLocation(Record, Idx);
}
void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=130289&r1=130288&r2=130289&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Wed Apr 27 00:04:02 2011
@@ -180,7 +180,7 @@
void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
VisitStmt(S);
Writer.AddSourceLocation(S->getSemiLoc(), Record);
- Record.push_back(S->LeadingEmptyMacro);
+ Writer.AddSourceLocation(S->LeadingEmptyMacro, Record);
Code = serialization::STMT_NULL;
}
More information about the cfe-commits
mailing list