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
3930e460
Commit
3930e460
authored
Jun 29, 2014
by
Jason Choy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added hex binary literals
parent
95b8fb45
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
161 additions
and
0 deletions
+161
-0
grammar.capnp
c++/src/capnp/compiler/grammar.capnp
+1
-0
grammar.capnp.c++
c++/src/capnp/compiler/grammar.capnp.c++
+0
-0
grammar.capnp.h
c++/src/capnp/compiler/grammar.capnp.h
+65
-0
lexer.c++
c++/src/capnp/compiler/lexer.c++
+7
-0
lexer.capnp
c++/src/capnp/compiler/lexer.capnp
+1
-0
lexer.capnp.c++
c++/src/capnp/compiler/lexer.capnp.c++
+0
-0
lexer.capnp.h
c++/src/capnp/compiler/lexer.capnp.h
+65
-0
node-translator.c++
c++/src/capnp/compiler/node-translator.c++
+7
-0
parser.c++
c++/src/capnp/compiler/parser.c++
+9
-0
char.h
c++/src/kj/parse/char.h
+6
-0
No files found.
c++/src/capnp/compiler/grammar.capnp
View file @
3930e460
...
...
@@ -96,6 +96,7 @@ struct ValueExpression {
negativeInt @2 :UInt64;
float @3 :Float64;
string @4 :Text;
binary @10 :Data;
name @5 :DeclName;
list @6 :List(ValueExpression);
struct @7 :List(FieldAssignment);
...
...
c++/src/capnp/compiler/grammar.capnp.c++
View file @
3930e460
This diff is collapsed.
Click to expand it.
c++/src/capnp/compiler/grammar.capnp.h
View file @
3930e460
...
...
@@ -83,6 +83,7 @@ struct ValueExpression {
NAME
,
LIST
,
STRUCT
,
BINARY
,
};
struct
FieldAssignment
;
};
...
...
@@ -1003,6 +1004,10 @@ public:
inline
::
uint32_t
getEndByte
()
const
;
inline
bool
isBinary
()
const
;
inline
bool
hasBinary
()
const
;
inline
::
capnp
::
Data
::
Reader
getBinary
()
const
;
private
:
::
capnp
::
_
::
StructReader
_reader
;
template
<
typename
T
,
::
capnp
::
Kind
k
>
...
...
@@ -1088,6 +1093,14 @@ public:
inline
::
uint32_t
getEndByte
();
inline
void
setEndByte
(
::
uint32_t
value
);
inline
bool
isBinary
();
inline
bool
hasBinary
();
inline
::
capnp
::
Data
::
Builder
getBinary
();
inline
void
setBinary
(
::
capnp
::
Data
::
Reader
value
);
inline
::
capnp
::
Data
::
Builder
initBinary
(
unsigned
int
size
);
inline
void
adoptBinary
(
::
capnp
::
Orphan
<
::
capnp
::
Data
>&&
value
);
inline
::
capnp
::
Orphan
<
::
capnp
::
Data
>
disownBinary
();
private
:
::
capnp
::
_
::
StructBuilder
_builder
;
template
<
typename
T
,
::
capnp
::
Kind
k
>
...
...
@@ -3763,6 +3776,58 @@ inline void ValueExpression::Builder::setEndByte( ::uint32_t value) {
4
*
::
capnp
::
ELEMENTS
,
value
);
}
inline
bool
ValueExpression
::
Reader
::
isBinary
()
const
{
return
which
()
==
ValueExpression
::
BINARY
;
}
inline
bool
ValueExpression
::
Builder
::
isBinary
()
{
return
which
()
==
ValueExpression
::
BINARY
;
}
inline
bool
ValueExpression
::
Reader
::
hasBinary
()
const
{
if
(
which
()
!=
ValueExpression
::
BINARY
)
return
false
;
return
!
_reader
.
getPointerField
(
0
*
::
capnp
::
POINTERS
).
isNull
();
}
inline
bool
ValueExpression
::
Builder
::
hasBinary
()
{
if
(
which
()
!=
ValueExpression
::
BINARY
)
return
false
;
return
!
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
).
isNull
();
}
inline
::
capnp
::
Data
::
Reader
ValueExpression
::
Reader
::
getBinary
()
const
{
KJ_IREQUIRE
(
which
()
==
ValueExpression
::
BINARY
,
"Must check which() before get()ing a union member."
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
get
(
_reader
.
getPointerField
(
0
*
::
capnp
::
POINTERS
));
}
inline
::
capnp
::
Data
::
Builder
ValueExpression
::
Builder
::
getBinary
()
{
KJ_IREQUIRE
(
which
()
==
ValueExpression
::
BINARY
,
"Must check which() before get()ing a union member."
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
get
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
));
}
inline
void
ValueExpression
::
Builder
::
setBinary
(
::
capnp
::
Data
::
Reader
value
)
{
_builder
.
setDataField
<
ValueExpression
::
Which
>
(
0
*
::
capnp
::
ELEMENTS
,
ValueExpression
::
BINARY
);
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
set
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
),
value
);
}
inline
::
capnp
::
Data
::
Builder
ValueExpression
::
Builder
::
initBinary
(
unsigned
int
size
)
{
_builder
.
setDataField
<
ValueExpression
::
Which
>
(
0
*
::
capnp
::
ELEMENTS
,
ValueExpression
::
BINARY
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
init
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
),
size
);
}
inline
void
ValueExpression
::
Builder
::
adoptBinary
(
::
capnp
::
Orphan
<
::
capnp
::
Data
>&&
value
)
{
_builder
.
setDataField
<
ValueExpression
::
Which
>
(
0
*
::
capnp
::
ELEMENTS
,
ValueExpression
::
BINARY
);
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
adopt
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
),
kj
::
mv
(
value
));
}
inline
::
capnp
::
Orphan
<
::
capnp
::
Data
>
ValueExpression
::
Builder
::
disownBinary
()
{
KJ_IREQUIRE
(
which
()
==
ValueExpression
::
BINARY
,
"Must check which() before get()ing a union member."
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
disown
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
));
}
inline
bool
ValueExpression
::
FieldAssignment
::
Reader
::
hasFieldName
()
const
{
return
!
_reader
.
getPointerField
(
0
*
::
capnp
::
POINTERS
).
isNull
();
}
...
...
c++/src/capnp/compiler/lexer.c++
View file @
3930e460
...
...
@@ -173,6 +173,13 @@ Lexer::Lexer(Orphanage orphanageParam, ErrorReporter& errorReporterParam)
initTok
(
t
,
loc
).
setStringLiteral
(
text
);
return
t
;
}),
p
::
transformWithLocation
(
p
::
doubleQuotedHexBinary
,
[
this
](
Location
loc
,
kj
::
Array
<
char
>
data
)
->
Orphan
<
Token
>
{
auto
t
=
orphanage
.
newOrphan
<
Token
>
();
kj
::
ArrayPtr
<
byte
>
dataPtr
(
reinterpret_cast
<
byte
*>
(
data
.
begin
()),
reinterpret_cast
<
byte
*>
(
data
.
end
()));
initTok
(
t
,
loc
).
setBinaryLiteral
(
dataPtr
);
return
t
;
}),
p
::
transformWithLocation
(
p
::
integer
,
[
this
](
Location
loc
,
uint64_t
i
)
->
Orphan
<
Token
>
{
auto
t
=
orphanage
.
newOrphan
<
Token
>
();
...
...
c++/src/capnp/compiler/lexer.capnp
View file @
3930e460
...
...
@@ -29,6 +29,7 @@ struct Token {
union {
identifier @0 :Text;
stringLiteral @1 :Text;
binaryLiteral @9 :Data;
integerLiteral @2 :UInt64;
floatLiteral @3 :Float64;
operator @4 :Text;
...
...
c++/src/capnp/compiler/lexer.capnp.c++
View file @
3930e460
This diff is collapsed.
Click to expand it.
c++/src/capnp/compiler/lexer.capnp.h
View file @
3930e460
...
...
@@ -28,6 +28,7 @@ struct Token {
OPERATOR
,
PARENTHESIZED_LIST
,
BRACKETED_LIST
,
BINARY_LITERAL
,
};
};
...
...
@@ -138,6 +139,10 @@ public:
inline
::
uint32_t
getEndByte
()
const
;
inline
bool
isBinaryLiteral
()
const
;
inline
bool
hasBinaryLiteral
()
const
;
inline
::
capnp
::
Data
::
Reader
getBinaryLiteral
()
const
;
private
:
::
capnp
::
_
::
StructReader
_reader
;
template
<
typename
T
,
::
capnp
::
Kind
k
>
...
...
@@ -225,6 +230,14 @@ public:
inline
::
uint32_t
getEndByte
();
inline
void
setEndByte
(
::
uint32_t
value
);
inline
bool
isBinaryLiteral
();
inline
bool
hasBinaryLiteral
();
inline
::
capnp
::
Data
::
Builder
getBinaryLiteral
();
inline
void
setBinaryLiteral
(
::
capnp
::
Data
::
Reader
value
);
inline
::
capnp
::
Data
::
Builder
initBinaryLiteral
(
unsigned
int
size
);
inline
void
adoptBinaryLiteral
(
::
capnp
::
Orphan
<
::
capnp
::
Data
>&&
value
);
inline
::
capnp
::
Orphan
<
::
capnp
::
Data
>
disownBinaryLiteral
();
private
:
::
capnp
::
_
::
StructBuilder
_builder
;
template
<
typename
T
,
::
capnp
::
Kind
k
>
...
...
@@ -884,6 +897,58 @@ inline void Token::Builder::setEndByte( ::uint32_t value) {
4
*
::
capnp
::
ELEMENTS
,
value
);
}
inline
bool
Token
::
Reader
::
isBinaryLiteral
()
const
{
return
which
()
==
Token
::
BINARY_LITERAL
;
}
inline
bool
Token
::
Builder
::
isBinaryLiteral
()
{
return
which
()
==
Token
::
BINARY_LITERAL
;
}
inline
bool
Token
::
Reader
::
hasBinaryLiteral
()
const
{
if
(
which
()
!=
Token
::
BINARY_LITERAL
)
return
false
;
return
!
_reader
.
getPointerField
(
0
*
::
capnp
::
POINTERS
).
isNull
();
}
inline
bool
Token
::
Builder
::
hasBinaryLiteral
()
{
if
(
which
()
!=
Token
::
BINARY_LITERAL
)
return
false
;
return
!
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
).
isNull
();
}
inline
::
capnp
::
Data
::
Reader
Token
::
Reader
::
getBinaryLiteral
()
const
{
KJ_IREQUIRE
(
which
()
==
Token
::
BINARY_LITERAL
,
"Must check which() before get()ing a union member."
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
get
(
_reader
.
getPointerField
(
0
*
::
capnp
::
POINTERS
));
}
inline
::
capnp
::
Data
::
Builder
Token
::
Builder
::
getBinaryLiteral
()
{
KJ_IREQUIRE
(
which
()
==
Token
::
BINARY_LITERAL
,
"Must check which() before get()ing a union member."
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
get
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
));
}
inline
void
Token
::
Builder
::
setBinaryLiteral
(
::
capnp
::
Data
::
Reader
value
)
{
_builder
.
setDataField
<
Token
::
Which
>
(
0
*
::
capnp
::
ELEMENTS
,
Token
::
BINARY_LITERAL
);
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
set
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
),
value
);
}
inline
::
capnp
::
Data
::
Builder
Token
::
Builder
::
initBinaryLiteral
(
unsigned
int
size
)
{
_builder
.
setDataField
<
Token
::
Which
>
(
0
*
::
capnp
::
ELEMENTS
,
Token
::
BINARY_LITERAL
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
init
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
),
size
);
}
inline
void
Token
::
Builder
::
adoptBinaryLiteral
(
::
capnp
::
Orphan
<
::
capnp
::
Data
>&&
value
)
{
_builder
.
setDataField
<
Token
::
Which
>
(
0
*
::
capnp
::
ELEMENTS
,
Token
::
BINARY_LITERAL
);
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
adopt
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
),
kj
::
mv
(
value
));
}
inline
::
capnp
::
Orphan
<
::
capnp
::
Data
>
Token
::
Builder
::
disownBinaryLiteral
()
{
KJ_IREQUIRE
(
which
()
==
Token
::
BINARY_LITERAL
,
"Must check which() before get()ing a union member."
);
return
::
capnp
::
_
::
PointerHelpers
<
::
capnp
::
Data
>::
disown
(
_builder
.
getPointerField
(
0
*
::
capnp
::
POINTERS
));
}
inline
Statement
::
Which
Statement
::
Reader
::
which
()
const
{
return
_reader
.
getDataField
<
Which
>
(
0
*
::
capnp
::
ELEMENTS
);
}
...
...
c++/src/capnp/compiler/node-translator.c++
View file @
3930e460
...
...
@@ -1859,6 +1859,13 @@ Orphan<DynamicValue> ValueTranslator::compileValueInner(
}
break
;
case
ValueExpression
:
:
BINARY
:
if
(
!
type
.
isData
())
{
errorReporter
.
addErrorOn
(
src
,
kj
::
str
(
"Type mismatch; expected "
,
makeTypeName
(
type
),
"."
));
return
nullptr
;
}
return
orphanage
.
newOrphanCopy
(
src
.
getBinary
());
case
ValueExpression
:
:
LIST
:
{
if
(
!
type
.
isList
())
{
errorReporter
.
addErrorOn
(
src
,
kj
::
str
(
"Type mismatch; expected "
,
makeTypeName
(
type
),
"."
));
...
...
c++/src/capnp/compiler/parser.c++
View file @
3930e460
...
...
@@ -227,6 +227,7 @@ struct MatchTokenType {
constexpr
auto
identifier
=
TOKEN_TYPE_PARSER
(
Text
::
Reader
,
IDENTIFIER
,
getIdentifier
);
constexpr
auto
stringLiteral
=
TOKEN_TYPE_PARSER
(
Text
::
Reader
,
STRING_LITERAL
,
getStringLiteral
);
constexpr
auto
binaryLiteral
=
TOKEN_TYPE_PARSER
(
Data
::
Reader
,
BINARY_LITERAL
,
getBinaryLiteral
);
constexpr
auto
integerLiteral
=
TOKEN_TYPE_PARSER
(
uint64_t
,
INTEGER_LITERAL
,
getIntegerLiteral
);
constexpr
auto
floatLiteral
=
TOKEN_TYPE_PARSER
(
double
,
FLOAT_LITERAL
,
getFloatLiteral
);
constexpr
auto
operatorToken
=
TOKEN_TYPE_PARSER
(
Text
::
Reader
,
OPERATOR
,
getOperator
);
...
...
@@ -551,6 +552,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, ErrorReporter& errorReporterP
value
.
copyLocationTo
(
builder
);
return
result
;
}),
p
::
transform
(
binaryLiteral
,
[
this
](
Located
<
Data
::
Reader
>&&
value
)
->
Orphan
<
ValueExpression
>
{
auto
result
=
orphanage
.
newOrphan
<
ValueExpression
>
();
auto
builder
=
result
.
get
();
builder
.
setBinary
(
value
.
value
);
value
.
copyLocationTo
(
builder
);
return
result
;
}),
p
::
transformWithLocation
(
parsers
.
declName
,
[
this
](
kj
::
parse
::
Span
<
List
<
Token
>::
Reader
::
Iterator
>
location
,
Orphan
<
DeclName
>&&
value
)
->
Orphan
<
ValueExpression
>
{
...
...
c++/src/kj/parse/char.h
View file @
3930e460
...
...
@@ -326,6 +326,12 @@ constexpr auto singleQuotedString = charsToString(sequence(
exactChar
<
'\''
>
()));
// Parses a C-style single-quoted string.
constexpr
auto
doubleQuotedHexBinary
=
sequence
(
exactChar
<
'0'
>
(),
exactChar
<
'x'
>
(),
exactChar
<
'\"'
>
(),
oneOrMore
(
transform
(
sequence
(
hexDigit
,
hexDigit
),
_
::
ParseHexEscape
())),
exactChar
<
'\"'
>
());
// Parses a double-quoted hex binary literal.
}
// namespace parse
}
// namespace kj
...
...
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