language: Check For Incorrect Order For Action Parameters
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -614,6 +614,17 @@ extension Action: Compilable {
|
|||||||
}
|
}
|
||||||
current_context = updated_context
|
current_context = updated_context
|
||||||
|
|
||||||
|
// Check whether the parameters are in the proper order.
|
||||||
|
let remaining_parameters = action_parameters.parameters.drop(while: {
|
||||||
|
$0.type.direction() != .none
|
||||||
|
})
|
||||||
|
if remaining_parameters.contains(where: { $0.type.direction() != .none }) {
|
||||||
|
return .Error(
|
||||||
|
ErrorWithLocation(
|
||||||
|
sourceLocation: current_node!.toSourceLocation(),
|
||||||
|
withError: "All parameters with direction must precede directionless parameters"))
|
||||||
|
}
|
||||||
|
|
||||||
walker.next()
|
walker.next()
|
||||||
#MustOr(
|
#MustOr(
|
||||||
result: current_node, thing: walker.getNext(),
|
result: current_node, thing: walker.getNext(),
|
||||||
|
|||||||
@@ -18,12 +18,12 @@
|
|||||||
import Common
|
import Common
|
||||||
import Foundation
|
import Foundation
|
||||||
import Macros
|
import Macros
|
||||||
|
import P4Lang
|
||||||
import Runtime
|
import Runtime
|
||||||
import SwiftTreeSitter
|
import SwiftTreeSitter
|
||||||
import Testing
|
import Testing
|
||||||
import TreeSitter
|
import TreeSitter
|
||||||
import TreeSitterP4
|
import TreeSitterP4
|
||||||
import P4Lang
|
|
||||||
|
|
||||||
@testable import P4Compiler
|
@testable import P4Compiler
|
||||||
|
|
||||||
@@ -320,3 +320,80 @@ import P4Lang
|
|||||||
Program.Compile(simple_parser_declaration))
|
Program.Compile(simple_parser_declaration))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func test_simple_control_declaration_with_action_with_params_right_order() async throws {
|
||||||
|
let simple_parser_declaration = """
|
||||||
|
control simple(int x, int y) {
|
||||||
|
action a(inout int ax, bool ay) {
|
||||||
|
ax = 5;
|
||||||
|
}
|
||||||
|
table t {
|
||||||
|
key = {
|
||||||
|
x: exact;
|
||||||
|
y: exact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apply {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
|
||||||
|
let x = { (tipe: P4QualifiedType) -> Bool in
|
||||||
|
switch tipe.baseType() {
|
||||||
|
case let c as Control: c.name == "simple"
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||||
|
#expect(program.InstancesWithTypes(x).count == 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func test_simple_control_declaration_with_action_with_params_wrong_order() async throws {
|
||||||
|
let simple_parser_declaration = """
|
||||||
|
control simple(int x, int y) {
|
||||||
|
action a(int ax, inout bool ay) {
|
||||||
|
ay = false;
|
||||||
|
}
|
||||||
|
table t {
|
||||||
|
key = {
|
||||||
|
x: exact;
|
||||||
|
y: exact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apply {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
#expect(
|
||||||
|
#RequireErrorResult(
|
||||||
|
ErrorWithLocation(
|
||||||
|
sourceLocation: SourceLocation(41, 23),
|
||||||
|
withError: "All parameters with direction must precede directionless parameters"),
|
||||||
|
Program.Compile(simple_parser_declaration))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func test_simple_control_declaration_with_action_with_params_wrong_order_interspersed() async throws {
|
||||||
|
let simple_parser_declaration = """
|
||||||
|
control simple(int x, int y) {
|
||||||
|
action a(inout bool aa, int ax, inout bool ay) {
|
||||||
|
aa = false;
|
||||||
|
}
|
||||||
|
table t {
|
||||||
|
key = {
|
||||||
|
x: exact;
|
||||||
|
y: exact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apply {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
#expect(
|
||||||
|
#RequireErrorResult(
|
||||||
|
ErrorWithLocation(
|
||||||
|
sourceLocation: SourceLocation(41, 38),
|
||||||
|
withError: "All parameters with direction must precede directionless parameters"),
|
||||||
|
Program.Compile(simple_parser_declaration))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user