Commit 6b61f9c4 authored by Kenton Varda's avatar Kenton Varda

Cleanup: enum value -> enumerant

parent 5a19e0a1
...@@ -202,7 +202,7 @@ compileValue _ (BuiltinType BuiltinData) (StringFieldValue x) = ...@@ -202,7 +202,7 @@ compileValue _ (BuiltinType BuiltinData) (StringFieldValue x) =
compileValue pos (EnumType desc) (IdentifierFieldValue name) = compileValue pos (EnumType desc) (IdentifierFieldValue name) =
case lookupMember name (enumMemberMap desc) of case lookupMember name (enumMemberMap desc) of
Just (DescEnumValue value) -> succeed (EnumValueValueDesc value) Just (DescEnumerant value) -> succeed (EnumerantValueDesc value)
_ -> makeError pos (printf "Enum type '%s' has no value '%s'." (enumName desc) name) _ -> makeError pos (printf "Enum type '%s' has no value '%s'." (enumName desc) name)
compileValue pos (StructType desc) (RecordFieldValue fields) = do compileValue pos (StructType desc) (RecordFieldValue fields) = do
...@@ -248,7 +248,7 @@ compileValue pos (BuiltinType BuiltinFloat64) _ = makeExpectError pos "number" ...@@ -248,7 +248,7 @@ compileValue pos (BuiltinType BuiltinFloat64) _ = makeExpectError pos "number"
compileValue pos (BuiltinType BuiltinText) _ = makeExpectError pos "string" compileValue pos (BuiltinType BuiltinText) _ = makeExpectError pos "string"
compileValue pos (BuiltinType BuiltinData) _ = makeExpectError pos "string" compileValue pos (BuiltinType BuiltinData) _ = makeExpectError pos "string"
compileValue pos (EnumType _) _ = makeExpectError pos "enum value name" compileValue pos (EnumType _) _ = makeExpectError pos "enumerant name"
compileValue pos (StructType _) _ = makeExpectError pos "parenthesized list of field assignments" compileValue pos (StructType _) _ = makeExpectError pos "parenthesized list of field assignments"
compileValue pos (InterfaceType _) _ = makeError pos "Interfaces can't have default values." compileValue pos (InterfaceType _) _ = makeError pos "Interfaces can't have default values."
compileValue pos (ListType _) _ = makeExpectError pos "list" compileValue pos (ListType _) _ = makeExpectError pos "list"
...@@ -580,33 +580,33 @@ compileDecl scope (EnumDecl (Located _ name) annotations decls) = ...@@ -580,33 +580,33 @@ compileDecl scope (EnumDecl (Located _ name) annotations decls) =
CompiledStatementStatus name (feedback (\desc -> do CompiledStatementStatus name (feedback (\desc -> do
(members, memberMap) <- compileChildDecls desc decls (members, memberMap) <- compileChildDecls desc decls
requireNoDuplicateNames decls requireNoDuplicateNames decls
let numbers = [ num | EnumValueDecl _ num _ <- decls ] let numbers = [ num | EnumerantDecl _ num _ <- decls ]
requireSequentialNumbering "Enum values" numbers requireSequentialNumbering "Enumerants" numbers
requireOrdinalsInRange numbers requireOrdinalsInRange numbers
(theId, compiledAnnotations) <- compileAnnotations scope EnumAnnotation annotations (theId, compiledAnnotations) <- compileAnnotations scope EnumAnnotation annotations
return (DescEnum EnumDesc return (DescEnum EnumDesc
{ enumName = name { enumName = name
, enumId = theId , enumId = theId
, enumParent = scope , enumParent = scope
, enumValues = [d | DescEnumValue d <- members] , enumerants = [d | DescEnumerant d <- members]
, enumAnnotations = compiledAnnotations , enumAnnotations = compiledAnnotations
, enumMemberMap = memberMap , enumMemberMap = memberMap
, enumStatements = members , enumStatements = members
}))) })))
compileDecl scope@(DescEnum parent) compileDecl scope@(DescEnum parent)
(EnumValueDecl (Located _ name) (Located _ number) annotations) = (EnumerantDecl (Located _ name) (Located _ number) annotations) =
CompiledStatementStatus name (do CompiledStatementStatus name (do
(theId, compiledAnnotations) <- compileAnnotations scope EnumValueAnnotation annotations (theId, compiledAnnotations) <- compileAnnotations scope EnumerantAnnotation annotations
return (DescEnumValue EnumValueDesc return (DescEnumerant EnumerantDesc
{ enumValueName = name { enumerantName = name
, enumValueId = theId , enumerantId = theId
, enumValueParent = parent , enumerantParent = parent
, enumValueNumber = number , enumerantNumber = number
, enumValueAnnotations = compiledAnnotations , enumerantAnnotations = compiledAnnotations
})) }))
compileDecl _ (EnumValueDecl (Located pos name) _ _) = compileDecl _ (EnumerantDecl (Located pos name) _ _) =
CompiledStatementStatus name (makeError pos "Enum values can only appear inside enums.") CompiledStatementStatus name (makeError pos "Enumerants can only appear inside enums.")
compileDecl scope (StructDecl (Located _ name) annotations decls) = compileDecl scope (StructDecl (Located _ name) annotations decls) =
CompiledStatementStatus name (feedback (\desc -> do CompiledStatementStatus name (feedback (\desc -> do
......
...@@ -153,7 +153,7 @@ isDefaultZero (UInt32Desc i) = i == 0 ...@@ -153,7 +153,7 @@ isDefaultZero (UInt32Desc i) = i == 0
isDefaultZero (UInt64Desc i) = i == 0 isDefaultZero (UInt64Desc i) = i == 0
isDefaultZero (Float32Desc x) = x == 0 isDefaultZero (Float32Desc x) = x == 0
isDefaultZero (Float64Desc x) = x == 0 isDefaultZero (Float64Desc x) = x == 0
isDefaultZero (EnumValueValueDesc v) = enumValueNumber v == 0 isDefaultZero (EnumerantValueDesc v) = enumerantNumber v == 0
isDefaultZero (TextDesc _) = error "Can't call isDefaultZero on aggregate types." isDefaultZero (TextDesc _) = error "Can't call isDefaultZero on aggregate types."
isDefaultZero (DataDesc _) = error "Can't call isDefaultZero on aggregate types." isDefaultZero (DataDesc _) = error "Can't call isDefaultZero on aggregate types."
isDefaultZero (StructValueDesc _) = error "Can't call isDefaultZero on aggregate types." isDefaultZero (StructValueDesc _) = error "Can't call isDefaultZero on aggregate types."
...@@ -171,7 +171,7 @@ defaultMask (UInt32Desc i) = show i ++ "u" ...@@ -171,7 +171,7 @@ defaultMask (UInt32Desc i) = show i ++ "u"
defaultMask (UInt64Desc i) = show i ++ "llu" defaultMask (UInt64Desc i) = show i ++ "llu"
defaultMask (Float32Desc x) = show (floatToWord x) ++ "u" defaultMask (Float32Desc x) = show (floatToWord x) ++ "u"
defaultMask (Float64Desc x) = show (doubleToWord x) ++ "ul" defaultMask (Float64Desc x) = show (doubleToWord x) ++ "ul"
defaultMask (EnumValueValueDesc v) = show (enumValueNumber v) defaultMask (EnumerantValueDesc v) = show (enumerantNumber v)
defaultMask (TextDesc _) = error "Can't call defaultMask on aggregate types." defaultMask (TextDesc _) = error "Can't call defaultMask on aggregate types."
defaultMask (DataDesc _) = error "Can't call defaultMask on aggregate types." defaultMask (DataDesc _) = error "Can't call defaultMask on aggregate types."
defaultMask (StructValueDesc _) = error "Can't call defaultMask on aggregate types." defaultMask (StructValueDesc _) = error "Can't call defaultMask on aggregate types."
...@@ -189,14 +189,14 @@ elementType _ = error "Called elementType on non-list." ...@@ -189,14 +189,14 @@ elementType _ = error "Called elementType on non-list."
repeatedlyTake _ [] = [] repeatedlyTake _ [] = []
repeatedlyTake n l = take n l : repeatedlyTake n (drop n l) repeatedlyTake n l = take n l : repeatedlyTake n (drop n l)
enumValueContext parent desc = mkStrContext context where enumerantContext parent desc = mkStrContext context where
context "enumValueName" = MuVariable $ toUpperCaseWithUnderscores $ enumValueName desc context "enumerantName" = MuVariable $ toUpperCaseWithUnderscores $ enumerantName desc
context "enumValueNumber" = MuVariable $ enumValueNumber desc context "enumerantNumber" = MuVariable $ enumerantNumber desc
context s = parent s context s = parent s
enumContext parent desc = mkStrContext context where enumContext parent desc = mkStrContext context where
context "enumName" = MuVariable $ enumName desc context "enumName" = MuVariable $ enumName desc
context "enumValues" = MuList $ map (enumValueContext context) $ enumValues desc context "enumerants" = MuList $ map (enumerantContext context) $ enumerants desc
context s = parent s context s = parent s
defaultBytesContext :: Monad m => (String -> MuType m) -> TypeDesc -> [Word8] -> MuContext m defaultBytesContext :: Monad m => (String -> MuType m) -> TypeDesc -> [Word8] -> MuContext m
......
...@@ -68,7 +68,7 @@ paramImports (ParamDecl _ t ann _) = typeImports t ++ concatMap annotationImport ...@@ -68,7 +68,7 @@ paramImports (ParamDecl _ t ann _) = typeImports t ++ concatMap annotationImport
data AnnotationTarget = FileAnnotation data AnnotationTarget = FileAnnotation
| ConstantAnnotation | ConstantAnnotation
| EnumAnnotation | EnumAnnotation
| EnumValueAnnotation | EnumerantAnnotation
| StructAnnotation | StructAnnotation
| FieldAnnotation | FieldAnnotation
| UnionAnnotation | UnionAnnotation
...@@ -82,7 +82,7 @@ instance Show AnnotationTarget where ...@@ -82,7 +82,7 @@ instance Show AnnotationTarget where
show FileAnnotation = "file" show FileAnnotation = "file"
show ConstantAnnotation = "const" show ConstantAnnotation = "const"
show EnumAnnotation = "enum" show EnumAnnotation = "enum"
show EnumValueAnnotation = "enumerant" show EnumerantAnnotation = "enumerant"
show StructAnnotation = "struct" show StructAnnotation = "struct"
show FieldAnnotation = "field" show FieldAnnotation = "field"
show UnionAnnotation = "union" show UnionAnnotation = "union"
...@@ -94,7 +94,7 @@ instance Show AnnotationTarget where ...@@ -94,7 +94,7 @@ instance Show AnnotationTarget where
data Declaration = AliasDecl (Located String) DeclName data Declaration = AliasDecl (Located String) DeclName
| ConstantDecl (Located String) TypeExpression [Annotation] (Located FieldValue) | ConstantDecl (Located String) TypeExpression [Annotation] (Located FieldValue)
| EnumDecl (Located String) [Annotation] [Declaration] | EnumDecl (Located String) [Annotation] [Declaration]
| EnumValueDecl (Located String) (Located Integer) [Annotation] | EnumerantDecl (Located String) (Located Integer) [Annotation]
| StructDecl (Located String) [Annotation] [Declaration] | StructDecl (Located String) [Annotation] [Declaration]
| FieldDecl (Located String) (Located Integer) | FieldDecl (Located String) (Located Integer)
TypeExpression [Annotation] (Maybe (Located FieldValue)) TypeExpression [Annotation] (Maybe (Located FieldValue))
...@@ -109,7 +109,7 @@ declarationName :: Declaration -> Maybe (Located String) ...@@ -109,7 +109,7 @@ declarationName :: Declaration -> Maybe (Located String)
declarationName (AliasDecl n _) = Just n declarationName (AliasDecl n _) = Just n
declarationName (ConstantDecl n _ _ _) = Just n declarationName (ConstantDecl n _ _ _) = Just n
declarationName (EnumDecl n _ _) = Just n declarationName (EnumDecl n _ _) = Just n
declarationName (EnumValueDecl n _ _) = Just n declarationName (EnumerantDecl n _ _) = Just n
declarationName (StructDecl n _ _) = Just n declarationName (StructDecl n _ _) = Just n
declarationName (FieldDecl n _ _ _ _) = Just n declarationName (FieldDecl n _ _ _ _) = Just n
declarationName (UnionDecl n _ _ _) = Just n declarationName (UnionDecl n _ _ _) = Just n
...@@ -121,7 +121,7 @@ declImports :: Declaration -> [Located String] ...@@ -121,7 +121,7 @@ declImports :: Declaration -> [Located String]
declImports (AliasDecl _ name) = maybeToList (declNameImport name) declImports (AliasDecl _ name) = maybeToList (declNameImport name)
declImports (ConstantDecl _ t ann _) = typeImports t ++ concatMap annotationImports ann declImports (ConstantDecl _ t ann _) = typeImports t ++ concatMap annotationImports ann
declImports (EnumDecl _ ann decls) = concatMap annotationImports ann ++ concatMap declImports decls declImports (EnumDecl _ ann decls) = concatMap annotationImports ann ++ concatMap declImports decls
declImports (EnumValueDecl _ _ ann) = concatMap annotationImports ann declImports (EnumerantDecl _ _ ann) = concatMap annotationImports ann
declImports (StructDecl _ ann decls) = concatMap annotationImports ann ++ declImports (StructDecl _ ann decls) = concatMap annotationImports ann ++
concatMap declImports decls concatMap declImports decls
declImports (FieldDecl _ _ t ann _) = typeImports t ++ concatMap annotationImports ann declImports (FieldDecl _ _ t ann _) = typeImports t ++ concatMap annotationImports ann
......
...@@ -120,7 +120,6 @@ structKeyword = tokenParser (matchSimpleToken StructKeyword) <?> "\"struct\"" ...@@ -120,7 +120,6 @@ structKeyword = tokenParser (matchSimpleToken StructKeyword) <?> "\"struct\""
unionKeyword = tokenParser (matchSimpleToken UnionKeyword) <?> "\"union\"" unionKeyword = tokenParser (matchSimpleToken UnionKeyword) <?> "\"union\""
interfaceKeyword = tokenParser (matchSimpleToken InterfaceKeyword) <?> "\"interface\"" interfaceKeyword = tokenParser (matchSimpleToken InterfaceKeyword) <?> "\"interface\""
annotationKeyword = tokenParser (matchSimpleToken AnnotationKeyword) <?> "\"annotation\"" annotationKeyword = tokenParser (matchSimpleToken AnnotationKeyword) <?> "\"annotation\""
onKeyword = tokenParser (matchSimpleToken OnKeyword) <?> "\"on\""
parenthesizedList parser = do parenthesizedList parser = do
items <- tokenParser (matchUnary ParenthesizedList) items <- tokenParser (matchUnary ParenthesizedList)
...@@ -201,13 +200,13 @@ enumDecl statements = do ...@@ -201,13 +200,13 @@ enumDecl statements = do
return (EnumDecl name annotations children) return (EnumDecl name annotations children)
enumLine :: Maybe [Located Statement] -> TokenParser Declaration enumLine :: Maybe [Located Statement] -> TokenParser Declaration
enumLine Nothing = enumValueDecl enumLine Nothing = enumerantDecl
enumLine (Just _) = fail "Blocks not allowed here." enumLine (Just _) = fail "Blocks not allowed here."
enumValueDecl = do enumerantDecl = do
(name, value) <- nameWithOrdinal (name, value) <- nameWithOrdinal
annotations <- many annotation annotations <- many annotation
return (EnumValueDecl name value annotations) return (EnumerantDecl name value annotations)
structDecl statements = do structDecl statements = do
structKeyword structKeyword
...@@ -313,7 +312,7 @@ annotationTarget = (constKeyword >> return ConstantAnnotation) ...@@ -313,7 +312,7 @@ annotationTarget = (constKeyword >> return ConstantAnnotation)
name <- varIdentifier name <- varIdentifier
case name of case name of
"file" -> return FileAnnotation "file" -> return FileAnnotation
"enumerant" -> return EnumValueAnnotation "enumerant" -> return EnumerantAnnotation
"field" -> return FieldAnnotation "field" -> return FieldAnnotation
"method" -> return MethodAnnotation "method" -> return MethodAnnotation
"parameter" -> return ParamAnnotation "parameter" -> return ParamAnnotation
......
...@@ -45,7 +45,7 @@ data Desc = DescFile FileDesc ...@@ -45,7 +45,7 @@ data Desc = DescFile FileDesc
| DescAlias AliasDesc | DescAlias AliasDesc
| DescConstant ConstantDesc | DescConstant ConstantDesc
| DescEnum EnumDesc | DescEnum EnumDesc
| DescEnumValue EnumValueDesc | DescEnumerant EnumerantDesc
| DescStruct StructDesc | DescStruct StructDesc
| DescUnion UnionDesc | DescUnion UnionDesc
| DescField FieldDesc | DescField FieldDesc
...@@ -61,7 +61,7 @@ descName (DescFile _) = "(top-level)" ...@@ -61,7 +61,7 @@ descName (DescFile _) = "(top-level)"
descName (DescAlias d) = aliasName d descName (DescAlias d) = aliasName d
descName (DescConstant d) = constantName d descName (DescConstant d) = constantName d
descName (DescEnum d) = enumName d descName (DescEnum d) = enumName d
descName (DescEnumValue d) = enumValueName d descName (DescEnumerant d) = enumerantName d
descName (DescStruct d) = structName d descName (DescStruct d) = structName d
descName (DescUnion d) = unionName d descName (DescUnion d) = unionName d
descName (DescField d) = fieldName d descName (DescField d) = fieldName d
...@@ -77,7 +77,7 @@ descId (DescFile d) = fileId d ...@@ -77,7 +77,7 @@ descId (DescFile d) = fileId d
descId (DescAlias _) = Nothing descId (DescAlias _) = Nothing
descId (DescConstant d) = constantId d descId (DescConstant d) = constantId d
descId (DescEnum d) = enumId d descId (DescEnum d) = enumId d
descId (DescEnumValue d) = enumValueId d descId (DescEnumerant d) = enumerantId d
descId (DescStruct d) = structId d descId (DescStruct d) = structId d
descId (DescUnion d) = unionId d descId (DescUnion d) = unionId d
descId (DescField d) = fieldId d descId (DescField d) = fieldId d
...@@ -101,7 +101,7 @@ descParent (DescFile _) = error "File descriptor has no parent." ...@@ -101,7 +101,7 @@ descParent (DescFile _) = error "File descriptor has no parent."
descParent (DescAlias d) = aliasParent d descParent (DescAlias d) = aliasParent d
descParent (DescConstant d) = constantParent d descParent (DescConstant d) = constantParent d
descParent (DescEnum d) = enumParent d descParent (DescEnum d) = enumParent d
descParent (DescEnumValue d) = DescEnum (enumValueParent d) descParent (DescEnumerant d) = DescEnum (enumerantParent d)
descParent (DescStruct d) = structParent d descParent (DescStruct d) = structParent d
descParent (DescUnion d) = DescStruct (unionParent d) descParent (DescUnion d) = DescStruct (unionParent d)
descParent (DescField d) = DescStruct (fieldParent d) descParent (DescField d) = DescStruct (fieldParent d)
...@@ -117,7 +117,7 @@ descAnnotations (DescFile d) = fileAnnotations d ...@@ -117,7 +117,7 @@ descAnnotations (DescFile d) = fileAnnotations d
descAnnotations (DescAlias _) = Map.empty descAnnotations (DescAlias _) = Map.empty
descAnnotations (DescConstant d) = constantAnnotations d descAnnotations (DescConstant d) = constantAnnotations d
descAnnotations (DescEnum d) = enumAnnotations d descAnnotations (DescEnum d) = enumAnnotations d
descAnnotations (DescEnumValue d) = enumValueAnnotations d descAnnotations (DescEnumerant d) = enumerantAnnotations d
descAnnotations (DescStruct d) = structAnnotations d descAnnotations (DescStruct d) = structAnnotations d
descAnnotations (DescUnion d) = unionAnnotations d descAnnotations (DescUnion d) = unionAnnotations d
descAnnotations (DescField d) = fieldAnnotations d descAnnotations (DescField d) = fieldAnnotations d
...@@ -161,7 +161,7 @@ data ValueDesc = VoidDesc ...@@ -161,7 +161,7 @@ data ValueDesc = VoidDesc
| Float64Desc Double | Float64Desc Double
| TextDesc String | TextDesc String
| DataDesc ByteString | DataDesc ByteString
| EnumValueValueDesc EnumValueDesc | EnumerantValueDesc EnumerantDesc
| StructValueDesc [(FieldDesc, ValueDesc)] | StructValueDesc [(FieldDesc, ValueDesc)]
| ListDesc [ValueDesc] | ListDesc [ValueDesc]
deriving (Show) deriving (Show)
...@@ -180,7 +180,7 @@ valueString (Float32Desc x) = show x ...@@ -180,7 +180,7 @@ valueString (Float32Desc x) = show x
valueString (Float64Desc x) = show x valueString (Float64Desc x) = show x
valueString (TextDesc s) = show s valueString (TextDesc s) = show s
valueString (DataDesc s) = show (map (chr . fromIntegral) s) valueString (DataDesc s) = show (map (chr . fromIntegral) s)
valueString (EnumValueValueDesc v) = enumValueName v valueString (EnumerantValueDesc v) = enumerantName v
valueString (StructValueDesc l) = "(" ++ delimit ", " (map assignmentString l) ++ ")" where valueString (StructValueDesc l) = "(" ++ delimit ", " (map assignmentString l) ++ ")" where
assignmentString (field, value) = case fieldUnion field of assignmentString (field, value) = case fieldUnion field of
Nothing -> fieldName field ++ " = " ++ valueString value Nothing -> fieldName field ++ " = " ++ valueString value
...@@ -259,7 +259,7 @@ fieldValueSize (Float32Desc _) = Size32 ...@@ -259,7 +259,7 @@ fieldValueSize (Float32Desc _) = Size32
fieldValueSize (Float64Desc _) = Size64 fieldValueSize (Float64Desc _) = Size64
fieldValueSize (TextDesc _) = SizeReference fieldValueSize (TextDesc _) = SizeReference
fieldValueSize (DataDesc _) = SizeReference fieldValueSize (DataDesc _) = SizeReference
fieldValueSize (EnumValueValueDesc _) = Size16 fieldValueSize (EnumerantValueDesc _) = Size16
fieldValueSize (StructValueDesc _) = SizeReference fieldValueSize (StructValueDesc _) = SizeReference
fieldValueSize (ListDesc _) = SizeReference fieldValueSize (ListDesc _) = SizeReference
...@@ -337,18 +337,18 @@ data EnumDesc = EnumDesc ...@@ -337,18 +337,18 @@ data EnumDesc = EnumDesc
{ enumName :: String { enumName :: String
, enumId :: Maybe String , enumId :: Maybe String
, enumParent :: Desc , enumParent :: Desc
, enumValues :: [EnumValueDesc] , enumerants :: [EnumerantDesc]
, enumAnnotations :: AnnotationMap , enumAnnotations :: AnnotationMap
, enumMemberMap :: MemberMap , enumMemberMap :: MemberMap
, enumStatements :: [Desc] , enumStatements :: [Desc]
} }
data EnumValueDesc = EnumValueDesc data EnumerantDesc = EnumerantDesc
{ enumValueName :: String { enumerantName :: String
, enumValueId :: Maybe String , enumerantId :: Maybe String
, enumValueParent :: EnumDesc , enumerantParent :: EnumDesc
, enumValueNumber :: Integer , enumerantNumber :: Integer
, enumValueAnnotations :: AnnotationMap , enumerantAnnotations :: AnnotationMap
} }
data StructDesc = StructDesc data StructDesc = StructDesc
...@@ -469,8 +469,8 @@ descToCode indent self@(DescEnum desc) = printf "%senum %s%s {\n%s%s}\n" indent ...@@ -469,8 +469,8 @@ descToCode indent self@(DescEnum desc) = printf "%senum %s%s {\n%s%s}\n" indent
(annotationsCode self) (annotationsCode self)
(blockCode indent (enumStatements desc)) (blockCode indent (enumStatements desc))
indent indent
descToCode indent self@(DescEnumValue desc) = printf "%s%s @%d%s;\n" indent descToCode indent self@(DescEnumerant desc) = printf "%s%s @%d%s;\n" indent
(enumValueName desc) (enumValueNumber desc) (enumerantName desc) (enumerantNumber desc)
(annotationsCode self) (annotationsCode self)
descToCode indent self@(DescStruct desc) = printf "%sstruct %s%s {\n%s%s}\n" indent descToCode indent self@(DescStruct desc) = printf "%sstruct %s%s {\n%s%s}\n" indent
(structName desc) (structName desc)
...@@ -546,7 +546,7 @@ instance Show FileDesc where { show desc = descToCode "" (DescFile desc) } ...@@ -546,7 +546,7 @@ instance Show FileDesc where { show desc = descToCode "" (DescFile desc) }
instance Show AliasDesc where { show desc = descToCode "" (DescAlias desc) } instance Show AliasDesc where { show desc = descToCode "" (DescAlias desc) }
instance Show ConstantDesc where { show desc = descToCode "" (DescConstant desc) } instance Show ConstantDesc where { show desc = descToCode "" (DescConstant desc) }
instance Show EnumDesc where { show desc = descToCode "" (DescEnum desc) } instance Show EnumDesc where { show desc = descToCode "" (DescEnum desc) }
instance Show EnumValueDesc where { show desc = descToCode "" (DescEnumValue desc) } instance Show EnumerantDesc where { show desc = descToCode "" (DescEnumerant desc) }
instance Show StructDesc where { show desc = descToCode "" (DescStruct desc) } instance Show StructDesc where { show desc = descToCode "" (DescStruct desc) }
instance Show FieldDesc where { show desc = descToCode "" (DescField desc) } instance Show FieldDesc where { show desc = descToCode "" (DescField desc) }
instance Show InterfaceDesc where { show desc = descToCode "" (DescInterface desc) } instance Show InterfaceDesc where { show desc = descToCode "" (DescInterface desc) }
......
...@@ -64,7 +64,7 @@ encodeDataValue (Float32Desc v) = bytes (floatToWord v) 4 ...@@ -64,7 +64,7 @@ encodeDataValue (Float32Desc v) = bytes (floatToWord v) 4
encodeDataValue (Float64Desc v) = bytes (doubleToWord v) 8 encodeDataValue (Float64Desc v) = bytes (doubleToWord v) 8
encodeDataValue (TextDesc _) = error "Not fixed-width data." encodeDataValue (TextDesc _) = error "Not fixed-width data."
encodeDataValue (DataDesc _) = error "Not fixed-width data." encodeDataValue (DataDesc _) = error "Not fixed-width data."
encodeDataValue (EnumValueValueDesc v) = bytes (enumValueNumber v) 2 encodeDataValue (EnumerantValueDesc v) = bytes (enumerantNumber v) 2
encodeDataValue (StructValueDesc _) = error "Not fixed-width data." encodeDataValue (StructValueDesc _) = error "Not fixed-width data."
encodeDataValue (ListDesc _) = error "Not fixed-width data." encodeDataValue (ListDesc _) = error "Not fixed-width data."
......
...@@ -61,9 +61,9 @@ struct {{typeFullName}} { ...@@ -61,9 +61,9 @@ struct {{typeFullName}} {
{{#structNestedEnums}} {{#structNestedEnums}}
enum class {{enumName}}: uint16_t { enum class {{enumName}}: uint16_t {
{{#enumValues}} {{#enumerants}}
{{enumValueName}} = {{enumValueNumber}}, {{enumerantName}} = {{enumerantNumber}},
{{/enumValues}} {{/enumerants}}
}; };
{{/structNestedEnums}} {{/structNestedEnums}}
...@@ -93,9 +93,9 @@ struct {{typeFullName}} { ...@@ -93,9 +93,9 @@ struct {{typeFullName}} {
{{#fileEnums}} {{#fileEnums}}
enum class {{enumName}}: uint16_t { enum class {{enumName}}: uint16_t {
{{#enumValues}} {{#enumerants}}
{{enumValueName}} = {{enumValueNumber}}, {{enumerantName}} = {{enumerantNumber}},
{{/enumValues}} {{/enumerants}}
}; };
{{/fileEnums}} {{/fileEnums}}
{{! =========================================================================================== }} {{! =========================================================================================== }}
......
...@@ -43,7 +43,7 @@ Some notes: ...@@ -43,7 +43,7 @@ Some notes:
* Types come after names. The name is by far the most important thing to see, especially when * Types come after names. The name is by far the most important thing to see, especially when
quickly skimming, so we put it up front where it is most visible. Sorry, C got it wrong. quickly skimming, so we put it up front where it is most visible. Sorry, C got it wrong.
* The `@N` annotations show how the protocol evolved over time, so that the system can make sure * The `@N` annotations show how the protocol evolved over time, so that the system can make sure
to maintain compatibility with older versions. Fields (and enum values, and interface methods) to maintain compatibility with older versions. Fields (and enumerants, and interface methods)
must be numbered consecutively starting from zero in the order in which they were added. In this must be numbered consecutively starting from zero in the order in which they were added. In this
example, it looks like the `birthdate` field was added to the `Person` structure recently -- its example, it looks like the `birthdate` field was added to the `Person` structure recently -- its
number is higher than the `email` and `phones` fields. Unlike Protobufs, you cannot skip numbers number is higher than the `email` and `phones` fields. Unlike Protobufs, you cannot skip numbers
...@@ -172,7 +172,7 @@ enum Rfc3092Variable { ...@@ -172,7 +172,7 @@ enum Rfc3092Variable {
} }
{% endhighlight %} {% endhighlight %}
Like fields, enum values must be numbered sequentially starting from zero. In languages where Like fields, enumerants must be numbered sequentially starting from zero. In languages where
enums have numeric values, these numbers will be used, but in general Cap'n Proto enums should not enums have numeric values, these numbers will be used, but in general Cap'n Proto enums should not
be considered numeric. be considered numeric.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment