Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup -- remove unnecessary default args to constructors #458

Merged
merged 2 commits into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions backends/bmv2/jsonconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ArithmeticFixup : public Transform {
const IR::Expression* fix(const IR::Expression* expr, const IR::Type_Bits* type) {
unsigned width = type->size;
if (!type->isSigned) {
auto mask = new IR::Constant(Util::SourceInfo(), type, Util::mask(width), 16);
auto mask = new IR::Constant(type, Util::mask(width), 16);
typeMap->setType(mask, type);
auto result = new IR::BAnd(expr->srcInfo, expr, mask);
typeMap->setType(result, type);
Expand Down Expand Up @@ -817,12 +817,12 @@ cstring JsonConverter::createCalculation(cstring algo, const IR::Expression* fie
auto type = typeMap->getType(fields, true);
BUG_CHECK(type->is<IR::Type_StructLike>(), "%1%: expected a struct", fields);
for (auto f : *type->to<IR::Type_StructLike>()->fields) {
auto e = new IR::Member(Util::SourceInfo(), fields, f->name);
auto e = new IR::Member(fields, f->name);
auto ftype = typeMap->getType(f);
typeMap->setType(e, ftype);
vec->push_back(e);
}
fields = new IR::ListExpression(Util::SourceInfo(), vec);
fields = new IR::ListExpression(vec);
typeMap->setType(fields, type);
}
auto jright = conv->convert(fields);
Expand Down Expand Up @@ -982,8 +982,7 @@ JsonConverter::convertActionBody(const IR::Vector<IR::StatOrDecl>* body,
if (ef->method->name == v1model.clone.name) {
BUG_CHECK(mc->arguments->size() == 2, "Expected 2 arguments for %1%", mc);
cstring name = refMap->newName("fl");
auto emptylist = new IR::ListExpression(
Util::SourceInfo(), new IR::Vector<IR::Expression>());
auto emptylist = new IR::ListExpression(new IR::Vector<IR::Expression>());
id = createFieldList(emptylist, "field_lists", name, fieldLists);
} else {
BUG_CHECK(mc->arguments->size() == 3, "Expected 3 arguments for %1%", mc);
Expand Down Expand Up @@ -1129,7 +1128,7 @@ void JsonConverter::addToFieldList(const IR::Expression* expr, Util::JsonArray*
// recursively add all fields
auto st = type->to<IR::Type_StructLike>();
for (auto f : *st->fields) {
auto member = new IR::Member(Util::SourceInfo(), expr, f->name);
auto member = new IR::Member(expr, f->name);
typeMap->setType(member, typeMap->getType(f, true));
addToFieldList(member, fl);
}
Expand Down Expand Up @@ -2695,7 +2694,7 @@ Util::IJson* JsonConverter::convertParserStatement(const IR::StatOrDecl* stat) {
} else if (minst->is<P4::BuiltInMethod>()) {
auto bi = minst->to<P4::BuiltInMethod>();
if (bi->name == IR::Type_Header::setValid || bi->name == IR::Type_Header::setInvalid) {
auto mem = new IR::Member(Util::SourceInfo(), bi->appliedTo, "$valid$");
auto mem = new IR::Member(bi->appliedTo, "$valid$");
typeMap->setType(mem, IR::Type_Void::get());
auto jexpr = conv->convert(mem, true, false);
result->emplace("op", "set");
Expand Down
8 changes: 3 additions & 5 deletions backends/bmv2/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,10 @@ const IR::PathExpression*
RemoveComplexExpressions::createTemporary(const IR::Expression* expression) {
auto type = typeMap->getType(expression, true);
auto name = refMap->newName("tmp");
auto decl = new IR::Declaration_Variable(Util::SourceInfo(), IR::ID(name),
IR::Annotations::empty, type->getP4Type(), nullptr);
auto decl = new IR::Declaration_Variable(IR::ID(name), type->getP4Type());
newDecls.push_back(decl);
typeMap->setType(decl, type);
auto assign = new IR::AssignmentStatement(
Util::SourceInfo(), new IR::PathExpression(name), expression);
auto assign = new IR::AssignmentStatement(new IR::PathExpression(name), expression);
assignments.push_back(assign);
return new IR::PathExpression(name);
}
Expand Down Expand Up @@ -488,7 +486,7 @@ RemoveComplexExpressions::postorder(IR::Statement* statement) {
return statement;
auto vec = new IR::IndexedVector<IR::StatOrDecl>(assignments);
vec->push_back(statement);
auto block = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, vec);
auto block = new IR::BlockStatement(vec);
assignments.clear();
return block;
}
Expand Down
2 changes: 1 addition & 1 deletion backends/ebpf/ebpfType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ EBPFType* EBPFTypeFactory::create(const IR::Type* type) {
auto canon = typeMap->getTypeType(type, true);
result = create(canon);
auto path = new IR::Path(type->to<IR::Type_Typedef>()->name);
result = new EBPFTypeName(new IR::Type_Name(Util::SourceInfo(), path), result);
result = new EBPFTypeName(new IR::Type_Name(path), result);
} else if (type->is<IR::Type_Name>()) {
auto canon = typeMap->getTypeType(type, true);
result = create(canon);
Expand Down
5 changes: 2 additions & 3 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ const IR::Node* DoConstantFolding::postorder(IR::Concat* e) {
return e;
}

auto resultType = IR::Type_Bits::get(Util::SourceInfo(), lt->size + rt->size, lt->isSigned);
auto resultType = IR::Type_Bits::get(lt->size + rt->size, lt->isSigned);
mpz_class value = Util::shift_left(left->value, static_cast<unsigned>(rt->size)) + right->value;
auto result = new IR::Constant(e->srcInfo, resultType, value, left->base);
setConstant(e, result);
Expand Down Expand Up @@ -785,8 +785,7 @@ const IR::Node* DoConstantFolding::postorder(IR::SelectExpression* expression) {
changes = true;
finished = true;
if (someUnknown) {
auto newc = new IR::SelectCase(
c->srcInfo, new IR::DefaultExpression(Util::SourceInfo()), c->state);
auto newc = new IR::SelectCase(c->srcInfo, new IR::DefaultExpression(), c->state);
cases.push_back(newc);
} else {
// This is the result.
Expand Down
2 changes: 1 addition & 1 deletion frontends/p4-14/p4-14-parse.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ table_body: /* epsilon */ { $$ = new IR::V1Table(getPragmas()); }
$$->default_action_args = $6; }
| table_body IDENTIFIER ':' expression ';'
{ auto exp = new IR::ExpressionValue(@4, $4);
auto prop = new IR::Property(@2, IR::ID(@2, $2), IR::Annotations::empty, exp, false);
auto prop = new IR::Property(@2, IR::ID(@2, $2), exp, false);
$1->addProperty(prop);
$$ = $1; }
| table_body error ';' { $$=$1; }
Expand Down
8 changes: 2 additions & 6 deletions frontends/p4/createBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ limitations under the License.
namespace P4 {
void CreateBuiltins::postorder(IR::P4Parser* parser) {
auto newStates = new IR::IndexedVector<IR::ParserState>(*parser->states);
IR::ParserState* ac = new IR::ParserState(Util::SourceInfo(),
IR::ParserState::accept,
IR::Annotations::empty,
IR::ParserState* ac = new IR::ParserState(IR::ParserState::accept,
new IR::IndexedVector<IR::StatOrDecl>(),
nullptr);
IR::ParserState* rj = new IR::ParserState(Util::SourceInfo(),
IR::ParserState::reject,
IR::Annotations::empty,
IR::ParserState* rj = new IR::ParserState(IR::ParserState::reject,
new IR::IndexedVector<IR::StatOrDecl>(),
nullptr);
newStates->push_back(ac);
Expand Down
35 changes: 14 additions & 21 deletions frontends/p4/fromv1.0/converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ const IR::Node* ExpressionConverter::postorder(IR::Mask* expression) {
return exp;
if (value != range.value)
return new IR::BAnd(expression->srcInfo, exp, cst);
return new IR::Slice(Util::SourceInfo(), exp,
new IR::Constant(range.highIndex), new IR::Constant(range.lowIndex));
return new IR::Slice(exp, new IR::Constant(range.highIndex), new IR::Constant(range.lowIndex));
}

const IR::Node* ExpressionConverter::postorder(IR::Constant* expression) {
Expand Down Expand Up @@ -95,13 +94,11 @@ const IR::Node* ExpressionConverter::postorder(IR::Primitive* primitive) {
}

const IR::Expression* method = new IR::Member(
Util::SourceInfo(),
structure->paramReference(structure->parserPacketIn),
P4::P4CoreLibrary::instance.packetIn.lookahead.Id());
auto typeargs = new IR::Vector<IR::Type>();
typeargs->push_back(IR::Type_Bits::get(aval + bval));
auto lookahead = new IR::MethodCallExpression(
Util::SourceInfo(), method, typeargs, new IR::Vector<IR::Expression>());
auto lookahead = new IR::MethodCallExpression(method, typeargs);
auto result = new IR::Slice(primitive->srcInfo, lookahead,
new IR::Constant(bval - 1),
new IR::Constant(0));
Expand All @@ -112,7 +109,7 @@ const IR::Node* ExpressionConverter::postorder(IR::Primitive* primitive) {
auto base = primitive->operands.at(0);
auto method = new IR::Member(primitive->srcInfo, base, IR::ID(IR::Type_Header::isValid));
auto result = new IR::MethodCallExpression(primitive->srcInfo, IR::Type::Boolean::get(),
method, new IR::Vector<IR::Type>(), new IR::Vector<IR::Expression>());
method);
return result;
}
BUG("Unexpected primitive %1%", primitive);
Expand Down Expand Up @@ -145,7 +142,7 @@ const IR::Node* ExpressionConverter::postorder(IR::ConcreteHeaderRef* nhr) {
else
ref = structure->conversionContext.userMetadata->clone();
}
auto result = new IR::Member(Util::SourceInfo(), ref, nhr->ref->name);
auto result = new IR::Member(ref, nhr->ref->name);
result->type = nhr->type;
return result;
}
Expand Down Expand Up @@ -178,11 +175,8 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) {
auto table = structure->tables.get(apply->name);
auto newname = structure->tables.get(table);
auto tbl = new IR::PathExpression(newname);
auto method = new IR::Member(Util::SourceInfo(), tbl,
IR::ID(IR::IApply::applyMethodName));
auto call = new IR::MethodCallExpression(apply->srcInfo, method,
structure->emptyTypeArguments,
new IR::Vector<IR::Expression>());
auto method = new IR::Member(tbl, IR::ID(IR::IApply::applyMethodName));
auto call = new IR::MethodCallExpression(apply->srcInfo, method);
if (apply->actions.size() == 0) {
auto stat = new IR::MethodCallStatement(apply->srcInfo, call);
prune();
Expand Down Expand Up @@ -210,9 +204,9 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) {

if (!otherLabels) {
StatementConverter conv(structure, renameMap);
auto hitcase = hit ? conv.convert(hit) : new IR::EmptyStatement(Util::SourceInfo());
auto hitcase = hit ? conv.convert(hit) : new IR::EmptyStatement();
auto misscase = miss ? conv.convert(miss) : nullptr;
auto check = new IR::Member(Util::SourceInfo(), call, IR::Type_Table::hit);
auto check = new IR::Member(call, IR::Type_Table::hit);
auto ifstat = new IR::IfStatement(apply->srcInfo, check, hitcase, misscase);
prune();
return ifstat;
Expand All @@ -230,7 +224,7 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) {
stat = conv.convert(a.second); }
const IR::Expression* destination;
if (a.first == "default") {
destination = new IR::DefaultExpression(Util::SourceInfo());
destination = new IR::DefaultExpression();
} else {
cstring act_name = a.first;
cstring full_name = table->name + '.' + act_name;
Expand All @@ -239,7 +233,7 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) {
destination = new IR::PathExpression(IR::ID(act_name)); }
auto swcase = new IR::SwitchCase(a.second->srcInfo, destination, stat);
cases.insert(insert_at, swcase); }
auto check = new IR::Member(Util::SourceInfo(), call, IR::Type_Table::action_run);
auto check = new IR::Member(call, IR::Type_Table::action_run);
auto sw = new IR::SwitchStatement(apply->srcInfo, check, std::move(cases));
prune();
return sw;
Expand All @@ -252,13 +246,12 @@ const IR::Node* StatementConverter::preorder(IR::Primitive* primitive) {
if (control != nullptr) {
auto instanceName = get(renameMap, control->name);
auto ctrl = new IR::PathExpression(IR::ID(instanceName));
auto method = new IR::Member(Util::SourceInfo(), ctrl, IR::ID(IR::IApply::applyMethodName));
auto method = new IR::Member(ctrl, IR::ID(IR::IApply::applyMethodName));
auto args = new IR::Vector<IR::Expression>();
args->push_back(structure->conversionContext.header->clone());
args->push_back(structure->conversionContext.userMetadata->clone());
args->push_back(structure->conversionContext.standardMetadata->clone());
auto call = new IR::MethodCallExpression(primitive->srcInfo, method,
structure->emptyTypeArguments, args);
auto call = new IR::MethodCallExpression(primitive->srcInfo, method, args);
auto stat = new IR::MethodCallStatement(primitive->srcInfo, call);
return stat;
}
Expand All @@ -273,7 +266,7 @@ const IR::Node* StatementConverter::preorder(IR::If* cond) {
BUG_CHECK(pred != nullptr, "Expected to get an expression when converting %1%", cond->pred);
const IR::Statement* t, *f;
if (cond->ifTrue == nullptr)
t = new IR::EmptyStatement(Util::SourceInfo());
t = new IR::EmptyStatement();
else
t = conv.convert(cond->ifTrue);

Expand All @@ -293,7 +286,7 @@ const IR::Statement* StatementConverter::convert(const IR::Vector<IR::Expression
auto s = convert(e);
stats->push_back(s);
}
auto result = new IR::BlockStatement(toConvert->srcInfo, IR::Annotations::empty, stats);
auto result = new IR::BlockStatement(toConvert->srcInfo, stats);
return result;
}

Expand Down
Loading