compiler, runtime: Make Default Values Optional
For types, make it optional to return a default value. While default values for some types are meaningful, they are not meaningful for all types (e.g., Action, Control, Parser, Parser state, etc.). Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -64,8 +64,8 @@ public struct Action: CustomStringConvertible, P4Type, P4DataValue {
|
||||
}
|
||||
}
|
||||
|
||||
public func def() -> any Common.P4DataValue {
|
||||
return Action()
|
||||
public func def() -> P4DataValue? {
|
||||
return .none
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
@@ -284,15 +284,8 @@ public struct Control: P4Type, P4DataValue, Equatable, CustomStringConvertible {
|
||||
withActions: self.actions, withApply: self.apply)
|
||||
}
|
||||
|
||||
public func def() -> any P4DataValue {
|
||||
return Control(
|
||||
named: Identifier(name: ""),
|
||||
withParameters: ParameterList(),
|
||||
withTable: Table(
|
||||
withName: Identifier(name: "empty"),
|
||||
withPropertyList: TablePropertyList(
|
||||
withActions: TableActionsProperty(), withKeys: TableKeys())),
|
||||
withActions: Actions(withActions: []), withApply: ApplyStatement())
|
||||
public func def() -> P4DataValue? {
|
||||
return .none
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public struct Declaration: P4Type {
|
||||
}
|
||||
}
|
||||
|
||||
public func def() -> any Common.P4DataValue {
|
||||
public func def() -> P4DataValue? {
|
||||
/// TODO: Is a default of the extern'd type the right way to go?
|
||||
return self.identifier.type.baseType().def()
|
||||
}
|
||||
@@ -107,11 +107,8 @@ public struct FunctionDeclaration: P4Type, P4DataValue {
|
||||
}
|
||||
}
|
||||
|
||||
public func def() -> any Common.P4DataValue {
|
||||
return FunctionDeclaration(
|
||||
named: Identifier(name: ""), ofType: P4QualifiedType(P4Boolean()),
|
||||
withParameters: ParameterList([]),
|
||||
withBody: .none)
|
||||
public func def() -> P4DataValue? {
|
||||
return .none
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
|
||||
@@ -101,8 +101,8 @@ public class ParserState: P4Type, P4DataValue, Equatable, CustomStringConvertibl
|
||||
/// Construct a ParserState
|
||||
public init() {}
|
||||
|
||||
public func def() -> any P4DataValue {
|
||||
return ParserState()
|
||||
public func def() -> P4DataValue? {
|
||||
return .none
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,8 +353,8 @@ public struct Parser: P4Type, P4DataValue {
|
||||
return "Parser \(self.name) with parameters: \(parameters) and states: \(self.states)"
|
||||
}
|
||||
|
||||
public func def() -> any P4DataValue {
|
||||
return Parser(withName: Identifier(name: ""))
|
||||
public func def() -> P4DataValue? {
|
||||
return .none
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user