Remove random windows line endings that snuck into the middle of this

code.

llvm-svn: 351633
This commit is contained in:
Chandler Carruth 2019-01-19 06:36:00 +00:00
parent 79b37483c8
commit d92d70b7f0
1 changed files with 124 additions and 124 deletions

View File

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