mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 388243 - [LR parser] ICPPASTConstructorInitializer offsets did not
include parentheses
This commit is contained in:
parent
edd32c480d
commit
ace8f06e2d
1 changed files with 34 additions and 8 deletions
|
@ -172,13 +172,18 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
||||||
|
|
||||||
|
|
||||||
public void consumeNewInitializer() {
|
public void consumeNewInitializer() {
|
||||||
|
IASTExpression expr;
|
||||||
if(astStack.peek() == null) { // if there is an empty set of parens
|
if(astStack.peek() == null) { // if there is an empty set of parens
|
||||||
astStack.pop();
|
astStack.pop();
|
||||||
IASTExpression initializer = nodeFactory.newExpressionList();
|
expr = nodeFactory.newExpressionList();
|
||||||
|
setOffsetAndLength(expr);
|
||||||
|
} else {
|
||||||
|
expr = (IASTExpression) astStack.pop(); // may be null
|
||||||
|
}
|
||||||
|
ICPPASTConstructorInitializer initializer = nodeFactory.newConstructorInitializer(expr);
|
||||||
setOffsetAndLength(initializer);
|
setOffsetAndLength(initializer);
|
||||||
astStack.push(initializer);
|
astStack.push(initializer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,13 +194,13 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
||||||
* | dcolon_opt 'new' new_placement_opt '(' type_id ')' <openscope-ast> new_array_expressions_op new_initializer_opt
|
* | dcolon_opt 'new' new_placement_opt '(' type_id ')' <openscope-ast> new_array_expressions_op new_initializer_opt
|
||||||
*/
|
*/
|
||||||
public void consumeExpressionNew(boolean isNewTypeId) {
|
public void consumeExpressionNew(boolean isNewTypeId) {
|
||||||
IASTExpression initializer = (IASTExpression) astStack.pop(); // may be null
|
ICPPASTConstructorInitializer initializer = (ICPPASTConstructorInitializer) astStack.pop(); // may be null
|
||||||
List<Object> arrayExpressions = astStack.closeScope();
|
List<Object> arrayExpressions = astStack.closeScope();
|
||||||
IASTTypeId typeId = (IASTTypeId) astStack.pop();
|
IASTTypeId typeId = (IASTTypeId) astStack.pop();
|
||||||
IASTExpression placement = (IASTExpression) astStack.pop(); // may be null
|
IASTExpression placement = (IASTExpression) astStack.pop(); // may be null
|
||||||
boolean hasDoubleColon = astStack.pop() != null;
|
boolean hasDoubleColon = astStack.pop() != null;
|
||||||
|
|
||||||
ICPPASTNewExpression newExpression = nodeFactory.newNewExpression(placement, initializer, typeId);
|
ICPPASTNewExpression newExpression = nodeFactory.newNewExpression(new IASTExpression[] {placement}, initializer, typeId);
|
||||||
newExpression.setIsGlobal(hasDoubleColon);
|
newExpression.setIsGlobal(hasDoubleColon);
|
||||||
newExpression.setIsNewTypeId(isNewTypeId);
|
newExpression.setIsNewTypeId(isNewTypeId);
|
||||||
setOffsetAndLength(newExpression);
|
setOffsetAndLength(newExpression);
|
||||||
|
@ -1635,9 +1640,30 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
|
||||||
* ::= mem_initializer_id '(' expression_list_opt ')'
|
* ::= mem_initializer_id '(' expression_list_opt ')'
|
||||||
*/
|
*/
|
||||||
public void consumeConstructorChainInitializer() {
|
public void consumeConstructorChainInitializer() {
|
||||||
IASTExpression expr = (IASTExpression) astStack.pop();
|
Object o = astStack.pop();
|
||||||
IASTName name = (IASTName) astStack.pop();
|
IASTName name = (IASTName) astStack.pop();
|
||||||
ICPPASTConstructorChainInitializer initializer = nodeFactory.newConstructorChainInitializer(name, expr);
|
IASTInitializerClause[] initClauseList =null;
|
||||||
|
if(o instanceof IASTExpressionList){
|
||||||
|
initClauseList = ((IASTExpressionList) o).getExpressions();
|
||||||
|
}else if(o instanceof IASTInitializerClause){
|
||||||
|
initClauseList = new IASTInitializerClause[]{(IASTInitializerClause)o};
|
||||||
|
}
|
||||||
|
ICPPASTConstructorInitializer init = nodeFactory.newConstructorInitializer(initClauseList);
|
||||||
|
int rule_start_offset = stream.getLeftIToken().getStartOffset();
|
||||||
|
int initClauseList_offset = ParserUtil.offset(initClauseList[0]);
|
||||||
|
List<IToken> ruleTokens = stream.getRuleTokens();
|
||||||
|
int start_offset = -1;
|
||||||
|
|
||||||
|
for (int i = initClauseList_offset, n = rule_start_offset; i >= n; i--){
|
||||||
|
if(tokenMap.mapKind(ruleTokens.get(i).getKind()) == TK_LeftParen) {
|
||||||
|
start_offset = ruleTokens.get(i).getStartOffset();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int ruleLength = stream.getRightIToken().getEndOffset() - start_offset;
|
||||||
|
ParserUtil.setOffsetAndLength(init, start_offset, ruleLength < 0 ? 0 : ruleLength);
|
||||||
|
|
||||||
|
ICPPASTConstructorChainInitializer initializer = nodeFactory.newConstructorChainInitializer(name, init);
|
||||||
setOffsetAndLength(initializer);
|
setOffsetAndLength(initializer);
|
||||||
astStack.push(initializer);
|
astStack.push(initializer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue