compiler: Use Macro to Derive CompilableStatement Implementations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -90,16 +90,8 @@ extension BlockStatement: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension BlockStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension BlockStatement: CompilableStatement {}
|
||||
|
||||
extension ConditionalStatement: Compilable {
|
||||
public typealias C = ConditionalStatement
|
||||
@@ -173,16 +165,8 @@ extension ConditionalStatement: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension ConditionalStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension ConditionalStatement: CompilableStatement {}
|
||||
|
||||
extension VariableDeclarationStatement: Compilable {
|
||||
public typealias C = VariableDeclarationStatement
|
||||
@@ -279,16 +263,8 @@ extension VariableDeclarationStatement: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension VariableDeclarationStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension VariableDeclarationStatement: CompilableStatement {}
|
||||
|
||||
extension ExpressionStatement: Compilable {
|
||||
public typealias C = ExpressionStatement
|
||||
@@ -307,16 +283,8 @@ extension ExpressionStatement: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension ExpressionStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension ExpressionStatement: CompilableStatement {}
|
||||
|
||||
extension ParserAssignmentStatement: Compilable {
|
||||
public typealias C = ParserAssignmentStatement
|
||||
@@ -372,16 +340,8 @@ extension ParserAssignmentStatement: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension ParserAssignmentStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension ParserAssignmentStatement: CompilableStatement {}
|
||||
|
||||
extension ReturnStatement: Compilable {
|
||||
public typealias C = ReturnStatement
|
||||
@@ -410,16 +370,8 @@ extension ReturnStatement: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension ReturnStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension ReturnStatement: CompilableStatement {}
|
||||
|
||||
extension ApplyStatement: Compilable {
|
||||
public typealias C = ApplyStatement
|
||||
@@ -433,22 +385,14 @@ extension ApplyStatement: Compilable {
|
||||
|
||||
return switch BlockStatement.Compile(node: expression_node, withContext: context) {
|
||||
case .Ok(let statement):
|
||||
.Ok(ApplyStatement(statement as! BlockStatement))
|
||||
.Ok(ApplyStatement(statement))
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ApplyStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension ApplyStatement: CompilableStatement {}
|
||||
|
||||
extension Instantiation: Compilable {
|
||||
public typealias C = Instantiation
|
||||
@@ -582,13 +526,5 @@ extension Instantiation: Compilable {
|
||||
}
|
||||
}
|
||||
|
||||
extension Instantiation: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@deriveCompilableStatement
|
||||
extension Instantiation: CompilableStatement {}
|
||||
|
||||
Reference in New Issue
Block a user