Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
08c0a048
Commit
08c0a048
authored
Apr 20, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: alias -> using
parent
6b61f9c4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
36 deletions
+36
-36
Compiler.hs
compiler/src/Compiler.hs
+12
-12
Grammar.hs
compiler/src/Grammar.hs
+3
-3
Parser.hs
compiler/src/Parser.hs
+3
-3
Semantics.hs
compiler/src/Semantics.hs
+18
-18
No files found.
compiler/src/Compiler.hs
View file @
08c0a048
...
...
@@ -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
(
Desc
Alias
d
)
=
descMember
name
(
alias
Target
d
)
descMember
name
(
Desc
Using
d
)
=
descMember
name
(
using
Target
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
(
Desc
Alias
desc
)
=
descAsType
name
(
alias
Target
desc
)
descAsType
name
(
Desc
Using
desc
)
=
descAsType
name
(
using
Target
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
(
Alias
Decl
(
Located
_
name
)
target
)
=
compileDecl
scope
(
Using
Decl
(
Located
_
name
)
target
)
=
CompiledStatementStatus
name
(
do
targetDesc
<-
lookupDesc
scope
target
return
(
Desc
Alias
Alias
Desc
{
alias
Name
=
name
,
alias
Parent
=
scope
,
alias
Target
=
targetDesc
return
(
Desc
Using
Using
Desc
{
using
Name
=
name
,
using
Parent
=
scope
,
using
Target
=
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
,
structNested
Aliases
=
[
d
|
DescAlias
d
<-
members
]
,
structNested
Usings
=
[
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
]
,
interfaceNested
Aliases
=
[
d
|
DescAlias
d
<-
members
]
,
interfaceNested
Usings
=
[
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
,
file
Aliases
=
[
d
|
DescAlias
d
<-
members
]
,
file
Usings
=
[
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
=
[]
,
file
Aliase
s
=
[]
,
file
Using
s
=
[]
,
fileConstants
=
[]
,
fileEnums
=
[]
,
fileStructs
=
[]
...
...
compiler/src/Grammar.hs
View file @
08c0a048
...
...
@@ -91,7 +91,7 @@ instance Show AnnotationTarget where
show
ParamAnnotation
=
"param"
show
AnnotationAnnotation
=
"annotation"
data
Declaration
=
Alias
Decl
(
Located
String
)
DeclName
data
Declaration
=
Using
Decl
(
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
(
Alias
Decl
n
_
)
=
Just
n
declarationName
(
Using
Decl
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
(
Alias
Decl
_
name
)
=
maybeToList
(
declNameImport
name
)
declImports
(
Using
Decl
_
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
...
...
compiler/src/Parser.hs
View file @
08c0a048
...
...
@@ -167,16 +167,16 @@ annotation = do
return
(
Annotation
name
value
)
topLine
::
Maybe
[
Located
Statement
]
->
TokenParser
(
Either
Declaration
Annotation
)
topLine
Nothing
=
liftM
Left
(
alias
Decl
<|>
constantDecl
<|>
annotationDecl
)
topLine
Nothing
=
liftM
Left
(
using
Decl
<|>
constantDecl
<|>
annotationDecl
)
<|>
liftM
Right
annotation
topLine
(
Just
statements
)
=
liftM
Left
$
typeDecl
statements
alias
Decl
=
do
using
Decl
=
do
usingKeyword
name
<-
located
typeIdentifier
equalsSign
target
<-
declName
return
(
Alias
Decl
name
target
)
return
(
Using
Decl
name
target
)
constantDecl
=
do
constKeyword
...
...
compiler/src/Semantics.hs
View file @
08c0a048
...
...
@@ -42,7 +42,7 @@ maxOrdinal = 65534 :: Integer
type
ByteString
=
[
Word8
]
data
Desc
=
DescFile
FileDesc
|
Desc
Alias
Alias
Desc
|
Desc
Using
Using
Desc
|
DescConstant
ConstantDesc
|
DescEnum
EnumDesc
|
DescEnumerant
EnumerantDesc
...
...
@@ -58,7 +58,7 @@ data Desc = DescFile FileDesc
|
DescBuiltinId
descName
(
DescFile
_
)
=
"(top-level)"
descName
(
Desc
Alias
d
)
=
alias
Name
d
descName
(
Desc
Using
d
)
=
using
Name
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
(
Desc
Alias
_
)
=
Nothing
descId
(
Desc
Using
_
)
=
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
(
Desc
Alias
d
)
=
alias
Parent
d
descParent
(
Desc
Using
d
)
=
using
Parent
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
(
Desc
Alias
_
)
=
Map
.
empty
descAnnotations
(
Desc
Using
_
)
=
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
aliase
s 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 a
n 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
]
,
file
Aliases
::
[
Alias
Desc
]
,
file
Usings
::
[
Using
Desc
]
,
fileConstants
::
[
ConstantDesc
]
,
fileEnums
::
[
EnumDesc
]
,
fileStructs
::
[
StructDesc
]
...
...
@@ -318,10 +318,10 @@ data FileDesc = FileDesc
,
fileStatements
::
[
Desc
]
}
data
AliasDesc
=
Alias
Desc
{
alias
Name
::
String
,
alias
Parent
::
Desc
,
alias
Target
::
Desc
data
UsingDesc
=
Using
Desc
{
using
Name
::
String
,
using
Parent
::
Desc
,
using
Target
::
Desc
}
data
ConstantDesc
=
ConstantDesc
...
...
@@ -358,7 +358,7 @@ data StructDesc = StructDesc
,
structPacking
::
PackingState
,
structFields
::
[
FieldDesc
]
,
structUnions
::
[
UnionDesc
]
,
structNested
Aliases
::
[
Alias
Desc
]
,
structNested
Usings
::
[
Using
Desc
]
,
structNestedConstants
::
[
ConstantDesc
]
,
structNestedEnums
::
[
EnumDesc
]
,
structNestedStructs
::
[
StructDesc
]
...
...
@@ -407,7 +407,7 @@ data InterfaceDesc = InterfaceDesc
,
interfaceId
::
Maybe
String
,
interfaceParent
::
Desc
,
interfaceMethods
::
[
MethodDesc
]
,
interfaceNested
Aliases
::
[
Alias
Desc
]
,
interfaceNested
Usings
::
[
Using
Desc
]
,
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
(
Desc
Alias
desc
)
=
printf
"%susing %s = %s;
\n
"
indent
(
alias
Name
desc
)
(
descQualifiedName
(
aliasParent
desc
)
(
alias
Target
desc
))
descToCode
indent
(
Desc
Using
desc
)
=
printf
"%susing %s = %s;
\n
"
indent
(
using
Name
desc
)
(
descQualifiedName
(
usingParent
desc
)
(
using
Target
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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment