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
1cd5a240
Commit
1cd5a240
authored
Apr 20, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid generating #includes for imports that are used only for their annotations.
parent
dc51ed6b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
1 deletion
+58
-1
Compiler.hs
compiler/src/Compiler.hs
+2
-0
CxxGenerator.hs
compiler/src/CxxGenerator.hs
+5
-1
Semantics.hs
compiler/src/Semantics.hs
+51
-0
No files found.
compiler/src/Compiler.hs
View file @
1cd5a240
...
...
@@ -785,6 +785,8 @@ compileFile name decls annotations importMap =
{
fileName
=
name
,
fileId
=
theId
,
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
]
...
...
compiler/src/CxxGenerator.hs
View file @
1cd5a240
...
...
@@ -30,6 +30,7 @@ import Data.FileEmbed(embedFile)
import
Data.Word
(
Word8
)
import
qualified
Data.Digest.MD5
as
MD5
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
Data.Maybe
(
catMaybes
,
fromMaybe
)
import
Data.Binary.IEEE754
(
floatToWord
,
doubleToWord
)
import
Text.Printf
(
printf
)
...
...
@@ -320,6 +321,8 @@ fileContext desc = mkStrContext context where
namespace
=
maybe
[]
(
splitOn
"::"
)
$
fileNamespace
desc
isImportUsed
(
_
,
dep
)
=
Set
.
member
(
fileName
dep
)
(
fileRuntimeImports
desc
)
context
"fileName"
=
MuVariable
$
fileName
desc
context
"fileBasename"
=
MuVariable
$
takeBaseName
$
fileName
desc
context
"fileIncludeGuard"
=
MuVariable
$
...
...
@@ -327,7 +330,8 @@ fileContext desc = mkStrContext context where
context
"fileNamespaces"
=
MuList
$
map
(
namespaceContext
context
)
namespace
context
"fileEnums"
=
MuList
$
map
(
enumContext
context
)
$
fileEnums
desc
context
"fileTypes"
=
MuList
$
map
(
typeContext
context
)
flattenedMembers
context
"fileImports"
=
MuList
$
map
(
importContext
context
)
$
Map
.
keys
$
fileImportMap
desc
context
"fileImports"
=
MuList
$
map
(
importContext
context
.
fst
)
$
filter
isImportUsed
$
Map
.
toList
$
fileImportMap
desc
context
s
=
error
(
"Template variable not defined: "
++
s
)
headerTemplate
::
String
...
...
compiler/src/Semantics.hs
View file @
1cd5a240
...
...
@@ -113,6 +113,9 @@ descParent (DescBuiltinType _) = error "Builtin type has no parent."
descParent
DescBuiltinList
=
error
"Builtin type has no parent."
descParent
DescBuiltinId
=
error
"Builtin annotation has no parent."
descFile
(
DescFile
d
)
=
d
descFile
desc
=
descFile
$
descParent
desc
descAnnotations
(
DescFile
d
)
=
fileAnnotations
d
descAnnotations
(
DescUsing
_
)
=
Map
.
empty
descAnnotations
(
DescConstant
d
)
=
constantAnnotations
d
...
...
@@ -129,6 +132,22 @@ descAnnotations (DescBuiltinType _) = Map.empty
descAnnotations
DescBuiltinList
=
Map
.
empty
descAnnotations
DescBuiltinId
=
Map
.
empty
descRuntimeImports
(
DescFile
d
)
=
error
"Not to be called on files."
descRuntimeImports
(
DescUsing
d
)
=
usingRuntimeImports
d
descRuntimeImports
(
DescConstant
d
)
=
constantRuntimeImports
d
descRuntimeImports
(
DescEnum
d
)
=
enumRuntimeImports
d
descRuntimeImports
(
DescEnumerant
d
)
=
enumerantRuntimeImports
d
descRuntimeImports
(
DescStruct
d
)
=
structRuntimeImports
d
descRuntimeImports
(
DescUnion
d
)
=
unionRuntimeImports
d
descRuntimeImports
(
DescField
d
)
=
fieldRuntimeImports
d
descRuntimeImports
(
DescInterface
d
)
=
interfaceRuntimeImports
d
descRuntimeImports
(
DescMethod
d
)
=
methodRuntimeImports
d
descRuntimeImports
(
DescParam
d
)
=
paramRuntimeImports
d
descRuntimeImports
(
DescAnnotation
d
)
=
annotationRuntimeImports
d
descRuntimeImports
(
DescBuiltinType
_
)
=
[]
descRuntimeImports
DescBuiltinList
=
[]
descRuntimeImports
DescBuiltinId
=
[]
type
MemberMap
=
Map
.
Map
String
(
Maybe
Desc
)
lookupMember
::
String
->
MemberMap
->
Maybe
Desc
...
...
@@ -196,6 +215,12 @@ data TypeDesc = BuiltinType BuiltinType
|
InterfaceType
InterfaceDesc
|
ListType
TypeDesc
typeRuntimeImports
(
BuiltinType
_
)
=
[]
typeRuntimeImports
(
EnumType
d
)
=
[
descFile
(
DescEnum
d
)]
typeRuntimeImports
(
StructType
d
)
=
[
descFile
(
DescStruct
d
)]
typeRuntimeImports
(
InterfaceType
d
)
=
[
descFile
(
DescInterface
d
)]
typeRuntimeImports
(
ListType
d
)
=
typeRuntimeImports
d
data
PackingState
=
PackingState
{
packingHole1
::
Integer
,
packingHole8
::
Integer
...
...
@@ -307,6 +332,9 @@ data FileDesc = FileDesc
{
fileName
::
String
,
fileId
::
Maybe
String
,
fileImports
::
[
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
]
...
...
@@ -324,6 +352,8 @@ data UsingDesc = UsingDesc
,
usingTarget
::
Desc
}
usingRuntimeImports
_
=
[]
data
ConstantDesc
=
ConstantDesc
{
constantName
::
String
,
constantId
::
Maybe
String
...
...
@@ -333,6 +363,8 @@ data ConstantDesc = ConstantDesc
,
constantValue
::
ValueDesc
}
constantRuntimeImports
desc
=
typeRuntimeImports
$
constantType
desc
data
EnumDesc
=
EnumDesc
{
enumName
::
String
,
enumId
::
Maybe
String
...
...
@@ -343,6 +375,8 @@ data EnumDesc = EnumDesc
,
enumStatements
::
[
Desc
]
}
enumRuntimeImports
desc
=
concatMap
descRuntimeImports
$
enumStatements
desc
data
EnumerantDesc
=
EnumerantDesc
{
enumerantName
::
String
,
enumerantId
::
Maybe
String
...
...
@@ -351,6 +385,8 @@ data EnumerantDesc = EnumerantDesc
,
enumerantAnnotations
::
AnnotationMap
}
enumerantRuntimeImports
_
=
[]
data
StructDesc
=
StructDesc
{
structName
::
String
,
structId
::
Maybe
String
...
...
@@ -373,6 +409,8 @@ data StructDesc = StructDesc
,
structFieldPackingMap
::
Map
.
Map
Integer
(
Integer
,
PackingState
)
}
structRuntimeImports
desc
=
concatMap
descRuntimeImports
$
structStatements
desc
data
UnionDesc
=
UnionDesc
{
unionName
::
String
,
unionId
::
Maybe
String
...
...
@@ -389,6 +427,8 @@ data UnionDesc = UnionDesc
,
unionFieldDiscriminantMap
::
Map
.
Map
Integer
Integer
}
unionRuntimeImports
desc
=
concatMap
descRuntimeImports
$
unionStatements
desc
data
FieldDesc
=
FieldDesc
{
fieldName
::
String
,
fieldId
::
Maybe
String
...
...
@@ -402,6 +442,8 @@ data FieldDesc = FieldDesc
,
fieldAnnotations
::
AnnotationMap
}
fieldRuntimeImports
desc
=
typeRuntimeImports
$
fieldType
desc
data
InterfaceDesc
=
InterfaceDesc
{
interfaceName
::
String
,
interfaceId
::
Maybe
String
...
...
@@ -417,6 +459,8 @@ data InterfaceDesc = InterfaceDesc
,
interfaceStatements
::
[
Desc
]
}
interfaceRuntimeImports
desc
=
concatMap
descRuntimeImports
$
interfaceStatements
desc
data
MethodDesc
=
MethodDesc
{
methodName
::
String
,
methodId
::
Maybe
String
...
...
@@ -427,6 +471,9 @@ data MethodDesc = MethodDesc
,
methodAnnotations
::
AnnotationMap
}
methodRuntimeImports
desc
=
typeRuntimeImports
(
methodReturnType
desc
)
++
concatMap
paramRuntimeImports
(
methodParams
desc
)
data
ParamDesc
=
ParamDesc
{
paramName
::
String
,
paramId
::
Maybe
String
...
...
@@ -437,6 +484,8 @@ data ParamDesc = ParamDesc
,
paramAnnotations
::
AnnotationMap
}
paramRuntimeImports
desc
=
typeRuntimeImports
$
paramType
desc
data
AnnotationDesc
=
AnnotationDesc
{
annotationName
::
String
,
annotationParent
::
Desc
...
...
@@ -446,6 +495,8 @@ data AnnotationDesc = AnnotationDesc
,
annotationTargets
::
Set
.
Set
AnnotationTarget
}
annotationRuntimeImports
desc
=
typeRuntimeImports
$
annotationType
desc
type
AnnotationMap
=
Map
.
Map
String
(
AnnotationDesc
,
ValueDesc
)
descToCode
::
String
->
Desc
->
String
...
...
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