Commit 08c0a048 authored by Kenton Varda's avatar Kenton Varda

Cleanup: alias -> using

parent 6b61f9c4
...@@ -115,7 +115,7 @@ descMember name (DescFile d) = lookupMember name (fileMemberMap d) ...@@ -115,7 +115,7 @@ descMember name (DescFile d) = lookupMember name (fileMemberMap d)
descMember name (DescEnum d) = lookupMember name (enumMemberMap d) descMember name (DescEnum d) = lookupMember name (enumMemberMap d)
descMember name (DescStruct d) = lookupMember name (structMemberMap d) descMember name (DescStruct d) = lookupMember name (structMemberMap d)
descMember name (DescInterface d) = lookupMember name (interfaceMemberMap d) descMember name (DescInterface d) = lookupMember name (interfaceMemberMap d)
descMember name (DescAlias d) = descMember name (aliasTarget d) descMember name (DescUsing d) = descMember name (usingTarget d)
descMember _ _ = Nothing descMember _ _ = Nothing
-- | Lookup the given name in the scope of the given descriptor. -- | Lookup the given name in the scope of the given descriptor.
...@@ -255,7 +255,7 @@ compileValue pos (ListType _) _ = makeExpectError pos "list" ...@@ -255,7 +255,7 @@ compileValue pos (ListType _) _ = makeExpectError pos "list"
makeFileMemberMap :: FileDesc -> Map.Map String Desc makeFileMemberMap :: FileDesc -> Map.Map String Desc
makeFileMemberMap desc = Map.fromList allMembers where makeFileMemberMap desc = Map.fromList allMembers where
allMembers = [ (aliasName m, DescAlias m) | m <- fileAliases desc ] allMembers = [ (usingName m, DescUsing m) | m <- fileUsings desc ]
++ [ (constantName m, DescConstant m) | m <- fileConstants desc ] ++ [ (constantName m, DescConstant m) | m <- fileConstants desc ]
++ [ (enumName m, DescEnum m) | m <- fileEnums desc ] ++ [ (enumName m, DescEnum m) | m <- fileEnums desc ]
++ [ (structName m, DescStruct m) | m <- fileStructs desc ] ++ [ (structName m, DescStruct m) | m <- fileStructs desc ]
...@@ -265,7 +265,7 @@ descAsType _ (DescEnum desc) = succeed (EnumType desc) ...@@ -265,7 +265,7 @@ descAsType _ (DescEnum desc) = succeed (EnumType desc)
descAsType _ (DescStruct desc) = succeed (StructType desc) descAsType _ (DescStruct desc) = succeed (StructType desc)
descAsType _ (DescInterface desc) = succeed (InterfaceType desc) descAsType _ (DescInterface desc) = succeed (InterfaceType desc)
descAsType _ (DescBuiltinType desc) = succeed (BuiltinType desc) descAsType _ (DescBuiltinType desc) = succeed (BuiltinType desc)
descAsType name (DescAlias desc) = descAsType name (aliasTarget desc) descAsType name (DescUsing desc) = descAsType name (usingTarget desc)
descAsType name DescBuiltinList = makeError (declNamePos name) message where descAsType name DescBuiltinList = makeError (declNamePos name) message where
message = printf "'List' requires exactly one type parameter." (declNameString name) message = printf "'List' requires exactly one type parameter." (declNameString name)
descAsType name _ = makeError (declNamePos name) message where descAsType name _ = makeError (declNamePos name) message where
...@@ -553,13 +553,13 @@ compileChildDecls desc decls = Active (members, memberMap) errors where ...@@ -553,13 +553,13 @@ compileChildDecls desc decls = Active (members, memberMap) errors where
| CompiledStatementStatus name status <- compiledDecls] | CompiledStatementStatus name status <- compiledDecls]
errors = concatMap compiledErrors compiledDecls errors = concatMap compiledErrors compiledDecls
compileDecl scope (AliasDecl (Located _ name) target) = compileDecl scope (UsingDecl (Located _ name) target) =
CompiledStatementStatus name (do CompiledStatementStatus name (do
targetDesc <- lookupDesc scope target targetDesc <- lookupDesc scope target
return (DescAlias AliasDesc return (DescUsing UsingDesc
{ aliasName = name { usingName = name
, aliasParent = scope , usingParent = scope
, aliasTarget = targetDesc , usingTarget = targetDesc
})) }))
compileDecl scope (ConstantDecl (Located _ name) t annotations (Located valuePos value)) = compileDecl scope (ConstantDecl (Located _ name) t annotations (Located valuePos value)) =
...@@ -627,7 +627,7 @@ compileDecl scope (StructDecl (Located _ name) annotations decls) = ...@@ -627,7 +627,7 @@ compileDecl scope (StructDecl (Located _ name) annotations decls) =
, structPacking = packing , structPacking = packing
, structFields = fields , structFields = fields
, structUnions = unions , structUnions = unions
, structNestedAliases = [d | DescAlias d <- members] , structNestedUsings = [d | DescUsing d <- members]
, structNestedConstants = [d | DescConstant d <- members] , structNestedConstants = [d | DescConstant d <- members]
, structNestedEnums = [d | DescEnum d <- members] , structNestedEnums = [d | DescEnum d <- members]
, structNestedStructs = [d | DescStruct d <- members] , structNestedStructs = [d | DescStruct d <- members]
...@@ -708,7 +708,7 @@ compileDecl scope (InterfaceDecl (Located _ name) annotations decls) = ...@@ -708,7 +708,7 @@ compileDecl scope (InterfaceDecl (Located _ name) annotations decls) =
, interfaceId = theId , interfaceId = theId
, interfaceParent = scope , interfaceParent = scope
, interfaceMethods = [d | DescMethod d <- members] , interfaceMethods = [d | DescMethod d <- members]
, interfaceNestedAliases = [d | DescAlias d <- members] , interfaceNestedUsings = [d | DescUsing d <- members]
, interfaceNestedConstants = [d | DescConstant d <- members] , interfaceNestedConstants = [d | DescConstant d <- members]
, interfaceNestedEnums = [d | DescEnum d <- members] , interfaceNestedEnums = [d | DescEnum d <- members]
, interfaceNestedStructs = [d | DescStruct d <- members] , interfaceNestedStructs = [d | DescStruct d <- members]
...@@ -777,7 +777,7 @@ compileFile name decls annotations importMap = ...@@ -777,7 +777,7 @@ compileFile name decls annotations importMap =
{ fileName = name { fileName = name
, fileId = theId , fileId = theId
, fileImports = Map.elems importMap , fileImports = Map.elems importMap
, fileAliases = [d | DescAlias d <- members] , fileUsings = [d | DescUsing d <- members]
, fileConstants = [d | DescConstant d <- members] , fileConstants = [d | DescConstant d <- members]
, fileEnums = [d | DescEnum d <- members] , fileEnums = [d | DescEnum d <- members]
, fileStructs = [d | DescStruct d <- members] , fileStructs = [d | DescStruct d <- members]
...@@ -795,7 +795,7 @@ emptyFileDesc filename = FileDesc ...@@ -795,7 +795,7 @@ emptyFileDesc filename = FileDesc
{ fileName = filename { fileName = filename
, fileId = Nothing , fileId = Nothing
, fileImports = [] , fileImports = []
, fileAliases = [] , fileUsings = []
, fileConstants = [] , fileConstants = []
, fileEnums = [] , fileEnums = []
, fileStructs = [] , fileStructs = []
......
...@@ -91,7 +91,7 @@ instance Show AnnotationTarget where ...@@ -91,7 +91,7 @@ instance Show AnnotationTarget where
show ParamAnnotation = "param" show ParamAnnotation = "param"
show AnnotationAnnotation = "annotation" show AnnotationAnnotation = "annotation"
data Declaration = AliasDecl (Located String) DeclName data Declaration = UsingDecl (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]
| EnumerantDecl (Located String) (Located Integer) [Annotation] | EnumerantDecl (Located String) (Located Integer) [Annotation]
...@@ -106,7 +106,7 @@ data Declaration = AliasDecl (Located String) DeclName ...@@ -106,7 +106,7 @@ data Declaration = AliasDecl (Located String) DeclName
deriving (Show) deriving (Show)
declarationName :: Declaration -> Maybe (Located String) declarationName :: Declaration -> Maybe (Located String)
declarationName (AliasDecl n _) = Just n declarationName (UsingDecl n _) = Just n
declarationName (ConstantDecl n _ _ _) = Just n declarationName (ConstantDecl n _ _ _) = Just n
declarationName (EnumDecl n _ _) = Just n declarationName (EnumDecl n _ _) = Just n
declarationName (EnumerantDecl n _ _) = Just n declarationName (EnumerantDecl n _ _) = Just n
...@@ -118,7 +118,7 @@ declarationName (MethodDecl n _ _ _ _) = Just n ...@@ -118,7 +118,7 @@ declarationName (MethodDecl n _ _ _ _) = Just n
declarationName (AnnotationDecl n _ _ _) = Just n declarationName (AnnotationDecl n _ _ _) = Just n
declImports :: Declaration -> [Located String] declImports :: Declaration -> [Located String]
declImports (AliasDecl _ name) = maybeToList (declNameImport name) declImports (UsingDecl _ 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 (EnumerantDecl _ _ ann) = concatMap annotationImports ann declImports (EnumerantDecl _ _ ann) = concatMap annotationImports ann
......
...@@ -167,16 +167,16 @@ annotation = do ...@@ -167,16 +167,16 @@ annotation = do
return (Annotation name value) return (Annotation name value)
topLine :: Maybe [Located Statement] -> TokenParser (Either Declaration Annotation) topLine :: Maybe [Located Statement] -> TokenParser (Either Declaration Annotation)
topLine Nothing = liftM Left (aliasDecl <|> constantDecl <|> annotationDecl) topLine Nothing = liftM Left (usingDecl <|> constantDecl <|> annotationDecl)
<|> liftM Right annotation <|> liftM Right annotation
topLine (Just statements) = liftM Left $ typeDecl statements topLine (Just statements) = liftM Left $ typeDecl statements
aliasDecl = do usingDecl = do
usingKeyword usingKeyword
name <- located typeIdentifier name <- located typeIdentifier
equalsSign equalsSign
target <- declName target <- declName
return (AliasDecl name target) return (UsingDecl name target)
constantDecl = do constantDecl = do
constKeyword constKeyword
......
...@@ -42,7 +42,7 @@ maxOrdinal = 65534 :: Integer ...@@ -42,7 +42,7 @@ maxOrdinal = 65534 :: Integer
type ByteString = [Word8] type ByteString = [Word8]
data Desc = DescFile FileDesc data Desc = DescFile FileDesc
| DescAlias AliasDesc | DescUsing UsingDesc
| DescConstant ConstantDesc | DescConstant ConstantDesc
| DescEnum EnumDesc | DescEnum EnumDesc
| DescEnumerant EnumerantDesc | DescEnumerant EnumerantDesc
...@@ -58,7 +58,7 @@ data Desc = DescFile FileDesc ...@@ -58,7 +58,7 @@ data Desc = DescFile FileDesc
| DescBuiltinId | DescBuiltinId
descName (DescFile _) = "(top-level)" descName (DescFile _) = "(top-level)"
descName (DescAlias d) = aliasName d descName (DescUsing d) = usingName d
descName (DescConstant d) = constantName d descName (DescConstant d) = constantName d
descName (DescEnum d) = enumName d descName (DescEnum d) = enumName d
descName (DescEnumerant d) = enumerantName d descName (DescEnumerant d) = enumerantName d
...@@ -74,7 +74,7 @@ descName DescBuiltinList = "List" ...@@ -74,7 +74,7 @@ descName DescBuiltinList = "List"
descName DescBuiltinId = "id" descName DescBuiltinId = "id"
descId (DescFile d) = fileId d descId (DescFile d) = fileId d
descId (DescAlias _) = Nothing descId (DescUsing _) = Nothing
descId (DescConstant d) = constantId d descId (DescConstant d) = constantId d
descId (DescEnum d) = enumId d descId (DescEnum d) = enumId d
descId (DescEnumerant d) = enumerantId d descId (DescEnumerant d) = enumerantId d
...@@ -98,7 +98,7 @@ descAutoId d = case descId d of ...@@ -98,7 +98,7 @@ descAutoId d = case descId d of
_ -> fmap (++ '.':descName d) $ descAutoId $ descParent d _ -> fmap (++ '.':descName d) $ descAutoId $ descParent d
descParent (DescFile _) = error "File descriptor has no parent." descParent (DescFile _) = error "File descriptor has no parent."
descParent (DescAlias d) = aliasParent d descParent (DescUsing d) = usingParent d
descParent (DescConstant d) = constantParent d descParent (DescConstant d) = constantParent d
descParent (DescEnum d) = enumParent d descParent (DescEnum d) = enumParent d
descParent (DescEnumerant d) = DescEnum (enumerantParent d) descParent (DescEnumerant d) = DescEnum (enumerantParent d)
...@@ -114,7 +114,7 @@ descParent DescBuiltinList = error "Builtin type has no parent." ...@@ -114,7 +114,7 @@ descParent DescBuiltinList = error "Builtin type has no parent."
descParent DescBuiltinId = error "Builtin annotation has no parent." descParent DescBuiltinId = error "Builtin annotation has no parent."
descAnnotations (DescFile d) = fileAnnotations d descAnnotations (DescFile d) = fileAnnotations d
descAnnotations (DescAlias _) = Map.empty descAnnotations (DescUsing _) = Map.empty
descAnnotations (DescConstant d) = constantAnnotations d descAnnotations (DescConstant d) = constantAnnotations d
descAnnotations (DescEnum d) = enumAnnotations d descAnnotations (DescEnum d) = enumAnnotations d
descAnnotations (DescEnumerant d) = enumerantAnnotations d descAnnotations (DescEnumerant d) = enumerantAnnotations d
...@@ -291,9 +291,9 @@ typeName scope (ListType t) = "List(" ++ typeName scope t ++ ")" ...@@ -291,9 +291,9 @@ typeName scope (ListType t) = "List(" ++ typeName scope t ++ ")"
-- This could be made fancier in a couple ways: -- This could be made fancier in a couple ways:
-- 1) Drop the common prefix between scope and desc to form a minimal relative name. Note that -- 1) Drop the common prefix between scope and desc to form a minimal relative name. Note that
-- we'll need to check for shadowing. -- we'll need to check for shadowing.
-- 2) Examine aliases visible in the current scope to see if they refer to a prefix of the target -- 2) Examine `using`s visible in the current scope to see if they refer to a prefix of the target
-- symbol, and use them if so. A particularly important case of this is imports -- typically -- symbol, and use them if so. A particularly important case of this is imports -- typically
-- the import will have an alias in the file scope. -- the import will have a `using` in the file scope.
descQualifiedName :: Desc -> Desc -> String descQualifiedName :: Desc -> Desc -> String
descQualifiedName (DescFile scope) (DescFile desc) = descQualifiedName (DescFile scope) (DescFile desc) =
if fileName scope == fileName desc if fileName scope == fileName desc
...@@ -307,7 +307,7 @@ data FileDesc = FileDesc ...@@ -307,7 +307,7 @@ data FileDesc = FileDesc
{ fileName :: String { fileName :: String
, fileId :: Maybe String , fileId :: Maybe String
, fileImports :: [FileDesc] , fileImports :: [FileDesc]
, fileAliases :: [AliasDesc] , fileUsings :: [UsingDesc]
, fileConstants :: [ConstantDesc] , fileConstants :: [ConstantDesc]
, fileEnums :: [EnumDesc] , fileEnums :: [EnumDesc]
, fileStructs :: [StructDesc] , fileStructs :: [StructDesc]
...@@ -318,10 +318,10 @@ data FileDesc = FileDesc ...@@ -318,10 +318,10 @@ data FileDesc = FileDesc
, fileStatements :: [Desc] , fileStatements :: [Desc]
} }
data AliasDesc = AliasDesc data UsingDesc = UsingDesc
{ aliasName :: String { usingName :: String
, aliasParent :: Desc , usingParent :: Desc
, aliasTarget :: Desc , usingTarget :: Desc
} }
data ConstantDesc = ConstantDesc data ConstantDesc = ConstantDesc
...@@ -358,7 +358,7 @@ data StructDesc = StructDesc ...@@ -358,7 +358,7 @@ data StructDesc = StructDesc
, structPacking :: PackingState , structPacking :: PackingState
, structFields :: [FieldDesc] , structFields :: [FieldDesc]
, structUnions :: [UnionDesc] , structUnions :: [UnionDesc]
, structNestedAliases :: [AliasDesc] , structNestedUsings :: [UsingDesc]
, structNestedConstants :: [ConstantDesc] , structNestedConstants :: [ConstantDesc]
, structNestedEnums :: [EnumDesc] , structNestedEnums :: [EnumDesc]
, structNestedStructs :: [StructDesc] , structNestedStructs :: [StructDesc]
...@@ -407,7 +407,7 @@ data InterfaceDesc = InterfaceDesc ...@@ -407,7 +407,7 @@ data InterfaceDesc = InterfaceDesc
, interfaceId :: Maybe String , interfaceId :: Maybe String
, interfaceParent :: Desc , interfaceParent :: Desc
, interfaceMethods :: [MethodDesc] , interfaceMethods :: [MethodDesc]
, interfaceNestedAliases :: [AliasDesc] , interfaceNestedUsings :: [UsingDesc]
, interfaceNestedConstants :: [ConstantDesc] , interfaceNestedConstants :: [ConstantDesc]
, interfaceNestedEnums :: [EnumDesc] , interfaceNestedEnums :: [EnumDesc]
, interfaceNestedStructs :: [StructDesc] , interfaceNestedStructs :: [StructDesc]
...@@ -456,9 +456,9 @@ descToCode indent self@(DescFile desc) = printf "# %s\n%s%s%s" ...@@ -456,9 +456,9 @@ descToCode indent self@(DescFile desc) = printf "# %s\n%s%s%s"
Nothing -> "") Nothing -> "")
(concatMap ((++ ";\n") . annotationCode self) $ Map.toList $ fileAnnotations desc) (concatMap ((++ ";\n") . annotationCode self) $ Map.toList $ fileAnnotations desc)
(concatMap (descToCode indent) (fileStatements desc)) (concatMap (descToCode indent) (fileStatements desc))
descToCode indent (DescAlias desc) = printf "%susing %s = %s;\n" indent descToCode indent (DescUsing desc) = printf "%susing %s = %s;\n" indent
(aliasName desc) (usingName desc)
(descQualifiedName (aliasParent desc) (aliasTarget desc)) (descQualifiedName (usingParent desc) (usingTarget desc))
descToCode indent self@(DescConstant desc) = printf "%sconst %s: %s = %s%s;\n" indent descToCode indent self@(DescConstant desc) = printf "%sconst %s: %s = %s%s;\n" indent
(constantName desc) (constantName desc)
(typeName (descParent self) (constantType desc)) (typeName (descParent self) (constantType desc))
...@@ -543,7 +543,7 @@ annotationsCode desc = let ...@@ -543,7 +543,7 @@ annotationsCode desc = let
Nothing -> nonIds Nothing -> nonIds
instance Show FileDesc where { show desc = descToCode "" (DescFile desc) } instance Show FileDesc where { show desc = descToCode "" (DescFile desc) }
instance Show AliasDesc where { show desc = descToCode "" (DescAlias desc) } instance Show UsingDesc where { show desc = descToCode "" (DescUsing 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 EnumerantDesc where { show desc = descToCode "" (DescEnumerant desc) } instance Show EnumerantDesc where { show desc = descToCode "" (DescEnumerant desc) }
......
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