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
fb31458e
Commit
fb31458e
authored
Feb 19, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow retroactive unionization.
parent
3c418b99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
Compiler.hs
compiler/src/Compiler.hs
+17
-3
Semantics.hs
compiler/src/Semantics.hs
+1
-0
No files found.
compiler/src/Compiler.hs
View file @
fb31458e
...
...
@@ -33,6 +33,7 @@ import Data.Maybe(mapMaybe)
import
Text.Parsec.Pos
(
SourcePos
,
newPos
)
import
Text.Parsec.Error
(
ParseError
,
newErrorMessage
,
Message
(
Message
,
Expect
))
import
Text.Printf
(
printf
)
import
Util
(
delimit
)
------------------------------------------------------------------------------------------
-- Error helpers
...
...
@@ -289,7 +290,17 @@ requireNoDuplicateNames decls = Active () (loop (List.sort locatedNames)) where
fieldInUnion
name
f
=
case
fieldUnion
f
of
Nothing
->
False
Just
x
->
(
unionName
x
)
==
name
Just
x
->
unionName
x
==
name
requireNoMoreThanOneFieldNumberLessThan
name
pos
num
fields
=
Active
()
errors
where
retroFields
=
[
fieldName
f
|
f
<-
fields
,
fieldNumber
f
<
num
]
message
=
printf
"No more than one field in a union may have a number less than the
\
\
union's number, as it is not possible to retroactively unionize fields that
\
\
had been separate. The following fields of union '%s' have lower numbers: %s"
name
(
delimit
", "
retroFields
)
errors
=
if
length
retroFields
<=
1
then
[]
else
[
newErrorMessage
(
Message
message
)
pos
]
------------------------------------------------------------------------------------------
...
...
@@ -378,6 +389,7 @@ compileDecl scope (StructDecl (Located _ name) decls) =
{
structName
=
name
,
structParent
=
scope
,
structFields
=
[
d
|
DescField
d
<-
members
]
,
structUnions
=
[
d
|
DescUnion
d
<-
members
]
,
structNestedAliases
=
[
d
|
DescAlias
d
<-
members
]
,
structNestedConstants
=
[
d
|
DescConstant
d
<-
members
]
,
structNestedEnums
=
[
d
|
DescEnum
d
<-
members
]
...
...
@@ -388,14 +400,16 @@ compileDecl scope (StructDecl (Located _ name) decls) =
,
structStatements
=
statements
})))
compileDecl
(
DescStruct
parent
)
(
UnionDecl
(
Located
_
name
)
(
Located
_
number
)
decls
)
=
compileDecl
(
DescStruct
parent
)
(
UnionDecl
(
Located
_
name
)
(
Located
numPos
number
)
decls
)
=
CompiledMemberStatus
name
(
feedback
(
\
desc
->
do
(
_
,
_
,
options
,
statements
)
<-
compileChildDecls
desc
decls
fields
<-
return
[
f
|
f
<-
structFields
parent
,
fieldInUnion
name
f
]
requireNoMoreThanOneFieldNumberLessThan
name
numPos
number
fields
return
(
DescUnion
UnionDesc
{
unionName
=
name
,
unionParent
=
parent
,
unionNumber
=
number
,
unionFields
=
[
f
|
f
<-
structFields
parent
,
fieldInUnion
name
f
]
,
unionFields
=
fields
,
unionOptions
=
options
,
unionStatements
=
statements
})))
...
...
compiler/src/Semantics.hs
View file @
fb31458e
...
...
@@ -216,6 +216,7 @@ data StructDesc = StructDesc
{
structName
::
String
,
structParent
::
Desc
,
structFields
::
[
FieldDesc
]
,
structUnions
::
[
UnionDesc
]
,
structNestedAliases
::
[
AliasDesc
]
,
structNestedConstants
::
[
ConstantDesc
]
,
structNestedEnums
::
[
EnumDesc
]
...
...
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