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:
Will Hawkins
2026-05-04 08:35:33 -04:00
parent 5cfe5532a2
commit b49ec104e9
8 changed files with 55 additions and 44 deletions
+3 -6
View File
@@ -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 {