bool isPublic) {
return new (BP) VisibilityMacroDirective(Loc, isPublic);
}
-\r
-/// Read and discard all tokens remaining on the current line until\r
-/// the tok::eod token is found.\r
-SourceRange Preprocessor::DiscardUntilEndOfDirective() {\r
- Token Tmp;\r
- SourceRange Res;\r
-\r
- LexUnexpandedToken(Tmp);\r
- Res.setBegin(Tmp.getLocation());\r
- while (Tmp.isNot(tok::eod)) {\r
- assert(Tmp.isNot(tok::eof) && "EOF seen while discarding directive tokens");\r
- LexUnexpandedToken(Tmp);\r
- }\r
- Res.setEnd(Tmp.getLocation());\r
- return Res;\r
-}\r
-\r
-/// Enumerates possible cases of #define/#undef a reserved identifier.\r
+
+/// Read and discard all tokens remaining on the current line until
+/// the tok::eod token is found.
+SourceRange Preprocessor::DiscardUntilEndOfDirective() {
+ Token Tmp;
+ SourceRange Res;
+
+ LexUnexpandedToken(Tmp);
+ Res.setBegin(Tmp.getLocation());
+ while (Tmp.isNot(tok::eod)) {
+ assert(Tmp.isNot(tok::eof) && "EOF seen while discarding directive tokens");
+ LexUnexpandedToken(Tmp);
+ }
+ Res.setEnd(Tmp.getLocation());
+ return Res;
+}
+
+/// Enumerates possible cases of #define/#undef a reserved identifier.
enum MacroDiag {
MD_NoWarn, //> Not a reserved identifier
MD_KeywordDef, //> Macro hides keyword, enabled by default
// If this is in a skipping block or if we're already handled this #if
// block, don't bother parsing the condition.
- if (CondInfo.WasSkipping || CondInfo.FoundNonSkip) {\r
- DiscardUntilEndOfDirective();\r
- } else {\r
- // Restore the value of LexingRawMode so that identifiers are\r
- // looked up, etc, inside the #elif expression.\r
- assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");\r
- CurPPLexer->LexingRawMode = false;\r
- IdentifierInfo *IfNDefMacro = nullptr;\r
- DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);\r
- const bool CondValue = DER.Conditional;\r
- CurPPLexer->LexingRawMode = true;\r
- if (Callbacks) {\r
- Callbacks->Elif(\r
- Tok.getLocation(), DER.ExprRange,\r
- (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False),\r
- CondInfo.IfLoc);\r
- }\r
- // If this condition is true, enter it!\r
- if (CondValue) {\r
+ if (CondInfo.WasSkipping || CondInfo.FoundNonSkip) {
+ DiscardUntilEndOfDirective();
+ } else {
+ // Restore the value of LexingRawMode so that identifiers are
+ // looked up, etc, inside the #elif expression.
+ assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");
+ CurPPLexer->LexingRawMode = false;
+ IdentifierInfo *IfNDefMacro = nullptr;
+ DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
+ const bool CondValue = DER.Conditional;
+ CurPPLexer->LexingRawMode = true;
+ if (Callbacks) {
+ Callbacks->Elif(
+ Tok.getLocation(), DER.ExprRange,
+ (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False),
+ CondInfo.IfLoc);
+ }
+ // If this condition is true, enter it!
+ if (CondValue) {
CondInfo.FoundNonSkip = true;
break;
}
// If the StrTok is "eod", then it wasn't present. Otherwise, it must be a
// string followed by eod.
if (StrTok.is(tok::eod))
- ; // ok\r
- else if (StrTok.isNot(tok::string_literal)) {\r
- Diag(StrTok, diag::err_pp_line_invalid_filename);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- } else if (StrTok.hasUDSuffix()) {\r
- Diag(StrTok, diag::err_invalid_string_udl);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- } else {\r
- // Parse and validate the string, converting it into a unique ID.\r
- StringLiteralParser Literal(StrTok, *this);\r
- assert(Literal.isAscii() && "Didn't allow wide strings in");\r
- if (Literal.hadError) {\r
- DiscardUntilEndOfDirective();\r
- return;\r
- }\r
- if (Literal.Pascal) {\r
- Diag(StrTok, diag::err_pp_linemarker_invalid_filename);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- }\r
- FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());\r
-\r
+ ; // ok
+ else if (StrTok.isNot(tok::string_literal)) {
+ Diag(StrTok, diag::err_pp_line_invalid_filename);
+ DiscardUntilEndOfDirective();
+ return;
+ } else if (StrTok.hasUDSuffix()) {
+ Diag(StrTok, diag::err_invalid_string_udl);
+ DiscardUntilEndOfDirective();
+ return;
+ } else {
+ // Parse and validate the string, converting it into a unique ID.
+ StringLiteralParser Literal(StrTok, *this);
+ assert(Literal.isAscii() && "Didn't allow wide strings in");
+ if (Literal.hadError) {
+ DiscardUntilEndOfDirective();
+ return;
+ }
+ if (Literal.Pascal) {
+ Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
+ DiscardUntilEndOfDirective();
+ return;
+ }
+ FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());
+
// Verify that there is nothing after the string, other than EOD. Because
// of C99 6.10.4p5, macros that expand to empty tokens are ok.
CheckEndOfDirective("line", true);
// string followed by eod.
if (StrTok.is(tok::eod)) {
// Treat this like "#line NN", which doesn't change file characteristics.
- FileKind = SourceMgr.getFileCharacteristic(DigitTok.getLocation());\r
- } else if (StrTok.isNot(tok::string_literal)) {\r
- Diag(StrTok, diag::err_pp_linemarker_invalid_filename);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- } else if (StrTok.hasUDSuffix()) {\r
- Diag(StrTok, diag::err_invalid_string_udl);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- } else {\r
- // Parse and validate the string, converting it into a unique ID.\r
- StringLiteralParser Literal(StrTok, *this);\r
- assert(Literal.isAscii() && "Didn't allow wide strings in");\r
- if (Literal.hadError) {\r
- DiscardUntilEndOfDirective();\r
- return;\r
- }\r
- if (Literal.Pascal) {\r
- Diag(StrTok, diag::err_pp_linemarker_invalid_filename);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- }\r
- FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());\r
-\r
+ FileKind = SourceMgr.getFileCharacteristic(DigitTok.getLocation());
+ } else if (StrTok.isNot(tok::string_literal)) {
+ Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
+ DiscardUntilEndOfDirective();
+ return;
+ } else if (StrTok.hasUDSuffix()) {
+ Diag(StrTok, diag::err_invalid_string_udl);
+ DiscardUntilEndOfDirective();
+ return;
+ } else {
+ // Parse and validate the string, converting it into a unique ID.
+ StringLiteralParser Literal(StrTok, *this);
+ assert(Literal.isAscii() && "Didn't allow wide strings in");
+ if (Literal.hadError) {
+ DiscardUntilEndOfDirective();
+ return;
+ }
+ if (Literal.Pascal) {
+ Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
+ DiscardUntilEndOfDirective();
+ return;
+ }
+ FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());
+
// If a filename was present, read any flags that are present.
if (ReadLineMarkerFlags(IsFileEntry, IsFileExit, FileKind, *this))
return;
DiscardUntilEndOfDirective();
return;
}
-\r
- if (StrTok.hasUDSuffix()) {\r
- Diag(StrTok, diag::err_invalid_string_udl);\r
- DiscardUntilEndOfDirective();\r
- return;\r
- }\r
-\r
- // Verify that there is nothing after the string, other than EOD.\r
+
+ if (StrTok.hasUDSuffix()) {
+ Diag(StrTok, diag::err_invalid_string_udl);
+ DiscardUntilEndOfDirective();
+ return;
+ }
+
+ // Verify that there is nothing after the string, other than EOD.
CheckEndOfDirective("ident");
if (Callbacks) {
const Token &HashToken,
bool ReadAnyTokensBeforeDirective) {
++NumIf;
-\r
- // Parse and evaluate the conditional expression.\r
- IdentifierInfo *IfNDefMacro = nullptr;\r
- const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);\r
- const bool ConditionalTrue = DER.Conditional;\r
-\r
- // If this condition is equivalent to #ifndef X, and if this is the first\r
- // directive seen, handle it for the multiple-include optimization.\r
+
+ // Parse and evaluate the conditional expression.
+ IdentifierInfo *IfNDefMacro = nullptr;
+ const DirectiveEvalResult DER = EvaluateDirectiveExpression(IfNDefMacro);
+ const bool ConditionalTrue = DER.Conditional;
+
+ // If this condition is equivalent to #ifndef X, and if this is the first
+ // directive seen, handle it for the multiple-include optimization.
if (CurPPLexer->getConditionalStackDepth() == 0) {
if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
// FIXME: Pass in the location of the macro name, not the 'if' token.
CurPPLexer->MIOpt.EnterTopLevelIfndef(IfNDefMacro, IfToken.getLocation());
else
CurPPLexer->MIOpt.EnterTopLevelConditional();
- }\r
-\r
- if (Callbacks)\r
- Callbacks->If(\r
- IfToken.getLocation(), DER.ExprRange,\r
- (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));\r
-\r
- // Should we include the stuff contained by this directive?\r
- if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {\r
+ }
+
+ if (Callbacks)
+ Callbacks->If(
+ IfToken.getLocation(), DER.ExprRange,
+ (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
+
+ // Should we include the stuff contained by this directive?
+ if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
const Token &HashToken) {
++NumElse;
- // #elif directive in a non-skipping conditional... start skipping.\r
- // We don't care what the condition is, because we will always skip it (since\r
- // the block immediately before it was included).\r
- SourceRange ConditionRange = DiscardUntilEndOfDirective();\r
-\r
- PPConditionalInfo CI;\r
- if (CurPPLexer->popConditionalLevel(CI)) {\r
+ // #elif directive in a non-skipping conditional... start skipping.
+ // We don't care what the condition is, because we will always skip it (since
+ // the block immediately before it was included).
+ SourceRange ConditionRange = DiscardUntilEndOfDirective();
+
+ PPConditionalInfo CI;
+ if (CurPPLexer->popConditionalLevel(CI)) {
Diag(ElifToken, diag::pp_err_elif_without_if);
return;
}
CurPPLexer->MIOpt.EnterTopLevelConditional();
// If this is a #elif with a #else before it, report the error.
- if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else);\r
-\r
- if (Callbacks)\r
- Callbacks->Elif(ElifToken.getLocation(), ConditionRange,\r
- PPCallbacks::CVK_NotEvaluated, CI.IfLoc);\r
-\r
- if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) {\r
+ if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else);
+
+ if (Callbacks)
+ Callbacks->Elif(ElifToken.getLocation(), ConditionRange,
+ PPCallbacks::CVK_NotEvaluated, CI.IfLoc);
+
+ if (PPOpts->SingleFileParseMode && !CI.FoundNonSkip) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,