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:
@@ -37,7 +37,7 @@ public struct Declaration: P4DataType {
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
return switch rhs {
|
||||
case let rrhs as Declaration:
|
||||
self.identifier.type.dataType().eq(rhs: rrhs.identifier.type.dataType())
|
||||
self.identifier.type.baseType().eq(rhs: rrhs.identifier.type.baseType())
|
||||
&& self.extern == rrhs.extern
|
||||
default: false
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public struct Declaration: P4DataType {
|
||||
|
||||
public func def() -> any Common.P4DataValue {
|
||||
/// TODO: Is a default of the extern'd type the right way to go?
|
||||
return self.identifier.type.dataType().def()
|
||||
return self.identifier.type.baseType().def()
|
||||
}
|
||||
|
||||
public func type() -> any Common.P4DataType {
|
||||
@@ -109,7 +109,7 @@ public struct FunctionDeclaration: P4DataType, P4DataValue {
|
||||
|
||||
public func def() -> any Common.P4DataValue {
|
||||
return FunctionDeclaration(
|
||||
named: Identifier(name: ""), ofType: P4Type(P4Boolean()),
|
||||
named: Identifier(name: ""), ofType: P4QualifiedType(P4Boolean()),
|
||||
withParameters: ParameterList([]),
|
||||
withBody: .none)
|
||||
}
|
||||
@@ -121,10 +121,10 @@ public struct FunctionDeclaration: P4DataType, P4DataValue {
|
||||
public var body: BlockStatement?
|
||||
public var params: ParameterList
|
||||
public var name: Identifier
|
||||
public var tipe: P4Type
|
||||
public var tipe: P4QualifiedType
|
||||
|
||||
public init(
|
||||
named name: Identifier, ofType type: P4Type, withParameters parameters: ParameterList,
|
||||
named name: Identifier, ofType type: P4QualifiedType, withParameters parameters: ParameterList,
|
||||
withBody body: BlockStatement?
|
||||
) {
|
||||
self.name = name
|
||||
|
||||
@@ -24,8 +24,8 @@ public struct KeysetExpression {
|
||||
self.key = key
|
||||
}
|
||||
|
||||
public func compatible(type: P4Type) -> Result<()> {
|
||||
if let key_type = self.key.type().dataType() as? P4Set {
|
||||
public func compatible(type: P4QualifiedType) -> Result<()> {
|
||||
if let key_type = self.key.type().baseType() as? P4Set {
|
||||
if !key_type.set_type().eq(type) {
|
||||
return .Error(
|
||||
Error(
|
||||
@@ -84,7 +84,7 @@ public struct SelectExpression {
|
||||
}
|
||||
}
|
||||
|
||||
public typealias NamedBinaryOperatorEvaluator = (String, P4Type, (P4Value, P4Value) -> P4DataValue)
|
||||
public typealias NamedBinaryOperatorEvaluator = (String, P4QualifiedType, (P4Value, P4Value) -> P4DataValue)
|
||||
public typealias BinaryOperatorEvaluator = (P4Value, P4Value) -> P4DataValue
|
||||
|
||||
public struct BinaryOperatorExpression {
|
||||
@@ -135,13 +135,13 @@ public struct FunctionCall {
|
||||
public init(_ callee: FunctionDeclaration, withArguments arguments: ArgumentList) {
|
||||
self.callee = (callee, .none)
|
||||
self.arguments = arguments
|
||||
self.return_type = callee.tipe.dataType()
|
||||
self.return_type = callee.tipe.baseType()
|
||||
}
|
||||
|
||||
public init(_ callee: P4FFI, withArguments arguments: ArgumentList) {
|
||||
self.callee = (.none, callee)
|
||||
self.arguments = arguments
|
||||
/// ASSUME: That the FFI has been checked and the type is always a function declaration.
|
||||
self.return_type = (callee.type().dataType() as! FunctionDeclaration).tipe.dataType()
|
||||
self.return_type = (callee.type().baseType() as! FunctionDeclaration).tipe.baseType()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ public struct ExpressionStatement {
|
||||
public struct Program {
|
||||
public var types: [P4DataType] = Array()
|
||||
public var externs: [P4DataType] = Array()
|
||||
public var instances: [P4Type] = Array()
|
||||
public var instances: [P4QualifiedType] = Array()
|
||||
|
||||
/// Type of closure for filtering results from ``Program/InstancesWithTypes(_:)``
|
||||
public typealias TypeFilter = (P4Type) -> Bool
|
||||
public typealias TypeFilter = (P4QualifiedType) -> Bool
|
||||
/// Type of closure for filtering results from ``Program/TypesWithTypes(_:)``
|
||||
public typealias DataTypeFilter = (P4DataType) -> Bool
|
||||
|
||||
/// Retrieve global instances in the compiled P4 program.
|
||||
public func InstancesWithTypes() -> [P4Type] {
|
||||
public func InstancesWithTypes() -> [P4QualifiedType] {
|
||||
return self.instances
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public struct Program {
|
||||
///
|
||||
/// @Snippet(path: "use-program-instanceswithtypes", slice: "include")
|
||||
///
|
||||
public func InstancesWithTypes(_ filter: TypeFilter) -> [P4Type] {
|
||||
public func InstancesWithTypes(_ filter: TypeFilter) -> [P4QualifiedType] {
|
||||
return self.instances.filter { instance in
|
||||
filter(instance)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public struct Program {
|
||||
|
||||
public func find_parser(withName name: Identifier) -> Result<Parser> {
|
||||
for instance in self.instances {
|
||||
guard let parser = instance.dataType() as? Parser else {
|
||||
guard let parser = instance.baseType() as? Parser else {
|
||||
continue
|
||||
}
|
||||
if parser.name == name {
|
||||
|
||||
@@ -19,9 +19,9 @@ import Common
|
||||
|
||||
public struct AttributedP4Type {
|
||||
public let type: P4DataType
|
||||
public let attributes: P4Type
|
||||
public let attributes: P4QualifiedType
|
||||
|
||||
public init(_ type: P4DataType, _ attributes: P4Type) {
|
||||
public init(_ type: P4DataType, _ attributes: P4QualifiedType) {
|
||||
self.type = type
|
||||
self.attributes = attributes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user