-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ front-end: More work on brace init
- Loading branch information
1 parent
56652be
commit bb79589
Showing
2 changed files
with
58 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ Author: Daniel Kroening, [email protected] | |
#include "cpp_member_spec.h" | ||
#include "cpp_enum_type.h" | ||
|
||
#define DEBUG | ||
#ifdef DEBUG | ||
#include <iostream> | ||
|
||
|
@@ -6321,7 +6320,10 @@ bool Parser::rAllocateInitializer(exprt &init) | |
postfix.exp | ||
: primary.exp | ||
| postfix.expr '[' comma.expression ']' | ||
| postfix.expr '[' initializer ']' | ||
| postfix.expr '(' function.arguments ')' | ||
| integral.or.class.spec '(' function.arguments ')' | ||
| integral.or.class.spec initializer | ||
| postfix.expr '.' var.name | ||
| postfix.expr ArrowOp var.name | ||
| postfix.expr IncOp | ||
|
@@ -6330,8 +6332,6 @@ bool Parser::rAllocateInitializer(exprt &init) | |
openc++.postfix.expr | ||
: postfix.expr '.' userdef.statement | ||
| postfix.expr ArrowOp userdef.statement | ||
Note: function-style casts are accepted as function calls. | ||
*/ | ||
bool Parser::rPostfixExpr(exprt &exp) | ||
{ | ||
|
@@ -6340,8 +6340,52 @@ bool Parser::rPostfixExpr(exprt &exp) | |
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0\n"; | ||
#endif | ||
|
||
if(!rPrimaryExpr(exp)) | ||
return false; | ||
typet type; | ||
|
||
cpp_token_buffert::post pos=lex.Save(); | ||
// try to see whether this is explicit type conversion, else it has to be | ||
// a primary-expression | ||
if(optIntegralTypeOrClassSpec(type) && | ||
(type.is_not_nil() || rName(type)) && | ||
(lex.LookAhead(0) == '(' || lex.LookAhead(0) == '{')) | ||
{ | ||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0.1\n"; | ||
#endif | ||
|
||
cpp_tokent tk; | ||
lex.LookAhead(0, tk); | ||
exprt exp2; | ||
if(lex.LookAhead(0)=='{') | ||
{ | ||
if(!rInitializeExpr(exp2)) | ||
return false; | ||
} | ||
else | ||
{ | ||
// lex.LookAhead(0)=='(' | ||
lex.get_token(tk); | ||
|
||
exprt exp2; | ||
if(!rFunctionArguments(exp2)) | ||
return false; | ||
|
||
cpp_tokent tk2; | ||
if(lex.get_token(tk2)!=')') | ||
return false; | ||
} | ||
|
||
exp=exprt("explicit-constructor-call"); | ||
exp.type().swap(type); | ||
exp.operands().swap(exp2.operands()); | ||
set_location(exp, tk); | ||
} | ||
else | ||
{ | ||
lex.Restore(pos); | ||
if(!rPrimaryExpr(exp)) | ||
return false; | ||
} | ||
|
||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 1\n"; | ||
|
@@ -6357,7 +6401,14 @@ bool Parser::rPostfixExpr(exprt &exp) | |
{ | ||
case '[': | ||
lex.get_token(op); | ||
if(!rCommaExpression(e)) | ||
|
||
if(lex.LookAhead(0) == '{') | ||
{ | ||
// C++11 initialisation expression | ||
if(!rInitializeExpr(e)) | ||
return false; | ||
} | ||
else if(!rCommaExpression(e)) | ||
return false; | ||
|
||
#ifdef DEBUG | ||
|
@@ -6405,35 +6456,6 @@ bool Parser::rPostfixExpr(exprt &exp) | |
} | ||
break; | ||
|
||
case '{': | ||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 3a\n"; | ||
#endif | ||
|
||
// this is a C++11 extension | ||
if(!rInitializeExpr(e)) | ||
return false; | ||
|
||
if(lex.get_token(cp)!='}') | ||
return false; | ||
|
||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 4a\n"; | ||
#endif | ||
|
||
{ | ||
side_effect_expr_function_callt fc( | ||
std::move(exp), {}, typet{}, source_locationt{}); | ||
fc.arguments().reserve(e.operands().size()); | ||
set_location(fc, op); | ||
|
||
Forall_operands(it, e) | ||
fc.arguments().push_back(*it); | ||
e.operands().clear(); // save some | ||
exp.swap(fc); | ||
} | ||
break; | ||
|
||
case TOK_INCR: | ||
lex.get_token(op); | ||
|
||
|
@@ -6704,8 +6726,6 @@ bool Parser::rTypePredicate(exprt &expr) | |
| THIS | ||
| var.name | ||
| '(' comma.expression ')' | ||
| integral.or.class.spec '(' function.arguments ')' | ||
| integral.or.class.spec initializer | ||
| typeid.expr | ||
| true | ||
| false | ||
|
@@ -6823,12 +6843,6 @@ bool Parser::rPrimaryExpr(exprt &exp) | |
#endif | ||
return true; | ||
|
||
case '{': // C++11 initialisation expression | ||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 10\n"; | ||
#endif | ||
return rInitializeExpr(exp); | ||
|
||
case TOK_TYPEID: | ||
return rTypeidExpr(exp); | ||
|
||
|
@@ -6859,60 +6873,6 @@ bool Parser::rPrimaryExpr(exprt &exp) | |
std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 14\n"; | ||
#endif | ||
{ | ||
typet type; | ||
|
||
if(!optIntegralTypeOrClassSpec(type)) | ||
return false; | ||
|
||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 15\n"; | ||
#endif | ||
|
||
if(type.is_not_nil() && lex.LookAhead(0)==TOK_SCOPE) | ||
{ | ||
lex.get_token(tk); | ||
lex.get_token(tk); | ||
|
||
// TODO | ||
} | ||
else if(type.is_not_nil()) | ||
{ | ||
#ifdef DEBUG | ||
std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 16\n"; | ||
#endif | ||
if(lex.LookAhead(0)=='{') | ||
{ | ||
lex.LookAhead(0, tk); | ||
|
||
exprt exp2; | ||
if(!rInitializeExpr(exp2)) | ||
return false; | ||
|
||
exp=exprt("explicit-constructor-call"); | ||
exp.type().swap(type); | ||
exp.add_to_operands(std::move(exp2)); | ||
set_location(exp, tk); | ||
} | ||
else if(lex.LookAhead(0)=='(') | ||
{ | ||
lex.get_token(tk); | ||
|
||
exprt exp2; | ||
if(!rFunctionArguments(exp2)) | ||
return false; | ||
|
||
if(lex.get_token(tk2)!=')') | ||
return false; | ||
|
||
exp=exprt("explicit-constructor-call"); | ||
exp.type().swap(type); | ||
exp.operands().swap(exp2.operands()); | ||
set_location(exp, tk); | ||
} | ||
else | ||
return false; | ||
} | ||
else | ||
{ | ||
if(!rVarName(exp)) | ||
return false; | ||
|