From 99d3d2bace69eea633df0185836926f7792137cf Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Mon, 20 Apr 2026 16:29:59 -0400 Subject: [PATCH] Make Formatter Happy Signed-off-by: Will Hawkins --- Sources/Common/Execution.swift | 2 -- Sources/Common/Protocols.swift | 6 +++--- Sources/P4Runtime/Common.swift | 4 ++-- Sources/P4Runtime/Expressions.swift | 32 +++++++++++++++++++---------- Sources/P4Runtime/Parser.swift | 3 ++- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Sources/Common/Execution.swift b/Sources/Common/Execution.swift index a4f932a..6ff030e 100644 --- a/Sources/Common/Execution.swift +++ b/Sources/Common/Execution.swift @@ -15,8 +15,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - - public typealias ExecuteStatementResultHandler = (ControlFlow, ProgramExecution) -> ( ControlFlow, ProgramExecution ) diff --git a/Sources/Common/Protocols.swift b/Sources/Common/Protocols.swift index 2f9c1ad..3cee68b 100644 --- a/Sources/Common/Protocols.swift +++ b/Sources/Common/Protocols.swift @@ -59,14 +59,14 @@ public protocol ProgramExecutionEvaluator { func ExecuteStatement( _ statements: [EvaluatableStatement], handleResult handler: ExecuteStatementResultHandler, inExecution execution: ProgramExecution, - ) -> (ControlFlow, ProgramExecution); + ) -> (ControlFlow, ProgramExecution) func ExecuteStatement( _ statement: EvaluatableStatement, handleResult handler: ExecuteStatementResultHandler, inExecution execution: ProgramExecution - ) -> (ControlFlow, ProgramExecution); + ) -> (ControlFlow, ProgramExecution) func EvaluateExpression( _ expression: EvaluatableExpression, inExecution execution: ProgramExecution, ) -> (Result, ProgramExecution) -} \ No newline at end of file +} diff --git a/Sources/P4Runtime/Common.swift b/Sources/P4Runtime/Common.swift index 8926de9..71e4b76 100644 --- a/Sources/P4Runtime/Common.swift +++ b/Sources/P4Runtime/Common.swift @@ -33,7 +33,8 @@ public func Call( let arg_idx = argument.index let arg_value = argument.argument //let maybe_argument_value = arg_value.evaluate(execution: called_execution) - let maybe_argument_value = called_execution.evaluator.EvaluateExpression(arg_value, inExecution: called_execution) + let maybe_argument_value = called_execution.evaluator.EvaluateExpression( + arg_value, inExecution: called_execution) guard case (.Ok(let argument_value), let updated_execution) = maybe_argument_value else { return ( .Error(Error(withMessage: "Cannot evaluate argument \(arg_idx): \(argument)")), @@ -83,4 +84,3 @@ public func Call( } return (.Ok(call_result), updated_execution.replaceScopes(inout_scopes)) } - diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift index bc4cf51..18e7015 100644 --- a/Sources/P4Runtime/Expressions.swift +++ b/Sources/P4Runtime/Expressions.swift @@ -33,12 +33,14 @@ extension SelectExpression: EvaluatableExpression { switch execution.evaluator.EvaluateExpression(self.selector, inExecution: execution) { case (.Ok(let selector_value), let updated_execution): for sce in self.case_expressions { - if case (.Ok(let kse), let updated_execution) = updated_execution.evaluator.EvaluateExpression( - sce.key, inExecution: updated_execution), + if case (.Ok(let kse), let updated_execution) = updated_execution.evaluator + .EvaluateExpression( + sce.key, inExecution: updated_execution), kse.eq(selector_value) { //let result = sce.evaluate(execution: updated_execution) - let result = updated_execution.evaluator.EvaluateExpression(sce, inExecution: updated_execution) + let result = updated_execution.evaluator.EvaluateExpression( + sce, inExecution: updated_execution) return result } } @@ -212,13 +214,15 @@ extension BinaryOperatorExpression: EvaluatableExpression { public func evaluate(execution: ProgramExecution) -> (Result, ProgramExecution) { let updated_execution = execution //let maybe_evaluated_left = self.left.evaluate(execution: updated_execution) - let maybe_evaluated_left = updated_execution.evaluator.EvaluateExpression(self.left, inExecution: updated_execution) + let maybe_evaluated_left = updated_execution.evaluator.EvaluateExpression( + self.left, inExecution: updated_execution) guard case (.Ok(let evaluated_left), let updated_execution) = maybe_evaluated_left else { return maybe_evaluated_left } //let maybe_evaluated_right = self.right.evaluate(execution: updated_execution) - let maybe_evaluated_right = updated_execution.evaluator.EvaluateExpression(self.right, inExecution: updated_execution) + let maybe_evaluated_right = updated_execution.evaluator.EvaluateExpression( + self.right, inExecution: updated_execution) guard case (.Ok(let evaluated_right), let updated_execution) = maybe_evaluated_right else { return maybe_evaluated_right } @@ -235,13 +239,15 @@ extension ArrayAccessExpression: EvaluatableExpression { public func evaluate(execution: ProgramExecution) -> (Result, ProgramExecution) { let updated_execution = execution //let maybe_name = self.name.evaluate(execution: updated_execution) - let maybe_name = updated_execution.evaluator.EvaluateExpression(self.name, inExecution: updated_execution) + let maybe_name = updated_execution.evaluator.EvaluateExpression( + self.name, inExecution: updated_execution) guard case (.Ok(let name), let updated_execution) = maybe_name else { return maybe_name } //let maybe_indexor = self.indexor.evaluate(execution: updated_execution) - let maybe_indexor = updated_execution.evaluator.EvaluateExpression(self.indexor, inExecution: updated_execution) + let maybe_indexor = updated_execution.evaluator.EvaluateExpression( + self.indexor, inExecution: updated_execution) guard case (.Ok(let indexor), let updated_execution) = maybe_indexor else { return maybe_indexor } @@ -271,7 +277,8 @@ extension ArrayAccessExpression: EvaluatableLValueExpression { let updated_execution = execution //let maybe_value = self.name.evaluate(execution: updated_execution) - let maybe_value = updated_execution.evaluator.EvaluateExpression(self.name, inExecution: updated_execution) + let maybe_value = updated_execution.evaluator.EvaluateExpression( + self.name, inExecution: updated_execution) guard case (.Ok(let value), let updated_execution) = maybe_value else { return .Error( Error(withMessage: "\(self.name) cannot be evaluated: \(maybe_value.0.error()!)")) @@ -282,7 +289,8 @@ extension ArrayAccessExpression: EvaluatableLValueExpression { // Now, get the indexor! //let maybe_indexor_value = self.indexor.evaluate(execution: updated_execution) - let maybe_indexor_value = updated_execution.evaluator.EvaluateExpression(self.indexor, inExecution: updated_execution) + let maybe_indexor_value = updated_execution.evaluator.EvaluateExpression( + self.indexor, inExecution: updated_execution) guard case (.Ok(let indexor_value), let updated_execution) = maybe_indexor_value else { return Result.Error( Error(withMessage: "\(self.indexor) cannot be evaluated: \(maybe_indexor_value.0.error()!)") @@ -349,7 +357,8 @@ extension FieldAccessExpression: EvaluatableExpression { let updated_execution = execution //let maybe_struct = self.strct.evaluate(execution: updated_execution) - let maybe_struct = updated_execution.evaluator.EvaluateExpression(self.strct, inExecution: updated_execution) + let maybe_struct = updated_execution.evaluator.EvaluateExpression( + self.strct, inExecution: updated_execution) guard case (.Ok(let strct), let updated_execution) = maybe_struct else { return maybe_struct } @@ -384,7 +393,8 @@ extension FieldAccessExpression: EvaluatableLValueExpression { let updated_execution = execution // First, evaluate strct_id and make sure that it names a struct. //let maybe_value = self.strct.evaluate(execution: updated_execution) - let maybe_value = updated_execution.evaluator.EvaluateExpression(self.strct, inExecution: updated_execution) + let maybe_value = updated_execution.evaluator.EvaluateExpression( + self.strct, inExecution: updated_execution) guard case (.Ok(let value), let updated_execution) = maybe_value else { return .Error( Error(withMessage: "\(self.strct) cannot be evaluated: \(maybe_value.0.error()!)")) diff --git a/Sources/P4Runtime/Parser.swift b/Sources/P4Runtime/Parser.swift index e03bcb5..ad04782 100644 --- a/Sources/P4Runtime/Parser.swift +++ b/Sources/P4Runtime/Parser.swift @@ -22,7 +22,8 @@ extension ParserAssignmentStatement: EvaluatableStatement { public func evaluate(execution: ProgramExecution) -> (ControlFlow, ProgramExecution) { let updated_execution = execution //let result = self.value.evaluate(execution: updated_execution) - let result = updated_execution.evaluator.EvaluateExpression(self.value, inExecution: updated_execution) + let result = updated_execution.evaluator.EvaluateExpression( + self.value, inExecution: updated_execution) guard case (.Ok(let value), let updated_execution) = result else { return (ControlFlow.Error, execution.setError(error: result.0.error()!)) }