Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVivian Kong2012-09-10 15:27:42 -0400
committerVivian Kong2012-09-10 15:27:42 -0400
commitace8f06e2d3e625bed70ff344901fccd25eba73b (patch)
tree05ed56e890a6a048b89e7dd9cbbd81c71e78244d
parentedd32c480d16febf5b2131f7e12b2b2f8e7d18e6 (diff)
downloadorg.eclipse.cdt-ace8f06e2d3e625bed70ff344901fccd25eba73b.tar.gz
org.eclipse.cdt-ace8f06e2d3e625bed70ff344901fccd25eba73b.tar.xz
org.eclipse.cdt-ace8f06e2d3e625bed70ff344901fccd25eba73b.zip
Bug 388243 - [LR parser] ICPPASTConstructorInitializer offsets did not
include parentheses
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java42
1 files changed, 34 insertions, 8 deletions
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
index 35f58f474b..19943bb3c5 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
@@ -172,12 +172,17 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
public void consumeNewInitializer() {
+ IASTExpression expr;
if(astStack.peek() == null) { // if there is an empty set of parens
astStack.pop();
- IASTExpression initializer = nodeFactory.newExpressionList();
- setOffsetAndLength(initializer);
- astStack.push(initializer);
+ expr = nodeFactory.newExpressionList();
+ setOffsetAndLength(expr);
+ } else {
+ expr = (IASTExpression) astStack.pop(); // may be null
}
+ ICPPASTConstructorInitializer initializer = nodeFactory.newConstructorInitializer(expr);
+ setOffsetAndLength(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
*/
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();
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTExpression placement = (IASTExpression) astStack.pop(); // may be 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.setIsNewTypeId(isNewTypeId);
setOffsetAndLength(newExpression);
@@ -1635,9 +1640,30 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= mem_initializer_id '(' expression_list_opt ')'
*/
public void consumeConstructorChainInitializer() {
- IASTExpression expr = (IASTExpression) astStack.pop();
- IASTName name = (IASTName) astStack.pop();
- ICPPASTConstructorChainInitializer initializer = nodeFactory.newConstructorChainInitializer(name, expr);
+ Object o = astStack.pop();
+ IASTName name = (IASTName) astStack.pop();
+ 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);
astStack.push(initializer);
}

Back to the top