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
dc51ed6b
Commit
dc51ed6b
authored
Apr 20, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support 'inf' and 'nan' as float/double literals.
parent
9baabb1d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
20 deletions
+46
-20
test-util.c++
c++/src/capnproto/test-util.c++
+27
-4
test.capnp
c++/src/capnproto/test.capnp
+2
-2
Compiler.hs
compiler/src/Compiler.hs
+8
-0
Parser.hs
compiler/src/Parser.hs
+9
-14
No files found.
c++/src/capnproto/test-util.c++
View file @
dc51ed6b
...
@@ -103,8 +103,14 @@ void genericInitTestMessage(Builder builder) {
...
@@ -103,8 +103,14 @@ void genericInitTestMessage(Builder builder) {
builder
.
setUInt16List
({
33333u
,
44444u
});
builder
.
setUInt16List
({
33333u
,
44444u
});
builder
.
setUInt32List
({
3333333333u
});
builder
.
setUInt32List
({
3333333333u
});
builder
.
setUInt64List
({
11111111111111111111ull
});
builder
.
setUInt64List
({
11111111111111111111ull
});
builder
.
setFloat32List
({
5555.5
,
2222.25
});
builder
.
setFloat32List
({
5555.5
,
builder
.
setFloat64List
({
7777.75
,
1111.125
});
std
::
numeric_limits
<
float
>::
infinity
(),
-
std
::
numeric_limits
<
float
>::
infinity
(),
std
::
numeric_limits
<
float
>::
quiet_NaN
()});
builder
.
setFloat64List
({
7777.75
,
std
::
numeric_limits
<
double
>::
infinity
(),
-
std
::
numeric_limits
<
double
>::
infinity
(),
std
::
numeric_limits
<
double
>::
quiet_NaN
()});
builder
.
setTextList
({
"plugh"
,
"xyzzy"
,
"thud"
});
builder
.
setTextList
({
"plugh"
,
"xyzzy"
,
"thud"
});
builder
.
setDataList
({
"oops"
,
"exhausted"
,
"rfc3092"
});
builder
.
setDataList
({
"oops"
,
"exhausted"
,
"rfc3092"
});
{
{
...
@@ -140,6 +146,9 @@ void checkList(T reader, std::initializer_list<double> expected) {
...
@@ -140,6 +146,9 @@ void checkList(T reader, std::initializer_list<double> expected) {
}
}
}
}
inline
bool
isNaN
(
float
f
)
{
return
f
!=
f
;
}
inline
bool
isNaN
(
double
f
)
{
return
f
!=
f
;
}
template
<
typename
Reader
>
template
<
typename
Reader
>
void
genericCheckTestMessage
(
Reader
reader
)
{
void
genericCheckTestMessage
(
Reader
reader
)
{
EXPECT_EQ
(
Void
::
VOID
,
reader
.
getVoidField
());
EXPECT_EQ
(
Void
::
VOID
,
reader
.
getVoidField
());
...
@@ -215,8 +224,22 @@ void genericCheckTestMessage(Reader reader) {
...
@@ -215,8 +224,22 @@ void genericCheckTestMessage(Reader reader) {
checkList
(
reader
.
getUInt16List
(),
{
33333u
,
44444u
});
checkList
(
reader
.
getUInt16List
(),
{
33333u
,
44444u
});
checkList
(
reader
.
getUInt32List
(),
{
3333333333u
});
checkList
(
reader
.
getUInt32List
(),
{
3333333333u
});
checkList
(
reader
.
getUInt64List
(),
{
11111111111111111111ull
});
checkList
(
reader
.
getUInt64List
(),
{
11111111111111111111ull
});
checkList
(
reader
.
getFloat32List
(),
{
5555.5
f
,
2222.25
f
});
{
checkList
(
reader
.
getFloat64List
(),
{
7777.75
,
1111.125
});
auto
listReader
=
reader
.
getFloat32List
();
ASSERT_EQ
(
4u
,
listReader
.
size
());
EXPECT_EQ
(
5555.5
f
,
listReader
[
0
]);
EXPECT_EQ
(
std
::
numeric_limits
<
float
>::
infinity
(),
listReader
[
1
]);
EXPECT_EQ
(
-
std
::
numeric_limits
<
float
>::
infinity
(),
listReader
[
2
]);
EXPECT_TRUE
(
isNaN
(
listReader
[
3
]));
}
{
auto
listReader
=
reader
.
getFloat64List
();
ASSERT_EQ
(
4u
,
listReader
.
size
());
EXPECT_EQ
(
7777.75
,
listReader
[
0
]);
EXPECT_EQ
(
std
::
numeric_limits
<
double
>::
infinity
(),
listReader
[
1
]);
EXPECT_EQ
(
-
std
::
numeric_limits
<
double
>::
infinity
(),
listReader
[
2
]);
EXPECT_TRUE
(
isNaN
(
listReader
[
3
]));
}
checkList
(
reader
.
getTextList
(),
{
"plugh"
,
"xyzzy"
,
"thud"
});
checkList
(
reader
.
getTextList
(),
{
"plugh"
,
"xyzzy"
,
"thud"
});
checkList
(
reader
.
getDataList
(),
{
"oops"
,
"exhausted"
,
"rfc3092"
});
checkList
(
reader
.
getDataList
(),
{
"oops"
,
"exhausted"
,
"rfc3092"
});
{
{
...
...
c++/src/capnproto/test.capnp
View file @
dc51ed6b
...
@@ -144,8 +144,8 @@ struct TestDefaults {
...
@@ -144,8 +144,8 @@ struct TestDefaults {
uInt16List @24 : List(UInt16) = [33333, 44444];
uInt16List @24 : List(UInt16) = [33333, 44444];
uInt32List @25 : List(UInt32) = [3333333333];
uInt32List @25 : List(UInt32) = [3333333333];
uInt64List @26 : List(UInt64) = [11111111111111111111];
uInt64List @26 : List(UInt64) = [11111111111111111111];
float32List @27 : List(Float32) = [5555.5,
2222.25
];
float32List @27 : List(Float32) = [5555.5,
inf, -inf, nan
];
float64List @28 : List(Float64) = [7777.75,
1111.125
];
float64List @28 : List(Float64) = [7777.75,
inf, -inf, nan
];
textList @29 : List(Text) = ["plugh", "xyzzy", "thud"];
textList @29 : List(Text) = ["plugh", "xyzzy", "thud"];
dataList @30 : List(Data) = ["oops", "exhausted", "rfc3092"];
dataList @30 : List(Data) = ["oops", "exhausted", "rfc3092"];
structList @31 : List(TestAllTypes) = [
structList @31 : List(TestAllTypes) = [
...
...
compiler/src/Compiler.hs
View file @
dc51ed6b
...
@@ -196,6 +196,14 @@ compileValue _ (BuiltinType BuiltinFloat32) (FloatFieldValue x) = succeed (Float
...
@@ -196,6 +196,14 @@ compileValue _ (BuiltinType BuiltinFloat32) (FloatFieldValue x) = succeed (Float
compileValue
_
(
BuiltinType
BuiltinFloat64
)
(
FloatFieldValue
x
)
=
succeed
(
Float64Desc
x
)
compileValue
_
(
BuiltinType
BuiltinFloat64
)
(
FloatFieldValue
x
)
=
succeed
(
Float64Desc
x
)
compileValue
_
(
BuiltinType
BuiltinFloat32
)
(
IntegerFieldValue
x
)
=
succeed
(
Float32Desc
(
realToFrac
x
))
compileValue
_
(
BuiltinType
BuiltinFloat32
)
(
IntegerFieldValue
x
)
=
succeed
(
Float32Desc
(
realToFrac
x
))
compileValue
_
(
BuiltinType
BuiltinFloat64
)
(
IntegerFieldValue
x
)
=
succeed
(
Float64Desc
(
realToFrac
x
))
compileValue
_
(
BuiltinType
BuiltinFloat64
)
(
IntegerFieldValue
x
)
=
succeed
(
Float64Desc
(
realToFrac
x
))
compileValue
_
(
BuiltinType
BuiltinFloat32
)
(
IdentifierFieldValue
"inf"
)
=
succeed
$
Float32Desc
$
realToFrac
$
1.0
/
0.0
compileValue
_
(
BuiltinType
BuiltinFloat64
)
(
IdentifierFieldValue
"inf"
)
=
succeed
$
Float64Desc
$
1.0
/
0.0
compileValue
_
(
BuiltinType
BuiltinFloat32
)
(
IdentifierFieldValue
"nan"
)
=
succeed
$
Float32Desc
$
realToFrac
$
0.0
/
0.0
compileValue
_
(
BuiltinType
BuiltinFloat64
)
(
IdentifierFieldValue
"nan"
)
=
succeed
$
Float64Desc
$
0.0
/
0.0
compileValue
_
(
BuiltinType
BuiltinText
)
(
StringFieldValue
x
)
=
succeed
(
TextDesc
x
)
compileValue
_
(
BuiltinType
BuiltinText
)
(
StringFieldValue
x
)
=
succeed
(
TextDesc
x
)
compileValue
_
(
BuiltinType
BuiltinData
)
(
StringFieldValue
x
)
=
compileValue
_
(
BuiltinType
BuiltinData
)
(
StringFieldValue
x
)
=
succeed
(
DataDesc
(
map
(
fromIntegral
.
fromEnum
)
x
))
succeed
(
DataDesc
(
map
(
fromIntegral
.
fromEnum
)
x
))
...
...
compiler/src/Parser.hs
View file @
dc51ed6b
...
@@ -121,6 +121,8 @@ unionKeyword = tokenParser (matchSimpleToken UnionKeyword) <?> "\"union\""
...
@@ -121,6 +121,8 @@ unionKeyword = tokenParser (matchSimpleToken UnionKeyword) <?> "\"union\""
interfaceKeyword
=
tokenParser
(
matchSimpleToken
InterfaceKeyword
)
<?>
"
\"
interface
\"
"
interfaceKeyword
=
tokenParser
(
matchSimpleToken
InterfaceKeyword
)
<?>
"
\"
interface
\"
"
annotationKeyword
=
tokenParser
(
matchSimpleToken
AnnotationKeyword
)
<?>
"
\"
annotation
\"
"
annotationKeyword
=
tokenParser
(
matchSimpleToken
AnnotationKeyword
)
<?>
"
\"
annotation
\"
"
exactIdentifier
s
=
tokenParser
(
matchSimpleToken
$
Identifier
s
)
<?>
"
\"
"
++
s
++
"
\"
"
parenthesizedList
parser
=
do
parenthesizedList
parser
=
do
items
<-
tokenParser
(
matchUnary
ParenthesizedList
)
items
<-
tokenParser
(
matchUnary
ParenthesizedList
)
parseList
parser
items
parseList
parser
items
...
@@ -250,6 +252,7 @@ fieldDecl = do
...
@@ -250,6 +252,7 @@ fieldDecl = do
negativeFieldValue
=
liftM
(
IntegerFieldValue
.
negate
)
literalInt
negativeFieldValue
=
liftM
(
IntegerFieldValue
.
negate
)
literalInt
<|>
liftM
(
FloatFieldValue
.
negate
)
literalFloat
<|>
liftM
(
FloatFieldValue
.
negate
)
literalFloat
<|>
(
exactIdentifier
"inf"
>>
return
(
FloatFieldValue
(
-
1.0
/
0.0
)))
fieldValue
=
(
literalVoid
>>
return
VoidFieldValue
)
fieldValue
=
(
literalVoid
>>
return
VoidFieldValue
)
<|>
liftM
BoolFieldValue
literalBool
<|>
liftM
BoolFieldValue
literalBool
...
@@ -312,25 +315,17 @@ annotationDecl = do
...
@@ -312,25 +315,17 @@ annotationDecl = do
return
(
AnnotationDecl
name
t
annotations
targets
)
return
(
AnnotationDecl
name
t
annotations
targets
)
allAnnotationTargets
=
[
minBound
::
AnnotationTarget
..
maxBound
::
AnnotationTarget
]
allAnnotationTargets
=
[
minBound
::
AnnotationTarget
..
maxBound
::
AnnotationTarget
]
annotationTarget
=
(
constKeyword
>>
return
ConstantAnnotation
)
annotationTarget
=
(
exactIdentifier
"file"
>>
return
FileAnnotation
)
<|>
(
constKeyword
>>
return
ConstantAnnotation
)
<|>
(
enumKeyword
>>
return
EnumAnnotation
)
<|>
(
enumKeyword
>>
return
EnumAnnotation
)
<|>
(
exactIdentifier
"enumerant"
>>
return
EnumerantAnnotation
)
<|>
(
structKeyword
>>
return
StructAnnotation
)
<|>
(
structKeyword
>>
return
StructAnnotation
)
<|>
(
exactIdentifier
"field"
>>
return
FieldAnnotation
)
<|>
(
unionKeyword
>>
return
UnionAnnotation
)
<|>
(
unionKeyword
>>
return
UnionAnnotation
)
<|>
(
interfaceKeyword
>>
return
InterfaceAnnotation
)
<|>
(
interfaceKeyword
>>
return
InterfaceAnnotation
)
<|>
(
exactIdentifier
"method"
>>
return
MethodAnnotation
)
<|>
(
exactIdentifier
"parameter"
>>
return
ParamAnnotation
)
<|>
(
annotationKeyword
>>
return
AnnotationAnnotation
)
<|>
(
annotationKeyword
>>
return
AnnotationAnnotation
)
<|>
(
do
name
<-
varIdentifier
case
name
of
"file"
->
return
FileAnnotation
"enumerant"
->
return
EnumerantAnnotation
"field"
->
return
FieldAnnotation
"method"
->
return
MethodAnnotation
"parameter"
->
return
ParamAnnotation
_
->
fail
""
<?>
annotationTargetList
)
<?>
annotationTargetList
annotationTargetList
=
"const, enum, enumerant, struct, field, union, interface, method,
\
\
parameter, or annotation"
extractErrors
::
Either
ParseError
(
a
,
[
ParseError
])
->
[
ParseError
]
extractErrors
::
Either
ParseError
(
a
,
[
ParseError
])
->
[
ParseError
]
extractErrors
(
Left
err
)
=
[
err
]
extractErrors
(
Left
err
)
=
[
err
]
...
...
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