compiler, runtime: Refactor P4DataType to P4Type
Now that the old P4Type is a P4QualifiedType, it makes sense to rename the data type back to just type. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
|
||||
import Common
|
||||
|
||||
public struct Action: CustomStringConvertible, P4DataType, P4DataValue {
|
||||
public func type() -> any Common.P4DataType {
|
||||
public struct Action: CustomStringConvertible, P4Type, P4DataValue {
|
||||
public func type() -> any P4Type {
|
||||
return self
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public struct Action: CustomStringConvertible, P4DataType, P4DataValue {
|
||||
}
|
||||
}
|
||||
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public func eq(rhs: any P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case is Action: true
|
||||
default: false
|
||||
@@ -194,20 +194,20 @@ public struct Table: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Control: P4DataType, P4DataValue, Equatable, CustomStringConvertible {
|
||||
public struct Control: P4Type, P4DataValue, Equatable, CustomStringConvertible {
|
||||
public static func == (lhs: Control, rhs: Control) -> Bool {
|
||||
// Two "bare" controls are always equal.
|
||||
return true
|
||||
}
|
||||
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public func eq(rhs: any P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case is Control: true
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
||||
public func type() -> any Common.P4DataType {
|
||||
public func type() -> any P4Type {
|
||||
return self
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import Common
|
||||
|
||||
public struct Declaration: P4DataType {
|
||||
public struct Declaration: P4Type {
|
||||
public let identifier: TypedIdentifier
|
||||
public let extern: Bool
|
||||
public let ffi: P4FFI?
|
||||
@@ -34,7 +34,7 @@ public struct Declaration: P4DataType {
|
||||
self.extern = true
|
||||
}
|
||||
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public func eq(rhs: any Common.P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case let rrhs as Declaration:
|
||||
self.identifier.type.baseType().eq(rhs: rrhs.identifier.type.baseType())
|
||||
@@ -48,7 +48,7 @@ public struct Declaration: P4DataType {
|
||||
return self.identifier.type.baseType().def()
|
||||
}
|
||||
|
||||
public func type() -> any Common.P4DataType {
|
||||
public func type() -> any Common.P4Type {
|
||||
return self
|
||||
}
|
||||
public var description: String {
|
||||
@@ -58,12 +58,12 @@ public struct Declaration: P4DataType {
|
||||
|
||||
public struct ExternDeclaration {}
|
||||
|
||||
public struct FunctionDeclaration: P4DataType, P4DataValue {
|
||||
public func type() -> any Common.P4DataType {
|
||||
public struct FunctionDeclaration: P4Type, P4DataValue {
|
||||
public func type() -> any Common.P4Type {
|
||||
return self
|
||||
}
|
||||
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public func eq(rhs: any Common.P4Type) -> Bool {
|
||||
switch rhs {
|
||||
case let frhs as FunctionDeclaration:
|
||||
return frhs.tipe.eq(self.tipe) && frhs.params == self.params
|
||||
@@ -73,7 +73,7 @@ public struct FunctionDeclaration: P4DataType, P4DataValue {
|
||||
|
||||
public func eq(rhs: any Common.P4DataValue) -> Bool {
|
||||
switch rhs {
|
||||
case let frhs as FunctionDeclaration: return self.eq(rhs: frhs as P4DataType)
|
||||
case let frhs as FunctionDeclaration: return self.eq(rhs: frhs as P4Type)
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public struct FieldAccessExpression {
|
||||
public struct FunctionCall {
|
||||
public let callee: (FunctionDeclaration?, P4FFI?)
|
||||
public let arguments: ArgumentList
|
||||
public let return_type: P4DataType
|
||||
public let return_type: P4Type
|
||||
|
||||
public init(_ callee: FunctionDeclaration, withArguments arguments: ArgumentList) {
|
||||
self.callee = (callee, .none)
|
||||
|
||||
@@ -41,20 +41,20 @@ public struct ParserAssignmentStatement {
|
||||
///
|
||||
/// Note: A P4 Parser State is both a type and a value.
|
||||
/// This "bare" parser state represents the state more as a type than a value.
|
||||
public class ParserState: P4DataType, P4DataValue, Equatable, CustomStringConvertible {
|
||||
public class ParserState: P4Type, P4DataValue, Equatable, CustomStringConvertible {
|
||||
public static func == (lhs: ParserState, rhs: ParserState) -> Bool {
|
||||
// Two "bare" parser states are always equal.
|
||||
return true
|
||||
}
|
||||
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public func eq(rhs: any Common.P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case is ParserState: true
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
||||
public func type() -> any Common.P4DataType {
|
||||
public func type() -> any Common.P4Type {
|
||||
return self
|
||||
}
|
||||
|
||||
@@ -116,14 +116,14 @@ public class InstantiatedParserState: ParserState {
|
||||
return lhs.state == rhs.state
|
||||
}
|
||||
|
||||
public override func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public override func eq(rhs: any Common.P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case is ParserState: true
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
||||
public override func type() -> any Common.P4DataType {
|
||||
public override func type() -> any Common.P4Type {
|
||||
return self
|
||||
}
|
||||
|
||||
@@ -276,12 +276,12 @@ public struct ParserStates {
|
||||
/// A P4 Parser
|
||||
///
|
||||
/// Note: A Parser is both a type _and_ a value.
|
||||
public struct Parser: P4DataType, P4DataValue {
|
||||
public func type() -> any Common.P4DataType {
|
||||
public struct Parser: P4Type, P4DataValue {
|
||||
public func type() -> any Common.P4Type {
|
||||
return self
|
||||
}
|
||||
|
||||
public func eq(rhs: any Common.P4DataType) -> Bool {
|
||||
public func eq(rhs: any Common.P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case let parser_rhs as Parser: self.name == parser_rhs.name
|
||||
default: false
|
||||
|
||||
@@ -26,14 +26,14 @@ public struct ExpressionStatement {
|
||||
}
|
||||
|
||||
public struct Program {
|
||||
public var types: [P4DataType] = Array()
|
||||
public var externs: [P4DataType] = Array()
|
||||
public var types: [P4Type] = Array()
|
||||
public var externs: [P4Type] = Array()
|
||||
public var instances: [P4QualifiedType] = Array()
|
||||
|
||||
/// Type of closure for filtering results from ``Program/InstancesWithTypes(_:)``
|
||||
public typealias TypeFilter = (P4QualifiedType) -> Bool
|
||||
/// Type of closure for filtering results from ``Program/TypesWithTypes(_:)``
|
||||
public typealias DataTypeFilter = (P4DataType) -> Bool
|
||||
public typealias DataTypeFilter = (P4Type) -> Bool
|
||||
|
||||
/// Retrieve global instances in the compiled P4 program.
|
||||
public func InstancesWithTypes() -> [P4QualifiedType] {
|
||||
@@ -59,7 +59,7 @@ public struct Program {
|
||||
}
|
||||
|
||||
/// Retrieve global types in the compiled P4 program.
|
||||
public func TypesWithTypes() -> [P4DataType] {
|
||||
public func TypesWithTypes() -> [P4Type] {
|
||||
return self.types
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ public struct Program {
|
||||
///
|
||||
/// @Snippet(path: "use-program-typeswithtypes", slice: "include")
|
||||
///
|
||||
public func TypesWithTypes(_ filter: DataTypeFilter) -> [P4DataType] {
|
||||
public func TypesWithTypes(_ filter: DataTypeFilter) -> [P4Type] {
|
||||
return self.types.filter { instance in
|
||||
filter(instance)
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieve extern types in the compiled P4 program.
|
||||
public func Externs() -> [P4DataType] {
|
||||
public func Externs() -> [P4Type] {
|
||||
return self.externs
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public struct Program {
|
||||
///
|
||||
/// @Snippet(path: "use-program-typeswithtypes", slice: "include")
|
||||
///
|
||||
public func Externs(_ filter: DataTypeFilter) -> [P4DataType] {
|
||||
public func Externs(_ filter: DataTypeFilter) -> [P4Type] {
|
||||
return self.externs.filter { instance in
|
||||
filter(instance)
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
import Common
|
||||
|
||||
public struct AttributedP4Type {
|
||||
public let type: P4DataType
|
||||
public let type: P4Type
|
||||
public let attributes: P4QualifiedType
|
||||
|
||||
public init(_ type: P4DataType, _ attributes: P4QualifiedType) {
|
||||
public init(_ type: P4Type, _ attributes: P4QualifiedType) {
|
||||
self.type = type
|
||||
self.attributes = attributes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user