//===----------------------------------------------------------------------===//
#include "TGParser.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CommandLine.h"
if (AddValue(CurRec, SubMultiClass.RefRange.Start, SMCVals[i]))
return true;
- int newDefStart = CurMC->DefPrototypes.size();
+ unsigned newDefStart = CurMC->DefPrototypes.size();
// Add all of the defs in the subclass into the current multiclass.
for (MultiClass::RecordVector::const_iterator i = SMC->DefPrototypes.begin(),
// If a value is specified for this template arg, set it in the
// new defs now.
- for (MultiClass::RecordVector::iterator j =
- CurMC->DefPrototypes.begin() + newDefStart,
- jend = CurMC->DefPrototypes.end();
- j != jend;
- ++j) {
- Record *Def = j->get();
-
- if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i],
+ for (const auto &Def :
+ makeArrayRef(CurMC->DefPrototypes).slice(newDefStart)) {
+ if (SetValue(Def.get(), SubMultiClass.RefRange.Start, SMCTArgs[i],
std::vector<unsigned>(),
SubMultiClass.TemplateArgs[i]))
return true;
/// GetNewAnonymousName - Generate a unique anonymous name that can be used as
/// an identifier.
std::string TGParser::GetNewAnonymousName() {
- unsigned Tmp = AnonCounter++; // MSVC2012 ICEs without this.
- return "anonymous_" + utostr(Tmp);
+ return "anonymous_" + utostr(AnonCounter++);
}
/// ParseObjectName - If an object name is specified, return it. Otherwise,
return nullptr;
}
- auto it = MultiClasses.find(Lex.getCurStrVal());
- if (it == MultiClasses.end())
+ MultiClass *Result = MultiClasses[Lex.getCurStrVal()].get();
+ if (!Result)
TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
Lex.Lex();
- return &it->second;
+ return Result;
}
/// ParseSubClassReference - Parse a reference to a subclass or to a templated
SMLoc EndLoc = Lex.getLoc();
// Create the new record, set it as CurRec temporarily.
- auto NewRecOwner = make_unique<Record>(GetNewAnonymousName(), NameLoc,
- Records, /*IsAnonymous=*/true);
+ auto NewRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), NameLoc,
+ Records, /*IsAnonymous=*/true);
Record *NewRec = NewRecOwner.get(); // Keep a copy since we may release.
SubClassReference SCRef;
SCRef.RefRange = SMRange(NameLoc, EndLoc);
unsigned int ArgN = 0;
if (ArgsRec && !EltTy) {
const std::vector<Init *> &TArgs = ArgsRec->getTemplateArgs();
- if (!TArgs.size()) {
+ if (TArgs.empty()) {
TokError("template argument provided to non-template class");
return std::vector<Init*>();
}
if (Name)
CurRecOwner = make_unique<Record>(Name, DefLoc, Records);
else
- CurRecOwner = make_unique<Record>(GetNewAnonymousName(), DefLoc, Records,
- /*IsAnonymous=*/true);
+ CurRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), DefLoc,
+ Records, /*IsAnonymous=*/true);
Record *CurRec = CurRecOwner.get(); // Keep a copy since we may release.
if (!CurMultiClass && Loops.empty()) {
+ "' already defined");
} else {
// If this is the first reference to this class, create and add it.
- auto NewRec = make_unique<Record>(Lex.getCurStrVal(), Lex.getLoc(),
- Records);
+ auto NewRec =
+ llvm::make_unique<Record>(Lex.getCurStrVal(), Lex.getLoc(), Records);
CurRec = NewRec.get();
Records.addClass(std::move(NewRec));
}
auto Result =
MultiClasses.insert(std::make_pair(Name,
- MultiClass(Name, Lex.getLoc(),Records)));
+ llvm::make_unique<MultiClass>(Name, Lex.getLoc(),Records)));
+
if (!Result.second)
return TokError("multiclass '" + Name + "' already defined");
- CurMultiClass = &Result.first->second;
+ CurMultiClass = Result.first->second.get();
Lex.Lex(); // Eat the identifier.
// If there are template args, parse them.
// To instantiate a multiclass, we need to first get the multiclass, then
// instantiate each def contained in the multiclass with the SubClassRef
// template parameters.
- auto it = MultiClasses.find(Ref.Rec->getName());
- assert(it != MultiClasses.end() && "Didn't lookup multiclass correctly?");
- MultiClass *MC = &it->second;
+ MultiClass *MC = MultiClasses[Ref.Rec->getName()].get();
+ assert(MC && "Didn't lookup multiclass correctly?");
std::vector<Init*> &TemplateVals = Ref.TemplateArgs;
// Verify that the correct number of template arguments were specified.