diff options
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r-- | llvm/lib/TableGen/TGLexer.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGLexer.h | 5 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.h | 4 |
4 files changed, 44 insertions, 47 deletions
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp index eee4251..e23aec6 100644 --- a/llvm/lib/TableGen/TGLexer.cpp +++ b/llvm/lib/TableGen/TGLexer.cpp @@ -81,8 +81,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) { TokStart = nullptr; // Pretend that we enter the "top-level" include file. - PrepIncludeStack.push_back( - std::make_unique<std::vector<PreprocessorControlDesc>>()); + PrepIncludeStack.emplace_back(); // Add all macros defined on the command line to the DefinedMacros set. // Check invalid macro names and print fatal error if we find one. @@ -453,8 +452,7 @@ bool TGLexer::LexInclude() { CurBuf = SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer(); CurPtr = CurBuf.begin(); - PrepIncludeStack.push_back( - std::make_unique<std::vector<PreprocessorControlDesc>>()); + PrepIncludeStack.emplace_back(); return false; } @@ -656,17 +654,13 @@ tgtok::TokKind TGLexer::LexExclaim() { bool TGLexer::prepExitInclude(bool IncludeStackMustBeEmpty) { // Report an error, if preprocessor control stack for the current // file is not empty. - if (!PrepIncludeStack.back()->empty()) { + if (!PrepIncludeStack.back().empty()) { prepReportPreprocessorStackError(); return false; } // Pop the preprocessing controls from the include stack. - if (PrepIncludeStack.empty()) { - PrintFatalError("preprocessor include stack is empty"); - } - PrepIncludeStack.pop_back(); if (IncludeStackMustBeEmpty) { @@ -761,7 +755,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind, // Regardless of whether we are processing tokens or not, // we put the #ifdef control on stack. // Note that MacroIsDefined has been canonicalized against ifdef. - PrepIncludeStack.back()->push_back( + PrepIncludeStack.back().push_back( {tgtok::Ifdef, MacroIsDefined, SMLoc::getFromPointer(TokStart)}); if (!prepSkipDirectiveEnd()) @@ -789,10 +783,10 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind, } else if (Kind == tgtok::Else) { // Check if this #else is correct before calling prepSkipDirectiveEnd(), // which will move CurPtr away from the beginning of #else. - if (PrepIncludeStack.back()->empty()) + if (PrepIncludeStack.back().empty()) return ReturnError(TokStart, "#else without #ifdef or #ifndef"); - PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back()->back(); + PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back().back(); if (IfdefEntry.Kind != tgtok::Ifdef) { PrintError(TokStart, "double #else"); @@ -801,9 +795,8 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind, // Replace the corresponding #ifdef's control with its negation // on the control stack. - PrepIncludeStack.back()->pop_back(); - PrepIncludeStack.back()->push_back( - {Kind, !IfdefEntry.IsDefined, SMLoc::getFromPointer(TokStart)}); + PrepIncludeStack.back().back() = {Kind, !IfdefEntry.IsDefined, + SMLoc::getFromPointer(TokStart)}; if (!prepSkipDirectiveEnd()) return ReturnError(CurPtr, "only comments are supported after #else"); @@ -822,10 +815,10 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind, } else if (Kind == tgtok::Endif) { // Check if this #endif is correct before calling prepSkipDirectiveEnd(), // which will move CurPtr away from the beginning of #endif. - if (PrepIncludeStack.back()->empty()) + if (PrepIncludeStack.back().empty()) return ReturnError(TokStart, "#endif without #ifdef"); - auto &IfdefOrElseEntry = PrepIncludeStack.back()->back(); + auto &IfdefOrElseEntry = PrepIncludeStack.back().back(); if (IfdefOrElseEntry.Kind != tgtok::Ifdef && IfdefOrElseEntry.Kind != tgtok::Else) { @@ -836,7 +829,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(tgtok::TokKind Kind, if (!prepSkipDirectiveEnd()) return ReturnError(CurPtr, "only comments are supported after #endif"); - PrepIncludeStack.back()->pop_back(); + PrepIncludeStack.back().pop_back(); // If we were processing tokens before this #endif, then // we should continue it. @@ -1055,20 +1048,16 @@ bool TGLexer::prepSkipDirectiveEnd() { } bool TGLexer::prepIsProcessingEnabled() { - for (const PreprocessorControlDesc &I : - llvm::reverse(*PrepIncludeStack.back())) - if (!I.IsDefined) - return false; - - return true; + return all_of(PrepIncludeStack.back(), + [](const PreprocessorControlDesc &I) { return I.IsDefined; }); } void TGLexer::prepReportPreprocessorStackError() { - if (PrepIncludeStack.back()->empty()) + if (PrepIncludeStack.back().empty()) PrintFatalError("prepReportPreprocessorStackError() called with " "empty control stack"); - auto &PrepControl = PrepIncludeStack.back()->back(); + auto &PrepControl = PrepIncludeStack.back().back(); PrintError(CurBuf.end(), "reached EOF without matching #endif"); PrintError(PrepControl.SrcPos, "the latest preprocessor control is here"); diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h index 963d75e..f8b32dc 100644 --- a/llvm/lib/TableGen/TGLexer.h +++ b/llvm/lib/TableGen/TGLexer.h @@ -13,6 +13,7 @@ #ifndef LLVM_LIB_TABLEGEN_TGLEXER_H #define LLVM_LIB_TABLEGEN_TGLEXER_H +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/DataTypes.h" @@ -21,7 +22,6 @@ #include <memory> #include <set> #include <string> -#include <vector> namespace llvm { template <typename T> class ArrayRef; @@ -323,8 +323,7 @@ private: // preprocessing control stacks for the current file and all its // parent files. The back() element is the preprocessing control // stack for the current file. - std::vector<std::unique_ptr<std::vector<PreprocessorControlDesc>>> - PrepIncludeStack; + SmallVector<SmallVector<PreprocessorControlDesc>> PrepIncludeStack; // Validate that the current preprocessing control stack is empty, // since we are about to exit a file, and pop the include stack. diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index e867943..60ae11b 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -776,13 +776,14 @@ ParseSubClassReference(Record *CurRec, bool isDefm) { return Result; } - if (ParseTemplateArgValueList(Result.TemplateArgs, CurRec, Result.Rec)) { + SmallVector<SMLoc> ArgLocs; + if (ParseTemplateArgValueList(Result.TemplateArgs, ArgLocs, CurRec, + Result.Rec)) { Result.Rec = nullptr; // Error parsing value list. return Result; } - if (CheckTemplateArgValues(Result.TemplateArgs, Result.RefRange.Start, - Result.Rec)) { + if (CheckTemplateArgValues(Result.TemplateArgs, ArgLocs, Result.Rec)) { Result.Rec = nullptr; // Error checking value list. return Result; } @@ -812,7 +813,8 @@ ParseSubMultiClassReference(MultiClass *CurMC) { return Result; } - if (ParseTemplateArgValueList(Result.TemplateArgs, &CurMC->Rec, + SmallVector<SMLoc> ArgLocs; + if (ParseTemplateArgValueList(Result.TemplateArgs, ArgLocs, &CurMC->Rec, &Result.MC->Rec)) { Result.MC = nullptr; // Error parsing value list. return Result; @@ -2722,11 +2724,12 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, } SmallVector<const ArgumentInit *, 8> Args; + SmallVector<SMLoc> ArgLocs; Lex.Lex(); // consume the < - if (ParseTemplateArgValueList(Args, CurRec, Class)) + if (ParseTemplateArgValueList(Args, ArgLocs, CurRec, Class)) return nullptr; // Error parsing value list. - if (CheckTemplateArgValues(Args, NameLoc.Start, Class)) + if (CheckTemplateArgValues(Args, ArgLocs, Class)) return nullptr; // Error checking template argument values. if (resolveArguments(Class, Args, NameLoc.Start)) @@ -3201,8 +3204,8 @@ void TGParser::ParseValueList(SmallVectorImpl<const Init *> &Result, // PostionalArgValueList ::= [Value {',' Value}*] // NamedArgValueList ::= [NameValue '=' Value {',' NameValue '=' Value}*] bool TGParser::ParseTemplateArgValueList( - SmallVectorImpl<const ArgumentInit *> &Result, Record *CurRec, - const Record *ArgsRec) { + SmallVectorImpl<const ArgumentInit *> &Result, + SmallVectorImpl<SMLoc> &ArgLocs, Record *CurRec, const Record *ArgsRec) { assert(Result.empty() && "Result vector is not empty"); ArrayRef<const Init *> TArgs = ArgsRec->getTemplateArgs(); @@ -3217,7 +3220,7 @@ bool TGParser::ParseTemplateArgValueList( return true; } - SMLoc ValueLoc = Lex.getLoc(); + SMLoc ValueLoc = ArgLocs.emplace_back(Lex.getLoc()); // If we are parsing named argument, we don't need to know the argument name // and argument type will be resolved after we know the name. const Init *Value = ParseValue( @@ -4417,11 +4420,15 @@ bool TGParser::ParseFile() { // If necessary, replace an argument with a cast to the required type. // The argument count has already been checked. bool TGParser::CheckTemplateArgValues( - SmallVectorImpl<const ArgumentInit *> &Values, SMLoc Loc, + SmallVectorImpl<const ArgumentInit *> &Values, ArrayRef<SMLoc> ValuesLocs, const Record *ArgsRec) { + assert(Values.size() == ValuesLocs.size() && + "expected as many values as locations"); + ArrayRef<const Init *> TArgs = ArgsRec->getTemplateArgs(); - for (const ArgumentInit *&Value : Values) { + bool HasError = false; + for (auto [Value, Loc] : llvm::zip_equal(Values, ValuesLocs)) { const Init *ArgName = nullptr; if (Value->isPositional()) ArgName = TArgs[Value->getIndex()]; @@ -4439,16 +4446,16 @@ bool TGParser::CheckTemplateArgValues( "result of template arg value cast has wrong type"); Value = Value->cloneWithValue(CastValue); } else { - PrintFatalError(Loc, "Value specified for template argument '" + - Arg->getNameInitAsString() + "' is of type " + - ArgValue->getType()->getAsString() + - "; expected type " + ArgType->getAsString() + - ": " + ArgValue->getAsString()); + HasError |= Error( + Loc, "Value specified for template argument '" + + Arg->getNameInitAsString() + "' is of type " + + ArgValue->getType()->getAsString() + "; expected type " + + ArgType->getAsString() + ": " + ArgValue->getAsString()); } } } - return false; + return HasError; } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h index cac1ba8..4509893 100644 --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/lib/TableGen/TGParser.h @@ -296,6 +296,7 @@ private: // Parser methods. void ParseValueList(SmallVectorImpl<const Init *> &Result, Record *CurRec, const RecTy *ItemType = nullptr); bool ParseTemplateArgValueList(SmallVectorImpl<const ArgumentInit *> &Result, + SmallVectorImpl<SMLoc> &ArgLocs, Record *CurRec, const Record *ArgsRec); void ParseDagArgList( SmallVectorImpl<std::pair<const Init *, const StringInit *>> &Result, @@ -321,7 +322,8 @@ private: // Parser methods. bool ApplyLetStack(Record *CurRec); bool ApplyLetStack(RecordsEntry &Entry); bool CheckTemplateArgValues(SmallVectorImpl<const ArgumentInit *> &Values, - SMLoc Loc, const Record *ArgsRec); + ArrayRef<SMLoc> ValuesLocs, + const Record *ArgsRec); }; } // end namespace llvm |