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) =
compileValue pos (EnumType desc) (IdentifierFieldValue name) =
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)
compileValue pos (StructType desc) (RecordFieldValue fields) = do
......@@ -248,7 +248,7 @@ compileValue pos (BuiltinType BuiltinFloat64) _ = makeExpectError pos "number"
compileValue pos (BuiltinType BuiltinText) _ = 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 (InterfaceType _) _ = makeError pos "Interfaces can't have default values."
compileValue pos (ListType _) _ = makeExpectError pos "list"
......@@ -580,33 +580,33 @@ compileDecl scope (EnumDecl (Located _ name) annotations decls) =
CompiledStatementStatus name (feedback (\desc -> do
(members, memberMap) <- compileChildDecls desc decls
requireNoDuplicateNames decls
let numbers = [ num | EnumValueDecl _ num _ <- decls ]
requireSequentialNumbering "Enum values" numbers
let numbers = [ num | EnumerantDecl _ num _ <- decls ]
requireSequentialNumbering "Enumerants" numbers
requireOrdinalsInRange numbers
(theId, compiledAnnotations) <- compileAnnotations scope EnumAnnotation annotations
return (DescEnum EnumDesc
{ enumName = name
, enumId = theId
, enumParent = scope
, enumValues = [d | DescEnumValue d <- members]
, enumerants = [d | DescEnumerant d <- members]
, enumAnnotations = compiledAnnotations
, enumMemberMap = memberMap
, enumStatements = members
})))
compileDecl scope@(DescEnum parent)
(EnumValueDecl (Located _ name) (Located _ number) annotations) =
(EnumerantDecl (Located _ name) (Located _ number) annotations) =
CompiledStatementStatus name (do
(theId, compiledAnnotations) <- compileAnnotations scope EnumValueAnnotation annotations
return (DescEnumValue EnumValueDesc
{ enumValueName = name
, enumValueId = theId
, enumValueParent = parent
, enumValueNumber = number
, enumValueAnnotations = compiledAnnotations
(theId, compiledAnnotations) <- compileAnnotations scope EnumerantAnnotation annotations
return (DescEnumerant EnumerantDesc
{ enumerantName = name
, enumerantId = theId
, enumerantParent = parent
, enumerantNumber = number
, enumerantAnnotations = compiledAnnotations
}))
compileDecl _ (EnumValueDecl (Located pos name) _ _) =
CompiledStatementStatus name (makeError pos "Enum values can only appear inside enums.")
compileDecl _ (EnumerantDecl (Located pos name) _ _) =
CompiledStatementStatus name (makeError pos "Enumerants can only appear inside enums.")
compileDecl scope (StructDecl (Located _ name) annotations decls) =
CompiledStatementStatus name (feedback (\desc -> do
......
......@@ -153,7 +153,7 @@ isDefaultZero (UInt32Desc i) = i == 0
isDefaultZero (UInt64Desc i) = i == 0
isDefaultZero (Float32Desc 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 (DataDesc _) = 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"
defaultMask (UInt64Desc i) = show i ++ "llu"
defaultMask (Float32Desc x) = show (floatToWord x) ++ "u"
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 (DataDesc _) = 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."
repeatedlyTake _ [] = []
repeatedlyTake n l = take n l : repeatedlyTake n (drop n l)
enumValueContext parent desc = mkStrContext context where
context "enumValueName" = MuVariable $ toUpperCaseWithUnderscores $ enumValueName desc
context "enumValueNumber" = MuVariable $ enumValueNumber desc
enumerantContext parent desc = mkStrContext context where
context "enumerantName" = MuVariable $ toUpperCaseWithUnderscores $ enumerantName desc
context "enumerantNumber" = MuVariable $ enumerantNumber desc
context s = parent s
enumContext parent desc = mkStrContext context where
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
defaultBytesContext :: Monad m => (String -> MuType m) -> TypeDesc -> [Word8] -> MuContext m
......
......@@ -68,7 +68,7 @@ paramImports (ParamDecl _ t ann _) = typeImports t ++ concatMap annotationImport
data AnnotationTarget = FileAnnotation
| ConstantAnnotation
| EnumAnnotation
| EnumValueAnnotation
| EnumerantAnnotation
| StructAnnotation
| FieldAnnotation
| UnionAnnotation
......@@ -82,7 +82,7 @@ instance Show AnnotationTarget where
show FileAnnotation = "file"
show ConstantAnnotation = "const"
show EnumAnnotation = "enum"
show EnumValueAnnotation = "enumerant"
show EnumerantAnnotation = "enumerant"
show StructAnnotation = "struct"
show FieldAnnotation = "field"
show UnionAnnotation = "union"
......@@ -94,7 +94,7 @@ instance Show AnnotationTarget where
data Declaration = AliasDecl (Located String) DeclName
| ConstantDecl (Located String) TypeExpression [Annotation] (Located FieldValue)
| EnumDecl (Located String) [Annotation] [Declaration]
| EnumValueDecl (Located String) (Located Integer) [Annotation]
| EnumerantDecl (Located String) (Located Integer) [Annotation]
| StructDecl (Located String) [Annotation] [Declaration]
| FieldDecl (Located String) (Located Integer)
TypeExpression [Annotation] (Maybe (Located FieldValue))
......@@ -109,7 +109,7 @@ declarationName :: Declaration -> Maybe (Located String)
declarationName (AliasDecl n _) = Just n
declarationName (ConstantDecl n _ _ _) = Just n
declarationName (EnumDecl n _ _) = Just n
declarationName (EnumValueDecl n _ _) = Just n
declarationName (EnumerantDecl n _ _) = Just n
declarationName (StructDecl n _ _) = Just n
declarationName (FieldDecl n _ _ _ _) = Just n
declarationName (UnionDecl n _ _ _) = Just n
......@@ -121,7 +121,7 @@ declImports :: Declaration -> [Located String]
declImports (AliasDecl _ name) = maybeToList (declNameImport name)
declImports (ConstantDecl _ t ann _) = typeImports t ++ concatMap annotationImports ann
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 ++
concatMap declImports decls
declImports (FieldDecl _ _ t ann _) = typeImports t ++ concatMap annotationImports ann
......
......@@ -120,7 +120,6 @@ structKeyword = tokenParser (matchSimpleToken StructKeyword) <?> "\"struct\""
unionKeyword = tokenParser (matchSimpleToken UnionKeyword) <?> "\"union\""
interfaceKeyword = tokenParser (matchSimpleToken InterfaceKeyword) <?> "\"interface\""
annotationKeyword = tokenParser (matchSimpleToken AnnotationKeyword) <?> "\"annotation\""
onKeyword = tokenParser (matchSimpleToken OnKeyword) <?> "\"on\""
parenthesizedList parser = do
items <- tokenParser (matchUnary ParenthesizedList)
......@@ -201,13 +200,13 @@ enumDecl statements = do
return (EnumDecl name annotations children)
enumLine :: Maybe [Located Statement] -> TokenParser Declaration
enumLine Nothing = enumValueDecl
enumLine Nothing = enumerantDecl
enumLine (Just _) = fail "Blocks not allowed here."
enumValueDecl = do
enumerantDecl = do
(name, value) <- nameWithOrdinal
annotations <- many annotation
return (EnumValueDecl name value annotations)
return (EnumerantDecl name value annotations)
structDecl statements = do
structKeyword
......@@ -313,7 +312,7 @@ annotationTarget = (constKeyword >> return ConstantAnnotation)
name <- varIdentifier
case name of
"file" -> return FileAnnotation
"enumerant" -> return EnumValueAnnotation
"enumerant" -> return EnumerantAnnotation
"field" -> return FieldAnnotation
"method" -> return MethodAnnotation
"parameter" -> return ParamAnnotation
......
......@@ -45,7 +45,7 @@ data Desc = DescFile FileDesc
| DescAlias AliasDesc
| DescConstant ConstantDesc
| DescEnum EnumDesc
| DescEnumValue EnumValueDesc
| DescEnumerant EnumerantDesc
| DescStruct StructDesc
| DescUnion UnionDesc
| DescField FieldDesc
......@@ -61,7 +61,7 @@ descName (DescFile _) = "(top-level)"
descName (DescAlias d) = aliasName d
descName (DescConstant d) = constantName d
descName (DescEnum d) = enumName d
descName (DescEnumValue d) = enumValueName d
descName (DescEnumerant d) = enumerantName d
descName (DescStruct d) = structName d
descName (DescUnion d) = unionName d
descName (DescField d) = fieldName d
......@@ -77,7 +77,7 @@ descId (DescFile d) = fileId d
descId (DescAlias _) = Nothing
descId (DescConstant d) = constantId d
descId (DescEnum d) = enumId d
descId (DescEnumValue d) = enumValueId d
descId (DescEnumerant d) = enumerantId d
descId (DescStruct d) = structId d
descId (DescUnion d) = unionId d
descId (DescField d) = fieldId d
......@@ -101,7 +101,7 @@ descParent (DescFile _) = error "File descriptor has no parent."
descParent (DescAlias d) = aliasParent d
descParent (DescConstant d) = constantParent d
descParent (DescEnum d) = enumParent d
descParent (DescEnumValue d) = DescEnum (enumValueParent d)
descParent (DescEnumerant d) = DescEnum (enumerantParent d)
descParent (DescStruct d) = structParent d
descParent (DescUnion d) = DescStruct (unionParent d)
descParent (DescField d) = DescStruct (fieldParent d)
......@@ -117,7 +117,7 @@ descAnnotations (DescFile d) = fileAnnotations d
descAnnotations (DescAlias _) = Map.empty
descAnnotations (DescConstant d) = constantAnnotations d
descAnnotations (DescEnum d) = enumAnnotations d
descAnnotations (DescEnumValue d) = enumValueAnnotations d
descAnnotations (DescEnumerant d) = enumerantAnnotations d
descAnnotations (DescStruct d) = structAnnotations d
descAnnotations (DescUnion d) = unionAnnotations d
descAnnotations (DescField d) = fieldAnnotations d
......@@ -161,7 +161,7 @@ data ValueDesc = VoidDesc
| Float64Desc Double
| TextDesc String
| DataDesc ByteString
| EnumValueValueDesc EnumValueDesc
| EnumerantValueDesc EnumerantDesc
| StructValueDesc [(FieldDesc, ValueDesc)]
| ListDesc [ValueDesc]
deriving (Show)
......@@ -180,7 +180,7 @@ valueString (Float32Desc x) = show x
valueString (Float64Desc x) = show x
valueString (TextDesc s) = show 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
assignmentString (field, value) = case fieldUnion field of
Nothing -> fieldName field ++ " = " ++ valueString value
......@@ -259,7 +259,7 @@ fieldValueSize (Float32Desc _) = Size32
fieldValueSize (Float64Desc _) = Size64
fieldValueSize (TextDesc _) = SizeReference
fieldValueSize (DataDesc _) = SizeReference
fieldValueSize (EnumValueValueDesc _) = Size16
fieldValueSize (EnumerantValueDesc _) = Size16
fieldValueSize (StructValueDesc _) = SizeReference
fieldValueSize (ListDesc _) = SizeReference
......@@ -337,18 +337,18 @@ data EnumDesc = EnumDesc
{ enumName :: String
, enumId :: Maybe String
, enumParent :: Desc
, enumValues :: [EnumValueDesc]
, enumerants :: [EnumerantDesc]
, enumAnnotations :: AnnotationMap
, enumMemberMap :: MemberMap
, enumStatements :: [Desc]
}
data EnumValueDesc = EnumValueDesc
{ enumValueName :: String
, enumValueId :: Maybe String
, enumValueParent :: EnumDesc
, enumValueNumber :: Integer
, enumValueAnnotations :: AnnotationMap
data EnumerantDesc = EnumerantDesc
{ enumerantName :: String
, enumerantId :: Maybe String
, enumerantParent :: EnumDesc
, enumerantNumber :: Integer
, enumerantAnnotations :: AnnotationMap
}
data StructDesc = StructDesc
......@@ -469,8 +469,8 @@ descToCode indent self@(DescEnum desc) = printf "%senum %s%s {\n%s%s}\n" indent
(annotationsCode self)
(blockCode indent (enumStatements desc))
indent
descToCode indent self@(DescEnumValue desc) = printf "%s%s @%d%s;\n" indent
(enumValueName desc) (enumValueNumber desc)
descToCode indent self@(DescEnumerant desc) = printf "%s%s @%d%s;\n" indent
(enumerantName desc) (enumerantNumber desc)
(annotationsCode self)
descToCode indent self@(DescStruct desc) = printf "%sstruct %s%s {\n%s%s}\n" indent
(structName 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 ConstantDesc where { show desc = descToCode "" (DescConstant 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 FieldDesc where { show desc = descToCode "" (DescField desc) }
instance Show InterfaceDesc where { show desc = descToCode "" (DescInterface desc) }
......
......@@ -64,7 +64,7 @@ encodeDataValue (Float32Desc v) = bytes (floatToWord v) 4
encodeDataValue (Float64Desc v) = bytes (doubleToWord v) 8
encodeDataValue (TextDesc _) = 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 (ListDesc _) = error "Not fixed-width data."
......
......@@ -61,9 +61,9 @@ struct {{typeFullName}} {
{{#structNestedEnums}}
enum class {{enumName}}: uint16_t {
{{#enumValues}}
{{enumValueName}} = {{enumValueNumber}},
{{/enumValues}}
{{#enumerants}}
{{enumerantName}} = {{enumerantNumber}},
{{/enumerants}}
};
{{/structNestedEnums}}
......@@ -93,9 +93,9 @@ struct {{typeFullName}} {
{{#fileEnums}}
enum class {{enumName}}: uint16_t {
{{#enumValues}}
{{enumValueName}} = {{enumValueNumber}},
{{/enumValues}}
{{#enumerants}}
{{enumerantName}} = {{enumerantNumber}},
{{/enumerants}}
};
{{/fileEnums}}
{{! =========================================================================================== }}
......
......@@ -43,7 +43,7 @@ Some notes:
* 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.
* 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
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
......@@ -172,7 +172,7 @@ enum Rfc3092Variable {
}
{% 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
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