diff --git a/Sources/Cli/main.swift b/Sources/Cli/main.swift index 4f01b7b..08bf002 100644 --- a/Sources/Cli/main.swift +++ b/Sources/Cli/main.swift @@ -140,16 +140,16 @@ extension Cli { return } -/* - let maybe_codegen = P4Runtime.CodeGenerator().codeGen(program) - guard case .Ok(let codegen) = maybe_codegen else { - let formatter = FormatterAnsi() - print(ErrorWithLabel("Code Generation Error", maybe_codegen.error()!).format(formatter)) - return - } + /* + let maybe_codegen = P4Runtime.CodeGenerator().codeGen(program) + guard case .Ok(let codegen) = maybe_codegen else { + let formatter = FormatterAnsi() + print(ErrorWithLabel("Code Generation Error", maybe_codegen.error()!).format(formatter)) + return + } - print("\(codegen.getGeneratedCode())") - */ + print("\(codegen.getGeneratedCode())") + */ } } } diff --git a/Sources/P4Compiler/AST.swift b/Sources/P4Compiler/AST.swift index 8b3f94f..10b4965 100644 --- a/Sources/P4Compiler/AST.swift +++ b/Sources/P4Compiler/AST.swift @@ -309,7 +309,10 @@ public struct AST { public var tipe: AST.Identifier public let arguments: AST.ArgumentList - public init(named name: AST.Identifier, withType tipe: AST.Identifier, withArguments arguments: AST.ArgumentList) { + public init( + named name: AST.Identifier, withType tipe: AST.Identifier, + withArguments arguments: AST.ArgumentList + ) { self.name = name self.arguments = arguments self.tipe = tipe @@ -643,7 +646,9 @@ public struct ASTCompilerContext { public let lexical_context_statements: [AST.AnStatement]? public let extern_context: Bool - public init(_ name: AST.Identifier? = .none, _ stmts: [AST.AnStatement]? = .none, _ extern: Bool = false) { + public init( + _ name: AST.Identifier? = .none, _ stmts: [AST.AnStatement]? = .none, _ extern: Bool = false + ) { self.lexical_context_name = name self.lexical_context_statements = stmts self.extern_context = extern @@ -661,5 +666,3 @@ public struct ASTCompilerContext { return ASTCompilerContext(self.lexical_context_name, self.lexical_context_statements, extern) } } - - diff --git a/Sources/P4Compiler/Declarations.swift b/Sources/P4Compiler/Declarations.swift index a81ee7c..d52f342 100644 --- a/Sources/P4Compiler/Declarations.swift +++ b/Sources/P4Compiler/Declarations.swift @@ -93,7 +93,8 @@ extension AST.FunctionDeclaration: Compilable { sourceLocation: function_declaration_node.toSourceLocation(), withError: "Missing function declaration component"))) - let maybe_function_name = AST.Identifier.CompileExpression(node: current_node!, withContext: context) + let maybe_function_name = AST.Identifier.CompileExpression( + node: current_node!, withContext: context) guard case .Ok(let function_name) = maybe_function_name else { return .Error(maybe_function_name.error()!) } @@ -476,9 +477,11 @@ extension AST.Control: Compilable { )) } - return .Ok(AST.Control( - named: control_name as! AST.Identifier, withParameters: control_parameters, withTable: tables[0], - withActions: AST.Actions(withActions: actions), withApply: apply)) + return .Ok( + AST.Control( + named: control_name as! AST.Identifier, withParameters: control_parameters, + withTable: tables[0], + withActions: AST.Actions(withActions: actions), withApply: apply)) } } diff --git a/Sources/P4Compiler/Expression.swift b/Sources/P4Compiler/Expression.swift index 903008a..15347b6 100644 --- a/Sources/P4Compiler/Expression.swift +++ b/Sources/P4Compiler/Expression.swift @@ -133,7 +133,8 @@ extension AST.Expression: Compilable { let expression_parsers: [CompilableExpression.Type] = [ P4BooleanValue.self, P4StringValue.self, P4IntValue.self, AST.Identifier.self, - AST.BinaryOperatorExpression.self, AST.ArrayAccessExpression.self, AST.FieldAccessExpression.self, + AST.BinaryOperatorExpression.self, AST.ArrayAccessExpression.self, + AST.FieldAccessExpression.self, AST.FunctionCall.self, ] diff --git a/Sources/P4Compiler/Parser.swift b/Sources/P4Compiler/Parser.swift index f39e4e1..f6b95e7 100644 --- a/Sources/P4Compiler/Parser.swift +++ b/Sources/P4Compiler/Parser.swift @@ -39,7 +39,8 @@ extension AST.Statement: Compilable { "assignmentStatement": AST.ParserAssignmentStatement.self, "expressionStatement": AST.ExpressionStatement.self, "variableDeclaration": AST.VariableDeclarationStatement.self, - "conditionalStatement": AST.ConditionalStatement.self, "blockStatement": AST.BlockStatement.self, + "conditionalStatement": AST.ConditionalStatement.self, + "blockStatement": AST.BlockStatement.self, "return_statement": AST.ReturnStatement.self, ] guard let parser = statementParsers[statement.nodeType ?? ""] else { @@ -176,8 +177,9 @@ extension AST.ParserState: Compilable { sourceLocation: node.toSourceLocation(), withError: "Missing transition statement of state declaration"))) - let updated_context = context.update(withContextName: (state_identifier as! AST.Identifier)).update(withContextStatements: parsed_s) + let updated_context = context.update(withContextName: (state_identifier as! AST.Identifier)) + .update(withContextStatements: parsed_s) return AST.TransitionStatement.Compile(node: current_node!, withContext: updated_context) } -} \ No newline at end of file +} diff --git a/Sources/P4Compiler/Protocols.swift b/Sources/P4Compiler/Protocols.swift index 142f01e..abdbeae 100644 --- a/Sources/P4Compiler/Protocols.swift +++ b/Sources/P4Compiler/Protocols.swift @@ -61,7 +61,11 @@ public protocol ASTVisitor { func visit(node: AST.Identifier, driver: ASTVisitorDriver, context: T) -> Result func visit(node: AST.Parser, driver: ASTVisitorDriver, context: T) -> Result - func visit(node: AST.ParserStateDirectTransition, driver: ASTVisitorDriver, context: T) -> Result + func visit( + node: AST.ParserStateDirectTransition, driver: ASTVisitorDriver, context: T + ) -> Result func visit(node: AST.ParserStateNoTransition, driver: ASTVisitorDriver, context: T) -> Result - func visit(node: AST.ParserStateSelectTransition, driver: ASTVisitorDriver, context: T) -> Result -} \ No newline at end of file + func visit( + node: AST.ParserStateSelectTransition, driver: ASTVisitorDriver, context: T + ) -> Result +}