Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
730f7455
Commit
730f7455
authored
May 26, 2015
by
Miro Knejp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AST representation of external types
parent
18b37727
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
13 deletions
+30
-13
src/source/ast.scala
src/source/ast.scala
+8
-1
src/source/generator.scala
src/source/generator.scala
+6
-8
src/source/parser.scala
src/source/parser.scala
+1
-1
src/source/resolver.scala
src/source/resolver.scala
+15
-3
No files found.
src/source/ast.scala
View file @
730f7455
...
...
@@ -37,7 +37,14 @@ case class TypeParam(ident: Ident)
case
class
Doc
(
lines
:
Seq
[
String
])
case
class
TypeDecl
(
ident
:
Ident
,
params
:
Seq
[
TypeParam
],
body
:
TypeDef
,
doc
:
Doc
,
origin
:
String
)
sealed
abstract
class
TypeDecl
{
val
ident
:
Ident
val
params
:
Seq
[
TypeParam
]
val
body
:
TypeDef
val
origin
:
String
}
case
class
InternTypeDecl
(
override
val
ident
:
Ident
,
override
val
params
:
Seq
[
TypeParam
],
override
val
body
:
TypeDef
,
doc
:
Doc
,
override
val
origin
:
String
)
extends
TypeDecl
case
class
ExternTypeDecl
(
override
val
ident
:
Ident
,
override
val
params
:
Seq
[
TypeParam
],
override
val
body
:
TypeDef
,
properties
:
Map
[
String
,
Any
],
override
val
origin
:
String
)
extends
TypeDecl
case
class
Ext
(
java
:
Boolean
,
cpp
:
Boolean
,
objc
:
Boolean
)
{
def
any
()
:
Boolean
=
{
...
...
src/source/generator.scala
View file @
730f7455
...
...
@@ -298,8 +298,7 @@ abstract class Generator(spec: Spec)
}
def
generate
(
idl
:
Seq
[
TypeDecl
])
{
for
(
td
<-
idl
)
{
td
.
body
match
{
for
(
td
<-
idl
.
collect
{
case
itd
:
InternTypeDecl
=>
itd
})
td
.
body
match
{
case
e
:
Enum
=>
assert
(
td
.
params
.
isEmpty
)
generateEnum
(
td
.
origin
,
td
.
ident
,
td
.
doc
,
e
)
...
...
@@ -307,7 +306,6 @@ abstract class Generator(spec: Spec)
case
i
:
Interface
=>
generateInterface
(
td
.
origin
,
td
.
ident
,
td
.
doc
,
td
.
params
,
i
)
}
}
}
def
generateEnum
(
origin
:
String
,
ident
:
Ident
,
doc
:
Doc
,
e
:
Enum
)
def
generateRecord
(
origin
:
String
,
ident
:
Ident
,
doc
:
Doc
,
params
:
Seq
[
TypeParam
],
r
:
Record
)
...
...
src/source/parser.scala
View file @
730f7455
...
...
@@ -51,7 +51,7 @@ private object IdlParser extends RegexParsers {
def
externDirective
=
"extern"
.
r
def
typeDecl
(
origin
:
String
)
:
Parser
[
TypeDecl
]
=
doc
~
ident
~
typeList
(
ident
^^
TypeParam
)
~
"="
~
typeDef
^^
{
case
doc
~
ident
~
typeParams
~
_
~
body
=>
TypeDecl
(
ident
,
typeParams
,
body
,
doc
,
origin
)
case
doc
~
ident
~
typeParams
~
_
~
body
=>
Intern
TypeDecl
(
ident
,
typeParams
,
body
,
doc
,
origin
)
}
def
ext
(
default
:
Ext
)
=
(
rep1
(
"+"
~>
ident
)
>>
checkExts
)
|
success
(
default
)
...
...
src/source/resolver.scala
View file @
730f7455
...
...
@@ -42,7 +42,7 @@ def resolve(metas: Scope, idl: Seq[TypeDecl]): Option[Error] = {
for
(
typeDecl
<-
idl
)
{
topLevelDupeChecker
.
check
(
typeDecl
.
ident
)
val
defType
=
typeDecl
.
body
match
{
def
defType
=
typeDecl
.
body
match
{
case
e
:
Enum
=>
if
(!
typeDecl
.
params
.
isEmpty
)
{
throw
Error
(
typeDecl
.
ident
.
loc
,
"enums can't have type parameters"
).
toException
...
...
@@ -51,8 +51,10 @@ def resolve(metas: Scope, idl: Seq[TypeDecl]): Option[Error] = {
case
r
:
Record
=>
DRecord
case
i
:
Interface
=>
DInterface
}
val
mdef
=
MDef
(
typeDecl
.
ident
.
name
,
typeDecl
.
params
.
length
,
defType
,
typeDecl
.
body
)
topScope
=
topScope
.
updated
(
typeDecl
.
ident
.
name
,
mdef
)
topScope
=
topScope
.
updated
(
typeDecl
.
ident
.
name
,
typeDecl
match
{
case
td
:
InternTypeDecl
=>
MDef
(
typeDecl
.
ident
.
name
,
typeDecl
.
params
.
length
,
defType
,
typeDecl
.
body
)
case
td
:
ExternTypeDecl
=>
throw
new
AssertionError
(
"not implemented"
)
})
}
// Resolve everything
...
...
@@ -201,6 +203,7 @@ private def constTypeCheck(ty: MExpr, value: Any, resolvedConsts: Seq[Const]) {
throw
new
AssertionError
(
s
"Const type mismatch: enum ${d.name} does not have option ${opt.name}"
)
}
}
case
e
:
MExtern
=>
throw
new
AssertionError
(
"Extern type not allowed for constant"
)
case
_
=>
throw
new
AssertionError
(
"Const type cannot be resolved"
)
}
}
...
...
@@ -241,6 +244,15 @@ private def resolveRecord(scope: Scope, r: Record) {
throw
new
Error
(
f
.
ident
.
loc
,
s
"Some deriving required is not implemented in record ${f.ident.name}"
).
toException
case
DEnum
=>
}
case
e
:
MExtern
=>
e
.
defType
match
{
case
DInterface
=>
throw
new
Error
(
f
.
ident
.
loc
,
"Interface reference cannot live in a record"
).
toException
case
DRecord
=>
val
record
=
e
.
body
.
asInstanceOf
[
Record
]
if
(!
r
.
derivingTypes
.
subsetOf
(
record
.
derivingTypes
))
throw
new
Error
(
f
.
ident
.
loc
,
s
"Some deriving required is not implemented in record ${f.ident.name}"
).
toException
case
DEnum
=>
}
case
_
=>
throw
new
AssertionError
(
"Type cannot be resolved"
)
}
}
...
...
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