void UnwrappedLineParser::parsePPDirective() { assert(FormatTok->Tok.is(tok::hash) && "'#' expected"); ScopedMacroState MacroState(*Line, Tokens, FormatTok, StructuralError); nextToken(); if (!FormatTok->Tok.getIdentifierInfo()) { parsePPUnknown(); return; } switch (FormatTok->Tok.getIdentifierInfo()->getPPKeywordID()) { case tok::pp_define: parsePPDefine(); return; case tok::pp_if: parsePPIf(/*IfDef=*/false); break; case tok::pp_ifdef: case tok::pp_ifndef: parsePPIf(/*IfDef=*/true); break; case tok::pp_else: parsePPElse(); break; case tok::pp_elif: parsePPElIf(); break; case tok::pp_endif: parsePPEndIf(); break; default: parsePPUnknown(); break; } }
void UnwrappedLineParser::parsePPIf(bool IfDef) { nextToken(); bool IsLiteralFalse = (FormatTok->Tok.isLiteral() && StringRef(FormatTok->Tok.getLiteralData(), FormatTok->Tok.getLength()) == "0") || FormatTok->Tok.is(tok::kw_false); conditionalCompilationStart(!IfDef && IsLiteralFalse); parsePPUnknown(); }
void UnwrappedLineParser::parsePPIf() { nextToken(); if ((FormatTok->Tok.isLiteral() && StringRef(FormatTok->Tok.getLiteralData(), FormatTok->Tok.getLength()) == "0") || FormatTok->Tok.is(tok::kw_false)) { PPStack.push_back(PP_Unreachable); } else { pushPPConditional(); } parsePPUnknown(); }
void UnwrappedLineParser::parsePPEndIf() { assert(PPBranchLevel < (int)PPLevelBranchIndex.size()); if (PPBranchLevel >= 0 && !PPChainBranchIndex.empty()) { if (PPChainBranchIndex.top() + 1 > PPLevelBranchCount[PPBranchLevel]) { PPLevelBranchCount[PPBranchLevel] = PPChainBranchIndex.top() + 1; } } --PPBranchLevel; if (!PPChainBranchIndex.empty()) PPChainBranchIndex.pop(); if (!PPStack.empty()) PPStack.pop_back(); parsePPUnknown(); }
void UnwrappedLineParser::parsePPElse() { if (!PPStack.empty()) PPStack.pop_back(); assert(PPBranchLevel < (int)PPLevelBranchIndex.size()); if (!PPChainBranchIndex.empty()) ++PPChainBranchIndex.top(); if (PPBranchLevel >= 0 && !PPChainBranchIndex.empty() && PPLevelBranchIndex[PPBranchLevel] != PPChainBranchIndex.top()) { PPStack.push_back(PP_Unreachable); } else { pushPPConditional(); } parsePPUnknown(); }
void UnwrappedLineParser::parsePPDefine() { nextToken(); if (FormatTok.Tok.getKind() != tok::identifier) { parsePPUnknown(); return; } nextToken(); if (FormatTok.Tok.getKind() == tok::l_paren) { parseParens(); } addUnwrappedLine(); Line.Level = 1; parseFile(); }
void UnwrappedLineParser::parsePPDirective() { assert(FormatTok.Tok.is(tok::hash) && "'#' expected"); ScopedMacroState MacroState(Line, Tokens, FormatTok); nextToken(); if (FormatTok.Tok.getIdentifierInfo() == NULL) { addUnwrappedLine(); return; } switch (FormatTok.Tok.getIdentifierInfo()->getPPKeywordID()) { case tok::pp_define: parsePPDefine(); break; default: parsePPUnknown(); break; } }
void UnwrappedLineParser::parsePPIf(bool IfDef) { ++PPBranchLevel; assert(PPBranchLevel >= 0 && PPBranchLevel <= (int)PPLevelBranchIndex.size()); if (PPBranchLevel == (int)PPLevelBranchIndex.size()) { PPLevelBranchIndex.push_back(0); PPLevelBranchCount.push_back(0); } PPChainBranchIndex.push(0); nextToken(); bool IsLiteralFalse = (FormatTok->Tok.isLiteral() && StringRef(FormatTok->Tok.getLiteralData(), FormatTok->Tok.getLength()) == "0") || FormatTok->Tok.is(tok::kw_false); if ((!IfDef && IsLiteralFalse) || PPLevelBranchIndex[PPBranchLevel] > 0) { PPStack.push_back(PP_Unreachable); } else { pushPPConditional(); } parsePPUnknown(); }
void UnwrappedLineParser::parsePPDefine() { nextToken(); if (FormatTok->Tok.getKind() != tok::identifier) { parsePPUnknown(); return; } nextToken(); if (FormatTok->Tok.getKind() == tok::l_paren && FormatTok->WhitespaceRange.getBegin() == FormatTok->WhitespaceRange.getEnd()) { parseParens(); } addUnwrappedLine(); Line->Level = 1; // Errors during a preprocessor directive can only affect the layout of the // preprocessor directive, and thus we ignore them. An alternative approach // would be to use the same approach we use on the file level (no // re-indentation if there was a structural error) within the macro // definition. parseFile(); }
void UnwrappedLineParser::parsePPEndIf() { conditionalCompilationEnd(); parsePPUnknown(); }
void UnwrappedLineParser::parsePPElse() { conditionalCompilationAlternative(); parsePPUnknown(); }
void UnwrappedLineParser::parsePPEndIf() { if (!PPStack.empty()) PPStack.pop_back(); parsePPUnknown(); }
void UnwrappedLineParser::parsePPElse() { if (!PPStack.empty()) PPStack.pop_back(); pushPPConditional(); parsePPUnknown(); }
void UnwrappedLineParser::parsePPIfdef() { pushPPConditional(); parsePPUnknown(); }