Commit ae0a8037 authored by David Gobbi's avatar David Gobbi
Browse files

Add C++14 header support to wrappers.

This patch adds support for parsing headers that have various features
that were introduced in the C++14 standard:
1) binary literals
2) digit separators in numeric literals
3) variable templates
4) "typename" instead of "class" in templated template parameters

It also introduces a proposed C++17 feature:
5) the u8 prefix for character literals
parent 987d98dd
This diff is collapsed.
......@@ -128,7 +128,7 @@ ID [a-zA-Z_\x80-\xff][0-9a-zA-Z_\x80-\xff]*
return(STRING_LITERAL);
}
[uUL]?\'([^\']|\\\')+\'(_{ID})? {
("u8"|"u"|"U"|"L")?\'([^\']|\\\')+\'(_{ID})? {
yylval.str = vtkstrndup(yytext, yyleng);
return(CHAR_LITERAL);
}
......@@ -493,32 +493,42 @@ ID [a-zA-Z_\x80-\xff][0-9a-zA-Z_\x80-\xff]*
}
}
[0-9]*"."[0-9]+([eE][+-]?[0-9]+)?{ID}? {
"."[0-9]([0-9]|\'[0-9])*([eE][+-]?[0-9]([0-9]|\'[0-9])*)?{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(FLOAT_LITERAL);
}
[0-9]+"."([eE][+-]?[0-9]+)?{ID}? {
[0-9]([0-9]|\'[0-9])*"."([eE][+-]?[0-9]([0-9]|\'[0-9])*)?{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(FLOAT_LITERAL);
}
[0-9]+[eE][+-]?[0-9]+{ID}? {
[0-9]([0-9]|\'[0-9])*"."[0-9]([0-9]|\'[0-9])*([eE][+-]?[0-9]([0-9]|\'[0-9])*)?{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(FLOAT_LITERAL);
}
"0"[xX][0-9a-fA-F]+{ID}? {
[0-9]([0-9]|\'[0-9])*[eE][+-]?[0-9]([0-9]|\'[0-9])*{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(FLOAT_LITERAL);
}
"0"[xX][0-9a-fA-F]([0-9a-fA-F]|\'[0-9a-fA-F])*{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(HEX_LITERAL);
}
"0"[0-9]+{ID}? {
"0"[bB][0-1]([0-1]|\'[0-1])*{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(BIN_LITERAL);
}
"0"([0-8]|\'[0-8])+{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(OCT_LITERAL);
}
[1-9][0-9]*{ID}? {
[1-9]([0-9]|\'[0-9])*{ID}? {
yylval.str = vtkstrndup(yytext, yyleng);
return(INT_LITERAL);
}
......
This diff is collapsed.
......@@ -1291,9 +1291,9 @@ unsigned int add_indirection_to_array(unsigned int type)
/* Expect five shift-reduce conflicts from opt_final (final classes) */
%expect 5
/* Expect 120 reduce/reduce conflicts, these can be cleared by removing
/* Expect 121 reduce/reduce conflicts, these can be cleared by removing
either '<' or angle_brackets_sig from constant_expression_item. */
%expect-rr 120
%expect-rr 121
/* The parser will shift/reduce values <str> or <integer>, where
<str> is for IDs and <integer> is for types, modifiers, etc. */
......@@ -1328,6 +1328,7 @@ unsigned int add_indirection_to_array(unsigned int type)
%token <str> STRING_LITERAL
%token <str> INT_LITERAL
%token <str> HEX_LITERAL
%token <str> BIN_LITERAL
%token <str> OCT_LITERAL
%token <str> FLOAT_LITERAL
%token <str> CHAR_LITERAL
......@@ -1511,6 +1512,7 @@ template_declaration:
| template_head nested_variable_initialization
| template_head template_declaration
| template_head alias_declaration
| template_head variable_declaration
explicit_instantiation:
EXTERN TEMPLATE ignored_item_no_angle ignored_expression ';'
......@@ -1649,6 +1651,7 @@ template_member_declaration:
| template_head method_definition
| template_head template_member_declaration
| template_head alias_declaration
| template_head variable_declaration
friend_declaration:
FRIEND ignored_class
......@@ -1820,6 +1823,12 @@ typedef_declarator_id:
handle_complex_type(item, getType(), $<integer>1, getSig());
if (currentTemplate)
{
item->Template = currentTemplate;
currentTemplate = NULL;
}
if (getVarName())
{
item->Name = getVarName();
......@@ -1929,13 +1938,13 @@ template_parameter:
{ add_template_parameter(0, $<integer>3, copySig()); }
opt_template_parameter_initializer
| { pushTemplate(); markSig(); }
template_head CLASS { postSig("class "); }
template_head class_or_typename
direct_abstract_declarator
{
int i;
TemplateInfo *newTemplate = currentTemplate;
popTemplate();
add_template_parameter(0, $<integer>5, copySig());
add_template_parameter(0, $<integer>4, copySig());
i = currentTemplate->NumberOfParameters-1;
currentTemplate->Parameters[i]->Template = newTemplate;
}
......@@ -2234,6 +2243,12 @@ init_declarator_id:
handle_complex_type(var, type, $<integer>1, getSig());
if (currentTemplate)
{
var->Template = currentTemplate;
currentTemplate = NULL;
}
var->Name = getVarName();
if (getVarValue())
......@@ -2397,6 +2412,7 @@ bitfield_size:
OCT_LITERAL
| INT_LITERAL
| HEX_LITERAL
| BIN_LITERAL
opt_array_decorator_seq:
{ clearArray(); }
......@@ -3138,6 +3154,7 @@ literal:
OCT_LITERAL
| INT_LITERAL
| HEX_LITERAL
| BIN_LITERAL
| FLOAT_LITERAL
| CHAR_LITERAL
| STRING_LITERAL
......
......@@ -385,7 +385,11 @@ static int preproc_evaluate_char(
preproc_int_t code = 0;
int typecode = 0;
if (cp[0] == 'u' || cp[0] == 'U' || cp[0] == 'L')
if (cp[0] == 'u' && cp[1] == '8')
{
cp += 2;
}
else if (cp[0] == 'u' || cp[0] == 'U' || cp[0] == 'L')
{
typecode = cp[0];
cp++;
......@@ -467,7 +471,10 @@ static int preproc_evaluate_char(
static int preproc_evaluate_integer(
const char *cp, preproc_int_t *val, int *is_unsigned)
{
char temp[72];
const char *ep;
size_t apos = 0;
size_t i = 0;
int base = 0;
ep = cp;
......@@ -480,6 +487,27 @@ static int preproc_evaluate_integer(
while (vtkParse_CharType(*ep, CPRE_HEX))
{
ep++;
if (*ep == '\'' && vtkParse_CharType(ep[1], CPRE_HEX))
{
apos++;
ep += 2;
}
}
}
else if (cp[0] == '0' && (cp[1] == 'b' || cp[1] == 'B'))
{
cp += 2;
base = 2;
*is_unsigned = 1;
ep = cp;
while (*ep >= '0' && *ep <= '1')
{
ep++;
if (*ep == '\'' && ep[1] >= '0' && ep[1] <= '1')
{
apos++;
ep += 2;
}
}
}
else if (cp[0] == '0' && vtkParse_CharType(cp[1], CPRE_DIGIT))
......@@ -491,6 +519,11 @@ static int preproc_evaluate_integer(
while (*ep >= '0' && *ep <= '7')
{
ep++;
if (*ep == '\'' && ep[1] >= '0' && ep[1] <= '7')
{
apos++;
ep += 2;
}
}
}
else
......@@ -500,7 +533,35 @@ static int preproc_evaluate_integer(
while (vtkParse_CharType(*ep, CPRE_DIGIT))
{
ep++;
if (*ep == '\'' && vtkParse_CharType(ep[1], CPRE_DIGIT))
{
apos++;
ep += 2;
}
}
}
if (*ep == '.' ||
((ep[0] == 'e' || ep[0] == 'E') &&
(vtkParse_CharType(ep[1], CPRE_SIGN) ||
vtkParse_CharType(ep[1], CPRE_DIGIT))))
{
*val = 0;
return VTK_PARSE_PREPROC_DOUBLE;
}
if (apos > 0 && ep-cp-apos < sizeof(temp))
{
while (cp != ep)
{
if (*cp != '\'')
{
temp[i++] = *cp;
}
++cp;
}
temp[i++] = '\0';
cp = temp;
}
for (;;)
......@@ -520,11 +581,6 @@ static int preproc_evaluate_integer(
*val = string_to_preproc_int(cp, base);
}
if (*ep == '.' || *ep == 'e' || *ep == 'E')
{
return VTK_PARSE_PREPROC_DOUBLE;
}
return VTK_PARSE_OK;
}
......
......@@ -202,10 +202,12 @@ size_t vtkParse_SkipNumber(const char *text)
if (parse_chartype(cp[0], CPRE_DIGIT) ||
(cp[0] == '.' && parse_chartype(cp[1], CPRE_DIGIT)))
{
if (cp[0] == '.') { cp++; }
do
{
char c = *cp++;
if (parse_chartype(*cp, CPRE_SIGN) && (c == 'e' || c == 'E'))
if ((*cp == '\'' && parse_chartype(cp[1], CPRE_XDIGIT)) ||
(parse_chartype(*cp, CPRE_SIGN) && (c == 'e' || c == 'E')))
{
cp++;
}
......@@ -363,11 +365,9 @@ int vtkParse_NextToken(StringTokenizer *tokens)
/* check if this is a prefixed string */
if (parse_chartype(*ep, CPRE_QUOTE) &&
((*ep == '\'' && tokens->len == 1 &&
(*cp == 'u' || *cp == 'U' || *cp == 'L')) ||
(*ep == '\"' && tokens->len == 1 &&
(*cp == 'U' || *cp == 'u' || *cp == 'L')) ||
(*ep == '\"' && tokens->len == 2 && cp[0] == 'u' && cp[1] == '8')))
((*ep == '\'' || *ep == '\"') &&
((tokens->len == 1 && (*cp == 'U' || *cp == 'u' || *cp == 'L')) ||
(tokens->len == 2 && cp[0] == 'u' && cp[1] == '8'))))
{
tokens->tok = (*ep == '\"' ? TOK_STRING : TOK_CHAR);
tokens->hash = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment