ParseValueList(Vals, CurRec);
if (Vals.empty()) return nullptr;
}
- if (Lex.getCode() != tgtok::r_brace) {
+ if (!consume(tgtok::r_brace)) {
TokError("expected '}' at end of bit list value");
return nullptr;
}
- Lex.Lex(); // eat the '}'
SmallVector<Init *, 16> NewBits;
if (!ParseDeclaration(CurRec, false))
return true;
- if (Lex.getCode() != tgtok::semi)
+ if (!consume(tgtok::semi))
return TokError("expected ';' after declaration");
- Lex.Lex();
return false;
}
return true;
std::reverse(BitList.begin(), BitList.end());
- if (Lex.getCode() != tgtok::equal)
+ if (!consume(tgtok::equal))
return TokError("expected '=' in let expression");
- Lex.Lex(); // eat the '='.
RecordVal *Field = CurRec->getValue(FieldName);
if (!Field)
Init *Val = ParseValue(CurRec, Type);
if (!Val) return true;
- if (Lex.getCode() != tgtok::semi)
+ if (!consume(tgtok::semi))
return TokError("expected ';' after let expression");
- Lex.Lex();
return SetValue(CurRec, IdLoc, FieldName, BitList, Val);
}
if (AddSubClass(CurRec, SubClass))
return true;
- if (Lex.getCode() != tgtok::comma) break;
- Lex.Lex(); // eat ','.
+ if (!consume(tgtok::comma))
+ break;
SubClass = ParseSubClassReference(CurRec, false);
}
}
if (Err)
return true;
- if (Lex.getCode() != tgtok::r_brace) {
+ if (!consume(tgtok::r_brace)) {
TokError("expected '}' at end of defset");
return Error(BraceLoc, "to match this '{'");
}
- Lex.Lex(); // Eat the '}'
Records.addExtraGlobal(DeclName->getValue(),
ListInit::get(Defset.Elements, Defset.EltTy));
return TokError("def or global variable of this name already exists");
}
- if (Lex.Lex() != tgtok::equal) // Eat the identifier
+ Lex.Lex();
+ if (!consume(tgtok::equal))
return TokError("expected '='");
- Lex.Lex(); // Eat the '='
Init *Value = ParseValue(nullptr);
if (!Value)
return true;
- if (Lex.getCode() != tgtok::semi)
+ if (!consume(tgtok::semi))
return TokError("expected ';'");
- Lex.Lex(); // Eat the ';'
if (CurLocalScope)
CurLocalScope->addVar(DeclName->getValue(), Value);
if (!IterName)
return TokError("expected declaration in for");
- if (Lex.getCode() != tgtok::In)
+ if (!consume(tgtok::In))
return TokError("Unknown tok");
- Lex.Lex(); // Eat the in
// Create a loop object and remember it.
Loops.push_back(std::make_unique<ForeachLoop>(Loc, IterName, ListValue));
if (ParseObjectList(CurMultiClass))
return true;
- if (Lex.getCode() != tgtok::r_brace) {
+ if (!consume(tgtok::r_brace)) {
TokError("expected '}' at end of foreach command");
return Error(BraceLoc, "to match this '{'");
}
- Lex.Lex(); // Eat the }
}
PopLocalScope(ForeachScope);
if (!Condition)
return true;
- if (Lex.getCode() != tgtok::Then)
+ if (!consume(tgtok::Then))
return TokError("Unknown tok");
- Lex.Lex(); // Eat the 'then'
// We have to be able to save if statements to execute later, and they have
// to live on the same stack as foreach loops. The simplest implementation
if (ParseObjectList(CurMultiClass))
return true;
- if (Lex.getCode() != tgtok::r_brace) {
+ if (!consume(tgtok::r_brace)) {
TokError("expected '}' at end of '" + Kind + "' clause");
return Error(BraceLoc, "to match this '{'");
}
-
- Lex.Lex(); // Eat the }
}
PopLocalScope(BodyScope);
/// LetItem ::= ID OptionalRangeList '=' Value
///
void TGParser::ParseLetList(SmallVectorImpl<LetRecord> &Result) {
- while (true) {
+ do {
if (Lex.getCode() != tgtok::Id) {
TokError("expected identifier in let definition");
Result.clear();
}
std::reverse(Bits.begin(), Bits.end());
- if (Lex.getCode() != tgtok::equal) {
+ if (!consume(tgtok::equal)) {
TokError("expected '=' in let expression");
Result.clear();
return;
}
- Lex.Lex(); // eat the '='.
Init *Val = ParseValue(nullptr);
if (!Val) {
// Now that we have everything, add the record.
Result.emplace_back(Name, Bits, Val, NameLoc);
-
- if (Lex.getCode() != tgtok::comma)
- return;
- Lex.Lex(); // eat the comma.
- }
+ } while (consume(tgtok::comma));
}
/// ParseTopLevelLet - Parse a 'let' at top level. This can be a couple of
if (LetInfo.empty()) return true;
LetStack.push_back(std::move(LetInfo));
- if (Lex.getCode() != tgtok::In)
+ if (!consume(tgtok::In))
return TokError("expected 'in' at end of top-level 'let'");
- Lex.Lex();
TGLocalVarScope *LetScope = PushLocalScope();
if (ParseObjectList(CurMultiClass))
return true;
- if (Lex.getCode() != tgtok::r_brace) {
+ if (!consume(tgtok::r_brace)) {
TokError("expected '}' at end of top level let command");
return Error(BraceLoc, "to match this '{'");
}
- Lex.Lex();
}
PopLocalScope(LetScope);