Commit 2e3f671c authored by Kenton Varda's avatar Kenton Varda

class -> struct

parent 22a75445
......@@ -105,7 +105,7 @@ statusToMaybe (Failed _) = Nothing
-- | Look up a direct member of a descriptor by name.
descMember name (DescFile d) = lookupMember name (fileMemberMap d)
descMember name (DescEnum d) = lookupMember name (enumMemberMap d)
descMember name (DescClass d) = lookupMember name (classMemberMap d)
descMember name (DescStruct d) = lookupMember name (structMemberMap d)
descMember name (DescInterface d) = lookupMember name (interfaceMemberMap d)
descMember name (DescAlias d) = descMember name (aliasTarget d)
descMember _ _ = Nothing
......@@ -191,7 +191,7 @@ compileValue pos (BuiltinType BuiltinText) _ = makeExpectError pos "string"
compileValue pos (BuiltinType BuiltinBytes) _ = makeExpectError pos "string"
compileValue pos (EnumType _) _ = makeError pos "Unimplemented: enum default values"
compileValue pos (ClassType _) _ = makeError pos "Unimplemented: class default values"
compileValue pos (StructType _) _ = makeError pos "Unimplemented: struct default values"
compileValue pos (InterfaceType _) _ = makeError pos "Interfaces can't have default values."
compileValue pos (ListType _) _ = makeError pos "Unimplemented: array default values"
......@@ -200,11 +200,11 @@ makeFileMemberMap desc = Map.fromList allMembers where
allMembers = [ (aliasName m, DescAlias m) | m <- fileAliases desc ]
++ [ (constantName m, DescConstant m) | m <- fileConstants desc ]
++ [ (enumName m, DescEnum m) | m <- fileEnums desc ]
++ [ (className m, DescClass m) | m <- fileClasses desc ]
++ [ (structName m, DescStruct m) | m <- fileStructs desc ]
++ [ (interfaceName m, DescInterface m) | m <- fileInterfaces desc ]
descAsType _ (DescEnum desc) = succeed (EnumType desc)
descAsType _ (DescClass desc) = succeed (ClassType desc)
descAsType _ (DescStruct desc) = succeed (StructType desc)
descAsType _ (DescInterface desc) = succeed (InterfaceType desc)
descAsType _ (DescBuiltinType desc) = succeed (BuiltinType desc)
descAsType name (DescAlias desc) = descAsType name (aliasTarget desc)
......@@ -286,21 +286,21 @@ compileDecl scope (EnumValueDecl (Located _ name) (Located _ number) decls) =
, enumValueOptions = options
})))
compileDecl scope (ClassDecl (Located _ name) decls) =
compileDecl scope (StructDecl (Located _ name) decls) =
CompiledMember name (feedback (\desc -> do
(members, memberMap, options) <- compileChildDecls desc decls
return (DescClass ClassDesc
{ className = name
, classParent = scope
, classFields = [d | DescField d <- members]
, classNestedAliases = [d | DescAlias d <- members]
, classNestedConstants = [d | DescConstant d <- members]
, classNestedEnums = [d | DescEnum d <- members]
, classNestedClasses = [d | DescClass d <- members]
, classNestedInterfaces = [d | DescInterface d <- members]
, classOptions = options
, classMembers = members
, classMemberMap = memberMap
return (DescStruct StructDesc
{ structName = name
, structParent = scope
, structFields = [d | DescField d <- members]
, structNestedAliases = [d | DescAlias d <- members]
, structNestedConstants = [d | DescConstant d <- members]
, structNestedEnums = [d | DescEnum d <- members]
, structNestedStructs = [d | DescStruct d <- members]
, structNestedInterfaces = [d | DescInterface d <- members]
, structOptions = options
, structMembers = members
, structMemberMap = memberMap
})))
compileDecl scope (FieldDecl (Located _ name) (Located _ number) typeExp defaultValue decls) =
......@@ -329,7 +329,7 @@ compileDecl scope (InterfaceDecl (Located _ name) decls) =
, interfaceNestedAliases = [d | DescAlias d <- members]
, interfaceNestedConstants = [d | DescConstant d <- members]
, interfaceNestedEnums = [d | DescEnum d <- members]
, interfaceNestedClasses = [d | DescClass d <- members]
, interfaceNestedStructs = [d | DescStruct d <- members]
, interfaceNestedInterfaces = [d | DescInterface d <- members]
, interfaceOptions = options
, interfaceMembers = members
......@@ -378,7 +378,7 @@ compileFile name decls =
, fileAliases = [d | DescAlias d <- members]
, fileConstants = [d | DescConstant d <- members]
, fileEnums = [d | DescEnum d <- members]
, fileClasses = [d | DescClass d <- members]
, fileStructs = [d | DescStruct d <- members]
, fileInterfaces = [d | DescInterface d <- members]
, fileOptions = options
, fileMembers = members
......
......@@ -47,7 +47,7 @@ data Declaration = AliasDecl (Located String) DeclName
| ConstantDecl (Located String) TypeExpression (Located FieldValue)
| EnumDecl (Located String) [Declaration]
| EnumValueDecl (Located String) (Located Integer) [Declaration]
| ClassDecl (Located String) [Declaration]
| StructDecl (Located String) [Declaration]
| FieldDecl (Located String) (Located Integer)
TypeExpression (Maybe (Located FieldValue)) [Declaration]
| InterfaceDecl (Located String) [Declaration]
......
......@@ -35,7 +35,7 @@ keywords =
, (UsingKeyword, "using")
, (ConstKeyword, "const")
, (EnumKeyword, "enum")
, (ClassKeyword, "class")
, (StructKeyword, "struct")
, (InterfaceKeyword, "interface")
, (OptionKeyword, "option")
]
......
......@@ -62,7 +62,7 @@ importKeyword = tokenParser (matchSimpleToken ImportKeyword)
usingKeyword = tokenParser (matchSimpleToken UsingKeyword)
constKeyword = tokenParser (matchSimpleToken ConstKeyword)
enumKeyword = tokenParser (matchSimpleToken EnumKeyword)
classKeyword = tokenParser (matchSimpleToken ClassKeyword)
structKeyword = tokenParser (matchSimpleToken StructKeyword)
interfaceKeyword = tokenParser (matchSimpleToken InterfaceKeyword)
optionKeyword = tokenParser (matchSimpleToken OptionKeyword)
......@@ -111,7 +111,7 @@ constantDecl = do
return (ConstantDecl name typeName value)
typeDecl statements = enumDecl statements
<|> classDecl statements
<|> structDecl statements
<|> interfaceDecl statements
enumDecl statements = do
......@@ -135,15 +135,15 @@ enumValueLine :: Maybe [Located Statement] -> TokenParser Declaration
enumValueLine Nothing = optionDecl
enumValueLine (Just _) = fail "Blocks not allowed here."
classDecl statements = do
classKeyword
structDecl statements = do
structKeyword
name <- located identifier
children <- parseBlock classLine statements
return (ClassDecl name children)
children <- parseBlock structLine statements
return (StructDecl name children)
classLine :: Maybe [Located Statement] -> TokenParser Declaration
classLine Nothing = optionDecl <|> constantDecl <|> fieldDecl []
classLine (Just statements) = typeDecl statements <|> fieldDecl statements
structLine :: Maybe [Located Statement] -> TokenParser Declaration
structLine Nothing = optionDecl <|> constantDecl <|> fieldDecl []
structLine (Just statements) = typeDecl statements <|> fieldDecl statements
fieldDecl statements = do
name <- located identifier
......
......@@ -38,7 +38,7 @@ data Desc = DescFile FileDesc
| DescConstant ConstantDesc
| DescEnum EnumDesc
| DescEnumValue EnumValueDesc
| DescClass ClassDesc
| DescStruct StructDesc
| DescField FieldDesc
| DescInterface InterfaceDesc
| DescMethod MethodDesc
......@@ -51,7 +51,7 @@ descName (DescAlias d) = aliasName d
descName (DescConstant d) = constantName d
descName (DescEnum d) = enumName d
descName (DescEnumValue d) = enumValueName d
descName (DescClass d) = className d
descName (DescStruct d) = structName d
descName (DescField d) = fieldName d
descName (DescInterface d) = interfaceName d
descName (DescMethod d) = methodName d
......@@ -64,7 +64,7 @@ descParent (DescAlias d) = aliasParent d
descParent (DescConstant d) = constantParent d
descParent (DescEnum d) = enumParent d
descParent (DescEnumValue d) = enumValueParent d
descParent (DescClass d) = classParent d
descParent (DescStruct d) = structParent d
descParent (DescField d) = fieldParent d
descParent (DescInterface d) = interfaceParent d
descParent (DescMethod d) = methodParent d
......@@ -123,7 +123,7 @@ valueString (BytesDesc s) = show (map (chr . fromIntegral) s)
data TypeDesc = BuiltinType BuiltinType
| EnumType EnumDesc
| ClassType ClassDesc
| StructType StructDesc
| InterfaceType InterfaceDesc
| ListType TypeDesc
......@@ -131,7 +131,7 @@ data TypeDesc = BuiltinType BuiltinType
typeName :: Desc -> TypeDesc -> String
typeName _ (BuiltinType t) = builtinTypeName t -- TODO: Check for shadowing.
typeName scope (EnumType desc) = descQualifiedName scope (DescEnum desc)
typeName scope (ClassType desc) = descQualifiedName scope (DescClass desc)
typeName scope (StructType desc) = descQualifiedName scope (DescStruct desc)
typeName scope (InterfaceType desc) = descQualifiedName scope (DescInterface desc)
typeName scope (ListType t) = "List(" ++ typeName scope t ++ ")"
......@@ -159,7 +159,7 @@ data FileDesc = FileDesc
, fileAliases :: [AliasDesc]
, fileConstants :: [ConstantDesc]
, fileEnums :: [EnumDesc]
, fileClasses :: [ClassDesc]
, fileStructs :: [StructDesc]
, fileInterfaces :: [InterfaceDesc]
, fileOptions :: OptionMap
, fileMembers :: [Desc]
......@@ -196,18 +196,18 @@ data EnumValueDesc = EnumValueDesc
, enumValueOptions :: OptionMap
}
data ClassDesc = ClassDesc
{ className :: String
, classParent :: Desc
, classFields :: [FieldDesc]
, classNestedAliases :: [AliasDesc]
, classNestedConstants :: [ConstantDesc]
, classNestedEnums :: [EnumDesc]
, classNestedClasses :: [ClassDesc]
, classNestedInterfaces :: [InterfaceDesc]
, classOptions :: OptionMap
, classMembers :: [Desc]
, classMemberMap :: MemberMap
data StructDesc = StructDesc
{ structName :: String
, structParent :: Desc
, structFields :: [FieldDesc]
, structNestedAliases :: [AliasDesc]
, structNestedConstants :: [ConstantDesc]
, structNestedEnums :: [EnumDesc]
, structNestedStructs :: [StructDesc]
, structNestedInterfaces :: [InterfaceDesc]
, structOptions :: OptionMap
, structMembers :: [Desc]
, structMemberMap :: MemberMap
}
data FieldDesc = FieldDesc
......@@ -226,7 +226,7 @@ data InterfaceDesc = InterfaceDesc
, interfaceNestedAliases :: [AliasDesc]
, interfaceNestedConstants :: [ConstantDesc]
, interfaceNestedEnums :: [EnumDesc]
, interfaceNestedClasses :: [ClassDesc]
, interfaceNestedStructs :: [StructDesc]
, interfaceNestedInterfaces :: [InterfaceDesc]
, interfaceOptions :: OptionMap
, interfaceMembers :: [Desc]
......@@ -273,9 +273,9 @@ descToCode indent (DescEnum desc) = printf "%senum %s {\n%s%s}\n" indent
indent
descToCode indent (DescEnumValue desc) = printf "%s%s = %d;\n" indent
(enumValueName desc) (enumValueNumber desc)
descToCode indent (DescClass desc) = printf "%sclass %s {\n%s%s}\n" indent
(className desc)
(concatMap (descToCode (" " ++ indent)) (classMembers desc))
descToCode indent (DescStruct desc) = printf "%sstruct %s {\n%s%s}\n" indent
(structName desc)
(concatMap (descToCode (" " ++ indent)) (structMembers desc))
indent
descToCode indent (DescField desc) = printf "%s%s@%d: %s%s;\n" indent
(fieldName desc) (fieldNumber desc)
......@@ -303,7 +303,7 @@ 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 ClassDesc where { show desc = descToCode "" (DescClass 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) }
instance Show MethodDesc where { show desc = descToCode "" (DescMethod desc) }
......@@ -45,7 +45,7 @@ data Token = Identifier String
| UsingKeyword
| ConstKeyword
| EnumKeyword
| ClassKeyword
| StructKeyword
| InterfaceKeyword
| OptionKeyword
deriving (Show, Eq)
......
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