compiler, runtime: Refactor P4Type to P4QualifiedType
Also, refer to the different pieces of the qualified type as qualifiers and not attributes. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -23,8 +23,8 @@ extension SelectCaseExpression: EvaluatableExpression {
|
||||
return (execution.scopes.lookup(identifier: next_state_identifier), execution)
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
return P4Type(ParserState())
|
||||
public func type() -> P4QualifiedType {
|
||||
return P4QualifiedType(ParserState())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,14 +49,14 @@ extension SelectExpression: EvaluatableExpression {
|
||||
}
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
return P4Type(ParserState())
|
||||
public func type() -> P4QualifiedType {
|
||||
return P4QualifiedType(ParserState())
|
||||
}
|
||||
}
|
||||
|
||||
// Variables are evaluatable because they can be looked up by identifiers.
|
||||
extension TypedIdentifier: EvaluatableExpression {
|
||||
public func type() -> P4Type {
|
||||
public func type() -> P4QualifiedType {
|
||||
return self.type
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public func binary_and_or_operator_checker(
|
||||
left: EvaluatableExpression, right: EvaluatableExpression
|
||||
) -> Result<()> {
|
||||
// Check that both are Boolean-typed things!
|
||||
if !(left.type().dataType().eq(rhs: P4Boolean()) && right.type().dataType().eq(rhs: P4Boolean()))
|
||||
if !(left.type().baseType().eq(rhs: P4Boolean()) && right.type().baseType().eq(rhs: P4Boolean()))
|
||||
{
|
||||
return .Error(Error(withMessage: "And/Or on operands with non-bool type is not allowed"))
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public func binary_int_math_operator_checker(
|
||||
left: EvaluatableExpression, right: EvaluatableExpression
|
||||
) -> Result<()> {
|
||||
// Check that both are int-typed things!
|
||||
if !(left.type().dataType().eq(rhs: P4Int()) && right.type().dataType().eq(rhs: P4Int())) {
|
||||
if !(left.type().baseType().eq(rhs: P4Int()) && right.type().baseType().eq(rhs: P4Int())) {
|
||||
return .Error(
|
||||
Error(withMessage: "Mathematical operation on operands with non-int type is not allowed"))
|
||||
}
|
||||
@@ -230,7 +230,7 @@ extension BinaryOperatorExpression: EvaluatableExpression {
|
||||
return (.Ok(P4Value(self.evaluator.2(evaluated_left, evaluated_right))), updated_execution)
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
public func type() -> P4QualifiedType {
|
||||
return self.evaluator.1
|
||||
}
|
||||
}
|
||||
@@ -264,7 +264,7 @@ extension ArrayAccessExpression: EvaluatableExpression {
|
||||
return (.Ok(accessed), updated_execution)
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
public func type() -> P4QualifiedType {
|
||||
return self.type.value_type()
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ extension FieldAccessExpression: EvaluatableExpression {
|
||||
return (.Ok(value), updated_execution)
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
public func type() -> P4QualifiedType {
|
||||
return self.field.type
|
||||
}
|
||||
}
|
||||
@@ -467,7 +467,7 @@ extension KeysetExpression: EvaluatableExpression {
|
||||
return execution.evaluator.EvaluateExpression(self.key, inExecution: execution)
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
public func type() -> P4QualifiedType {
|
||||
return self.key.type()
|
||||
}
|
||||
}
|
||||
@@ -524,8 +524,8 @@ extension FunctionCall: EvaluatableExpression {
|
||||
inExecution: execution)
|
||||
}
|
||||
|
||||
public func type() -> P4Type {
|
||||
return P4Type(self.return_type)
|
||||
public func type() -> P4QualifiedType {
|
||||
return P4QualifiedType(self.return_type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ extension ParserStateDirectTransition: EvaluatableParserState {
|
||||
let res = program.scopes.lookup(identifier: get_next_state())
|
||||
|
||||
if case .Ok(let value) = res {
|
||||
if value.type().dataType().eq(rhs: self) {
|
||||
if value.type().baseType().eq(rhs: self) {
|
||||
return (value.dataValue() as! EvaluatableParserState, program.exit_scope())
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ extension ParserStateSelectTransition: EvaluatableParserState {
|
||||
//switch self.selectExpression.evaluate(execution: program) {
|
||||
switch program.evaluator.EvaluateExpression(self.selectExpression, inExecution: program) {
|
||||
case (.Ok(let value), let program):
|
||||
if value.type().dataType().eq(rhs: self) {
|
||||
if value.type().baseType().eq(rhs: self) {
|
||||
return (value.dataValue() as! EvaluatableParserState, program.exit_scope())
|
||||
} else {
|
||||
return (
|
||||
@@ -150,10 +150,10 @@ extension Parser: LibraryCallable {
|
||||
|
||||
execution = execution.declare(
|
||||
identifier: AsInstantiatedParserState(accept.state()).state,
|
||||
withValue: P4Value(accept, P4Type.ReadOnly(accept.type())))
|
||||
withValue: P4Value(accept, P4QualifiedType.ReadOnly(accept.type())))
|
||||
execution = execution.declare(
|
||||
identifier: AsInstantiatedParserState(reject.state()).state,
|
||||
withValue: P4Value(reject, P4Type.ReadOnly(reject.type())))
|
||||
withValue: P4Value(reject, P4QualifiedType.ReadOnly(reject.type())))
|
||||
|
||||
// Add initial values to the global scope
|
||||
for (name, value) in execution.getGlobalValues() {
|
||||
|
||||
@@ -69,7 +69,7 @@ extension ConditionalStatement: EvaluatableStatement {
|
||||
)
|
||||
}
|
||||
|
||||
if !evaluated_condition.type().dataType().eq(rhs: P4Boolean()) {
|
||||
if !evaluated_condition.type().baseType().eq(rhs: P4Boolean()) {
|
||||
return (
|
||||
ControlFlow.Error,
|
||||
execution.setError(error: Error(withMessage: "Condition expression is not a Boolean"))
|
||||
|
||||
Reference in New Issue
Block a user