compiler, language, runtime: Separate Parser Type From Instances
In P4, parsers are considered types. Those parsers are instantiated. The instantiated parsers are values. Previously, gp4 treated a parser type and a parser value as identical. This PR makes that difference clear _and_ sets the stage for the future. TODO: Make the same distinction between control and action types and values. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -28,7 +28,7 @@ public struct ExpressionStatement {
|
||||
public struct Program {
|
||||
public var types: [P4Type] = Array()
|
||||
public var externs: [P4Type] = Array()
|
||||
public var instances: [P4QualifiedType] = Array()
|
||||
public var instances: [P4Value] = Array()
|
||||
|
||||
/// Type of closure for filtering results from ``Program/InstancesWithTypes(_:)``
|
||||
public typealias TypeFilter = (P4QualifiedType) -> Bool
|
||||
@@ -36,7 +36,7 @@ public struct Program {
|
||||
public typealias DataTypeFilter = (P4Type) -> Bool
|
||||
|
||||
/// Retrieve global instances in the compiled P4 program.
|
||||
public func InstancesWithTypes() -> [P4QualifiedType] {
|
||||
public func InstancesWithTypes() -> [P4Value] {
|
||||
return self.instances
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ public struct Program {
|
||||
///
|
||||
/// @Snippet(path: "use-program-instanceswithtypes", slice: "include")
|
||||
///
|
||||
public func InstancesWithTypes(_ filter: TypeFilter) -> [P4QualifiedType] {
|
||||
public func InstancesWithTypes(_ filter: TypeFilter) -> [P4Value] {
|
||||
return self.instances.filter { instance in
|
||||
filter(instance)
|
||||
filter(instance.type())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ public struct Program {
|
||||
}
|
||||
|
||||
public func find_parser(withName name: Identifier) -> Result<Parser> {
|
||||
for instance in self.instances {
|
||||
guard let parser = instance.baseType() as? Parser else {
|
||||
for instance in self.types {
|
||||
guard let parser = instance as? Parser else {
|
||||
continue
|
||||
}
|
||||
if parser.name == name {
|
||||
|
||||
Reference in New Issue
Block a user