Skip to content

Commit 690c1cc

Browse files
usiemsmrbean-bremen
authored andcommitted
Implement methods with lvalue/rvalue references, ...
also moved code into an own method to avoid some code duplication
1 parent e5c6423 commit 690c1cc

4 files changed

Lines changed: 65 additions & 63 deletions

File tree

generator/parser/ast.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,9 @@ struct DeclarationStatementAST: public StatementAST
372372
struct DeclaratorAST: public AST
373373
{
374374
DECLARE_AST_NODE(Declarator)
375+
enum ValueReferenceEnum { UnspecifiedRef, Lvalue, Rvalue }; // "&" or "&&" after member function
375376

376-
DeclaratorAST() {
377-
_override = false;
378-
}
377+
DeclaratorAST() = default;
379378
const ListNode<PtrOperatorAST*> *ptr_ops{};
380379
DeclaratorAST *sub_declarator{};
381380
NameAST *id{};
@@ -385,6 +384,7 @@ struct DeclaratorAST: public AST
385384
const ListNode<std::size_t> *fun_cv{};
386385
ExceptionSpecificationAST *exception_spec{};
387386
bool _override{};
387+
ValueReferenceEnum valueRef{ UnspecifiedRef };
388388
};
389389

390390
struct DeleteExpressionAST: public ExpressionAST

generator/parser/binder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
393393
}
394394
CodeModelFinder finder(model(), this);
395395

396+
if (declarator->valueRef == DeclaratorAST::Rvalue)
397+
{
398+
// rvalue reference methods are ignored, since we can't use them for the wrappers
399+
// (there is usually also a method with lvalue reference binding)
400+
return;
401+
}
402+
396403
ScopeModelItem functionScope = finder.resolveScope(declarator->id, scope);
397404
if (! functionScope)
398405
{

generator/parser/parser.cpp

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,50 +1362,27 @@ bool Parser::parseDeclarator(DeclaratorAST *&node)
13621362
return false;
13631363
}
13641364

1365-
std::size_t index = token_stream.cursor();
1366-
if (token_stream.lookAhead() == '(')
1365+
if (parseDeclaratorParametersAndSuffix(ast)) {
1366+
1367+
if (token_stream.lookAhead() == Token_identifier &&
1368+
token_stream.symbol(token_stream.cursor())->as_string() == "override")
13671369
{
13681370
nextToken();
1369-
1370-
ParameterDeclarationClauseAST *params = 0;
1371-
if (!parseParameterDeclarationClause(params))
1372-
{
1373-
rewind(index);
1374-
goto update_pos;
1375-
}
1376-
1377-
ast->parameter_declaration_clause = params;
1378-
1379-
if (token_stream.lookAhead() != ')')
1380-
{
1381-
rewind(index);
1382-
goto update_pos;
1383-
}
1384-
1385-
nextToken(); // skip ')'
1386-
1387-
parseCvQualify(ast->fun_cv);
1388-
parseExceptionSpecification(ast->exception_spec);
1389-
if (token_stream.lookAhead() == Token_identifier) {
1390-
const NameSymbol *name_symbol = token_stream.symbol(token_stream.cursor());
1391-
QString name = name_symbol->as_string();
1392-
if (name == "override") {
1393-
nextToken();
1394-
ast->_override = true;
1395-
}
1396-
}
1397-
skipAttributes();
1371+
ast->_override = true;
13981372
}
1373+
skipAttributes();
13991374

1400-
if (skipParen)
1375+
if (skipParen)
14011376
{
14021377
if (token_stream.lookAhead() != ')')
1403-
{
1404-
reportError(("')' expected"));
1405-
}
1378+
{
1379+
reportError(("')' expected"));
1380+
}
14061381
else
14071382
nextToken();
14081383
}
1384+
1385+
}
14091386
}
14101387

14111388
update_pos:
@@ -1485,31 +1462,7 @@ bool Parser::parseAbstractDeclarator(DeclaratorAST *&node)
14851462
return false;
14861463
}
14871464

1488-
int index = (int) token_stream.cursor();
1489-
if (token_stream.lookAhead() == '(')
1490-
{
1491-
nextToken();
1492-
1493-
ParameterDeclarationClauseAST *params = 0;
1494-
if (!parseParameterDeclarationClause(params))
1495-
{
1496-
rewind(index);
1497-
goto update_pos;
1498-
}
1499-
1500-
ast->parameter_declaration_clause = params;
1501-
1502-
if (token_stream.lookAhead() != ')')
1503-
{
1504-
rewind(index);
1505-
goto update_pos;
1506-
}
1507-
1508-
nextToken(); // skip ')'
1509-
1510-
parseCvQualify(ast->fun_cv);
1511-
parseExceptionSpecification(ast->exception_spec);
1512-
}
1465+
parseDeclaratorParametersAndSuffix(ast);
15131466
}
15141467

15151468
update_pos:
@@ -1522,6 +1475,47 @@ bool Parser::parseAbstractDeclarator(DeclaratorAST *&node)
15221475
return true;
15231476
}
15241477

1478+
bool Parser::parseDeclaratorParametersAndSuffix(DeclaratorAST* ast)
1479+
{
1480+
std::size_t index = token_stream.cursor();
1481+
if (token_stream.lookAhead() == '(')
1482+
{
1483+
nextToken();
1484+
1485+
ParameterDeclarationClauseAST* params = 0;
1486+
if (!parseParameterDeclarationClause(params))
1487+
{
1488+
rewind(index);
1489+
return false;
1490+
}
1491+
1492+
ast->parameter_declaration_clause = params;
1493+
1494+
if (token_stream.lookAhead() != ')')
1495+
{
1496+
rewind(index);
1497+
return false;
1498+
}
1499+
1500+
nextToken(); // skip ')'
1501+
1502+
parseCvQualify(ast->fun_cv);
1503+
if (token_stream.lookAhead() == '&')
1504+
{
1505+
ast->valueRef = DeclaratorAST::Lvalue;
1506+
nextToken();
1507+
}
1508+
else if (token_stream.lookAhead() == Token_and)
1509+
{
1510+
ast->valueRef = DeclaratorAST::Rvalue;
1511+
nextToken();
1512+
}
1513+
parseExceptionSpecification(ast->exception_spec);
1514+
return true;
1515+
}
1516+
return false;
1517+
}
1518+
15251519
bool Parser::parseEnumSpecifier(TypeSpecifierAST *&node)
15261520
{
15271521
std::size_t start = token_stream.cursor();

generator/parser/parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class Parser
9494
bool parseDeclarationInternal(DeclarationAST *&node);
9595
bool parseDeclarationStatement(StatementAST *&node);
9696
bool parseDeclarator(DeclaratorAST *&node);
97+
bool parseDeclaratorParametersAndSuffix(DeclaratorAST* node);
9798
bool parseDeleteExpression(ExpressionAST *&node);
9899
bool parseDoStatement(StatementAST *&node);
99100
bool parseElaboratedTypeSpecifier(TypeSpecifierAST *&node);

0 commit comments

Comments
 (0)