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)
descMember name (DescEnum d) = lookupMember name (enumMemberMap 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 name (DescUsing d) = descMember name (usingTarget d)
descMember _ _ = Nothing
-- | Lookup the given name in the scope of the given descriptor.
......@@ -255,7 +255,7 @@ compileValue pos (ListType _) _ = makeExpectError pos "list"
makeFileMemberMap :: FileDesc -> Map.Map String Desc
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 ]
++ [ (enumName m, DescEnum m) | m <- fileEnums desc ]
++ [ (structName m, DescStruct m) | m <- fileStructs desc ]
......@@ -265,7 +265,7 @@ descAsType _ (DescEnum desc) = succeed (EnumType 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)
descAsType name (DescUsing desc) = descAsType name (usingTarget desc)
descAsType name DescBuiltinList = makeError (declNamePos name) message where
message = printf "'List' requires exactly one type parameter." (declNameString name)
descAsType name _ = makeError (declNamePos name) message where
......@@ -553,13 +553,13 @@ compileChildDecls desc decls = Active (members, memberMap) errors where
| CompiledStatementStatus name status <- compiledDecls]
errors = concatMap compiledErrors compiledDecls
compileDecl scope (AliasDecl (Located _ name) target) =
compileDecl scope (UsingDecl (Located _ name) target) =
CompiledStatementStatus name (do
targetDesc <- lookupDesc scope target
return (DescAlias AliasDesc
{ aliasName = name
, aliasParent = scope
, aliasTarget = targetDesc
return (DescUsing UsingDesc
{ usingName = name
, usingParent = scope
, usingTarget = targetDesc
}))
compileDecl scope (ConstantDecl (Located _ name) t annotations (Located valuePos value)) =
......@@ -627,7 +627,7 @@ compileDecl scope (StructDecl (Located _ name) annotations decls) =
, structPacking = packing
, structFields = fields
, structUnions = unions
, structNestedAliases = [d | DescAlias d <- members]
, structNestedUsings = [d | DescUsing d <- members]
, structNestedConstants = [d | DescConstant d <- members]
, structNestedEnums = [d | DescEnum d <- members]
, structNestedStructs = [d | DescStruct d <- members]
......@@ -708,7 +708,7 @@ compileDecl scope (InterfaceDecl (Located _ name) annotations decls) =
, interfaceId = theId
, interfaceParent = scope
, interfaceMethods = [d | DescMethod d <- members]
, interfaceNestedAliases = [d | DescAlias d <- members]
, interfaceNestedUsings = [d | DescUsing d <- members]
, interfaceNestedConstants = [d | DescConstant d <- members]
, interfaceNestedEnums = [d | DescEnum d <- members]
, interfaceNestedStructs = [d | DescStruct d <- members]
......@@ -777,7 +777,7 @@ compileFile name decls annotations importMap =
{ fileName = name
, fileId = theId
, fileImports = Map.elems importMap
, fileAliases = [d | DescAlias d <- members]
, fileUsings = [d | DescUsing d <- members]
, fileConstants = [d | DescConstant d <- members]
, fileEnums = [d | DescEnum d <- members]
, fileStructs = [d | DescStruct d <- members]
......@@ -795,7 +795,7 @@ emptyFileDesc filename = FileDesc
{ fileName = filename
, fileId = Nothing
, fileImports = []
, fileAliases = []
, fileUsings = []
, fileConstants = []
, fileEnums = []
, fileStructs = []
......
......@@ -91,7 +91,7 @@ instance Show AnnotationTarget where
show ParamAnnotation = "param"
show AnnotationAnnotation = "annotation"
data Declaration = AliasDecl (Located String) DeclName
data Declaration = UsingDecl (Located String) DeclName
| ConstantDecl (Located String) TypeExpression [Annotation] (Located FieldValue)
| EnumDecl (Located String) [Annotation] [Declaration]
| EnumerantDecl (Located String) (Located Integer) [Annotation]
......@@ -106,7 +106,7 @@ data Declaration = AliasDecl (Located String) DeclName
deriving (Show)
declarationName :: Declaration -> Maybe (Located String)
declarationName (AliasDecl n _) = Just n
declarationName (UsingDecl n _) = Just n
declarationName (ConstantDecl n _ _ _) = Just n
declarationName (EnumDecl n _ _) = Just n
declarationName (EnumerantDecl n _ _) = Just n
......@@ -118,7 +118,7 @@ declarationName (MethodDecl n _ _ _ _) = Just n
declarationName (AnnotationDecl n _ _ _) = Just n
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 (EnumDecl _ ann decls) = concatMap annotationImports ann ++ concatMap declImports decls
declImports (EnumerantDecl _ _ ann) = concatMap annotationImports ann
......
......@@ -167,16 +167,16 @@ annotation = do
return (Annotation name value)
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
topLine (Just statements) = liftM Left $ typeDecl statements
aliasDecl = do
usingDecl = do
usingKeyword
name <- located typeIdentifier
equalsSign
target <- declName
return (AliasDecl name target)
return (UsingDecl name target)
constantDecl = do
constKeyword
......
......@@ -42,7 +42,7 @@ maxOrdinal = 65534 :: Integer
type ByteString = [Word8]
data Desc = DescFile FileDesc
| DescAlias AliasDesc
| DescUsing UsingDesc
| DescConstant ConstantDesc
| DescEnum EnumDesc
| DescEnumerant EnumerantDesc
......@@ -58,7 +58,7 @@ data Desc = DescFile FileDesc
| DescBuiltinId
descName (DescFile _) = "(top-level)"
descName (DescAlias d) = aliasName d
descName (DescUsing d) = usingName d
descName (DescConstant d) = constantName d
descName (DescEnum d) = enumName d
descName (DescEnumerant d) = enumerantName d
......@@ -74,7 +74,7 @@ descName DescBuiltinList = "List"
descName DescBuiltinId = "id"
descId (DescFile d) = fileId d
descId (DescAlias _) = Nothing
descId (DescUsing _) = Nothing
descId (DescConstant d) = constantId d
descId (DescEnum d) = enumId d
descId (DescEnumerant d) = enumerantId d
......@@ -98,7 +98,7 @@ descAutoId d = case descId d of
_ -> fmap (++ '.':descName d) $ descAutoId $ descParent d
descParent (DescFile _) = error "File descriptor has no parent."
descParent (DescAlias d) = aliasParent d
descParent (DescUsing d) = usingParent d
descParent (DescConstant d) = constantParent d
descParent (DescEnum d) = enumParent d
descParent (DescEnumerant d) = DescEnum (enumerantParent d)
......@@ -114,7 +114,7 @@ descParent DescBuiltinList = error "Builtin type has no parent."
descParent DescBuiltinId = error "Builtin annotation has no parent."
descAnnotations (DescFile d) = fileAnnotations d
descAnnotations (DescAlias _) = Map.empty
descAnnotations (DescUsing _) = Map.empty
descAnnotations (DescConstant d) = constantAnnotations d
descAnnotations (DescEnum d) = enumAnnotations d
descAnnotations (DescEnumerant d) = enumerantAnnotations d
......@@ -291,9 +291,9 @@ typeName scope (ListType t) = "List(" ++ typeName scope t ++ ")"
-- 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
-- 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
-- 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 (DescFile scope) (DescFile desc) =
if fileName scope == fileName desc
......@@ -307,7 +307,7 @@ data FileDesc = FileDesc
{ fileName :: String
, fileId :: Maybe String
, fileImports :: [FileDesc]
, fileAliases :: [AliasDesc]
, fileUsings :: [UsingDesc]
, fileConstants :: [ConstantDesc]
, fileEnums :: [EnumDesc]
, fileStructs :: [StructDesc]
......@@ -318,10 +318,10 @@ data FileDesc = FileDesc
, fileStatements :: [Desc]
}
data AliasDesc = AliasDesc
{ aliasName :: String
, aliasParent :: Desc
, aliasTarget :: Desc
data UsingDesc = UsingDesc
{ usingName :: String
, usingParent :: Desc
, usingTarget :: Desc
}
data ConstantDesc = ConstantDesc
......@@ -358,7 +358,7 @@ data StructDesc = StructDesc
, structPacking :: PackingState
, structFields :: [FieldDesc]
, structUnions :: [UnionDesc]
, structNestedAliases :: [AliasDesc]
, structNestedUsings :: [UsingDesc]
, structNestedConstants :: [ConstantDesc]
, structNestedEnums :: [EnumDesc]
, structNestedStructs :: [StructDesc]
......@@ -407,7 +407,7 @@ data InterfaceDesc = InterfaceDesc
, interfaceId :: Maybe String
, interfaceParent :: Desc
, interfaceMethods :: [MethodDesc]
, interfaceNestedAliases :: [AliasDesc]
, interfaceNestedUsings :: [UsingDesc]
, interfaceNestedConstants :: [ConstantDesc]
, interfaceNestedEnums :: [EnumDesc]
, interfaceNestedStructs :: [StructDesc]
......@@ -456,9 +456,9 @@ descToCode indent self@(DescFile desc) = printf "# %s\n%s%s%s"
Nothing -> "")
(concatMap ((++ ";\n") . annotationCode self) $ Map.toList $ fileAnnotations desc)
(concatMap (descToCode indent) (fileStatements desc))
descToCode indent (DescAlias desc) = printf "%susing %s = %s;\n" indent
(aliasName desc)
(descQualifiedName (aliasParent desc) (aliasTarget desc))
descToCode indent (DescUsing desc) = printf "%susing %s = %s;\n" indent
(usingName desc)
(descQualifiedName (usingParent desc) (usingTarget desc))
descToCode indent self@(DescConstant desc) = printf "%sconst %s: %s = %s%s;\n" indent
(constantName desc)
(typeName (descParent self) (constantType desc))
......@@ -543,7 +543,7 @@ annotationsCode desc = let
Nothing -> nonIds
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 EnumDesc where { show desc = descToCode "" (DescEnum 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