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

Improve diagnostics for StructExpression #4357

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion backends/p4tools/p4tools.def
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public:
inline cstring concolicMethodName = "";

toString {
cstring argumentStr;
cstring argumentStr = "";
cstring sep = "";
for (const auto *arg : *arguments) {
argumentStr += sep + arg->toString();
Expand Down
12 changes: 12 additions & 0 deletions ir/expression.def
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,18 @@ class StructExpression : Expression {
size_t size = components.size();
return components.at(size - 1)->is<IR::NamedDots>();
}
toString {
cstring str = "{";
if (!components.empty()) {
cstring exprStr = components.at(0)->expression->toString();
str += " " + components.at(0)->toString() + " = " + exprStr;
}
for (unsigned i = 1; i < size(); i++) {
cstring exprStr = components.at(i)->expression->toString();
str += ", " + components.at(i)->toString() + " = " + exprStr;
}
return str + " }";
}
}

/// Can be an invalid header or header_union
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_errors_outputs/issue2220.p4-stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
issue2220.p4(11): [--Werror=type-error] error: StructExpression: values of type 'bit<8>' cannot be implicitly cast to type 'myEnum'
issue2220.p4(11): [--Werror=type-error] error: { val = 8w0 }: values of type 'bit<8>' cannot be implicitly cast to type 'myEnum'
S s1 = { val = (bit<8>)0 };
^^^^^^^^^^^^^^^^^^^
issue2220.p4(3)
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_errors_outputs/issue3671-2.p4-stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
issue3671-2.p4(17): [--Werror=type-error] error: StructExpression: argument does not match declaration in actions list: StructExpression
issue3671-2.p4(17): [--Werror=type-error] error: { f1 = ext1, f0 = ext2 }: argument does not match declaration in actions list: { f0 = ext1, f1 = ext2 }
default_action = a1({f1 = ext1(),f0 = ext2()});
^^^^^^^^^^^^^^^^^^^^^^^^^
issue3671-2.p4(15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ structure-valued-expr-errs-1.p4(31)
header h1_t {
^^^^
---- Originating from:
structure-valued-expr-errs-1.p4(112): Source expression 'StructExpression' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'header h1_t'
structure-valued-expr-errs-1.p4(112): Source expression '{ f2 = 5, f1 = 2 }' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'header h1_t'
hdr.h1 = {f2=5, f1=2};
^^^^^^^^^^^^
structure-valued-expr-errs-1.p4(112)
Expand All @@ -186,7 +186,7 @@ structure-valued-expr-errs-1.p4(32): No initializer for field f1
bit<8> f1;
^^
---- Originating from:
structure-valued-expr-errs-1.p4(113): Source expression 'StructExpression' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'header h1_t'
structure-valued-expr-errs-1.p4(113): Source expression '{ f2 = 5 }' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'header h1_t'
hdr.h1 = {f2=5};
^^^^^^
structure-valued-expr-errs-1.p4(113)
Expand All @@ -206,7 +206,7 @@ structure-valued-expr-errs-1.p4(43)
struct s1_t {
^^^^
---- Originating from:
structure-valued-expr-errs-1.p4(114): Source expression 'StructExpression' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'struct s1_t'
structure-valued-expr-errs-1.p4(114): Source expression '{ f2 = 5, f1 = 2 }' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'struct s1_t'
hdr.hstructs.s1 = {f2=5, f1=2};
^^^^^^^^^^^^
structure-valued-expr-errs-1.p4(114)
Expand All @@ -223,7 +223,7 @@ structure-valued-expr-errs-1.p4(44): No initializer for field f1
bit<8> f1;
^^
---- Originating from:
structure-valued-expr-errs-1.p4(115): Source expression 'StructExpression' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'struct s1_t'
structure-valued-expr-errs-1.p4(115): Source expression '{ f2 = 5 }' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'struct s1_t'
hdr.hstructs.s1 = {f2=5};
^^^^^^
structure-valued-expr-errs-1.p4(115)
Expand All @@ -243,7 +243,7 @@ structure-valued-expr-errs-1.p4(35)
header h2_t {
^^^^
---- Originating from:
structure-valued-expr-errs-1.p4(120): Source expression 'StructExpression' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'header h2_t'
structure-valued-expr-errs-1.p4(120): Source expression '{ f2 = 5 }' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'header h2_t'
hdr.h2 = {f2=5};
^^^^^^
structure-valued-expr-errs-1.p4(120)
Expand All @@ -263,7 +263,7 @@ structure-valued-expr-errs-1.p4(47)
struct s2_t {
^^^^
---- Originating from:
structure-valued-expr-errs-1.p4(121): Source expression 'StructExpression' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'struct s2_t'
structure-valued-expr-errs-1.p4(121): Source expression '{ f2 = 5 }' produces a result of type 'unknown struct' which cannot be assigned to a left-value with type 'struct s2_t'
hdr.hstructs.s2 = {f2=5};
^^^^^^
structure-valued-expr-errs-1.p4(121)
Expand Down
Loading