From 35b2537754c221c3ae7f3c2b37fc2afb8da1ac48 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Mon, 13 Apr 2026 06:25:08 -0400 Subject: [PATCH] compiler, runtime, common, testing: Support Directions on Parameters and Attributed Types Add support for directions on parameters and attributed types. The latter is necessary to support the former, but is not limited to the direction use case. An attributed type is a P4 type with attributes (like its direction, whether it is read only, etc.) Other attributes will be added in the future. Changes necessary to support attributed types include: 1. Global instances tracked during compilation are not attributed types and not simply types. 2. (future) Type checking will have to make sure that a types attributes do not affect type compatibility. Signed-off-by: Will Hawkins --- Snippets/use-program-instanceswithtypes.swift | 4 +- Sources/Common/Compiler.swift | 4 +- Sources/Common/ProgramTypes.swift | 73 +++++++++++++++++++ Sources/P4Compiler/Common.swift | 43 +++++++++-- Sources/P4Compiler/Declarations.swift | 15 ++-- Sources/P4Compiler/Expression.swift | 4 +- Sources/P4Compiler/Statement.swift | 2 +- Sources/P4Lang/Common.swift | 22 +++++- Sources/P4Lang/Program.swift | 14 ++-- Sources/P4Lang/Types.swift | 12 +++ Sources/P4Runtime/Expressions.swift | 5 +- Tests/p4rseTests/ArrayTests.swift | 16 ++-- Tests/p4rseTests/ControlCompilerTests.swift | 8 +- Tests/p4rseTests/Declarations.swift | 9 +++ Tests/p4rseTests/ScopeTests.swift | 20 ++--- Tests/p4rseTests/StructTests.swift | 20 ++--- Tests/p4rseTests/ValueTypeParserTests.swift | 2 +- 17 files changed, 209 insertions(+), 64 deletions(-) diff --git a/Snippets/use-program-instanceswithtypes.swift b/Snippets/use-program-instanceswithtypes.swift index ba88ba7..aa81c4c 100644 --- a/Snippets/use-program-instanceswithtypes.swift +++ b/Snippets/use-program-instanceswithtypes.swift @@ -39,8 +39,8 @@ let p4_program_with_control_decl = """ // snippet.include -let flter = { (tipe: P4Type) -> Bool in - switch tipe { +let flter = { (tipe: P4TypeAttributed) -> Bool in + switch tipe.type { case let c as Control: c.name == "simple" default: false } diff --git a/Sources/Common/Compiler.swift b/Sources/Common/Compiler.swift index 931bf16..5aca1e6 100644 --- a/Sources/Common/Compiler.swift +++ b/Sources/Common/Compiler.swift @@ -16,10 +16,10 @@ // along with this program. If not, see . /// A scope that resolves variable identifiers to their types. -public typealias VarTypeScope = Scope +public typealias VarTypeScope = Scope /// Scopes that resolve variable identifiers to their types. -public typealias VarTypeScopes = Scopes +public typealias VarTypeScopes = Scopes /// A scope that resolves type identifiers to their types. public typealias TypeTypeScope = Scope diff --git a/Sources/Common/ProgramTypes.swift b/Sources/Common/ProgramTypes.swift index 8beaa3e..3bcc55a 100644 --- a/Sources/Common/ProgramTypes.swift +++ b/Sources/Common/ProgramTypes.swift @@ -782,3 +782,76 @@ public class P4SetDefaultValue: P4Value { "Default of P4Set of \(self.type()) type" } } + +public enum Direction: Equatable, CustomStringConvertible { + case In + case Out + case InOut + + public var description: String { + return switch self { + case Direction.In: "In" + case Direction.Out: "Out" + case Direction.InOut: "InOut" + } + } + + /// Compare two optional ``Direction``s + static public func eqopt(_ lhs: Direction?, _ rhs: Direction?) -> Bool { + // If both are empty, they are the same. + if lhs == .none && rhs == .none { + return true + } + + // If one is empty, they are different + if lhs == .none || rhs == .none { + return false + } + + // Both have values -- compare them natively. + return lhs! == rhs! + } +} + +public enum P4TypeAttribute { + case Direction(Direction) + case Readonly // Not yet used -- here to keep Swift warnings at bay +} + +public struct P4TypeAttributed { + let attributes: [P4TypeAttribute] + public let type: P4Type + + public init(_ type: P4Type, _ attributes: [P4TypeAttribute]) { + self.attributes = attributes + self.type = type + } + + public func direction() -> Direction? { + let result = attributes.firstIndex { attribute in + return switch attribute { + case .Direction(_): true + default: false + } + } + return result.flatMap { index in + return switch attributes[index] { + case .Direction(let d): d + default: Optional.none + } + } + } + + public func readOnly() -> Bool { + return attributes.contains { attribute in + return switch attribute { + case .Readonly: true + default: false + } + } + } + + public static func Attributeless(_ type: P4Type) -> P4TypeAttributed { + return P4TypeAttributed(type, []) + } +} diff --git a/Sources/P4Compiler/Common.swift b/Sources/P4Compiler/Common.swift index 84cf5a9..b5cdc9e 100644 --- a/Sources/P4Compiler/Common.swift +++ b/Sources/P4Compiler/Common.swift @@ -120,6 +120,30 @@ extension ParameterList: Compilable { } } +extension Direction: Compilable { + public typealias T = Direction + public static func Compile( + node: Node, withContext context: CompilerContext + ) -> Result<(Direction, CompilerContext)> { + let direction_node = node + #RequireNodeType( + node: direction_node, type: "direction", nice_type_name: "direction") + let directions = [ + "in": Direction.In, + "out": Direction.Out, + "inout": Direction.InOut, + ] + + guard let parsed_direction = directions[direction_node.text!] else { + return .Error( + ErrorOnNode( + node: direction_node, withError: "\(direction_node.text!) is not a valid direction")) + } + + return .Ok((parsed_direction, context)) + } +} + extension Parameter: Compilable { public typealias T = Parameter public static func Compile( @@ -148,15 +172,22 @@ extension Parameter: Compilable { withError: "Annotations in parameter declarations are not yet handled")) // Will increment indexes here. } + currentChild = node.child(at: currentChildIdx) + var direction: Direction? = .none // Direction? if currentChild!.nodeType == "direction" { - return .Error( - ErrorOnNode( - node: currentChild!, withError: "Direction in parameter declarations are not yet handled" - )) - // Will increment indexes here. + + let maybe_parsed_direction = Direction.Compile(node: currentChild!, withContext: context) + guard case .Ok((let parsed_direction, _)) = maybe_parsed_direction else { + return .Error(maybe_parsed_direction.error()!) + } + direction = parsed_direction + + currentChildIdx += 1 + currentChildIdxSafe += 1 } + currentChild = node.child(at: currentChildIdx) if currentChild!.nodeType != "typeRef" { return Result.Error( @@ -195,7 +226,7 @@ extension Parameter: Compilable { return Result.Ok( ( Parameter( - identifier: parameter_name, withType: parameter_type), + identifier: parameter_name, withType: parameter_type, withDirection: direction), context )) } diff --git a/Sources/P4Compiler/Declarations.swift b/Sources/P4Compiler/Declarations.swift index 69cdf83..f501ca9 100644 --- a/Sources/P4Compiler/Declarations.swift +++ b/Sources/P4Compiler/Declarations.swift @@ -108,7 +108,8 @@ extension FunctionDeclaration: CompilableDeclaration { // Add the parameters into scope. var function_scope = context.instances.enter() for parameter in function_parameters.parameters { - function_scope = function_scope.declare(identifier: parameter.name, withValue: parameter.type) + function_scope = function_scope.declare( + identifier: parameter.name, withValue: parameter.attributedType()) } let maybe_function_body = Parser.Statement.Compile( @@ -331,7 +332,7 @@ extension P4Lang.Parser: CompilableDeclaration { for parameter in parameter_list.parameters { current_context = current_context.update( newInstances: current_context.instances.declare( - identifier: parameter.name, withValue: parameter.type)) + identifier: parameter.name, withValue: parameter.attributedType())) } currentChildIdx += 1 @@ -374,7 +375,7 @@ extension P4Lang.Parser: CompilableDeclaration { parser, context.update( newInstances: updated_context.instances.declare( - identifier: parser.name, withValue: parser)) + identifier: parser.name, withValue: P4TypeAttributed(parser, []))) )) case Result.Error(let error): return .Error(error) } @@ -436,7 +437,8 @@ extension Control: CompilableDeclaration { // Before continuing, make sure to put the parameters into context. var control_scope = local_context.instances.enter() for parameter in control_parameters.parameters { - control_scope = control_scope.declare(identifier: parameter.name, withValue: parameter.type) + control_scope = control_scope.declare( + identifier: parameter.name, withValue: parameter.attributedType()) } local_context = local_context.update(newInstances: control_scope) @@ -505,7 +507,7 @@ extension Control: CompilableDeclaration { declared_control, context.update( newInstances: context.instances.declare( - identifier: control_name, withValue: declared_control)) + identifier: control_name, withValue: P4TypeAttributed(declared_control, []))) )) } } @@ -566,7 +568,8 @@ extension Action: Compilable { // Add the parameters into scope. var function_scope = context.instances.enter() for parameter in action_parameters.parameters { - function_scope = function_scope.declare(identifier: parameter.name, withValue: parameter.type) + function_scope = function_scope.declare( + identifier: parameter.name, withValue: parameter.attributedType()) } let maybe_action_body = Parser.Statement.Compile( diff --git a/Sources/P4Compiler/Expression.swift b/Sources/P4Compiler/Expression.swift index eae1715..e8d59fc 100644 --- a/Sources/P4Compiler/Expression.swift +++ b/Sources/P4Compiler/Expression.swift @@ -43,13 +43,13 @@ extension TypedIdentifier: CompilableExpression { node: node, type: "identifier") guard - case Result.Ok(let type) = context.instances.lookup( + case Result.Ok(let attributed_type) = context.instances.lookup( identifier: Common.Identifier(name: node.text!)) else { return .Error(ErrorOnNode(node: node, withError: "Cannot find \(node.text!) in scope")) } - return .Ok(TypedIdentifier(name: node.text!, withType: type)) + return .Ok(TypedIdentifier(name: node.text!, withType: attributed_type.type)) } } diff --git a/Sources/P4Compiler/Statement.swift b/Sources/P4Compiler/Statement.swift index 1e749b0..df7bfc3 100644 --- a/Sources/P4Compiler/Statement.swift +++ b/Sources/P4Compiler/Statement.swift @@ -231,7 +231,7 @@ extension VariableDeclarationStatement: CompilableStatement { // Context with updated names to include the newly declared name. context.update( newInstances: context.instances.declare( - identifier: parsed_variablename, withValue: declaration_p4_type)) + identifier: parsed_variablename, withValue: P4TypeAttributed(declaration_p4_type, []))) )) } } diff --git a/Sources/P4Lang/Common.swift b/Sources/P4Lang/Common.swift index d54643c..a3b8d7e 100644 --- a/Sources/P4Lang/Common.swift +++ b/Sources/P4Lang/Common.swift @@ -19,21 +19,35 @@ import Common public struct Parameter: CustomStringConvertible, Equatable { public static func == (lhs: Parameter, rhs: Parameter) -> Bool { - return lhs.name == rhs.name && lhs.type.eq(rhs: rhs.type) + return lhs.name == rhs.name && lhs.type.eq(rhs: rhs.type) && lhs.direction == rhs.direction } public var name: Identifier public var type: P4Type + public var direction: Direction? public init( - identifier: Identifier, withType type: P4Type + identifier: Identifier, withType type: P4Type, withDirection direction: Direction? = .none ) { self.name = identifier self.type = type + self.direction = direction } public var description: String { - return "Parameter: \(self.name) with type \(self.type)" + let direction = self.direction != .none ? self.direction!.description : "no" + return "Parameter: \(self.name) with type \(self.type) with \(direction) direction" + } + + /// Calculate whether the `argument` is compatible with this parameter. + public func compatible(_ argument: Argument) -> Bool { + let arg_type = argument.argument.type() + return arg_type.eq(rhs: self.type) + } + + public func attributedType() -> P4TypeAttributed { + return P4TypeAttributed( + self.type, self.direction == .none ? [] : [P4TypeAttribute.Direction(self.direction!)]) } } @@ -89,7 +103,7 @@ public struct ArgumentList { for (arg, param) in zip(self.arguments, parameters.parameters) { let arg_index = arg.index let arg_type = arg.argument.type() - if !arg_type.eq(rhs: param.type) { + if !param.compatible(arg) { return .Error( Error( withMessage: diff --git a/Sources/P4Lang/Program.swift b/Sources/P4Lang/Program.swift index a1e5dfd..9986757 100644 --- a/Sources/P4Lang/Program.swift +++ b/Sources/P4Lang/Program.swift @@ -23,13 +23,15 @@ public struct ExpressionStatement { public struct Program { public var types: [P4Type] = Array() - public var instances: [P4Type] = Array() + public var instances: [P4TypeAttributed] = Array() - /// Type of closure for filtering results from ``Program/InstancesWithTypes(_:)`` and ``Program/TypesWithTypes(_:)`` + /// Type of closure for filtering results from ``Program/InstancesWithTypes(_:)`` + public typealias AttributedTypeFilter = (P4TypeAttributed) -> Bool + /// Type of closure for filtering results from ``Program/TypesWithTypes(_:)`` public typealias TypeFilter = (P4Type) -> Bool /// Retrieve global instances in the compiled P4 program. - public func InstancesWithTypes() -> [P4Type] { + public func InstancesWithTypes() -> [P4TypeAttributed] { return self.instances } @@ -45,7 +47,7 @@ public struct Program { /// /// @Snippet(path: "use-program-instanceswithtypes", slice: "include") /// - public func InstancesWithTypes(_ filter: TypeFilter) -> [P4Type] { + public func InstancesWithTypes(_ filter: AttributedTypeFilter) -> [P4TypeAttributed] { return self.instances.filter { instance in filter(instance) } @@ -82,8 +84,8 @@ public struct Program { } public func find_parser(withName name: Identifier) -> Result { - for instances in self.instances { - guard let parser = instances as? Parser else { + for instance in self.instances { + guard let parser = instance.type as? Parser else { continue } if parser.name == name { diff --git a/Sources/P4Lang/Types.swift b/Sources/P4Lang/Types.swift index aca375f..fc85538 100644 --- a/Sources/P4Lang/Types.swift +++ b/Sources/P4Lang/Types.swift @@ -14,3 +14,15 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . + +import Common + +public struct AttributedP4Type { + public let type: P4Type + public let attributes: P4TypeAttributed + + public init(_ type: P4Type, _ attributes: P4TypeAttributed) { + self.type = type + self.attributes = attributes + } +} diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift index a975e63..f93595c 100644 --- a/Sources/P4Runtime/Expressions.swift +++ b/Sources/P4Runtime/Expressions.swift @@ -81,11 +81,12 @@ extension TypedIdentifier: EvaluatableLValueExpression { return .Error(Error(withMessage: "Cannot assign to identifier not in scope")) } - if !type.eq(rhs: to.type()) { + if !type.type.eq(rhs: to.type()) { return .Error( Error( withMessage: - "Cannot assign value with type \(to.type()) to identifier \(self) with type \(type)")) + "Cannot assign value with type \(to.type()) to identifier \(self) with type \(type.type)" + )) } return .Ok(()) } diff --git a/Tests/p4rseTests/ArrayTests.swift b/Tests/p4rseTests/ArrayTests.swift index 37c07cf..fcd5148 100644 --- a/Tests/p4rseTests/ArrayTests.swift +++ b/Tests/p4rseTests/ArrayTests.swift @@ -40,7 +40,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int())) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Int()))) var test_values = VarValueScopes().enter() test_values = test_values.declare( identifier: Identifier(name: "ta"), @@ -68,7 +68,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Int()) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Int())) #expect( #RequireErrorResult( Error( @@ -91,7 +91,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int())) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Int()))) var test_values = VarValueScopes().enter() test_values = test_values.declare( identifier: Identifier(name: "ta"), @@ -118,7 +118,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int())) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Int()))) var test_values = VarValueScopes().enter() test_values = test_values.declare( identifier: Identifier(name: "ta"), @@ -145,7 +145,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int())) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Int()))) var test_values = VarValueScopes().enter() test_values = test_values.declare( identifier: Identifier(name: "ta"), @@ -173,7 +173,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Array(withValueType: P4Int()))) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Array(withValueType: P4Int())))) var test_values = VarValueScopes().enter() let nested = P4ArrayValue( @@ -206,7 +206,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int())) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Int()))) var test_values = VarValueScopes().enter() test_values = test_values.declare( identifier: Identifier(name: "ta"), @@ -235,7 +235,7 @@ import TreeSitterP4 }; """ var test_declarations = VarTypeScopes().enter() - test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Array(withValueType: P4Int()))) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Array(withValueType: P4Int())))) var test_values = VarValueScopes().enter() let nested = P4ArrayValue( diff --git a/Tests/p4rseTests/ControlCompilerTests.swift b/Tests/p4rseTests/ControlCompilerTests.swift index e4a8333..4b36fce 100644 --- a/Tests/p4rseTests/ControlCompilerTests.swift +++ b/Tests/p4rseTests/ControlCompilerTests.swift @@ -39,8 +39,8 @@ import P4Lang } }; """ - let x = { (tipe: P4Type) -> Bool in - switch tipe { + let x = { (tipe: P4TypeAttributed) -> Bool in + switch tipe.type { case let c as Control: c.name == "simple" default: false } @@ -73,8 +73,8 @@ import P4Lang }; """ - let filter = { (tipe: P4Type) -> Bool in - switch tipe { + let filter = { (tipe: P4TypeAttributed) -> Bool in + switch tipe.type { case let c as Control: c.name == "simple" || c.name == "complex" default: false } diff --git a/Tests/p4rseTests/Declarations.swift b/Tests/p4rseTests/Declarations.swift index 331aff0..5a99f20 100644 --- a/Tests/p4rseTests/Declarations.swift +++ b/Tests/p4rseTests/Declarations.swift @@ -166,3 +166,12 @@ import TreeSitterP4 #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) } +@Test func test_function_declaration_with_parameters_and_direction() async throws { + let simple_parser_declaration = """ + bool functionb(in bool x, out string y, inout int z) { + x = true; + }; + """ + #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) +} + diff --git a/Tests/p4rseTests/ScopeTests.swift b/Tests/p4rseTests/ScopeTests.swift index e40a106..457a78f 100644 --- a/Tests/p4rseTests/ScopeTests.swift +++ b/Tests/p4rseTests/ScopeTests.swift @@ -28,39 +28,39 @@ import TreeSitterP4 @Test func test_scope() async throws { let s = VarTypeScope() - let s2 = s.declare(identifier: Identifier(name: "first"), withValue: P4Int()) + let s2 = s.declare(identifier: Identifier(name: "first"), withValue: P4TypeAttributed.Attributeless(P4Int())) let found_first = try! #require(s2.lookup(identifier: Identifier(name: "first"))) - #expect(found_first.eq(rhs: P4Int())) + #expect(found_first.type.eq(rhs: P4Int())) #expect(s2.count == 1) } @Test func test_scope_no_set() async throws { var ss = VarTypeScopes().enter() - ss = ss.declare(identifier: Identifier(name: "first"), withValue: P4Int()) + ss = ss.declare(identifier: Identifier(name: "first"), withValue: P4TypeAttributed.Attributeless(P4Int())) ss = ss.enter() - ss = ss.declare(identifier: Identifier(name: "second"), withValue: P4Boolean()) + ss = ss.declare(identifier: Identifier(name: "second"), withValue: P4TypeAttributed.Attributeless(P4Boolean())) let found_first = try! #UseOkResult(ss.lookup(identifier: Identifier(name: "first"))) let found_second = try! #UseOkResult(ss.lookup(identifier: Identifier(name: "second"))) - #expect(found_first.eq(rhs: P4Int())) - #expect(found_second.eq(rhs: P4Boolean())) + #expect(found_first.type.eq(rhs: P4Int())) + #expect(found_second.type.eq(rhs: P4Boolean())) } @Test func test_scope_set() async throws { var ss = VarTypeScopes().enter() let id = Identifier(name: "first") - let id_type = P4Int() + let id_type = P4TypeAttributed.Attributeless(P4Int()) ss = ss.declare(identifier: id, withValue: id_type) ss = ss.enter() - ss = ss.declare(identifier: Identifier(name: "second"), withValue: P4Boolean()) + ss = ss.declare(identifier: Identifier(name: "second"), withValue: P4TypeAttributed.Attributeless(P4Boolean())) // Change the value of `first`. - ss = ss.set(identifier: id, withValue: P4String()) + ss = ss.set(identifier: id, withValue: P4TypeAttributed.Attributeless(P4String())) // Verify the change! let found = try! #UseOkResult(ss.lookup(identifier: id)) - #expect(found.eq(rhs: P4String())) + #expect(found.type.eq(rhs: P4String())) } diff --git a/Tests/p4rseTests/StructTests.swift b/Tests/p4rseTests/StructTests.swift index 56ab83c..e97df55 100644 --- a/Tests/p4rseTests/StructTests.swift +++ b/Tests/p4rseTests/StructTests.swift @@ -45,7 +45,7 @@ import TreeSitterP4 P4StructFieldIdentifier(name: "count", withType: P4Int()), ]) let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(struct_type)) var test_values = VarValueScopes().enter() test_values = test_values.declare( @@ -139,7 +139,7 @@ import TreeSitterP4 P4StructFieldIdentifier(name: "count", withType: P4Int()), ]) let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(struct_type)) var test_values = VarValueScopes().enter() test_values = test_values.declare( @@ -174,7 +174,7 @@ import TreeSitterP4 P4StructFieldIdentifier(name: "count", withType: P4Int()), ]) let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(struct_type)) var test_values = VarValueScopes().enter() test_values = test_values.declare( @@ -208,7 +208,7 @@ import TreeSitterP4 P4StructFieldIdentifier(name: "count", withType: P4Int()), ]) let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(struct_type)) var test_values = VarValueScopes().enter() test_values = test_values.declare( @@ -248,7 +248,7 @@ import TreeSitterP4 let ts_fields = P4StructFields([P4StructFieldIdentifier(name: "ty", withType: ty_struct_type)]) let ts_struct_type = P4Struct(withName: Identifier(name: "outer"), andFields: ts_fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: ts_struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(ts_struct_type)) var test_values = VarValueScopes().enter() @@ -290,7 +290,7 @@ import TreeSitterP4 P4StructFieldIdentifier(name: "count", withType: P4Int()), ]) let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(struct_type)) var test_values = VarValueScopes().enter() test_values = test_values.declare( @@ -322,7 +322,7 @@ import TreeSitterP4 P4StructFieldIdentifier(name: "count", withType: P4Int()), ]) let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(struct_type)) #expect( #RequireErrorResult( @@ -357,7 +357,7 @@ import TreeSitterP4 let ts_fields = P4StructFields([P4StructFieldIdentifier(name: "ty", withType: ty_struct_type)]) let ts_struct_type = P4Struct(withName: Identifier(name: "outer"), andFields: ts_fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: ts_struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(ts_struct_type)) var test_values = VarValueScopes().enter() @@ -405,7 +405,7 @@ import TreeSitterP4 let ts_fields = P4StructFields([P4StructFieldIdentifier(name: "ty", withType: ty_struct_type)]) let ts_struct_type = P4Struct(withName: Identifier(name: "outer"), andFields: ts_fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: ts_struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(ts_struct_type)) var test_values = VarValueScopes().enter() @@ -452,7 +452,7 @@ import TreeSitterP4 let ts_fields = P4StructFields([P4StructFieldIdentifier(name: "ty", withType: ty_struct_type)]) let ts_struct_type = P4Struct(withName: Identifier(name: "outer"), andFields: ts_fields) - test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: ts_struct_type) + test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4TypeAttributed.Attributeless(ts_struct_type)) #expect( #RequireErrorResult( diff --git a/Tests/p4rseTests/ValueTypeParserTests.swift b/Tests/p4rseTests/ValueTypeParserTests.swift index de6155a..9c8072e 100644 --- a/Tests/p4rseTests/ValueTypeParserTests.swift +++ b/Tests/p4rseTests/ValueTypeParserTests.swift @@ -253,7 +253,7 @@ import TreeSitterP4 }; """ var test_types = VarTypeScopes().enter() - test_types = test_types.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int())) + test_types = test_types.declare(identifier: Identifier(name: "ta"), withValue: P4TypeAttributed.Attributeless(P4Array(withValueType: P4Int()))) #expect( #RequireErrorResult( Error(