[cfe-commits] r38649 - in /cfe/cfe/trunk: Lex/PPExpressions.cpp Lex/Pragma.cpp Lex/Preprocessor.cpp include/clang/Lex/MultipleIncludeOpt.h include/clang/Lex/Preprocessor.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:30 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:30 2007
New Revision: 38649
URL: http://llvm.org/viewvc/llvm-project?rev=38649&view=rev
Log:
Eliminate MultipleIncludeOpt::ReadDirective and all calls to it. Any directives
that are lexed are made up of tokens, so the calls are just ugly and redundant.
Hook up the MIOpt for the #if case. PPCExpressions doesn't currently implement
the hook though, so we still don't handle #if !defined(X) with the MIOpt.
Modified:
cfe/cfe/trunk/Lex/PPExpressions.cpp
cfe/cfe/trunk/Lex/Pragma.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Lex/MultipleIncludeOpt.h
cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/cfe/trunk/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/PPExpressions.cpp?rev=38649&r1=38648&r2=38649&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/PPExpressions.cpp (original)
+++ cfe/cfe/trunk/Lex/PPExpressions.cpp Wed Jul 11 11:23:30 2007
@@ -26,12 +26,10 @@
using namespace clang;
/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
-/// may occur after a #if or #elif directive. Sets Result to the result of
-/// the expression. Returns false normally, true if lexing must be aborted.
-///
-/// MinPrec is the minimum precedence that this range of the expression is
-/// allowed to include.
-bool Preprocessor::EvaluateDirectiveExpression() {
+/// may occur after a #if or #elif directive. If the
+/// expression is equivalent to "!defined(X)" return X in IfNDefMacro.
+bool Preprocessor::
+EvaluateDirectiveExpression(IdentifierTokenInfo *&IfNDefMacro) {
// Peek ahead one token.
LexerToken Tok;
Lex(Tok);
Modified: cfe/cfe/trunk/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Pragma.cpp?rev=38649&r1=38648&r2=38649&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Pragma.cpp (original)
+++ cfe/cfe/trunk/Lex/Pragma.cpp Wed Jul 11 11:23:30 2007
@@ -74,9 +74,6 @@
void Preprocessor::HandlePragmaDirective() {
++NumPragma;
- // Inform MIOpt that we found a side-effect of parsing this file.
- CurLexer->MIOpt.ReadDirective();
-
// Invoke the first level of pragma handlers which reads the namespace id.
LexerToken Tok;
PragmaHandlers->HandlePragma(*this, Tok);
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38649&r1=38648&r2=38649&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:30 2007
@@ -1020,7 +1020,8 @@
// looked up, etc, inside the #elif expression.
assert(SkippingContents && "We have to be skipping here!");
SkippingContents = false;
- ShouldEnter = EvaluateDirectiveExpression();
+ IdentifierTokenInfo *IfNDefMacro = 0;
+ ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro);
SkippingContents = true;
}
@@ -1077,14 +1078,13 @@
#if 0
case tok::numeric_constant:
- MIOpt.ReadDirective();
// FIXME: implement # 7 line numbers!
break;
#endif
case tok::kw_else:
return HandleElseDirective(Result);
case tok::kw_if:
- return HandleIfDirective(Result);
+ return HandleIfDirective(Result, ReadAnyTokensBeforeDirective);
case tok::identifier:
// Get the identifier name without trigraphs or embedded newlines.
const char *Directive = Result.getIdentifierInfo()->getName();
@@ -1092,7 +1092,7 @@
switch (Result.getIdentifierInfo()->getNameLength()) {
case 4:
if (Directive[0] == 'l' && !strcmp(Directive, "line"))
- CurLexer->MIOpt.ReadDirective(); // FIXME: implement #line
+ ; // FIXME: implement #line
if (Directive[0] == 'e' && !strcmp(Directive, "elif"))
return HandleElifDirective(Result);
if (Directive[0] == 's' && !strcmp(Directive, "sccs"))
@@ -1168,9 +1168,6 @@
/// HandleIdentSCCSDirective - Handle a #ident/#sccs directive.
///
void Preprocessor::HandleIdentSCCSDirective(LexerToken &Tok) {
- // Inform MIOpt that we found a side-effect of parsing this file.
- CurLexer->MIOpt.ReadDirective();
-
// Yes, this directive is an extension.
Diag(Tok, diag::ext_pp_ident_directive);
@@ -1202,9 +1199,6 @@
bool isImport) {
++NumIncluded;
- // Inform MIOpt that we found a side-effect of parsing this file.
- CurLexer->MIOpt.ReadDirective();
-
LexerToken FilenameTok;
std::string Filename = CurLexer->LexIncludeFilename(FilenameTok);
@@ -1310,9 +1304,6 @@
void Preprocessor::HandleDefineDirective(LexerToken &DefineTok) {
++NumDefined;
- // Inform MIOpt that we found a side-effect of parsing this file.
- CurLexer->MIOpt.ReadDirective();
-
LexerToken MacroNameTok;
ReadMacroName(MacroNameTok, true);
@@ -1383,9 +1374,6 @@
void Preprocessor::HandleUndefDirective(LexerToken &UndefTok) {
++NumUndefined;
- // Inform MIOpt that we found a side-effect of parsing this file.
- CurLexer->MIOpt.ReadDirective();
-
LexerToken MacroNameTok;
ReadMacroName(MacroNameTok, true);
@@ -1462,17 +1450,22 @@
/// HandleIfDirective - Implements the #if directive.
///
-void Preprocessor::HandleIfDirective(LexerToken &IfToken) {
+void Preprocessor::HandleIfDirective(LexerToken &IfToken,
+ bool ReadAnyTokensBeforeDirective) {
++NumIf;
- // FIXME: Detect "#if !defined(X)" for the MIOpt.
- CurLexer->MIOpt.ReadDirective();
-
// Parse and evaluation the conditional expression.
- bool ConditionalTrue = EvaluateDirectiveExpression();
+ IdentifierTokenInfo *IfNDefMacro = 0;
+ bool ConditionalTrue = EvaluateDirectiveExpression(IfNDefMacro);
// Should we include the stuff contained by this directive?
if (ConditionalTrue) {
+ // If this condition is equivalent to #ifndef X, and if this is the first
+ // directive seen, handle it for the multiple-include optimization.
+ if (!ReadAnyTokensBeforeDirective &&
+ CurLexer->getConditionalStackDepth() == 0 && IfNDefMacro)
+ CurLexer->MIOpt.EnterTopLevelIFNDEF(IfNDefMacro);
+
// Yes, remember that we are inside a conditional, then lex the next token.
CurLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
/*foundnonskip*/true, /*foundelse*/false);
Modified: cfe/cfe/trunk/include/clang/Lex/MultipleIncludeOpt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/MultipleIncludeOpt.h?rev=38649&r1=38648&r2=38649&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/MultipleIncludeOpt.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/MultipleIncludeOpt.h Wed Jul 11 11:23:30 2007
@@ -51,10 +51,8 @@
/// the "ifndef x" would count as reading tokens.
bool getHasReadAnyTokensVal() const { return ReadAnyTokens; }
- // If a token or directive is read, remember that we have seen a side-effect
- // in this file.
- void ReadToken() { ReadAnyTokens = true; }
- void ReadDirective() { ReadAnyTokens = true; }
+ // If a token is read, remember that we have seen a side-effect in this file.
+ void ReadToken() { ReadAnyTokens = true; }
/// EnterTopLevelIFNDEF - When entering a top-level #ifndef directive (or the
/// "#if !defined" equivalent) without any preceding tokens, this method is
Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38649&r1=38648&r2=38649&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:30 2007
@@ -429,9 +429,9 @@
bool FoundNonSkipPortion, bool FoundElse);
/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
- /// may occur after a #if or #elif directive. Sets Result to the result of
- /// the expression.
- bool EvaluateDirectiveExpression();
+ /// may occur after a #if or #elif directive and return it as a bool. If the
+ /// expression is equivalent to "!defined(X)" return X in IfNDefMacro.
+ bool EvaluateDirectiveExpression(IdentifierTokenInfo *&IfNDefMacro);
/// EvaluateValue/EvaluateDirectiveSubExpr - Used to implement
/// EvaluateDirectiveExpression, see PPExpressions.cpp.
bool EvaluateValue(int &Result, LexerToken &PeekTok);
@@ -489,7 +489,7 @@
// Conditional Inclusion.
void HandleIfdefDirective(LexerToken &Tok, bool isIfndef,
bool ReadAnyTokensBeforeDirective);
- void HandleIfDirective(LexerToken &Tok);
+ void HandleIfDirective(LexerToken &Tok, bool ReadAnyTokensBeforeDirective);
void HandleEndifDirective(LexerToken &Tok);
void HandleElseDirective(LexerToken &Tok);
void HandleElifDirective(LexerToken &Tok);
More information about the cfe-commits
mailing list