diff --git a/Sources/Common/Execution.swift b/Sources/Common/Execution.swift
index ea94a4d..a5e138f 100644
--- a/Sources/Common/Execution.swift
+++ b/Sources/Common/Execution.swift
@@ -16,7 +16,8 @@
// along with this program. If not, see .
public typealias StatementInterloper = (EvaluatableStatement, ControlFlow, ProgramExecution) -> Void
-public typealias ExpressionInterloper = (EvaluatableExpression, Result, ProgramExecution) -> Void
+public typealias ExpressionInterloper = (EvaluatableExpression, Result, ProgramExecution)
+ -> Void
open class ProgramExecution: CustomStringConvertible {
public var scopes: VarValueScopes = VarValueScopes()
@@ -75,7 +76,9 @@ open class ProgramExecution: CustomStringConvertible {
return self.statement_interloper
}
- public func setStatementInterloper(_ interloper: @escaping StatementInterloper) -> ProgramExecution {
+ public func setStatementInterloper(
+ _ interloper: @escaping StatementInterloper
+ ) -> ProgramExecution {
let pe = ProgramExecution(copy: self)
pe.statement_interloper = interloper
return pe
@@ -85,7 +88,9 @@ open class ProgramExecution: CustomStringConvertible {
return self.expression_interloper
}
- public func setExpressionInterloper(_ interloper: @escaping ExpressionInterloper) -> ProgramExecution {
+ public func setExpressionInterloper(
+ _ interloper: @escaping ExpressionInterloper
+ ) -> ProgramExecution {
let pe = ProgramExecution(copy: self)
pe.expression_interloper = interloper
return pe
@@ -138,7 +143,6 @@ open class ProgramExecution: CustomStringConvertible {
return new_pe
}
-
}
/// A scope that resolves variable identifiers to their values.
diff --git a/Sources/P4Compiler/Common.swift b/Sources/P4Compiler/Common.swift
index 694384b..b1100ea 100644
--- a/Sources/P4Compiler/Common.swift
+++ b/Sources/P4Compiler/Common.swift
@@ -363,8 +363,9 @@ func ContainsInvalidStatements(
return false
}
-func ContainsInvalidStatements(block: BlockStatement, invalids: [EvaluatableStatement.Type]) -> Bool {
- return block.statements.contains() { statement in
+func ContainsInvalidStatements(block: BlockStatement, invalids: [EvaluatableStatement.Type]) -> Bool
+{
+ return block.statements.contains { statement in
for es in invalids {
if type(of: statement) == es {
return true
@@ -372,4 +373,4 @@ func ContainsInvalidStatements(block: BlockStatement, invalids: [EvaluatableStat
}
return false
}
-}
\ No newline at end of file
+}
diff --git a/Sources/P4Compiler/Declarations.swift b/Sources/P4Compiler/Declarations.swift
index 638c641..ebfa01f 100644
--- a/Sources/P4Compiler/Declarations.swift
+++ b/Sources/P4Compiler/Declarations.swift
@@ -492,7 +492,7 @@ extension Control: CompilableDeclaration {
apply = (apply_statement as! ApplyStatement)
// The apply is the last thing in a control declaration.
- break;
+ break
} else {
return .Error(
ErrorOnNode(node: currentChild, withError: "Uknown node type in control declaration"))
@@ -603,7 +603,9 @@ extension Action: Compilable {
return .Ok(
(
- Action(named: action_name, withParameters: action_parameters, withBody: (action_body as! BlockStatement)),
+ Action(
+ named: action_name, withParameters: action_parameters,
+ withBody: (action_body as! BlockStatement)),
current_context
))
}
diff --git a/Sources/P4Compiler/Statement.swift b/Sources/P4Compiler/Statement.swift
index 301a180..fea358c 100644
--- a/Sources/P4Compiler/Statement.swift
+++ b/Sources/P4Compiler/Statement.swift
@@ -247,8 +247,8 @@ extension ExpressionStatement: CompilableStatement {
let expression_node = node.child(at: 0)!
return switch Expression.Compile(node: expression_node, withContext: context) {
- case .Ok(let expression): .Ok((ExpressionStatement(expression), context))
- case .Error(let e): .Error(e)
+ case .Ok(let expression): .Ok((ExpressionStatement(expression), context))
+ case .Error(let e): .Error(e)
}
}
}
@@ -340,7 +340,8 @@ extension ApplyStatement: CompilableStatement {
let expression_node = node.child(at: 1)!
return switch BlockStatement.Compile(node: expression_node, withContext: context) {
- case .Ok((let statement, let updated_context)): .Ok((ApplyStatement(statement as! BlockStatement), updated_context))
+ case .Ok((let statement, let updated_context)):
+ .Ok((ApplyStatement(statement as! BlockStatement), updated_context))
case .Error(let e): .Error(e)
}
}
diff --git a/Sources/P4Runtime/Common.swift b/Sources/P4Runtime/Common.swift
index f6fc9d9..de70e3d 100644
--- a/Sources/P4Runtime/Common.swift
+++ b/Sources/P4Runtime/Common.swift
@@ -84,7 +84,9 @@ public func Call(
return (.Ok(call_result), updated_execution.replaceScopes(inout_scopes))
}
-public typealias ExecuteStatementResultHandler = (ControlFlow, ProgramExecution) -> (ControlFlow, ProgramExecution)
+public typealias ExecuteStatementResultHandler = (ControlFlow, ProgramExecution) -> (
+ ControlFlow, ProgramExecution
+)
public func ExecuteStatement(
_ statements: [EvaluatableStatement], handleResult handler: ExecuteStatementResultHandler,
@@ -119,7 +121,8 @@ public func ExecuteStatement(
public func ExecuteStatement(
_ statement: EvaluatableStatement, handleResult handler: ExecuteStatementResultHandler,
- inExecution execution: ProgramExecution) -> (ControlFlow, ProgramExecution) {
+ inExecution execution: ProgramExecution
+) -> (ControlFlow, ProgramExecution) {
return ExecuteStatement([statement], handleResult: handler, inExecution: execution)
}
diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift
index 90c5d5d..db6946e 100644
--- a/Sources/P4Runtime/Expressions.swift
+++ b/Sources/P4Runtime/Expressions.swift
@@ -33,7 +33,8 @@ extension SelectExpression: EvaluatableExpression {
switch 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) = EvaluateExpression(sce.key, inExecution: updated_execution),
+ if case (.Ok(let kse), let updated_execution) = EvaluateExpression(
+ sce.key, inExecution: updated_execution),
kse.eq(selector_value)
{
//let result = sce.evaluate(execution: updated_execution)
diff --git a/Sources/P4Runtime/Parser.swift b/Sources/P4Runtime/Parser.swift
index e2db657..8223c8c 100644
--- a/Sources/P4Runtime/Parser.swift
+++ b/Sources/P4Runtime/Parser.swift
@@ -44,12 +44,12 @@ extension ParserStateDirectTransition: EvaluatableParserState {
) -> (any EvaluatableParserState, Common.ProgramExecution) {
var program = program.enter_scope()
-
- let (control_flow, next_execution) = ExecuteStatement(statements, handleResult: { (control_flow, execution) in
- return (control_flow, execution)
+ let (control_flow, next_execution) = ExecuteStatement(
+ statements,
+ handleResult: { (control_flow, execution) in
+ return (control_flow, execution)
}, inExecution: program)
-
switch control_flow {
case .Next: program = next_execution
case .Error: return (reject, next_execution.exit_scope())
@@ -105,11 +105,12 @@ extension ParserStateSelectTransition: EvaluatableParserState {
) -> (any EvaluatableParserState, Common.ProgramExecution) {
var program = program.enter_scope()
- let (control_flow, next_execution) = ExecuteStatement(statements, handleResult: { (control_flow, execution) in
- return (control_flow, execution)
+ let (control_flow, next_execution) = ExecuteStatement(
+ statements,
+ handleResult: { (control_flow, execution) in
+ return (control_flow, execution)
}, inExecution: program)
-
switch control_flow {
case .Next: program = next_execution
case .Error: return (reject, next_execution.exit_scope())
@@ -121,7 +122,6 @@ extension ParserStateSelectTransition: EvaluatableParserState {
)
}
-
//switch self.selectExpression.evaluate(execution: program) {
switch EvaluateExpression(self.selectExpression, inExecution: program) {
case (.Ok(let value), let program):
diff --git a/Sources/P4Runtime/Runtime.swift b/Sources/P4Runtime/Runtime.swift
index 0e2b45f..64e2fd1 100644
--- a/Sources/P4Runtime/Runtime.swift
+++ b/Sources/P4Runtime/Runtime.swift
@@ -55,7 +55,8 @@ public struct ParserRuntime: CustomStringConvertible {
}
- public func run(withArguments arguments: ArgumentList) -> Result<(ParserState, ProgramExecution)> {
+ public func run(withArguments arguments: ArgumentList) -> Result<(ParserState, ProgramExecution)>
+ {
let pe =
if let initial = initialValues {
ProgramExecution(withGlobalValues: initial)
@@ -67,14 +68,16 @@ public struct ParserRuntime: CustomStringConvertible {
}
/// Run the P4 parser on a given packet
- public func run(withArguments arguments: ArgumentList, inExecution pe: ProgramExecution) -> Result<(ParserState, ProgramExecution)>
- {
+ public func run(
+ withArguments arguments: ArgumentList, inExecution pe: ProgramExecution
+ ) -> Result<(ParserState, ProgramExecution)> {
- let pe = if let globals = initialValues {
- pe.setGlobalValues(globals)
- } else {
- pe
- }
+ let pe =
+ if let globals = initialValues {
+ pe.setGlobalValues(globals)
+ } else {
+ pe
+ }
let (end_state, execution) = parser.call(execution: pe, arguments: arguments)
if let error = execution.getError() {
diff --git a/Sources/P4Runtime/Statements.swift b/Sources/P4Runtime/Statements.swift
index 4400b0f..9e72d4b 100644
--- a/Sources/P4Runtime/Statements.swift
+++ b/Sources/P4Runtime/Statements.swift
@@ -44,7 +44,8 @@ extension VariableDeclarationStatement: EvaluatableStatement {
public func evaluate(execution: ProgramExecution) -> (ControlFlow, ProgramExecution) {
guard
//case (.Ok(let initial_value), let execution) = self.initializer.evaluate(execution: execution)
- case (.Ok(let initial_value), let execution) = EvaluateExpression(self.initializer, inExecution: execution)
+ case (.Ok(let initial_value), let execution) = EvaluateExpression(
+ self.initializer, inExecution: execution)
else {
return (
ControlFlow.Error,
@@ -61,7 +62,8 @@ extension ConditionalStatement: EvaluatableStatement {
public func evaluate(execution: ProgramExecution) -> (ControlFlow, ProgramExecution) {
guard
//case (.Ok(let evaluated_condition), let execution) = self.condition.evaluate(execution: execution)
- case (.Ok(let evaluated_condition), let execution) = EvaluateExpression(self.condition, inExecution: execution)
+ case (.Ok(let evaluated_condition), let execution) = EvaluateExpression(
+ self.condition, inExecution: execution)
else {
return (
ControlFlow.Error,