From ad7e5a6f6d68a1813ab174c7fdfb057c3d844742 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Thu, 9 Apr 2026 23:17:18 -0400 Subject: [PATCH] Make Formatter Happy Signed-off-by: Will Hawkins --- Sources/Common/Execution.swift | 10 +++++----- Sources/P4Compiler/Common.swift | 9 +++++---- Sources/P4Compiler/Expression.swift | 23 +++++++++++++---------- Sources/P4Compiler/Statement.swift | 2 +- Sources/P4Lang/Common.swift | 2 +- Sources/P4Lang/Expressions.swift | 2 +- Sources/P4Lang/Statement.swift | 2 +- Sources/P4Runtime/Common.swift | 2 +- Sources/P4Runtime/Expressions.swift | 11 +++++++---- Sources/P4Runtime/Parser.swift | 22 ++++++++++++++++------ Sources/P4Runtime/Statements.swift | 6 ++---- 11 files changed, 53 insertions(+), 38 deletions(-) diff --git a/Sources/Common/Execution.swift b/Sources/Common/Execution.swift index ce9968d..e6d1541 100644 --- a/Sources/Common/Execution.swift +++ b/Sources/Common/Execution.swift @@ -108,9 +108,9 @@ public typealias VarValueScopes = Scopes /// Indicate the control flow result of a particular statement. public enum ControlFlow { - case Next - case Continue - case Break - case Return(P4Value?) - case Error + case Next + case Continue + case Break + case Return(P4Value?) + case Error } diff --git a/Sources/P4Compiler/Common.swift b/Sources/P4Compiler/Common.swift index 3b2725a..84cf5a9 100644 --- a/Sources/P4Compiler/Common.swift +++ b/Sources/P4Compiler/Common.swift @@ -263,7 +263,8 @@ func argument_list_compiler( // Otherwise, there should be one argument left! switch Argument.Compile(node: currentChild!, withContext: context) { case .Ok(let (ce, updated_context)): - return Result.Ok((arguments.addArgument(Argument(ce, atIndex: arguments.count() + 1)), updated_context)) + return Result.Ok( + (arguments.addArgument(Argument(ce, atIndex: arguments.count() + 1)), updated_context)) case .Error(let e): return Result.Error(e) } } @@ -311,8 +312,8 @@ extension Argument: Compilable { let expression_node = node.child(at: 0)! return switch Expression.Compile(node: expression_node, withContext: context) { - case .Ok(let compiled_expression): .Ok((compiled_expression, context)) - case .Error(let e): .Error(e) + case .Ok(let compiled_expression): .Ok((compiled_expression, context)) + case .Error(let e): .Error(e) } } -} \ No newline at end of file +} diff --git a/Sources/P4Compiler/Expression.swift b/Sources/P4Compiler/Expression.swift index fc3eb85..fc81faa 100644 --- a/Sources/P4Compiler/Expression.swift +++ b/Sources/P4Compiler/Expression.swift @@ -163,7 +163,7 @@ struct Expression { let expression_parsers: [CompilableExpression.Type] = [ P4BooleanValue.self, P4StringValue.self, P4IntValue.self, TypedIdentifier.self, BinaryOperatorExpression.self, ArrayAccessExpression.self, FieldAccessExpression.self, - FunctionCall.self + FunctionCall.self, ] for candidate_expression_parser in expression_parsers { @@ -680,19 +680,22 @@ extension FunctionCall: CompilableExpression { return Result.Error(maybe_callee_name.error()!) } - let maybe_callee = switch context.types.lookup(identifier: callee_name) { - case .Ok(let looked_up): switch looked_up { - case let callee as FunctionDeclaration: Result.Ok(callee) // What we found is actually a function declaration - default: Result.Error(ErrorOnNode(node: currentChild!, withError: "\(callee_name) is not a function")) - } + let maybe_callee = + switch context.types.lookup(identifier: callee_name) { + case .Ok(let looked_up): + switch looked_up { + case let callee as FunctionDeclaration: Result.Ok(callee) // What we found is actually a function declaration + default: + Result.Error( + ErrorOnNode(node: currentChild!, withError: "\(callee_name) is not a function")) + } case .Error(let e): Result.Error(e) - } + } guard case .Ok(let callee) = maybe_callee else { return .Error(maybe_callee.error()!) } - currentChildIdx += 1 currentChildIdxSafe += 1 if expression.childCount < currentChildIdxSafe { @@ -702,8 +705,8 @@ extension FunctionCall: CompilableExpression { currentChild = expression.child(at: currentChildIdx) let maybe_argument_list = ArgumentList.Compile(node: currentChild!, withContext: context) - - guard case .Ok((let arguments, _)) = maybe_argument_list else { + + guard case .Ok((let arguments, _)) = maybe_argument_list else { return .Error(maybe_argument_list.error()!) } diff --git a/Sources/P4Compiler/Statement.swift b/Sources/P4Compiler/Statement.swift index de65988..da3a65b 100644 --- a/Sources/P4Compiler/Statement.swift +++ b/Sources/P4Compiler/Statement.swift @@ -314,4 +314,4 @@ extension ReturnStatement: CompilableStatement { case .Error(let e): .Error(e) } } -} \ No newline at end of file +} diff --git a/Sources/P4Lang/Common.swift b/Sources/P4Lang/Common.swift index 59fe267..d54643c 100644 --- a/Sources/P4Lang/Common.swift +++ b/Sources/P4Lang/Common.swift @@ -117,4 +117,4 @@ public struct Argument { self.argument = argument self.index = index } -} \ No newline at end of file +} diff --git a/Sources/P4Lang/Expressions.swift b/Sources/P4Lang/Expressions.swift index ba7a884..6492090 100644 --- a/Sources/P4Lang/Expressions.swift +++ b/Sources/P4Lang/Expressions.swift @@ -209,4 +209,4 @@ public struct FunctionCall { self.callee = callee self.arguments = arguments } -} \ No newline at end of file +} diff --git a/Sources/P4Lang/Statement.swift b/Sources/P4Lang/Statement.swift index a903cd8..15c1b3d 100644 --- a/Sources/P4Lang/Statement.swift +++ b/Sources/P4Lang/Statement.swift @@ -62,4 +62,4 @@ public struct ReturnStatement { public init(_ value: EvaluatableExpression) { self.value = value } -} \ No newline at end of file +} diff --git a/Sources/P4Runtime/Common.swift b/Sources/P4Runtime/Common.swift index 604a61a..7419abc 100644 --- a/Sources/P4Runtime/Common.swift +++ b/Sources/P4Runtime/Common.swift @@ -16,4 +16,4 @@ // along with this program. If not, see . import Common -import P4Lang \ No newline at end of file +import P4Lang diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift index 63dad0a..bfa6fd5 100644 --- a/Sources/P4Runtime/Expressions.swift +++ b/Sources/P4Runtime/Expressions.swift @@ -400,18 +400,21 @@ extension FunctionCall: EvaluatableExpression { guard case .Ok(let argument_value) = maybe_argument_value else { return .Error(Error(withMessage: "Cannot evaluate argument \(arg_idx): \(argument)")) } - called_execution = called_execution.declare(identifier: parameter.name, withValue: argument_value) + called_execution = called_execution.declare( + identifier: parameter.name, withValue: argument_value) } let (control_flow, _) = body.evaluate(execution: called_execution) return switch control_flow { - case ControlFlow.Return(let value): if let value = value { - .Ok(value) + case ControlFlow.Return(let value): + if let value = value { + .Ok(value) } else { .Error(Error(withMessage: "No value returned from called function (\(self.callee.name))")) } - default: .Error(Error(withMessage: "No value returned from called function (\(self.callee.name))")) + default: + .Error(Error(withMessage: "No value returned from called function (\(self.callee.name))")) } } diff --git a/Sources/P4Runtime/Parser.swift b/Sources/P4Runtime/Parser.swift index fdee834..036ceec 100644 --- a/Sources/P4Runtime/Parser.swift +++ b/Sources/P4Runtime/Parser.swift @@ -45,9 +45,14 @@ extension ParserStateDirectTransition: EvaluatableParserState { for statement in statements { let (control_flow, next_program) = statement.evaluate(execution: program) switch control_flow { - case .Next: program = next_program // Ok! - case .Error: return (reject, next_program) - default: return (reject, next_program.setError(error: Error(withMessage: "Invalid control flow (\(control_flow) in parser)"))) + case .Next: program = next_program // Ok! + case .Error: return (reject, next_program) + default: + return ( + reject, + next_program.setError( + error: Error(withMessage: "Invalid control flow (\(control_flow) in parser)")) + ) } } let res = program.scopes.lookup(identifier: get_next_state()) @@ -100,9 +105,14 @@ extension ParserStateSelectTransition: EvaluatableParserState { for statement in statements { let (control_flow, next_program) = statement.evaluate(execution: program) switch control_flow { - case .Next: program = next_program // Ok! - case .Error: return (reject, next_program) - default: return (reject, next_program.setError(error: Error(withMessage: "Invalid control flow (\(control_flow) in parser)"))) + case .Next: program = next_program // Ok! + case .Error: return (reject, next_program) + default: + return ( + reject, + next_program.setError( + error: Error(withMessage: "Invalid control flow (\(control_flow) in parser)")) + ) } } diff --git a/Sources/P4Runtime/Statements.swift b/Sources/P4Runtime/Statements.swift index c7acc9c..3213d98 100644 --- a/Sources/P4Runtime/Statements.swift +++ b/Sources/P4Runtime/Statements.swift @@ -108,10 +108,8 @@ extension ExpressionStatement: EvaluatableStatement { extension ReturnStatement: EvaluatableStatement { public func evaluate(execution: ProgramExecution) -> (ControlFlow, ProgramExecution) { return switch self.value.evaluate(execution: execution) { - case .Ok(let v): (ControlFlow.Return(v), execution) - case .Error(let e): (ControlFlow.Error, execution.setError(error: e)) + case .Ok(let v): (ControlFlow.Return(v), execution) + case .Error(let e): (ControlFlow.Error, execution.setError(error: e)) } } } - -