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
5b8035fa
Commit
5b8035fa
authored
Apr 20, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: Remove some redundant fields in descriptor structures.
parent
5d83e1db
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
69 deletions
+26
-69
Compiler.hs
compiler/src/Compiler.hs
+8
-36
CxxGenerator.hs
compiler/src/CxxGenerator.hs
+4
-4
Semantics.hs
compiler/src/Semantics.hs
+14
-29
No files found.
compiler/src/Compiler.hs
View file @
5b8035fa
...
...
@@ -21,7 +21,7 @@
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module
Compiler
where
module
Compiler
(
Status
(
..
),
parseAndCompileFile
)
where
import
Grammar
import
Semantics
...
...
@@ -257,14 +257,6 @@ compileValue pos (StructType _) _ = makeExpectError pos "parenthesized list of f
compileValue
pos
(
InterfaceType
_
)
_
=
makeError
pos
"Interfaces can't have default values."
compileValue
pos
(
ListType
_
)
_
=
makeExpectError
pos
"list"
makeFileMemberMap
::
FileDesc
->
Map
.
Map
String
Desc
makeFileMemberMap
desc
=
Map
.
fromList
allMembers
where
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
]
++
[
(
interfaceName
m
,
DescInterface
m
)
|
m
<-
fileInterfaces
desc
]
descAsType
_
(
DescEnum
desc
)
=
succeed
(
EnumType
desc
)
descAsType
_
(
DescStruct
desc
)
=
succeed
(
StructType
desc
)
descAsType
_
(
DescInterface
desc
)
=
succeed
(
InterfaceType
desc
)
...
...
@@ -595,7 +587,7 @@ compileDecl scope (EnumDecl (Located _ name) annotations decls) =
,
enumerants
=
[
d
|
DescEnumerant
d
<-
members
]
,
enumAnnotations
=
compiledAnnotations
,
enumMemberMap
=
memberMap
,
enum
Statement
s
=
members
,
enum
Member
s
=
members
})))
compileDecl
scope
@
(
DescEnum
parent
)
...
...
@@ -631,14 +623,9 @@ compileDecl scope (StructDecl (Located _ name) annotations decls) =
,
structPacking
=
packing
,
structFields
=
fields
,
structUnions
=
unions
,
structNestedUsings
=
[
d
|
DescUsing
d
<-
members
]
,
structNestedConstants
=
[
d
|
DescConstant
d
<-
members
]
,
structNestedEnums
=
[
d
|
DescEnum
d
<-
members
]
,
structNestedStructs
=
[
d
|
DescStruct
d
<-
members
]
,
structNestedInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
structAnnotations
=
compiledAnnotations
,
structMemberMap
=
memberMap
,
struct
Statement
s
=
members
,
struct
Member
s
=
members
,
structFieldPackingMap
=
fieldPackingMap
})))
...
...
@@ -663,7 +650,7 @@ compileDecl scope@(DescStruct parent)
,
unionFields
=
fields
,
unionAnnotations
=
compiledAnnotations
,
unionMemberMap
=
memberMap
,
union
Statement
s
=
members
,
union
Member
s
=
members
,
unionFieldDiscriminantMap
=
discriminantMap
})))
compileDecl
_
(
UnionDecl
(
Located
pos
name
)
_
_
_
)
=
...
...
@@ -711,15 +698,10 @@ compileDecl scope (InterfaceDecl (Located _ name) annotations decls) =
{
interfaceName
=
name
,
interfaceId
=
theId
,
interfaceParent
=
scope
,
interfaceMethods
=
[
d
|
DescMethod
d
<-
members
]
,
interfaceNestedUsings
=
[
d
|
DescUsing
d
<-
members
]
,
interfaceNestedConstants
=
[
d
|
DescConstant
d
<-
members
]
,
interfaceNestedEnums
=
[
d
|
DescEnum
d
<-
members
]
,
interfaceNestedStructs
=
[
d
|
DescStruct
d
<-
members
]
,
interfaceNestedInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
interfaceMethods
=
[
d
|
DescMethod
d
<-
members
]
,
interfaceAnnotations
=
compiledAnnotations
,
interfaceMemberMap
=
memberMap
,
interface
Statement
s
=
members
,
interface
Member
s
=
members
})))
compileDecl
scope
@
(
DescInterface
parent
)
...
...
@@ -783,15 +765,10 @@ compileFile name decls annotations importMap =
,
fileImports
=
Map
.
elems
importMap
,
fileRuntimeImports
=
Set
.
fromList
$
map
fileName
$
concatMap
descRuntimeImports
members
,
fileUsings
=
[
d
|
DescUsing
d
<-
members
]
,
fileConstants
=
[
d
|
DescConstant
d
<-
members
]
,
fileEnums
=
[
d
|
DescEnum
d
<-
members
]
,
fileStructs
=
[
d
|
DescStruct
d
<-
members
]
,
fileInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
fileAnnotations
=
compiledAnnotations
,
fileMemberMap
=
memberMap
,
fileImportMap
=
importMap
,
file
Statement
s
=
members
,
file
Member
s
=
members
})
dedup
::
Ord
a
=>
[
a
]
->
[
a
]
...
...
@@ -802,15 +779,10 @@ emptyFileDesc filename = FileDesc
,
fileId
=
Nothing
,
fileImports
=
[]
,
fileRuntimeImports
=
Set
.
empty
,
fileUsings
=
[]
,
fileConstants
=
[]
,
fileEnums
=
[]
,
fileStructs
=
[]
,
fileInterfaces
=
[]
,
fileAnnotations
=
Map
.
empty
,
fileMemberMap
=
Map
.
empty
,
fileImportMap
=
Map
.
empty
,
file
Statement
s
=
[]
,
file
Member
s
=
[]
}
parseAndCompileFile
::
Monad
m
...
...
compiler/src/CxxGenerator.hs
View file @
5b8035fa
...
...
@@ -286,11 +286,11 @@ structContext parent desc = mkStrContext context where
context
"structDataSize"
=
MuVariable
$
packingDataSize
$
structPacking
desc
context
"structReferenceCount"
=
MuVariable
$
packingReferenceCount
$
structPacking
desc
context
"structNestedEnums"
=
MuList
$
map
(
enumContext
context
)
$
structNestedEnums
desc
MuList
$
map
(
enumContext
context
)
[
m
|
DescEnum
m
<-
structMembers
desc
]
context
"structNestedStructs"
=
MuList
$
map
(
childContext
context
.
structName
)
$
structNestedStructs
desc
MuList
$
map
(
childContext
context
.
structName
)
[
m
|
DescStruct
m
<-
structMembers
desc
]
context
"structNestedInterfaces"
=
MuList
$
map
(
childContext
context
.
interfaceName
)
$
structNestedInterfaces
desc
MuList
$
map
(
childContext
context
.
interfaceName
)
[
m
|
DescInterface
m
<-
structMembers
desc
]
context
s
=
parent
s
typeContext
parent
desc
=
mkStrContext
context
where
...
...
@@ -328,7 +328,7 @@ fileContext desc = mkStrContext context where
context
"fileIncludeGuard"
=
MuVariable
$
"CAPNPROTO_INCLUDED_"
++
hashString
(
fileName
desc
++
':'
:
fromMaybe
""
(
fileId
desc
))
context
"fileNamespaces"
=
MuList
$
map
(
namespaceContext
context
)
namespace
context
"fileEnums"
=
MuList
$
map
(
enumContext
context
)
$
fileEnums
desc
context
"fileEnums"
=
MuList
$
map
(
enumContext
context
)
[
e
|
DescEnum
e
<-
fileMembers
desc
]
context
"fileTypes"
=
MuList
$
map
(
typeContext
context
)
flattenedMembers
context
"fileImports"
=
MuList
$
map
(
importContext
context
.
fst
)
$
filter
isImportUsed
$
Map
.
toList
$
fileImportMap
desc
...
...
compiler/src/Semantics.hs
View file @
5b8035fa
...
...
@@ -335,15 +335,10 @@ data FileDesc = FileDesc
-- Set of imports which are used at runtime, i.e. not just for annotations.
-- The set contains file names matching files in fileImports.
,
fileRuntimeImports
::
Set
.
Set
String
,
fileUsings
::
[
UsingDesc
]
,
fileConstants
::
[
ConstantDesc
]
,
fileEnums
::
[
EnumDesc
]
,
fileStructs
::
[
StructDesc
]
,
fileInterfaces
::
[
InterfaceDesc
]
,
fileAnnotations
::
AnnotationMap
,
fileMemberMap
::
MemberMap
,
fileImportMap
::
Map
.
Map
String
FileDesc
,
file
Statement
s
::
[
Desc
]
,
file
Member
s
::
[
Desc
]
}
data
UsingDesc
=
UsingDesc
...
...
@@ -372,10 +367,10 @@ data EnumDesc = EnumDesc
,
enumerants
::
[
EnumerantDesc
]
,
enumAnnotations
::
AnnotationMap
,
enumMemberMap
::
MemberMap
,
enum
Statement
s
::
[
Desc
]
,
enum
Member
s
::
[
Desc
]
}
enumRuntimeImports
desc
=
concatMap
descRuntimeImports
$
enum
Statement
s
desc
enumRuntimeImports
desc
=
concatMap
descRuntimeImports
$
enum
Member
s
desc
data
EnumerantDesc
=
EnumerantDesc
{
enumerantName
::
String
...
...
@@ -394,14 +389,9 @@ data StructDesc = StructDesc
,
structPacking
::
PackingState
,
structFields
::
[
FieldDesc
]
,
structUnions
::
[
UnionDesc
]
,
structNestedUsings
::
[
UsingDesc
]
,
structNestedConstants
::
[
ConstantDesc
]
,
structNestedEnums
::
[
EnumDesc
]
,
structNestedStructs
::
[
StructDesc
]
,
structNestedInterfaces
::
[
InterfaceDesc
]
,
structAnnotations
::
AnnotationMap
,
structMemberMap
::
MemberMap
,
struct
Statement
s
::
[
Desc
]
,
struct
Member
s
::
[
Desc
]
-- Don't use this directly, use the members of FieldDesc and UnionDesc.
-- This field is exposed here only because I was too lazy to create a way to pass it on
...
...
@@ -409,7 +399,7 @@ data StructDesc = StructDesc
,
structFieldPackingMap
::
Map
.
Map
Integer
(
Integer
,
PackingState
)
}
structRuntimeImports
desc
=
concatMap
descRuntimeImports
$
struct
Statement
s
desc
structRuntimeImports
desc
=
concatMap
descRuntimeImports
$
struct
Member
s
desc
data
UnionDesc
=
UnionDesc
{
unionName
::
String
...
...
@@ -421,13 +411,13 @@ data UnionDesc = UnionDesc
,
unionFields
::
[
FieldDesc
]
,
unionAnnotations
::
AnnotationMap
,
unionMemberMap
::
MemberMap
,
union
Statement
s
::
[
Desc
]
,
union
Member
s
::
[
Desc
]
-- Maps field numbers to discriminants for all fields in the union.
,
unionFieldDiscriminantMap
::
Map
.
Map
Integer
Integer
}
unionRuntimeImports
desc
=
concatMap
descRuntimeImports
$
union
Statement
s
desc
unionRuntimeImports
desc
=
concatMap
descRuntimeImports
$
union
Member
s
desc
data
FieldDesc
=
FieldDesc
{
fieldName
::
String
...
...
@@ -449,17 +439,12 @@ data InterfaceDesc = InterfaceDesc
,
interfaceId
::
Maybe
String
,
interfaceParent
::
Desc
,
interfaceMethods
::
[
MethodDesc
]
,
interfaceNestedUsings
::
[
UsingDesc
]
,
interfaceNestedConstants
::
[
ConstantDesc
]
,
interfaceNestedEnums
::
[
EnumDesc
]
,
interfaceNestedStructs
::
[
StructDesc
]
,
interfaceNestedInterfaces
::
[
InterfaceDesc
]
,
interfaceAnnotations
::
AnnotationMap
,
interfaceMemberMap
::
MemberMap
,
interface
Statement
s
::
[
Desc
]
,
interface
Member
s
::
[
Desc
]
}
interfaceRuntimeImports
desc
=
concatMap
descRuntimeImports
$
interface
Statement
s
desc
interfaceRuntimeImports
desc
=
concatMap
descRuntimeImports
$
interface
Member
s
desc
data
MethodDesc
=
MethodDesc
{
methodName
::
String
...
...
@@ -506,7 +491,7 @@ descToCode indent self@(DescFile desc) = printf "# %s\n%s%s%s"
Just
i
->
printf
"$id(%s);
\n
"
$
show
i
Nothing
->
""
)
(
concatMap
((
++
";
\n
"
)
.
annotationCode
self
)
$
Map
.
toList
$
fileAnnotations
desc
)
(
concatMap
(
descToCode
indent
)
(
file
Statement
s
desc
))
(
concatMap
(
descToCode
indent
)
(
file
Member
s
desc
))
descToCode
indent
(
DescUsing
desc
)
=
printf
"%susing %s = %s;
\n
"
indent
(
usingName
desc
)
(
descQualifiedName
(
usingParent
desc
)
(
usingTarget
desc
))
...
...
@@ -518,7 +503,7 @@ descToCode indent self@(DescConstant desc) = printf "%sconst %s: %s = %s%s;\n" i
descToCode
indent
self
@
(
DescEnum
desc
)
=
printf
"%senum %s%s {
\n
%s%s}
\n
"
indent
(
enumName
desc
)
(
annotationsCode
self
)
(
blockCode
indent
(
enum
Statement
s
desc
))
(
blockCode
indent
(
enum
Member
s
desc
))
indent
descToCode
indent
self
@
(
DescEnumerant
desc
)
=
printf
"%s%s @%d%s;
\n
"
indent
(
enumerantName
desc
)
(
enumerantNumber
desc
)
...
...
@@ -526,7 +511,7 @@ descToCode indent self@(DescEnumerant desc) = printf "%s%s @%d%s;\n" indent
descToCode
indent
self
@
(
DescStruct
desc
)
=
printf
"%sstruct %s%s {
\n
%s%s}
\n
"
indent
(
structName
desc
)
(
annotationsCode
self
)
(
blockCode
indent
(
struct
Statement
s
desc
))
(
blockCode
indent
(
struct
Member
s
desc
))
indent
descToCode
indent
self
@
(
DescField
desc
)
=
printf
"%s%s@%d%s: %s%s%s; # %s
\n
"
indent
(
fieldName
desc
)
(
fieldNumber
desc
)
...
...
@@ -545,12 +530,12 @@ descToCode indent self@(DescUnion desc) = printf "%sunion %s@%d%s { # [%d, %d)\
(
unionName
desc
)
(
unionNumber
desc
)
(
annotationsCode
self
)
(
unionTagOffset
desc
*
16
)
(
unionTagOffset
desc
*
16
+
16
)
(
blockCode
indent
$
union
Statement
s
desc
)
(
blockCode
indent
$
union
Member
s
desc
)
indent
descToCode
indent
self
@
(
DescInterface
desc
)
=
printf
"%sinterface %s%s {
\n
%s%s}
\n
"
indent
(
interfaceName
desc
)
(
annotationsCode
self
)
(
blockCode
indent
(
interface
Statement
s
desc
))
(
blockCode
indent
(
interface
Member
s
desc
))
indent
descToCode
indent
self
@
(
DescMethod
desc
)
=
printf
"%s%s@%d(%s): %s%s"
indent
(
methodName
desc
)
(
methodNumber
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