diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser')
440 files changed, 23673 insertions, 22715 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java index d087117cd66..562956b5ca6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousBinaryVsCastExpression.java @@ -29,33 +29,34 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding; */ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression { private final IASTBinaryExpression fBinaryExpression; - private final IASTCastExpression fCastExpression; + private final IASTCastExpression fCastExpression; - /** - * The binary expression must have one of the following operators: +,-,&,*. The left hand side of the binary expression - * must end with an expression in parenthesis (which could be read as the beginning of the cast-expression. - * The cast-expression must contain the type-id (corresponding to the last expression in parenthesis on the left side of the - * binary expression. The operand of the castExpression can be <code>null</code>, it will be computed from the binary expression. - */ - public ASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression binaryExpression, IASTCastExpression castExpression) { - fBinaryExpression= binaryExpression; - fCastExpression= castExpression; - } + /** + * The binary expression must have one of the following operators: +,-,&,*. The left hand side of the binary expression + * must end with an expression in parenthesis (which could be read as the beginning of the cast-expression. + * The cast-expression must contain the type-id (corresponding to the last expression in parenthesis on the left side of the + * binary expression. The operand of the castExpression can be <code>null</code>, it will be computed from the binary expression. + */ + public ASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression binaryExpression, + IASTCastExpression castExpression) { + fBinaryExpression = binaryExpression; + fCastExpression = castExpression; + } - @Override + @Override public final IASTExpression copy() { - throw new UnsupportedOperationException(); - } + throw new UnsupportedOperationException(); + } @Override public final IASTExpression copy(CopyStyle style) { throw new UnsupportedOperationException(); } - @Override + @Override public final void addExpression(IASTExpression e) { - throw new UnsupportedOperationException(); - } + throw new UnsupportedOperationException(); + } @Override public final IASTNode[] getNodes() { @@ -64,40 +65,39 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod @Override public IASTExpression[] getExpressions() { - return new IASTExpression[] {fBinaryExpression, fCastExpression}; + return new IASTExpression[] { fBinaryExpression, fCastExpression }; } @Override protected final IASTNode doResolveAmbiguity(ASTVisitor visitor) { - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); - IASTNode nodeToReplace= this; + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace = this; // handle nested ambiguities first owner.replace(nodeToReplace, fCastExpression); - nodeToReplace= fCastExpression; + nodeToReplace = fCastExpression; fCastExpression.getTypeId().accept(visitor); owner.replace(nodeToReplace, fBinaryExpression); - nodeToReplace= fBinaryExpression; + nodeToReplace = fBinaryExpression; fBinaryExpression.accept(visitor); - // find nested names - final NameCollector nameCollector= new NameCollector(); + final NameCollector nameCollector = new NameCollector(); fCastExpression.getTypeId().accept(nameCollector); - final IASTName[] names= nameCollector.getNames(); + final IASTName[] names = nameCollector.getNames(); // resolve names - boolean hasIssue= false; + boolean hasIssue = false; for (IASTName name : names) { try { IBinding b = name.resolveBinding(); if (b instanceof IProblemBinding) { - hasIssue= true; + hasIssue = true; break; } } catch (Exception t) { - hasIssue= true; + hasIssue = true; break; } } @@ -109,16 +109,17 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod final IASTExpression right = fBinaryExpression.getOperand2(); left.setParent(null); right.setParent(null); - IASTUnaryExpression primaryInParenthesis= findTrailingBracketedPrimaryExpression(left); - IASTExpression leadingCastExpression= findLeadingCastExpression(right); - IASTExpression castedUnary= fCastExpression.getOperand(); - if (primaryInParenthesis != null && leadingCastExpression != null && castedUnary instanceof IASTUnaryExpression) { - IASTExpression lp= (IASTExpression) primaryInParenthesis.getParent(); - IASTBinaryExpression rp= (IASTBinaryExpression) leadingCastExpression.getParent(); + IASTUnaryExpression primaryInParenthesis = findTrailingBracketedPrimaryExpression(left); + IASTExpression leadingCastExpression = findLeadingCastExpression(right); + IASTExpression castedUnary = fCastExpression.getOperand(); + if (primaryInParenthesis != null && leadingCastExpression != null + && castedUnary instanceof IASTUnaryExpression) { + IASTExpression lp = (IASTExpression) primaryInParenthesis.getParent(); + IASTBinaryExpression rp = (IASTBinaryExpression) leadingCastExpression.getParent(); ((IASTUnaryExpression) castedUnary).setOperand(leadingCastExpression); setEnd(castedUnary, leadingCastExpression); setRange(fCastExpression, primaryInParenthesis, leadingCastExpression); - IASTExpression root= joinExpressions(lp, fCastExpression, rp); + IASTExpression root = joinExpressions(lp, fCastExpression, rp); if (root != null) { owner.replace(nodeToReplace, root); return root; @@ -128,24 +129,23 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod } private void setEnd(IASTNode node, IASTNode end) { - final ASTNode target= (ASTNode) node; - final ASTNode e= (ASTNode) end; + final ASTNode target = (ASTNode) node; + final ASTNode e = (ASTNode) end; target.setLength(e.getOffset() + e.getLength() - target.getOffset()); } private void setStart(IASTNode node, IASTNode start) { - final ASTNode target= (ASTNode) node; + final ASTNode target = (ASTNode) node; final int offset = ((ASTNode) start).getOffset(); target.setOffsetAndLength(offset, target.getOffset() + target.getLength() - offset); } private void setRange(IASTNode node, IASTNode from, IASTNode to) { final int offset = ((ASTNode) from).getOffset(); - final ASTNode t= (ASTNode) to; - ((ASTNode) node).setOffsetAndLength(offset, t.getOffset()+t.getLength()-offset); + final ASTNode t = (ASTNode) to; + ((ASTNode) node).setOffsetAndLength(offset, t.getOffset() + t.getLength() - offset); } - /** * @param l unary, cast or binary expression to the left, all parents are unary, cast or binary expressions. * @param middle initially a cast-expression, always suitable to put into l or r @@ -159,31 +159,31 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod } r.setOperand1(middle); setStart(r, middle); - middle= r; - r= (IASTBinaryExpression) r.getParent(); + middle = r; + r = (IASTBinaryExpression) r.getParent(); } else if (l instanceof IASTCastExpression) { // cast binds stronger than binary operator ((IASTCastExpression) l).setOperand(middle); setEnd(l, middle); - middle= l; // middle becomes cast-expr, can be put into r (a binary-expr) - l= (IASTExpression) l.getParent(); + middle = l; // middle becomes cast-expr, can be put into r (a binary-expr) + l = (IASTExpression) l.getParent(); } else if (l instanceof IASTUnaryExpression) { // // unary operator binds stronger than binary operator ((IASTUnaryExpression) l).setOperand(middle); setEnd(l, middle); - middle= l; // middle becomes unary-expr, can be put into r (a binary-expr) - l= (IASTExpression) l.getParent(); + middle = l; // middle becomes unary-expr, can be put into r (a binary-expr) + l = (IASTExpression) l.getParent(); } else { - if (r== null || getPrecendence((IASTBinaryExpression) l) >= getPrecendence(r)) { + if (r == null || getPrecendence((IASTBinaryExpression) l) >= getPrecendence(r)) { ((IASTBinaryExpression) l).setOperand2(middle); setEnd(l, middle); - middle= l; // middle becomes binary, can be put into r because precedence is greater or equal. - l= (IASTExpression) l.getParent(); + middle = l; // middle becomes binary, can be put into r because precedence is greater or equal. + l = (IASTExpression) l.getParent(); } else { r.setOperand1(middle); setStart(r, middle); - middle= r; // middle becomes binary, can be put into r because precedence is greater. - r= (IASTBinaryExpression) r.getParent(); + middle = r; // middle becomes binary, can be put into r because precedence is greater. + r = (IASTBinaryExpression) r.getParent(); } } } @@ -245,14 +245,14 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod private IASTUnaryExpression findTrailingBracketedPrimaryExpression(IASTExpression expr) { while (true) { if (expr instanceof IASTBinaryExpression) { - expr= ((IASTBinaryExpression) expr).getOperand2(); + expr = ((IASTBinaryExpression) expr).getOperand2(); } else if (expr instanceof IASTCastExpression) { - expr= ((IASTCastExpression) expr).getOperand(); + expr = ((IASTCastExpression) expr).getOperand(); } else if (expr instanceof IASTUnaryExpression) { - IASTUnaryExpression u= (IASTUnaryExpression) expr; + IASTUnaryExpression u = (IASTUnaryExpression) expr; if (u.getOperator() == IASTUnaryExpression.op_bracketedPrimary) return u; - expr= u.getOperand(); + expr = u.getOperand(); } else { return null; } @@ -261,7 +261,7 @@ public abstract class ASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousNod private IASTExpression findLeadingCastExpression(IASTExpression expr) { while (expr instanceof IASTBinaryExpression) { - expr= ((IASTBinaryExpression) expr).getOperand1(); + expr = ((IASTBinaryExpression) expr).getOperand1(); } return expr; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java index c1af22f359f..c1e679c6980 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java @@ -31,27 +31,29 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding; * Handles the ambiguity between cast and function-call expressions: (type)(expr) versus (function)(expr); * It also handles the impact on the grouping of the sub-expressions. */ -public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression { - private final IASTCastExpression fCastExpression; - private final IASTFunctionCallExpression fFunctionCallExpression; - - /** - * The operand of the cast expression must start with an expression in parenthesis (which could be read as the parameter - * list of the function call). - * The function-call must contain the name expression (corresponding to the type-id of the cast expression). The parameter - * expression may be <code>null</code>, it will be computed from the cast expression. - */ - public ASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpression, IASTFunctionCallExpression functionCall) { - fCastExpression= castExpression; - fFunctionCallExpression= functionCall; - } +public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbiguousNode + implements IASTAmbiguousExpression { + private final IASTCastExpression fCastExpression; + private final IASTFunctionCallExpression fFunctionCallExpression; + + /** + * The operand of the cast expression must start with an expression in parenthesis (which could be read as the parameter + * list of the function call). + * The function-call must contain the name expression (corresponding to the type-id of the cast expression). The parameter + * expression may be <code>null</code>, it will be computed from the cast expression. + */ + public ASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpression, + IASTFunctionCallExpression functionCall) { + fCastExpression = castExpression; + fFunctionCallExpression = functionCall; + } @Override public final IASTNode[] getNodes() { return getExpressions(); } - @Override + @Override public final IASTExpression copy() { throw new UnsupportedOperationException(); } @@ -61,49 +63,49 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu throw new UnsupportedOperationException(); } - @Override + @Override public void addExpression(IASTExpression e) { throw new UnsupportedOperationException(); - } + } @Override public IASTExpression[] getExpressions() { - return new IASTExpression[] {fCastExpression, fFunctionCallExpression}; + return new IASTExpression[] { fCastExpression, fFunctionCallExpression }; } @Override protected final IASTNode doResolveAmbiguity(ASTVisitor visitor) { - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); - IASTNode nodeToReplace= this; + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace = this; // try cast-expression owner.replace(nodeToReplace, fCastExpression); - nodeToReplace= fCastExpression; + nodeToReplace = fCastExpression; // resolve nested ambiguities fCastExpression.accept(visitor); // if the operand of the cast-expr is not suitable for a function call, we are done. - final IASTUnaryExpression primaryWithParenthesis= findPrimaryExpressionInParenthesis(fCastExpression.getOperand()); + final IASTUnaryExpression primaryWithParenthesis = findPrimaryExpressionInParenthesis( + fCastExpression.getOperand()); if (primaryWithParenthesis == null) return nodeToReplace; - // find nested names - final NameCollector nameCollector= new NameCollector(); + final NameCollector nameCollector = new NameCollector(); fCastExpression.getTypeId().accept(nameCollector); - final IASTName[] names= nameCollector.getNames(); + final IASTName[] names = nameCollector.getNames(); // resolve names - boolean hasIssue= false; + boolean hasIssue = false; for (IASTName name : names) { try { IBinding b = name.resolveBinding(); if (b instanceof IProblemBinding) { - hasIssue= true; + hasIssue = true; break; } } catch (Exception t) { - hasIssue= true; + hasIssue = true; break; } } @@ -112,45 +114,45 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu final IASTExpression operand = primaryWithParenthesis.getOperand(); if (operand instanceof IASTExpressionList) { - final IASTExpressionList list= (IASTExpressionList) operand; + final IASTExpressionList list = (IASTExpressionList) operand; fFunctionCallExpression.setArguments(list.getExpressions()); } else if (operand != null) { - fFunctionCallExpression.setArguments(new IASTInitializerClause[] {operand}); + fFunctionCallExpression.setArguments(new IASTInitializerClause[] { operand }); } else { fFunctionCallExpression.setArguments(IASTExpression.EMPTY_EXPRESSION_ARRAY); } setRange(fFunctionCallExpression, fCastExpression, primaryWithParenthesis); - IASTExpression result= fFunctionCallExpression; - IASTExpression postFix= fCastExpression.getOperand(); + IASTExpression result = fFunctionCallExpression; + IASTExpression postFix = fCastExpression.getOperand(); if (postFix != primaryWithParenthesis) { - result= postFix; + result = postFix; while (true) { setStart(postFix, fFunctionCallExpression); if (postFix instanceof IASTArraySubscriptExpression) { final IASTArraySubscriptExpression ase = (IASTArraySubscriptExpression) postFix; - postFix= ase.getArrayExpression(); + postFix = ase.getArrayExpression(); if (postFix == primaryWithParenthesis) { ase.setArrayExpression(fFunctionCallExpression); break; } } else if (postFix instanceof IASTFunctionCallExpression) { final IASTFunctionCallExpression fc = (IASTFunctionCallExpression) postFix; - postFix= fc.getFunctionNameExpression(); + postFix = fc.getFunctionNameExpression(); if (postFix == primaryWithParenthesis) { fc.setFunctionNameExpression(fFunctionCallExpression); break; } } else if (postFix instanceof IASTFieldReference) { final IASTFieldReference fr = (IASTFieldReference) postFix; - postFix= fr.getFieldOwner(); + postFix = fr.getFieldOwner(); if (postFix == primaryWithParenthesis) { fr.setFieldOwner(fFunctionCallExpression); break; } } else { final IASTUnaryExpression ue = (IASTUnaryExpression) postFix; - postFix= ue.getOperand(); + postFix = ue.getOperand(); if (postFix == primaryWithParenthesis) { ue.setOperand(fFunctionCallExpression); break; @@ -168,23 +170,23 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu private IASTUnaryExpression findPrimaryExpressionInParenthesis(IASTExpression operand) { while (true) { if (operand instanceof IASTUnaryExpression) { - final IASTUnaryExpression unary= (IASTUnaryExpression) operand; + final IASTUnaryExpression unary = (IASTUnaryExpression) operand; switch (unary.getOperator()) { case IASTUnaryExpression.op_bracketedPrimary: return unary; case IASTUnaryExpression.op_postFixDecr: case IASTUnaryExpression.op_postFixIncr: - operand= unary.getOperand(); + operand = unary.getOperand(); break; default: return null; } } else if (operand instanceof IASTArraySubscriptExpression) { - operand= ((IASTArraySubscriptExpression) operand).getArrayExpression(); + operand = ((IASTArraySubscriptExpression) operand).getArrayExpression(); } else if (operand instanceof IASTFunctionCallExpression) { - operand= ((IASTFunctionCallExpression) operand).getFunctionNameExpression(); + operand = ((IASTFunctionCallExpression) operand).getFunctionNameExpression(); } else if (operand instanceof IASTFieldReference) { - operand= ((IASTFieldReference) operand).getFieldOwner(); + operand = ((IASTFieldReference) operand).getFieldOwner(); } else { return null; } @@ -192,14 +194,14 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu } private void setStart(IASTNode node, IASTNode start) { - final ASTNode target= (ASTNode) node; + final ASTNode target = (ASTNode) node; final int offset = ((ASTNode) start).getOffset(); target.setOffsetAndLength(offset, target.getOffset() + target.getLength() - offset); } private void setRange(IASTNode node, IASTNode from, IASTNode to) { final int offset = ((ASTNode) from).getOffset(); - final ASTNode t= (ASTNode) to; - ((ASTNode) node).setOffsetAndLength(offset, t.getOffset()+t.getLength()-offset); + final ASTNode t = (ASTNode) to; + ((ASTNode) node).setOffsetAndLength(offset, t.getOffset() + t.getLength() - offset); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java index 380d2e8441e..be1c5dfcc36 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousNode.java @@ -33,9 +33,9 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * Base implementation for all ambiguous nodes. */ -public abstract class ASTAmbiguousNode extends ASTNode { +public abstract class ASTAmbiguousNode extends ASTNode { - public static class NameCollector extends ASTVisitor { + public static class NameCollector extends ASTVisitor { private IASTName[] names = new IASTName[2]; private int namesPos = -1; @@ -60,19 +60,19 @@ public abstract class ASTAmbiguousNode extends ASTNode { private IASTNode fResolution; - /** - * Return the alternative nodes for this ambiguity. - */ - public abstract IASTNode[] getNodes(); + /** + * Return the alternative nodes for this ambiguity. + */ + public abstract IASTNode[] getNodes(); - @Override + @Override public final boolean accept(ASTVisitor visitor) { - if (visitor.shouldVisitAmbiguousNodes && visitor.visit(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (visitor.shouldVisitAmbiguousNodes && visitor.visit(this) == ASTVisitor.PROCESS_ABORT) + return false; - // Alternatives are not visited on purpose. - return true; - } + // Alternatives are not visited on purpose. + return true; + } protected void beforeResolution() { } @@ -84,16 +84,16 @@ public abstract class ASTAmbiguousNode extends ASTNode { } public IASTNode resolveAmbiguity(ASTVisitor resolver) { - return fResolution= doResolveAmbiguity(resolver); + return fResolution = doResolveAmbiguity(resolver); } - protected IASTNode doResolveAmbiguity(ASTVisitor resolver) { - beforeResolution(); - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); - IASTNode nodeToReplace= this; + protected IASTNode doResolveAmbiguity(ASTVisitor resolver) { + beforeResolution(); + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace = this; - final IASTNode[] alternatives= getNodes(); - IASTNode bestAlternative= null; + final IASTNode[] alternatives = getNodes(); + IASTNode bestAlternative = null; int minIssues = Integer.MAX_VALUE; for (IASTNode alternative : alternatives) { @@ -103,16 +103,16 @@ public abstract class ASTAmbiguousNode extends ASTNode { beforeAlternative(alternative); // Handle nested ambiguities - alternative= resolveNestedAmbiguities(alternative, resolver); - nodeToReplace= alternative; + alternative = resolveNestedAmbiguities(alternative, resolver); + nodeToReplace = alternative; // Find nested names - final NameCollector nameCollector= new NameCollector(); + final NameCollector nameCollector = new NameCollector(); alternative.accept(nameCollector); - final IASTName[] names= nameCollector.getNames(); + final IASTName[] names = nameCollector.getNames(); // Resolve names and count issues - int issues= 0; + int issues = 0; for (IASTName name : names) { try { // Avoid resolution of parameters (can always be resolved), @@ -120,14 +120,14 @@ public abstract class ASTAmbiguousNode extends ASTNode { // while the declarator is still ambiguous. Could be solved by introducing an // intermediate binding for parameters, similar to template parameters. if (name.getPropertyInParent() == IASTDeclarator.DECLARATOR_NAME) { - IASTNode parent= name.getParent(); + IASTNode parent = name.getParent(); if (parent instanceof IASTDeclarator) { - parent= ASTQueries.findOutermostDeclarator((IASTDeclarator) parent); + parent = ASTQueries.findOutermostDeclarator((IASTDeclarator) parent); if (parent.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR) continue; } } - IBinding b= name.resolvePreBinding(); + IBinding b = name.resolvePreBinding(); if (b instanceof IProblemBinding) { issues++; } @@ -139,8 +139,8 @@ public abstract class ASTAmbiguousNode extends ASTNode { } } if (issues < minIssues) { - minIssues= issues; - bestAlternative= alternative; + minIssues = issues; + bestAlternative = alternative; if (issues == 0) { break; } @@ -165,24 +165,24 @@ public abstract class ASTAmbiguousNode extends ASTNode { public final IType getExpressionType() { logAmbiguousNodeError(); return ProblemType.UNKNOWN_FOR_EXPRESSION; - } + } public final ValueCategory getValueCategory() { logAmbiguousNodeError(); return ValueCategory.PRVALUE; - } + } - public final boolean isLValue() { + public final boolean isLValue() { logAmbiguousNodeError(); return false; - } + } - public final ICPPEvaluation getEvaluation() { + public final ICPPEvaluation getEvaluation() { logAmbiguousNodeError(); return EvalFixed.INCOMPLETE; } - public final ICPPExecution getExecution() { + public final ICPPExecution getExecution() { logAmbiguousNodeError(); return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java index 8d6cde22934..f83401e6e23 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java @@ -21,18 +21,18 @@ import org.eclipse.cdt.core.dom.ast.IASTToken; * Base class for C and C++ attributes. */ public abstract class ASTAttribute extends ASTNode implements IASTAttribute { - private final char[] name; - private final IASTToken argumentClause; + private final char[] name; + private final IASTToken argumentClause; public ASTAttribute(char[] name, IASTToken arguments) { this.name = name; this.argumentClause = arguments; } - @Override + @Override public char[] getName() { - return name; - } + return name; + } @Override public IASTToken getArgumentClause() { @@ -50,19 +50,23 @@ public abstract class ASTAttribute extends ASTNode implements IASTAttribute { @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitAttributes) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitAttributes) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (argumentClause != null && !argumentClause.accept(action)) return false; + if (argumentClause != null && !argumentClause.accept(action)) + return false; - if (action.shouldVisitAttributes && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (action.shouldVisitAttributes && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java index bc7d1848c43..f4c42a2ab31 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java @@ -36,8 +36,7 @@ public abstract class ASTAttributeOwner extends ASTNode implements IASTAttribute IASTAttribute[] attributes = IASTAttribute.EMPTY_ATTRIBUTE_ARRAY; for (IASTAttributeSpecifier attributeSpecifier : getAttributeSpecifiers()) { if (attributeSpecifier instanceof IASTAttributeList) { - attributes = ArrayUtil.addAll(attributes, - ((IASTAttributeList) attributeSpecifier).getAttributes()); + attributes = ArrayUtil.addAll(attributes, ((IASTAttributeList) attributeSpecifier).getAttributes()); } } return attributes; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java index c8637907aa1..a76ebb9afb9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java @@ -34,11 +34,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; * Base class for C and C++ enumerators. */ public abstract class ASTEnumerator extends ASTAttributeOwner implements IASTEnumerator, IASTAmbiguityParent { - private IASTName name; - private IASTExpression value; - private IValue integralValue; + private IASTName name; + private IASTExpression value; + private IValue integralValue; - public ASTEnumerator() { + public ASTEnumerator() { } public ASTEnumerator(IASTName name, IASTExpression value) { @@ -55,54 +55,63 @@ public abstract class ASTEnumerator extends ASTAttributeOwner implements IASTEnu @Override public void setName(IASTName name) { assertNotFrozen(); - this.name = name; - if (name != null) { + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(ENUMERATOR_NAME); } - } + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setValue(IASTExpression expression) { - assertNotFrozen(); - this.value = expression; - if (expression != null) { + assertNotFrozen(); + this.value = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(ENUMERATOR_VALUE); } - } + } - @Override + @Override public IASTExpression getValue() { - return value; - } + return value; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitEnumerators) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitEnumerators) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (name != null && !name.accept(action)) return false; - if (!acceptByAttributeSpecifiers(action)) return false; - if (value != null && !value.accept(action)) return false; - if (action.shouldVisitEnumerators) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (name != null && !name.accept(action)) + return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (value != null && !value.accept(action)) + return false; + if (action.shouldVisitEnumerators) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -112,26 +121,26 @@ public abstract class ASTEnumerator extends ASTAttributeOwner implements IASTEnu return r_reference; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == value) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - value = (IASTExpression) other; - } - } + if (child == value) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + value = (IASTExpression) other; + } + } public IValue getIntegralValue() { if (integralValue == null) { - IASTNode parent= getParent(); + IASTNode parent = getParent(); if (parent instanceof IASTInternalEnumerationSpecifier) { - IASTInternalEnumerationSpecifier enumeration= (IASTInternalEnumerationSpecifier) parent; + IASTInternalEnumerationSpecifier enumeration = (IASTInternalEnumerationSpecifier) parent; if (enumeration.startValueComputation()) { // Prevent infinite recursion. computeEnumValues(enumeration); } } if (integralValue == null) { - integralValue= IntegralValue.UNKNOWN; + integralValue = IntegralValue.UNKNOWN; } } return integralValue; @@ -149,13 +158,13 @@ public abstract class ASTEnumerator extends ASTAttributeOwner implements IASTEnu IType type = fixedType == null ? CPPBasicType.INT : null; IValue previousExplicitValue = null; int delta = 0; - IASTEnumerator[] etors= enumeration.getEnumerators(); + IASTEnumerator[] etors = enumeration.getEnumerators(); for (IASTEnumerator etor : etors) { IBinding etorBinding = etor.getName().resolveBinding(); IValue val; - IASTExpression expr= etor.getValue(); + IASTExpression expr = etor.getValue(); if (expr != null) { - val= ValueFactory.create(expr); + val = ValueFactory.create(expr); previousExplicitValue = val; delta = 1; if (fixedType == null) { @@ -180,7 +189,7 @@ public abstract class ASTEnumerator extends ASTAttributeOwner implements IASTEnu } } if (etor instanceof ASTEnumerator) { - ((ASTEnumerator) etor).integralValue= val; + ((ASTEnumerator) etor).integralValue = val; } } } finally { @@ -203,8 +212,7 @@ public abstract class ASTEnumerator extends ASTAttributeOwner implements IASTEnu Number numericalValue = val.numberValue(); if (numericalValue != null) { long longValue = numericalValue.longValue(); - if ((type.getKind() != Kind.eInt && type.getKind() != Kind.eInt128) || - type.isShort()) { + if ((type.getKind() != Kind.eInt && type.getKind() != Kind.eInt128) || type.isShort()) { type = type.isUnsigned() ? CPPBasicType.UNSIGNED_INT : CPPBasicType.INT; } if (!ArithmeticConversion.fitsIntoType(type, longValue)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java index 42cb1330e7c..4381e4fbe74 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java @@ -23,11 +23,10 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; /** * Initializer with equals sign (copy initialization) */ -public abstract class ASTEqualsInitializer extends ASTNode - implements IASTEqualsInitializer, IASTAmbiguityParent { - private IASTInitializerClause fArgument; +public abstract class ASTEqualsInitializer extends ASTNode implements IASTEqualsInitializer, IASTAmbiguityParent { + private IASTInitializerClause fArgument; - public ASTEqualsInitializer() { + public ASTEqualsInitializer() { } public ASTEqualsInitializer(IASTInitializerClause arg) { @@ -36,27 +35,30 @@ public abstract class ASTEqualsInitializer extends ASTNode @Override public IASTInitializerClause getInitializerClause() { - return fArgument; - } + return fArgument; + } - @Override + @Override public void setInitializerClause(IASTInitializerClause clause) { - assertNotFrozen(); - fArgument = clause; - if (clause != null) { - clause.setParent(this); - clause.setPropertyInParent(INITIALIZER); + assertNotFrozen(); + fArgument = clause; + if (clause != null) { + clause.setParent(this); + clause.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitInitializers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fArgument != null && !fArgument.accept(action)) @@ -65,8 +67,8 @@ public abstract class ASTEqualsInitializer extends ASTNode if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java index f65b51623e9..dfd2db34048 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java @@ -56,7 +56,7 @@ public class ASTInternal { if (binding instanceof ICInternalBinding) { return ((ICInternalBinding) binding).getDefinition(); } - CCorePlugin.log("ASTInternal.getDefinitionOfBinding() called for binding of type " + //$NON-NLS-1$ + CCorePlugin.log("ASTInternal.getDefinitionOfBinding() called for binding of type " + //$NON-NLS-1$ binding.getClass().getName()); assert false; return null; @@ -96,7 +96,7 @@ public class ASTInternal { public static void addName(IScope scope, IASTName name) { addName(scope, name, /* adlOnly = */ false); } - + public static void addName(IScope scope, IASTName name, boolean adlOnly) { if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).addName(name, adlOnly); @@ -133,7 +133,7 @@ public class ASTInternal { } } - IASTTranslationUnit tu= result.getTranslationUnit(); + IASTTranslationUnit tu = result.getTranslationUnit(); if (tu != null) { if (tu.getIndexFileSet().containsNonLocalDeclaration(binding, forFragment)) return null; @@ -146,7 +146,7 @@ public class ASTInternal { if (result == null) return null; - IASTTranslationUnit ast= result.getTranslationUnit(); + IASTTranslationUnit ast = result.getTranslationUnit(); if (ast != null) { ITranslationUnit tu = ast.getOriginatingTranslationUnit(); if (tu == null) @@ -165,31 +165,31 @@ public class ASTInternal { IASTNode[] decls; IASTNode def; if (binding instanceof ICPPInternalBinding) { - ICPPInternalBinding ib= (ICPPInternalBinding) binding; - decls= ib.getDeclarations(); - def= ib.getDefinition(); + ICPPInternalBinding ib = (ICPPInternalBinding) binding; + decls = ib.getDeclarations(); + def = ib.getDefinition(); } else if (binding instanceof ICInternalBinding) { - ICInternalBinding ib= (ICInternalBinding) binding; - decls= ib.getDeclarations(); - def= ib.getDefinition(); + ICInternalBinding ib = (ICInternalBinding) binding; + decls = ib.getDeclarations(); + def = ib.getDefinition(); } else { return null; } if (requireDefinition && def == null) { return null; } - IASTNode result= null; + IASTNode result = null; if (def != null) { if (!isPartOfSource(def)) return null; - result= def; + result = def; } if (decls != null) { for (final IASTNode node : decls) { if (node != null) { if (!isPartOfSource(node)) return null; - if ((result= resolveConflict(result, node)) == null) + if ((result = resolveConflict(result, node)) == null) return null; } } @@ -205,11 +205,11 @@ public class ASTInternal { if (n1 == null) return n2; - IASTFileLocation loc1= n1.getFileLocation(); + IASTFileLocation loc1 = n1.getFileLocation(); if (loc1 == null) return n2; - IASTFileLocation loc2= n2.getFileLocation(); + IASTFileLocation loc2 = n2.getFileLocation(); if (loc2 != null && loc1.getContextInclusionStatement() != loc2.getContextInclusionStatement()) return null; @@ -220,24 +220,24 @@ public class ASTInternal { IASTNode[] decls; IASTNode def; if (binding instanceof ICPPInternalBinding) { - ICPPInternalBinding ib= (ICPPInternalBinding) binding; - decls= ib.getDeclarations(); - def= ib.getDefinition(); + ICPPInternalBinding ib = (ICPPInternalBinding) binding; + decls = ib.getDeclarations(); + def = ib.getDefinition(); } else if (binding instanceof ICInternalBinding) { - ICInternalBinding ib= (ICInternalBinding) binding; - decls= ib.getDeclarations(); - def= ib.getDefinition(); + ICInternalBinding ib = (ICInternalBinding) binding; + decls = ib.getDeclarations(); + def = ib.getDefinition(); } else { return null; } - IASTNode result= null; + IASTNode result = null; if (def != null) { - result= def; + result = def; } if (decls != null) { for (final IASTNode node : decls) { if (node != null) { - if ((result= resolveConflict(result, node)) == null) + if ((result = resolveConflict(result, node)) == null) return null; } } @@ -259,10 +259,10 @@ public class ASTInternal { public static boolean hasDeclaration(IBinding binding) { if (binding instanceof ICPPInternalBinding) { - ICPPInternalBinding internal= (ICPPInternalBinding) binding; + ICPPInternalBinding internal = (ICPPInternalBinding) binding; if (internal.getDefinition() != null) return true; - IASTNode[] decls= internal.getDeclarations(); + IASTNode[] decls = internal.getDeclarations(); return decls != null && decls.length > 0 && decls[0] != null; } if (binding instanceof IIndexBinding) { @@ -282,7 +282,7 @@ public class ASTInternal { if (declarations != null) { for (IASTNode node : declarations) { if (!CPPVisitor.isNameOfFriendDeclaration(node)) - return true; + return true; } } return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java index a5708165557..fe43e6438a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java @@ -36,29 +36,29 @@ import org.eclipse.cdt.internal.core.parser.scanner.Token; * Base class for all non-preprocessor nodes in the AST. */ public abstract class ASTNode implements IASTNode { - private IASTNode parent; - private ASTNodeProperty property; - - /** - * The sequence number of the ast-node as calculated by the location map. - * Do not access directly, because getOffset() may be overloaded for lazy calculations. - */ - private int offset; - private int length; - private IASTNodeLocation[] locations; - private IASTFileLocation fileLocation; - - private boolean frozen = false; - private boolean active = true; - - @Override + private IASTNode parent; + private ASTNodeProperty property; + + /** + * The sequence number of the ast-node as calculated by the location map. + * Do not access directly, because getOffset() may be overloaded for lazy calculations. + */ + private int offset; + private int length; + private IASTNodeLocation[] locations; + private IASTFileLocation fileLocation; + + private boolean frozen = false; + private boolean active = true; + + @Override public IASTNode getParent() { - return parent; - } + return parent; + } @Override public IASTNode[] getChildren() { - ChildCollector collector= new ChildCollector(this); + ChildCollector collector = new ChildCollector(this); return collector.getChildren(); } @@ -77,8 +77,8 @@ public abstract class ASTNode implements IASTNode { } public void setInactive() { - assertNotFrozen(); - active= false; + assertNotFrozen(); + active = false; } protected final void assertNotFrozen() throws IllegalStateException { @@ -86,187 +86,187 @@ public abstract class ASTNode implements IASTNode { throw new IllegalStateException("Attempt to modify a frozen AST node"); //$NON-NLS-1$ } - @Override + @Override public void setParent(IASTNode node) { - assertNotFrozen(); - this.parent = node; - } + assertNotFrozen(); + this.parent = node; + } - @Override + @Override public final ASTNodeProperty getPropertyInParent() { - return property; - } + return property; + } - @Override + @Override public void setPropertyInParent(ASTNodeProperty property) { - assertNotFrozen(); - this.property = property; - } - - public int getOffset() { - return offset; - } - - public final int getLength() { - return length; - } - - public void setOffset(int offset) { - this.offset = offset; - this.locations = null; - this.fileLocation = null; - } - - public void setLength(int length) { - this.length = length; - this.locations = null; - this.fileLocation = null; - } - - public void setOffsetAndLength(int offset, int length) { - this.offset = offset; - this.length = length; - this.locations = null; - this.fileLocation = null; - } - - public void setOffsetAndLength(ASTNode node) { - setOffsetAndLength(node.getOffset(), node.getLength()); - } - - @Override + assertNotFrozen(); + this.property = property; + } + + public int getOffset() { + return offset; + } + + public final int getLength() { + return length; + } + + public void setOffset(int offset) { + this.offset = offset; + this.locations = null; + this.fileLocation = null; + } + + public void setLength(int length) { + this.length = length; + this.locations = null; + this.fileLocation = null; + } + + public void setOffsetAndLength(int offset, int length) { + this.offset = offset; + this.length = length; + this.locations = null; + this.fileLocation = null; + } + + public void setOffsetAndLength(ASTNode node) { + setOffsetAndLength(node.getOffset(), node.getLength()); + } + + @Override public IASTNodeLocation[] getNodeLocations() { - if (locations == null) { - if (length != 0) { - final IASTTranslationUnit tu= getTranslationUnit(); - if (tu != null) { - ILocationResolver l= tu.getAdapter(ILocationResolver.class); - if (l != null) { - locations= l.getLocations(getOffset(), length); - } - } - } - if (locations == null) - locations= IASTNodeLocation.EMPTY_ARRAY; - } - return locations; - } - - public IASTImageLocation getImageLocation() { - final IASTTranslationUnit tu= getTranslationUnit(); - if (tu != null) { - ILocationResolver l= tu.getAdapter(ILocationResolver.class); - if (l != null) { - return l.getImageLocation(getOffset(), length); - } - } - return null; - } - - protected char[] getRawSignatureChars() { - final IASTNode originalNode = getOriginalNode(); - final IASTFileLocation floc= originalNode.getFileLocation(); - final IASTTranslationUnit ast = originalNode.getTranslationUnit(); - if (floc != null && ast != null) { - ILocationResolver lr= ast.getAdapter(ILocationResolver.class); - if (lr != null) { - return lr.getUnpreprocessedSignature(floc); - } - } - return CharArrayUtils.EMPTY; - } - - @Override + if (locations == null) { + if (length != 0) { + final IASTTranslationUnit tu = getTranslationUnit(); + if (tu != null) { + ILocationResolver l = tu.getAdapter(ILocationResolver.class); + if (l != null) { + locations = l.getLocations(getOffset(), length); + } + } + } + if (locations == null) + locations = IASTNodeLocation.EMPTY_ARRAY; + } + return locations; + } + + public IASTImageLocation getImageLocation() { + final IASTTranslationUnit tu = getTranslationUnit(); + if (tu != null) { + ILocationResolver l = tu.getAdapter(ILocationResolver.class); + if (l != null) { + return l.getImageLocation(getOffset(), length); + } + } + return null; + } + + protected char[] getRawSignatureChars() { + final IASTNode originalNode = getOriginalNode(); + final IASTFileLocation floc = originalNode.getFileLocation(); + final IASTTranslationUnit ast = originalNode.getTranslationUnit(); + if (floc != null && ast != null) { + ILocationResolver lr = ast.getAdapter(ILocationResolver.class); + if (lr != null) { + return lr.getUnpreprocessedSignature(floc); + } + } + return CharArrayUtils.EMPTY; + } + + @Override public String getRawSignature() { - return new String(getRawSignatureChars()); - } + return new String(getRawSignatureChars()); + } - @Override + @Override public String getContainingFilename() { - final int offset = getOffset(); + final int offset = getOffset(); if (offset <= 0 && (length == 0 || offset < 0)) { - final IASTNode parent = getParent(); - if (parent == null) { - if (this instanceof IASTTranslationUnit) { - return ((IASTTranslationUnit) this).getFilePath(); - } - return ""; //$NON-NLS-1$ - } - return parent.getContainingFilename(); - } - return getTranslationUnit().getContainingFilename(offset); - } - - @Override + final IASTNode parent = getParent(); + if (parent == null) { + if (this instanceof IASTTranslationUnit) { + return ((IASTTranslationUnit) this).getFilePath(); + } + return ""; //$NON-NLS-1$ + } + return parent.getContainingFilename(); + } + return getTranslationUnit().getContainingFilename(offset); + } + + @Override public IASTFileLocation getFileLocation() { - if (fileLocation != null) - return fileLocation; - final int offset = getOffset(); - // Only an empty translation unit should have offset = 0 and length = 0. - // Otherwise these values mean the parser failed to set the offset and length. + if (fileLocation != null) + return fileLocation; + final int offset = getOffset(); + // Only an empty translation unit should have offset = 0 and length = 0. + // Otherwise these values mean the parser failed to set the offset and length. if (offset < 0 || (offset == 0 && length == 0 && !(this instanceof IASTTranslationUnit))) { - return null; - } - IASTTranslationUnit ast = getTranslationUnit(); - if (ast != null) { - ILocationResolver lr= ast.getAdapter(ILocationResolver.class); - if (lr != null) { - fileLocation= lr.getMappedFileLocation(offset, length); - } else { - // Support for old location map - fileLocation= ast.flattenLocationsToFile(getNodeLocations()); - } - } - return fileLocation; - } - - @Override + return null; + } + IASTTranslationUnit ast = getTranslationUnit(); + if (ast != null) { + ILocationResolver lr = ast.getAdapter(ILocationResolver.class); + if (lr != null) { + fileLocation = lr.getMappedFileLocation(offset, length); + } else { + // Support for old location map + fileLocation = ast.flattenLocationsToFile(getNodeLocations()); + } + } + return fileLocation; + } + + @Override public boolean isPartOfTranslationUnitFile() { - IASTTranslationUnit ast = getTranslationUnit(); - if (ast != null) { - ILocationResolver lr= ast.getAdapter(ILocationResolver.class); - if (lr != null) { - return lr.isPartOfTranslationUnitFile(getOffset()); - } - } - return false; - } - - public boolean isPartOfSourceFile() { - IASTTranslationUnit ast = getTranslationUnit(); - if (ast != null) { - ILocationResolver lr= ast.getAdapter(ILocationResolver.class); - if (lr != null) { - return lr.isPartOfSourceFile(getOffset()); - } - } - return false; - } - - @Override + IASTTranslationUnit ast = getTranslationUnit(); + if (ast != null) { + ILocationResolver lr = ast.getAdapter(ILocationResolver.class); + if (lr != null) { + return lr.isPartOfTranslationUnitFile(getOffset()); + } + } + return false; + } + + public boolean isPartOfSourceFile() { + IASTTranslationUnit ast = getTranslationUnit(); + if (ast != null) { + ILocationResolver lr = ast.getAdapter(ILocationResolver.class); + if (lr != null) { + return lr.isPartOfSourceFile(getOffset()); + } + } + return false; + } + + @Override public IASTTranslationUnit getTranslationUnit() { - IASTNode node = this; - for (IASTNode p = parent; p != null; p = p.getParent()) { - node = p; - } - return node instanceof IASTTranslationUnit ? (IASTTranslationUnit) node : null; - } - - @Override + IASTNode node = this; + for (IASTNode p = parent; p != null; p = p.getParent()) { + node = p; + } + return node instanceof IASTTranslationUnit ? (IASTTranslationUnit) node : null; + } + + @Override public boolean accept(ASTVisitor visitor) { - return true; - } + return true; + } - @Override + @Override public boolean contains(IASTNode node) { - if (node instanceof ASTNode) { - ASTNode astNode= (ASTNode) node; - final int offset = getOffset(); - final int nodeOffset= astNode.getOffset(); + if (node instanceof ASTNode) { + ASTNode astNode = (ASTNode) node; + final int offset = getOffset(); + final int nodeOffset = astNode.getOffset(); return offset <= nodeOffset && nodeOffset + astNode.length <= offset + length; - } - return false; - } + } + return false; + } @Override public IToken getSyntax() throws ExpansionOverlapsBoundaryException { @@ -276,13 +276,13 @@ public abstract class ASTNode implements IASTNode { @Override public IToken getLeadingSyntax() throws ExpansionOverlapsBoundaryException { - int left= getBoundary(-1); + int left = getBoundary(-1); return getSyntax(left, getOffset(), -1); } @Override public IToken getTrailingSyntax() throws ExpansionOverlapsBoundaryException { - int right= getBoundary(1); + int right = getBoundary(1); return getSyntax(getOffset() + length, right, 1); } @@ -290,15 +290,15 @@ public abstract class ASTNode implements IASTNode { * Compute the sequence number of the boundary of the leading/trailing syntax. */ private int getBoundary(int direction) { - ASTNodeSearch visitor= new ASTNodeSearch(this); - IASTNode sib= direction < 0 ? visitor.findLeftSibling() : visitor.findRightSibling(); + ASTNodeSearch visitor = new ASTNodeSearch(this); + IASTNode sib = direction < 0 ? visitor.findLeftSibling() : visitor.findRightSibling(); if (sib == null) { - direction= -direction; - sib= getParent(); + direction = -direction; + sib = getParent(); } if (sib instanceof ASTNode) { - ASTNode astNode= (ASTNode) sib; - int offset= astNode.getOffset(); + ASTNode astNode = (ASTNode) sib; + int offset = astNode.getOffset(); if (direction < 0) { offset += astNode.getLength(); } @@ -308,62 +308,65 @@ public abstract class ASTNode implements IASTNode { throw new UnsupportedOperationException(); } - private IToken getSyntax(int fromSequenceNumber, int nextSequenceNumber, int direction) throws ExpansionOverlapsBoundaryException { - final IASTTranslationUnit tu= getTranslationUnit(); - if (!(tu instanceof ASTNode)) - throw new UnsupportedOperationException(); - - ILocationResolver lr= tu.getAdapter(ILocationResolver.class); - if (lr == null) - throw new UnsupportedOperationException(); - - int endSequenceNumber= lr.convertToSequenceEndNumber(nextSequenceNumber); - IASTFileLocation total= lr.getMappedFileLocation(fromSequenceNumber, endSequenceNumber - fromSequenceNumber); - IASTFileLocation myfloc= getFileLocation(); - if (total == null || myfloc == null) - throw new UnsupportedOperationException(); - - if (!total.getFileName().equals(myfloc.getFileName())) - throw new ExpansionOverlapsBoundaryException(); - - if (fromSequenceNumber > 0) { - IASTFileLocation fl= lr.getMappedFileLocation(fromSequenceNumber-1, endSequenceNumber - fromSequenceNumber + 1); - if (fl.getFileName().equals(total.getFileName()) && fl.getNodeOffset() == total.getNodeOffset()) - throw new ExpansionOverlapsBoundaryException(); - } - - if (endSequenceNumber < ((ASTNode) tu).getOffset() + ((ASTNode) tu).getLength()) { - IASTFileLocation fl= lr.getMappedFileLocation(fromSequenceNumber, nextSequenceNumber - fromSequenceNumber + 1); - if (fl.getFileName().equals(total.getFileName()) && fl.getNodeLength() == total.getNodeLength()) - throw new ExpansionOverlapsBoundaryException(); - } - - int adjustment= total.getNodeOffset() - myfloc.getNodeOffset(); - if (direction > 0) { - adjustment-= myfloc.getNodeLength(); - } - - char[] txt= lr.getUnpreprocessedSignature(total); - Lexer lex= new Lexer(txt, tu.getAdapter(LexerOptions.class), ILexerLog.NULL, null); - try { - Token result= null; - Token last= null; + private IToken getSyntax(int fromSequenceNumber, int nextSequenceNumber, int direction) + throws ExpansionOverlapsBoundaryException { + final IASTTranslationUnit tu = getTranslationUnit(); + if (!(tu instanceof ASTNode)) + throw new UnsupportedOperationException(); + + ILocationResolver lr = tu.getAdapter(ILocationResolver.class); + if (lr == null) + throw new UnsupportedOperationException(); + + int endSequenceNumber = lr.convertToSequenceEndNumber(nextSequenceNumber); + IASTFileLocation total = lr.getMappedFileLocation(fromSequenceNumber, endSequenceNumber - fromSequenceNumber); + IASTFileLocation myfloc = getFileLocation(); + if (total == null || myfloc == null) + throw new UnsupportedOperationException(); + + if (!total.getFileName().equals(myfloc.getFileName())) + throw new ExpansionOverlapsBoundaryException(); + + if (fromSequenceNumber > 0) { + IASTFileLocation fl = lr.getMappedFileLocation(fromSequenceNumber - 1, + endSequenceNumber - fromSequenceNumber + 1); + if (fl.getFileName().equals(total.getFileName()) && fl.getNodeOffset() == total.getNodeOffset()) + throw new ExpansionOverlapsBoundaryException(); + } + + if (endSequenceNumber < ((ASTNode) tu).getOffset() + ((ASTNode) tu).getLength()) { + IASTFileLocation fl = lr.getMappedFileLocation(fromSequenceNumber, + nextSequenceNumber - fromSequenceNumber + 1); + if (fl.getFileName().equals(total.getFileName()) && fl.getNodeLength() == total.getNodeLength()) + throw new ExpansionOverlapsBoundaryException(); + } + + int adjustment = total.getNodeOffset() - myfloc.getNodeOffset(); + if (direction > 0) { + adjustment -= myfloc.getNodeLength(); + } + + char[] txt = lr.getUnpreprocessedSignature(total); + Lexer lex = new Lexer(txt, tu.getAdapter(LexerOptions.class), ILexerLog.NULL, null); + try { + Token result = null; + Token last = null; while (true) { - Token t= lex.nextToken(); + Token t = lex.nextToken(); switch (t.getType()) { case IToken.tEND_OF_INPUT: return result; case Lexer.tNEWLINE: break; default: - int offset= t.getOffset() + adjustment; - int endOffset= t.getEndOffset() + adjustment; + int offset = t.getOffset() + adjustment; + int endOffset = t.getEndOffset() + adjustment; t.setOffset(offset, endOffset); if (last == null) { - result= last= t; + result = last = t; } else { last.setNext(t); - last= t; + last = t; } break; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSearch.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSearch.java index a4af6736772..9444017e013 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSearch.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSearch.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; */ public class ASTNodeSearch extends ASTGenericVisitor { private static final int LEFT = 0; - private static final int RIGHT= 1; + private static final int RIGHT = 1; private int fMode; private IASTNode fLeft; private IASTNode fRight; @@ -30,16 +30,16 @@ public class ASTNodeSearch extends ASTGenericVisitor { public ASTNodeSearch(IASTNode node) { super(true); - fNode= node; - fParent= node.getParent(); + fNode = node; + fParent = node.getParent(); } public IASTNode findLeftSibling() { if (fParent == null) return null; - fMode= LEFT; - fLeft= fRight= null; + fMode = LEFT; + fLeft = fRight = null; fParent.accept(this); return fLeft; } @@ -48,8 +48,8 @@ public class ASTNodeSearch extends ASTGenericVisitor { if (fParent == null) return null; - fMode= RIGHT; - fLeft= fRight= null; + fMode = RIGHT; + fLeft = fRight = null; fParent.accept(this); return fRight; } @@ -63,13 +63,13 @@ public class ASTNodeSearch extends ASTGenericVisitor { case LEFT: if (node == fNode) return PROCESS_ABORT; - fLeft= node; + fLeft = node; return PROCESS_SKIP; case RIGHT: if (node == fNode) { - fLeft= fNode; + fLeft = fNode; } else if (fLeft != null) { - fRight= node; + fRight = node; return PROCESS_ABORT; } return PROCESS_SKIP; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java index 10bbb8edc44..e7d9ec8565d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSelector.java @@ -33,16 +33,16 @@ public class ASTNodeSelector implements IASTNodeSelector { private final boolean fIsValid; public ASTNodeSelector(ASTTranslationUnit tu, ILocationResolver locationResolver, String filePath) { - fTu= tu; - fLocationResolver= locationResolver; - fFilePath= filePath; - fIsValid= verify(); + fTu = tu; + fLocationResolver = locationResolver; + fFilePath = filePath; + fIsValid = verify(); } private boolean verify() { if (fLocationResolver != null) { if (fFilePath == null) { - fFilePath= fLocationResolver.getTranslationUnitPath(); + fFilePath = fLocationResolver.getTranslationUnitPath(); } return true; } @@ -63,62 +63,62 @@ public class ASTNodeSelector implements IASTNodeSelector { throw new IllegalArgumentException("Length cannot be less than zero."); //$NON-NLS-1$ } int sequenceLength; - int altSequenceNumber= -1; - int sequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile); - if (sequenceNumber < 0) { - return null; - } + int altSequenceNumber = -1; + int sequenceNumber = fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile); + if (sequenceNumber < 0) { + return null; + } if (lengthInFile > 0) { - sequenceLength= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, + sequenceLength = fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile + lengthInFile - 1) + 1 - sequenceNumber; } else { - sequenceLength= 0; + sequenceLength = 0; if (offsetInFile > 0) { - altSequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile - 1); + altSequenceNumber = fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile - 1); if (altSequenceNumber + 1 == sequenceNumber) { - altSequenceNumber= -1; + altSequenceNumber = -1; } else { // we are on a context boundary and we need to check the variant to the left and // the one to the right - sequenceLength= 1; + sequenceLength = 1; } } } - final ASTNodeSpecification<T> nodeSpec= - new ASTNodeSpecification<T>(relation, requiredClass, offsetInFile, lengthInFile); + final ASTNodeSpecification<T> nodeSpec = new ASTNodeSpecification<T>(relation, requiredClass, offsetInFile, + lengthInFile); nodeSpec.setRangeInSequence(sequenceNumber, sequenceLength, false); nodeSpec.setSearchInExpansion(searchInExpansion); - getNode(nodeSpec); - if (altSequenceNumber != -1) { - nodeSpec.setRangeInSequence(altSequenceNumber, sequenceLength, true); - getNode(nodeSpec); - } - return nodeSpec.getBestNode(); + getNode(nodeSpec); + if (altSequenceNumber != -1) { + nodeSpec.setRangeInSequence(altSequenceNumber, sequenceLength, true); + getNode(nodeSpec); + } + return nodeSpec.getBestNode(); } private <T extends IASTNode> T getNode(ASTNodeSpecification<T> nodeSpec) { fLocationResolver.findPreprocessorNode(nodeSpec); - if (!nodeSpec.requiresClass(IASTPreprocessorMacroExpansion.class)) { - // adjust sequence number for search in the expansion of macros - int seqbegin= nodeSpec.getSequenceStart(); - int seqend= nodeSpec.getSequenceEnd(); - IASTPreprocessorMacroExpansion expansion= nodeSpec.findLeadingMacroExpansion(this); - if (expansion != null) { - IASTFileLocation floc= expansion.getFileLocation(); - seqbegin= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, - floc.getNodeOffset() + floc.getNodeLength() - 1) + 1; - } - expansion= nodeSpec.findTrailingMacroExpansion(this); - if (expansion != null) { - IASTFileLocation floc= expansion.getFileLocation(); - seqend= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, - floc.getNodeOffset() + floc.getNodeLength()); - } - nodeSpec.setRangeInSequence(seqbegin, seqend - seqbegin); - - FindNodeForOffsetAction nodeFinder= new FindNodeForOffsetAction(nodeSpec); - fTu.accept(nodeFinder); - } + if (!nodeSpec.requiresClass(IASTPreprocessorMacroExpansion.class)) { + // adjust sequence number for search in the expansion of macros + int seqbegin = nodeSpec.getSequenceStart(); + int seqend = nodeSpec.getSequenceEnd(); + IASTPreprocessorMacroExpansion expansion = nodeSpec.findLeadingMacroExpansion(this); + if (expansion != null) { + IASTFileLocation floc = expansion.getFileLocation(); + seqbegin = fLocationResolver.getSequenceNumberForFileOffset(fFilePath, + floc.getNodeOffset() + floc.getNodeLength() - 1) + 1; + } + expansion = nodeSpec.findTrailingMacroExpansion(this); + if (expansion != null) { + IASTFileLocation floc = expansion.getFileLocation(); + seqend = fLocationResolver.getSequenceNumberForFileOffset(fFilePath, + floc.getNodeOffset() + floc.getNodeLength()); + } + nodeSpec.setRangeInSequence(seqbegin, seqend - seqbegin); + + FindNodeForOffsetAction nodeFinder = new FindNodeForOffsetAction(nodeSpec); + fTu.accept(nodeFinder); + } return nodeSpec.getBestNode(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java index de83fbbb1fb..0e7c81baa04 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java @@ -26,7 +26,9 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion; * @since 5.0 */ public class ASTNodeSpecification<T extends IASTNode> { - public enum Relation { FIRST_CONTAINED, EXACT_MATCH, ENCLOSING, STRICTLY_ENCLOSING } + public enum Relation { + FIRST_CONTAINED, EXACT_MATCH, ENCLOSING, STRICTLY_ENCLOSING + } private final Class<T> fClass; private final Relation fRelation; @@ -41,24 +43,24 @@ public class ASTNodeSpecification<T extends IASTNode> { private boolean fZeroToLeft; public ASTNodeSpecification(Relation relation, Class<T> clazz, int fileOffset, int fileLength) { - fRelation= relation; - fClass= clazz; - fFileOffset= fileOffset; - fFileEndOffset= fileOffset + fileLength; + fRelation = relation; + fClass = clazz; + fFileOffset = fileOffset; + fFileEndOffset = fileOffset + fileLength; } public void setRangeInSequence(int offsetInSeq, int lengthInSeq) { - fSeqNumber= offsetInSeq; - fSeqEndNumber= offsetInSeq + lengthInSeq; + fSeqNumber = offsetInSeq; + fSeqEndNumber = offsetInSeq + lengthInSeq; } public void setRangeInSequence(int offsetInSeq, int lengthInSeq, boolean zeroRangeToLeft) { setRangeInSequence(offsetInSeq, lengthInSeq); - fZeroToLeft= zeroRangeToLeft; + fZeroToLeft = zeroRangeToLeft; } public void setSearchInExpansion(boolean searchInExpansion) { - fSearchInExpansion= searchInExpansion; + fSearchInExpansion = searchInExpansion; } public Relation getRelationToSelection() { @@ -83,9 +85,9 @@ public class ASTNodeSpecification<T extends IASTNode> { @SuppressWarnings("unchecked") public void visit(ASTNode astNode) { - if (isAcceptableNode(astNode) && - isMatchingRange(astNode.getOffset(), astNode.getLength(), fSeqNumber, fSeqEndNumber)) { - IASTFileLocation loc= astNode.getFileLocation(); + if (isAcceptableNode(astNode) + && isMatchingRange(astNode.getOffset(), astNode.getLength(), fSeqNumber, fSeqEndNumber)) { + IASTFileLocation loc = astNode.getFileLocation(); if (loc != null) { storeIfBest(loc, (T) astNode); } @@ -95,14 +97,15 @@ public class ASTNodeSpecification<T extends IASTNode> { @SuppressWarnings("unchecked") public void visit(ASTNode astNode, IASTImageLocation imageLocation) { if (isAcceptableNode(astNode) && imageLocation != null) { - if (isMatchingRange(imageLocation.getNodeOffset(), imageLocation.getNodeLength(), fFileOffset, fFileEndOffset)) { + if (isMatchingRange(imageLocation.getNodeOffset(), imageLocation.getNodeLength(), fFileOffset, + fFileEndOffset)) { storeIfBest(imageLocation, (T) astNode); } } } private boolean isMatchingRange(int offset, int length, int selOffset, int selEndOffset) { - final int endOffset= offset + length; + final int endOffset = offset + length; switch (fRelation) { case EXACT_MATCH: return selOffset == offset && selEndOffset == endOffset; @@ -125,7 +128,7 @@ public class ASTNodeSpecification<T extends IASTNode> { return false; if (fSearchInExpansion) { - IASTNode check= astNode instanceof IASTName ? astNode.getParent() : astNode; + IASTNode check = astNode instanceof IASTName ? astNode.getParent() : astNode; if (check instanceof IASTPreprocessorMacroExpansion) { return false; } @@ -137,8 +140,8 @@ public class ASTNodeSpecification<T extends IASTNode> { * Returns whether the node can contain matches in its range. */ public boolean canContainMatches(ASTNode node) { - final int offset= node.getOffset(); - final int endOffset= offset + node.getLength(); + final int offset = node.getOffset(); + final int endOffset = offset + node.getLength(); switch (fRelation) { case EXACT_MATCH: case ENCLOSING: @@ -160,9 +163,9 @@ public class ASTNodeSpecification<T extends IASTNode> { final int offset = loc.getNodeOffset(); final int length = loc.getNodeLength(); if (isBetterMatch(offset, length, astNode)) { - fBestNode= astNode; - fBestOffset= offset; - fBestEndOffset= offset + length; + fBestNode = astNode; + fBestOffset = offset; + fBestEndOffset = offset + length; } } } @@ -176,7 +179,7 @@ public class ASTNodeSpecification<T extends IASTNode> { return true; } - final int endOffset= offset + length; + final int endOffset = offset + length; switch (fRelation) { case EXACT_MATCH: return isParent(fBestNode, cand); @@ -193,7 +196,7 @@ public class ASTNodeSpecification<T extends IASTNode> { return false; case ENCLOSING: case STRICTLY_ENCLOSING: - final int bestLength= fBestEndOffset-fBestOffset; + final int bestLength = fBestEndOffset - fBestOffset; if (length < bestLength) { return true; } @@ -209,22 +212,22 @@ public class ASTNodeSpecification<T extends IASTNode> { if (cand2 == cand1) { return true; } - cand2= cand2.getParent(); + cand2 = cand2.getParent(); } return false; } public IASTPreprocessorMacroExpansion findLeadingMacroExpansion(ASTNodeSelector nodeSelector) { - IASTPreprocessorMacroExpansion exp= - nodeSelector.findEnclosingMacroExpansion(fZeroToLeft ? fFileOffset - 1 : fFileOffset, 1); + IASTPreprocessorMacroExpansion exp = nodeSelector + .findEnclosingMacroExpansion(fZeroToLeft ? fFileOffset - 1 : fFileOffset, 1); if (fRelation == Relation.ENCLOSING || fRelation == Relation.STRICTLY_ENCLOSING) return exp; if (exp != null) { - IASTFileLocation loc= exp.getFileLocation(); + IASTFileLocation loc = exp.getFileLocation(); if (loc != null) { - final int offset= loc.getNodeOffset(); - final int endOffset= offset + loc.getNodeLength(); + final int offset = loc.getNodeOffset(); + final int endOffset = offset + loc.getNodeLength(); if (offset == fFileOffset && endOffset <= fFileEndOffset) return exp; } @@ -233,16 +236,16 @@ public class ASTNodeSpecification<T extends IASTNode> { } public IASTPreprocessorMacroExpansion findTrailingMacroExpansion(ASTNodeSelector nodeSelector) { - IASTPreprocessorMacroExpansion exp= - nodeSelector.findEnclosingMacroExpansion(fFileEndOffset == fFileOffset && !fZeroToLeft ? fFileEndOffset : fFileEndOffset - 1, 1); + IASTPreprocessorMacroExpansion exp = nodeSelector.findEnclosingMacroExpansion( + fFileEndOffset == fFileOffset && !fZeroToLeft ? fFileEndOffset : fFileEndOffset - 1, 1); if (fRelation == Relation.ENCLOSING || fRelation == Relation.STRICTLY_ENCLOSING) return exp; if (exp != null) { - IASTFileLocation loc= exp.getFileLocation(); + IASTFileLocation loc = exp.getFileLocation(); if (loc != null) { - final int offset= loc.getNodeOffset(); - final int endOffset= offset + loc.getNodeLength(); + final int offset = loc.getNodeOffset(); + final int endOffset = offset + loc.getNodeLength(); if (endOffset == fFileEndOffset && offset >= fFileOffset) return exp; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTPreprocessorSelectionResult.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTPreprocessorSelectionResult.java index a9354df40e2..e33374cee56 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTPreprocessorSelectionResult.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTPreprocessorSelectionResult.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * nodes from the preprocessor tree. * @author dsteffle */ -public class ASTPreprocessorSelectionResult { +public class ASTPreprocessorSelectionResult { IASTNode selectedNode = null; int globalOffset = 0; @@ -41,7 +41,6 @@ public class ASTPreprocessorSelectionResult { return globalOffset; } - public void setGlobalOffset(int globalOffset) { this.globalOffset = globalOffset; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java index 91ef671d2bb..6e1db9ca820 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java @@ -30,102 +30,102 @@ import com.ibm.icu.text.MessageFormat; * Models problems, all problems should derive from this class. */ public class ASTProblem extends ASTNode implements IASTProblem { - protected static final Map<Integer, String> errorMessages; - static { - errorMessages = new HashMap<Integer, String>(); - errorMessages.put(Integer.valueOf(PREPROCESSOR_POUND_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_POUND_WARNING), - ParserMessages.getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_INCLUSION_NOT_FOUND), - ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_DEFINITION_NOT_FOUND), - ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_MACRO_DEFN), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_MACRO_REDEFN), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_UNBALANCE_CONDITION), - ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_CONDITIONAL_EVAL_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_MACRO_USAGE_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_CIRCULAR_INCLUSION), - ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_DIRECTIVE), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_MACRO_PASTING_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_MISSING_RPAREN_PARMLIST), - ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_VA_ARGS), - ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_INVALID_ESCAPECHAR), - ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_UNBOUNDED_STRING), - ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_FLOATING_POINT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_BINARY_FORMAT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badBinaryFormat")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_HEX_FORMAT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_OCTAL_FORMAT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_DECIMAL_FORMAT), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_ASSIGNMENT_NOT_ALLOWED), - ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_DIVIDE_BY_ZERO), - ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_MISSING_R_PAREN), - ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_EXPRESSION_SYNTAX_ERROR), - ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_ILLEGAL_IDENTIFIER), - ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_CONDITIONAL_EXPRESSION), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_UNEXPECTED_EOF), - ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_BAD_CHARACTER), - ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_CONSTANT_WITH_BAD_SUFFIX), - ParserMessages.getString("ScannerProblemFactory.error.scanner.constantWithBadSuffix")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SCANNER_FLOAT_WITH_BAD_PREFIX), - ParserMessages.getString("ScannerProblemFactory.error.scanner.floatWithBadPrefix")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(PREPROCESSOR_MULTIPLE_USER_DEFINED_SUFFIXES_IN_CONCATENATION), - ParserMessages.getString("ScannerProblemFactory.error.preproc.multipleUserDefinedLiteralSuffixesOnStringLiteral")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(SYNTAX_ERROR), - ParserMessages.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(MISSING_SEMICOLON), - ParserMessages.getString("ParserProblemFactory.error.syntax.missingSemicolon")); //$NON-NLS-1$ - errorMessages.put(Integer.valueOf(TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT_EXCEEDED), - ParserMessages.getString("ParserProblemFactory.error.syntax.templateArgumentNestingDepthLimitExceeded")); //$NON-NLS-1$ - } - - private final int id; - private final char[] arg; + protected static final Map<Integer, String> errorMessages; + static { + errorMessages = new HashMap<Integer, String>(); + errorMessages.put(Integer.valueOf(PREPROCESSOR_POUND_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_POUND_WARNING), + ParserMessages.getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_INCLUSION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_DEFINITION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_MACRO_DEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_MACRO_REDEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_UNBALANCE_CONDITION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_CONDITIONAL_EVAL_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_MACRO_USAGE_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_CIRCULAR_INCLUSION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_DIRECTIVE), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_MACRO_PASTING_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_MISSING_RPAREN_PARMLIST), + ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_INVALID_VA_ARGS), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_INVALID_ESCAPECHAR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_UNBOUNDED_STRING), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_FLOATING_POINT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_BINARY_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badBinaryFormat")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_HEX_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_OCTAL_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_DECIMAL_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_ASSIGNMENT_NOT_ALLOWED), + ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_DIVIDE_BY_ZERO), + ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_MISSING_R_PAREN), + ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_EXPRESSION_SYNTAX_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_ILLEGAL_IDENTIFIER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_CONDITIONAL_EXPRESSION), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_UNEXPECTED_EOF), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_BAD_CHARACTER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_CONSTANT_WITH_BAD_SUFFIX), + ParserMessages.getString("ScannerProblemFactory.error.scanner.constantWithBadSuffix")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SCANNER_FLOAT_WITH_BAD_PREFIX), + ParserMessages.getString("ScannerProblemFactory.error.scanner.floatWithBadPrefix")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(PREPROCESSOR_MULTIPLE_USER_DEFINED_SUFFIXES_IN_CONCATENATION), ParserMessages + .getString("ScannerProblemFactory.error.preproc.multipleUserDefinedLiteralSuffixesOnStringLiteral")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(SYNTAX_ERROR), + ParserMessages.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(MISSING_SEMICOLON), + ParserMessages.getString("ParserProblemFactory.error.syntax.missingSemicolon")); //$NON-NLS-1$ + errorMessages.put(Integer.valueOf(TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT_EXCEEDED), ParserMessages + .getString("ParserProblemFactory.error.syntax.templateArgumentNestingDepthLimitExceeded")); //$NON-NLS-1$ + } + + private final int id; + private final char[] arg; private boolean isError; private IASTProblem originalProblem = null; - public ASTProblem(IASTNode parent, ASTNodeProperty property, int id, char[] arg, boolean isError, - int startNumber, int endNumber) { + public ASTProblem(IASTNode parent, ASTNodeProperty property, int id, char[] arg, boolean isError, int startNumber, + int endNumber) { setParent(parent); setPropertyInParent(property); setOffset(startNumber); - setLength(endNumber-startNumber); + setLength(endNumber - startNumber); - this.id = id; - this.arg = arg; - this.isError= isError; - } + this.id = id; + this.arg = arg; + this.isError = isError; + } public ASTProblem(int id, char[] arg, boolean isError) { - this.id = id; - this.arg = arg; - this.isError= isError; + this.id = id; + this.arg = arg; + this.isError = isError; } @Override @@ -141,65 +141,65 @@ public class ASTProblem extends ASTNode implements IASTProblem { @Override public int getID() { - return id; - } + return id; + } - @Override + @Override public boolean isError() { - return isError; - } + return isError; + } - @Override + @Override public boolean isWarning() { - return !isError; - } + return !isError; + } - @Override + @Override public String getMessageWithLocation() { - String msg= getMessage(); - - char[] file= getOriginatingFileName(); - int line= getSourceLineNumber(); - Object[] args = new Object[] { msg, new String(file), Integer.valueOf(line) }; - return ParserMessages.getFormattedString("BaseProblemFactory.problemPattern", args); //$NON-NLS-1$ - } - - private static String getMessage(int id, String arg, IASTProblem originalProblem) { - String msg = errorMessages.get(Integer.valueOf(id)); - if (msg == null) - msg = ""; //$NON-NLS-1$ - - if (arg != null) { - msg = MessageFormat.format(msg, new Object[] {arg}); - } - if (originalProblem != null) { - msg = MessageFormat.format("{0}: {1}", msg, originalProblem.getMessage()); //$NON-NLS-1$ - } - return msg; - } - - public static String getMessage(int id, String arg) { - return getMessage(id, arg, null); - } - - @Override + String msg = getMessage(); + + char[] file = getOriginatingFileName(); + int line = getSourceLineNumber(); + Object[] args = new Object[] { msg, new String(file), Integer.valueOf(line) }; + return ParserMessages.getFormattedString("BaseProblemFactory.problemPattern", args); //$NON-NLS-1$ + } + + private static String getMessage(int id, String arg, IASTProblem originalProblem) { + String msg = errorMessages.get(Integer.valueOf(id)); + if (msg == null) + msg = ""; //$NON-NLS-1$ + + if (arg != null) { + msg = MessageFormat.format(msg, new Object[] { arg }); + } + if (originalProblem != null) { + msg = MessageFormat.format("{0}: {1}", msg, originalProblem.getMessage()); //$NON-NLS-1$ + } + return msg; + } + + public static String getMessage(int id, String arg) { + return getMessage(id, arg, null); + } + + @Override public String getMessage() { - return getMessage(id, arg == null ? null : new String(arg), originalProblem); - } + return getMessage(id, arg == null ? null : new String(arg), originalProblem); + } - @Override + @Override public boolean checkCategory(int bitmask) { - return (id & bitmask) != 0; - } + return (id & bitmask) != 0; + } - @Override + @Override public String[] getArguments() { - return arg == null ? new String[0] : new String[] { new String(arg) }; - } + return arg == null ? new String[0] : new String[] { new String(arg) }; + } - public char[] getArgument() { - return arg; - } + public char[] getArgument() { + return arg; + } @Override public char[] getOriginatingFileName() { @@ -208,7 +208,7 @@ public class ASTProblem extends ASTNode implements IASTProblem { @Override public int getSourceEnd() { - final IASTFileLocation location= getFileLocation(); + final IASTFileLocation location = getFileLocation(); if (location != null) { return location.getNodeOffset() + location.getNodeLength() - 1; } @@ -217,7 +217,7 @@ public class ASTProblem extends ASTNode implements IASTProblem { @Override public int getSourceLineNumber() { - final IASTFileLocation location= getFileLocation(); + final IASTFileLocation location = getFileLocation(); if (location != null) { return location.getStartingLineNumber(); } @@ -226,15 +226,13 @@ public class ASTProblem extends ASTNode implements IASTProblem { @Override public int getSourceStart() { - final IASTFileLocation location= getFileLocation(); + final IASTFileLocation location = getFileLocation(); if (location != null) { return location.getNodeOffset(); } return INT_VALUE_NOT_PROVIDED; } - - @Override public IASTProblem getOriginalProblem() { return originalProblem; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java index da09e581987..e0e4cfd5410 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java @@ -44,12 +44,12 @@ public class ASTQueries { NameSearch() { super(false); - shouldVisitAmbiguousNodes= true; - shouldVisitNames= true; + shouldVisitAmbiguousNodes = true; + shouldVisitNames = true; } public void reset() { - fFound= false; + fFound = false; } public boolean foundName() { @@ -58,13 +58,13 @@ public class ASTQueries { @Override public int visit(IASTName name) { - fFound= true; + fFound = true; return PROCESS_ABORT; } @Override public int visit(ASTAmbiguousNode node) { - IASTNode[] alternatives= node.getNodes(); + IASTNode[] alternatives = node.getNodes(); for (IASTNode alt : alternatives) { if (!alt.accept(this)) return PROCESS_ABORT; @@ -72,7 +72,8 @@ public class ASTQueries { return PROCESS_CONTINUE; } } - private static NameSearch NAME_SEARCH= new NameSearch(); + + private static NameSearch NAME_SEARCH = new NameSearch(); /** * Tests whether the given node can contain ast-names, suitable to be used before ambiguity @@ -92,11 +93,11 @@ public class ASTQueries { * the given {@code declarator} itself. */ public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) { - IASTDeclarator outermost= null; - IASTNode candidate= declarator; + IASTDeclarator outermost = null; + IASTNode candidate = declarator; while (candidate instanceof IASTDeclarator) { - outermost= (IASTDeclarator) candidate; - candidate= outermost.getParent(); + outermost = (IASTDeclarator) candidate; + candidate = outermost.getParent(); } return outermost; } @@ -106,10 +107,10 @@ public class ASTQueries { * the given {@code declarator} itself. */ public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) { - IASTDeclarator innermost= null; + IASTDeclarator innermost = null; while (declarator != null) { - innermost= declarator; - declarator= declarator.getNestedDeclarator(); + innermost = declarator; + declarator = declarator.getNestedDeclarator(); } return innermost; } @@ -121,14 +122,12 @@ public class ASTQueries { if (declarator == null) return null; - IASTDeclarator result= findInnermostDeclarator(declarator); - while (result.getPointerOperators().length == 0 - && !(result instanceof IASTFieldDeclarator) - && !(result instanceof IASTFunctionDeclarator) - && !(result instanceof IASTArrayDeclarator)) { - final IASTNode parent= result.getParent(); + IASTDeclarator result = findInnermostDeclarator(declarator); + while (result.getPointerOperators().length == 0 && !(result instanceof IASTFieldDeclarator) + && !(result instanceof IASTFunctionDeclarator) && !(result instanceof IASTArrayDeclarator)) { + final IASTNode parent = result.getParent(); if (parent instanceof IASTDeclarator) { - result= (IASTDeclarator) parent; + result = (IASTDeclarator) parent; } else { return result; } @@ -159,9 +158,9 @@ public class ASTQueries { if (functionDefinition == null) return null; - IASTDeclarator dtor= findInnermostDeclarator(functionDefinition.getDeclarator()); + IASTDeclarator dtor = findInnermostDeclarator(functionDefinition.getDeclarator()); if (dtor != null) { - IASTName name= dtor.getName(); + IASTName name = dtor.getName(); if (name != null) { return name.resolveBinding(); } @@ -175,17 +174,17 @@ public class ASTQueries { public static IASTDeclaration[] extractActiveDeclarations(IASTDeclaration[] allDeclarations, int size) { IASTDeclaration[] active; if (size == 0) { - active= IASTDeclaration.EMPTY_DECLARATION_ARRAY; + active = IASTDeclaration.EMPTY_DECLARATION_ARRAY; } else { - active= new IASTDeclaration[size]; - int j= 0; + active = new IASTDeclaration[size]; + int j = 0; for (int i = 0; i < size; i++) { - IASTDeclaration d= allDeclarations[i]; + IASTDeclaration d = allDeclarations[i]; if (d.isActive()) { - active[j++]= d; + active[j++] = d; } } - active= ArrayUtil.trim(active, j); + active = ArrayUtil.trim(active, j); } return active; } @@ -232,51 +231,49 @@ public class ASTQueries { } private static class FindLabelsAction extends ASTVisitor { - public IASTLabelStatement[] labels = IASTLabelStatement.EMPTY_ARRAY; + public IASTLabelStatement[] labels = IASTLabelStatement.EMPTY_ARRAY; - public FindLabelsAction() { - shouldVisitStatements = true; - } + public FindLabelsAction() { + shouldVisitStatements = true; + } - @Override + @Override public int visit(IASTStatement statement) { - if (statement instanceof IASTLabelStatement) { - labels = ArrayUtil.append(labels, (IASTLabelStatement) statement); - } - return PROCESS_CONTINUE; - } + if (statement instanceof IASTLabelStatement) { + labels = ArrayUtil.append(labels, (IASTLabelStatement) statement); + } + return PROCESS_CONTINUE; + } } protected static ILabel[] getLabels(IASTFunctionDefinition functionDefinition) { - FindLabelsAction action = new FindLabelsAction(); + FindLabelsAction action = new FindLabelsAction(); - functionDefinition.accept(action); + functionDefinition.accept(action); - ILabel[] result = ILabel.EMPTY_ARRAY; - if (action.labels != null) { - for (int i = 0; i < action.labels.length && action.labels[i] != null; i++) { - IASTLabelStatement labelStatement = action.labels[i]; - IBinding binding = labelStatement.getName().resolveBinding(); - if (binding != null) - result = ArrayUtil.append(result, (ILabel) binding); - } - } - return ArrayUtil.trim(result); + ILabel[] result = ILabel.EMPTY_ARRAY; + if (action.labels != null) { + for (int i = 0; i < action.labels.length && action.labels[i] != null; i++) { + IASTLabelStatement labelStatement = action.labels[i]; + IBinding binding = labelStatement.getName().resolveBinding(); + if (binding != null) + result = ArrayUtil.append(result, (ILabel) binding); + } + } + return ArrayUtil.trim(result); } protected static IBinding resolveLabel(IASTName labelReference) { char[] labelName = labelReference.toCharArray(); - IASTFunctionDefinition functionDefinition = - findAncestorWithType(labelReference, IASTFunctionDefinition.class); + IASTFunctionDefinition functionDefinition = findAncestorWithType(labelReference, IASTFunctionDefinition.class); if (functionDefinition != null) { - for (ILabel label : getLabels(functionDefinition)) { - if (CharArrayUtils.equals(label.getNameCharArray(), labelName)) { - return label; - } - } + for (ILabel label : getLabels(functionDefinition)) { + if (CharArrayUtils.equals(label.getNameCharArray(), labelName)) { + return label; + } + } } - // Label not found. - return new ProblemBinding(labelReference, IProblemBinding.SEMANTIC_LABEL_STATEMENT_NOT_FOUND, - labelName); + // Label not found. + return new ProblemBinding(labelReference, IProblemBinding.SEMANTIC_LABEL_STATEMENT_NOT_FOUND, labelName); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java index f14cf47ccf2..3f4ad2906f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTToken; * Represents a code token. */ public class ASTToken extends ASTNode implements IASTToken { - private final int tokenType; + private final int tokenType; private final char[] tokenImage; public ASTToken(int tokenType, char[] tokenImage) { @@ -50,21 +50,27 @@ public class ASTToken extends ASTNode implements IASTToken { @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitTokens) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTokens) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitTokens) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTokens) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java index f894f0d0420..fe4c2bddd8a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java @@ -22,7 +22,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; * Represents a sequence of code tokens. */ public class ASTTokenList extends ASTNode implements IASTTokenList { - private IASTToken[] tokens = IASTToken.EMPTY_TOKEN_ARRAY; + private IASTToken[] tokens = IASTToken.EMPTY_TOKEN_ARRAY; public ASTTokenList() { } @@ -68,23 +68,27 @@ public class ASTTokenList extends ASTNode implements IASTTokenList { @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitTokens) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTokens) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } for (IASTToken token : tokens) { if (token == null) break; - if (!token.accept(action)) return false; + if (!token.accept(action)) + return false; } - if (action.shouldVisitTokens && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (action.shouldVisitTokens && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java index 6943c0dc757..80a20e97e75 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java @@ -73,53 +73,52 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = {}; private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private IASTDeclaration[] fAllDeclarations; - private IASTDeclaration[] fActiveDeclarations; - private int fLastDeclaration= -1; + private IASTDeclaration[] fAllDeclarations; + private IASTDeclaration[] fActiveDeclarations; + private int fLastDeclaration = -1; protected ILocationResolver fLocationResolver; private IIndex fIndex; - private boolean fIsHeader= true; + private boolean fIsHeader = true; private IIndexFileSet fIndexFileSet; private IIndexFileSet fASTFileSet; private INodeFactory fNodeFactory; private boolean fForContentAssist; private ITranslationUnit fOriginatingTranslationUnit; - private ISignificantMacros fSignificantMacros= ISignificantMacros.NONE; + private ISignificantMacros fSignificantMacros = ISignificantMacros.NONE; private boolean fPragmaOnceSemantics; private SizeofCalculator fSizeofCalculator; /** The semaphore controlling exclusive access to the AST. */ - private final Semaphore fSemaphore= new Semaphore(1); + private final Semaphore fSemaphore = new Semaphore(1); private boolean fBasedOnIncompleteIndex; private boolean fNodesOmitted; private IBuiltinBindingsProvider fBuiltinBindingsProvider; - + // Caches private final WeakHashMap<IType, String> fUnnormalizedTypeStringCache = new WeakHashMap<>(); private final WeakHashMap<IType, String> fNormalizedTypeStringCache = new WeakHashMap<>(); @Override public final IASTTranslationUnit getTranslationUnit() { - return this; - } + return this; + } @Override public final void addDeclaration(IASTDeclaration d) { if (d != null) { d.setParent(this); d.setPropertyInParent(OWNED_DECLARATION); - fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, - fAllDeclarations, ++fLastDeclaration, d); - fActiveDeclarations= null; + fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, d); + fActiveDeclarations = null; } } @Override public final IASTDeclaration[] getDeclarations() { - IASTDeclaration[] active= fActiveDeclarations; + IASTDeclaration[] active = fActiveDeclarations; if (active == null) { - active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fLastDeclaration+1); - fActiveDeclarations= active; + active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fLastDeclaration + 1); + fActiveDeclarations = active; } return active; } @@ -127,8 +126,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat @Override public final IASTDeclaration[] getDeclarations(boolean includeInactive) { if (includeInactive) { - fAllDeclarations= ArrayUtil.trimAt(IASTDeclaration.class, - fAllDeclarations, fLastDeclaration); + fAllDeclarations = ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration); return fAllDeclarations; } return getDeclarations(); @@ -141,7 +139,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); fAllDeclarations[i] = (IASTDeclaration) other; - fActiveDeclarations= null; + fActiveDeclarations = null; return; } } @@ -149,15 +147,15 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat @Override public final IName[] getDeclarations(IBinding binding) { - IName[] names= getDeclarationsInAST(binding); - if (names.length == 0 && fIndex != null) { - try { - names = fIndex.findDeclarations(binding); - } catch (CoreException e) { - CCorePlugin.log(e); - return names; - } - } + IName[] names = getDeclarationsInAST(binding); + if (names.length == 0 && fIndex != null) { + try { + names = fIndex.findDeclarations(binding); + } catch (CoreException e) { + CCorePlugin.log(e); + return names; + } + } return names; } @@ -182,22 +180,22 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat protected final IASTName[] getMacroReferencesInAST(IMacroBinding binding) { if (fLocationResolver == null) return IASTName.EMPTY_NAME_ARRAY; - return fLocationResolver.getReferences(binding); - } + return fLocationResolver.getReferences(binding); + } - @Override + @Override public final IName[] getDefinitions(IBinding binding) { - IName[] names= getDefinitionsInAST(binding); - if (names.length == 0 && fIndex != null) { - try { - names= fIndex.findDefinitions(binding); - } catch (CoreException e) { - CCorePlugin.log(e); - return names; - } - } - return names; - } + IName[] names = getDefinitionsInAST(binding); + if (names.length == 0 && fIndex != null) { + try { + names = fIndex.findDefinitions(binding); + } catch (CoreException e) { + CCorePlugin.log(e); + return names; + } + } + return names; + } @Override public final IASTPreprocessorMacroDefinition[] getMacroDefinitions() { @@ -235,8 +233,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat } public final void setLocationResolver(ILocationResolver resolver) { - fLocationResolver= resolver; - resolver.setRootNode(this); + fLocationResolver = resolver; + resolver.setRootNode(this); } @Override @@ -268,35 +266,39 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat public final boolean accept(ASTVisitor action) { if (action.shouldVisitTranslationUnit) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } IASTDeclaration[] decls = getDeclarations(action.includeInactiveNodes); for (IASTDeclaration decl : decls) { - if (!decl.accept(action)) return false; + if (!decl.accept(action)) + return false; } - if (action.shouldVisitTranslationUnit && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (action.shouldVisitTranslationUnit && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; - return true; - } + return true; + } @Override public final IASTFileLocation flattenLocationsToFile(IASTNodeLocation[] nodeLocations) { - if (fLocationResolver == null) - return null; - return fLocationResolver.flattenLocations(nodeLocations); - } + if (fLocationResolver == null) + return null; + return fLocationResolver.flattenLocations(nodeLocations); + } - @Override + @Override public final IDependencyTree getDependencyTree() { - if (fLocationResolver == null) - return null; - return fLocationResolver.getDependencyTree(); - } + if (fLocationResolver == null) + return null; + return fLocationResolver.getDependencyTree(); + } @Override public final String getContainingFilename(int offset) { @@ -305,28 +307,28 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat return fLocationResolver.getContainingFilePath(offset); } - @Override + @Override public final IIndex getIndex() { - return fIndex; - } + return fIndex; + } - @Override + @Override public final void setIndex(IIndex index) { - this.fIndex = index; - if (index != null) { - fIndexFileSet= index.createFileSet(); - fASTFileSet= index.createFileSet(); - } - } - - @Override + this.fIndex = index; + if (index != null) { + fIndexFileSet = index.createFileSet(); + fASTFileSet = index.createFileSet(); + } + } + + @Override public final INodeFactory getASTNodeFactory() { - return fNodeFactory; - } + return fNodeFactory; + } - public final void setASTNodeFactory(INodeFactory nodeFactory) { - this.fNodeFactory = nodeFactory; - } + public final void setASTNodeFactory(INodeFactory nodeFactory) { + this.fNodeFactory = nodeFactory; + } @Override public final IASTComment[] getComments() { @@ -358,7 +360,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat @Override public final void setIsHeaderUnit(boolean headerUnit) { - fIsHeader= headerUnit; + fIsHeader = headerUnit; } public boolean isForContentAssist() { @@ -366,7 +368,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat } public final void setIsForContentAssist(boolean forContentAssist) { - fForContentAssist= forContentAssist; + fForContentAssist = forContentAssist; } @Override @@ -381,7 +383,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat @Override public void skippedFile(int offset, InternalFileContent fileContent) { if (fIndexFileSet != null) { - List<IIndexFile> files= fileContent.getFilesIncluded(); + List<IIndexFile> files = fileContent.getFilesIncluded(); for (IIndexFile indexFile : files) { fASTFileSet.remove(indexFile); fIndexFileSet.add(indexFile); @@ -473,10 +475,10 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat }); if (IndexFileSet.sDEBUG && fIndexFileSet != null && fASTFileSet != null) { - long t = ((IndexFileSet) fIndexFileSet).getTimingContainsDeclarationNanos() + - ((IndexFileSet) fASTFileSet).getTimingContainsDeclarationNanos(); - String forName = fOriginatingTranslationUnit == null ? - "" : " for " + fOriginatingTranslationUnit.getElementName(); //$NON-NLS-1$ //$NON-NLS-2$ + long t = ((IndexFileSet) fIndexFileSet).getTimingContainsDeclarationNanos() + + ((IndexFileSet) fASTFileSet).getTimingContainsDeclarationNanos(); + String forName = fOriginatingTranslationUnit == null ? "" //$NON-NLS-1$ + : " for " + fOriginatingTranslationUnit.getElementName(); //$NON-NLS-1$ System.out.println(String.format("IndexFileSet.containsDeclaration%s took %.2g ms", forName, t / 1.e6)); //$NON-NLS-1$ } } @@ -499,7 +501,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat public void setSignificantMacros(ISignificantMacros sigMacros) { assertNotFrozen(); if (sigMacros != null) - fSignificantMacros= sigMacros; + fSignificantMacros = sigMacros; } @Override @@ -510,13 +512,13 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat @Override public void setPragmaOnceSemantics(boolean value) { assertNotFrozen(); - fPragmaOnceSemantics= value; + fPragmaOnceSemantics = value; } /** * Starts exclusive access. * - * @throws InterruptedException if the current thread is interrupted + * @throws InterruptedException if the current thread is interrupted */ public void beginExclusiveAccess() throws InterruptedException { fSemaphore.acquire(); @@ -525,10 +527,10 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat /** * Starts exclusive access. * - * @param timeoutMillis the maximum time to wait in milliseconds - * @return {@code true} if exclusive access was acquired, or {@code false} if it - * was not possible to acquire exclusive access before the timeout expired - * @throws InterruptedException if the current thread is interrupted + * @param timeoutMillis the maximum time to wait in milliseconds + * @return {@code true} if exclusive access was acquired, or {@code false} if it + * was not possible to acquire exclusive access before the timeout expired + * @throws InterruptedException if the current thread is interrupted */ public boolean tryBeginExclusiveAccess(long timeoutMillis) throws InterruptedException { return fSemaphore.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS); @@ -560,8 +562,9 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat * If ambiguity resolution is in progress, and processing of 'node' has been deferred, * process it now. Has no effect if ambiguity resolution is not in progress. */ - public void resolvePendingAmbiguities(IASTNode node) {} - + public void resolvePendingAmbiguities(IASTNode node) { + } + public void setupBuiltinBindings(IBuiltinBindingsProvider builtinBindingsProvider) { IScope tuScope = getScope(); @@ -569,18 +572,18 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat for (IBinding binding : bindings) { ASTInternal.addBinding(tuScope, binding); } - + // Save the builtin bindings provider for later use by isKnownBuiltin(). fBuiltinBindingsProvider = builtinBindingsProvider; } - + public boolean isKnownBuiltin(char[] builtinName) { if (fBuiltinBindingsProvider != null) { return fBuiltinBindingsProvider.isKnownBuiltin(builtinName); } return false; } - + public Map<IType, String> getTypeStringCache(boolean normalized) { return normalized ? fNormalizedTypeStringCache : fUnnormalizedTypeStringCache; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index c1ab164eb72..b80211fb166 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -114,45 +114,47 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected static class FoundAggregateInitializer extends Exception { public final IASTDeclarator fDeclarator; public final IASTDeclSpecifier fDeclSpec; + public FoundAggregateInitializer(IASTDeclSpecifier declSpec, IASTDeclarator d) { - fDeclSpec= declSpec; - fDeclarator= d; + fDeclSpec = declSpec; + fDeclarator = d; } } - protected static class Decl { - public Decl() { - } + protected static class Decl { + public Decl() { + } - public IASTDeclSpecifier fDeclSpec1; + public IASTDeclSpecifier fDeclSpec1; public IASTDeclSpecifier fDeclSpec2; public IASTDeclarator fDtor1; public IASTDeclarator fDtor2; - public IToken fDtorToken1; - - public Decl set(IASTDeclSpecifier declspec, IASTDeclarator dtor, IToken dtorToken) { - fDeclSpec1= declspec; - fDtor1= dtor; - fDtorToken1= dtorToken; - fDeclSpec2= null; - fDtor2= null; + public IToken fDtorToken1; + + public Decl set(IASTDeclSpecifier declspec, IASTDeclarator dtor, IToken dtorToken) { + fDeclSpec1 = declspec; + fDtor1 = dtor; + fDtorToken1 = dtorToken; + fDeclSpec2 = null; + fDtor2 = null; return this; } - public Decl set(IASTDeclSpecifier declspec1, IASTDeclarator dtor1, IASTDeclSpecifier declspec2, IASTDeclarator dtor2) { - fDeclSpec1= declspec1; - fDtor1= dtor1; - fDtorToken1= null; - fDeclSpec2= declspec2; - fDtor2= dtor2; + public Decl set(IASTDeclSpecifier declspec1, IASTDeclarator dtor1, IASTDeclSpecifier declspec2, + IASTDeclarator dtor2) { + fDeclSpec1 = declspec1; + fDtor1 = dtor1; + fDtorToken1 = null; + fDeclSpec2 = declspec2; + fDtor2 = dtor2; return this; } - } + } private static final ASTVisitor MARK_INACTIVE = new ASTGenericVisitor(true) { { - shouldVisitAmbiguousNodes= true; + shouldVisitAmbiguousNodes = true; } @Override @@ -164,7 +166,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { @Override public int visit(ASTAmbiguousNode node) { node.setInactive(); - IASTNode[] alternatives= node.getNodes(); + IASTNode[] alternatives = node.getNodes(); for (IASTNode alt : alternatives) { if (!alt.accept(this)) return PROCESS_ABORT; @@ -177,201 +179,201 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * Information about the context in which a cast-expression is parsed: * in a binary expression, in a binary expression in a template-id, or elsewhere. */ - protected static enum CastExprCtx {eDirectlyInBExpr, eInBExpr, eNotInBExpr} - protected static enum ExprKind {eExpression, eAssignment, eConstant} + protected static enum CastExprCtx { + eDirectlyInBExpr, eInBExpr, eNotInBExpr + } + + protected static enum ExprKind { + eExpression, eAssignment, eConstant + } protected static final int DEFAULT_DESIGNATOR_LIST_SIZE = 4; protected final AbstractParserLogService log; - protected final IScanner scanner; - protected final ParserMode mode; - - protected final boolean supportStatementsInExpressions; - protected final boolean supportTypeOfUnaries; - protected final boolean supportAlignOfUnaries; - protected final boolean supportKnRC; - protected final boolean supportAttributeSpecifiers; - protected final boolean supportDeclspecSpecifiers; - protected boolean supportParameterInfoBlock; - protected boolean supportFunctionStyleAsm; - protected boolean supportExtendedSizeofOperator; - protected final IBuiltinBindingsProvider builtinBindingsProvider; - - protected boolean functionCallCanBeLValue; - protected int maximumTrivialExpressionsInAggregateInitializers= Integer.MAX_VALUE; - - /** - * Marks the beginning of the current declaration. It is important to clear the mark whenever we - * enter a nested declaration, in order to avoid holding on to all the tokens. - */ - protected IToken declarationMark; - protected IToken nextToken; - protected IToken lastToken; - protected IToken lastTokenFromScanner; - - protected boolean isCancelled = false; + protected final IScanner scanner; + protected final ParserMode mode; + + protected final boolean supportStatementsInExpressions; + protected final boolean supportTypeOfUnaries; + protected final boolean supportAlignOfUnaries; + protected final boolean supportKnRC; + protected final boolean supportAttributeSpecifiers; + protected final boolean supportDeclspecSpecifiers; + protected boolean supportParameterInfoBlock; + protected boolean supportFunctionStyleAsm; + protected boolean supportExtendedSizeofOperator; + protected final IBuiltinBindingsProvider builtinBindingsProvider; + + protected boolean functionCallCanBeLValue; + protected int maximumTrivialExpressionsInAggregateInitializers = Integer.MAX_VALUE; + + /** + * Marks the beginning of the current declaration. It is important to clear the mark whenever we + * enter a nested declaration, in order to avoid holding on to all the tokens. + */ + protected IToken declarationMark; + protected IToken nextToken; + protected IToken lastToken; + protected IToken lastTokenFromScanner; + + protected boolean isCancelled = false; protected boolean parsePassed = true; - protected int backtrackCount = 0; - protected BacktrackException backtrack = new BacktrackException(); - - protected ASTCompletionNode completionNode; - - private final INodeFactory nodeFactory; - private boolean fActiveCode= true; - - protected AbstractGNUSourceCodeParser(IScanner scanner, - IParserLogService logService, ParserMode parserMode, - INodeFactory nodeFactory, - boolean supportStatementsInExpressions, - boolean supportTypeOfUnaries, boolean supportAlignOfUnaries, - boolean supportKnRC, boolean supportAttributeSpecifiers, - boolean supportDeclspecSpecifiers, - IBuiltinBindingsProvider builtinBindingsProvider) { - this.scanner = scanner; - this.log = wrapLogService(logService); - this.mode = parserMode; - this.supportStatementsInExpressions = supportStatementsInExpressions; - this.supportTypeOfUnaries = supportTypeOfUnaries; - this.supportAlignOfUnaries = supportAlignOfUnaries; - this.supportKnRC = supportKnRC; - this.supportAttributeSpecifiers = supportAttributeSpecifiers; - this.supportDeclspecSpecifiers = supportDeclspecSpecifiers; - this.builtinBindingsProvider= builtinBindingsProvider; - this.nodeFactory = nodeFactory; - } + protected int backtrackCount = 0; + protected BacktrackException backtrack = new BacktrackException(); + + protected ASTCompletionNode completionNode; + + private final INodeFactory nodeFactory; + private boolean fActiveCode = true; + + protected AbstractGNUSourceCodeParser(IScanner scanner, IParserLogService logService, ParserMode parserMode, + INodeFactory nodeFactory, boolean supportStatementsInExpressions, boolean supportTypeOfUnaries, + boolean supportAlignOfUnaries, boolean supportKnRC, boolean supportAttributeSpecifiers, + boolean supportDeclspecSpecifiers, IBuiltinBindingsProvider builtinBindingsProvider) { + this.scanner = scanner; + this.log = wrapLogService(logService); + this.mode = parserMode; + this.supportStatementsInExpressions = supportStatementsInExpressions; + this.supportTypeOfUnaries = supportTypeOfUnaries; + this.supportAlignOfUnaries = supportAlignOfUnaries; + this.supportKnRC = supportKnRC; + this.supportAttributeSpecifiers = supportAttributeSpecifiers; + this.supportDeclspecSpecifiers = supportDeclspecSpecifiers; + this.builtinBindingsProvider = builtinBindingsProvider; + this.nodeFactory = nodeFactory; + } /** * Instructs the parser not to create AST nodes for expressions within aggregate initializers * when they do not contain names beyond the given limit. */ public void setMaximumTrivialExpressionsInAggregateInitializers(int limit) { - maximumTrivialExpressionsInAggregateInitializers= limit; + maximumTrivialExpressionsInAggregateInitializers = limit; } - private AbstractParserLogService wrapLogService(IParserLogService logService) { + private AbstractParserLogService wrapLogService(IParserLogService logService) { if (logService instanceof AbstractParserLogService) { return (AbstractParserLogService) logService; } return new ParserLogServiceWrapper(logService); } - protected final void throwBacktrack(int offset, int length) throws BacktrackException { - ++backtrackCount; - backtrack.initialize(offset, length < 0 ? 0 : length); - throw backtrack; - } + protected final void throwBacktrack(int offset, int length) throws BacktrackException { + ++backtrackCount; + backtrack.initialize(offset, length < 0 ? 0 : length); + throw backtrack; + } - protected INodeFactory getNodeFactory() { - return nodeFactory; - } + protected INodeFactory getNodeFactory() { + return nodeFactory; + } - @Override + @Override public IASTCompletionNode getCompletionNode() { - return completionNode; - } - - // Use to create the completion node - protected ASTCompletionNode createCompletionNode(IToken token) { - // the preprocessor may deliver tokens for literals or header-names. - if (completionNode == null && token != null && token.getType() == IToken.tCOMPLETION) { - completionNode = new ASTCompletionNode(token, getTranslationUnit()); - } - return completionNode; - } - - /** - * Fetches the next token from the scanner. - */ - private final IToken fetchToken(boolean skipInactive) throws EndOfFileException { - try { - IToken t= scanner.nextToken(); - if (skipInactive) { - while (t.getType() == IToken.tINACTIVE_CODE_START) { - scanner.skipInactiveCode(); - t= scanner.nextToken(); - } - } - if (lastTokenFromScanner != null) - lastTokenFromScanner.setNext(t); - lastTokenFromScanner= t; - return t; - } catch (OffsetLimitReachedException olre) { - if (mode != ParserMode.COMPLETION_PARSE) - throw new EndOfFileException(olre.getEndOffset()); - IToken completionToken = olre.getFinalToken(); - createCompletionNode(completionToken); - if (olre.getOriginator() == OffsetLimitReachedException.ORIGIN_INACTIVE_CODE) { - // If completion is invoked inside inactive code, there is no AST from which - // to give the completion node a completion name, so we invent a name. - // The invented name is not hooked up to the AST, but does have an offset - // and length, so it can provide an accurate point of reference in - // declaredBefore(). - IASTName completionName = nodeFactory.newInactiveCompletionName( - completionToken.getCharImage(), getTranslationUnit()); - ((ASTNode) completionName).setOffsetAndLength(completionToken.getOffset(), - completionToken.getLength()); - completionNode.addName(completionName); - - // Consume the completion token so we don't try to parse an AST fragment from it. - consume(); - } + return completionNode; + } + + // Use to create the completion node + protected ASTCompletionNode createCompletionNode(IToken token) { + // the preprocessor may deliver tokens for literals or header-names. + if (completionNode == null && token != null && token.getType() == IToken.tCOMPLETION) { + completionNode = new ASTCompletionNode(token, getTranslationUnit()); + } + return completionNode; + } + + /** + * Fetches the next token from the scanner. + */ + private final IToken fetchToken(boolean skipInactive) throws EndOfFileException { + try { + IToken t = scanner.nextToken(); + if (skipInactive) { + while (t.getType() == IToken.tINACTIVE_CODE_START) { + scanner.skipInactiveCode(); + t = scanner.nextToken(); + } + } + if (lastTokenFromScanner != null) + lastTokenFromScanner.setNext(t); + lastTokenFromScanner = t; + return t; + } catch (OffsetLimitReachedException olre) { + if (mode != ParserMode.COMPLETION_PARSE) + throw new EndOfFileException(olre.getEndOffset()); + IToken completionToken = olre.getFinalToken(); + createCompletionNode(completionToken); + if (olre.getOriginator() == OffsetLimitReachedException.ORIGIN_INACTIVE_CODE) { + // If completion is invoked inside inactive code, there is no AST from which + // to give the completion node a completion name, so we invent a name. + // The invented name is not hooked up to the AST, but does have an offset + // and length, so it can provide an accurate point of reference in + // declaredBefore(). + IASTName completionName = nodeFactory.newInactiveCompletionName(completionToken.getCharImage(), + getTranslationUnit()); + ((ASTNode) completionName).setOffsetAndLength(completionToken.getOffset(), completionToken.getLength()); + completionNode.addName(completionName); + + // Consume the completion token so we don't try to parse an AST fragment from it. + consume(); + } throw olre; - } - } - - private final IToken nextToken(boolean skipInactive) throws EndOfFileException { - final IToken t= nextToken; - if (t != null) - return t; - - final IToken tn= fetchToken(skipInactive); - nextToken= tn; - return tn; - } - - private final IToken lookaheadToken(int i, boolean skipInactive) throws EndOfFileException { - assert i >= 0; - if (isCancelled) { - throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED); - } - IToken t= nextToken(skipInactive); - for (; i > 1; --i) { - t = t.getNext(); - if (t == null) - t = fetchToken(skipInactive); - } - return t; - } - - /** - * Returns the next token without advancing. Same as {@code LA(1)}. - */ - protected final IToken LA() throws EndOfFileException { - IToken t= nextToken(true); - checkForEOI(t); - return t; - } - - /** - * Returns one of the next tokens. With {@code i == 1}, the next token is returned. - * @param i number of tokens to look ahead, must be greater than 0. - */ - protected final IToken LA(int i) throws EndOfFileException { - IToken t= lookaheadToken(i, true); - checkForEOI(t); - return t; - } - - /** - * Consumes and returns the next token available. - */ - protected final IToken consume() throws EndOfFileException { - IToken t= nextToken(true); + } + } + + private final IToken nextToken(boolean skipInactive) throws EndOfFileException { + final IToken t = nextToken; + if (t != null) + return t; + + final IToken tn = fetchToken(skipInactive); + nextToken = tn; + return tn; + } + + private final IToken lookaheadToken(int i, boolean skipInactive) throws EndOfFileException { + assert i >= 0; + if (isCancelled) { + throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED); + } + IToken t = nextToken(skipInactive); + for (; i > 1; --i) { + t = t.getNext(); + if (t == null) + t = fetchToken(skipInactive); + } + return t; + } + + /** + * Returns the next token without advancing. Same as {@code LA(1)}. + */ + protected final IToken LA() throws EndOfFileException { + IToken t = nextToken(true); checkForEOI(t); + return t; + } - nextToken= t.getNext(); - return t; - } + /** + * Returns one of the next tokens. With {@code i == 1}, the next token is returned. + * @param i number of tokens to look ahead, must be greater than 0. + */ + protected final IToken LA(int i) throws EndOfFileException { + IToken t = lookaheadToken(i, true); + checkForEOI(t); + return t; + } + + /** + * Consumes and returns the next token available. + */ + protected final IToken consume() throws EndOfFileException { + IToken t = nextToken(true); + checkForEOI(t); + + nextToken = t.getNext(); + return t; + } /** * Tests whether we are looking at a change from active to inactive code at this point. If so, the change @@ -382,145 +384,147 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @return <code>false</code> if an inactive code branch was rejected because of its nesting level, * <code>true</code>, otherwise. */ - protected final boolean acceptInactiveCodeBoundary(int nesting) { - try { - while (true) { - IToken t= nextToken(false); - switch (t.getType()) { - case IToken.tINACTIVE_CODE_START: - case IToken.tINACTIVE_CODE_SEPARATOR: - IInactiveCodeToken it = (IInactiveCodeToken) t; - if (it.getNewNesting() < nesting || (it.getNewNesting() == nesting && it.getOldNesting() == nesting)) { - return false; - } - fActiveCode= false; - nextToken= t.getNext(); // consume the token - continue; - case IToken.tINACTIVE_CODE_END: - it = (IInactiveCodeToken) t; - if (it.getNewNesting() < nesting || (it.getNewNesting() == nesting && it.getOldNesting() == nesting)) { - return false; - } - fActiveCode= true; - nextToken= t.getNext(); // consume the token - continue; - default: - return true; - } - } - } catch (EndOfFileException e) { - } - return true; - } - - protected final void skipInactiveCode() throws OffsetLimitReachedException { - IToken t= nextToken; - if (fActiveCode && (t == null || t.getType() != IToken.tINACTIVE_CODE_START)) - return; - try { - fActiveCode= true; - while (t != null && t.getType() != IToken.tINACTIVE_CODE_END) { - t= t.getNext(); - } - - if (t != null) { - nextToken= t.getNext(); - } else { - nextToken= null; - scanner.skipInactiveCode(); - } + protected final boolean acceptInactiveCodeBoundary(int nesting) { + try { + while (true) { + IToken t = nextToken(false); + switch (t.getType()) { + case IToken.tINACTIVE_CODE_START: + case IToken.tINACTIVE_CODE_SEPARATOR: + IInactiveCodeToken it = (IInactiveCodeToken) t; + if (it.getNewNesting() < nesting + || (it.getNewNesting() == nesting && it.getOldNesting() == nesting)) { + return false; + } + fActiveCode = false; + nextToken = t.getNext(); // consume the token + continue; + case IToken.tINACTIVE_CODE_END: + it = (IInactiveCodeToken) t; + if (it.getNewNesting() < nesting + || (it.getNewNesting() == nesting && it.getOldNesting() == nesting)) { + return false; + } + fActiveCode = true; + nextToken = t.getNext(); // consume the token + continue; + default: + return true; + } + } + } catch (EndOfFileException e) { + } + return true; + } + + protected final void skipInactiveCode() throws OffsetLimitReachedException { + IToken t = nextToken; + if (fActiveCode && (t == null || t.getType() != IToken.tINACTIVE_CODE_START)) + return; + try { + fActiveCode = true; + while (t != null && t.getType() != IToken.tINACTIVE_CODE_END) { + t = t.getNext(); + } + + if (t != null) { + nextToken = t.getNext(); + } else { + nextToken = null; + scanner.skipInactiveCode(); + } } catch (OffsetLimitReachedException olre) { if (mode == ParserMode.COMPLETION_PARSE) { createCompletionNode(olre.getFinalToken()); throw olre; } } - } + } - protected final boolean isActiveCode() { - return fActiveCode; - } + protected final boolean isActiveCode() { + return fActiveCode; + } - protected final int getCodeBranchNesting() { - return scanner.getCodeBranchNesting(); - } + protected final int getCodeBranchNesting() { + return scanner.getCodeBranchNesting(); + } - /** - * Returns the next token, which can be used to reset the input back to - * this point in the stream. - */ - protected final IToken mark() throws EndOfFileException { - return LA(); - } + /** + * Returns the next token, which can be used to reset the input back to + * this point in the stream. + */ + protected final IToken mark() throws EndOfFileException { + return LA(); + } - /** - * Roll back to a previous point, reseting the queue of tokens. - * @param mark a token previously obtained via {@link #mark()}. - */ - protected final void backup(IToken mark) { - nextToken = mark; - } + /** + * Roll back to a previous point, reseting the queue of tokens. + * @param mark a token previously obtained via {@link #mark()}. + */ + protected final void backup(IToken mark) { + nextToken = mark; + } private final void checkForEOI(IToken t) throws EndOfFileException { - final int lt= t.getType(); - if (lt == IToken.tINACTIVE_CODE_SEPARATOR || lt == IToken.tINACTIVE_CODE_END) - throw new EndOfFileException(t.getOffset(), true); - } - - /** - * Same as {@link #LA(int)}, but returns <code>null</code> when eof is reached. - */ - protected final IToken LAcatchEOF(int i) { - try { - return LA(i); - } catch (EndOfFileException e) { - return null; - } - } - - /** - * Look ahead in the token list and return the token type. - * @param i number of tokens to look ahead, must be greater or equal to 0. - * @return The type of that token - */ - protected final int LT(int i) throws EndOfFileException { - return LA(i).getType(); - } - - /** - * Same as {@link #LT(int)}, but returns <code>0</code> when eof is reached. - */ - protected final int LTcatchEOF(int i) { - try { - return LT(i); - } catch (EndOfFileException e) { - return 0; - } - } - - /** - * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} - * is thrown if the type does not match the expected one. - * @param type the expected type of the next token. - */ - protected final IToken consume(int type) throws EndOfFileException, BacktrackException { - final IToken result= consume(); - if (result.getType() != type) - throwBacktrack(result); - return result; - } - - /** - * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} - * is thrown if the type neither matches <code>type1</code> nor <code>type2</code>. - */ - protected final IToken consume(int type1, int type2) throws EndOfFileException, BacktrackException { - final IToken result= consume(); - final int lt1 = result.getType(); + final int lt = t.getType(); + if (lt == IToken.tINACTIVE_CODE_SEPARATOR || lt == IToken.tINACTIVE_CODE_END) + throw new EndOfFileException(t.getOffset(), true); + } + + /** + * Same as {@link #LA(int)}, but returns <code>null</code> when eof is reached. + */ + protected final IToken LAcatchEOF(int i) { + try { + return LA(i); + } catch (EndOfFileException e) { + return null; + } + } + + /** + * Look ahead in the token list and return the token type. + * @param i number of tokens to look ahead, must be greater or equal to 0. + * @return The type of that token + */ + protected final int LT(int i) throws EndOfFileException { + return LA(i).getType(); + } + + /** + * Same as {@link #LT(int)}, but returns <code>0</code> when eof is reached. + */ + protected final int LTcatchEOF(int i) { + try { + return LT(i); + } catch (EndOfFileException e) { + return 0; + } + } + + /** + * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} + * is thrown if the type does not match the expected one. + * @param type the expected type of the next token. + */ + protected final IToken consume(int type) throws EndOfFileException, BacktrackException { + final IToken result = consume(); + if (result.getType() != type) + throwBacktrack(result); + return result; + } + + /** + * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} + * is thrown if the type neither matches <code>type1</code> nor <code>type2</code>. + */ + protected final IToken consume(int type1, int type2) throws EndOfFileException, BacktrackException { + final IToken result = consume(); + final int lt1 = result.getType(); if (lt1 != type1 && lt1 != type2) - throwBacktrack(result); - return result; - } + throwBacktrack(result); + return result; + } /** * Consume the next token available only if the type is as specified. In case we reached @@ -532,260 +536,259 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @throws BacktrackException * if LT(1) != type */ - protected IToken consumeOrEOC(int type) throws EndOfFileException, BacktrackException { - final IToken la1= LA(1); - final int lt1 = la1.getType(); + protected IToken consumeOrEOC(int type) throws EndOfFileException, BacktrackException { + final IToken la1 = LA(1); + final int lt1 = la1.getType(); if (lt1 != type) { - if (lt1 == IToken.tEOC) - return la1; - throwBacktrack(la1); - } - return consume(); - } + if (lt1 == IToken.tEOC) + return la1; + throwBacktrack(la1); + } + return consume(); + } protected final boolean isOnSameLine(int offset1, int offset2) { - ILocationResolver lr= getTranslationUnit().getAdapter(ILocationResolver.class); - IASTFileLocation floc= lr.getMappedFileLocation(offset1, offset2 - offset1 + 1); - return floc.getFileName().equals(lr.getContainingFilePath(offset1)) && - floc.getStartingLineNumber() == floc.getEndingLineNumber(); + ILocationResolver lr = getTranslationUnit().getAdapter(ILocationResolver.class); + IASTFileLocation floc = lr.getMappedFileLocation(offset1, offset2 - offset1 + 1); + return floc.getFileName().equals(lr.getContainingFilePath(offset1)) + && floc.getStartingLineNumber() == floc.getEndingLineNumber(); } - protected final int calculateEndOffset(IASTNode n) { - ASTNode node = (ASTNode) n; - return node.getOffset() + node.getLength(); - } + protected final int calculateEndOffset(IASTNode n) { + ASTNode node = (ASTNode) n; + return node.getOffset() + node.getLength(); + } - protected final <T extends IASTNode> T setRange(T n, IASTNode from) { - ((ASTNode) n).setOffsetAndLength((ASTNode) from); - return n; - } + protected final <T extends IASTNode> T setRange(T n, IASTNode from) { + ((ASTNode) n).setOffsetAndLength((ASTNode) from); + return n; + } - protected final <T extends IASTNode> T setRange(T n, IASTNode from, int endOffset) { - final int offset = ((ASTNode) from).getOffset(); + protected final <T extends IASTNode> T setRange(T n, IASTNode from, int endOffset) { + final int offset = ((ASTNode) from).getOffset(); ((ASTNode) n).setOffsetAndLength(offset, endOffset - offset); - return n; - } + return n; + } - protected final <T extends IASTNode> T setRange(T n, int offset, int endOffset) { - ((ASTNode) n).setOffsetAndLength(offset, endOffset - offset); - return n; - } + protected final <T extends IASTNode> T setRange(T n, int offset, int endOffset) { + ((ASTNode) n).setOffsetAndLength(offset, endOffset - offset); + return n; + } - protected final void adjustLength(IASTNode n, IASTNode endNode) { - final int endOffset= calculateEndOffset(endNode); - adjustEndOffset(n, endOffset); - } + protected final void adjustLength(IASTNode n, IASTNode endNode) { + final int endOffset = calculateEndOffset(endNode); + adjustEndOffset(n, endOffset); + } protected final <T extends IASTNode> T adjustEndOffset(T n, final int endOffset) { final ASTNode node = (ASTNode) n; - node.setLength(endOffset - node.getOffset()); - return n; + node.setLength(endOffset - node.getOffset()); + return n; } - protected final int getEndOffset() { - if (lastTokenFromScanner == null) - return 0; - return lastTokenFromScanner.getEndOffset(); - } + protected final int getEndOffset() { + if (lastTokenFromScanner == null) + return 0; + return lastTokenFromScanner.getEndOffset(); + } - /** - * This is the single entry point for setting parsePassed to false - */ - protected void failParse() { - parsePassed = false; - } + /** + * This is the single entry point for setting parsePassed to false + */ + protected void failParse() { + parsePassed = false; + } - @Override + @Override public synchronized void cancel() { - isCancelled = true; - } - - /** - * Parses an identifier. - * - * @throws BacktrackException request a backtrack - */ - protected abstract IASTName identifier() throws EndOfFileException, BacktrackException; - - /** - * @return Returns the backtrackCount. - */ - public final int getBacktrackCount() { - return backtrackCount; - } - - protected IASTProblem createProblem(BacktrackException bt) { - IASTProblem result= bt.getProblem(); - if (result == null) { - result= createProblem(IProblem.SYNTAX_ERROR, bt.getOffset(), bt.getLength()); - } - return result; - } + isCancelled = true; + } + + /** + * Parses an identifier. + * + * @throws BacktrackException request a backtrack + */ + protected abstract IASTName identifier() throws EndOfFileException, BacktrackException; + + /** + * @return Returns the backtrackCount. + */ + public final int getBacktrackCount() { + return backtrackCount; + } + + protected IASTProblem createProblem(BacktrackException bt) { + IASTProblem result = bt.getProblem(); + if (result == null) { + result = createProblem(IProblem.SYNTAX_ERROR, bt.getOffset(), bt.getLength()); + } + return result; + } protected final IASTProblem createProblem(int signal, int offset, int length) { - IASTProblem result = nodeFactory.newProblem(signal, CharArrayUtils.EMPTY, true); - ((ASTNode) result).setOffsetAndLength(offset, length); - return result; - } - - protected void logThrowable(String methodName, Throwable e) { - if (e != null) { - if (log.isTracing()) { - String message = - String.format("Parser: Unexpected throwable in %s:%s::%s. w/%s", //$NON-NLS-1$ - methodName, e.getClass().getName(), e.getMessage(), scanner); - log.traceLog(message); - } - log.traceException(e); - } - } - - @Override + IASTProblem result = nodeFactory.newProblem(signal, CharArrayUtils.EMPTY, true); + ((ASTNode) result).setOffsetAndLength(offset, length); + return result; + } + + protected void logThrowable(String methodName, Throwable e) { + if (e != null) { + if (log.isTracing()) { + String message = String.format("Parser: Unexpected throwable in %s:%s::%s. w/%s", //$NON-NLS-1$ + methodName, e.getClass().getName(), e.getMessage(), scanner); + log.traceLog(message); + } + log.traceException(e); + } + } + + @Override public String toString() { - return scanner.toString(); - } - - /** - * @param methodName - * @param e - */ - protected void logException(String methodName, Exception e) { - if (!(e instanceof EndOfFileException) && e != null) { - if (log.isTracing()) { - String message = - String.format("Parser: Unexpected exception in %s:%s::%s. w/%s", //$NON-NLS-1$ - methodName, e.getClass().getName(), e.getMessage(), scanner); - log.traceLog(message); - } - log.traceException(e); - } - } - - protected final void throwBacktrack(IASTProblem problem, IASTNode node) throws BacktrackException { - ++backtrackCount; - backtrack.initialize(problem, node); - throw backtrack; - } - - protected final void throwBacktrack(IASTProblem problem) throws BacktrackException { - ++backtrackCount; - backtrack.initialize(problem); - throw backtrack; - } - - protected final void throwBacktrack(IASTNode node) throws BacktrackException { - final ASTNode n= (ASTNode) node; + return scanner.toString(); + } + + /** + * @param methodName + * @param e + */ + protected void logException(String methodName, Exception e) { + if (!(e instanceof EndOfFileException) && e != null) { + if (log.isTracing()) { + String message = String.format("Parser: Unexpected exception in %s:%s::%s. w/%s", //$NON-NLS-1$ + methodName, e.getClass().getName(), e.getMessage(), scanner); + log.traceLog(message); + } + log.traceException(e); + } + } + + protected final void throwBacktrack(IASTProblem problem, IASTNode node) throws BacktrackException { + ++backtrackCount; + backtrack.initialize(problem, node); + throw backtrack; + } + + protected final void throwBacktrack(IASTProblem problem) throws BacktrackException { + ++backtrackCount; + backtrack.initialize(problem); + throw backtrack; + } + + protected final void throwBacktrack(IASTNode node) throws BacktrackException { + final ASTNode n = (ASTNode) node; throwBacktrack(n.getOffset(), n.getLength()); - } + } - @Override + @Override public IASTTranslationUnit parse() { - long t0 = log.isTracing() ? System.currentTimeMillis() : 0; - translationUnit(); - long t1 = log.isTracing() ? System.currentTimeMillis() : 0; - resolveAmbiguities(); - IASTTranslationUnit ast = getTranslationUnit(); - if (log.isTracing()) { - ITranslationUnit tu = ast.getOriginatingTranslationUnit(); + long t0 = log.isTracing() ? System.currentTimeMillis() : 0; + translationUnit(); + long t1 = log.isTracing() ? System.currentTimeMillis() : 0; + resolveAmbiguities(); + IASTTranslationUnit ast = getTranslationUnit(); + if (log.isTracing()) { + ITranslationUnit tu = ast.getOriginatingTranslationUnit(); String name = tu == null ? "<unknown>" : tu.getElementName(); //$NON-NLS-1$ - String message = String.format("Parsed %s: %d ms%s. Ambiguity resolution: %d ms", //$NON-NLS-1$ - name, t1 - t0, parsePassed ? "" : " - parse failure", System.currentTimeMillis() - t1); //$NON-NLS-1$//$NON-NLS-2$ + String message = String.format("Parsed %s: %d ms%s. Ambiguity resolution: %d ms", //$NON-NLS-1$ + name, t1 - t0, parsePassed ? "" : " - parse failure", System.currentTimeMillis() - t1); //$NON-NLS-1$//$NON-NLS-2$ log.traceLog(message); - } - nullifyTranslationUnit(); - ast.freeze(); // Make the AST immutable. - return ast; - } + } + nullifyTranslationUnit(); + ast.freeze(); // Make the AST immutable. + return ast; + } - protected void resolveAmbiguities() { - final IASTTranslationUnit translationUnit = getTranslationUnit(); - if (translationUnit instanceof ASTTranslationUnit) { - ((ASTTranslationUnit) translationUnit).resolveAmbiguities(); - } - } + protected void resolveAmbiguities() { + final IASTTranslationUnit translationUnit = getTranslationUnit(); + if (translationUnit instanceof ASTTranslationUnit) { + ((ASTTranslationUnit) translationUnit).resolveAmbiguities(); + } + } - protected abstract ASTVisitor createAmbiguityNodeVisitor(); + protected abstract ASTVisitor createAmbiguityNodeVisitor(); - protected abstract void nullifyTranslationUnit(); + protected abstract void nullifyTranslationUnit(); protected IToken skipOverCompoundStatement(boolean hasSkippedNodes) throws BacktrackException, EndOfFileException { - // speed up the parser by skipping the body, simply look for matching brace and return + // speed up the parser by skipping the body, simply look for matching brace and return if (hasSkippedNodes) getTranslationUnit().setHasNodesOmitted(true); - final boolean isActive = isActiveCode(); - final int codeBranchNesting= getCodeBranchNesting(); - - consume(IToken.tLBRACE); - IToken result = null; - int depth = 1; - while (depth > 0) { - if (!isActive) { - IToken t= lookaheadToken(1, false); - final int lt= t.getType(); - if (lt == IToken.tINACTIVE_CODE_SEPARATOR || lt == IToken.tINACTIVE_CODE_END || lt == IToken.tINACTIVE_CODE_START) { + final boolean isActive = isActiveCode(); + final int codeBranchNesting = getCodeBranchNesting(); + + consume(IToken.tLBRACE); + IToken result = null; + int depth = 1; + while (depth > 0) { + if (!isActive) { + IToken t = lookaheadToken(1, false); + final int lt = t.getType(); + if (lt == IToken.tINACTIVE_CODE_SEPARATOR || lt == IToken.tINACTIVE_CODE_END + || lt == IToken.tINACTIVE_CODE_START) { if (!acceptInactiveCodeBoundary(codeBranchNesting)) throw new EndOfFileException(t.getOffset(), true); } - } + } result = consume(); - switch (result.getType()) { - case IToken.tRBRACE: - --depth; - break; - case IToken.tLBRACE: - ++depth; - break; - case IToken.tEOC: - throw new EndOfFileException(result.getOffset()); - } - } - return result; - } + switch (result.getType()) { + case IToken.tRBRACE: + --depth; + break; + case IToken.tLBRACE: + ++depth; + break; + case IToken.tEOC: + throw new EndOfFileException(result.getOffset()); + } + } + return result; + } protected IASTProblemDeclaration skipProblemDeclaration(int offset) { return skipProblemDeclaration(offset, null); } - - protected IASTProblemDeclaration skipProblemDeclaration(int offset, IASTProblem origProblem) { + + protected IASTProblemDeclaration skipProblemDeclaration(int offset, IASTProblem origProblem) { failParse(); - declarationMark= null; - int endOffset = skipToSemiOrClosingBrace(offset, false); - IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); + declarationMark = null; + int endOffset = skipToSemiOrClosingBrace(offset, false); + IASTProblem problem = createProblem(IProblem.SYNTAX_ERROR, offset, endOffset - offset); if (origProblem != null && origProblem.getID() != IProblem.SYNTAX_ERROR) { problem.setOriginalProblem(origProblem); } return buildProblemDeclaration(problem); - } + } - protected IASTProblemStatement skipProblemStatement(int offset) { + protected IASTProblemStatement skipProblemStatement(int offset) { failParse(); - declarationMark= null; - int endOffset = skipToSemiOrClosingBrace(offset, false); - IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); + declarationMark = null; + int endOffset = skipToSemiOrClosingBrace(offset, false); + IASTProblem problem = createProblem(IProblem.SYNTAX_ERROR, offset, endOffset - offset); return buildProblemStatement(problem); - } + } - private IASTProblem skipProblemEnumerator(int offset) { - failParse(); - final int endOffset= skipToSemiOrClosingBrace(offset, true); - return createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); - } + private IASTProblem skipProblemEnumerator(int offset) { + failParse(); + final int endOffset = skipToSemiOrClosingBrace(offset, true); + return createProblem(IProblem.SYNTAX_ERROR, offset, endOffset - offset); + } private int skipToSemiOrClosingBrace(int offset, boolean eatBrace) { failParse(); - declarationMark= null; - int depth= 0; - int endOffset; - loop: try { - endOffset= LA(1).getOffset(); + declarationMark = null; + int depth = 0; + int endOffset; + loop: try { + endOffset = LA(1).getOffset(); while (true) { switch (LT(1)) { case IToken.tEOC: - endOffset= getEndOffset(); + endOffset = getEndOffset(); break loop; case IToken.tSEMI: if (depth == 0) { - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break loop; } break; @@ -795,33 +798,33 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { case IToken.tRBRACE: if (--depth <= 0) { if (depth == 0 || offset == endOffset || eatBrace) { - endOffset= consume().getEndOffset(); // consume closing brace + endOffset = consume().getEndOffset(); // consume closing brace } if (LTcatchEOF(1) == IToken.tSEMI) { - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } break loop; } break; } - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } } catch (EndOfFileException e) { - endOffset= getEndOffset(); + endOffset = getEndOffset(); } return endOffset; } - protected IASTProblemExpression skipProblemConditionInParenthesis(int offset) { + protected IASTProblemExpression skipProblemConditionInParenthesis(int offset) { failParse(); - int compExpr= 0; - int depth= 0; - int endOffset= offset; + int compExpr = 0; + int depth = 0; + int endOffset = offset; loop: try { while (true) { switch (LT(1)) { case IToken.tEOC: - endOffset= getEndOffset(); + endOffset = getEndOffset(); break loop; case IToken.tSEMI: case IToken.tLBRACE: @@ -833,7 +836,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { depth++; if (LTcatchEOF(2) == IToken.tLBRACE) { if (compExpr == 0) { - compExpr= depth; + compExpr = depth; } consume(); } @@ -843,82 +846,82 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { break loop; } if (depth < compExpr) { - compExpr= 0; + compExpr = 0; } break; } - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } } catch (EndOfFileException e) { - endOffset= getEndOffset(); + endOffset = getEndOffset(); } - IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); + IASTProblem problem = createProblem(IProblem.SYNTAX_ERROR, offset, endOffset - offset); return buildProblemExpression(problem); - } - - protected IASTCompoundStatement compoundStatement() throws EndOfFileException, BacktrackException { - IASTCompoundStatement result = nodeFactory.newCompoundStatement(); - if (LT(1) == IToken.tEOC) - return result; - - final int offset= LA(1).getOffset(); - int endOffset= consume(IToken.tLBRACE).getOffset(); - - int stmtOffset= -1; - while (true) { - IToken next= LAcatchEOF(1); - if (next == null) { - ((ASTNode) result).setOffsetAndLength(offset, endOffset-offset); - throwBacktrack(createProblem(IProblem.SYNTAX_ERROR, endOffset, 0), result); - return null; // To make Java compiler happy. - } - try { - if (next.getType() == IToken.tEOC) - break; - - if (next.getType() == IToken.tRBRACE) { - endOffset= consume().getEndOffset(); - break; - } - - final int nextOffset = next.getOffset(); - declarationMark= next; - next= null; // Don't hold on to the token while parsing namespaces, class bodies, etc. - - IASTStatement stmt; - if (stmtOffset == nextOffset) { - // no progress - stmt= skipProblemStatement(stmtOffset); - } else { - stmtOffset= nextOffset; - stmt= statement(); - } - result.addStatement(stmt); - endOffset= calculateEndOffset(stmt); - } catch (BacktrackException bt) { - final IASTNode beforeProblem = bt.getNodeBeforeProblem(); - final IASTProblem problem = bt.getProblem(); + } + + protected IASTCompoundStatement compoundStatement() throws EndOfFileException, BacktrackException { + IASTCompoundStatement result = nodeFactory.newCompoundStatement(); + if (LT(1) == IToken.tEOC) + return result; + + final int offset = LA(1).getOffset(); + int endOffset = consume(IToken.tLBRACE).getOffset(); + + int stmtOffset = -1; + while (true) { + IToken next = LAcatchEOF(1); + if (next == null) { + ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); + throwBacktrack(createProblem(IProblem.SYNTAX_ERROR, endOffset, 0), result); + return null; // To make Java compiler happy. + } + try { + if (next.getType() == IToken.tEOC) + break; + + if (next.getType() == IToken.tRBRACE) { + endOffset = consume().getEndOffset(); + break; + } + + final int nextOffset = next.getOffset(); + declarationMark = next; + next = null; // Don't hold on to the token while parsing namespaces, class bodies, etc. + + IASTStatement stmt; + if (stmtOffset == nextOffset) { + // no progress + stmt = skipProblemStatement(stmtOffset); + } else { + stmtOffset = nextOffset; + stmt = statement(); + } + result.addStatement(stmt); + endOffset = calculateEndOffset(stmt); + } catch (BacktrackException bt) { + final IASTNode beforeProblem = bt.getNodeBeforeProblem(); + final IASTProblem problem = bt.getProblem(); if (problem != null && beforeProblem instanceof IASTStatement) { - result.addStatement((IASTStatement) beforeProblem); + result.addStatement((IASTStatement) beforeProblem); result.addStatement(buildProblemStatement(problem)); - endOffset= calculateEndOffset(beforeProblem); + endOffset = calculateEndOffset(beforeProblem); } else { - IASTStatement stmt= skipProblemStatement(stmtOffset); + IASTStatement stmt = skipProblemStatement(stmtOffset); result.addStatement(stmt); - endOffset= calculateEndOffset(stmt); + endOffset = calculateEndOffset(stmt); } - } catch (EndOfFileException e) { - IASTStatement stmt= skipProblemStatement(stmtOffset); - result.addStatement(stmt); - endOffset= calculateEndOffset(stmt); - break; - } finally { - declarationMark= null; - } - } - ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); - return result; - } + } catch (EndOfFileException e) { + IASTStatement stmt = skipProblemStatement(stmtOffset); + result.addStatement(stmt); + endOffset = calculateEndOffset(stmt); + break; + } finally { + declarationMark = null; + } + } + ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); + return result; + } private IASTProblemDeclaration buildProblemDeclaration(IASTProblem problem) { IASTProblemDeclaration pd = nodeFactory.newProblemDeclaration(problem); @@ -938,32 +941,32 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return pexpr; } - protected IASTExpression compoundStatementExpression() throws EndOfFileException, BacktrackException { - int startingOffset = consume().getOffset(); // tLPAREN always - IASTCompoundStatement compoundStatement = null; - if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { - skipOverCompoundStatement(true); - } else if (mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE) { - if (scanner.isOnTopContext()) { - compoundStatement(); - } else { - skipOverCompoundStatement(true); - } - } else if (mode == ParserMode.COMPLETE_PARSE) { - compoundStatement = compoundStatement(); - } - - int lastOffset = consume(IToken.tRPAREN).getEndOffset(); - IGNUASTCompoundStatementExpression resultExpression = - nodeFactory.newGNUCompoundStatementExpression(compoundStatement); - ((ASTNode) resultExpression).setOffsetAndLength(startingOffset, lastOffset - startingOffset); - return resultExpression; - } - - /** - * Models a cast expression followed by an operator. Can be linked into a chain. - * This is done right to left, such that a tree of variants can be built. - */ + protected IASTExpression compoundStatementExpression() throws EndOfFileException, BacktrackException { + int startingOffset = consume().getOffset(); // tLPAREN always + IASTCompoundStatement compoundStatement = null; + if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { + skipOverCompoundStatement(true); + } else if (mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE) { + if (scanner.isOnTopContext()) { + compoundStatement(); + } else { + skipOverCompoundStatement(true); + } + } else if (mode == ParserMode.COMPLETE_PARSE) { + compoundStatement = compoundStatement(); + } + + int lastOffset = consume(IToken.tRPAREN).getEndOffset(); + IGNUASTCompoundStatementExpression resultExpression = nodeFactory + .newGNUCompoundStatementExpression(compoundStatement); + ((ASTNode) resultExpression).setOffsetAndLength(startingOffset, lastOffset - startingOffset); + return resultExpression; + } + + /** + * Models a cast expression followed by an operator. Can be linked into a chain. + * This is done right to left, such that a tree of variants can be built. + */ public static class BinaryOperator { final int fOperatorToken; final int fLeftPrecedence; @@ -974,23 +977,23 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { public BinaryOperator(BinaryOperator nextOp, IASTInitializerClause expression, int operatorToken, int leftPrecedence, int rightPrecedence) { - fNext= nextOp; - fOperatorToken= operatorToken; - fLeftPrecedence= leftPrecedence; - fRightPrecedence= rightPrecedence; + fNext = nextOp; + fOperatorToken = operatorToken; + fLeftPrecedence = leftPrecedence; + fRightPrecedence = rightPrecedence; if (expression instanceof CastAmbiguityMarker) { - fAmbiguityMarker= (CastAmbiguityMarker) expression; - fExpression= fAmbiguityMarker.fExpression; - fAmbiguityMarker.fExpression= null; + fAmbiguityMarker = (CastAmbiguityMarker) expression; + fExpression = fAmbiguityMarker.fExpression; + fAmbiguityMarker.fExpression = null; } else { - fExpression= expression; - fAmbiguityMarker= null; + fExpression = expression; + fAmbiguityMarker = null; } } public IASTInitializerClause exchange(IASTInitializerClause expr) { - IASTInitializerClause e= fExpression; - fExpression= expr; + IASTInitializerClause e = fExpression; + fExpression = expr; return e; } @@ -1008,53 +1011,53 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } public final IASTExpression buildExpression(BinaryOperator leftChain, IASTInitializerClause expr) { - BinaryOperator rightChain= null; + BinaryOperator rightChain = null; for (;;) { if (leftChain == null) { if (rightChain == null) return (IASTExpression) expr; - expr= buildExpression((IASTExpression) expr, rightChain); - rightChain= rightChain.fNext; + expr = buildExpression((IASTExpression) expr, rightChain); + rightChain = rightChain.fNext; } else if (rightChain != null && leftChain.fRightPrecedence < rightChain.fLeftPrecedence) { - expr= buildExpression((IASTExpression) expr, rightChain); - rightChain= rightChain.fNext; + expr = buildExpression((IASTExpression) expr, rightChain); + rightChain = rightChain.fNext; } else { - BinaryOperator op= leftChain; - leftChain= leftChain.fNext; - expr= op.exchange(expr); - op.fNext= rightChain; - rightChain= op; + BinaryOperator op = leftChain; + leftChain = leftChain.fNext; + expr = op.exchange(expr); + op.fNext = rightChain; + rightChain = op; } } } private IASTExpression buildExpression(IASTExpression left, BinaryOperator operator) { - int op, unaryOp= 0; - final IASTInitializerClause right= operator.fExpression; + int op, unaryOp = 0; + final IASTInitializerClause right = operator.fExpression; switch (operator.fOperatorToken) { - case IToken.tQUESTION: - final IASTInitializerClause negative; - if (operator.fNext == null || operator.fNext.fOperatorToken != IToken.tCOLON) { - negative= null; - } else { - negative= operator.fNext.fExpression; - operator.fNext= operator.fNext.fNext; - } - IASTConditionalExpression conditionalEx = - nodeFactory.newConditionalExpession(left, (IASTExpression) right, (IASTExpression) negative); - setRange(conditionalEx, left); - if (negative != null) { - adjustLength(conditionalEx, negative); - } - return conditionalEx; + case IToken.tQUESTION: + final IASTInitializerClause negative; + if (operator.fNext == null || operator.fNext.fOperatorToken != IToken.tCOLON) { + negative = null; + } else { + negative = operator.fNext.fExpression; + operator.fNext = operator.fNext.fNext; + } + IASTConditionalExpression conditionalEx = nodeFactory.newConditionalExpession(left, (IASTExpression) right, + (IASTExpression) negative); + setRange(conditionalEx, left); + if (negative != null) { + adjustLength(conditionalEx, negative); + } + return conditionalEx; case IToken.tCOMMA: IASTExpressionList list; if (left instanceof IASTExpressionList) { - list= (IASTExpressionList) left; + list = (IASTExpressionList) left; } else { - list= nodeFactory.newExpressionList(); + list = nodeFactory.newExpressionList(); list.addExpression(left); setRange(list, left); } @@ -1063,121 +1066,121 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return list; case IToken.tASSIGN: - op= IASTBinaryExpression.op_assign; + op = IASTBinaryExpression.op_assign; break; - case IToken.tSTARASSIGN: - op= IASTBinaryExpression.op_multiplyAssign; + case IToken.tSTARASSIGN: + op = IASTBinaryExpression.op_multiplyAssign; break; - case IToken.tDIVASSIGN: - op= IASTBinaryExpression.op_divideAssign; + case IToken.tDIVASSIGN: + op = IASTBinaryExpression.op_divideAssign; break; - case IToken.tMODASSIGN: - op= IASTBinaryExpression.op_moduloAssign; + case IToken.tMODASSIGN: + op = IASTBinaryExpression.op_moduloAssign; break; - case IToken.tPLUSASSIGN: - op= IASTBinaryExpression.op_plusAssign; + case IToken.tPLUSASSIGN: + op = IASTBinaryExpression.op_plusAssign; break; - case IToken.tMINUSASSIGN: - op= IASTBinaryExpression.op_minusAssign; + case IToken.tMINUSASSIGN: + op = IASTBinaryExpression.op_minusAssign; break; - case IToken.tSHIFTRASSIGN: - op= IASTBinaryExpression.op_shiftRightAssign; + case IToken.tSHIFTRASSIGN: + op = IASTBinaryExpression.op_shiftRightAssign; break; - case IToken.tSHIFTLASSIGN: - op= IASTBinaryExpression.op_shiftLeftAssign; + case IToken.tSHIFTLASSIGN: + op = IASTBinaryExpression.op_shiftLeftAssign; break; - case IToken.tAMPERASSIGN: - op= IASTBinaryExpression.op_binaryAndAssign; + case IToken.tAMPERASSIGN: + op = IASTBinaryExpression.op_binaryAndAssign; break; - case IToken.tXORASSIGN: - op= IASTBinaryExpression.op_binaryXorAssign; + case IToken.tXORASSIGN: + op = IASTBinaryExpression.op_binaryXorAssign; break; - case IToken.tBITORASSIGN: - op= IASTBinaryExpression.op_binaryOrAssign; + case IToken.tBITORASSIGN: + op = IASTBinaryExpression.op_binaryOrAssign; break; - case IToken.tOR: - op= IASTBinaryExpression.op_logicalOr; + case IToken.tOR: + op = IASTBinaryExpression.op_logicalOr; break; - case IToken.tAND: - op= IASTBinaryExpression.op_logicalAnd; + case IToken.tAND: + op = IASTBinaryExpression.op_logicalAnd; unaryOp = IASTUnaryExpression.op_labelReference; break; - case IToken.tBITOR: - op= IASTBinaryExpression.op_binaryOr; + case IToken.tBITOR: + op = IASTBinaryExpression.op_binaryOr; + break; + case IToken.tXOR: + op = IASTBinaryExpression.op_binaryXor; break; - case IToken.tXOR: - op= IASTBinaryExpression.op_binaryXor; + case IToken.tAMPER: + op = IASTBinaryExpression.op_binaryAnd; + unaryOp = IASTUnaryExpression.op_amper; break; - case IToken.tAMPER: - op= IASTBinaryExpression.op_binaryAnd; - unaryOp= IASTUnaryExpression.op_amper; + case IToken.tEQUAL: + op = IASTBinaryExpression.op_equals; break; - case IToken.tEQUAL: - op= IASTBinaryExpression.op_equals; + case IToken.tNOTEQUAL: + op = IASTBinaryExpression.op_notequals; break; - case IToken.tNOTEQUAL: - op= IASTBinaryExpression.op_notequals; + case IToken.tGT: + op = IASTBinaryExpression.op_greaterThan; break; - case IToken.tGT: - op= IASTBinaryExpression.op_greaterThan; + case IToken.tLT: + op = IASTBinaryExpression.op_lessThan; break; - case IToken.tLT: - op= IASTBinaryExpression.op_lessThan; + case IToken.tLTEQUAL: + op = IASTBinaryExpression.op_lessEqual; break; - case IToken.tLTEQUAL: - op= IASTBinaryExpression.op_lessEqual; + case IToken.tGTEQUAL: + op = IASTBinaryExpression.op_greaterEqual; break; - case IToken.tGTEQUAL: - op= IASTBinaryExpression.op_greaterEqual; + case IGCCToken.tMAX: + op = IASTBinaryExpression.op_max; break; - case IGCCToken.tMAX: - op= IASTBinaryExpression.op_max; + case IGCCToken.tMIN: + op = IASTBinaryExpression.op_min; break; - case IGCCToken.tMIN: - op= IASTBinaryExpression.op_min; + case IToken.tSHIFTL: + op = IASTBinaryExpression.op_shiftLeft; break; - case IToken.tSHIFTL: - op= IASTBinaryExpression.op_shiftLeft; + case IToken.tSHIFTR: + op = IASTBinaryExpression.op_shiftRight; break; - case IToken.tSHIFTR: - op= IASTBinaryExpression.op_shiftRight; + case IToken.tPLUS: + op = IASTBinaryExpression.op_plus; + unaryOp = IASTUnaryExpression.op_plus; break; - case IToken.tPLUS: - op= IASTBinaryExpression.op_plus; - unaryOp= IASTUnaryExpression.op_plus; + case IToken.tMINUS: + op = IASTBinaryExpression.op_minus; + unaryOp = IASTUnaryExpression.op_minus; break; - case IToken.tMINUS: - op= IASTBinaryExpression.op_minus; - unaryOp= IASTUnaryExpression.op_minus; + case IToken.tSTAR: + op = IASTBinaryExpression.op_multiply; + unaryOp = IASTUnaryExpression.op_star; break; - case IToken.tSTAR: - op= IASTBinaryExpression.op_multiply; - unaryOp= IASTUnaryExpression.op_star; + case IToken.tDIV: + op = IASTBinaryExpression.op_divide; break; - case IToken.tDIV: - op= IASTBinaryExpression.op_divide; + case IToken.tMOD: + op = IASTBinaryExpression.op_modulo; break; - case IToken.tMOD: - op= IASTBinaryExpression.op_modulo; + case IToken.tDOTSTAR: + op = IASTBinaryExpression.op_pmdot; + break; + case IToken.tARROWSTAR: + op = IASTBinaryExpression.op_pmarrow; break; - case IToken.tDOTSTAR: - op = IASTBinaryExpression.op_pmdot; - break; - case IToken.tARROWSTAR: - op = IASTBinaryExpression.op_pmarrow; - break; - default: - assert false; - return null; + default: + assert false; + return null; } - IASTExpression result= buildBinaryExpression(op, left, right, calculateEndOffset(right)); + IASTExpression result = buildBinaryExpression(op, left, right, calculateEndOffset(right)); final CastAmbiguityMarker am = operator.fAmbiguityMarker; if (am != null) { if (unaryOp != 0) { - result = createCastVsBinaryExpressionAmbiguity((IASTBinaryExpression) result, - am.getTypeIdForCast(), unaryOp, am.getUnaryOperatorOffset()); + result = createCastVsBinaryExpressionAmbiguity((IASTBinaryExpression) result, am.getTypeIdForCast(), + unaryOp, am.getUnaryOperatorOffset()); } else { assert false; } @@ -1186,17 +1189,26 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } protected abstract IASTExpression expression() throws BacktrackException, EndOfFileException; + protected abstract IASTExpression constantExpression() throws BacktrackException, EndOfFileException; - protected abstract IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException; - protected abstract IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException; - protected abstract IASTTypeId typeId(DeclarationOptions option) throws EndOfFileException, BacktrackException; - // Methods for parsing a type-id and an expression with an optional trailing ellipsis. - // The optional trailing ellipsis can only appear in C++ code, and only the C++ parser - // allows it, but being able to invoke this from here allows reusing more productions - // between C and C++, such as alignmentSpecifier(). - protected abstract IASTExpression expressionWithOptionalTrailingEllipsis() throws BacktrackException, EndOfFileException; - protected abstract IASTTypeId typeIdWithOptionalTrailingEllipsis(DeclarationOptions option) throws EndOfFileException, BacktrackException; + protected abstract IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException; + + protected abstract IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException; + + protected abstract IASTTypeId typeId(DeclarationOptions option) throws EndOfFileException, BacktrackException; + + // Methods for parsing a type-id and an expression with an optional trailing ellipsis. + // The optional trailing ellipsis can only appear in C++ code, and only the C++ parser + // allows it, but being able to invoke this from here allows reusing more productions + // between C and C++, such as alignmentSpecifier(). + protected abstract IASTExpression expressionWithOptionalTrailingEllipsis() + throws BacktrackException, EndOfFileException; + + protected abstract IASTTypeId typeIdWithOptionalTrailingEllipsis(DeclarationOptions option) + throws EndOfFileException, BacktrackException; private final static class CastAmbiguityMarker extends ASTNode implements IASTExpression { private IASTExpression fExpression; @@ -1204,13 +1216,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { private final int fUnaryOperatorOffset; CastAmbiguityMarker(IASTExpression unary, IASTTypeId typeIdForCast, int unaryOperatorOffset) { - fExpression= unary; - fTypeIdForCast= typeIdForCast; - fUnaryOperatorOffset= unaryOperatorOffset; + fExpression = unary; + fTypeIdForCast = typeIdForCast; + fUnaryOperatorOffset = unaryOperatorOffset; } public CastAmbiguityMarker updateExpression(IASTExpression expression) { - fExpression= expression; + fExpression = expression; return this; } @@ -1252,59 +1264,64 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } } - protected final IASTExpression castExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + protected final IASTExpression castExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tLPAREN) { - final IToken mark= mark(); - final int startingOffset= mark.getOffset(); - final boolean canBeCast= canBeCastExpression(); + final IToken mark = mark(); + final int startingOffset = mark.getOffset(); + final boolean canBeCast = canBeCastExpression(); consume(); - IASTTypeId typeId= null; + IASTTypeId typeId = null; if (canBeCast) { try { - typeId= typeId(DeclarationOptions.TYPEID); + typeId = typeId(DeclarationOptions.TYPEID); } catch (BacktrackException e) { } } if (typeId != null && LT(1) == IToken.tRPAREN) { consume(); - boolean unaryFailed= false; + boolean unaryFailed = false; if (ctx == CastExprCtx.eDirectlyInBExpr) { - switch (LT(1)) { - // ambiguity with unary operator - case IToken.tPLUS: case IToken.tMINUS: - case IToken.tSTAR: case IToken.tAMPER: - case IToken.tAND: + switch (LT(1)) { + // ambiguity with unary operator + case IToken.tPLUS: + case IToken.tMINUS: + case IToken.tSTAR: + case IToken.tAMPER: + case IToken.tAND: final int operatorOffset = LA(1).getOffset(); - IToken markEnd= mark(); - backup(mark); - try { - IASTExpression unary= unaryExpression(CastExprCtx.eInBExpr, strat); + IToken markEnd = mark(); + backup(mark); + try { + IASTExpression unary = unaryExpression(CastExprCtx.eInBExpr, strat); return new CastAmbiguityMarker(unary, typeId, operatorOffset); - } catch (BacktrackException bt) { - backup(markEnd); - unaryFailed= true; - } - } + } catch (BacktrackException bt) { + backup(markEnd); + unaryFailed = true; + } + } } try { - boolean couldBeFunctionCall= LT(1) == IToken.tLPAREN; - IASTExpression rhs= castExpression(ctx, strat); + boolean couldBeFunctionCall = LT(1) == IToken.tLPAREN; + IASTExpression rhs = castExpression(ctx, strat); - CastAmbiguityMarker ca= null; + CastAmbiguityMarker ca = null; if (rhs instanceof CastAmbiguityMarker) { - ca= (CastAmbiguityMarker) rhs; - rhs= ca.getExpression(); + ca = (CastAmbiguityMarker) rhs; + rhs = ca.getExpression(); assert !(rhs instanceof CastAmbiguityMarker); } - IASTCastExpression result = buildCastExpression(IASTCastExpression.op_cast, - typeId, rhs, startingOffset, calculateEndOffset(rhs)); + IASTCastExpression result = buildCastExpression(IASTCastExpression.op_cast, typeId, rhs, + startingOffset, calculateEndOffset(rhs)); if (!unaryFailed && couldBeFunctionCall && !(rhs instanceof IASTCastExpression)) { - IToken markEnd= mark(); + IToken markEnd = mark(); backup(mark); try { - IASTExpression expr= primaryExpression(ctx, strat); - IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, (IASTExpression[]) null); - IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, fcall); + IASTExpression expr = primaryExpression(ctx, strat); + IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, + (IASTExpression[]) null); + IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, + fcall); ((ASTNode) ambiguity).setOffsetAndLength((ASTNode) result); return ca == null ? ambiguity : ca.updateExpression(ambiguity); } catch (BacktrackException bt) { @@ -1321,36 +1338,37 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { backup(mark); } return unaryExpression(ctx, strat); - } + } - protected abstract IASTTranslationUnit getTranslationUnit(); + protected abstract IASTTranslationUnit getTranslationUnit(); protected abstract void setupTranslationUnit() throws Exception; protected void translationUnit() { - try { - setupTranslationUnit(); - } catch (Exception e) { - logException("translationUnit::createCompilationUnit()", e); //$NON-NLS-1$ - return; - } - parseTranslationUnit(); - } + try { + setupTranslationUnit(); + } catch (Exception e) { + logException("translationUnit::createCompilationUnit()", e); //$NON-NLS-1$ + return; + } + parseTranslationUnit(); + } protected void parseTranslationUnit() { - final IASTTranslationUnit tu= getTranslationUnit(); + final IASTTranslationUnit tu = getTranslationUnit(); declarationList(tu, DeclarationOptions.GLOBAL, false, 0); } - protected final void declarationListInBraces(final IASTDeclarationListOwner tu, int offset, DeclarationOptions options) throws EndOfFileException, BacktrackException { + protected final void declarationListInBraces(final IASTDeclarationListOwner tu, int offset, + DeclarationOptions options) throws EndOfFileException, BacktrackException { // consume brace, if requested - int codeBranchNesting= getCodeBranchNesting(); + int codeBranchNesting = getCodeBranchNesting(); consume(IToken.tLBRACE); declarationList(tu, options, true, codeBranchNesting); final int lt1 = LTcatchEOF(1); if (lt1 == IToken.tRBRACE) { - int endOffset= consume().getEndOffset(); + int endOffset = consume().getEndOffset(); setRange(tu, offset, endOffset); return; } @@ -1363,10 +1381,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { throwBacktrack(createProblem(IProblem.SYNTAX_ERROR, endOffset, 0), tu); } - private final void declarationList(final IASTDeclarationListOwner tu, DeclarationOptions options, boolean upToBrace, int codeBranchNesting) { - final boolean wasActive= isActiveCode(); + private final void declarationList(final IASTDeclarationListOwner tu, DeclarationOptions options, boolean upToBrace, + int codeBranchNesting) { + final boolean wasActive = isActiveCode(); while (true) { - final boolean ok= acceptInactiveCodeBoundary(codeBranchNesting); + final boolean ok = acceptInactiveCodeBoundary(codeBranchNesting); if (!ok) { // We left to an enclosing code branch. If we started in inactive code, it's time to leave. if (!wasActive) @@ -1379,14 +1398,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } catch (OffsetLimitReachedException e) { return; } - codeBranchNesting= Math.min(getCodeBranchNesting() + 1, codeBranchNesting); + codeBranchNesting = Math.min(getCodeBranchNesting() + 1, codeBranchNesting); // We could be at the start of inactive code so restart the loop. continue; } - final boolean active= isActiveCode(); - IToken next= LAcatchEOF(1); + final boolean active = isActiveCode(); + IToken next = LAcatchEOF(1); if (next == null || next.getType() == IToken.tEOC) return; @@ -1395,27 +1414,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } final int offset = next.getOffset(); - declarationMark= next; - next= null; // Don't hold on to the token while parsing namespaces, class bodies, etc. + declarationMark = next; + next = null; // Don't hold on to the token while parsing namespaces, class bodies, etc. try { - IASTDeclaration declaration= declaration(options); + IASTDeclaration declaration = declaration(options); if (((ASTNode) declaration).getLength() == 0 && LTcatchEOF(1) != IToken.tEOC) { - declaration= skipProblemDeclaration(offset); + declaration = skipProblemDeclaration(offset); } addDeclaration(tu, declaration, active); } catch (BacktrackException bt) { - IASTDeclaration[] decls= problemDeclaration(offset, bt, options); + IASTDeclaration[] decls = problemDeclaration(offset, bt, options); for (IASTDeclaration declaration : decls) { addDeclaration(tu, declaration, active); } } catch (EndOfFileException e) { - IASTDeclaration declaration= skipProblemDeclaration(offset); + IASTDeclaration declaration = skipProblemDeclaration(offset); addDeclaration(tu, declaration, active); if (!e.endsInactiveCode()) { break; } } finally { - declarationMark= null; + declarationMark = null; } } } @@ -1428,245 +1447,250 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { parent.addDeclaration(declaration); } - abstract protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset); + abstract protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, + IASTInitializerClause expr2, int lastOffset); - private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, - final IASTTypeId typeid, int unaryOperator, int unaryOpOffset) { - IASTUnaryExpression unary= nodeFactory.newUnaryExpression(unaryOperator, null); + private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, final IASTTypeId typeid, + int unaryOperator, int unaryOpOffset) { + IASTUnaryExpression unary = nodeFactory.newUnaryExpression(unaryOperator, null); ((ASTNode) unary).setOffset(unaryOpOffset); IASTCastExpression castExpr = buildCastExpression(IASTCastExpression.op_cast, typeid, unary, 0, 0); - IASTExpression result= createAmbiguousBinaryVsCastExpression(expr, castExpr); + IASTExpression result = createAmbiguousBinaryVsCastExpression(expr, castExpr); ((ASTNode) result).setOffsetAndLength((ASTNode) expr); return result; } - protected IASTExpression unaryExpression(int operator, CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { - final IToken operatorToken= consume(); - IASTExpression operand= castExpression(ctx, strat); + protected IASTExpression unaryExpression(int operator, CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { + final IToken operatorToken = consume(); + IASTExpression operand = castExpression(ctx, strat); - CastAmbiguityMarker ca= null; + CastAmbiguityMarker ca = null; if (operand instanceof CastAmbiguityMarker) { - ca= (CastAmbiguityMarker) operand; - operand= ca.getExpression(); + ca = (CastAmbiguityMarker) operand; + operand = ca.getExpression(); assert !(operand instanceof CastAmbiguityMarker); } - if (operator == IASTUnaryExpression.op_star && operand instanceof IASTLiteralExpression) { - IASTLiteralExpression lit= (IASTLiteralExpression) operand; - switch (lit.getKind()) { - case IASTLiteralExpression.lk_char_constant: - case IASTLiteralExpression.lk_float_constant: - case IASTLiteralExpression.lk_integer_constant: - case IASTLiteralExpression.lk_true: - case IASTLiteralExpression.lk_false: - case IASTLiteralExpression.lk_nullptr: + if (operator == IASTUnaryExpression.op_star && operand instanceof IASTLiteralExpression) { + IASTLiteralExpression lit = (IASTLiteralExpression) operand; + switch (lit.getKind()) { + case IASTLiteralExpression.lk_char_constant: + case IASTLiteralExpression.lk_float_constant: + case IASTLiteralExpression.lk_integer_constant: + case IASTLiteralExpression.lk_true: + case IASTLiteralExpression.lk_false: + case IASTLiteralExpression.lk_nullptr: throwBacktrack(operatorToken); - } - } - - IASTExpression result= buildUnaryExpression(operator, operand, operatorToken.getOffset(), calculateEndOffset(operand)); - return ca == null ? result : ca.updateExpression(result); - } - - protected IASTExpression buildUnaryExpression(int operator, IASTExpression operand, int offset, int lastOffset) { - IASTUnaryExpression result = nodeFactory.newUnaryExpression(operator, operand); - setRange(result, offset, lastOffset); - return result; - } - - protected IASTStatement handleFunctionBody() throws BacktrackException, EndOfFileException { - declarationMark= null; - if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { - int offset = LA(1).getOffset(); - IToken last = skipOverCompoundStatement(true); - IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); - setRange(cs, offset, last.getEndOffset()); - return cs; - } else if (mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE) { - if (scanner.isOnTopContext()) - return functionBody(); - int offset = LA(1).getOffset(); - IToken last = skipOverCompoundStatement(true); - IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); - setRange(cs, offset, last.getEndOffset()); - return cs; - } - - // full parse - return functionBody(); - } - - /** - * Parses a function body. - * - * @return the compound statement representing the function body. - * @throws BacktrackException - * request a backtrack - */ - protected IASTCompoundStatement functionBody() throws EndOfFileException, BacktrackException { - return compoundStatement(); - } - - protected abstract IASTDeclarator initDeclarator(IASTDeclSpecifier declSpec, DeclarationOptions option) - throws EndOfFileException, BacktrackException, FoundAggregateInitializer; - - /** - * Parse an enumeration specifier, as according to the ANSI specs in C & - * C++. enumSpecifier: "enum" (name)? "{" (enumerator-list) "}" - * enumerator-list: enumerator-definition enumerator-list , - * enumerator-definition enumerator-definition: enumerator enumerator = - * constant-expression enumerator: identifier - * - * @throws BacktrackException request a backtrack - */ - protected IASTEnumerationSpecifier enumSpecifier() throws BacktrackException, EndOfFileException { - final IToken mark= mark(); - final int offset= consume().getOffset(); - - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - - IASTName name; - if (LT(1) == IToken.tIDENTIFIER) { - name= identifier(); - } else { - name= nodeFactory.newName(); - } - - if (LT(1) != IToken.tLBRACE) { - backup(mark); - throwBacktrack(mark); - } - - final IASTEnumerationSpecifier result= nodeFactory.newEnumerationSpecifier(name); - - int endOffset= enumBody(result); - return setRange(result, offset, endOffset); - } + } + } + + IASTExpression result = buildUnaryExpression(operator, operand, operatorToken.getOffset(), + calculateEndOffset(operand)); + return ca == null ? result : ca.updateExpression(result); + } + + protected IASTExpression buildUnaryExpression(int operator, IASTExpression operand, int offset, int lastOffset) { + IASTUnaryExpression result = nodeFactory.newUnaryExpression(operator, operand); + setRange(result, offset, lastOffset); + return result; + } + + protected IASTStatement handleFunctionBody() throws BacktrackException, EndOfFileException { + declarationMark = null; + if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { + int offset = LA(1).getOffset(); + IToken last = skipOverCompoundStatement(true); + IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); + setRange(cs, offset, last.getEndOffset()); + return cs; + } else if (mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE) { + if (scanner.isOnTopContext()) + return functionBody(); + int offset = LA(1).getOffset(); + IToken last = skipOverCompoundStatement(true); + IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); + setRange(cs, offset, last.getEndOffset()); + return cs; + } + + // full parse + return functionBody(); + } + + /** + * Parses a function body. + * + * @return the compound statement representing the function body. + * @throws BacktrackException + * request a backtrack + */ + protected IASTCompoundStatement functionBody() throws EndOfFileException, BacktrackException { + return compoundStatement(); + } + + protected abstract IASTDeclarator initDeclarator(IASTDeclSpecifier declSpec, DeclarationOptions option) + throws EndOfFileException, BacktrackException, FoundAggregateInitializer; + + /** + * Parse an enumeration specifier, as according to the ANSI specs in C & + * C++. enumSpecifier: "enum" (name)? "{" (enumerator-list) "}" + * enumerator-list: enumerator-definition enumerator-list , + * enumerator-definition enumerator-definition: enumerator enumerator = + * constant-expression enumerator: identifier + * + * @throws BacktrackException request a backtrack + */ + protected IASTEnumerationSpecifier enumSpecifier() throws BacktrackException, EndOfFileException { + final IToken mark = mark(); + final int offset = consume().getOffset(); + + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + + IASTName name; + if (LT(1) == IToken.tIDENTIFIER) { + name = identifier(); + } else { + name = nodeFactory.newName(); + } + + if (LT(1) != IToken.tLBRACE) { + backup(mark); + throwBacktrack(mark); + } + + final IASTEnumerationSpecifier result = nodeFactory.newEnumerationSpecifier(name); + + int endOffset = enumBody(result); + return setRange(result, offset, endOffset); + } protected int enumBody(final IASTEnumerationSpecifier result) throws EndOfFileException, BacktrackException { - boolean needComma= false; - int endOffset= consume(IToken.tLBRACE).getEndOffset(); // IToken.tLBRACE - int problemOffset= endOffset; - try { - loop: while (true) { - switch (LTcatchEOF(1)) { - case 0: // eof - endOffset= getEndOffset(); - break loop; - case IToken.tRBRACE: - endOffset= consume().getEndOffset(); - break loop; - case IToken.tEOC: - break loop; - case IToken.tCOMMA: - if (!needComma) { - problemOffset= LA(1).getOffset(); - throw backtrack; - } - endOffset= consume().getEndOffset(); - needComma= false; - continue loop; - case IToken.tIDENTIFIER: - case IToken.tCOMPLETION: - problemOffset= LA(1).getOffset(); - if (needComma) - throw backtrack; - - final IASTName etorName= identifier(); - final IASTEnumerator enumerator= nodeFactory.newEnumerator(etorName, null); - - List<IASTAttributeSpecifier> attributes = anyAttributes(supportAttributeSpecifiers, supportDeclspecSpecifiers); + boolean needComma = false; + int endOffset = consume(IToken.tLBRACE).getEndOffset(); // IToken.tLBRACE + int problemOffset = endOffset; + try { + loop: while (true) { + switch (LTcatchEOF(1)) { + case 0: // eof + endOffset = getEndOffset(); + break loop; + case IToken.tRBRACE: + endOffset = consume().getEndOffset(); + break loop; + case IToken.tEOC: + break loop; + case IToken.tCOMMA: + if (!needComma) { + problemOffset = LA(1).getOffset(); + throw backtrack; + } + endOffset = consume().getEndOffset(); + needComma = false; + continue loop; + case IToken.tIDENTIFIER: + case IToken.tCOMPLETION: + problemOffset = LA(1).getOffset(); + if (needComma) + throw backtrack; + + final IASTName etorName = identifier(); + final IASTEnumerator enumerator = nodeFactory.newEnumerator(etorName, null); + + List<IASTAttributeSpecifier> attributes = anyAttributes(supportAttributeSpecifiers, + supportDeclspecSpecifiers); addAttributeSpecifiers(attributes, enumerator); endOffset = attributesEndOffset(calculateEndOffset(etorName), attributes); setRange(enumerator, problemOffset, endOffset); - result.addEnumerator(enumerator); - if (LTcatchEOF(1) == IToken.tASSIGN) { - problemOffset= consume().getOffset(); - final IASTExpression value= constantExpression(); - enumerator.setValue(value); - adjustLength(enumerator, value); - endOffset= calculateEndOffset(value); - } - needComma= true; - continue loop; - default: - problemOffset= LA(1).getOffset(); - throw backtrack; - } - } - } catch (EndOfFileException eof) { - throwBacktrack(createProblem(IProblem.SYNTAX_ERROR, problemOffset, getEndOffset()-problemOffset), result); - } catch (BacktrackException bt) { - IASTProblem problem= skipProblemEnumerator(problemOffset); - throwBacktrack(problem, result); - } - return endOffset; - } - - protected abstract IASTStatement statement() throws EndOfFileException, BacktrackException; - - protected IASTExpression condition(boolean followedByParenthesis) throws BacktrackException, EndOfFileException { - IToken mark= mark(); - try { - IASTExpression expr= expression(); - if (!followedByParenthesis) - return expr; - - switch (LT(1)) { - case IToken.tEOC: - case IToken.tRPAREN: - return expr; - } - } catch (BacktrackException b) { - if (!followedByParenthesis) - throw b; - } + result.addEnumerator(enumerator); + if (LTcatchEOF(1) == IToken.tASSIGN) { + problemOffset = consume().getOffset(); + final IASTExpression value = constantExpression(); + enumerator.setValue(value); + adjustLength(enumerator, value); + endOffset = calculateEndOffset(value); + } + needComma = true; + continue loop; + default: + problemOffset = LA(1).getOffset(); + throw backtrack; + } + } + } catch (EndOfFileException eof) { + throwBacktrack(createProblem(IProblem.SYNTAX_ERROR, problemOffset, getEndOffset() - problemOffset), result); + } catch (BacktrackException bt) { + IASTProblem problem = skipProblemEnumerator(problemOffset); + throwBacktrack(problem, result); + } + return endOffset; + } + + protected abstract IASTStatement statement() throws EndOfFileException, BacktrackException; + + protected IASTExpression condition(boolean followedByParenthesis) throws BacktrackException, EndOfFileException { + IToken mark = mark(); + try { + IASTExpression expr = expression(); + if (!followedByParenthesis) + return expr; + + switch (LT(1)) { + case IToken.tEOC: + case IToken.tRPAREN: + return expr; + } + } catch (BacktrackException b) { + if (!followedByParenthesis) + throw b; + } backup(mark); return skipProblemConditionInParenthesis(mark.getOffset()); - } + } - @Override + @Override public boolean encounteredError() { - return !parsePassed; - } - - protected abstract IASTDeclaration declaration(DeclarationOptions option) throws BacktrackException, EndOfFileException; - - protected Decl declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException { - return declSpecifierSeq(option, null); - } - - /** - * Parses for two alternatives of a declspec sequence. If there is a second alternative the token after the second alternative - * is returned, such that the parser can continue after both variants. - */ - protected abstract Decl declSpecifierSeq(DeclarationOptions option, ITemplateIdStrategy strat) - throws BacktrackException, EndOfFileException; - - protected Decl declSpecifierSequence_initDeclarator(final DeclarationOptions option, - boolean acceptCompoundWithoutDtor) + return !parsePassed; + } + + protected abstract IASTDeclaration declaration(DeclarationOptions option) + throws BacktrackException, EndOfFileException; + + protected Decl declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException { + return declSpecifierSeq(option, null); + } + + /** + * Parses for two alternatives of a declspec sequence. If there is a second alternative the token after the second alternative + * is returned, such that the parser can continue after both variants. + */ + protected abstract Decl declSpecifierSeq(DeclarationOptions option, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException; + + protected Decl declSpecifierSequence_initDeclarator(final DeclarationOptions option, + boolean acceptCompoundWithoutDtor) throws EndOfFileException, FoundAggregateInitializer, BacktrackException { - return declSpecifierSequence_initDeclarator(option, acceptCompoundWithoutDtor, null); - } - - /** - * Parses for two alternatives of a declspec sequence followed by a initDeclarator. - * A second alternative is accepted only, if it ends at the same point of the first alternative. Otherwise the - * longer alternative is selected. - */ - protected Decl declSpecifierSequence_initDeclarator(final DeclarationOptions option, - boolean acceptCompoundWithoutDtor, ITemplateIdStrategy strat) + return declSpecifierSequence_initDeclarator(option, acceptCompoundWithoutDtor, null); + } + + /** + * Parses for two alternatives of a declspec sequence followed by a initDeclarator. + * A second alternative is accepted only, if it ends at the same point of the first alternative. Otherwise the + * longer alternative is selected. + */ + protected Decl declSpecifierSequence_initDeclarator(final DeclarationOptions option, + boolean acceptCompoundWithoutDtor, ITemplateIdStrategy strat) throws EndOfFileException, FoundAggregateInitializer, BacktrackException { - Decl result= declSpecifierSeq(option, strat); + Decl result = declSpecifierSeq(option, strat); final int lt1 = LTcatchEOF(1); if (lt1 == IToken.tEOC) return result; - // support simple declarations without declarators - final boolean acceptEmpty = acceptCompoundWithoutDtor && isLegalWithoutDtor(result.fDeclSpec1); + // support simple declarations without declarators + final boolean acceptEmpty = acceptCompoundWithoutDtor && isLegalWithoutDtor(result.fDeclSpec1); if (acceptEmpty) { switch (lt1) { case 0: @@ -1676,54 +1700,54 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } } - final IToken dtorMark1= mark(); - final IToken dtorMark2= result.fDtorToken1; - final IASTDeclSpecifier declspec1= result.fDeclSpec1; - final IASTDeclSpecifier declspec2= result.fDeclSpec2; + final IToken dtorMark1 = mark(); + final IToken dtorMark2 = result.fDtorToken1; + final IASTDeclSpecifier declspec1 = result.fDeclSpec1; + final IASTDeclSpecifier declspec2 = result.fDeclSpec2; IASTDeclarator dtor1, dtor2; try { // declarator for first variant - dtor1= initDeclarator(declspec1, option); - } catch (BacktrackException e) { + dtor1 = initDeclarator(declspec1, option); + } catch (BacktrackException e) { if (acceptEmpty) { backup(dtorMark1); - dtor1= null; + dtor1 = null; } else { // try second variant, if possible if (dtorMark2 == null) throw e; backup(dtorMark2); - dtor2= initDeclarator(declspec2, option); + dtor2 = initDeclarator(declspec2, option); return result.set(declspec2, dtor2, dtorMark2); } } - // first variant was a success. If possible, try second one. + // first variant was a success. If possible, try second one. if (dtorMark2 == null) { return result.set(declspec1, dtor1, dtorMark1); } - final IToken end1= mark(); - backup(dtorMark2); - try { - dtor2= initDeclarator(declspec2, option); - } catch (BacktrackException e) { - backup(end1); - return result.set(declspec1, dtor1, dtorMark1); - } + final IToken end1 = mark(); + backup(dtorMark2); + try { + dtor2 = initDeclarator(declspec2, option); + } catch (BacktrackException e) { + backup(end1); + return result.set(declspec1, dtor1, dtorMark1); + } - final IToken end2= mark(); - if (end1 == end2) { + final IToken end2 = mark(); + if (end1 == end2) { return result.set(declspec1, dtor1, declspec2, dtor2); } if (end1.getEndOffset() > end2.getEndOffset()) { - backup(end1); - return result.set(declspec1, dtor1, dtorMark1); + backup(end1); + return result.set(declspec1, dtor1, dtorMark1); } return result.set(declspec2, dtor2, dtorMark2); - } + } protected boolean isLegalWithoutDtor(IASTDeclSpecifier declSpec) { if (declSpec instanceof IASTCompositeTypeSpecifier) @@ -1736,115 +1760,116 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return false; } - protected IASTDeclaration[] problemDeclaration(int offset, BacktrackException bt, DeclarationOptions option) { - failParse(); - IASTProblem origProblem= createProblem(bt); - - // a node was detected by assuming additional tokens (e.g. missing semicolon) - IASTNode n= bt.getNodeBeforeProblem(); - if (n instanceof IASTDeclaration) { - IToken la1= LAcatchEOF(1); - if (la1 == null || la1.getOffset() > offset) { - declarationMark= null; - return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)}; - } - } - - if (declarationMark != null && isActiveCode()) { - IASTDeclaration trailingProblem= null; - offset= declarationMark.getOffset(); - - // try to skip identifiers (undefined macros?) - IASTDeclaration decl= null; - int endOffset= 0; - loop: while (declarationMark != null && declarationMark.getType() == IToken.tIDENTIFIER) { - endOffset= declarationMark.getEndOffset(); - declarationMark= declarationMark.getNext(); - if (declarationMark != null) { - backup(declarationMark); - // avoid creating an empty declaration - switch (LTcatchEOF(1)) { - case 0: // eof - case IToken.tEOC: - case IToken.tSEMI: - break loop; - } - try { - decl= declaration(option); - break; - } catch (BacktrackException bt2) { - n= bt2.getNodeBeforeProblem(); - if (n instanceof IASTDeclaration) { - decl= (IASTDeclaration) n; - trailingProblem= buildProblemDeclaration(bt2.getProblem()); - break; - } - } catch (EndOfFileException e) { - endOffset= getEndOffset(); - break; - } - } - } - declarationMark= null; - - if (decl != null) { - IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); - IASTDeclaration pd= buildProblemDeclaration(problem); - if (trailingProblem != null) - return new IASTDeclaration[] {pd, decl, trailingProblem}; - return new IASTDeclaration[] {pd, decl}; - } - } - - return new IASTDeclaration[] {skipProblemDeclaration(offset, origProblem)}; - } + protected IASTDeclaration[] problemDeclaration(int offset, BacktrackException bt, DeclarationOptions option) { + failParse(); + IASTProblem origProblem = createProblem(bt); + + // a node was detected by assuming additional tokens (e.g. missing semicolon) + IASTNode n = bt.getNodeBeforeProblem(); + if (n instanceof IASTDeclaration) { + IToken la1 = LAcatchEOF(1); + if (la1 == null || la1.getOffset() > offset) { + declarationMark = null; + return new IASTDeclaration[] { (IASTDeclaration) n, buildProblemDeclaration(origProblem) }; + } + } + + if (declarationMark != null && isActiveCode()) { + IASTDeclaration trailingProblem = null; + offset = declarationMark.getOffset(); + + // try to skip identifiers (undefined macros?) + IASTDeclaration decl = null; + int endOffset = 0; + loop: while (declarationMark != null && declarationMark.getType() == IToken.tIDENTIFIER) { + endOffset = declarationMark.getEndOffset(); + declarationMark = declarationMark.getNext(); + if (declarationMark != null) { + backup(declarationMark); + // avoid creating an empty declaration + switch (LTcatchEOF(1)) { + case 0: // eof + case IToken.tEOC: + case IToken.tSEMI: + break loop; + } + try { + decl = declaration(option); + break; + } catch (BacktrackException bt2) { + n = bt2.getNodeBeforeProblem(); + if (n instanceof IASTDeclaration) { + decl = (IASTDeclaration) n; + trailingProblem = buildProblemDeclaration(bt2.getProblem()); + break; + } + } catch (EndOfFileException e) { + endOffset = getEndOffset(); + break; + } + } + } + declarationMark = null; + + if (decl != null) { + IASTProblem problem = createProblem(IProblem.SYNTAX_ERROR, offset, endOffset - offset); + IASTDeclaration pd = buildProblemDeclaration(problem); + if (trailingProblem != null) + return new IASTDeclaration[] { pd, decl, trailingProblem }; + return new IASTDeclaration[] { pd, decl }; + } + } + + return new IASTDeclaration[] { skipProblemDeclaration(offset, origProblem) }; + } protected IASTDeclaration asmDeclaration() throws EndOfFileException, BacktrackException { - final int offset= consume().getOffset(); // t_asm - if (LT(1) == IToken.t_volatile) { - consume(); - } + final int offset = consume().getOffset(); // t_asm + if (LT(1) == IToken.t_volatile) { + consume(); + } - if (supportFunctionStyleAsm && LT(1) != IToken.tLPAREN) { - return functionStyleAsmDeclaration(); - } + if (supportFunctionStyleAsm && LT(1) != IToken.tLPAREN) { + return functionStyleAsmDeclaration(); + } - StringBuilder buffer= new StringBuilder(); - asmExpression(buffer); - int lastOffset = consume(IToken.tSEMI).getEndOffset(); + StringBuilder buffer = new StringBuilder(); + asmExpression(buffer); + int lastOffset = consume(IToken.tSEMI).getEndOffset(); - return buildASMDirective(offset, buffer.toString(), lastOffset); - } + return buildASMDirective(offset, buffer.toString(), lastOffset); + } protected IASTDeclaration functionStyleAsmDeclaration() throws BacktrackException, EndOfFileException { - final int offset= LA(1).getOffset(); + final int offset = LA(1).getOffset(); IASTDeclSpecifier declSpec; IASTDeclarator dtor; - try { - Decl decl= declSpecifierSequence_initDeclarator(DeclarationOptions.FUNCTION_STYLE_ASM, false); - declSpec= decl.fDeclSpec1; - dtor= decl.fDtor1; - } catch (FoundAggregateInitializer lie) { - declSpec= lie.fDeclSpec; - dtor= addInitializer(lie, DeclarationOptions.FUNCTION_STYLE_ASM); - } + try { + Decl decl = declSpecifierSequence_initDeclarator(DeclarationOptions.FUNCTION_STYLE_ASM, false); + declSpec = decl.fDeclSpec1; + dtor = decl.fDtor1; + } catch (FoundAggregateInitializer lie) { + declSpec = lie.fDeclSpec; + dtor = addInitializer(lie, DeclarationOptions.FUNCTION_STYLE_ASM); + } - if (LT(1) != IToken.tLBRACE) - throwBacktrack(LA(1)); + if (LT(1) != IToken.tLBRACE) + throwBacktrack(LA(1)); - final IASTDeclarator fdtor= ASTQueries.findTypeRelevantDeclarator(dtor); - if (!(fdtor instanceof IASTFunctionDeclarator)) - throwBacktrack(offset, LA(1).getEndOffset() - offset); + final IASTDeclarator fdtor = ASTQueries.findTypeRelevantDeclarator(dtor); + if (!(fdtor instanceof IASTFunctionDeclarator)) + throwBacktrack(offset, LA(1).getEndOffset() - offset); - final int compoundOffset= LA(1).getOffset(); - final int endOffset= skipOverCompoundStatement(false).getEndOffset(); - IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); //createCompoundStatement(); - ((ASTNode) cs).setOffsetAndLength(compoundOffset, endOffset - compoundOffset); + final int compoundOffset = LA(1).getOffset(); + final int endOffset = skipOverCompoundStatement(false).getEndOffset(); + IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); //createCompoundStatement(); + ((ASTNode) cs).setOffsetAndLength(compoundOffset, endOffset - compoundOffset); - IASTFunctionDefinition funcDefinition = nodeFactory.newFunctionDefinition(declSpec, (IASTFunctionDeclarator) fdtor, cs); - ((ASTNode) funcDefinition).setOffsetAndLength(offset, endOffset - offset); + IASTFunctionDefinition funcDefinition = nodeFactory.newFunctionDefinition(declSpec, + (IASTFunctionDeclarator) fdtor, cs); + ((ASTNode) funcDefinition).setOffsetAndLength(offset, endOffset - offset); - return funcDefinition; + return funcDefinition; } protected abstract IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions options) @@ -1852,520 +1877,522 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected IASTDeclarator addInitializer(FoundAggregateInitializer e, DeclarationOptions options) throws EndOfFileException, BacktrackException { - final IASTDeclarator d = e.fDeclarator; - IASTInitializer i = optionalInitializer(d, options); - if (i != null) { - d.setInitializer(i); - ((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset()); - } + final IASTDeclarator d = e.fDeclarator; + IASTInitializer i = optionalInitializer(d, options); + if (i != null) { + d.setInitializer(i); + ((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset()); + } return d; - } + } protected IToken asmExpression(StringBuilder content) throws EndOfFileException, BacktrackException { - IToken t= consume(IToken.tLPAREN); - boolean needspace= false; - int open= 1; - while (open > 0) { - t= consume(); + IToken t = consume(IToken.tLPAREN); + boolean needspace = false; + int open = 1; + while (open > 0) { + t = consume(); switch (t.getType()) { case IToken.tLPAREN: open++; break; - case IToken.tRPAREN: - open--; - break; - case IToken.tEOC: - throw new EndOfFileException(t.getOffset()); - - default: - if (content != null) { - if (needspace) { - content.append(' '); - } - content.append(t.getCharImage()); - needspace= true; - } - break; + case IToken.tRPAREN: + open--; + break; + case IToken.tEOC: + throw new EndOfFileException(t.getOffset()); + + default: + if (content != null) { + if (needspace) { + content.append(' '); + } + content.append(t.getCharImage()); + needspace = true; + } + break; } - } + } return t; } - protected IASTASMDeclaration buildASMDirective(int offset, String assembly, int lastOffset) { - IASTASMDeclaration result = nodeFactory.newASMDeclaration(assembly); - ((ASTNode) result).setOffsetAndLength(offset, lastOffset - offset); - return result; - } - - protected IASTCastExpression buildCastExpression(int op, IASTTypeId typeId, - IASTExpression operand, int offset, int endOffset) { - IASTCastExpression result = nodeFactory.newCastExpression(op, typeId, operand); - ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); - return result; - } - - /** - * There are many ambiguities in C and C++ between expressions and declarations. - * This method will attempt to parse a statement as both an expression and a declaration, - * if both parses succeed then an ambiguity node is returned. - */ - protected IASTStatement parseDeclarationOrExpressionStatement() throws EndOfFileException, BacktrackException { - return parseDeclarationOrExpressionStatement(null); - } - - protected IASTStatement parseDeclarationOrExpressionStatement(List<IASTAttributeSpecifier> attributeSpecifiers) - throws EndOfFileException, BacktrackException { - // First attempt to parse an expressionStatement - // Note: the function style cast ambiguity is handled in expression - // Since it only happens when we are in a statement - IToken mark = mark(); - IASTExpressionStatement expressionStatement = null; - IToken afterExpression = null; - boolean foundSemicolon= false; - try { - IASTExpression expression = expression(); - expressionStatement = nodeFactory.newExpressionStatement(expression); - addAttributeSpecifiers(attributeSpecifiers, expressionStatement); - setRange(expressionStatement, expression); - afterExpression= LA(); - - IToken semi= consumeOrEOC(IToken.tSEMI); - foundSemicolon= true; - adjustEndOffset(expressionStatement, semi.getEndOffset()); - afterExpression= LA(); - } catch (BacktrackException b) { - } - - backup(mark); - - // Now attempt to parse a declarationStatement - IASTDeclarationStatement ds = null; - try { - IASTDeclaration d = declaration(DeclarationOptions.LOCAL); - if (d instanceof IASTAttributeOwner) { - addAttributeSpecifiers(attributeSpecifiers, (IASTAttributeOwner) d); - } - ds = nodeFactory.newDeclarationStatement(d); - setRange(ds, d); - } catch (BacktrackException b) { - IASTNode node = b.getNodeBeforeProblem(); - final boolean isProblemDecl = node instanceof IASTDeclaration; - if (expressionStatement == null - || (!foundSemicolon && isProblemDecl && node.contains(expressionStatement))) { + protected IASTASMDeclaration buildASMDirective(int offset, String assembly, int lastOffset) { + IASTASMDeclaration result = nodeFactory.newASMDeclaration(assembly); + ((ASTNode) result).setOffsetAndLength(offset, lastOffset - offset); + return result; + } + + protected IASTCastExpression buildCastExpression(int op, IASTTypeId typeId, IASTExpression operand, int offset, + int endOffset) { + IASTCastExpression result = nodeFactory.newCastExpression(op, typeId, operand); + ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); + return result; + } + + /** + * There are many ambiguities in C and C++ between expressions and declarations. + * This method will attempt to parse a statement as both an expression and a declaration, + * if both parses succeed then an ambiguity node is returned. + */ + protected IASTStatement parseDeclarationOrExpressionStatement() throws EndOfFileException, BacktrackException { + return parseDeclarationOrExpressionStatement(null); + } + + protected IASTStatement parseDeclarationOrExpressionStatement(List<IASTAttributeSpecifier> attributeSpecifiers) + throws EndOfFileException, BacktrackException { + // First attempt to parse an expressionStatement + // Note: the function style cast ambiguity is handled in expression + // Since it only happens when we are in a statement + IToken mark = mark(); + IASTExpressionStatement expressionStatement = null; + IToken afterExpression = null; + boolean foundSemicolon = false; + try { + IASTExpression expression = expression(); + expressionStatement = nodeFactory.newExpressionStatement(expression); + addAttributeSpecifiers(attributeSpecifiers, expressionStatement); + setRange(expressionStatement, expression); + afterExpression = LA(); + + IToken semi = consumeOrEOC(IToken.tSEMI); + foundSemicolon = true; + adjustEndOffset(expressionStatement, semi.getEndOffset()); + afterExpression = LA(); + } catch (BacktrackException b) { + } + + backup(mark); + + // Now attempt to parse a declarationStatement + IASTDeclarationStatement ds = null; + try { + IASTDeclaration d = declaration(DeclarationOptions.LOCAL); + if (d instanceof IASTAttributeOwner) { + addAttributeSpecifiers(attributeSpecifiers, (IASTAttributeOwner) d); + } + ds = nodeFactory.newDeclarationStatement(d); + setRange(ds, d); + } catch (BacktrackException b) { + IASTNode node = b.getNodeBeforeProblem(); + final boolean isProblemDecl = node instanceof IASTDeclaration; + if (expressionStatement == null + || (!foundSemicolon && isProblemDecl && node.contains(expressionStatement))) { if (isProblemDecl) { - ds= nodeFactory.newDeclarationStatement((IASTDeclaration) node); - b.initialize(b.getProblem(), setRange(ds, node)); - } - throw b; - } - } - - if (ds == null) { - backup(afterExpression); - if (foundSemicolon) - return expressionStatement; - - throwBacktrack(createProblem(IProblem.MISSING_SEMICOLON, calculateEndOffset(expressionStatement)-1, 1), expressionStatement); - return null; // Hint for java-compiler - } - - if (expressionStatement == null || !foundSemicolon) { - return ds; - } - - // At this point we know we have an ambiguity. - // Attempt to resolve some ambiguities that are easy to detect. - - // A * B = C; // A*B cannot be a lvalue. - // foo() = x; // foo() cannot be a lvalue in c, in c++ it can. - if (expressionStatement.getExpression() instanceof IASTBinaryExpression) { - IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement.getExpression(); - if (exp.getOperator() == IASTBinaryExpression.op_assign) { - IASTExpression lhs = exp.getOperand1(); - if (lhs instanceof IASTBinaryExpression - && ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_multiply) { - return ds; - } - if (lhs instanceof IASTFunctionCallExpression && !functionCallCanBeLValue) { - return ds; - } - } - } - - final IASTDeclaration declaration = ds.getDeclaration(); + ds = nodeFactory.newDeclarationStatement((IASTDeclaration) node); + b.initialize(b.getProblem(), setRange(ds, node)); + } + throw b; + } + } + + if (ds == null) { + backup(afterExpression); + if (foundSemicolon) + return expressionStatement; + + throwBacktrack(createProblem(IProblem.MISSING_SEMICOLON, calculateEndOffset(expressionStatement) - 1, 1), + expressionStatement); + return null; // Hint for java-compiler + } + + if (expressionStatement == null || !foundSemicolon) { + return ds; + } + + // At this point we know we have an ambiguity. + // Attempt to resolve some ambiguities that are easy to detect. + + // A * B = C; // A*B cannot be a lvalue. + // foo() = x; // foo() cannot be a lvalue in c, in c++ it can. + if (expressionStatement.getExpression() instanceof IASTBinaryExpression) { + IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement.getExpression(); + if (exp.getOperator() == IASTBinaryExpression.op_assign) { + IASTExpression lhs = exp.getOperand1(); + if (lhs instanceof IASTBinaryExpression + && ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_multiply) { + return ds; + } + if (lhs instanceof IASTFunctionCallExpression && !functionCallCanBeLValue) { + return ds; + } + } + } + + final IASTDeclaration declaration = ds.getDeclaration(); if (declaration instanceof IASTSimpleDeclaration) { - final IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration; - IASTDeclSpecifier declspec= simpleDecl.getDeclSpecifier(); - if (declspec instanceof IASTNamedTypeSpecifier) { - final IASTDeclarator[] declarators = simpleDecl.getDeclarators(); - - // x; - // can be parsed as a named declaration specifier without a declarator - if (declarators.length == 0) { + final IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration; + IASTDeclSpecifier declspec = simpleDecl.getDeclSpecifier(); + if (declspec instanceof IASTNamedTypeSpecifier) { + final IASTDeclarator[] declarators = simpleDecl.getDeclarators(); + + // x; + // can be parsed as a named declaration specifier without a declarator + if (declarators.length == 0) { backup(afterExpression); return expressionStatement; - } - } - } - - // create and return ambiguity node - IASTAmbiguousStatement statement = createAmbiguousStatement(); - statement.addStatement(expressionStatement); - statement.addStatement(ds); - return setRange(statement, ds); - } - - /** - * Returns true if the given declaration has unspecified type, - * in this case the type defaults to int and is know as "implicit int". - */ - protected static boolean isImplicitInt(IASTDeclaration declaration) { - if (declaration instanceof IASTSimpleDeclaration) { - IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); - if (declSpec instanceof IASTSimpleDeclSpecifier && - ((IASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified) { - return true; - } - } - return false; - } - - protected abstract IASTAmbiguousStatement createAmbiguousStatement(); - - protected IASTStatement parseLabelStatement() throws EndOfFileException, BacktrackException { - int offset= LA(1).getOffset(); - IASTName name = identifier(); // tIDENTIFIER - consume(IToken.tCOLON); // tCOLON - IASTStatement nestedStatement = statement(); - int lastOffset = calculateEndOffset(nestedStatement); - - IASTLabelStatement label_statement = nodeFactory.newLabelStatement(name, nestedStatement); - setRange(label_statement, offset, lastOffset); - return label_statement; - } - - protected IASTStatement parseNullStatement() throws EndOfFileException, BacktrackException { - IToken t = consume(); // tSEMI - - IASTNullStatement null_statement = nodeFactory.newNullStatement(); - ((ASTNode) null_statement).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); - return null_statement; - } - - protected IASTStatement parseGotoStatement() throws EndOfFileException, BacktrackException { - int startOffset = consume(IToken.t_goto).getOffset(); - IASTStatement gotoStatement = null; - - if (LT(1) == IToken.tSTAR) - { - IASTExpression gotoLabelNameExpression = expression(); - gotoStatement = nodeFactory.newGotoStatement(gotoLabelNameExpression); - } else { - IASTName gotoLabelName = identifier(); - gotoStatement = nodeFactory.newGotoStatement(gotoLabelName); - } - - int lastOffset = consume(IToken.tSEMI).getEndOffset(); - ((ASTNode) gotoStatement).setOffsetAndLength(startOffset, lastOffset - startOffset); - return gotoStatement; - } - - protected IASTStatement parseBreakStatement() throws EndOfFileException, BacktrackException { - int startOffset = consume().getOffset(); // t_break - int lastOffset = consume(IToken.tSEMI).getEndOffset(); - - IASTBreakStatement break_statement = nodeFactory.newBreakStatement(); - ((ASTNode) break_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); - return break_statement; - } - - protected IASTStatement parseSwitchBody() throws EndOfFileException, BacktrackException { - IASTStatement stmt= null; - if (LT(1) != IToken.tEOC) - stmt= statement(); - - if (!(stmt instanceof IASTCaseStatement) && !(stmt instanceof IASTDefaultStatement)) - return stmt; - - // bug 105334, switch without compound statement - IASTCompoundStatement comp= nodeFactory.newCompoundStatement(); - ((ASTNode) comp).setOffsetAndLength((ASTNode) stmt); - comp.addStatement(stmt); - - while (LT(1) != IToken.tEOC && (stmt instanceof IASTCaseStatement || stmt instanceof IASTDefaultStatement)) { - stmt= statement(); - comp.addStatement(stmt); - } - adjustLength(comp, stmt); + } + } + } + + // create and return ambiguity node + IASTAmbiguousStatement statement = createAmbiguousStatement(); + statement.addStatement(expressionStatement); + statement.addStatement(ds); + return setRange(statement, ds); + } + + /** + * Returns true if the given declaration has unspecified type, + * in this case the type defaults to int and is know as "implicit int". + */ + protected static boolean isImplicitInt(IASTDeclaration declaration) { + if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); + if (declSpec instanceof IASTSimpleDeclSpecifier + && ((IASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified) { + return true; + } + } + return false; + } + + protected abstract IASTAmbiguousStatement createAmbiguousStatement(); + + protected IASTStatement parseLabelStatement() throws EndOfFileException, BacktrackException { + int offset = LA(1).getOffset(); + IASTName name = identifier(); // tIDENTIFIER + consume(IToken.tCOLON); // tCOLON + IASTStatement nestedStatement = statement(); + int lastOffset = calculateEndOffset(nestedStatement); + + IASTLabelStatement label_statement = nodeFactory.newLabelStatement(name, nestedStatement); + setRange(label_statement, offset, lastOffset); + return label_statement; + } + + protected IASTStatement parseNullStatement() throws EndOfFileException, BacktrackException { + IToken t = consume(); // tSEMI + + IASTNullStatement null_statement = nodeFactory.newNullStatement(); + ((ASTNode) null_statement).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); + return null_statement; + } + + protected IASTStatement parseGotoStatement() throws EndOfFileException, BacktrackException { + int startOffset = consume(IToken.t_goto).getOffset(); + IASTStatement gotoStatement = null; + + if (LT(1) == IToken.tSTAR) { + IASTExpression gotoLabelNameExpression = expression(); + gotoStatement = nodeFactory.newGotoStatement(gotoLabelNameExpression); + } else { + IASTName gotoLabelName = identifier(); + gotoStatement = nodeFactory.newGotoStatement(gotoLabelName); + } + + int lastOffset = consume(IToken.tSEMI).getEndOffset(); + ((ASTNode) gotoStatement).setOffsetAndLength(startOffset, lastOffset - startOffset); + return gotoStatement; + } + + protected IASTStatement parseBreakStatement() throws EndOfFileException, BacktrackException { + int startOffset = consume().getOffset(); // t_break + int lastOffset = consume(IToken.tSEMI).getEndOffset(); + + IASTBreakStatement break_statement = nodeFactory.newBreakStatement(); + ((ASTNode) break_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); + return break_statement; + } + + protected IASTStatement parseSwitchBody() throws EndOfFileException, BacktrackException { + IASTStatement stmt = null; + if (LT(1) != IToken.tEOC) + stmt = statement(); + + if (!(stmt instanceof IASTCaseStatement) && !(stmt instanceof IASTDefaultStatement)) + return stmt; + + // bug 105334, switch without compound statement + IASTCompoundStatement comp = nodeFactory.newCompoundStatement(); + ((ASTNode) comp).setOffsetAndLength((ASTNode) stmt); + comp.addStatement(stmt); + + while (LT(1) != IToken.tEOC && (stmt instanceof IASTCaseStatement || stmt instanceof IASTDefaultStatement)) { + stmt = statement(); + comp.addStatement(stmt); + } + adjustLength(comp, stmt); return comp; } - protected IASTStatement parseContinueStatement() throws EndOfFileException, BacktrackException { - int startOffset = consume().getOffset(); // t_continue - int lastOffset = consume(IToken.tSEMI).getEndOffset(); - - IASTContinueStatement continue_statement = nodeFactory.newContinueStatement(); - ((ASTNode) continue_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); - return continue_statement; - } - - protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException { - final int offset= consume(IToken.t_return).getOffset(); - - // Optional expression - IASTExpression expr = null; - if (LT(1) != IToken.tSEMI) { - expr = expression(); - } - // Semicolon - final int endOffset= consumeOrEOC(IToken.tSEMI).getEndOffset(); - - return setRange(nodeFactory.newReturnStatement(expr), offset, endOffset); - } - - protected IASTStatement parseDoStatement() throws EndOfFileException, BacktrackException { - int startOffset; - startOffset = consume().getOffset(); // t_do - IASTStatement do_body = statement(); - - IASTExpression do_condition = null; - if (LT(1) != IToken.tEOC) { - consume(IToken.t_while); - consume(IToken.tLPAREN); - do_condition = condition(true); - } - - int lastOffset; - switch (LT(1)) { - case IToken.tRPAREN: - case IToken.tEOC: - consume(); - break; - default: - throw backtrack; - } - - switch (LT(1)) { - case IToken.tSEMI: - case IToken.tEOC: - lastOffset = consume().getEndOffset(); - break; - default: - throw backtrack; - } - - IASTDoStatement do_statement = nodeFactory.newDoStatement(do_body, do_condition); - ((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); - return do_statement; - } - - protected IASTStatement parseWhileStatement() throws EndOfFileException, BacktrackException { - int startOffset = consume().getOffset(); - consume(IToken.tLPAREN); - IASTExpression while_condition = condition(true); - switch (LT(1)) { - case IToken.tRPAREN: - consume(); - break; - case IToken.tEOC: - break; - default: - throwBacktrack(LA(1)); - } - IASTStatement while_body = null; - if (LT(1) != IToken.tEOC) - while_body = statement(); - - IASTWhileStatement while_statement = nodeFactory.newWhileStatement(while_condition, while_body); - ((ASTNode) while_statement).setOffsetAndLength(startOffset, - (while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset); - - return while_statement; - } - - /** - * @param result - */ - protected void reconcileLengths(IASTIfStatement result) { - if (result == null) - return; - IASTIfStatement current = result; - while (current.getElseClause() instanceof IASTIfStatement) - current = (IASTIfStatement) current.getElseClause(); - - while (current != null) { - ASTNode r = ((ASTNode) current); - if (current.getElseClause() != null) { - ASTNode else_clause = ((ASTNode) current.getElseClause()); - r.setLength(else_clause.getOffset() + else_clause.getLength() - r.getOffset()); - } else { - ASTNode then_clause = (ASTNode) current.getThenClause(); - if (then_clause != null) - r.setLength(then_clause.getOffset() + then_clause.getLength() - r.getOffset()); - } - if (current.getParent() != null && current.getParent() instanceof IASTIfStatement) - current = (IASTIfStatement) current.getParent(); - else - current = null; - } - } - - protected IASTStatement parseCompoundStatement() throws EndOfFileException, BacktrackException { - IASTCompoundStatement compound = compoundStatement(); - return compound; - } - - protected IASTStatement parseDefaultStatement() throws EndOfFileException, BacktrackException { - int startOffset = consume(IToken.t_default).getOffset(); - int lastOffset = consume(IToken.tCOLON).getEndOffset(); - - IASTDefaultStatement df = nodeFactory.newDefaultStatement(); - ((ASTNode) df).setOffsetAndLength(startOffset, lastOffset - startOffset); - return df; - } - - protected IASTStatement parseCaseStatement() throws EndOfFileException, BacktrackException { - int startOffset = consume().getOffset(); // t_case - IASTExpression caseExpression = constantExpression(); - int lt1 = LT(1); + protected IASTStatement parseContinueStatement() throws EndOfFileException, BacktrackException { + int startOffset = consume().getOffset(); // t_continue + int lastOffset = consume(IToken.tSEMI).getEndOffset(); + + IASTContinueStatement continue_statement = nodeFactory.newContinueStatement(); + ((ASTNode) continue_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); + return continue_statement; + } + + protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException { + final int offset = consume(IToken.t_return).getOffset(); + + // Optional expression + IASTExpression expr = null; + if (LT(1) != IToken.tSEMI) { + expr = expression(); + } + // Semicolon + final int endOffset = consumeOrEOC(IToken.tSEMI).getEndOffset(); + + return setRange(nodeFactory.newReturnStatement(expr), offset, endOffset); + } + + protected IASTStatement parseDoStatement() throws EndOfFileException, BacktrackException { + int startOffset; + startOffset = consume().getOffset(); // t_do + IASTStatement do_body = statement(); + + IASTExpression do_condition = null; + if (LT(1) != IToken.tEOC) { + consume(IToken.t_while); + consume(IToken.tLPAREN); + do_condition = condition(true); + } + + int lastOffset; + switch (LT(1)) { + case IToken.tRPAREN: + case IToken.tEOC: + consume(); + break; + default: + throw backtrack; + } + + switch (LT(1)) { + case IToken.tSEMI: + case IToken.tEOC: + lastOffset = consume().getEndOffset(); + break; + default: + throw backtrack; + } + + IASTDoStatement do_statement = nodeFactory.newDoStatement(do_body, do_condition); + ((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); + return do_statement; + } + + protected IASTStatement parseWhileStatement() throws EndOfFileException, BacktrackException { + int startOffset = consume().getOffset(); + consume(IToken.tLPAREN); + IASTExpression while_condition = condition(true); + switch (LT(1)) { + case IToken.tRPAREN: + consume(); + break; + case IToken.tEOC: + break; + default: + throwBacktrack(LA(1)); + } + IASTStatement while_body = null; + if (LT(1) != IToken.tEOC) + while_body = statement(); + + IASTWhileStatement while_statement = nodeFactory.newWhileStatement(while_condition, while_body); + ((ASTNode) while_statement).setOffsetAndLength(startOffset, + (while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset); + + return while_statement; + } + + /** + * @param result + */ + protected void reconcileLengths(IASTIfStatement result) { + if (result == null) + return; + IASTIfStatement current = result; + while (current.getElseClause() instanceof IASTIfStatement) + current = (IASTIfStatement) current.getElseClause(); + + while (current != null) { + ASTNode r = ((ASTNode) current); + if (current.getElseClause() != null) { + ASTNode else_clause = ((ASTNode) current.getElseClause()); + r.setLength(else_clause.getOffset() + else_clause.getLength() - r.getOffset()); + } else { + ASTNode then_clause = (ASTNode) current.getThenClause(); + if (then_clause != null) + r.setLength(then_clause.getOffset() + then_clause.getLength() - r.getOffset()); + } + if (current.getParent() != null && current.getParent() instanceof IASTIfStatement) + current = (IASTIfStatement) current.getParent(); + else + current = null; + } + } + + protected IASTStatement parseCompoundStatement() throws EndOfFileException, BacktrackException { + IASTCompoundStatement compound = compoundStatement(); + return compound; + } + + protected IASTStatement parseDefaultStatement() throws EndOfFileException, BacktrackException { + int startOffset = consume(IToken.t_default).getOffset(); + int lastOffset = consume(IToken.tCOLON).getEndOffset(); + + IASTDefaultStatement df = nodeFactory.newDefaultStatement(); + ((ASTNode) df).setOffsetAndLength(startOffset, lastOffset - startOffset); + return df; + } + + protected IASTStatement parseCaseStatement() throws EndOfFileException, BacktrackException { + int startOffset = consume().getOffset(); // t_case + IASTExpression caseExpression = constantExpression(); + int lt1 = LT(1); if (lt1 == IToken.tELLIPSIS) { consume(); - IASTExpression upperBoundExpression= constantExpression(); - caseExpression = buildBinaryExpression(IASTBinaryExpression.op_ellipses, - caseExpression, upperBoundExpression, calculateEndOffset(upperBoundExpression)); - lt1= LT(1); - } - int lastOffset = 0; - switch (lt1) { - case IToken.tCOLON: - case IToken.tEOC: - lastOffset = consume().getEndOffset(); - break; - default: - throwBacktrack(LA(1)); - } - - IASTCaseStatement cs = nodeFactory.newCaseStatement(caseExpression); - ((ASTNode) cs).setOffsetAndLength(startOffset, lastOffset - startOffset); - return cs; - } - - protected int figureEndOffset(IASTDeclSpecifier declSpec, IASTDeclarator[] declarators) { - if (declarators.length == 0) - return calculateEndOffset(declSpec); - return calculateEndOffset(declarators[declarators.length - 1]); - } - - protected int figureEndOffset(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) { - if (declarator == null || ((ASTNode) declarator).getLength() == 0) - return calculateEndOffset(declSpecifier); - return calculateEndOffset(declarator); - } - - protected void throwBacktrack(IToken token) throws BacktrackException { - throwBacktrack(token.getOffset(), token.getLength()); - } - - protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis, - int offset, int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat) - throws BacktrackException, EndOfFileException { - IASTTypeId typeid; - IASTExpression expr= null; - IToken typeidLA= null; - IToken mark = mark(); - int endOffset1= -1; - int endOffset2= -1; - - try { - consume(IToken.tLPAREN); - int typeidOffset= LA(1).getOffset(); - typeid= typeId(DeclarationOptions.TYPEID); - if (!isValidTypeIDForUnaryExpression(unaryExprKind, typeid)) { - typeid= null; - } else { - switch (LT(1)) { - case IToken.tRPAREN: - case IToken.tEOC: - endOffset1= consume().getEndOffset(); - typeidLA= LA(1); - break; - case IToken.tCOMMA: - if (supportExtendedSizeofOperator && typeExprKind == IASTTypeIdExpression.op_sizeof) { - consume(); - IASTExpression expr2= expression(); - endOffset1= consumeOrEOC(IToken.tRPAREN).getEndOffset(); - expr= nodeFactory.newTypeIdExpression(IASTTypeIdExpression.op_typeof, typeid); + IASTExpression upperBoundExpression = constantExpression(); + caseExpression = buildBinaryExpression(IASTBinaryExpression.op_ellipses, caseExpression, + upperBoundExpression, calculateEndOffset(upperBoundExpression)); + lt1 = LT(1); + } + int lastOffset = 0; + switch (lt1) { + case IToken.tCOLON: + case IToken.tEOC: + lastOffset = consume().getEndOffset(); + break; + default: + throwBacktrack(LA(1)); + } + + IASTCaseStatement cs = nodeFactory.newCaseStatement(caseExpression); + ((ASTNode) cs).setOffsetAndLength(startOffset, lastOffset - startOffset); + return cs; + } + + protected int figureEndOffset(IASTDeclSpecifier declSpec, IASTDeclarator[] declarators) { + if (declarators.length == 0) + return calculateEndOffset(declSpec); + return calculateEndOffset(declarators[declarators.length - 1]); + } + + protected int figureEndOffset(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) { + if (declarator == null || ((ASTNode) declarator).getLength() == 0) + return calculateEndOffset(declSpecifier); + return calculateEndOffset(declarator); + } + + protected void throwBacktrack(IToken token) throws BacktrackException { + throwBacktrack(token.getOffset(), token.getLength()); + } + + protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis, int offset, + int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException { + IASTTypeId typeid; + IASTExpression expr = null; + IToken typeidLA = null; + IToken mark = mark(); + int endOffset1 = -1; + int endOffset2 = -1; + + try { + consume(IToken.tLPAREN); + int typeidOffset = LA(1).getOffset(); + typeid = typeId(DeclarationOptions.TYPEID); + if (!isValidTypeIDForUnaryExpression(unaryExprKind, typeid)) { + typeid = null; + } else { + switch (LT(1)) { + case IToken.tRPAREN: + case IToken.tEOC: + endOffset1 = consume().getEndOffset(); + typeidLA = LA(1); + break; + case IToken.tCOMMA: + if (supportExtendedSizeofOperator && typeExprKind == IASTTypeIdExpression.op_sizeof) { + consume(); + IASTExpression expr2 = expression(); + endOffset1 = consumeOrEOC(IToken.tRPAREN).getEndOffset(); + expr = nodeFactory.newTypeIdExpression(IASTTypeIdExpression.op_typeof, typeid); setRange(expr, typeidOffset, calculateEndOffset(typeid)); - IASTExpressionList expressionList = nodeFactory.newExpressionList(); - ((ASTNode) expressionList).setOffsetAndLength(typeidOffset, calculateEndOffset(expr2)-typeidOffset); - expressionList.addExpression(expr); - if (expr2 instanceof IASTExpressionList) { - for (IASTExpression e : ((IASTExpressionList) expr2).getExpressions()) { + IASTExpressionList expressionList = nodeFactory.newExpressionList(); + ((ASTNode) expressionList).setOffsetAndLength(typeidOffset, + calculateEndOffset(expr2) - typeidOffset); + expressionList.addExpression(expr); + if (expr2 instanceof IASTExpressionList) { + for (IASTExpression e : ((IASTExpressionList) expr2).getExpressions()) { expressionList.addExpression(e); } - } else { - expressionList.addExpression(expr2); - } - - return buildUnaryExpression(unaryExprKind, expressionList, offset, endOffset1); - } - typeid= null; - break; - default: - typeid= null; - break; - } - } - } catch (BacktrackException e) { - typeid= null; - } - - CastAmbiguityMarker ca= null; - backup(mark); - try { - if (exprIsLimitedToParenthesis) { - consume(IToken.tLPAREN); - expr= expression(); - endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset(); - } else { - expr= unaryExpression(ctx, strat); - if (expr instanceof CastAmbiguityMarker) { - ca= (CastAmbiguityMarker) expr; - expr= ca.getExpression(); - assert !(expr instanceof CastAmbiguityMarker); - } - endOffset2= calculateEndOffset(expr); - } - } catch (BacktrackException bte) { - if (typeid == null) - throw bte; - } - - IASTExpression result1= null; - if (typeid != null && endOffset1 >= endOffset2) { + } else { + expressionList.addExpression(expr2); + } + + return buildUnaryExpression(unaryExprKind, expressionList, offset, endOffset1); + } + typeid = null; + break; + default: + typeid = null; + break; + } + } + } catch (BacktrackException e) { + typeid = null; + } + + CastAmbiguityMarker ca = null; + backup(mark); + try { + if (exprIsLimitedToParenthesis) { + consume(IToken.tLPAREN); + expr = expression(); + endOffset2 = consumeOrEOC(IToken.tRPAREN).getEndOffset(); + } else { + expr = unaryExpression(ctx, strat); + if (expr instanceof CastAmbiguityMarker) { + ca = (CastAmbiguityMarker) expr; + expr = ca.getExpression(); + assert !(expr instanceof CastAmbiguityMarker); + } + endOffset2 = calculateEndOffset(expr); + } + } catch (BacktrackException bte) { + if (typeid == null) + throw bte; + } + + IASTExpression result1 = null; + if (typeid != null && endOffset1 >= endOffset2) { IASTTypeIdExpression typeIdExpression = nodeFactory.newTypeIdExpression(typeExprKind, typeid); setRange(typeIdExpression, offset, endOffset1); - result1= typeIdExpression; - backup(typeidLA); + result1 = typeIdExpression; + backup(typeidLA); - if (expr == null || endOffset1 > endOffset2) - return result1; - } + if (expr == null || endOffset1 > endOffset2) + return result1; + } - IASTExpression result2= unaryExprKind == -1 ? expr : buildUnaryExpression(unaryExprKind, expr, offset, endOffset2); - if (ca != null) - result2= ca.updateExpression(result2); + IASTExpression result2 = unaryExprKind == -1 ? expr + : buildUnaryExpression(unaryExprKind, expr, offset, endOffset2); + if (ca != null) + result2 = ca.updateExpression(result2); - if (result1 == null) - return result2; + if (result1 == null) + return result2; - IASTAmbiguousExpression ambExpr = createAmbiguousExpression(); - ambExpr.addExpression(result1); - ambExpr.addExpression(result2); - ((ASTNode) ambExpr).setOffsetAndLength((ASTNode) result1); - return ambExpr; - } + IASTAmbiguousExpression ambExpr = createAmbiguousExpression(); + ambExpr.addExpression(result1); + ambExpr.addExpression(result2); + ((ASTNode) ambExpr).setOffsetAndLength((ASTNode) result1); + return ambExpr; + } private boolean isValidTypeIDForUnaryExpression(int unaryExprKind, IASTTypeId typeid) { if (typeid == null) @@ -2379,84 +2406,89 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } protected abstract IASTAmbiguousExpression createAmbiguousExpression(); - protected abstract IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, IASTCastExpression castExpr); - protected abstract IASTAmbiguousExpression createAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall); - - protected IASTStatement initStatement() throws BacktrackException, EndOfFileException { - if (LT(1) == IToken.tSEMI) - return parseNullStatement(); - try { - return parseDeclarationOrExpressionStatement(); - } catch (BacktrackException e) { - // A init statement always terminates with a semicolon - IASTNode before = e.getNodeBeforeProblem(); - if (before != null) { - e.initialize(e.getProblem()); - } - throw e; - } - } - - protected List<IASTAttributeSpecifier> anyAttributes(boolean allowAttrib, boolean allowDeclspec) throws BacktrackException, EndOfFileException { + + protected abstract IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, + IASTCastExpression castExpr); + + protected abstract IASTAmbiguousExpression createAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, + IASTFunctionCallExpression funcCall); + + protected IASTStatement initStatement() throws BacktrackException, EndOfFileException { + if (LT(1) == IToken.tSEMI) + return parseNullStatement(); + try { + return parseDeclarationOrExpressionStatement(); + } catch (BacktrackException e) { + // A init statement always terminates with a semicolon + IASTNode before = e.getNodeBeforeProblem(); + if (before != null) { + e.initialize(e.getProblem()); + } + throw e; + } + } + + protected List<IASTAttributeSpecifier> anyAttributes(boolean allowAttrib, boolean allowDeclspec) + throws BacktrackException, EndOfFileException { return __attribute_decl_seq(allowAttrib, allowDeclspec); } - /** - * Accepts a sequence of __attribute__ or __declspec. - * - * @param allowAttrib if true accept any number of __attribute__ - * @param allowDeclspec if true accept any number of __declspec - * @return the list of attributes, or {@code null} if there are none - * @throws BacktrackException - * @throws EndOfFileException - */ - protected List<IASTAttributeSpecifier> __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec) - throws BacktrackException, EndOfFileException { - List<IASTAttributeSpecifier> result = null; - while (true) { - final int lt = LTcatchEOF(1); - if (allowAttrib && (lt == IGCCToken.t__attribute__)) { - if (result == null) { - result = new ArrayList<IASTAttributeSpecifier>(); - } - result.add(__attribute__()); - } else if (allowDeclspec && (lt == IGCCToken.t__declspec)) { - if (result == null) { - result = new ArrayList<IASTAttributeSpecifier>(); - } - result.add(__declspec()); - } else { - break; - } - } - return result; - } - - /** - * Parses an __attribute__ clause. - * @return the list of attributes, or {@code null} if the __attribute__ clause contained - * no attributes - * @throws BacktrackException - * @throws EndOfFileException - */ - protected IASTAttributeList __attribute__() throws BacktrackException, EndOfFileException { - if (LT(1) != IGCCToken.t__attribute__) - return null; - - IASTAttributeList result = nodeFactory.newGCCAttributeList(); - final int startOffset = LA().getOffset(); - int endOffset = consume().getEndOffset(); - if (LT(1) == IToken.tLPAREN) { - consume(); - consume(IToken.tLPAREN); - - addAttributesOrDeclspecs(result); - - consumeOrEOC(IToken.tRPAREN); - endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); - } - return setRange(result, startOffset, endOffset); - } + /** + * Accepts a sequence of __attribute__ or __declspec. + * + * @param allowAttrib if true accept any number of __attribute__ + * @param allowDeclspec if true accept any number of __declspec + * @return the list of attributes, or {@code null} if there are none + * @throws BacktrackException + * @throws EndOfFileException + */ + protected List<IASTAttributeSpecifier> __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec) + throws BacktrackException, EndOfFileException { + List<IASTAttributeSpecifier> result = null; + while (true) { + final int lt = LTcatchEOF(1); + if (allowAttrib && (lt == IGCCToken.t__attribute__)) { + if (result == null) { + result = new ArrayList<IASTAttributeSpecifier>(); + } + result.add(__attribute__()); + } else if (allowDeclspec && (lt == IGCCToken.t__declspec)) { + if (result == null) { + result = new ArrayList<IASTAttributeSpecifier>(); + } + result.add(__declspec()); + } else { + break; + } + } + return result; + } + + /** + * Parses an __attribute__ clause. + * @return the list of attributes, or {@code null} if the __attribute__ clause contained + * no attributes + * @throws BacktrackException + * @throws EndOfFileException + */ + protected IASTAttributeList __attribute__() throws BacktrackException, EndOfFileException { + if (LT(1) != IGCCToken.t__attribute__) + return null; + + IASTAttributeList result = nodeFactory.newGCCAttributeList(); + final int startOffset = LA().getOffset(); + int endOffset = consume().getEndOffset(); + if (LT(1) == IToken.tLPAREN) { + consume(); + consume(IToken.tLPAREN); + + addAttributesOrDeclspecs(result); + + consumeOrEOC(IToken.tRPAREN); + endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); + } + return setRange(result, startOffset, endOffset); + } protected IASTAttribute singleAttribute() throws EndOfFileException, BacktrackException { // Get an identifier including keywords @@ -2526,8 +2558,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @param endType the type of the token to stop before * @return a token sequence, possibly empty but never {@code null} */ - protected IASTTokenList balancedTokenSeq(int offset, int endType) - throws EndOfFileException, BacktrackException { + protected IASTTokenList balancedTokenSeq(int offset, int endType) throws EndOfFileException, BacktrackException { IASTTokenList result = nodeFactory.newTokenList(); IToken t; while ((t = LA(1)).getType() != endType) { @@ -2587,7 +2618,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } consume(); lt1 = LT(1); - } while(lt1 != IToken.tRPAREN && lt1 != IToken.tEOC); + } while (lt1 != IToken.tRPAREN && lt1 != IToken.tEOC); } /** @@ -2608,10 +2639,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return result; } - /** + /** * Hook method to support (skip) additional declspec modifiers. * @throws BacktrackException - * @throws EndOfFileException + * @throws EndOfFileException */ protected void handleOtherDeclSpecModifier() throws BacktrackException, EndOfFileException { // default action: consume keyword plus optional parenthesized "something" @@ -2621,7 +2652,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (token.getType() == IToken.tLPAREN) { consume(); - int openParen= 1; + int openParen = 1; while (true) { token = LA(1); consume(); @@ -2638,7 +2669,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } protected boolean canBeCompoundLiteral() throws EndOfFileException { - IToken m= mark(); + IToken m = mark(); try { // The parenthesis cannot be followed by a binary operator skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI); @@ -2651,7 +2682,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } protected boolean canBeCastExpression() throws EndOfFileException { - IToken m= mark(); + IToken m = mark(); try { // The parenthesis cannot be followed by a binary operator skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI); @@ -2706,56 +2737,57 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // simple type specifiers: case IToken.tIDENTIFIER: case IToken.tCOLONCOLON: - case IToken.t_void: + case IToken.t_void: case IToken.t_char: case IToken.t_char16_t: case IToken.t_char32_t: case IToken.t_wchar_t: case IToken.t_bool: case IToken.t_short: - case IToken.t_int: - case IToken.t_long: - case IToken.t_float: - case IToken.t_double: - case IToken.t__Bool: - case IToken.t__Complex: - case IToken.t__Imaginary: - case IGCCToken.t__int128: - case IGCCToken.t__float128: - case IGCCToken.t_decimal32: - case IGCCToken.t_decimal64: - case IGCCToken.t_decimal128: - case IToken.t_signed: - case IToken.t_unsigned: - case IToken.t_decltype: - case IToken.t_auto: - - // class-specifier: - case IToken.t_class: - case IToken.t_struct: - case IToken.t_union: - - // enum-specifier: - case IToken.t_enum: - - // elaborated type specifier: (together with class, struct, union, enum) - case IToken.t_typename: - - // cq-qualifiers + case IToken.t_int: + case IToken.t_long: + case IToken.t_float: + case IToken.t_double: + case IToken.t__Bool: + case IToken.t__Complex: + case IToken.t__Imaginary: + case IGCCToken.t__int128: + case IGCCToken.t__float128: + case IGCCToken.t_decimal32: + case IGCCToken.t_decimal64: + case IGCCToken.t_decimal128: + case IToken.t_signed: + case IToken.t_unsigned: + case IToken.t_decltype: + case IToken.t_auto: + + // class-specifier: + case IToken.t_class: + case IToken.t_struct: + case IToken.t_union: + + // enum-specifier: + case IToken.t_enum: + + // elaborated type specifier: (together with class, struct, union, enum) + case IToken.t_typename: + + // cq-qualifiers case IToken.t_const: - case IToken.t_volatile: - case IToken.t_restrict: + case IToken.t_volatile: + case IToken.t_restrict: - // gcc-special - case IGCCToken.t_typeof: - case IGCCToken.t__attribute__: + // gcc-special + case IGCCToken.t_typeof: + case IGCCToken.t__attribute__: - // content assist - case IToken.tCOMPLETION: - return true; + // content assist + case IToken.tCOMPLETION: + return true; - default: - if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) + default: + if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst + && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) return true; return false; @@ -2767,7 +2799,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { int nesting = 0; int braceNesting = 0; while (true) { - final int lt1= LT(1); + final int lt1 = LT(1); if (lt1 == IToken.tEOC) throwBacktrack(LA(1)); @@ -2837,7 +2869,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // No expression - use the type id. backup(typeIdEnd); result = nodeFactory.newAlignmentSpecifier(typeId); - } else if (expression.contains(typeId)) { // otherwise, pick the longer one + } else if (expression.contains(typeId)) { // otherwise, pick the longer one if (typeId.contains(expression)) { // They are both the same length - ambiguous. int endOffset = consume(IToken.tRPAREN).getEndOffset(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java index 931db1530bc..ce8d9a32141 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ArithmeticConversion.java @@ -32,21 +32,22 @@ public abstract class ArithmeticConversion { private static final int DOMAIN_FLAGS = IBasicType.IS_IMAGINARY | IBasicType.IS_COMPLEX; private enum Domain { - eReal(0), - eImaginary(IBasicType.IS_IMAGINARY), - eComplex(IBasicType.IS_COMPLEX); + eReal(0), eImaginary(IBasicType.IS_IMAGINARY), eComplex(IBasicType.IS_COMPLEX); private final int fModifier; private Domain(int modifier) { - fModifier= modifier; + fModifier = modifier; } int getModifier() { return fModifier; } } - private enum Rank {eInt, eLong, eLongLong} + + private enum Rank { + eInt, eLong, eLongLong + } protected abstract IBasicType createBasicType(IBasicType.Kind kind, int modifiers); @@ -65,14 +66,14 @@ public abstract class ArithmeticConversion { case IASTBinaryExpression.op_divide: case IASTBinaryExpression.op_modulo: case IASTBinaryExpression.op_multiply: - // Additive operators + // Additive operators case IASTBinaryExpression.op_minus: case IASTBinaryExpression.op_plus: - // Bitwise operators + // Bitwise operators case IASTBinaryExpression.op_binaryAnd: case IASTBinaryExpression.op_binaryOr: case IASTBinaryExpression.op_binaryXor: - // Gcc's minimum/maximum operators + // Gcc's minimum/maximum operators case IASTBinaryExpression.op_max: case IASTBinaryExpression.op_min: return convert(op1, op2); @@ -94,7 +95,7 @@ public abstract class ArithmeticConversion { } private boolean isArithmeticOrUnscopedEnum(IType op1) { - if (op1 instanceof IBasicType) { + if (op1 instanceof IBasicType) { final Kind kind = ((IBasicType) op1).getKind(); switch (kind) { case eUnspecified: @@ -118,7 +119,7 @@ public abstract class ArithmeticConversion { return true; if (op1 instanceof IBasicType) { - Kind kind= ((IBasicType) op1).getKind(); + Kind kind = ((IBasicType) op1).getKind(); switch (kind) { case eBoolean: case eChar: @@ -145,7 +146,7 @@ public abstract class ArithmeticConversion { } private final IType convert(IType type1, IType type2) { - Domain domain= getDomain(type1, type2); + Domain domain = getDomain(type1, type2); // If either type is a long double, return that type if (isLongDouble(type1)) { @@ -185,15 +186,15 @@ public abstract class ArithmeticConversion { IBasicType unsignedType, signedType; if (btype1.isUnsigned()) { - unsignedType= btype1; - signedType= btype2; + unsignedType = btype1; + signedType = btype2; } else { - unsignedType= btype2; - signedType= btype1; + unsignedType = btype2; + signedType = btype1; } - final Rank signedRank= getIntegerRank(signedType); - final Rank unsignedRank= getIntegerRank(unsignedType); + final Rank signedRank = getIntegerRank(signedType); + final Rank unsignedRank = getIntegerRank(unsignedType); // same rank -> use unsigned if (unsignedRank.ordinal() >= signedRank.ordinal()) { @@ -211,13 +212,13 @@ public abstract class ArithmeticConversion { private IBasicType promote(IType type, Domain domain) { if (type instanceof IEnumeration) { - IType fixedType= null; + IType fixedType = null; if (type instanceof ICPPEnumeration) { - fixedType= ((ICPPEnumeration) type).getFixedType(); + fixedType = ((ICPPEnumeration) type).getFixedType(); } if (fixedType == null) return createBasicType(Kind.eInt, domain.getModifier() | getEnumIntTypeModifiers((IEnumeration) type)); - type= fixedType; + type = fixedType; } if (type instanceof IBasicType) { @@ -258,8 +259,8 @@ public abstract class ArithmeticConversion { } private Domain getDomain(IType type1, IType type2) { - Domain d1= getDomain(type1); - Domain d2= getDomain(type2); + Domain d1 = getDomain(type1); + Domain d2 = getDomain(type2); if (d1 == d2) return d1; return Domain.eComplex; @@ -267,7 +268,7 @@ public abstract class ArithmeticConversion { private Domain getDomain(IType type) { if (type instanceof IBasicType) { - IBasicType bt= (IBasicType) type; + IBasicType bt = (IBasicType) type; if (bt.isComplex()) return Domain.eComplex; if (bt.isImaginary()) @@ -277,7 +278,7 @@ public abstract class ArithmeticConversion { } private IBasicType adjustDomain(IBasicType t, Domain d) { - Domain myDomain= getDomain(t); + Domain myDomain = getDomain(t); if (myDomain == d) return t; @@ -301,16 +302,16 @@ public abstract class ArithmeticConversion { private boolean isLongDouble(IType type) { if (type instanceof IBasicType) { - final IBasicType bt= (IBasicType) type; - return bt.isLong() && bt.getKind() == Kind.eDouble || bt.getKind() == Kind.eFloat128 || - bt.getKind() == Kind.eDecimal128; + final IBasicType bt = (IBasicType) type; + return bt.isLong() && bt.getKind() == Kind.eDouble || bt.getKind() == Kind.eFloat128 + || bt.getKind() == Kind.eDecimal128; } return false; } private static boolean isDouble(IType type) { if (type instanceof IBasicType) { - final IBasicType bt= (IBasicType) type; + final IBasicType bt = (IBasicType) type; return bt.getKind() == Kind.eDouble || bt.getKind() == Kind.eDecimal64; } return false; @@ -318,7 +319,7 @@ public abstract class ArithmeticConversion { private static boolean isFloat(IType type) { if (type instanceof IBasicType) { - final IBasicType bt= (IBasicType) type; + final IBasicType bt = (IBasicType) type; return bt.getKind() == Kind.eFloat || bt.getKind() == Kind.eDecimal32; } return false; @@ -345,7 +346,7 @@ public abstract class ArithmeticConversion { switch (kind) { case eBoolean: return n == 0 || n == 1; - + case eInt: if (!basicTarget.isUnsigned()) { if (basicTarget.isShort()) { @@ -383,11 +384,11 @@ public abstract class ArithmeticConversion { return Integer.MIN_VALUE <= n && n <= Integer.MAX_VALUE; case eFloat: - float f= n; + float f = n; return (long) f == n; case eDouble: - double d= n; + double d = n; return (long) d == n; default: @@ -400,21 +401,25 @@ public abstract class ArithmeticConversion { */ private static long getApproximateSize(IBasicType type) { switch (type.getKind()) { - case eChar: return 1; - case eWChar: return 2; - case eInt: - // Note: we return 6 for long so that both long -> int - // and long long -> long conversions are reported - // as narrowing, to be on the safe side. - return type.isShort() ? 2 - : type.isLong() ? 6 - : type.isLongLong() ? 8 - : 4; - case eBoolean: return 1; - case eChar16: return 2; - case eChar32: return 4; - case eInt128: return 16; - default: return 0; // shouldn't happen + case eChar: + return 1; + case eWChar: + return 2; + case eInt: + // Note: we return 6 for long so that both long -> int + // and long long -> long conversions are reported + // as narrowing, to be on the safe side. + return type.isShort() ? 2 : type.isLong() ? 6 : type.isLongLong() ? 8 : 4; + case eBoolean: + return 1; + case eChar16: + return 2; + case eChar32: + return 4; + case eInt128: + return 16; + default: + return 0; // shouldn't happen } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/BacktrackException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/BacktrackException.java index f8bf0e4a59b..aaa30441b0f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/BacktrackException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/BacktrackException.java @@ -23,85 +23,87 @@ import org.eclipse.cdt.core.parser.IProblem; * @author jcamelon */ public class BacktrackException extends Exception { - private static final StackTraceElement[] EMPTY_STACK = new StackTraceElement[0]; + private static final StackTraceElement[] EMPTY_STACK = new StackTraceElement[0]; - private IASTProblem problem; - private IASTNode nodeBeforeProblem; // a node has been created in spite of the problem. - private int offset, length; + private IASTProblem problem; + private IASTNode nodeBeforeProblem; // a node has been created in spite of the problem. + private int offset, length; - public BacktrackException() { - } + public BacktrackException() { + } public BacktrackException(BacktrackException e) { - problem= e.problem; - nodeBeforeProblem= e.nodeBeforeProblem; - offset= e.offset; - length= e.length; + problem = e.problem; + nodeBeforeProblem = e.nodeBeforeProblem; + offset = e.offset; + length = e.length; + } + + public void initialize(IASTProblem p) { + reset(); + problem = p; + } + + public void initialize(IASTProblem p, IASTNode node) { + reset(); + problem = p; + nodeBeforeProblem = node; + } + + /** + * + */ + private void reset() { + nodeBeforeProblem = null; + problem = null; + offset = 0; + length = 0; + } + + /** + * @return Returns the problem. + */ + public final IASTProblem getProblem() { + return problem; + } + + public final IASTNode getNodeBeforeProblem() { + return nodeBeforeProblem; } - public void initialize(IASTProblem p) { - reset(); - problem = p; - } - - public void initialize(IASTProblem p, IASTNode node) { - reset(); - problem = p; - nodeBeforeProblem= node; - } - - /** - * - */ - private void reset() { - nodeBeforeProblem= null; - problem = null; - offset = 0; - length = 0; - } - /** - * @return Returns the problem. - */ - public final IASTProblem getProblem() { - return problem; - } - - public final IASTNode getNodeBeforeProblem() { - return nodeBeforeProblem; - } - - public void initialize(int start, int l) { - reset(); - offset = start; - length = l; - } - - /** - * @return Returns the length. - */ - public int getLength() { - return length; - } - /** - * @return Returns the offset. - */ - public int getOffset() { - return offset; - } - - @Override - public Throwable fillInStackTrace() { - // Do nothing, performance optimization - return this; - } - - @Override - public StackTraceElement[] getStackTrace() { - return EMPTY_STACK; - } - - // Don't try alternative parses if this returns true. - public boolean isFatal() { - return problem != null && problem.getID() == IProblem.TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT_EXCEEDED; - } + public void initialize(int start, int l) { + reset(); + offset = start; + length = l; + } + + /** + * @return Returns the length. + */ + public int getLength() { + return length; + } + + /** + * @return Returns the offset. + */ + public int getOffset() { + return offset; + } + + @Override + public Throwable fillInStackTrace() { + // Do nothing, performance optimization + return this; + } + + @Override + public StackTraceElement[] getStackTrace() { + return EMPTY_STACK; + } + + // Don't try alternative parses if this returns true. + public boolean isFatal() { + return problem != null && problem.getID() == IProblem.TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT_EXCEEDED; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java index 01ec4432f88..a20e86ec9f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CStringValue.java @@ -244,7 +244,7 @@ public final class CStringValue implements IValue { public String toString() { return new String(fFixedValue); } - + @Override public boolean isEquivalentTo(IValue other) { if (!(other instanceof CStringValue)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ChildCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ChildCollector.java index 91a8f32f7cb..74264b0fa33 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ChildCollector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ChildCollector.java @@ -28,7 +28,7 @@ class ChildCollector extends ASTGenericVisitor { public ChildCollector(IASTNode node) { super(true); - fNode= node; + fNode = node; } public IASTNode[] getChildren() { @@ -44,7 +44,7 @@ class ChildCollector extends ASTGenericVisitor { if (fNodes == null) { if (child == fNode) return PROCESS_CONTINUE; - fNodes= new ArrayList<IASTNode>(); + fNodes = new ArrayList<IASTNode>(); } fNodes.add(child); return PROCESS_SKIP; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java index f8819cfaa88..c3192b799f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CompositeValue.java @@ -65,7 +65,7 @@ public final class CompositeValue implements IValue { if (evaluation != null) { return evaluation.getSignature(); } - return new char[]{}; + return new char[] {}; } @Override @@ -160,8 +160,7 @@ public final class CompositeValue implements IValue { // The set of class types for which composite value creation is in progress on each thread. // Used to guard against infinite recursion due to a class (illegally) aggregating itself. - private static final ThreadLocal<Set<ICPPClassType>> fCreateInProgress = - new ThreadLocal<Set<ICPPClassType>>() { + private static final ThreadLocal<Set<ICPPClassType>> fCreateInProgress = new ThreadLocal<Set<ICPPClassType>>() { @Override protected Set<ICPPClassType> initialValue() { return new TreeSet<>((type1, type2) -> { @@ -193,7 +192,8 @@ public final class CompositeValue implements IValue { } try { if (sDEBUG && nestingLevel > 0) { - System.out.println("CompositeValue.create(" + ASTTypeUtil.getType(classType) + ", " + nestingLevel + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + System.out + .println("CompositeValue.create(" + ASTTypeUtil.getType(classType) + ", " + nestingLevel + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ System.out.flush(); } ActivationRecord record = new ActivationRecord(); @@ -249,8 +249,8 @@ public final class CompositeValue implements IValue { if (position >= 0 && position < values.length) { values[position] = newValue == null ? EvalFixed.INCOMPLETE : newValue; } else { - CCorePlugin.log(IStatus.WARNING, "Out-of-bounds access to composite value: " + position + //$NON-NLS-1$ - " (length is " + values.length + ")"); //$NON-NLS-1$//$NON-NLS-2$ + CCorePlugin.log(IStatus.WARNING, "Out-of-bounds access to composite value: " + position + //$NON-NLS-1$ + " (length is " + values.length + ")"); //$NON-NLS-1$//$NON-NLS-2$ } } @@ -302,15 +302,14 @@ public final class CompositeValue implements IValue { } return new CompositeValue(evaluation, values); } - + @Override public boolean isEquivalentTo(IValue other) { if (!(other instanceof CompositeValue)) { return false; } CompositeValue o = (CompositeValue) other; - if (!((evaluation == null && o.evaluation == null) || - (evaluation.isEquivalentTo(o.evaluation)))) { + if (!((evaluation == null && o.evaluation == null) || (evaluation.isEquivalentTo(o.evaluation)))) { return false; } if (values.length != o.values.length) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java index 25690692851..1c8285c104b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java @@ -17,39 +17,44 @@ package org.eclipse.cdt.internal.core.dom.parser; * Configures the parsing of a declaration in various contexts. */ public class DeclarationOptions { - final public static int ALLOW_EMPTY_SPECIFIER= 0x01; - final public static int ALLOW_ABSTRACT= 0x02; - final public static int REQUIRE_ABSTRACT= 0x04; - final public static int ALLOW_BITFIELD= 0x08; - final public static int NO_INITIALIZER= 0x10; - final public static int NO_CTOR_STYLE_INITIALIZER= 0x20; - final public static int NO_BRACED_INITIALIZER= 0x40; - final public static int NO_FUNCTIONS= 0x80; - final public static int NO_ARRAYS= 0x100; - final public static int NO_NESTED= 0x200; - final public static int ALLOW_PARAMETER_PACKS= 0x400; - final public static int REQUIRE_SIMPLE_NAME= 0x800; - final public static int ALLOW_FOLLOWED_BY_BRACE= 0x1000; - final public static int ALLOW_OPAQUE_ENUM= 0x2000; - final public static int SINGLE_DTOR= 0x4000; - final public static int ALLOW_FUNCTION_DEFINITION= 0x8000; - final public static int NO_COMPOSITE_SPECIFIER= 0x10000; + final public static int ALLOW_EMPTY_SPECIFIER = 0x01; + final public static int ALLOW_ABSTRACT = 0x02; + final public static int REQUIRE_ABSTRACT = 0x04; + final public static int ALLOW_BITFIELD = 0x08; + final public static int NO_INITIALIZER = 0x10; + final public static int NO_CTOR_STYLE_INITIALIZER = 0x20; + final public static int NO_BRACED_INITIALIZER = 0x40; + final public static int NO_FUNCTIONS = 0x80; + final public static int NO_ARRAYS = 0x100; + final public static int NO_NESTED = 0x200; + final public static int ALLOW_PARAMETER_PACKS = 0x400; + final public static int REQUIRE_SIMPLE_NAME = 0x800; + final public static int ALLOW_FOLLOWED_BY_BRACE = 0x1000; + final public static int ALLOW_OPAQUE_ENUM = 0x2000; + final public static int SINGLE_DTOR = 0x4000; + final public static int ALLOW_FUNCTION_DEFINITION = 0x8000; + final public static int NO_COMPOSITE_SPECIFIER = 0x10000; - public static final DeclarationOptions - GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_OPAQUE_ENUM | ALLOW_FUNCTION_DEFINITION), - FUNCTION_STYLE_ASM= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | NO_INITIALIZER | ALLOW_ABSTRACT | ALLOW_FUNCTION_DEFINITION), - C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT), - CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD | ALLOW_OPAQUE_ENUM | NO_CTOR_STYLE_INITIALIZER | ALLOW_FUNCTION_DEFINITION), - LOCAL= new DeclarationOptions(ALLOW_OPAQUE_ENUM), - PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME | NO_BRACED_INITIALIZER | NO_CTOR_STYLE_INITIALIZER), - TYPEID= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER), - TYPEID_TRAILING_RETURN_TYPE= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | ALLOW_FOLLOWED_BY_BRACE | ALLOW_FUNCTION_DEFINITION | NO_COMPOSITE_SPECIFIER), - TYPEID_NEW= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED | ALLOW_FOLLOWED_BY_BRACE), - TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED), - EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER), - CONDITION= new DeclarationOptions(NO_CTOR_STYLE_INITIALIZER), - C_PARAMETER_NON_ABSTRACT= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER), - RANGE_BASED_FOR = new DeclarationOptions(NO_INITIALIZER | REQUIRE_SIMPLE_NAME | SINGLE_DTOR); + public static final DeclarationOptions GLOBAL = new DeclarationOptions( + ALLOW_EMPTY_SPECIFIER | ALLOW_OPAQUE_ENUM | ALLOW_FUNCTION_DEFINITION), + FUNCTION_STYLE_ASM = new DeclarationOptions( + ALLOW_EMPTY_SPECIFIER | NO_INITIALIZER | ALLOW_ABSTRACT | ALLOW_FUNCTION_DEFINITION), + C_MEMBER = new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT), + CPP_MEMBER = new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD | ALLOW_OPAQUE_ENUM + | NO_CTOR_STYLE_INITIALIZER | ALLOW_FUNCTION_DEFINITION), + LOCAL = new DeclarationOptions(ALLOW_OPAQUE_ENUM), + PARAMETER = new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME + | NO_BRACED_INITIALIZER | NO_CTOR_STYLE_INITIALIZER), + TYPEID = new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER), + TYPEID_TRAILING_RETURN_TYPE = new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER + | ALLOW_FOLLOWED_BY_BRACE | ALLOW_FUNCTION_DEFINITION | NO_COMPOSITE_SPECIFIER), + TYPEID_NEW = new DeclarationOptions( + REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED | ALLOW_FOLLOWED_BY_BRACE), + TYPEID_CONVERSION = new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED), + EXCEPTION = new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER), + CONDITION = new DeclarationOptions(NO_CTOR_STYLE_INITIALIZER), + C_PARAMETER_NON_ABSTRACT = new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER), + RANGE_BASED_FOR = new DeclarationOptions(NO_INITIALIZER | REQUIRE_SIMPLE_NAME | SINGLE_DTOR); final public boolean fAllowEmptySpecifier; final public boolean fAllowAbstract; @@ -69,21 +74,21 @@ public class DeclarationOptions { final public boolean fAllowCompositeSpecifier; public DeclarationOptions(int options) { - fAllowEmptySpecifier= (options & ALLOW_EMPTY_SPECIFIER) != 0; - fRequireAbstract= (options & REQUIRE_ABSTRACT) != 0; - fAllowAbstract= fRequireAbstract || (options & ALLOW_ABSTRACT) != 0; - fAllowBitField= (options & ALLOW_BITFIELD) != 0; - fAllowInitializer= (options & NO_INITIALIZER) == 0; - fAllowBracedInitializer= fAllowInitializer && (options & NO_BRACED_INITIALIZER) == 0; - fAllowCtorStyleInitializer= fAllowInitializer && (options & NO_CTOR_STYLE_INITIALIZER) == 0; - fAllowFunctions= (options & NO_FUNCTIONS) == 0; - fAllowNested= (options & NO_NESTED) == 0; - fAllowParameterPacks= (options & ALLOW_PARAMETER_PACKS) != 0; - fRequireSimpleName= (options & REQUIRE_SIMPLE_NAME) != 0; - fCanBeFollowedByBrace= fAllowBracedInitializer || (options & ALLOW_FOLLOWED_BY_BRACE) != 0; - fAllowOpaqueEnum= (options & ALLOW_OPAQUE_ENUM) != 0; - fSingleDtor= (options & SINGLE_DTOR) != 0; - fAllowFunctionDefinition= (options & ALLOW_FUNCTION_DEFINITION) != 0; - fAllowCompositeSpecifier= (options & NO_COMPOSITE_SPECIFIER) == 0; + fAllowEmptySpecifier = (options & ALLOW_EMPTY_SPECIFIER) != 0; + fRequireAbstract = (options & REQUIRE_ABSTRACT) != 0; + fAllowAbstract = fRequireAbstract || (options & ALLOW_ABSTRACT) != 0; + fAllowBitField = (options & ALLOW_BITFIELD) != 0; + fAllowInitializer = (options & NO_INITIALIZER) == 0; + fAllowBracedInitializer = fAllowInitializer && (options & NO_BRACED_INITIALIZER) == 0; + fAllowCtorStyleInitializer = fAllowInitializer && (options & NO_CTOR_STYLE_INITIALIZER) == 0; + fAllowFunctions = (options & NO_FUNCTIONS) == 0; + fAllowNested = (options & NO_NESTED) == 0; + fAllowParameterPacks = (options & ALLOW_PARAMETER_PACKS) != 0; + fRequireSimpleName = (options & REQUIRE_SIMPLE_NAME) != 0; + fCanBeFollowedByBrace = fAllowBracedInitializer || (options & ALLOW_FOLLOWED_BY_BRACE) != 0; + fAllowOpaqueEnum = (options & ALLOW_OPAQUE_ENUM) != 0; + fSingleDtor = (options & SINGLE_DTOR) != 0; + fAllowFunctionDefinition = (options & ALLOW_FUNCTION_DEFINITION) != 0; + fAllowCompositeSpecifier = (options & NO_COMPOSITE_SPECIFIER) == 0; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java index 7c2f48fe1cb..a69d219ffb2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DependentValue.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.CoreException; /** * Represents the value of an expression, which is not simplified yet, - * usually because it depends on the value of a template parameter. + * usually because it depends on the value of a template parameter. */ public class DependentValue implements IValue { public static final int MAX_RECURSION_DEPTH = 25; @@ -58,7 +58,7 @@ public class DependentValue implements IValue { } public static IValue unmarshal(short firstBytes, ITypeMarshalBuffer buf) throws CoreException { - ICPPEvaluation eval= buf.unmarshalEvaluation(); + ICPPEvaluation eval = buf.unmarshalEvaluation(); if (eval != null) return new DependentValue(eval); return IntegralValue.UNKNOWN; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java index 613cb17fa73..6d41896362f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java @@ -30,15 +30,14 @@ public class FindNodeForOffsetAction extends ASTGenericVisitor { public FindNodeForOffsetAction(ASTNodeSpecification<?> nodeSpec) { super(!nodeSpec.requiresClass(IASTName.class)); - fNodeSpec= nodeSpec; + fNodeSpec = nodeSpec; shouldVisitNames = true; - shouldVisitDeclarations= true; - includeInactiveNodes= true; + shouldVisitDeclarations = true; + includeInactiveNodes = true; // only visit implicit names if asked - shouldVisitImplicitNames = - shouldVisitImplicitNameAlternates = nodeSpec.requiresClass(IASTImplicitName.class); + shouldVisitImplicitNames = shouldVisitImplicitNameAlternates = nodeSpec.requiresClass(IASTImplicitName.class); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java index 9250104d58f..fb792fe96d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FloatingPointValue.java @@ -107,7 +107,7 @@ public final class FloatingPointValue implements IValue { @Override public ICPPEvaluation[] getAllSubValues() { - return new ICPPEvaluation[]{ getEvaluation() }; + return new ICPPEvaluation[] { getEvaluation() }; } @Override @@ -141,7 +141,7 @@ public final class FloatingPointValue implements IValue { } private static char[] toCharArray(double value) { - StringBuilder buf= new StringBuilder(); + StringBuilder buf = new StringBuilder(); buf.append(value); return CharArrayUtils.extractChars(buf); } @@ -166,7 +166,7 @@ public final class FloatingPointValue implements IValue { public static IValue unmarshal(short firstBytes, ITypeMarshalBuffer buf) throws CoreException { return new FloatingPointValue(buf.getCharArray()); } - + @Override public boolean isEquivalentTo(IValue other) { if (!(other instanceof FloatingPointValue)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index ef8c6818f2e..a6529b19558 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -64,7 +64,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { * {@code BUILTIN_GCC_SYMBOL} is a built-in GCC symbol. */ public static final ASTNodeProperty BUILTIN_GCC_SYMBOL = new ASTNodeProperty( - "GCCBuiltinSymbolProvider.BUILTIN_GCC_SYMBOL - built-in GCC symbol"); //$NON-NLS-1$ + "GCCBuiltinSymbolProvider.BUILTIN_GCC_SYMBOL - built-in GCC symbol"); //$NON-NLS-1$ private static final Map<String, char[]> CHAR_ARRAYS = new HashMap<String, char[]>(); @@ -75,36 +75,36 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { private Map<String, IType> fTypeMap; private List<IBinding> fBindingList; - + private CharArraySet fKnownBuiltins = new CharArraySet(50); public GCCBuiltinSymbolProvider(ParserLanguage lang, boolean supportGnuSymbols) { - fCpp= lang == ParserLanguage.CPP; - fGnu= supportGnuSymbols; + fCpp = lang == ParserLanguage.CPP; + fGnu = supportGnuSymbols; } @Override public IBinding[] getBuiltinBindings(IScope scope) { - fScope= scope; + fScope = scope; initialize(); return fBindings; } private void initialize() { // Symbols for all parsers - fTypeMap= new HashMap<>(); - fBindingList= new ArrayList<>(); + fTypeMap = new HashMap<>(); + fBindingList = new ArrayList<>(); addStdBuiltins(); if (fGnu) { addGnuBuiltins(); } - fBindings= fBindingList.toArray(new IBinding[fBindingList.size()]); + fBindings = fBindingList.toArray(new IBinding[fBindingList.size()]); for (IBinding binding : fBindings) { fKnownBuiltins.put(binding.getNameCharArray()); } - fTypeMap= null; - fBindingList= null; + fTypeMap = null; + fBindingList = null; } private void addStdBuiltins() { @@ -119,348 +119,348 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { typedef("unsigned __int128", "__uint128_t"); // Used in stdtypes.h, mentioned in the manual but not defined in there. - typedef("va_list", "__builtin_va_list"); - function("void*", "__builtin_va_start", "va_list", "..."); - function("void", "__builtin_va_end", "va_list"); - function("void", "__builtin_va_copy", "va_list", "va_list"); + typedef("va_list", "__builtin_va_list"); + function("void*", "__builtin_va_start", "va_list", "..."); + function("void", "__builtin_va_end", "va_list"); + function("void", "__builtin_va_copy", "va_list", "va_list"); // Return Address (https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html) - function("void*", "__builtin_return_address", "unsigned int"); - function("void*", "__builtin_extract_return_address", "void*"); - function("void*", "__builtin_frob_return_address", "void*"); - function("void*", "__builtin_frame_address", "unsigned int"); + function("void*", "__builtin_return_address", "unsigned int"); + function("void*", "__builtin_extract_return_address", "void*"); + function("void*", "__builtin_frob_return_address", "void*"); + function("void*", "__builtin_frame_address", "unsigned int"); // __sync Builtins (https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html) - String[] types= {"int", "long", "long long", "unsigned int", "unsigned long", "unsigned long long", "void*"}; + String[] types = { "int", "long", "long long", "unsigned int", "unsigned long", "unsigned long long", "void*" }; for (String type : types) { // Manual does not mention volatile, however functions can be used for ptr to volatile - String typePtr= type + " volatile *"; - function(type, "__sync_fetch_and_add", typePtr, type, "..."); - function(type, "__sync_fetch_and_sub", typePtr, type, "..."); - function(type, "__sync_fetch_and_or", typePtr, type, "..."); - function(type, "__sync_fetch_and_and", typePtr, type, "..."); - function(type, "__sync_fetch_and_xor", typePtr, type, "..."); - function(type, "__sync_fetch_and_nand", typePtr, type, "..."); - function(type, "__sync_add_and_fetch", typePtr, type, "..."); - function(type, "__sync_sub_and_fetch", typePtr, type, "..."); - function(type, "__sync_or_and_fetch", typePtr, type, "..."); - function(type, "__sync_and_and_fetch", typePtr, type, "..."); - function(type, "__sync_xor_and_fetch", typePtr, type, "..."); - function(type, "__sync_nand_and_fetch", typePtr, type, "..."); - function(type, "__sync_lock_test_and_set", typePtr, type, "..."); + String typePtr = type + " volatile *"; + function(type, "__sync_fetch_and_add", typePtr, type, "..."); + function(type, "__sync_fetch_and_sub", typePtr, type, "..."); + function(type, "__sync_fetch_and_or", typePtr, type, "..."); + function(type, "__sync_fetch_and_and", typePtr, type, "..."); + function(type, "__sync_fetch_and_xor", typePtr, type, "..."); + function(type, "__sync_fetch_and_nand", typePtr, type, "..."); + function(type, "__sync_add_and_fetch", typePtr, type, "..."); + function(type, "__sync_sub_and_fetch", typePtr, type, "..."); + function(type, "__sync_or_and_fetch", typePtr, type, "..."); + function(type, "__sync_and_and_fetch", typePtr, type, "..."); + function(type, "__sync_xor_and_fetch", typePtr, type, "..."); + function(type, "__sync_nand_and_fetch", typePtr, type, "..."); + function(type, "__sync_lock_test_and_set", typePtr, type, "..."); function(type, "__sync_val_compare_and_swap", typePtr, type, type, "..."); function("bool", "__sync_bool_compare_and_swap", typePtr, type, type, "..."); function("void", "__sync_lock_release", typePtr, "..."); } - function("void", "__sync_synchronize"); + function("void", "__sync_synchronize"); // __atomic Builtins (https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html) for (String type : types) { // Manual does not mention volatile, however functions can be used for ptr to volatile - String typePtr= type + " volatile *"; - function(type, "__atomic_load_n", typePtr, "int"); - function("void", "__atomic_load", typePtr, typePtr, "int"); - function("void", "__atomic_store_n", typePtr, type, "int"); - function("void", "__atomic_store", typePtr, typePtr, "int"); - function(type, "__atomic_exchange_n", typePtr, type, "int"); - function("void", "__atomic_exchange", typePtr, typePtr, typePtr, "int"); - function("bool", "__atomic_compare_exchange_n", typePtr, typePtr, type, "int", "int", "int"); - function("bool", "__atomic_compare_exchange", typePtr, typePtr, typePtr, "int", "int", "int"); - function(type, "__atomic_add_fetch", typePtr, type, "int"); - function(type, "__atomic_sub_fetch", typePtr, type, "int"); - function(type, "__atomic_and_fetch", typePtr, type, "int"); - function(type, "__atomic_xor_fetch", typePtr, type, "int"); - function(type, "__atomic_or_fetch", typePtr, type, "int"); - function(type, "__atomic_nadd_fetch", typePtr, type, "int"); - function(type, "__atomic_fetch_add", typePtr, type, "int"); - function(type, "__atomic_fetch_sub", typePtr, type, "int"); - function(type, "__atomic_fetch_and", typePtr, type, "int"); - function(type, "__atomic_fetch_xor", typePtr, type, "int"); - function(type, "__atomic_fetch_or", typePtr, type, "int"); - function(type, "__atomic_fetch_nadd", typePtr, type, "int"); + String typePtr = type + " volatile *"; + function(type, "__atomic_load_n", typePtr, "int"); + function("void", "__atomic_load", typePtr, typePtr, "int"); + function("void", "__atomic_store_n", typePtr, type, "int"); + function("void", "__atomic_store", typePtr, typePtr, "int"); + function(type, "__atomic_exchange_n", typePtr, type, "int"); + function("void", "__atomic_exchange", typePtr, typePtr, typePtr, "int"); + function("bool", "__atomic_compare_exchange_n", typePtr, typePtr, type, "int", "int", "int"); + function("bool", "__atomic_compare_exchange", typePtr, typePtr, typePtr, "int", "int", "int"); + function(type, "__atomic_add_fetch", typePtr, type, "int"); + function(type, "__atomic_sub_fetch", typePtr, type, "int"); + function(type, "__atomic_and_fetch", typePtr, type, "int"); + function(type, "__atomic_xor_fetch", typePtr, type, "int"); + function(type, "__atomic_or_fetch", typePtr, type, "int"); + function(type, "__atomic_nadd_fetch", typePtr, type, "int"); + function(type, "__atomic_fetch_add", typePtr, type, "int"); + function(type, "__atomic_fetch_sub", typePtr, type, "int"); + function(type, "__atomic_fetch_and", typePtr, type, "int"); + function(type, "__atomic_fetch_xor", typePtr, type, "int"); + function(type, "__atomic_fetch_or", typePtr, type, "int"); + function(type, "__atomic_fetch_nadd", typePtr, type, "int"); } - function("bool", "__atomic_test_and_set", "void*", "int"); - function("bool", "__atomic_test_and_set", "volatile void*", "int"); - function("void", "__atomic_clear", "bool*", "int"); - function("void", "__atomic_clear", "volatile bool*", "int"); - function("void", "__atomic_thread_fence", "int"); - function("void", "__atomic_signal_fence", "int"); - function("bool", "__atomic_always_lock_free", "size_t", "void*"); - function("bool", "__atomic_is_lock_free", "size_t", "void*"); + function("bool", "__atomic_test_and_set", "void*", "int"); + function("bool", "__atomic_test_and_set", "volatile void*", "int"); + function("void", "__atomic_clear", "bool*", "int"); + function("void", "__atomic_clear", "volatile bool*", "int"); + function("void", "__atomic_thread_fence", "int"); + function("void", "__atomic_signal_fence", "int"); + function("bool", "__atomic_always_lock_free", "size_t", "void*"); + function("bool", "__atomic_is_lock_free", "size_t", "void*"); // Other Builtins (https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) [incomplete] - function("void", "__builtin_abort"); - function("int", "__builtin_abs", "int"); - function("double", "__builtin_acos", "double"); - function("float", "__builtin_acosf", "float"); + function("void", "__builtin_abort"); + function("int", "__builtin_abs", "int"); + function("double", "__builtin_acos", "double"); + function("float", "__builtin_acosf", "float"); function("long double", "__builtin_acosl", "long double"); - function("double", "__builtin_acosh", "double"); - function("float", "__builtin_acoshf", "float"); + function("double", "__builtin_acosh", "double"); + function("float", "__builtin_acoshf", "float"); function("long double", "__builtin_acoshl", "long double"); - function("double", "__builtin_asin", "double"); - function("float", "__builtin_asinf", "float"); + function("double", "__builtin_asin", "double"); + function("float", "__builtin_asinf", "float"); function("long double", "__builtin_asinl", "long double"); - function("double", "__builtin_asinh", "double"); - function("float", "__builtin_asinhf", "float"); + function("double", "__builtin_asinh", "double"); + function("float", "__builtin_asinhf", "float"); function("long double", "__builtin_asinhl", "long double"); - function("void*", "__builtin_assume_aligned", "const void*", "size_t", "..."); - function("double", "__builtin_atan", "double"); - function("float", "__builtin_atanf", "float"); + function("void*", "__builtin_assume_aligned", "const void*", "size_t", "..."); + function("double", "__builtin_atan", "double"); + function("float", "__builtin_atanf", "float"); function("long double", "__builtin_atanl", "long double"); - function("double", "__builtin_atanh", "double"); - function("float", "__builtin_atanhf", "float"); + function("double", "__builtin_atanh", "double"); + function("float", "__builtin_atanhf", "float"); function("long double", "__builtin_atanhl", "long double"); - function("double", "__builtin_atan2", "double", "double"); - function("float", "__builtin_atan2f", "float", "float"); + function("double", "__builtin_atan2", "double", "double"); + function("float", "__builtin_atan2f", "float", "float"); function("long double", "__builtin_atan2l", "long double", "long double"); - function("void*", "__builtin_alloca", "size_t"); - cfunction("", "__builtin_choose_expr", "", "", ""); - function("double", "__builtin_cbrt", "double"); - function("float", "__builtin_cbrtf", "float"); + function("void*", "__builtin_alloca", "size_t"); + cfunction("", "__builtin_choose_expr", "", "", ""); + function("double", "__builtin_cbrt", "double"); + function("float", "__builtin_cbrtf", "float"); function("long double", "__builtin_cbrtl", "long double"); - function("double", "__builtin_ceil", "double"); - function("float", "__builtin_ceilf", "float"); + function("double", "__builtin_ceil", "double"); + function("float", "__builtin_ceilf", "float"); function("long double", "__builtin_ceill", "long double"); - function("double", "__builtin_cimag", "complex double"); - function("float", "__builtin_cimagf", "complex float"); + function("double", "__builtin_cimag", "complex double"); + function("float", "__builtin_cimagf", "complex float"); function("long double", "__builtin_cimagl", "complex long double"); - function("int", "__builtin_clz", "unsigned int"); - function("int", "__builtin_clzl", "unsigned long"); - function("int", "__builtin_clzll", "unsigned long long"); - function("complex double", "__builtin_conj", "complex double"); - function("complex float", "__builtin_conjf", "complex float"); + function("int", "__builtin_clz", "unsigned int"); + function("int", "__builtin_clzl", "unsigned long"); + function("int", "__builtin_clzll", "unsigned long long"); + function("complex double", "__builtin_conj", "complex double"); + function("complex float", "__builtin_conjf", "complex float"); function("complex long double", "__builtin_conjl", "complex long double"); - function("int", "__builtin_constant_p", "..."); - function("double", "__builtin_copysign", "double", "double"); - function("float", "__builtin_copysignf", "float", "float"); + function("int", "__builtin_constant_p", "..."); + function("double", "__builtin_copysign", "double", "double"); + function("float", "__builtin_copysignf", "float", "float"); function("long double", "__builtin_copysignl", "long double", "long double"); - function("double", "__builtin_cos", "double"); - function("float", "__builtin_cosf", "float"); + function("double", "__builtin_cos", "double"); + function("float", "__builtin_cosf", "float"); function("long double", "__builtin_cosl", "long double"); - function("double", "__builtin_cosh", "double"); - function("float", "__builtin_coshf", "float"); + function("double", "__builtin_cosh", "double"); + function("float", "__builtin_coshf", "float"); function("long double", "__builtin_coshl", "long double"); - function("double", "__builtin_creal", "complex double"); - function("float", "__builtin_crealf", "complex float"); + function("double", "__builtin_creal", "complex double"); + function("float", "__builtin_crealf", "complex float"); function("long double", "__builtin_creall", "complex long double"); - function("int", "__builtin_ctz", "unsigned int"); - function("int", "__builtin_ctzl", "unsigned long"); - function("int", "__builtin_ctzll", "unsigned long long"); - function("double", "__builtin_erf", "double"); - function("float", "__builtin_erff", "float"); + function("int", "__builtin_ctz", "unsigned int"); + function("int", "__builtin_ctzl", "unsigned long"); + function("int", "__builtin_ctzll", "unsigned long long"); + function("double", "__builtin_erf", "double"); + function("float", "__builtin_erff", "float"); function("long double", "__builtin_erfl", "long double"); - function("double", "__builtin_ercf", "double"); - function("float", "__builtin_erfcf", "float"); + function("double", "__builtin_ercf", "double"); + function("float", "__builtin_erfcf", "float"); function("long double", "__builtin_erfcl", "long double"); - function("void", "__builtin__Exit", "int"); - function("void", "__builtin__exit", "int"); - function("void", "__builtin_exit", "int"); - function("double", "__builtin_exp", "double"); - function("float", "__builtin_expf", "float"); + function("void", "__builtin__Exit", "int"); + function("void", "__builtin__exit", "int"); + function("void", "__builtin_exit", "int"); + function("double", "__builtin_exp", "double"); + function("float", "__builtin_expf", "float"); function("long double", "__builtin_expl", "long double"); - function("double", "__builtin_exp2", "double"); - function("float", "__builtin_exp2f", "float"); + function("double", "__builtin_exp2", "double"); + function("float", "__builtin_exp2f", "float"); function("long double", "__builtin_exp2l", "long double"); - function("double", "__builtin_expm1", "double"); - function("float", "__builtin_expm1f", "float"); + function("double", "__builtin_expm1", "double"); + function("float", "__builtin_expm1f", "float"); function("long double", "__builtin_expm1l", "long double"); - function("long", "__builtin_expect", "long", "long"); - function("double", "__builtin_fabs", "double"); - function("float", "__builtin_fabsf", "float"); + function("long", "__builtin_expect", "long", "long"); + function("double", "__builtin_fabs", "double"); + function("float", "__builtin_fabsf", "float"); function("long double", "__builtin_fabsl", "long double"); - function("double", "__builtin_fdim", "double", "double"); - function("float", "__builtin_fdimf", "float", "float"); + function("double", "__builtin_fdim", "double", "double"); + function("float", "__builtin_fdimf", "float", "float"); function("long double", "__builtin_fdiml", "long double", "long double"); - function("int", "__builtin_ffs", "unsigned int"); - function("int", "__builtin_ffsl", "unsigned long"); - function("int", "__builtin_ffsll", "unsigned long long"); - function("double", "__builtin_floor", "double"); - function("float", "__builtin_floorf", "float"); + function("int", "__builtin_ffs", "unsigned int"); + function("int", "__builtin_ffsl", "unsigned long"); + function("int", "__builtin_ffsll", "unsigned long long"); + function("double", "__builtin_floor", "double"); + function("float", "__builtin_floorf", "float"); function("long double", "__builtin_floorl", "long double"); - function("double", "__builtin_fma", "double", "double", "double"); - function("float", "__builtin_fmaf", "float", "float", "float"); + function("double", "__builtin_fma", "double", "double", "double"); + function("float", "__builtin_fmaf", "float", "float", "float"); function("long double", "__builtin_fmal", "long double", "long double", "long double"); - function("double", "__builtin_fmax", "double", "double"); - function("float", "__builtin_fmaxf", "float", "float"); + function("double", "__builtin_fmax", "double", "double"); + function("float", "__builtin_fmaxf", "float", "float"); function("long double", "__builtin_fmaxl", "long double", "long double"); - function("double", "__builtin_fmin", "double", "double"); - function("float", "__builtin_fminf", "float", "float"); + function("double", "__builtin_fmin", "double", "double"); + function("float", "__builtin_fminf", "float", "float"); function("long double", "__builtin_fminl", "long double", "long double"); - function("double", "__builtin_fmod", "double", "double"); - function("float", "__builtin_fmodf", "float", "float"); + function("double", "__builtin_fmod", "double", "double"); + function("float", "__builtin_fmodf", "float", "float"); function("long double", "__builtin_fmodl", "long double", "long double"); - function("int", "__builtin_fpclassify", "int", "int", "int", "int", "int", "double"); - function("int", "__builtin_fprintf", "FILE*", "const char*"); - function("int", "__builtin_fputs", "const char*", "FILE*"); - function("double", "__builtin_frexp", "double", "int*"); - function("float", "__builtin_frexpf", "float", "int*"); + function("int", "__builtin_fpclassify", "int", "int", "int", "int", "int", "double"); + function("int", "__builtin_fprintf", "FILE*", "const char*"); + function("int", "__builtin_fputs", "const char*", "FILE*"); + function("double", "__builtin_frexp", "double", "int*"); + function("float", "__builtin_frexpf", "float", "int*"); function("long double", "__builtin_frexpl", "long double", "int*"); - function("double", "__builtin_huge_val"); - function("float", "__builtin_huge_valf"); + function("double", "__builtin_huge_val"); + function("float", "__builtin_huge_valf"); function("long double", "__builtin_huge_vall"); - function("double", "__builtin_fhypot", "double"); - function("float", "__builtin_fhypotf", "float"); + function("double", "__builtin_fhypot", "double"); + function("float", "__builtin_fhypotf", "float"); function("long double", "__builtin_fhypotl", "long double"); - function("int", "__builtin_ilogb", "double"); - function("int", "__builtin_ilogbf", "float"); - function("int", "__builtin_ilogbl", "long double"); - function("long long", "__builtin_imaxabs", "long long"); - function("double", "__builtin_inf"); - function("float", "__builtin_inff"); + function("int", "__builtin_ilogb", "double"); + function("int", "__builtin_ilogbf", "float"); + function("int", "__builtin_ilogbl", "long double"); + function("long long", "__builtin_imaxabs", "long long"); + function("double", "__builtin_inf"); + function("float", "__builtin_inff"); function("long double", "__builtin_infl"); - function("bool", "__builtin_isfinite", "double"); - function("bool", "__builtin_isgreater", "float", "float"); - function("bool", "__builtin_isgreaterequal", "float", "float"); - function("bool", "__builtin_isinf", "double"); - function("bool", "__builtin_isless", "float", "float"); - function("bool", "__builtin_islessequal", "float", "float"); - function("bool", "__builtin_islessgreater", "float", "float"); - function("bool", "__builtin_isnan", "double"); - function("bool", "__builtin_isnormal", "double"); - function("bool", "__builtin_isunordered", "float", "float"); - function("long", "__builtin_labs", "long"); - function("double", "__builtin_ldexp", "double", "int"); - function("float", "__builtin_ldexpf", "float", "int"); + function("bool", "__builtin_isfinite", "double"); + function("bool", "__builtin_isgreater", "float", "float"); + function("bool", "__builtin_isgreaterequal", "float", "float"); + function("bool", "__builtin_isinf", "double"); + function("bool", "__builtin_isless", "float", "float"); + function("bool", "__builtin_islessequal", "float", "float"); + function("bool", "__builtin_islessgreater", "float", "float"); + function("bool", "__builtin_isnan", "double"); + function("bool", "__builtin_isnormal", "double"); + function("bool", "__builtin_isunordered", "float", "float"); + function("long", "__builtin_labs", "long"); + function("double", "__builtin_ldexp", "double", "int"); + function("float", "__builtin_ldexpf", "float", "int"); function("long double", "__builtin_ldexpl", "long double", "int"); - function("double", "__builtin_lgamma", "double"); - function("float", "__builtin_lgammaf", "float"); + function("double", "__builtin_lgamma", "double"); + function("float", "__builtin_lgammaf", "float"); function("long double", "__builtin_lgammal", "long double"); - function("long long", "__builtin_llabs", "long long"); - function("long long", "__builtin_llrint", "double"); - function("long long", "__builtin_llrintf", "float"); - function("long long", "__builtin_llrintl", "long double"); - function("long long", "__builtin_llround", "double"); - function("long long", "__builtin_llroundf", "float"); - function("long long", "__builtin_llroundl", "long double"); - function("double", "__builtin_log", "double"); - function("float", "__builtin_logf", "float"); + function("long long", "__builtin_llabs", "long long"); + function("long long", "__builtin_llrint", "double"); + function("long long", "__builtin_llrintf", "float"); + function("long long", "__builtin_llrintl", "long double"); + function("long long", "__builtin_llround", "double"); + function("long long", "__builtin_llroundf", "float"); + function("long long", "__builtin_llroundl", "long double"); + function("double", "__builtin_log", "double"); + function("float", "__builtin_logf", "float"); function("long double", "__builtin_logl", "long double"); - function("double", "__builtin_log10", "double"); - function("float", "__builtin_log10f", "float"); + function("double", "__builtin_log10", "double"); + function("float", "__builtin_log10f", "float"); function("long double", "__builtin_log10l", "long double"); - function("double", "__builtin_log1p", "double"); - function("float", "__builtin_log1pf", "float"); + function("double", "__builtin_log1p", "double"); + function("float", "__builtin_log1pf", "float"); function("long double", "__builtin_log1pl", "long double"); - function("double", "__builtin_log2", "double"); - function("float", "__builtin_log2f", "float"); + function("double", "__builtin_log2", "double"); + function("float", "__builtin_log2f", "float"); function("long double", "__builtin_log2l", "long double"); - function("double", "__builtin_logb", "double"); - function("float", "__builtin_logbf", "float"); + function("double", "__builtin_logb", "double"); + function("float", "__builtin_logbf", "float"); function("long double", "__builtin_logbl", "long double"); - function("long", "__builtin_lrint", "double"); - function("long", "__builtin_lrintf", "float"); - function("long", "__builtin_lrintl", "long double"); - function("long", "__builtin_lround", "double"); - function("long", "__builtin_lroundf", "float"); - function("long", "__builtin_lroundl", "long double"); - function("float", "__builtin_modff", "float", "float*"); + function("long", "__builtin_lrint", "double"); + function("long", "__builtin_lrintf", "float"); + function("long", "__builtin_lrintl", "long double"); + function("long", "__builtin_lround", "double"); + function("long", "__builtin_lroundf", "float"); + function("long", "__builtin_lroundl", "long double"); + function("float", "__builtin_modff", "float", "float*"); function("long double", "__builtin_modfl", "long double", "long double*"); - function("void*", "__builtin_memchr", "const void*", "int", "size_t"); // not in the manual - function("int", "__builtin_memcmp", "const void*", "const void*", "size_t"); - function("void*", "__builtin_memcpy", "void*", "const void*", "size_t"); - function("void*", "__builtin_memmove", "void*", "const void*", "size_t"); // not in the manual - function("void*", "__builtin_memset", "void*", "int", "size_t"); - function("double", "__builtin_nan", "const char*"); - function("float", "__builtin_nanf", "const char*"); + function("void*", "__builtin_memchr", "const void*", "int", "size_t"); // not in the manual + function("int", "__builtin_memcmp", "const void*", "const void*", "size_t"); + function("void*", "__builtin_memcpy", "void*", "const void*", "size_t"); + function("void*", "__builtin_memmove", "void*", "const void*", "size_t"); // not in the manual + function("void*", "__builtin_memset", "void*", "int", "size_t"); + function("double", "__builtin_nan", "const char*"); + function("float", "__builtin_nanf", "const char*"); function("long double", "__builtin_nanl", "const char*"); - function("double", "__builtin_nans", "const char*"); - function("float", "__builtin_nansf", "const char*"); + function("double", "__builtin_nans", "const char*"); + function("float", "__builtin_nansf", "const char*"); function("long double", "__builtin_nansl", "const char*"); - function("double", "__builtin_nearby", "double"); - function("float", "__builtin_nearbyf", "float"); + function("double", "__builtin_nearby", "double"); + function("float", "__builtin_nearbyf", "float"); function("long double", "__builtin_nearbyl", "long double"); - function("double", "__builtin_nextafter", "double", "double"); - function("float", "__builtin_nextafterf", "float", "float"); + function("double", "__builtin_nextafter", "double", "double"); + function("float", "__builtin_nextafterf", "float", "float"); function("long double", "__builtin_nextafterl", "long double", "long double"); - function("double", "__builtin_nexttoward", "double", "long double"); - function("float", "__builtin_nexttowardf", "float", "long double"); + function("double", "__builtin_nexttoward", "double", "long double"); + function("float", "__builtin_nexttowardf", "float", "long double"); function("long double", "__builtin_nexttowardl", "long double", "long double"); - function("int", "__builtin_parity", "unsigned int"); - function("int", "__builtin_parityl", "unsigned long"); - function("int", "__builtin_parityll", "unsigned long long"); - function("int", "__builtin_popcount", "unsigned int"); - function("int", "__builtin_popcountl", "unsigned long"); - function("int", "__builtin_popcountll", "unsigned long long"); - function("double", "__builtin_pow", "double", "double"); - function("float", "__builtin_powf", "float", "float"); + function("int", "__builtin_parity", "unsigned int"); + function("int", "__builtin_parityl", "unsigned long"); + function("int", "__builtin_parityll", "unsigned long long"); + function("int", "__builtin_popcount", "unsigned int"); + function("int", "__builtin_popcountl", "unsigned long"); + function("int", "__builtin_popcountll", "unsigned long long"); + function("double", "__builtin_pow", "double", "double"); + function("float", "__builtin_powf", "float", "float"); function("long double", "__builtin_powl", "long double", "long double"); - function("double", "__builtin_powi", "double", "int"); - function("float", "__builtin_powif", "float", "int"); + function("double", "__builtin_powi", "double", "int"); + function("float", "__builtin_powif", "float", "int"); function("long double", "__builtin_powil", "long double", "int"); - function("void", "__builtin_prefetch", "const void*", "..."); - function("int", "__builtin_printf", "const char*", "..."); - function("int", "__builtin_putchar", "int"); - function("int", "__builtin_puts", "const char*"); - function("double", "__builtin_remainder", "double", "double"); - function("float", "__builtin_remainderf", "float", "float"); + function("void", "__builtin_prefetch", "const void*", "..."); + function("int", "__builtin_printf", "const char*", "..."); + function("int", "__builtin_putchar", "int"); + function("int", "__builtin_puts", "const char*"); + function("double", "__builtin_remainder", "double", "double"); + function("float", "__builtin_remainderf", "float", "float"); function("long double", "__builtin_remainderl", "long double", "long double"); - function("double", "__builtin_remquo", "double", "double", "int*"); - function("float", "__builtin_remquof", "float", "float", "int*"); + function("double", "__builtin_remquo", "double", "double", "int*"); + function("float", "__builtin_remquof", "float", "float", "int*"); function("long double", "__builtin_remquol", "long double", "long double", "int*"); - function("double", "__builtin_rint", "double"); - function("float", "__builtin_rintf", "float"); + function("double", "__builtin_rint", "double"); + function("float", "__builtin_rintf", "float"); function("long double", "__builtin_rintl", "long double"); - function("double", "__builtin_round", "double"); - function("float", "__builtin_roundf", "float"); + function("double", "__builtin_round", "double"); + function("float", "__builtin_roundf", "float"); function("long double", "__builtin_roundl", "long double"); - function("double", "__builtin_scalbln", "double", "long"); - function("float", "__builtin_scalblnf", "float", "long"); + function("double", "__builtin_scalbln", "double", "long"); + function("float", "__builtin_scalblnf", "float", "long"); function("long double", "__builtin_scalblnl", "long double", "long"); - function("double", "__builtin_scalbn", "double", "int"); - function("float", "__builtin_scalbnf", "float", "int"); + function("double", "__builtin_scalbn", "double", "int"); + function("float", "__builtin_scalbnf", "float", "int"); function("long double", "__builtin_scalbnl", "long double", "int"); - function("int", "__builtin_scanf", "const char*", "..."); - function("bool", "__builtin_signbit", "double"); - function("double", "__builtin_sin", "double"); - function("float", "__builtin_sinf", "float"); + function("int", "__builtin_scanf", "const char*", "..."); + function("bool", "__builtin_signbit", "double"); + function("double", "__builtin_sin", "double"); + function("float", "__builtin_sinf", "float"); function("long double", "__builtin_sinl", "long double"); - function("double", "__builtin_sinh", "double"); - function("float", "__builtin_sinhf", "float"); + function("double", "__builtin_sinh", "double"); + function("float", "__builtin_sinhf", "float"); function("long double", "__builtin_sinhl", "long double"); - function("int", "__builtin_snprintf", "char*", "size_t", "const char*", "..."); - function("int", "__builtin_sprintf", "char*", "const char*", "..."); - function("double", "__builtin_sqrt", "double"); - function("float", "__builtin_sqrtf", "float"); + function("int", "__builtin_snprintf", "char*", "size_t", "const char*", "..."); + function("int", "__builtin_sprintf", "char*", "const char*", "..."); + function("double", "__builtin_sqrt", "double"); + function("float", "__builtin_sqrtf", "float"); function("long double", "__builtin_sqrtl", "long double"); - function("int", "__builtin_sscanf", "const char*", "const char*", "..."); - function("char*", "__builtin_strcat", "char*", "const char*"); - function("char*", "__builtin_strchr", "const char*", "int"); - function("int", "__builtin_strcmp", "const char*", "const char*"); - function("char*", "__builtin_strcpy", "char*", "const char*"); - function("size_t", "__builtin_strcspn", "const char*", "const char*"); - function("size_t", "__builtin_strlen", "const char*"); - function("char*", "__builtin_strncat", "char*", "const char*", "size_t"); - function("int", "__builtin_strncmp", "const char*", "const char*", "size_t"); - function("char*", "__builtin_strncpy", "char*", "const char*", "size_t"); - function("char*", "__builtin_strpbrk", "const char*", "const char*"); - function("char*", "__builtin_strrchr", "const char*", "int"); - function("size_t", "__builtin_strspn", "const char*", "const char*"); - function("char*", "__builtin_strstr", "const char*", "const char*"); - function("double", "__builtin_tan", "double"); - function("float", "__builtin_tanf", "float"); + function("int", "__builtin_sscanf", "const char*", "const char*", "..."); + function("char*", "__builtin_strcat", "char*", "const char*"); + function("char*", "__builtin_strchr", "const char*", "int"); + function("int", "__builtin_strcmp", "const char*", "const char*"); + function("char*", "__builtin_strcpy", "char*", "const char*"); + function("size_t", "__builtin_strcspn", "const char*", "const char*"); + function("size_t", "__builtin_strlen", "const char*"); + function("char*", "__builtin_strncat", "char*", "const char*", "size_t"); + function("int", "__builtin_strncmp", "const char*", "const char*", "size_t"); + function("char*", "__builtin_strncpy", "char*", "const char*", "size_t"); + function("char*", "__builtin_strpbrk", "const char*", "const char*"); + function("char*", "__builtin_strrchr", "const char*", "int"); + function("size_t", "__builtin_strspn", "const char*", "const char*"); + function("char*", "__builtin_strstr", "const char*", "const char*"); + function("double", "__builtin_tan", "double"); + function("float", "__builtin_tanf", "float"); function("long double", "__builtin_tanl", "long double"); - function("double", "__builtin_tanh", "double"); - function("float", "__builtin_tanhf", "float"); + function("double", "__builtin_tanh", "double"); + function("float", "__builtin_tanhf", "float"); function("long double", "__builtin_tanhl", "long double"); - function("double", "__builtin_tgamma", "double"); - function("float", "__builtin_tgammaf", "float"); + function("double", "__builtin_tgamma", "double"); + function("float", "__builtin_tgammaf", "float"); function("long double", "__builtin_tgammal", "long double"); - function("double", "__builtin_trunc", "double"); - function("float", "__builtin_truncf", "float"); + function("double", "__builtin_trunc", "double"); + function("float", "__builtin_truncf", "float"); function("long double", "__builtin_truncl", "long double"); - function("int", "__builtin_types_compatible_p", "", ""); - function("int", "__builtin_vprintf", "const char*", "va_list"); - function("int", "__builtin_vscanf", "const char*", "va_list"); - function("int", "__builtin_vsnprintf", "char*", "size_t", "const char*", "va_list"); - function("int", "__builtin_vsprintf", "char*", "const char*", "va_list"); - function("int", "__builtin_vsscanf", "const char*", "const char*", "va_list"); - + function("int", "__builtin_types_compatible_p", "", ""); + function("int", "__builtin_vprintf", "const char*", "va_list"); + function("int", "__builtin_vscanf", "const char*", "va_list"); + function("int", "__builtin_vsnprintf", "char*", "size_t", "const char*", "va_list"); + function("int", "__builtin_vsprintf", "char*", "const char*", "va_list"); + function("int", "__builtin_vsscanf", "const char*", "const char*", "va_list"); + // Object size checking (https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html) [incomplete] - function("size_t", "__builtin_object_size", "const void*", "int"); - + function("size_t", "__builtin_object_size", "const void*", "int"); + // x86 built-in functions (https://gcc.gnu.org/onlinedocs/gcc/x86-Built-in-Functions.html) [incomplete] - function("double", "__builtin_ia32_shufpd", "double", "double", "int"); - } + function("double", "__builtin_ia32_shufpd", "double", "double", "int"); + } private void variable(String type, String name) { IBinding b = fCpp ? new CPPBuiltinVariable(toType(type), toCharArray(name), fScope) @@ -482,7 +482,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { private void function(String returnType, String name, String... parameterTypes) { int len = parameterTypes.length; - boolean varargs= len > 0 && parameterTypes[len - 1].equals("..."); + boolean varargs = len > 0 && parameterTypes[len - 1].equals("..."); if (varargs) len--; @@ -496,18 +496,18 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { IType rt = toType(returnType); IFunctionType ft = fCpp ? new CPPFunctionType(rt, pTypes) : new CFunctionType(rt, pTypes); - IBinding b = fCpp ? - new CPPImplicitFunction(toCharArray(name), fScope, (ICPPFunctionType) ft, - (ICPPParameter[]) theParms, false, varargs) : - new CImplicitFunction(toCharArray(name), fScope, ft, theParms, varargs); + IBinding b = fCpp + ? new CPPImplicitFunction(toCharArray(name), fScope, (ICPPFunctionType) ft, (ICPPParameter[]) theParms, + false, varargs) + : new CImplicitFunction(toCharArray(name), fScope, ft, theParms, varargs); fBindingList.add(b); } private char[] toCharArray(String name) { - synchronized(CHAR_ARRAYS) { - char[] result= CHAR_ARRAYS.get(name); + synchronized (CHAR_ARRAYS) { + char[] result = CHAR_ARRAYS.get(name); if (result == null) { - result= name.toCharArray(); + result = name.toCharArray(); CHAR_ARRAYS.put(name, result); } return result; @@ -515,28 +515,28 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { } private IType toType(String type) { - IType t= fTypeMap.get(type); + IType t = fTypeMap.get(type); if (t == null) { - t= createType(type); + t = createType(type); fTypeMap.put(type, t); } return t; } private IType createType(final String type) { - String tstr= type; + String tstr = type; if (fCpp && tstr.endsWith("&")) { - final String nested = tstr.substring(0, tstr.length() - 1).trim(); + final String nested = tstr.substring(0, tstr.length() - 1).trim(); return new CPPReferenceType(toType(nested), false); } if (tstr.equals("FILE*")) { return toType("void*"); } else if (tstr.endsWith("*")) { - final String nested = tstr.substring(0, tstr.length() - 1).trim(); - final IType nt= toType(nested); + final String nested = tstr.substring(0, tstr.length() - 1).trim(); + final IType nt = toType(nested); return fCpp ? new CPPPointerType(nt) : new CPointerType(nt, 0); } else if (tstr.endsWith("[1]")) { - final String nested = tstr.substring(0, tstr.length()-3).trim(); + final String nested = tstr.substring(0, tstr.length() - 3).trim(); final IType nt = toType(nested); return fCpp ? new CPPArrayType(nt, IntegralValue.create(1)) : new CArrayType(nt); } @@ -544,41 +544,41 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { boolean isConst = false; boolean isVolatile = false; if (tstr.startsWith("const ")) { - isConst= true; - tstr= tstr.substring(6); + isConst = true; + tstr = tstr.substring(6); } if (tstr.endsWith("const")) { - isConst= true; - tstr= tstr.substring(0, tstr.length() - 5).trim(); + isConst = true; + tstr = tstr.substring(0, tstr.length() - 5).trim(); } if (tstr.startsWith("volatile ")) { - isVolatile= true; - tstr= tstr.substring(9); + isVolatile = true; + tstr = tstr.substring(9); } if (tstr.endsWith("volatile")) { - isVolatile= true; - tstr= tstr.substring(0, tstr.length() - 8).trim(); + isVolatile = true; + tstr = tstr.substring(0, tstr.length() - 8).trim(); } - int q= 0; + int q = 0; if (tstr.startsWith("signed ")) { q |= IBasicType.IS_SIGNED; - tstr= tstr.substring(7); + tstr = tstr.substring(7); } if (tstr.startsWith("unsigned ")) { q |= IBasicType.IS_UNSIGNED; - tstr= tstr.substring(9); + tstr = tstr.substring(9); } if (tstr.startsWith("complex ")) { q |= IBasicType.IS_COMPLEX; - tstr= tstr.substring(8); + tstr = tstr.substring(8); } if (tstr.startsWith("long long")) { q |= IBasicType.IS_LONG_LONG; - tstr= tstr.substring(9).trim(); + tstr = tstr.substring(9).trim(); } if (tstr.startsWith("long")) { q |= IBasicType.IS_LONG; - tstr= tstr.substring(4).trim(); + tstr = tstr.substring(4).trim(); } IType t; @@ -607,24 +607,23 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { t = fCpp ? new CPPBasicType(Kind.eBoolean, q) : new CBasicType(Kind.eInt, q); } else if (tstr.equals("va_list")) { // Use 'char*(*)()' - IType rt= toType("char*"); - t = fCpp ? new CPPPointerType(new CPPFunctionType(rt, IType.EMPTY_TYPE_ARRAY)) : - new CPointerType(new CFunctionType(rt, IType.EMPTY_TYPE_ARRAY), 0); + IType rt = toType("char*"); + t = fCpp ? new CPPPointerType(new CPPFunctionType(rt, IType.EMPTY_TYPE_ARRAY)) + : new CPointerType(new CFunctionType(rt, IType.EMPTY_TYPE_ARRAY), 0); } else if (tstr.equals("size_t")) { - t= toType("unsigned long"); + t = toType("unsigned long"); } else if (tstr.equals("void*")) { // This can occur inside a qualifier type in which case it's not handled // by the general '*' check above. - t= fCpp ? new CPPPointerType(new CPPBasicType(Kind.eVoid, q)) + t = fCpp ? new CPPPointerType(new CPPBasicType(Kind.eVoid, q)) : new CPointerType(new CBasicType(Kind.eVoid, q), 0); } else { throw new IllegalArgumentException(type); } if (isConst || isVolatile) { - return fCpp ? - new CPPQualifierType(t, isConst, isVolatile) : - new CQualifierType(t, isConst, isVolatile, false); + return fCpp ? new CPPQualifierType(t, isConst, isVolatile) + : new CQualifierType(t, isConst, isVolatile, false); } return t; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java index ed417c05382..6f5f692cd9d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java @@ -16,5 +16,5 @@ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.IASTNode; public interface IASTAmbiguityParent { - public void replace(IASTNode child, IASTNode other); + public void replace(IASTNode child, IASTNode other); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclarator.java index 0b86cc84394..43bc81b58ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousDeclarator.java @@ -22,15 +22,15 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator; */ public interface IASTAmbiguousDeclarator extends IASTDeclarator { - public static final ASTNodeProperty SUBDECLARATOR = new ASTNodeProperty("IASTAmbiguousDeclarator.SUBDECLARATOR"); //$NON-NLS-1$ + public static final ASTNodeProperty SUBDECLARATOR = new ASTNodeProperty("IASTAmbiguousDeclarator.SUBDECLARATOR"); //$NON-NLS-1$ - /** - * Add an alternative to this ambiguous declarator. - */ - public void addDeclarator(IASTDeclarator e); + /** + * Add an alternative to this ambiguous declarator. + */ + public void addDeclarator(IASTDeclarator e); - /** - * Return an array of all alternatives for this ambiguous declarator. - */ - public IASTDeclarator[] getDeclarators(); + /** + * Return an array of all alternatives for this ambiguous declarator. + */ + public IASTDeclarator[] getDeclarators(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousExpression.java index 1b4edeff13a..918b7582653 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousExpression.java @@ -18,7 +18,9 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; public interface IASTAmbiguousExpression extends IASTExpression { - public static final ASTNodeProperty SUBEXPRESSION = new ASTNodeProperty("IASTAmbiguousExpression.SUBEXPRESSION"); //$NON-NLS-1$ - public void addExpression(IASTExpression e); - public IASTExpression [] getExpressions(); + public static final ASTNodeProperty SUBEXPRESSION = new ASTNodeProperty("IASTAmbiguousExpression.SUBEXPRESSION"); //$NON-NLS-1$ + + public void addExpression(IASTExpression e); + + public IASTExpression[] getExpressions(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousParameterDeclaration.java index 45d6cb0dd45..bc0dd2f14a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousParameterDeclaration.java @@ -22,15 +22,16 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; */ public interface IASTAmbiguousParameterDeclaration extends IASTParameterDeclaration { - public static final ASTNodeProperty SUBDECLARATION = new ASTNodeProperty("IASTAmbiguousParameterDeclaration.SUBDECLARATION"); //$NON-NLS-1$ + public static final ASTNodeProperty SUBDECLARATION = new ASTNodeProperty( + "IASTAmbiguousParameterDeclaration.SUBDECLARATION"); //$NON-NLS-1$ - /** - * Add an alternative to this ambiguous parameter declaration. - */ - public void addParameterDeclaration(IASTParameterDeclaration e); + /** + * Add an alternative to this ambiguous parameter declaration. + */ + public void addParameterDeclaration(IASTParameterDeclaration e); - /** - * Return an array of all alternatives for this ambiguous parameter declaration. - */ - public IASTParameterDeclaration[] getParameterDeclarations(); + /** + * Return an array of all alternatives for this ambiguous parameter declaration. + */ + public IASTParameterDeclaration[] getParameterDeclarations(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java index 985e93bce7d..6b6c8a02bf7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java @@ -17,9 +17,10 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.IASTStatement; public interface IASTAmbiguousStatement extends IASTStatement { - public static final ASTNodeProperty STATEMENT = new ASTNodeProperty("IASTAmbiguousStatement.STATEMENT - Ambiguous statement."); //$NON-NLS-1$ + public static final ASTNodeProperty STATEMENT = new ASTNodeProperty( + "IASTAmbiguousStatement.STATEMENT - Ambiguous statement."); //$NON-NLS-1$ - public void addStatement(IASTStatement s); + public void addStatement(IASTStatement s); - public IASTStatement[] getStatements(); + public IASTStatement[] getStatements(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java index 2f8082d1fa7..7dd35b6f9cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java @@ -22,10 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IScope; * Interface for methods on scopes that are internal to the AST. */ public interface IASTInternalScope extends IScope { - /** - * Returns the physical IASTNode that this scope was created for - */ - public IASTNode getPhysicalNode(); + /** + * Returns the physical IASTNode that this scope was created for + */ + public IASTNode getPhysicalNode(); /** * Adds an IBinding to the scope. It is primarily used by the parser to add @@ -37,7 +37,7 @@ public interface IASTInternalScope extends IScope { * Adds an IASTName to be cached in this scope. * @param adlOnly whether this declaration of this name only makes the name visible to * argument-dependent lookup - * + * * Implementation note: only CPPNamespaceScope cares about "adlOnly". */ public void addName(IASTName name, boolean adlOnly); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java index f6302184d01..6471c9ba555 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeContainer.java @@ -20,13 +20,13 @@ import org.eclipse.cdt.core.dom.ast.IType; * Internal interface representing types that contain other types */ public interface ITypeContainer extends IType { - /** - * Returns the type this container contains. - */ - IType getType(); + /** + * Returns the type this container contains. + */ + IType getType(); - /** - * Sets the type this container contains. - */ - void setType(IType type); + /** + * Sets the type this container contains. + */ + void setType(IType type); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java index a7333c48398..fab7f546028 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java @@ -28,79 +28,31 @@ import org.eclipse.core.runtime.CoreException; * Buffer for marshalling and unmarshalling types. */ public interface ITypeMarshalBuffer { - final static byte - BASIC_TYPE = 0x01, - POINTER_TYPE = 0x02, - ARRAY_TYPE = 0x03, - CVQUALIFIER_TYPE = 0x04, - FUNCTION_TYPE = 0x05, - REFERENCE_TYPE = 0x06, - POINTER_TO_MEMBER_TYPE = 0x07, - PACK_EXPANSION_TYPE = 0x08, - PROBLEM_TYPE = 0x09, - VALUE = 0x0A, - DEPENDENT_EXPRESSION_TYPE = 0x0B, - UNKNOWN_MEMBER = 0x0C, - UNKNOWN_MEMBER_CLASS_INSTANCE = 0x0D, - DEFERRED_CLASS_INSTANCE = 0x0E, - TYPE_TRANSFORMATION = 0x0F, - UNKNOWN_MEMBER_TYPE = 0x10, - INITIALIZER_LIST_TYPE = 0x11, - DEFERRED_FUNCTION = 0x12, - DEFERRED_VARIABLE_INSTANCE = 0x13, - PLACEHOLDER_TYPE = 0x14; + final static byte BASIC_TYPE = 0x01, POINTER_TYPE = 0x02, ARRAY_TYPE = 0x03, CVQUALIFIER_TYPE = 0x04, + FUNCTION_TYPE = 0x05, REFERENCE_TYPE = 0x06, POINTER_TO_MEMBER_TYPE = 0x07, PACK_EXPANSION_TYPE = 0x08, + PROBLEM_TYPE = 0x09, VALUE = 0x0A, DEPENDENT_EXPRESSION_TYPE = 0x0B, UNKNOWN_MEMBER = 0x0C, + UNKNOWN_MEMBER_CLASS_INSTANCE = 0x0D, DEFERRED_CLASS_INSTANCE = 0x0E, TYPE_TRANSFORMATION = 0x0F, + UNKNOWN_MEMBER_TYPE = 0x10, INITIALIZER_LIST_TYPE = 0x11, DEFERRED_FUNCTION = 0x12, + DEFERRED_VARIABLE_INSTANCE = 0x13, PLACEHOLDER_TYPE = 0x14; // Can add more types up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. - final static byte - INTEGRAL_VALUE = 0x01, - FLOATING_POINT_VALUE = 0x02, - C_STRING_VALUE = 0x03, - COMPOSITE_VALUE = 0x04, - DEPENDENT_VALUE = 0x05; + final static byte INTEGRAL_VALUE = 0x01, FLOATING_POINT_VALUE = 0x02, C_STRING_VALUE = 0x03, COMPOSITE_VALUE = 0x04, + DEPENDENT_VALUE = 0x05; // Can add more values up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. - final static byte - EVAL_BINARY = 0x01, - EVAL_BINARY_TYPE_ID = 0x02, - EVAL_BINDING = 0x03, - EVAL_COMMA = 0x04, - EVAL_COMPOUND = 0x05, - EVAL_CONDITIONAL = 0x06, - EVAL_FIXED = 0x07, - EVAL_FUNCTION_CALL = 0x08, - EVAL_FUNCTION_SET = 0x09, - EVAL_ID = 0x0A, - EVAL_INIT_LIST = 0x0B, - EVAL_MEMBER_ACCESS = 0x0C, - EVAL_PACK_EXPANSION = 0x0D, - EVAL_TYPE_ID = 0x0E, - EVAL_UNARY = 0x0F, - EVAL_UNARY_TYPE_ID = 0x10, - EVAL_CONSTRUCTOR = 0x11, - EVAL_REFERENCE = 0x12, - EVAL_POINTER = 0x13, - EVAL_COMPOSITE_ACCESS = 0x14, - EVAL_NARY_TYPE_ID = 0x15; + final static byte EVAL_BINARY = 0x01, EVAL_BINARY_TYPE_ID = 0x02, EVAL_BINDING = 0x03, EVAL_COMMA = 0x04, + EVAL_COMPOUND = 0x05, EVAL_CONDITIONAL = 0x06, EVAL_FIXED = 0x07, EVAL_FUNCTION_CALL = 0x08, + EVAL_FUNCTION_SET = 0x09, EVAL_ID = 0x0A, EVAL_INIT_LIST = 0x0B, EVAL_MEMBER_ACCESS = 0x0C, + EVAL_PACK_EXPANSION = 0x0D, EVAL_TYPE_ID = 0x0E, EVAL_UNARY = 0x0F, EVAL_UNARY_TYPE_ID = 0x10, + EVAL_CONSTRUCTOR = 0x11, EVAL_REFERENCE = 0x12, EVAL_POINTER = 0x13, EVAL_COMPOSITE_ACCESS = 0x14, + EVAL_NARY_TYPE_ID = 0x15; // Can add more evaluations up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. - final static byte - EXEC_COMPOUND_STATEMENT = 0x01, - EXEC_BREAK = 0x02, - EXEC_CASE = 0x03, - EXEC_CONTINUE = 0x04, - EXEC_DECLARATION_STATEMENT = 0x05, - EXEC_DECLARATOR = 0x06, - EXEC_DEFAULT = 0x07, - EXEC_SIMPLE_DECLARATION = 0x08, - EXEC_RETURN = 0x09, - EXEC_EXPRESSION_STATEMENT = 0x0A, - EXEC_IF = 0x0B, - EXEC_WHILE = 0x0C, - EXEC_DO = 0x0D, - EXEC_FOR = 0x0E, - EXEC_RANGE_BASED_FOR = 0x0F, - EXEC_SWITCH = 0x10, - EXEC_CONSTRUCTOR_CHAIN = 0x11; + final static byte EXEC_COMPOUND_STATEMENT = 0x01, EXEC_BREAK = 0x02, EXEC_CASE = 0x03, EXEC_CONTINUE = 0x04, + EXEC_DECLARATION_STATEMENT = 0x05, EXEC_DECLARATOR = 0x06, EXEC_DEFAULT = 0x07, + EXEC_SIMPLE_DECLARATION = 0x08, EXEC_RETURN = 0x09, EXEC_EXPRESSION_STATEMENT = 0x0A, EXEC_IF = 0x0B, + EXEC_WHILE = 0x0C, EXEC_DO = 0x0D, EXEC_FOR = 0x0E, EXEC_RANGE_BASED_FOR = 0x0F, EXEC_SWITCH = 0x10, + EXEC_CONSTRUCTOR_CHAIN = 0x11; // Can add more executions up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. static final short KIND_MASK = 0x001F; @@ -115,19 +67,26 @@ public interface ITypeMarshalBuffer { final static short FLAG8 = 0x1000; final static short FLAG9 = 0x2000; - final static short FIRST_FLAG = FLAG1; + final static short FIRST_FLAG = FLAG1; final static short SECOND_LAST_FLAG = FLAG8; - final static short LAST_FLAG = FLAG9; + final static short LAST_FLAG = FLAG9; CoreException unmarshallingError(); IType unmarshalType() throws CoreException; + IValue unmarshalValue() throws CoreException; + IBinding unmarshalBinding() throws CoreException; + ICPPEvaluation unmarshalEvaluation() throws CoreException; + ICPPExecution unmarshalExecution() throws CoreException; + ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException; + int getByte() throws CoreException; + int getFixedInt() throws CoreException; /** @@ -148,12 +107,19 @@ public interface ITypeMarshalBuffer { char[] getCharArray() throws CoreException; void marshalType(IType type) throws CoreException; + void marshalValue(IValue value) throws CoreException; + void marshalBinding(IBinding binding) throws CoreException; + void marshalEvaluation(ICPPEvaluation eval, boolean includeValue) throws CoreException; + void marshalExecution(ICPPExecution exec, boolean includeValue) throws CoreException; + void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException; + void putByte(byte data); + void putFixedInt(int data); /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java index 182497c9e62..1cf9d4f822b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java @@ -49,24 +49,19 @@ public class IntegralValue implements IValue { }; // IntegralValue.ERROR indicates that an error, such as a substitution failure, occurred during evaluation. - public static final IntegralValue ERROR= new IntegralValue("<error>".toCharArray()); //$NON-NLS-1$ + public static final IntegralValue ERROR = new IntegralValue("<error>".toCharArray()); //$NON-NLS-1$ - public static final IntegralValue NOT_INITIALIZED= new IntegralValue("<__>".toCharArray()); //$NON-NLS-1$ + public static final IntegralValue NOT_INITIALIZED = new IntegralValue("<__>".toCharArray()); //$NON-NLS-1$ private static final char UNIQUE_CHAR = '_'; - private final static IntegralValue[] TYPICAL= { - new IntegralValue(new char[] {'-', '1'}), - new IntegralValue(new char[] {'0'}), - new IntegralValue(new char[] {'1'}), - new IntegralValue(new char[] {'2'}), - new IntegralValue(new char[] {'3'}), - new IntegralValue(new char[] {'4'}), - new IntegralValue(new char[] {'5'}), - new IntegralValue(new char[] {'6'}), - new IntegralValue(new char[] {'7'})}; + private final static IntegralValue[] TYPICAL = { new IntegralValue(new char[] { '-', '1' }), + new IntegralValue(new char[] { '0' }), new IntegralValue(new char[] { '1' }), + new IntegralValue(new char[] { '2' }), new IntegralValue(new char[] { '3' }), + new IntegralValue(new char[] { '4' }), new IntegralValue(new char[] { '5' }), + new IntegralValue(new char[] { '6' }), new IntegralValue(new char[] { '7' }) }; - private static int sUnique= 0; + private static int sUnique = 0; private final char[] fFixedValue; @@ -78,7 +73,7 @@ public class IntegralValue implements IValue { public final Number numberValue() { return parseLong(fFixedValue); } - + @Override public ICPPEvaluation getEvaluation() { return null; @@ -94,13 +89,14 @@ public class IntegralValue implements IValue { if (UNKNOWN == this) { buf.putShort((short) (ITypeMarshalBuffer.INTEGRAL_VALUE | ITypeMarshalBuffer.FLAG1)); } else if (ERROR == this) { - buf.putShort((short) (ITypeMarshalBuffer.INTEGRAL_VALUE | ITypeMarshalBuffer.FLAG1 | ITypeMarshalBuffer.FLAG2)); + buf.putShort( + (short) (ITypeMarshalBuffer.INTEGRAL_VALUE | ITypeMarshalBuffer.FLAG1 | ITypeMarshalBuffer.FLAG2)); } else if (THIS == this) { buf.putShort((short) (ITypeMarshalBuffer.INTEGRAL_VALUE | ITypeMarshalBuffer.FLAG5)); } else { - Number num= numberValue(); + Number num = numberValue(); if (num != null) { - long lv= num.longValue(); + long lv = num.longValue(); if (lv >= 0) { buf.putShort((short) (ITypeMarshalBuffer.INTEGRAL_VALUE | ITypeMarshalBuffer.FLAG2)); buf.putLong(lv); @@ -184,8 +180,8 @@ public class IntegralValue implements IValue { } ICPPEvaluation arg1 = value.getEvaluation(); EvalFixed arg2 = new EvalFixed(CPPBasicType.INT, ValueCategory.PRVALUE, create(increment)); - return DependentValue.create(new EvalBinary(IASTBinaryExpression.op_plus, arg1, arg2, - arg1.getTemplateDefinition())); + return DependentValue + .create(new EvalBinary(IASTBinaryExpression.op_plus, arg1, arg2, arg1.getTemplateDefinition())); } /** @@ -226,7 +222,7 @@ public class IntegralValue implements IValue { * Creates a unique value needed during template instantiation. */ public static IValue unique() { - StringBuilder buf= new StringBuilder(10); + StringBuilder buf = new StringBuilder(10); buf.append(UNIQUE_CHAR); buf.append(++sUnique); return new IntegralValue(CharArrayUtils.extractChars(buf)); @@ -236,11 +232,11 @@ public class IntegralValue implements IValue { * Parses a long, returns <code>null</code> if not possible */ private static Long parseLong(char[] value) { - final long maxvalue= Long.MAX_VALUE / 10; - final int len= value.length; - boolean negative= false; + final long maxvalue = Long.MAX_VALUE / 10; + final int len = value.length; + boolean negative = false; long result = 0; - int i= 0; + int i = 0; if (len > 0 && value[0] == '-') { negative = true; @@ -253,10 +249,10 @@ public class IntegralValue implements IValue { if (result > maxvalue) return null; - final int digit= (value[i] - '0'); + final int digit = (value[i] - '0'); if (digit < 0 || digit > 9) return null; - result= result * 10 + digit; + result = result * 10 + digit; } return negative ? -result : result; } @@ -265,7 +261,7 @@ public class IntegralValue implements IValue { * Converts long to a char array */ private static char[] toCharArray(long value) { - StringBuilder buf= new StringBuilder(); + StringBuilder buf = new StringBuilder(); buf.append(value); return CharArrayUtils.extractChars(buf); } @@ -294,7 +290,7 @@ public class IntegralValue implements IValue { public IValue clone() { return new IntegralValue(Arrays.copyOf(fFixedValue, fFixedValue.length)); } - + @Override public boolean isEquivalentTo(IValue other) { if (!(other instanceof IntegralValue)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java index fd6e122cbfb..15e26962dd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java @@ -29,14 +29,14 @@ public abstract class NodeFactory implements INodeFactory { @Override public final void setEndOffset(IASTNode node, int endOffset) { - ASTNode a= (ASTNode) node; + ASTNode a = (ASTNode) node; a.setLength(endOffset - a.getOffset()); } @Override public final void setEndOffset(IASTNode node, IASTNode endNode) { - ASTNode a= (ASTNode) node; - ASTNode e= (ASTNode) endNode; + ASTNode a = (ASTNode) node; + ASTNode e = (ASTNode) endNode; a.setLength(e.getOffset() + e.getLength() - a.getOffset()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java index b369b403abb..93cfc620fd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ParserLogServiceWrapper.java @@ -20,7 +20,7 @@ public class ParserLogServiceWrapper extends AbstractParserLogService { private IParserLogService fDelegate; public ParserLogServiceWrapper(IParserLogService log) { - fDelegate= log; + fDelegate = log; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index ebe0886acac..00ccb61ae42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -46,72 +46,72 @@ import com.ibm.icu.text.MessageFormat; * Implementation of problem bindings */ public class ProblemBinding extends PlatformObject implements IProblemBinding, IASTInternalScope { - public static ProblemBinding NOT_INITIALIZED= new ProblemBinding(null, 0); + public static ProblemBinding NOT_INITIALIZED = new ProblemBinding(null, 0); - protected final int id; - protected char[] arg; - protected IASTNode node; + protected final int id; + protected char[] arg; + protected IASTNode node; private IBinding[] candidateBindings; - public ProblemBinding(IASTName name, int id) { - this(name, id, null, null); - } - - public ProblemBinding(IASTName name, int id, IBinding[] candidateBindings) { - this(name, id, null, candidateBindings); - } - - /** - * @param name the name that could not be resolved, may be {@code null} - * @param point the point in code where the problem was encountered - * @param id the ID of the problem, see {@link IProblemBinding} - */ - public ProblemBinding(IASTName name, IASTNode point, int id) { - this(name, point, id, null); - } - - /** - * @param name the name that could not be resolved, may be {@code null} - * @param point the point in code where the problem was encountered - * @param id the ID of the problem, see {@link IProblemBinding} - * @param candidateBindings candidate bindings that were rejected due to ambiguity or for other - * reasons, may be {@code null} - */ - public ProblemBinding(IASTName name, IASTNode point, int id, IBinding[] candidateBindings) { - this.id = id; - if (name != null && name.getTranslationUnit() != null) { - this.node = name; - } else { - this.node = point; - if (name != null) { - this.arg = name.getSimpleID(); - } else if (candidateBindings != null && candidateBindings.length != 0) { - this.arg = candidateBindings[0].getNameCharArray(); - } - } + public ProblemBinding(IASTName name, int id) { + this(name, id, null, null); + } + + public ProblemBinding(IASTName name, int id, IBinding[] candidateBindings) { + this(name, id, null, candidateBindings); + } + + /** + * @param name the name that could not be resolved, may be {@code null} + * @param point the point in code where the problem was encountered + * @param id the ID of the problem, see {@link IProblemBinding} + */ + public ProblemBinding(IASTName name, IASTNode point, int id) { + this(name, point, id, null); + } + + /** + * @param name the name that could not be resolved, may be {@code null} + * @param point the point in code where the problem was encountered + * @param id the ID of the problem, see {@link IProblemBinding} + * @param candidateBindings candidate bindings that were rejected due to ambiguity or for other + * reasons, may be {@code null} + */ + public ProblemBinding(IASTName name, IASTNode point, int id, IBinding[] candidateBindings) { + this.id = id; + if (name != null && name.getTranslationUnit() != null) { + this.node = name; + } else { + this.node = point; + if (name != null) { + this.arg = name.getSimpleID(); + } else if (candidateBindings != null && candidateBindings.length != 0) { + this.arg = candidateBindings[0].getNameCharArray(); + } + } this.candidateBindings = candidateBindings; - } + } - public ProblemBinding(IASTNode node, int id, char[] arg) { - this(node, id, arg, null); - } + public ProblemBinding(IASTNode node, int id, char[] arg) { + this(node, id, arg, null); + } - public ProblemBinding(IASTNode node, int id, char[] arg, IBinding[] candidateBindings) { - this.id = id; - this.arg = arg; - this.node = node; + public ProblemBinding(IASTNode node, int id, char[] arg, IBinding[] candidateBindings) { + this.id = id; + this.arg = arg; + this.node = node; this.candidateBindings = candidateBindings; - } + } - @Override + @Override public EScopeKind getKind() { return EScopeKind.eLocal; } - @Override + @Override public IASTNode getASTNode() { - return node; - } + return node; + } @Override public IBinding[] getCandidateBindings() { @@ -119,99 +119,99 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I } public void setCandidateBindings(IBinding[] foundBindings) { - candidateBindings= foundBindings; + candidateBindings = foundBindings; } - @Override + @Override public int getID() { - return id; - } + return id; + } - @Override + @Override public String getMessage() { - String msg = ParserMessages.getProblemPattern(this); - if (msg == null) - return ""; //$NON-NLS-1$ - - if (arg == null) { - if (node instanceof IASTName) { - arg= ((IASTName) node).toCharArray(); - } else if (candidateBindings != null && candidateBindings.length != 0) { - arg = candidateBindings[0].getNameCharArray(); - } - } - - if (arg != null) { - msg = MessageFormat.format(msg, new Object[] { new String(arg) }); - } + String msg = ParserMessages.getProblemPattern(this); + if (msg == null) + return ""; //$NON-NLS-1$ + + if (arg == null) { + if (node instanceof IASTName) { + arg = ((IASTName) node).toCharArray(); + } else if (candidateBindings != null && candidateBindings.length != 0) { + arg = candidateBindings[0].getNameCharArray(); + } + } + + if (arg != null) { + msg = MessageFormat.format(msg, new Object[] { new String(arg) }); + } return msg; - } + } - @Override + @Override public String getName() { - return node instanceof IASTName ? new String(((IASTName) node).getSimpleID()) : CPPSemantics.EMPTY_NAME; - } + return node instanceof IASTName ? new String(((IASTName) node).getSimpleID()) : CPPSemantics.EMPTY_NAME; + } - @Override + @Override public char[] getNameCharArray() { - return node instanceof IASTName ? ((IASTName) node).getSimpleID() : CharArrayUtils.EMPTY; - } + return node instanceof IASTName ? ((IASTName) node).getSimpleID() : CharArrayUtils.EMPTY; + } - @Override + @Override public IScope getScope() throws DOMException { - throw new DOMException(this); - } + throw new DOMException(this); + } - @Override + @Override public IASTNode getPhysicalNode() { - return getASTNode(); - } + return getASTNode(); + } - @Override + @Override public Object clone() { - // Don't clone problems. - return this; - } + // Don't clone problems. + return this; + } - @Override + @Override public IScope getParent() throws DOMException { - throw new DOMException(this); - } + throw new DOMException(this); + } - @Override + @Override public IBinding[] find(String name, IASTTranslationUnit tu) { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } - @Override + @Override public IBinding[] find(String name) { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } @Override public IName getScopeName() { return null; } - @Override + @Override public void addName(IASTName name, boolean adlOnly) { - } + } - @Override + @Override public IBinding getBinding(IASTName name, boolean resolve) { - return null; - } + return null; + } @Override public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) { - return IBinding.EMPTY_BINDING_ARRAY; + return IBinding.EMPTY_BINDING_ARRAY; } - @Override + @Override public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) { - return null; - } + return null; + } @Deprecated @Override @@ -219,15 +219,15 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); } - @Override + @Override public IBinding[] getBindings(ScopeLookupData lookup) { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } - @Override + @Override public boolean isSameType(IType type) { - return type == this; - } + return type == this; + } @Override public String getFileName() { @@ -264,7 +264,7 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I @Override public IBinding getOwner() { if (node instanceof IASTName) { - IASTTranslationUnit tu= node.getTranslationUnit(); + IASTTranslationUnit tu = node.getTranslationUnit(); if (tu instanceof ICPPASTTranslationUnit) { return CPPVisitor.findNameOwner((IASTName) node, true); } @@ -274,8 +274,8 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I public void setASTNode(IASTName name) { if (name != null) { - this.node= name; - this.arg= null; + this.node = name; + this.arg = null; } } @@ -288,76 +288,76 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I } // Dummy methods for derived classes. - public IType getType() { - return new ProblemType(getID()); - } + public IType getType() { + return new ProblemType(getID()); + } - public boolean isStatic() { - return false; - } + public boolean isStatic() { + return false; + } - public String[] getQualifiedName() throws DOMException { - throw new DOMException(this); - } + public String[] getQualifiedName() throws DOMException { + throw new DOMException(this); + } - public char[][] getQualifiedNameCharArray() throws DOMException { - throw new DOMException(this); - } + public char[][] getQualifiedNameCharArray() throws DOMException { + throw new DOMException(this); + } - public boolean isGloballyQualified() throws DOMException { - throw new DOMException(this); - } + public boolean isGloballyQualified() throws DOMException { + throw new DOMException(this); + } - public boolean isMutable() { - return false; - } + public boolean isMutable() { + return false; + } - public boolean isConstexpr() { - return false; - } + public boolean isConstexpr() { + return false; + } - public boolean isExtern() { - return false; - } + public boolean isExtern() { + return false; + } - public boolean isExternC() { - return false; - } + public boolean isExternC() { + return false; + } - public boolean isAuto() { - return false; - } + public boolean isAuto() { + return false; + } - public boolean isRegister() { - return false; - } + public boolean isRegister() { + return false; + } - public IValue getInitialValue() { + public IValue getInitialValue() { return null; } - public ICPPEvaluation getInitializerEvaluation() { - return EvalFixed.INCOMPLETE; + public ICPPEvaluation getInitializerEvaluation() { + return EvalFixed.INCOMPLETE; } - public boolean isAnonymous() { + public boolean isAnonymous() { return false; } - public boolean isDeleted() { + public boolean isDeleted() { return false; } - public boolean isInline() { - return false; - } + public boolean isInline() { + return false; + } - public boolean takesVarArgs() { - return false; - } + public boolean takesVarArgs() { + return false; + } - public IType[] getExceptionSpecification() { - return null; + public IType[] getExceptionSpecification() { + return null; } public boolean hasParameterPack() { @@ -377,11 +377,11 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I } public boolean isExplicit() { - return false; - } + return false; + } public boolean hasDefaultValue() { - return false; + return false; } public IValue getDefaultValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java index e89f284e2ba..e554b3a5597 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java @@ -49,7 +49,7 @@ public class ProblemFunctionType extends ProblemType implements ICPPFunctionType @Override public IType[] getParameterTypes() { - return new IType[] {new ProblemType(getID())}; + return new IType[] { new ProblemType(getID()) }; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java index bf277a1102b..e2a026f862a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java @@ -37,7 +37,7 @@ public class ProblemType implements IProblemType, ISerializableType { private final int fID; public ProblemType(int id) { - fID= id; + fID = id; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index b51ee14e84b..e9bc40364e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -93,8 +93,8 @@ public class SizeofCalculator { */ public static SizeAndAlignment getSizeAndAlignment(IType type) { IASTNode point = CPPSemantics.getCurrentLookupPoint(); - SizeofCalculator calc = point == null ? - getDefault() : ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); + SizeofCalculator calc = point == null ? getDefault() + : ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); return calc.sizeAndAlignment(type); } @@ -147,11 +147,11 @@ public class SizeofCalculator { sizeof_complex_double = getSizeOfPair(sizeof_double); sizeof_long_double = getSize(sizeofMacros, "__SIZEOF_LONG_DOUBLE__", maxAlignment); //$NON-NLS-1$ sizeof_complex_long_double = getSizeOfPair(sizeof_long_double); - sizeof_float128 = size_16; // GCC does not define __SIZEOF_FLOAT128__ + sizeof_float128 = size_16; // GCC does not define __SIZEOF_FLOAT128__ sizeof_complex_float128 = getSizeOfPair(sizeof_float128); - sizeof_decimal32 = size_4; // GCC does not define __SIZEOF_DECIMAL32__ - sizeof_decimal64 = size_8; // GCC does not define __SIZEOF_DECIMAL64__ - sizeof_decimal128 = size_16; // GCC does not define __SIZEOF_DECIMAL128__ + sizeof_decimal32 = size_4; // GCC does not define __SIZEOF_DECIMAL32__ + sizeof_decimal64 = size_8; // GCC does not define __SIZEOF_DECIMAL64__ + sizeof_decimal128 = size_16; // GCC does not define __SIZEOF_DECIMAL128__ } private SizeofCalculator() { @@ -232,16 +232,15 @@ public class SizeofCalculator { case eChar: return SIZE_1; case eInt: - return type.isShort() ? sizeof_short : type.isLong() ? sizeof_long : - type.isLongLong() ? sizeof_long_long : sizeof_int; + return type.isShort() ? sizeof_short + : type.isLong() ? sizeof_long : type.isLongLong() ? sizeof_long_long : sizeof_int; case eInt128: return sizeof_int128; case eFloat: return type.isComplex() ? sizeof_complex_float : sizeof_float; case eDouble: - return type.isComplex() ? - (type.isLong() ? sizeof_complex_long_double : sizeof_complex_double) : - (type.isLong() ? sizeof_long_double : sizeof_double); + return type.isComplex() ? (type.isLong() ? sizeof_complex_long_double : sizeof_complex_double) + : (type.isLong() ? sizeof_long_double : sizeof_double); case eFloat128: return type.isComplex() ? sizeof_complex_float128 : sizeof_float128; case eDecimal32: @@ -301,7 +300,7 @@ public class SizeofCalculator { ICPPClassType classType = (ICPPClassType) type; for (ICPPBase base : classType.getBases()) { if (base.isVirtual()) - return null; // Don't know how to calculate size when there are virtual bases. + return null; // Don't know how to calculate size when there are virtual bases. IBinding baseClass = base.getBaseClass(); if (!(baseClass instanceof IType)) return null; @@ -355,14 +354,13 @@ public class SizeofCalculator { if (maxAlignment < info.alignment) maxAlignment = info.alignment; } - if (size == 0) // a structure cannot have size 0 + if (size == 0) // a structure cannot have size 0 size = 1; size += maxAlignment - (size - 1) % maxAlignment - 1; return new SizeAndAlignment(size, maxAlignment); } - private static SizeAndAlignment getSize(Map<String, String> macros, String name, - int maxAlignment) { + private static SizeAndAlignment getSize(Map<String, String> macros, String name, int maxAlignment) { String value = macros.get(name); if (value == null) return null; @@ -375,7 +373,7 @@ public class SizeofCalculator { } private SizeAndAlignment getSizeOfPair(SizeAndAlignment sizeAndAlignment) { - return sizeAndAlignment == null ? - null : new SizeAndAlignment(sizeAndAlignment.size * 2, sizeAndAlignment.alignment); + return sizeAndAlignment == null ? null + : new SizeAndAlignment(sizeAndAlignment.size * 2, sizeAndAlignment.alignment); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java index 940e9dca37b..9d104b03465 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ValueFactory.java @@ -87,14 +87,14 @@ public class ValueFactory { public static IValue create(IASTExpression expr) { try { CPPSemantics.pushLookupPoint(expr); - IValue val= evaluate(expr); + IValue val = evaluate(expr); if (val != null) { return val; } - + if (expr instanceof ICPPASTInitializerClause) { ICPPEvaluation evaluation = ((ICPPASTInitializerClause) expr).getEvaluation(); - return evaluation.getValue(); + return evaluation.getValue(); } return IntegralValue.UNKNOWN; } finally { @@ -245,12 +245,12 @@ public class ValueFactory { case IASTBinaryExpression.op_notequals: value = v1 != v2 ? 1l : 0l; break; - case IASTBinaryExpression.op_max: - value = Math.max(v1, v2); - break; - case IASTBinaryExpression.op_min: - value = Math.min(v1, v2); - break; + case IASTBinaryExpression.op_max: + value = Math.max(v1, v2); + break; + case IASTBinaryExpression.op_min: + value = Math.min(v1, v2); + break; } if (value != null) { @@ -267,16 +267,15 @@ public class ValueFactory { return val; } - public static IValue evaluateBinaryTypeIdExpression(IASTBinaryTypeIdExpression.Operator operator, - IType type1, IType type2) { + public static IValue evaluateBinaryTypeIdExpression(IASTBinaryTypeIdExpression.Operator operator, IType type1, + IType type2) { IValue val = applyBinaryTypeIdOperator(operator, type1, type2); if (isInvalidValue(val)) return IntegralValue.UNKNOWN; return val; } - - public static IValue evaluateNaryTypeIdExpression(Operator operator, IType[] operands, - IBinding pointOfDefinition) { + + public static IValue evaluateNaryTypeIdExpression(Operator operator, IType[] operands, IBinding pointOfDefinition) { IValue val = applyNaryTypeIdOperator(operator, operands, pointOfDefinition); if (isInvalidValue(val)) return IntegralValue.UNKNOWN; @@ -289,13 +288,11 @@ public class ValueFactory { private static IValue evaluate(IASTExpression exp) { // Some C++ expression types can involve evaluating functions. // For these, the value will be computed based on the evaluation. - if (exp instanceof ICPPASTFunctionCallExpression || - exp instanceof ICPPASTSimpleTypeConstructorExpression || - exp instanceof ICPPASTUnaryExpression || - exp instanceof ICPPASTBinaryExpression) { + if (exp instanceof ICPPASTFunctionCallExpression || exp instanceof ICPPASTSimpleTypeConstructorExpression + || exp instanceof ICPPASTUnaryExpression || exp instanceof ICPPASTBinaryExpression) { return null; } - + if (exp == null) return IntegralValue.UNKNOWN; @@ -312,12 +309,12 @@ public class ValueFactory { return evaluateUnaryExpression((IASTUnaryExpression) exp); } if (exp instanceof IASTConditionalExpression) { - IASTConditionalExpression cexpr= (IASTConditionalExpression) exp; - IValue v= evaluate(cexpr.getLogicalConditionExpression()); + IASTConditionalExpression cexpr = (IASTConditionalExpression) exp; + IValue v = evaluate(cexpr.getLogicalConditionExpression()); if (isInvalidValue(v)) return v; if (isDeferredValue(v)) - return null; // The value will be computed using the evaluation. + return null; // The value will be computed using the evaluation. Number numericValue = v.numberValue(); if (numericValue == null) return IntegralValue.UNKNOWN; @@ -329,11 +326,11 @@ public class ValueFactory { return evaluate(pe); } if (exp instanceof IASTIdExpression) { - IBinding b= ((IASTIdExpression) exp).getName().resolvePreBinding(); + IBinding b = ((IASTIdExpression) exp).getName().resolvePreBinding(); return evaluateBinding(b); } if (exp instanceof IASTLiteralExpression) { - IASTLiteralExpression litEx= (IASTLiteralExpression) exp; + IASTLiteralExpression litEx = (IASTLiteralExpression) exp; switch (litEx.getKind()) { case IASTLiteralExpression.lk_false: case IASTLiteralExpression.lk_nullptr: @@ -348,7 +345,7 @@ public class ValueFactory { } case IASTLiteralExpression.lk_char_constant: try { - final char[] image= litEx.getValue(); + final char[] image = litEx.getValue(); if (image.length > 1 && image[0] == 'L') return IntegralValue.create(ExpressionEvaluator.getChar(image, 2)); return IntegralValue.create(ExpressionEvaluator.getChar(image, 1)); @@ -373,8 +370,8 @@ public class ValueFactory { if (exp instanceof IASTBinaryTypeIdExpression) { IASTBinaryTypeIdExpression typeIdExp = (IASTBinaryTypeIdExpression) exp; ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit(); - IType t1= ast.createType(typeIdExp.getOperand1()); - IType t2= ast.createType(typeIdExp.getOperand2()); + IType t1 = ast.createType(typeIdExp.getOperand1()); + IType t2 = ast.createType(typeIdExp.getOperand2()); if (CPPTemplates.isDependentType(t1) || CPPTemplates.isDependentType(t2)) return null; return applyBinaryTypeIdOperator(typeIdExp.getOperator(), t1, t2); @@ -397,11 +394,11 @@ public class ValueFactory { return null; } - IValue value= null; + IValue value = null; if (b instanceof IVariable) { - value= ((IVariable) b).getInitialValue(); + value = ((IVariable) b).getInitialValue(); } else if (b instanceof IEnumerator) { - value= ((IEnumerator) b).getValue(); + value = ((IEnumerator) b).getValue(); } if (isInvalidValue(value)) { return IntegralValue.UNKNOWN; @@ -413,58 +410,60 @@ public class ValueFactory { type = SemanticUtil.getNestedType(type, TDEF | CVTYPE); switch (operator) { - case op_sizeof: - return getSize(type); - case op_alignof: - return getAlignment(type); - case op_typeid: - break; - case op_has_nothrow_copy: - break; // TODO(sprigogin): Implement - case op_has_nothrow_constructor: - break; // TODO(sprigogin): Implement - case op_has_trivial_assign: - break; // TODO(sprigogin): Implement - case op_has_trivial_constructor: - break; // TODO(sprigogin): Implement - case op_has_trivial_copy: - return IntegralValue.create(!(type instanceof ICPPClassType) || - TypeTraits.hasTrivialCopyCtor((ICPPClassType) type) ? 1 : 0); - case op_has_trivial_destructor: - break; // TODO(sprigogin): Implement - case op_has_virtual_destructor: - break; // TODO(sprigogin): Implement - case op_is_abstract: - return IntegralValue.create(type instanceof ICPPClassType && - TypeTraits.isAbstract((ICPPClassType) type) ? 1 : 0); - case op_is_class: - return IntegralValue.create(type instanceof ICompositeType && - ((ICompositeType) type).getKey() != ICompositeType.k_union ? 1 : 0); - case op_is_empty: - return IntegralValue.create(TypeTraits.isEmpty(type) ? 1 : 0); - case op_is_enum: - return IntegralValue.create(type instanceof IEnumeration ? 1 : 0); - case op_is_final: - return IntegralValue.create(type instanceof ICPPClassType && ((ICPPClassType) type).isFinal() ? 1 : 0); - case op_is_literal_type: - break; // TODO(sprigogin): Implement - case op_is_pod: - return IntegralValue.create(TypeTraits.isPOD(type) ? 1 : 0); - case op_is_polymorphic: - return IntegralValue.create(type instanceof ICPPClassType && - TypeTraits.isPolymorphic((ICPPClassType) type) ? 1 : 0); - case op_is_standard_layout: - return IntegralValue.create(TypeTraits.isStandardLayout(type) ? 1 : 0); - case op_is_trivial: - return IntegralValue.create(type instanceof ICPPClassType && - TypeTraits.isTrivial((ICPPClassType) type) ? 1 : 0); - case op_is_trivially_copyable: - return IntegralValue.create(TypeTraits.isTriviallyCopyable(type) ? 1 : 0); - case op_is_union: - return IntegralValue.create(type instanceof ICompositeType && - ((ICompositeType) type).getKey() == ICompositeType.k_union ? 1 : 0); - case op_typeof: - break; + case op_sizeof: + return getSize(type); + case op_alignof: + return getAlignment(type); + case op_typeid: + break; + case op_has_nothrow_copy: + break; // TODO(sprigogin): Implement + case op_has_nothrow_constructor: + break; // TODO(sprigogin): Implement + case op_has_trivial_assign: + break; // TODO(sprigogin): Implement + case op_has_trivial_constructor: + break; // TODO(sprigogin): Implement + case op_has_trivial_copy: + return IntegralValue.create( + !(type instanceof ICPPClassType) || TypeTraits.hasTrivialCopyCtor((ICPPClassType) type) ? 1 : 0); + case op_has_trivial_destructor: + break; // TODO(sprigogin): Implement + case op_has_virtual_destructor: + break; // TODO(sprigogin): Implement + case op_is_abstract: + return IntegralValue + .create(type instanceof ICPPClassType && TypeTraits.isAbstract((ICPPClassType) type) ? 1 : 0); + case op_is_class: + return IntegralValue.create( + type instanceof ICompositeType && ((ICompositeType) type).getKey() != ICompositeType.k_union ? 1 + : 0); + case op_is_empty: + return IntegralValue.create(TypeTraits.isEmpty(type) ? 1 : 0); + case op_is_enum: + return IntegralValue.create(type instanceof IEnumeration ? 1 : 0); + case op_is_final: + return IntegralValue.create(type instanceof ICPPClassType && ((ICPPClassType) type).isFinal() ? 1 : 0); + case op_is_literal_type: + break; // TODO(sprigogin): Implement + case op_is_pod: + return IntegralValue.create(TypeTraits.isPOD(type) ? 1 : 0); + case op_is_polymorphic: + return IntegralValue + .create(type instanceof ICPPClassType && TypeTraits.isPolymorphic((ICPPClassType) type) ? 1 : 0); + case op_is_standard_layout: + return IntegralValue.create(TypeTraits.isStandardLayout(type) ? 1 : 0); + case op_is_trivial: + return IntegralValue + .create(type instanceof ICPPClassType && TypeTraits.isTrivial((ICPPClassType) type) ? 1 : 0); + case op_is_trivially_copyable: + return IntegralValue.create(TypeTraits.isTriviallyCopyable(type) ? 1 : 0); + case op_is_union: + return IntegralValue.create( + type instanceof ICompositeType && ((ICompositeType) type).getKey() == ICompositeType.k_union ? 1 + : 0); + case op_typeof: + break; } return IntegralValue.UNKNOWN; } @@ -472,19 +471,19 @@ public class ValueFactory { private static IValue getAlignment(IType type) { SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(type); if (sizeAndAlignment == null) - return IntegralValue.UNKNOWN; + return IntegralValue.UNKNOWN; return IntegralValue.create(sizeAndAlignment.alignment); } private static IValue getSize(IType type) { SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(type); if (sizeAndAlignment == null) - return IntegralValue.UNKNOWN; + return IntegralValue.UNKNOWN; return IntegralValue.create(sizeAndAlignment.size); } private static IValue evaluateUnaryExpression(IASTUnaryExpression exp) { - final int unaryOp= exp.getOperator(); + final int unaryOp = exp.getOperator(); if (unaryOp == IASTUnaryExpression.op_sizeof) { final IASTExpression operand = exp.getOperand(); @@ -501,16 +500,16 @@ public class ValueFactory { return IntegralValue.UNKNOWN; } - if (unaryOp == IASTUnaryExpression.op_amper || unaryOp == IASTUnaryExpression.op_star || - unaryOp == IASTUnaryExpression.op_sizeofParameterPack) { + if (unaryOp == IASTUnaryExpression.op_amper || unaryOp == IASTUnaryExpression.op_star + || unaryOp == IASTUnaryExpression.op_sizeofParameterPack) { return IntegralValue.UNKNOWN; } - final IValue value= evaluate(exp.getOperand()); + final IValue value = evaluate(exp.getOperand()); if (isInvalidValue(value)) return value; if (isDeferredValue(value)) - return null; // the value will be computed using the evaluation + return null; // the value will be computed using the evaluation return applyUnaryOperator(unaryOp, value); } @@ -570,7 +569,7 @@ public class ValueFactory { } private static IValue evaluateBinaryExpression(IASTBinaryExpression exp) { - final int op= exp.getOperator(); + final int op = exp.getOperator(); // Optimization: if the operator is == or != and the AST nodes // themselves are equal, we know the answer without having to @@ -582,37 +581,36 @@ public class ValueFactory { return IntegralValue.create(false); } - final IValue o1= evaluate(exp.getOperand1()); + final IValue o1 = evaluate(exp.getOperand1()); if (isInvalidValue(o1)) return o1; - final IValue o2= evaluate(exp.getOperand2()); + final IValue o2 = evaluate(exp.getOperand2()); if (isInvalidValue(o2)) return o2; if (isDeferredValue(o1) || isDeferredValue(o2)) - return null; // the value will be computed using the evaluation + return null; // the value will be computed using the evaluation return evaluateBinaryExpression(op, o1, o2); } - private static IValue applyBinaryTypeIdOperator(IASTBinaryTypeIdExpression.Operator operator, - IType type1, IType type2) { + private static IValue applyBinaryTypeIdOperator(IASTBinaryTypeIdExpression.Operator operator, IType type1, + IType type2) { switch (operator) { case __is_base_of: type1 = SemanticUtil.getNestedType(type1, TDEF); type2 = SemanticUtil.getNestedType(type2, TDEF); - if (type1 instanceof ICPPClassType && type2 instanceof ICPPClassType && - (type1.isSameType(type2) || - ClassTypeHelper.isSubclass((ICPPClassType) type2, (ICPPClassType) type1))) { + if (type1 instanceof ICPPClassType && type2 instanceof ICPPClassType && (type1.isSameType(type2) + || ClassTypeHelper.isSubclass((ICPPClassType) type2, (ICPPClassType) type1))) { return IntegralValue.create(1); } return IntegralValue.create(0); case __is_trivially_assignable: - return IntegralValue.UNKNOWN; // TODO: Implement. + return IntegralValue.UNKNOWN; // TODO: Implement. } return IntegralValue.UNKNOWN; } - - private static IValue applyNaryTypeIdOperator(ICPPASTNaryTypeIdExpression.Operator operator, - IType[] operands, IBinding pointOfDefinition) { + + private static IValue applyNaryTypeIdOperator(ICPPASTNaryTypeIdExpression.Operator operator, IType[] operands, + IBinding pointOfDefinition) { switch (operator) { case __is_constructible: case __is_trivially_constructible: @@ -622,8 +620,9 @@ public class ValueFactory { boolean checkTrivial = (operator == Operator.__is_trivially_constructible); IType typeToConstruct = operands[0]; IType[] argumentTypes = Arrays.copyOfRange(operands, 1, operands.length); - return IntegralValue.create(TypeTraits.isConstructible(typeToConstruct, argumentTypes, - pointOfDefinition, checkTrivial) ? 1 : 0); + return IntegralValue.create( + TypeTraits.isConstructible(typeToConstruct, argumentTypes, pointOfDefinition, checkTrivial) ? 1 + : 0); } return IntegralValue.UNKNOWN; } @@ -633,8 +632,8 @@ public class ValueFactory { } private static boolean isDeferredValue(IValue value) { - return value instanceof DependentValue || - (value instanceof IntegralValue && ((IntegralValue) value).numberValue() == null); + return value instanceof DependentValue + || (value instanceof IntegralValue && ((IntegralValue) value).numberValue() == null); } /** @@ -652,7 +651,7 @@ public class ValueFactory { if (val != null) { return val.numberValue(); } - + if (expr instanceof ICPPASTInitializerClause) { ICPPEvaluation eval = ((ICPPASTInitializerClause) expr).getEvaluation(); if (eval.isConstantExpression() && !eval.isValueDependent()) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java index 2df197d396d..d693071b73a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java @@ -90,31 +90,31 @@ public abstract class VariableReadWriteFlags { } protected int rwInEqualsInitializer(IASTEqualsInitializer parent, int indirection) { - IASTNode grand= parent.getParent(); + IASTNode grand = parent.getParent(); if (grand instanceof IASTDeclarator) { - IBinding binding= ((IASTDeclarator) grand).getName().getBinding(); + IBinding binding = ((IASTDeclarator) grand).getName().getBinding(); if (binding instanceof IVariable) { return rwAssignmentToType(((IVariable) binding).getType(), indirection); } } - return READ | WRITE; // fallback + return READ | WRITE; // fallback } protected int rwInInitializerList(IASTInitializerList parent, int indirection) { - IASTNode grand= parent.getParent(); + IASTNode grand = parent.getParent(); if (grand instanceof IASTEqualsInitializer) { - IASTNode grandGrand= grand.getParent(); + IASTNode grandGrand = grand.getParent(); if (grandGrand instanceof IASTDeclarator) { - IBinding binding= ((IASTDeclarator) grandGrand).getName().resolveBinding(); + IBinding binding = ((IASTDeclarator) grandGrand).getName().resolveBinding(); if (binding instanceof IVariable) { - IType type= ((IVariable) binding).getType(); + IType type = ((IVariable) binding).getType(); if (type instanceof IArrayType) { return rwAssignmentToType(type, indirection); } } } } - return READ | WRITE; // fallback + return READ | WRITE; // fallback } protected int rwInExpression(IASTExpression expr, IASTNode node, int indirection) { @@ -166,14 +166,14 @@ public abstract class VariableReadWriteFlags { return 0; } - return READ | WRITE; // fall back + return READ | WRITE; // fall back } protected int rwInFieldReference(IASTNode node, IASTFieldReference expr, int indirection) { if (node.getPropertyInParent() == IASTFieldReference.FIELD_NAME) { if (expr.getPropertyInParent() != IASTFunctionCallExpression.FUNCTION_NAME) return rwAnyNode(expr, indirection); - } else { // IASTFieldReference.FIELD_OWNER + } else { // IASTFieldReference.FIELD_OWNER if (expr.isPointerDereference()) --indirection; if (indirection >= 0) @@ -186,14 +186,14 @@ public abstract class VariableReadWriteFlags { return READ; } - protected int rwArgumentForFunctionCall(final IASTFunctionCallExpression funcCall, - IASTNode argument, int indirection) { + protected int rwArgumentForFunctionCall(final IASTFunctionCallExpression funcCall, IASTNode argument, + int indirection) { final IASTInitializerClause[] args = funcCall.getArguments(); for (int i = 0; i < args.length; i++) { if (args[i] == argument) { final IASTExpression functionNameExpression = funcCall.getFunctionNameExpression(); if (functionNameExpression != null) { - final IType type= functionNameExpression.getExpressionType(); + final IType type = functionNameExpression.getExpressionType(); if (type instanceof IFunctionType) { return rwArgumentForFunctionCall((IFunctionType) type, i, args[i], indirection); } else if (funcCall instanceof IASTImplicitNameOwner) { @@ -202,8 +202,8 @@ public abstract class VariableReadWriteFlags { IASTImplicitName name = implicitNames[0]; IBinding binding = name.resolveBinding(); if (binding instanceof IFunction) { - return rwArgumentForFunctionCall(((IFunction) binding).getType(), i, - args[i], indirection); + return rwArgumentForFunctionCall(((IFunction) binding).getType(), i, args[i], + indirection); } } } @@ -211,7 +211,7 @@ public abstract class VariableReadWriteFlags { break; } } - return READ | WRITE; // Fallback + return READ | WRITE; // Fallback } private IType getArgumentType(IASTInitializerClause argument) { @@ -223,9 +223,9 @@ public abstract class VariableReadWriteFlags { return null; } - protected int rwArgumentForFunctionCall(IFunctionType type, int parameterIdx, - IASTInitializerClause argument, int indirection) { - IType[] ptypes= type.getParameterTypes(); + protected int rwArgumentForFunctionCall(IFunctionType type, int parameterIdx, IASTInitializerClause argument, + int indirection) { + IType[] ptypes = type.getParameterTypes(); IType parameterType = null; if (ptypes != null && ptypes.length > parameterIdx) { parameterType = ptypes[parameterIdx]; @@ -253,15 +253,15 @@ public abstract class VariableReadWriteFlags { return READ; } } else if (stmt instanceof IASTExpressionStatement) { - IASTNode parent= stmt.getParent(); + IASTNode parent = stmt.getParent(); while (parent instanceof IASTCompoundStatement) { - IASTCompoundStatement compound= (IASTCompoundStatement) parent; - IASTStatement[] statements= compound.getStatements(); + IASTCompoundStatement compound = (IASTCompoundStatement) parent; + IASTStatement[] statements = compound.getStatements(); if (statements[statements.length - 1] != stmt) { return 0; } - stmt= compound; - parent= stmt.getParent(); + stmt = compound; + parent = stmt.getParent(); } if (parent instanceof IGNUASTCompoundStatementExpression) { return rwAnyNode(parent, indirection); @@ -377,6 +377,6 @@ public abstract class VariableReadWriteFlags { } return READ; } - return READ; // fallback + return READ; // fallback } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java index 58f91d48510..5de9e725b8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTASMDeclaration.java @@ -23,9 +23,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; */ public class CASTASMDeclaration extends ASTNode implements IASTASMDeclaration { - char [] assembly = null; + char[] assembly = null; - public CASTASMDeclaration() { + public CASTASMDeclaration() { } public CASTASMDeclaration(String assembly) { @@ -46,33 +46,40 @@ public class CASTASMDeclaration extends ASTNode implements IASTASMDeclaration { @Override public String getAssembly() { - if (assembly == null) return ""; //$NON-NLS-1$ - return new String(assembly); - } + if (assembly == null) + return ""; //$NON-NLS-1$ + return new String(assembly); + } - @Override + @Override public void setAssembly(String assembly) { - assertNotFrozen(); - this.assembly = assembly == null ? null : assembly.toCharArray(); - } + assertNotFrozen(); + this.assembly = assembly == null ? null : assembly.toCharArray(); + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java index a9e2af1a463..172ba6ac308 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguityResolver.java @@ -30,13 +30,13 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; public final class CASTAmbiguityResolver extends ASTVisitor { public CASTAmbiguityResolver() { super(false); - includeInactiveNodes= true; - shouldVisitAmbiguousNodes= true; + includeInactiveNodes = true; + shouldVisitAmbiguousNodes = true; } @Override public int visit(ASTAmbiguousNode astAmbiguousNode) { - IASTNode node= astAmbiguousNode.resolveAmbiguity(this); + IASTNode node = astAmbiguousNode.resolveAmbiguity(this); if (node instanceof IASTDeclarator || node instanceof IASTParameterDeclaration || node instanceof IASTDeclaration) { while (node != null) { @@ -47,14 +47,14 @@ public final class CASTAmbiguityResolver extends ASTVisitor { if (node instanceof IASTExpression) { break; } - node= node.getParent(); + node = node.getParent(); } } return PROCESS_SKIP; } private void repopulateScope(IASTNode node) { - IScope scope= CVisitor.getContainingScope(node); + IScope scope = CVisitor.getContainingScope(node); if (scope instanceof CScope) { CScope cscope = (CScope) scope; if (scope instanceof ICCompositeTypeScope) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java index 12675b367db..4381b109c09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousBinaryVsCastExpression.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousBinaryVsCastExpressi public class CASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsCastExpression { - public CASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression binaryExpr, IASTCastExpression castExpr) { - super(binaryExpr, castExpr); + public CASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression binaryExpr, IASTCastExpression castExpr) { + super(binaryExpr, castExpr); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousCastVsFunctionCallExpression.java index e2187ff1d53..9cea1bb6780 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousCastVsFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousCastVsFunctionCallExpression.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousCastVsFunctionCallEx public class CASTAmbiguousCastVsFunctionCallExpression extends ASTAmbiguousCastVsFunctionCallExpression { - public CASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall) { - super(castExpr, funcCall); + public CASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall) { + super(castExpr, funcCall); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java index 8f9e6dceba2..de8ca346698 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java @@ -36,10 +36,10 @@ import org.eclipse.core.runtime.Assert; * @since 5.0.1 */ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmbiguousDeclarator { - private IASTDeclarator[] dtors = new IASTDeclarator[2]; - private int dtorPos= -1; + private IASTDeclarator[] dtors = new IASTDeclarator[2]; + private int dtorPos = -1; - public CASTAmbiguousDeclarator(IASTDeclarator... decls) { + public CASTAmbiguousDeclarator(IASTDeclarator... decls) { for (IASTDeclarator d : decls) { if (d != null) { addDeclarator(d); @@ -50,7 +50,7 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb @Override protected void beforeResolution() { // populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CVisitor.getContainingScope(this); + IScope scope = CVisitor.getContainingScope(this); if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).populateCache(); } @@ -58,24 +58,24 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb @Override public void addDeclarator(IASTDeclarator d) { - assertNotFrozen(); - if (d != null) { - dtors = ArrayUtil.appendAt(IASTDeclarator.class, dtors, ++dtorPos, d); - d.setParent(this); + assertNotFrozen(); + if (d != null) { + dtors = ArrayUtil.appendAt(IASTDeclarator.class, dtors, ++dtorPos, d); + d.setParent(this); d.setPropertyInParent(SUBDECLARATOR); - } - } + } + } - @Override + @Override public IASTDeclarator[] getDeclarators() { - dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos); - return dtors; - } + dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos); + return dtors; + } - @Override + @Override public IASTNode[] getNodes() { - return getDeclarators(); - } + return getDeclarators(); + } @Override public IASTInitializer getInitializer() { @@ -104,7 +104,7 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb @Override public void addAttribute(IASTAttribute attribute) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @@ -126,25 +126,25 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb @Override public void addPointerOperator(IASTPointerOperator operator) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @Override public void setInitializer(IASTInitializer initializer) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @Override public void setName(IASTName name) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @Override public void setNestedDeclarator(IASTDeclarator nested) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java index d28b502a675..3e5d3fed162 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousExpression.java @@ -22,35 +22,34 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; public class CASTAmbiguousExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression { - private IASTExpression [] expressions = new IASTExpression[2]; - private int expressionsPos=-1; + private IASTExpression[] expressions = new IASTExpression[2]; + private int expressionsPos = -1; - - public CASTAmbiguousExpression(IASTExpression... expressions) { + public CASTAmbiguousExpression(IASTExpression... expressions) { for (IASTExpression e : expressions) addExpression(e); } @Override public void addExpression(IASTExpression e) { - assertNotFrozen(); - if (e != null) { - expressions = ArrayUtil.appendAt(IASTExpression.class, expressions, ++expressionsPos, e); - e.setParent(this); + assertNotFrozen(); + if (e != null) { + expressions = ArrayUtil.appendAt(IASTExpression.class, expressions, ++expressionsPos, e); + e.setParent(this); e.setPropertyInParent(SUBEXPRESSION); - } - } + } + } - @Override + @Override public IASTExpression[] getExpressions() { - expressions = ArrayUtil.trimAt(IASTExpression.class, expressions, expressionsPos); - return expressions; - } + expressions = ArrayUtil.trimAt(IASTExpression.class, expressions, expressionsPos); + return expressions; + } - @Override + @Override public IASTNode[] getNodes() { - return getExpressions(); - } + return getExpressions(); + } @Override public IASTExpression copy() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java index 3d3e9f4a354..6af47b0e3fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousParameterDeclaration.java @@ -32,44 +32,43 @@ import org.eclipse.core.runtime.Assert; */ public class CASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implements IASTAmbiguousParameterDeclaration { - private IASTParameterDeclaration[] paramDecls = new IASTParameterDeclaration[2]; - private int declPos=-1; + private IASTParameterDeclaration[] paramDecls = new IASTParameterDeclaration[2]; + private int declPos = -1; - - public CASTAmbiguousParameterDeclaration(IASTParameterDeclaration... decls) { + public CASTAmbiguousParameterDeclaration(IASTParameterDeclaration... decls) { for (IASTParameterDeclaration d : decls) addParameterDeclaration(d); } @Override public void addParameterDeclaration(IASTParameterDeclaration d) { - assertNotFrozen(); - if (d != null) { - paramDecls = ArrayUtil.appendAt(IASTParameterDeclaration.class, paramDecls, ++declPos, d); - d.setParent(this); + assertNotFrozen(); + if (d != null) { + paramDecls = ArrayUtil.appendAt(IASTParameterDeclaration.class, paramDecls, ++declPos, d); + d.setParent(this); d.setPropertyInParent(SUBDECLARATION); - } - } + } + } @Override protected void beforeResolution() { // populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CVisitor.getContainingScope(this); + IScope scope = CVisitor.getContainingScope(this); if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).populateCache(); } } - @Override + @Override public IASTParameterDeclaration[] getParameterDeclarations() { - paramDecls = ArrayUtil.trimAt(IASTParameterDeclaration.class, paramDecls, declPos); - return paramDecls; - } + paramDecls = ArrayUtil.trimAt(IASTParameterDeclaration.class, paramDecls, declPos); + return paramDecls; + } - @Override + @Override public IASTNode[] getNodes() { - return getParameterDeclarations(); - } + return getParameterDeclarations(); + } @Override public IASTDeclSpecifier getDeclSpecifier() { @@ -83,13 +82,13 @@ public class CASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implemen @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @Override public void setDeclarator(IASTDeclarator declarator) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java index 272e5640390..d515003e2cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java @@ -39,29 +39,29 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; * @since 5.0.1 */ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration { - private IASTSimpleDeclaration fSimpleDecl; - private IASTDeclSpecifier fAltDeclSpec; - private IASTDeclarator fAltDtor; - - public CASTAmbiguousSimpleDeclaration(IASTSimpleDeclaration decl, IASTDeclSpecifier declSpec, IASTDeclarator dtor) { - fSimpleDecl= decl; - fAltDeclSpec= declSpec; - fAltDtor= dtor; + private IASTSimpleDeclaration fSimpleDecl; + private IASTDeclSpecifier fAltDeclSpec; + private IASTDeclarator fAltDtor; + + public CASTAmbiguousSimpleDeclaration(IASTSimpleDeclaration decl, IASTDeclSpecifier declSpec, IASTDeclarator dtor) { + fSimpleDecl = decl; + fAltDeclSpec = declSpec; + fAltDtor = dtor; } @Override protected void beforeResolution() { // Populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CVisitor.getContainingScope(this); + IScope scope = CVisitor.getContainingScope(this); if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).populateCache(); } } - @Override + @Override public IASTNode[] getNodes() { - return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor}; - } + return new IASTNode[] { fSimpleDecl, fAltDeclSpec, fAltDtor }; + } @Override public IASTSimpleDeclaration copy() { @@ -116,31 +116,30 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements @Override protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) { - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); - IASTNode nodeToReplace= this; + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace = this; // Handle nested ambiguities first. owner.replace(nodeToReplace, fSimpleDecl); - IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier(); + IASTDeclSpecifier declSpec = fSimpleDecl.getDeclSpecifier(); declSpec.accept(resolver); - // Find nested names. - final NameCollector nameCollector= new NameCollector(); + final NameCollector nameCollector = new NameCollector(); declSpec.accept(nameCollector); - final IASTName[] names= nameCollector.getNames(); + final IASTName[] names = nameCollector.getNames(); // Resolve names. - boolean hasIssue= false; + boolean hasIssue = false; for (IASTName name : names) { try { IBinding b = name.resolveBinding(); if (b instanceof IProblemBinding) { - hasIssue= true; + hasIssue = true; break; } } catch (Exception t) { - hasIssue= true; + hasIssue = true; break; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java index 97a1c5e98fd..48743f060f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java @@ -31,12 +31,12 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalScope; public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement { - private IASTStatement[] stmts = new IASTStatement[2]; - private int stmtsPos= -1; + private IASTStatement[] stmts = new IASTStatement[2]; + private int stmtsPos = -1; private IScope fScope; private IASTDeclaration fDeclaration; - public CASTAmbiguousStatement(IASTStatement... statements) { + public CASTAmbiguousStatement(IASTStatement... statements) { for (IASTStatement s : statements) addStatement(s); } @@ -45,7 +45,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi protected void beforeResolution() { // Populate containing scope, so that it will not be affected by the alternative // branches. - fScope= CVisitor.getContainingScope(this); + fScope = CVisitor.getContainingScope(this); if (fScope instanceof ICPPASTInternalScope) { ((ICPPASTInternalScope) fScope).populateCache(); } @@ -71,35 +71,35 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi @Override protected void afterResolution(ASTVisitor resolver, IASTNode best) { beforeAlternative(best); - fDeclaration= null; - fScope= null; + fDeclaration = null; + fScope = null; } @Override public void addStatement(IASTStatement s) { - assertNotFrozen(); - if (s != null) { - stmts = ArrayUtil.appendAt(IASTStatement.class, stmts, ++stmtsPos, s); - s.setParent(this); + assertNotFrozen(); + if (s != null) { + stmts = ArrayUtil.appendAt(IASTStatement.class, stmts, ++stmtsPos, s); + s.setParent(this); s.setPropertyInParent(STATEMENT); - } - } + } + } - @Override + @Override public IASTStatement[] getStatements() { - stmts = ArrayUtil.trimAt(IASTStatement.class, stmts, stmtsPos); - return stmts; - } + stmts = ArrayUtil.trimAt(IASTStatement.class, stmts, stmtsPos); + return stmts; + } @Override public IASTAttribute[] getAttributes() { return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY; - } + } - @Override + @Override public void addAttribute(IASTAttribute attribute) { throw new UnsupportedOperationException(); - } + } @Override public IASTAttributeSpecifier[] getAttributeSpecifiers() { @@ -111,10 +111,10 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi throw new UnsupportedOperationException(); } - @Override + @Override public IASTNode[] getNodes() { - return getStatements(); - } + return getStatements(); + } @Override public IASTStatement copy() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java index f22980fdd42..cabfc2e1bb0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java @@ -26,10 +26,10 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; * @author jcamelon */ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDeclarator { - private IASTArrayModifier[] arrayMods; - private int arrayModsPos = -1; + private IASTArrayModifier[] arrayMods; + private int arrayModsPos = -1; - public CASTArrayDeclarator() { + public CASTArrayDeclarator() { } public CASTArrayDeclarator(IASTName name, IASTInitializer initializer) { @@ -56,24 +56,23 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl @Override public IASTArrayModifier[] getArrayModifiers() { - if (arrayMods == null) - return IASTArrayModifier.EMPTY_ARRAY; - arrayMods = ArrayUtil.trimAt(IASTArrayModifier.class, arrayMods, arrayModsPos); - return arrayMods; - } + if (arrayMods == null) + return IASTArrayModifier.EMPTY_ARRAY; + arrayMods = ArrayUtil.trimAt(IASTArrayModifier.class, arrayMods, arrayModsPos); + return arrayMods; + } - @Override + @Override public void addArrayModifier(IASTArrayModifier arrayModifier) { - assertNotFrozen(); - if (arrayModifier != null) { - arrayModifier.setParent(this); + assertNotFrozen(); + if (arrayModifier != null) { + arrayModifier.setParent(this); arrayModifier.setPropertyInParent(ARRAY_MODIFIER); - arrayMods = ArrayUtil.appendAt(IASTArrayModifier.class, arrayMods, - ++arrayModsPos, arrayModifier); - } - } + arrayMods = ArrayUtil.appendAt(IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier); + } + } - @Override + @Override protected boolean postAccept(ASTVisitor action) { IASTArrayModifier[] mods = getArrayModifiers(); for (int i = 0; i < mods.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java index e1ad5384ad3..0afc94362c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDesignator.java @@ -26,9 +26,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * Implementation of array designator. */ public class CASTArrayDesignator extends ASTNode implements ICASTArrayDesignator, IASTAmbiguityParent { - private IASTExpression expression; + private IASTExpression expression; - public CASTArrayDesignator() { + public CASTArrayDesignator() { } public CASTArrayDesignator(IASTExpression exp) { @@ -42,34 +42,36 @@ public class CASTArrayDesignator extends ASTNode implements ICASTArrayDesignator @Override public CASTArrayDesignator copy(CopyStyle style) { - CASTArrayDesignator copy = - new CASTArrayDesignator(expression == null ? null : expression.copy(style)); + CASTArrayDesignator copy = new CASTArrayDesignator(expression == null ? null : expression.copy(style)); return copy(copy, style); } - @Override + @Override public IASTExpression getSubscriptExpression() { - return expression; - } + return expression; + } - @Override + @Override public void setSubscriptExpression(IASTExpression value) { - assertNotFrozen(); - expression = value; - if (value != null) { - value.setParent(this); - value.setPropertyInParent(SUBSCRIPT_EXPRESSION); - } - } + assertNotFrozen(); + expression = value; + if (value != null) { + value.setParent(this); + value.setPropertyInParent(SUBSCRIPT_EXPRESSION); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDesignators) { + if (action.shouldVisitDesignators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (expression != null && !expression.accept(action)) return false; @@ -78,14 +80,14 @@ public class CASTArrayDesignator extends ASTNode implements ICASTArrayDesignator return false; return true; - } + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == expression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expression = (IASTExpression) other; - } - } + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expression = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java index 196a87ce039..b6e1a8323ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java @@ -27,14 +27,14 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; */ public class CASTArrayModifier extends ASTAttributeOwner implements ICASTArrayModifier, IASTAmbiguityParent { - private IASTExpression exp; - private boolean isVolatile; - private boolean isRestrict; - private boolean isStatic; - private boolean isConst; - private boolean isVarSized; - - public CASTArrayModifier() { + private IASTExpression exp; + private boolean isVolatile; + private boolean isRestrict; + private boolean isStatic; + private boolean isConst; + private boolean isVarSized; + + public CASTArrayModifier() { } public CASTArrayModifier(IASTExpression exp) { @@ -57,104 +57,106 @@ public class CASTArrayModifier extends ASTAttributeOwner implements ICASTArrayMo return copy(copy, style); } - @Override + @Override public IASTExpression getConstantExpression() { - return exp; - } + return exp; + } - @Override + @Override public void setConstantExpression(IASTExpression expression) { - assertNotFrozen(); - this.exp = expression; - if (expression != null) { - expression.setParent(this); - expression.setPropertyInParent(CONSTANT_EXPRESSION); - } - } + assertNotFrozen(); + this.exp = expression; + if (expression != null) { + expression.setParent(this); + expression.setPropertyInParent(CONSTANT_EXPRESSION); + } + } @Override public boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public boolean isStatic() { - return isStatic; - } + return isStatic; + } - @Override + @Override public boolean isRestrict() { - return isRestrict; - } + return isRestrict; + } - @Override + @Override public boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public void setConst(boolean value) { - assertNotFrozen(); - this.isConst = value; - } + assertNotFrozen(); + this.isConst = value; + } - @Override + @Override public void setVolatile(boolean value) { - assertNotFrozen(); - this.isVolatile = value; - } + assertNotFrozen(); + this.isVolatile = value; + } - @Override + @Override public void setRestrict(boolean value) { - assertNotFrozen(); - this.isRestrict = value; - } + assertNotFrozen(); + this.isRestrict = value; + } - @Override + @Override public void setStatic(boolean value) { - assertNotFrozen(); - this.isStatic = value; - } + assertNotFrozen(); + this.isStatic = value; + } - @Override + @Override public boolean isVariableSized() { - return isVarSized; - } + return isVarSized; + } - @Override + @Override public void setVariableSized(boolean value) { - assertNotFrozen(); - isVarSized = value; - } + assertNotFrozen(); + isVarSized = value; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitArrayModifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } - if (exp != null && !exp.accept(action)) - return false; - - if (!acceptByAttributeSpecifiers(action)) - return false; - - if (action.shouldVisitArrayModifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT) { - return false; - } - return true; - } - - @Override + if (action.shouldVisitArrayModifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + if (exp != null && !exp.accept(action)) + return false; + + if (!acceptByAttributeSpecifiers(action)) + return false; + + if (action.shouldVisitArrayModifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT) { + return false; + } + return true; + } + + @Override public void replace(IASTNode child, IASTNode other) { - if (child == exp) - { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - exp = (IASTExpression) other; - } - } + if (child == exp) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + exp = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java index a21d19051f6..c5567b454da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayRangeDesignator.java @@ -25,12 +25,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Implementation of array range designator. */ -public class CASTArrayRangeDesignator extends ASTNode - implements IGCCASTArrayRangeDesignator, IASTAmbiguityParent { - private IASTExpression floor; - private IASTExpression ceiling; +public class CASTArrayRangeDesignator extends ASTNode implements IGCCASTArrayRangeDesignator, IASTAmbiguityParent { + private IASTExpression floor; + private IASTExpression ceiling; - public CASTArrayRangeDesignator() { + public CASTArrayRangeDesignator() { } public CASTArrayRangeDesignator(IASTExpression floor, IASTExpression ceiling) { @@ -53,65 +52,68 @@ public class CASTArrayRangeDesignator extends ASTNode @Override public IASTExpression getRangeFloor() { - return this.floor; - } + return this.floor; + } - @Override + @Override public void setRangeFloor(IASTExpression expression) { - assertNotFrozen(); - floor = expression; - if (expression != null) { - expression.setParent(this); - expression.setPropertyInParent(SUBSCRIPT_FLOOR_EXPRESSION); - } - } + assertNotFrozen(); + floor = expression; + if (expression != null) { + expression.setParent(this); + expression.setPropertyInParent(SUBSCRIPT_FLOOR_EXPRESSION); + } + } - @Override + @Override public IASTExpression getRangeCeiling() { - return ceiling; - } + return ceiling; + } - @Override + @Override public void setRangeCeiling(IASTExpression expression) { - assertNotFrozen(); - ceiling = expression; - if (expression != null) { - expression.setParent(this); - expression.setPropertyInParent(SUBSCRIPT_CEILING_EXPRESSION); - } - } + assertNotFrozen(); + ceiling = expression; + if (expression != null) { + expression.setParent(this); + expression.setPropertyInParent(SUBSCRIPT_CEILING_EXPRESSION); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDesignators) { + if (action.shouldVisitDesignators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (floor != null && !floor.accept(action)) return false; if (ceiling != null && !ceiling.accept(action)) return false; - if (action.shouldVisitDesignators && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (action.shouldVisitDesignators && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == floor) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - floor = (IASTExpression) other; - } - if (child == ceiling) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - ceiling = (IASTExpression) other; - } - } + if (child == floor) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + floor = (IASTExpression) other; + } + if (child == ceiling) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + ceiling = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java index dd026b60171..908482295aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java @@ -29,12 +29,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Array subscript expression for C. */ -public class CASTArraySubscriptExpression extends ASTNode implements - IASTArraySubscriptExpression, IASTAmbiguityParent { - private IASTExpression array; - private IASTExpression subscript; +public class CASTArraySubscriptExpression extends ASTNode implements IASTArraySubscriptExpression, IASTAmbiguityParent { + private IASTExpression array; + private IASTExpression subscript; - public CASTArraySubscriptExpression() { + public CASTArraySubscriptExpression() { } public CASTArraySubscriptExpression(IASTExpression array, IASTExpression subscript) { @@ -57,35 +56,35 @@ public class CASTArraySubscriptExpression extends ASTNode implements @Override public IASTExpression getArrayExpression() { - return array; - } + return array; + } - @Override + @Override public void setArrayExpression(IASTExpression expression) { - assertNotFrozen(); - array = expression; - if (expression != null) { - expression.setParent(this); - expression.setPropertyInParent(ARRAY); - } - } - - @Override + assertNotFrozen(); + array = expression; + if (expression != null) { + expression.setParent(this); + expression.setPropertyInParent(ARRAY); + } + } + + @Override public IASTExpression getSubscriptExpression() { - return subscript; - } + return subscript; + } - @Override + @Override public void setSubscriptExpression(IASTExpression expression) { - assertNotFrozen(); - this.subscript = expression; - if (expression != null) { - expression.setParent(this); - expression.setPropertyInParent(SUBSCRIPT); - } - } - - @Override + assertNotFrozen(); + this.subscript = expression; + if (expression != null) { + expression.setParent(this); + expression.setPropertyInParent(SUBSCRIPT); + } + } + + @Override public IASTInitializerClause getArgument() { return subscript; } @@ -101,42 +100,50 @@ public class CASTArraySubscriptExpression extends ASTNode implements @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (array != null && !array.accept(action)) return false; - if (subscript != null && !subscript.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (array != null && !array.accept(action)) + return false; + if (subscript != null && !subscript.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == array) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - array = (IASTExpression) other; - } - if (child == subscript) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - subscript = (IASTExpression) other; - } - } - - @Override + if (child == array) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + array = (IASTExpression) other; + } + if (child == subscript) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + subscript = (IASTExpression) other; + } + } + + @Override public IType getExpressionType() { IType t = getArrayExpression().getExpressionType(); t = CVisitor.unwrapTypedefs(t); @@ -145,7 +152,7 @@ public class CASTArraySubscriptExpression extends ASTNode implements else if (t instanceof IArrayType) return ((IArrayType) t).getType(); return t; - } + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBaseDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBaseDeclSpecifier.java index 38b8e335c7b..3eb2f641e82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBaseDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBaseDeclSpecifier.java @@ -20,125 +20,123 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; - /** * @author jcamelon */ public abstract class CASTBaseDeclSpecifier extends ASTAttributeOwner implements ICASTDeclSpecifier, IASTAmbiguityParent { - protected int storageClass; - protected boolean isConst; - protected boolean isVolatile; - protected boolean isRestrict; - protected boolean isInline; - protected IASTAlignmentSpecifier[] alignmentSpecifiers = - IASTAlignmentSpecifier.EMPTY_ALIGNMENT_SPECIFIER_ARRAY; + protected int storageClass; + protected boolean isConst; + protected boolean isVolatile; + protected boolean isRestrict; + protected boolean isInline; + protected IASTAlignmentSpecifier[] alignmentSpecifiers = IASTAlignmentSpecifier.EMPTY_ALIGNMENT_SPECIFIER_ARRAY; @Override public boolean isRestrict() { - return isRestrict; - } + return isRestrict; + } - @Override + @Override public int getStorageClass() { - return storageClass; - } + return storageClass; + } - @Override + @Override public boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public boolean isInline() { - return isInline; - } + return isInline; + } - @Override - public IASTAlignmentSpecifier[] getAlignmentSpecifiers() { - return alignmentSpecifiers; - } + @Override + public IASTAlignmentSpecifier[] getAlignmentSpecifiers() { + return alignmentSpecifiers; + } - @Override + @Override public void setStorageClass(int storageClass) { - assertNotFrozen(); - this.storageClass = storageClass; - } + assertNotFrozen(); + this.storageClass = storageClass; + } - @Override + @Override public void setConst(boolean value) { - assertNotFrozen(); - this.isConst = value; - } + assertNotFrozen(); + this.isConst = value; + } - @Override + @Override public void setVolatile(boolean value) { - assertNotFrozen(); - this.isVolatile = value; - } + assertNotFrozen(); + this.isVolatile = value; + } - @Override + @Override public void setRestrict(boolean value) { - assertNotFrozen(); - this.isRestrict = value; - } + assertNotFrozen(); + this.isRestrict = value; + } - @Override + @Override public void setInline(boolean value) { - assertNotFrozen(); - this.isInline = value; - } - - @Override - public void setAlignmentSpecifiers(IASTAlignmentSpecifier[] alignmentSpecifiers) { - assertNotFrozen(); - for (IASTAlignmentSpecifier specifier : alignmentSpecifiers) { - specifier.setParent(this); - specifier.setPropertyInParent(ALIGNMENT_SPECIFIER); - } - this.alignmentSpecifiers = alignmentSpecifiers; - } - - protected <T extends CASTBaseDeclSpecifier> T copy(T copy, CopyStyle style) { - copy.storageClass = storageClass; - copy.isConst = isConst; - copy.isVolatile = isVolatile; - copy.isRestrict = isRestrict; - copy.isInline = isInline; - copy.alignmentSpecifiers = new IASTAlignmentSpecifier[alignmentSpecifiers.length]; - for (int i = 0; i < alignmentSpecifiers.length; ++i) { - copy.alignmentSpecifiers[i] = alignmentSpecifiers[i].copy(style); - copy.alignmentSpecifiers[i].setParent(copy); - } + assertNotFrozen(); + this.isInline = value; + } + + @Override + public void setAlignmentSpecifiers(IASTAlignmentSpecifier[] alignmentSpecifiers) { + assertNotFrozen(); + for (IASTAlignmentSpecifier specifier : alignmentSpecifiers) { + specifier.setParent(this); + specifier.setPropertyInParent(ALIGNMENT_SPECIFIER); + } + this.alignmentSpecifiers = alignmentSpecifiers; + } + + protected <T extends CASTBaseDeclSpecifier> T copy(T copy, CopyStyle style) { + copy.storageClass = storageClass; + copy.isConst = isConst; + copy.isVolatile = isVolatile; + copy.isRestrict = isRestrict; + copy.isInline = isInline; + copy.alignmentSpecifiers = new IASTAlignmentSpecifier[alignmentSpecifiers.length]; + for (int i = 0; i < alignmentSpecifiers.length; ++i) { + copy.alignmentSpecifiers[i] = alignmentSpecifiers[i].copy(style); + copy.alignmentSpecifiers[i].setParent(copy); + } return super.copy(copy, style); - } - - protected boolean visitAlignmentSpecifiers(ASTVisitor visitor) { - for (IASTAlignmentSpecifier specifier : alignmentSpecifiers) { - if (!specifier.accept(visitor)) { - return false; - } - } - return true; - } - - @Override - public void replace(IASTNode child, IASTNode other) { - if (child instanceof IASTAlignmentSpecifier && other instanceof IASTAlignmentSpecifier) { - for (int i = 0; i < alignmentSpecifiers.length; ++i) { - if (alignmentSpecifiers[i] == child) { - alignmentSpecifiers[i] = (IASTAlignmentSpecifier) other; - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - return; - } - } - } - } + } + + protected boolean visitAlignmentSpecifiers(ASTVisitor visitor) { + for (IASTAlignmentSpecifier specifier : alignmentSpecifiers) { + if (!specifier.accept(visitor)) { + return false; + } + } + return true; + } + + @Override + public void replace(IASTNode child, IASTNode other) { + if (child instanceof IASTAlignmentSpecifier && other instanceof IASTAlignmentSpecifier) { + for (int i = 0; i < alignmentSpecifiers.length; ++i) { + if (alignmentSpecifiers[i] == child) { + alignmentSpecifiers[i] = (IASTAlignmentSpecifier) other; + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + return; + } + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java index fe436a16961..b93f604f461 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java @@ -34,13 +34,12 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Binary expression for c */ -public class CASTBinaryExpression extends ASTNode - implements IASTBinaryExpression, IASTAmbiguityParent { - private int op; - private IASTExpression operand1; - private IASTExpression operand2; +public class CASTBinaryExpression extends ASTNode implements IASTBinaryExpression, IASTAmbiguityParent { + private int op; + private IASTExpression operand1; + private IASTExpression operand2; - public CASTBinaryExpression() { + public CASTBinaryExpression() { } public CASTBinaryExpression(int op, IASTExpression operand1, IASTExpression operand2) { @@ -65,65 +64,68 @@ public class CASTBinaryExpression extends ASTNode @Override public int getOperator() { - return op; - } + return op; + } - @Override + @Override public IASTExpression getOperand1() { - return operand1; - } + return operand1; + } - @Override + @Override public IASTExpression getOperand2() { - return operand2; - } + return operand2; + } - @Override + @Override public IASTInitializerClause getInitOperand2() { - return operand2; + return operand2; } /** - * @param op An op_X field from {@link IASTBinaryExpression} - */ - @Override + * @param op An op_X field from {@link IASTBinaryExpression} + */ + @Override public void setOperator(int op) { - assertNotFrozen(); - this.op = op; - } + assertNotFrozen(); + this.op = op; + } - @Override + @Override public void setOperand1(IASTExpression expression) { - assertNotFrozen(); - operand1 = expression; - if (expression != null) { + assertNotFrozen(); + operand1 = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND_ONE); } - } + } - @Override + @Override public void setOperand2(IASTExpression expression) { - assertNotFrozen(); - operand2 = expression; - if (expression != null) { + assertNotFrozen(); + operand2 = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND_TWO); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (operand1 instanceof IASTBinaryExpression || operand2 instanceof IASTBinaryExpression) { - return acceptWithoutRecursion(this, action); - } - - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (operand1 instanceof IASTBinaryExpression || operand2 instanceof IASTBinaryExpression) { + return acceptWithoutRecursion(this, action); + } + + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (operand1 != null && !operand1.accept(action)) @@ -135,7 +137,7 @@ public class CASTBinaryExpression extends ASTNode return false; return true; - } + } private static class N { final IASTBinaryExpression fExpression; @@ -148,38 +150,38 @@ public class CASTBinaryExpression extends ASTNode } public static boolean acceptWithoutRecursion(IASTBinaryExpression bexpr, ASTVisitor action) { - N stack= new N(bexpr); + N stack = new N(bexpr); while (stack != null) { - IASTBinaryExpression expr= stack.fExpression; + IASTBinaryExpression expr = stack.fExpression; if (stack.fState == 0) { if (action.shouldVisitExpressions) { switch (action.visit(expr)) { case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_SKIP: - stack= stack.fNext; + stack = stack.fNext; continue; } } - stack.fState= 1; + stack.fState = 1; IASTExpression op1 = expr.getOperand1(); if (op1 instanceof IASTBinaryExpression) { - N n= new N((IASTBinaryExpression) op1); - n.fNext= stack; - stack= n; + N n = new N((IASTBinaryExpression) op1); + n.fNext = stack; + stack = n; continue; } if (op1 != null && !op1.accept(action)) return false; } if (stack.fState == 1) { - stack.fState= 2; + stack.fState = 2; IASTExpression op2 = expr.getOperand2(); if (op2 instanceof IASTBinaryExpression) { - N n= new N((IASTBinaryExpression) op2); - n.fNext= stack; - stack= n; + N n = new N((IASTBinaryExpression) op2); + n.fNext = stack; + stack = n; continue; } if (op2 != null && !op2.accept(action)) @@ -189,38 +191,37 @@ public class CASTBinaryExpression extends ASTNode if (action.shouldVisitExpressions && action.leave(expr) == ASTVisitor.PROCESS_ABORT) return false; - stack= stack.fNext; + stack = stack.fNext; } return true; } - - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == operand1) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - operand1 = (IASTExpression) other; - } - if (child == operand2) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - operand2 = (IASTExpression) other; - } - } - - @Override + if (child == operand1) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + operand1 = (IASTExpression) other; + } + if (child == operand2) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + operand2 = (IASTExpression) other; + } + } + + @Override public IType getExpressionType() { - final int op = getOperator(); - IType originalType1 = getOperand1().getExpressionType(); - IType originalType2 = getOperand2().getExpressionType(); - final IType type1= CVisitor.unwrapTypedefs(originalType1); - final IType type2= CVisitor.unwrapTypedefs(originalType2); - IType type= CArithmeticConversion.convertCOperandTypes(op, type1, type2); - if (type != null) { - return restoreTypedefs(type, originalType1, originalType2); - } + final int op = getOperator(); + IType originalType1 = getOperand1().getExpressionType(); + IType originalType2 = getOperand2().getExpressionType(); + final IType type1 = CVisitor.unwrapTypedefs(originalType1); + final IType type2 = CVisitor.unwrapTypedefs(originalType2); + IType type = CArithmeticConversion.convertCOperandTypes(op, type1, type2); + if (type != null) { + return restoreTypedefs(type, originalType1, originalType2); + } switch (op) { case op_lessEqual: @@ -233,27 +234,27 @@ public class CASTBinaryExpression extends ASTNode case op_notequals: return new CBasicType(Kind.eInt, 0, this); - case IASTBinaryExpression.op_plus: - if (type1 instanceof IArrayType) { - return Conversions.arrayTypeToPointerType((ICArrayType) type1); - } else if (type2 instanceof IPointerType) { - return restoreTypedefs(type2, originalType2); - } else if (type2 instanceof IArrayType) { - return Conversions.arrayTypeToPointerType((ICArrayType) type2); - } - break; + case IASTBinaryExpression.op_plus: + if (type1 instanceof IArrayType) { + return Conversions.arrayTypeToPointerType((ICArrayType) type1); + } else if (type2 instanceof IPointerType) { + return restoreTypedefs(type2, originalType2); + } else if (type2 instanceof IArrayType) { + return Conversions.arrayTypeToPointerType((ICArrayType) type2); + } + break; case IASTBinaryExpression.op_minus: if (type2 instanceof IPointerType || type2 instanceof IArrayType) { if (type1 instanceof IPointerType || type1 instanceof IArrayType) { - return CVisitor.getPtrDiffType(this); + return CVisitor.getPtrDiffType(this); } - return restoreTypedefs(type1, originalType1); + return restoreTypedefs(type1, originalType1); } break; } return restoreTypedefs(type1, originalType1); - } + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java index 05c68e8ee45..6d209064eff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java @@ -23,30 +23,37 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; * @author jcamelon */ public class CASTBreakStatement extends ASTAttributeOwner implements IASTBreakStatement { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } - return true; - } + return true; + } - @Override + @Override public CASTBreakStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java index 924e60be589..74d431d61ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java @@ -26,9 +26,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * @author jcamelon */ public class CASTCaseStatement extends ASTAttributeOwner implements IASTCaseStatement, IASTAmbiguityParent { - private IASTExpression expression; + private IASTExpression expression; - public CASTCaseStatement() { + public CASTCaseStatement() { } public CASTCaseStatement(IASTExpression expression) { @@ -48,46 +48,54 @@ public class CASTCaseStatement extends ASTAttributeOwner implements IASTCaseStat @Override public IASTExpression getExpression() { - return expression; - } + return expression; + } - @Override + @Override public void setExpression(IASTExpression expression) { - assertNotFrozen(); - this.expression = expression; - if (expression != null) { + assertNotFrozen(); + this.expression = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(EXPRESSION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + if (expression != null) + if (!expression.accept(action)) + return false; + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (expression != null) if (!expression.accept(action)) return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == expression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expression = (IASTExpression) other; - } - } + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expression = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java index 600f2dd02b3..7e1785e341e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCastExpression.java @@ -27,12 +27,12 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * Cast expressions for c */ public class CASTCastExpression extends ASTNode implements IASTCastExpression, IASTAmbiguityParent { - private int operator; - private IASTExpression operand; - private IASTTypeId typeId; + private int operator; + private IASTExpression operand; + private IASTTypeId typeId; - public CASTCastExpression() { - this.operator = op_cast; + public CASTCastExpression() { + this.operator = op_cast; } public CASTCastExpression(IASTTypeId typeId, IASTExpression operand) { @@ -57,70 +57,79 @@ public class CASTCastExpression extends ASTNode implements IASTCastExpression, I @Override public int getOperator() { - return operator; - } + return operator; + } - @Override + @Override public void setOperator(int value) { - assertNotFrozen(); - this.operator = value; - } + assertNotFrozen(); + this.operator = value; + } - @Override + @Override public IASTExpression getOperand() { - return operand; - } + return operand; + } - @Override + @Override public void setOperand(IASTExpression expression) { - assertNotFrozen(); - operand = expression; - if (expression != null) { + assertNotFrozen(); + operand = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND); } - } + } @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.typeId = typeId; - if (typeId != null) { + assertNotFrozen(); + this.typeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); } - } + } - @Override + @Override public IASTTypeId getTypeId() { - return typeId; - } + return typeId; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (typeId != null) if (!typeId.accept(action)) return false; - IASTExpression operand = getOperand(); - if (operand != null) if (!operand.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (typeId != null) + if (!typeId.accept(action)) + return false; + IASTExpression operand = getOperand(); + if (operand != null) + if (!operand.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -133,9 +142,9 @@ public class CASTCastExpression extends ASTNode implements IASTCastExpression, I @Override public IType getExpressionType() { - IASTTypeId id= getTypeId(); - return CVisitor.createType(id.getAbstractDeclarator()); - } + IASTTypeId id = getTypeId(); + return CVisitor.createType(id.getAbstractDeclarator()); + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java index a697173c582..855cfb003f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java @@ -27,16 +27,15 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; /** * Implementation for C composite specifiers. */ -public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements - ICASTCompositeTypeSpecifier { - private int fKey; - private IASTName fName; - private IASTDeclaration[] fActiveDeclarations; - private IASTDeclaration[] fAllDeclarations; - private int fDeclarationsPos = -1; - private IScope fScope; - - public CASTCompositeTypeSpecifier() { +public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements ICASTCompositeTypeSpecifier { + private int fKey; + private IASTName fName; + private IASTDeclaration[] fActiveDeclarations; + private IASTDeclaration[] fAllDeclarations; + private int fDeclarationsPos = -1; + private IScope fScope; + + public CASTCompositeTypeSpecifier() { } public CASTCompositeTypeSpecifier(int key, IASTName name) { @@ -64,38 +63,38 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements return super.copy(copy, style); } - @Override + @Override public int getKey() { - return fKey; - } + return fKey; + } - @Override + @Override public void setKey(int key) { - assertNotFrozen(); - this.fKey = key; - } + assertNotFrozen(); + this.fKey = key; + } - @Override + @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName = name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(TYPE_NAME); } - } + } @Override public IASTDeclaration[] getMembers() { - IASTDeclaration[] active= fActiveDeclarations; + IASTDeclaration[] active = fActiveDeclarations; if (active == null) { active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fDeclarationsPos + 1); - fActiveDeclarations= active; + fActiveDeclarations = active; } return active; } @@ -103,45 +102,47 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements @Override public final IASTDeclaration[] getDeclarations(boolean includeInactive) { if (includeInactive) { - fAllDeclarations= ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, - fDeclarationsPos); + fAllDeclarations = ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fDeclarationsPos); return fAllDeclarations; } return getMembers(); } - @Override + @Override public void addMemberDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - if (declaration != null) { - declaration.setParent(this); - declaration.setPropertyInParent(MEMBER_DECLARATION); - fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, - ++fDeclarationsPos, declaration); - fActiveDeclarations= null; - } - } - - @Override + assertNotFrozen(); + if (declaration != null) { + declaration.setParent(this); + declaration.setPropertyInParent(MEMBER_DECLARATION); + fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fDeclarationsPos, + declaration); + fActiveDeclarations = null; + } + } + + @Override public void addDeclaration(IASTDeclaration declaration) { - addMemberDeclaration(declaration); - } + addMemberDeclaration(declaration); + } - @Override + @Override public IScope getScope() { - if (fScope == null) - fScope = new CCompositeTypeScope(this); - return fScope; - } + if (fScope == null) + fScope = new CCompositeTypeScope(this); + return fScope; + } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclSpecifiers) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (!visitAlignmentSpecifiers(action)) { return false; @@ -150,7 +151,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements if (fName != null && !fName.accept(action)) return false; - IASTDeclaration[] decls= getDeclarations(action.includeInactiveNodes); + IASTDeclaration[] decls = getDeclarations(action.includeInactiveNodes); for (int i = 0; i < decls.length; i++) { if (!decls[i].accept(action)) return false; @@ -158,13 +159,16 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements if (action.shouldVisitDeclSpecifiers) { switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -173,7 +177,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements return r_unclear; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { assert child.isActive() == other.isActive(); for (int i = 0; i <= fDeclarationsPos; ++i) { @@ -181,10 +185,10 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); fAllDeclarations[i] = (IASTDeclaration) other; - fActiveDeclarations= null; + fActiveDeclarations = null; return; } } super.replace(child, other); - } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java index b8d3a18b922..8cf7f71ee36 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java @@ -29,10 +29,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * @author jcamelon */ public class CASTCompoundStatement extends ASTAttributeOwner implements IASTCompoundStatement, IASTAmbiguityParent { - private IASTStatement[] statements; - private IScope scope; + private IASTStatement[] statements; + private IScope scope; - @Override + @Override public CASTCompoundStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -45,65 +45,75 @@ public class CASTCompoundStatement extends ASTAttributeOwner implements IASTComp return copy(copy, style); } - @Override + @Override public IASTStatement[] getStatements() { - if (statements == null) return IASTStatement.EMPTY_STATEMENT_ARRAY; - return ArrayUtil.trim(IASTStatement.class, statements); - } + if (statements == null) + return IASTStatement.EMPTY_STATEMENT_ARRAY; + return ArrayUtil.trim(IASTStatement.class, statements); + } - @Override + @Override public void addStatement(IASTStatement statement) { - assertNotFrozen(); - statements = ArrayUtil.append(IASTStatement.class, statements, statement); - if (statement != null) { - statement.setParent(this); - statement.setPropertyInParent(NESTED_STATEMENT); - } - } + assertNotFrozen(); + statements = ArrayUtil.append(IASTStatement.class, statements, statement); + if (statement != null) { + statement.setParent(this); + statement.setPropertyInParent(NESTED_STATEMENT); + } + } - @Override + @Override public IScope getScope() { - if (scope == null) - scope = new CScope(this, EScopeKind.eLocal); - return scope; - } + if (scope == null) + scope = new CScope(this, EScopeKind.eLocal); + return scope; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - IASTStatement[] s = getStatements(); - for (int i = 0; i < s.length; i++) { - if (!s[i].accept(action)) return false; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + IASTStatement[] s = getStatements(); + for (int i = 0; i < s.length; i++) { + if (!s[i].accept(action)) + return false; + } - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (statements == null) return; - for (int i = 0; i < statements.length; ++i) { - if (statements[i] == child) { - other.setParent(statements[i].getParent()); - other.setPropertyInParent(statements[i].getPropertyInParent()); - statements[i] = (IASTStatement) other; - break; - } - } - } + if (statements == null) + return; + for (int i = 0; i < statements.length; ++i) { + if (statements[i] == child) { + other.setParent(statements[i].getParent()); + other.setPropertyInParent(statements[i].getPropertyInParent()); + statements[i] = (IASTStatement) other; + break; + } + } + } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java index b0b253d3286..7a071ffffe6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatementExpression.java @@ -30,9 +30,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; */ public class CASTCompoundStatementExpression extends ASTNode implements IGNUASTCompoundStatementExpression { - private IASTCompoundStatement statement; + private IASTCompoundStatement statement; - public CASTCompoundStatementExpression() { + public CASTCompoundStatementExpression() { } public CASTCompoundStatementExpression(IASTCompoundStatement statement) { @@ -53,41 +53,49 @@ public class CASTCompoundStatementExpression extends ASTNode implements IGNUASTC @Override public IASTCompoundStatement getCompoundStatement() { - return statement; - } + return statement; + } - @Override + @Override public void setCompoundStatement(IASTCompoundStatement statement) { - assertNotFrozen(); - this.statement = statement; - if (statement != null) { + assertNotFrozen(); + this.statement = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(STATEMENT); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (statement != null) if (!statement.accept(action)) return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } - return true; - } + if (statement != null) + if (!statement.accept(action)) + return false; + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public IType getExpressionType() { IASTCompoundStatement compound = getCompoundStatement(); IASTStatement[] statements = compound.getStatements(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java index 226648edc41..9548edf594c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTConditionalExpression.java @@ -33,18 +33,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes; /** * Conditional expression in C */ -public class CASTConditionalExpression extends ASTNode implements - IASTConditionalExpression, IASTAmbiguityParent { +public class CASTConditionalExpression extends ASTNode implements IASTConditionalExpression, IASTAmbiguityParent { - private IASTExpression condition; - private IASTExpression negative; - private IASTExpression positive; + private IASTExpression condition; + private IASTExpression negative; + private IASTExpression positive; - public CASTConditionalExpression() { + public CASTConditionalExpression() { } - public CASTConditionalExpression(IASTExpression condition, - IASTExpression positive, IASTExpression negative) { + public CASTConditionalExpression(IASTExpression condition, IASTExpression positive, IASTExpression negative) { setLogicalConditionExpression(condition); setPositiveResultExpression(positive); setNegativeResultExpression(negative); @@ -66,133 +64,139 @@ public class CASTConditionalExpression extends ASTNode implements @Override public IASTExpression getLogicalConditionExpression() { - return condition; - } + return condition; + } - @Override + @Override public void setLogicalConditionExpression(IASTExpression expression) { - assertNotFrozen(); - condition = expression; - if (expression != null) { + assertNotFrozen(); + condition = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(LOGICAL_CONDITION); } - } + } - @Override + @Override public IASTExpression getPositiveResultExpression() { - return positive; - } + return positive; + } - @Override + @Override public void setPositiveResultExpression(IASTExpression expression) { - assertNotFrozen(); - this.positive = expression; - if (expression != null) { + assertNotFrozen(); + this.positive = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(POSITIVE_RESULT); } - } + } - @Override + @Override public IASTExpression getNegativeResultExpression() { - return negative; - } + return negative; + } - @Override + @Override public void setNegativeResultExpression(IASTExpression expression) { - assertNotFrozen(); - this.negative = expression; - if (expression != null) { + assertNotFrozen(); + this.negative = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(NEGATIVE_RESULT); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + if (condition != null) + if (!condition.accept(action)) + return false; + if (positive != null) + if (!positive.accept(action)) + return false; + if (negative != null) + if (!negative.accept(action)) + return false; + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } + return true; + } - if (condition != null) if (!condition.accept(action)) return false; - if (positive != null) if (!positive.accept(action)) return false; - if (negative != null) if (!negative.accept(action)) return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } - return true; - } - - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == condition) - { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - condition = (IASTExpression) other; - } - if (child == positive) - { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - positive= (IASTExpression) other; - } - if (child == negative) - { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - negative= (IASTExpression) other; - } - } - - @Override + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + condition = (IASTExpression) other; + } + if (child == positive) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + positive = (IASTExpression) other; + } + if (child == negative) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + negative = (IASTExpression) other; + } + } + + @Override public IType getExpressionType() { IASTExpression positiveExpression = getPositiveResultExpression(); if (positiveExpression == null) { - positiveExpression= getLogicalConditionExpression(); + positiveExpression = getLogicalConditionExpression(); } IASTExpression negativeExpression = getNegativeResultExpression(); IType originalPositiveType = positiveExpression.getExpressionType(); IType originalNegativeType = getNegativeResultExpression().getExpressionType(); IType positiveType = CVisitor.unwrapTypedefs(originalPositiveType); IType negativeType = CVisitor.unwrapTypedefs(originalNegativeType); - IType resultType = computeResultType(positiveExpression, negativeExpression, - positiveType, negativeType); + IType resultType = computeResultType(positiveExpression, negativeExpression, positiveType, negativeType); if (resultType == null) { return ProblemType.UNKNOWN_FOR_EXPRESSION; } return ExpressionTypes.restoreTypedefs(resultType, originalPositiveType, originalPositiveType); } - private IType computeResultType(IASTExpression positiveExpression, IASTExpression negativeExpression, - IType positiveType, IType negativeType) { + IType positiveType, IType negativeType) { // Unwrap any top-level cv-qualifiers. positiveType = CVisitor.unwrapCV(positiveType); negativeType = CVisitor.unwrapCV(negativeType); - + // [6.5.15] p5: If both the second and third operands have arithmetic type, the result type // that would be determined by the usual arithmetic conversions, were they applied to those // two operands, is the type of the result. If both operands have void type, the result has // void type. if (positiveType instanceof IBasicType && negativeType instanceof IBasicType) { if (((IBasicType) positiveType).getKind() == IBasicType.Kind.eVoid - && ((IBasicType) negativeType).getKind() == IBasicType.Kind.eVoid) { + && ((IBasicType) negativeType).getKind() == IBasicType.Kind.eVoid) { return CBasicType.VOID; } // It doesn't really matter which operator we use here, so we'll use op_plus. - return CArithmeticConversion.convertCOperandTypes(IASTBinaryExpression.op_plus, - positiveType, negativeType); + return CArithmeticConversion.convertCOperandTypes(IASTBinaryExpression.op_plus, positiveType, negativeType); } // If both the operands have structure or union type, the result has that type. @@ -202,7 +206,7 @@ public class CASTConditionalExpression extends ASTNode implements return positiveType; } } - + // Perform array-to-pointer decay on the operand types. if (positiveType instanceof ICArrayType) { positiveType = Conversions.arrayTypeToPointerType(((ICArrayType) positiveType)); @@ -233,13 +237,12 @@ public class CASTConditionalExpression extends ASTNode implements resultPointee = negativePointee; } else if (positivePointee.isSameType(CBasicType.VOID) || negativePointee.isSameType(CBasicType.VOID)) { resultPointee = CBasicType.VOID; - } else { + } else { return ProblemType.UNKNOWN_FOR_EXPRESSION; } - return new CPointerType( - ExpressionTypes.restoreCV(resultPointee, positivePointeeCV, negativePointeeCV), 0); + return new CPointerType(ExpressionTypes.restoreCV(resultPointee, positivePointeeCV, negativePointeeCV), 0); } - + return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java index 3199802dce8..45cecba7a74 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java @@ -23,29 +23,36 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; * @author jcamelon */ public class CASTContinueStatement extends ASTAttributeOwner implements IASTContinueStatement { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public CASTContinueStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java index 6db9bc58a06..00e4103ab99 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java @@ -29,11 +29,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * A declaration statement. */ -public class CASTDeclarationStatement extends ASTNode - implements IASTDeclarationStatement, IASTAmbiguityParent { - private IASTDeclaration declaration; +public class CASTDeclarationStatement extends ASTNode implements IASTDeclarationStatement, IASTAmbiguityParent { + private IASTDeclaration declaration; - public CASTDeclarationStatement() { + public CASTDeclarationStatement() { } public CASTDeclarationStatement(IASTDeclaration declaration) { @@ -54,40 +53,47 @@ public class CASTDeclarationStatement extends ASTNode @Override public IASTDeclaration getDeclaration() { - return declaration; - } + return declaration; + } - @Override + @Override public void setDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - this.declaration = declaration; - if (declaration != null) { + assertNotFrozen(); + this.declaration = declaration; + if (declaration != null) { declaration.setParent(this); declaration.setPropertyInParent(DECLARATION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declaration != null && !declaration.accept(action)) return false; - - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (declaration != null && !declaration.accept(action)) + return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -107,7 +113,7 @@ public class CASTDeclarationStatement extends ASTNode @Override public void addAttribute(IASTAttribute attribute) { // Declaration statements don't have attributes. - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java index 4f8a22d5aea..f1a33fddb2d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java @@ -37,16 +37,16 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * @author jcamelon */ public class CASTDeclarator extends ASTAttributeOwner implements IASTDeclarator, IASTAmbiguityParent { - private IASTInitializer initializer; - private IASTName name; - private IASTDeclarator nestedDeclarator; - private IASTPointerOperator[] pointerOps; - private int pointerOpsPos= -1; + private IASTInitializer initializer; + private IASTName name; + private IASTDeclarator nestedDeclarator; + private IASTPointerOperator[] pointerOps; + private int pointerOpsPos = -1; - public CASTDeclarator() { + public CASTDeclarator() { } - public CASTDeclarator(IASTName name) { + public CASTDeclarator(IASTName name) { setName(name); } @@ -77,137 +77,142 @@ public class CASTDeclarator extends ASTAttributeOwner implements IASTDeclarator, @Override public IASTPointerOperator[] getPointerOperators() { - if (pointerOps == null) return IASTPointerOperator.EMPTY_ARRAY; - pointerOps = ArrayUtil.trimAt(IASTPointerOperator.class, pointerOps, pointerOpsPos); - return pointerOps; - } + if (pointerOps == null) + return IASTPointerOperator.EMPTY_ARRAY; + pointerOps = ArrayUtil.trimAt(IASTPointerOperator.class, pointerOps, pointerOpsPos); + return pointerOps; + } - @Override + @Override public IASTDeclarator getNestedDeclarator() { - return nestedDeclarator; - } + return nestedDeclarator; + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public IASTInitializer getInitializer() { - return initializer; - } + return initializer; + } - @Override + @Override public void setInitializer(IASTInitializer initializer) { - assertNotFrozen(); - this.initializer = initializer; - if (initializer != null) { + assertNotFrozen(); + this.initializer = initializer; + if (initializer != null) { initializer.setParent(this); initializer.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public void addPointerOperator(IASTPointerOperator operator) { - assertNotFrozen(); - if (operator != null) { - operator.setParent(this); - operator.setPropertyInParent(POINTER_OPERATOR); - pointerOps = ArrayUtil.appendAt(IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator); - } - } - - @Override + assertNotFrozen(); + if (operator != null) { + operator.setParent(this); + operator.setPropertyInParent(POINTER_OPERATOR); + pointerOps = ArrayUtil.appendAt(IASTPointerOperator.class, pointerOps, ++pointerOpsPos, operator); + } + } + + @Override public void setNestedDeclarator(IASTDeclarator nested) { - assertNotFrozen(); - this.nestedDeclarator = nested; - if (nested != null) { + assertNotFrozen(); + this.nestedDeclarator = nested; + if (nested != null) { nested.setParent(this); nested.setPropertyInParent(NESTED_DECLARATOR); } - } + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(DECLARATOR_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarators) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarators) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + for (int i = 0; i <= pointerOpsPos; i++) { + if (!pointerOps[i].accept(action)) + return false; } - for (int i = 0; i <= pointerOpsPos; i++) { - if (!pointerOps[i].accept(action)) - return false; - } - - if (!acceptByAttributeSpecifiers(action)) return false; - - if (getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && nestedDeclarator == null) { - if (getParent() instanceof IASTDeclarator) { - IASTDeclarator outermostDeclarator = (IASTDeclarator) getParent(); - while (outermostDeclarator.getParent() instanceof IASTDeclarator) - outermostDeclarator = (IASTDeclarator) outermostDeclarator.getParent(); - if (outermostDeclarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && - name != null && !name.accept(action)) { - return false; - } - } else if (name != null && !name.accept(action)) { - return false; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + + if (getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && nestedDeclarator == null) { + if (getParent() instanceof IASTDeclarator) { + IASTDeclarator outermostDeclarator = (IASTDeclarator) getParent(); + while (outermostDeclarator.getParent() instanceof IASTDeclarator) + outermostDeclarator = (IASTDeclarator) outermostDeclarator.getParent(); + if (outermostDeclarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && name != null + && !name.accept(action)) { + return false; + } + } else if (name != null && !name.accept(action)) { + return false; + } + } + if (nestedDeclarator != null && !nestedDeclarator.accept(action)) { + return false; } - if (nestedDeclarator != null && !nestedDeclarator.accept(action)) { - return false; - } - if (!postAccept(action)) + if (!postAccept(action)) return false; if (action.shouldVisitDeclarators && action.leave(this) == ASTVisitor.PROCESS_ABORT) { return false; } return true; - } + } - protected boolean postAccept(ASTVisitor action) { - if (initializer != null && !initializer.accept(action)) - return false; + protected boolean postAccept(ASTVisitor action) { + if (initializer != null && !initializer.accept(action)) + return false; return true; - } + } @Override public int getRoleForName(IASTName n) { if (n == this.name) { IASTNode getParent = getParent(); - boolean fnDtor = (this instanceof IASTFunctionDeclarator); + boolean fnDtor = (this instanceof IASTFunctionDeclarator); if (getParent instanceof IASTDeclaration) { - if (getParent instanceof IASTFunctionDefinition) - return r_definition; - if (getParent instanceof IASTSimpleDeclaration) { + if (getParent instanceof IASTFunctionDefinition) + return r_definition; + if (getParent instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration sd = (IASTSimpleDeclaration) getParent; - int storage = sd.getDeclSpecifier().getStorageClass(); + int storage = sd.getDeclSpecifier().getStorageClass(); if (getInitializer() != null || storage == IASTDeclSpecifier.sc_typedef) - return r_definition; + return r_definition; if (storage == IASTDeclSpecifier.sc_extern || storage == IASTDeclSpecifier.sc_static) { - return r_declaration; - } + return r_declaration; + } return fnDtor ? r_declaration : r_definition; - } - } + } + } if (getParent instanceof IASTTypeId) return r_reference; if (getParent instanceof IASTDeclarator) { @@ -215,35 +220,35 @@ public class CASTDeclarator extends ASTAttributeOwner implements IASTDeclarator, while (t instanceof IASTDeclarator) t = t.getParent(); if (t instanceof IASTDeclaration) { - if (getParent instanceof IASTFunctionDefinition) - return r_definition; - if (getParent instanceof IASTSimpleDeclaration) { + if (getParent instanceof IASTFunctionDefinition) + return r_definition; + if (getParent instanceof IASTSimpleDeclaration) { if (getInitializer() != null) - return r_definition; + return r_definition; IASTSimpleDeclaration sd = (IASTSimpleDeclaration) getParent; - int storage = sd.getDeclSpecifier().getStorageClass(); - if (storage == IASTDeclSpecifier.sc_extern || storage == IASTDeclSpecifier.sc_static) { - return r_declaration; - } - } - return fnDtor ? r_declaration : r_definition; - } + int storage = sd.getDeclSpecifier().getStorageClass(); + if (storage == IASTDeclSpecifier.sc_extern || storage == IASTDeclSpecifier.sc_static) { + return r_declaration; + } + } + return fnDtor ? r_declaration : r_definition; + } if (t instanceof IASTTypeId) return r_reference; } - if (getParent instanceof IASTParameterDeclaration) - return (n.toCharArray().length > 0) ? r_definition : r_declaration; + if (getParent instanceof IASTParameterDeclaration) + return (n.toCharArray().length > 0) ? r_definition : r_declaration; } return r_unclear; } @Override public void replace(IASTNode child, IASTNode other) { - if (child == nestedDeclarator) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - nestedDeclarator= (IASTDeclarator) other; - } + if (child == nestedDeclarator) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + nestedDeclarator = (IASTDeclarator) other; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java index 97dbf6ff3d3..497051e6bdf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java @@ -23,29 +23,36 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; * @author jcamelon */ public class CASTDefaultStatement extends ASTAttributeOwner implements IASTDefaultStatement { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public CASTDefaultStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java index 75bb5632641..add964926cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java @@ -31,11 +31,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * Implementation for designated initializers. */ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignatedInitializer, IASTAmbiguityParent { - private IASTInitializerClause rhs; - private ICASTDesignator[] designators; - private int designatorsPos = -1; + private IASTInitializerClause rhs; + private ICASTDesignator[] designators; + private int designatorsPos = -1; - public CASTDesignatedInitializer() { + public CASTDesignatedInitializer() { } public CASTDesignatedInitializer(IASTInitializerClause init) { @@ -49,8 +49,7 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate @Override public CASTDesignatedInitializer copy(CopyStyle style) { - CASTDesignatedInitializer copy = - new CASTDesignatedInitializer(rhs == null ? null : rhs.copy(style)); + CASTDesignatedInitializer copy = new CASTDesignatedInitializer(rhs == null ? null : rhs.copy(style)); for (ICASTDesignator designator : getDesignators()) { copy.addDesignator(designator == null ? null : designator.copy(style)); } @@ -59,32 +58,32 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate @Override public void addDesignator(ICASTDesignator designator) { - assertNotFrozen(); - if (designator != null) { - designator.setParent(this); - designator.setPropertyInParent(DESIGNATOR); - designators = ArrayUtil.appendAt(ICASTDesignator.class, designators, ++designatorsPos, designator); - } - } + assertNotFrozen(); + if (designator != null) { + designator.setParent(this); + designator.setPropertyInParent(DESIGNATOR); + designators = ArrayUtil.appendAt(ICASTDesignator.class, designators, ++designatorsPos, designator); + } + } - @Override + @Override public ICASTDesignator[] getDesignators() { - if (designators == null) - return ICASTDesignatedInitializer.EMPTY_DESIGNATOR_ARRAY; - designators = ArrayUtil.trimAt(ICASTDesignator.class, designators, designatorsPos); - return designators; - } + if (designators == null) + return ICASTDesignatedInitializer.EMPTY_DESIGNATOR_ARRAY; + designators = ArrayUtil.trimAt(ICASTDesignator.class, designators, designatorsPos); + return designators; + } - @Override + @Override public IASTInitializerClause getOperand() { - return rhs; + return rhs; } @Override public void setOperand(IASTInitializerClause operand) { - assertNotFrozen(); - this.rhs = operand; - if (rhs != null) { + assertNotFrozen(); + this.rhs = operand; + if (rhs != null) { rhs.setParent(this); rhs.setPropertyInParent(OPERAND); } @@ -102,53 +101,60 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate init.setPropertyInParent(OPERAND); return init; } - return null; - } + return null; + } - @Override + @Override @Deprecated - public void setOperandInitializer(IASTInitializer rhs) { - if (rhs instanceof IASTEqualsInitializer) { - setOperand(((IASTEqualsInitializer) rhs).getInitializerClause()); - } else if (rhs instanceof IASTInitializerClause) { - setOperand((IASTInitializerClause) rhs); - } else { - setOperand(null); - } - } + public void setOperandInitializer(IASTInitializer rhs) { + if (rhs instanceof IASTEqualsInitializer) { + setOperand(((IASTEqualsInitializer) rhs).getInitializerClause()); + } else if (rhs instanceof IASTInitializerClause) { + setOperand((IASTInitializerClause) rhs); + } else { + setOperand(null); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitInitializers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - ICASTDesignator[] ds = getDesignators(); - for (int i = 0; i < ds.length; i++) { - if (!ds[i].accept(action)) - return false; - } - if (rhs != null && !rhs.accept(action)) return false; + ICASTDesignator[] ds = getDesignators(); + for (int i = 0; i < ds.length; i++) { + if (!ds[i].accept(action)) + return false; + } + if (rhs != null && !rhs.accept(action)) + return false; - if (action.shouldVisitInitializers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == rhs) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - rhs = (IASTInitializerClause) other; - } - } + if (child == rhs) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + rhs = (IASTInitializerClause) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java index 656e27b5710..21bc1d553ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java @@ -27,10 +27,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * @author jcamelon */ public class CASTDoStatement extends ASTAttributeOwner implements IASTDoStatement, IASTAmbiguityParent { - private IASTStatement body; - private IASTExpression condition; + private IASTStatement body; + private IASTExpression condition; - public CASTDoStatement() { + public CASTDoStatement() { } public CASTDoStatement(IASTStatement body, IASTExpression condition) { @@ -53,69 +53,78 @@ public class CASTDoStatement extends ASTAttributeOwner implements IASTDoStatemen @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement body) { - assertNotFrozen(); - this.body = body; - if (body != null) { + assertNotFrozen(); + this.body = body; + if (body != null) { body.setParent(this); body.setPropertyInParent(BODY); } - } + } - @Override + @Override public IASTExpression getCondition() { - return condition; - } + return condition; + } - @Override + @Override public void setCondition(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (body != null && !body.accept(action)) return false; - if (condition != null && !condition.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (body != null && !body.accept(action)) + return false; + if (condition != null && !condition.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (body == child) { - other.setPropertyInParent(body.getPropertyInParent()); - other.setParent(body.getParent()); - body = (IASTStatement) other; - } - if (child == condition) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - condition = (IASTExpression) other; - } - } + if (body == child) { + other.setPropertyInParent(body.getPropertyInParent()); + other.setParent(body.getParent()); + body = (IASTStatement) other; + } + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + condition = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java index 67b06e364c5..ca196b4b4a6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTElaboratedTypeSpecifier.java @@ -31,14 +31,13 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; /** * Node for elaborated type specifiers (examples: struct S; union U; enum E;) */ -public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implements - ICASTElaboratedTypeSpecifier, IASTCompletionContext { +public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier + implements ICASTElaboratedTypeSpecifier, IASTCompletionContext { - private int kind; - private IASTName name; + private int kind; + private IASTName name; - - public CASTElaboratedTypeSpecifier() { + public CASTElaboratedTypeSpecifier() { } public CASTElaboratedTypeSpecifier(int kind, IASTName name) { @@ -60,63 +59,72 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement @Override public int getKind() { - return kind; - } + return kind; + } - @Override + @Override public void setKind(int value) { - assertNotFrozen(); - this.kind = value; - } + assertNotFrozen(); + this.kind = value; + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(TYPE_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!visitAlignmentSpecifiers(action)) { - return false; - } - if (name != null) if (!name.accept(action)) return false; - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (!visitAlignmentSpecifiers(action)) { + return false; } - return true; - } + if (name != null) + if (!name.accept(action)) + return false; + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } @Override public int getRoleForName(IASTName n) { - if (n != name) return r_unclear; + if (n != name) + return r_unclear; IASTNode parent = getParent(); if (!(parent instanceof IASTDeclaration)) return r_reference; if (parent instanceof IASTSimpleDeclaration) { - IASTDeclarator [] dtors = ((IASTSimpleDeclaration) parent).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) parent).getDeclarators(); if (dtors.length == 0) return r_declaration; } @@ -133,30 +141,30 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement @Override public IBinding[] findBindings(IASTName n, boolean isPrefix) { - IBinding[] result= CVisitor.findBindingsForContentAssist(n, isPrefix); - int nextPos= 0; + IBinding[] result = CVisitor.findBindingsForContentAssist(n, isPrefix); + int nextPos = 0; for (int i = 0; i < result.length; i++) { - IBinding b= result[i]; + IBinding b = result[i]; if (b instanceof ICompositeType) { - ICompositeType ct= (ICompositeType) b; + ICompositeType ct = (ICompositeType) b; switch (ct.getKey()) { case ICompositeType.k_struct: if (getKind() != k_struct) - b= null; + b = null; break; case ICompositeType.k_union: if (getKind() != k_union) - b= null; + b = null; break; } } else if (b instanceof IEnumeration) { if (getKind() != k_enum) - b= null; + b = null; } else if (b instanceof ITypedef) { - b= null; + b = null; } if (b != null) { - result[nextPos++]= b; + result[nextPos++] = b; } } if (nextPos != result.length) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java index 188271e92c9..620220772e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java @@ -27,12 +27,12 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalEnumerationSpecifier */ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements IASTInternalEnumerationSpecifier, ICASTEnumerationSpecifier { - private IASTName fName; + private IASTName fName; private Boolean fValuesComputed; - private IASTEnumerator[] fEnumerators = IASTEnumerator.EMPTY_ENUMERATOR_ARRAY; - private int fNumEnumerators; + private IASTEnumerator[] fEnumerators = IASTEnumerator.EMPTY_ENUMERATOR_ARRAY; + private int fNumEnumerators; - public CASTEnumerationSpecifier() { + public CASTEnumerationSpecifier() { } public CASTEnumerationSpecifier(IASTName name) { @@ -63,13 +63,13 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier if (fValuesComputed != null) return false; - fValuesComputed= Boolean.FALSE; + fValuesComputed = Boolean.FALSE; return true; } @Override public void finishValueComputation() { - fValuesComputed= Boolean.TRUE; + fValuesComputed = Boolean.TRUE; } @Override @@ -79,63 +79,69 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier @Override public void addEnumerator(IASTEnumerator enumerator) { - assertNotFrozen(); - if (enumerator != null) { - enumerator.setParent(this); + assertNotFrozen(); + if (enumerator != null) { + enumerator.setParent(this); enumerator.setPropertyInParent(ENUMERATOR); - fEnumerators = ArrayUtil.appendAt(fEnumerators, fNumEnumerators++, enumerator); - } - } + fEnumerators = ArrayUtil.appendAt(fEnumerators, fNumEnumerators++, enumerator); + } + } - @Override + @Override public IASTEnumerator[] getEnumerators() { - fEnumerators = ArrayUtil.trim(fEnumerators, fNumEnumerators); - return fEnumerators; - } + fEnumerators = ArrayUtil.trim(fEnumerators, fNumEnumerators); + return fEnumerators; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName = name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(ENUMERATION_NAME); } - } + } - @Override + @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + if (!visitAlignmentSpecifiers(action)) { + return false; } - if (!visitAlignmentSpecifiers(action)) { - return false; - } - if (fName != null && !fName.accept(action)) - return false; - IASTEnumerator[] etors = getEnumerators(); - for (int i = 0; i < etors.length; i++) { - if (!etors[i].accept(action)) - return false; - } - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (fName != null && !fName.accept(action)) + return false; + IASTEnumerator[] etors = getEnumerators(); + for (int i = 0; i < etors.length; i++) { + if (!etors[i].accept(action)) + return false; } - return true; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } @Override public int getRoleForName(IASTName n) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java index 6d2d6a2aadf..4ea2937609a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java @@ -22,8 +22,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator; */ public class CASTEnumerator extends ASTEnumerator { - public CASTEnumerator() { - super(); + public CASTEnumerator() { + super(); } public CASTEnumerator(IASTName name, IASTExpression value) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java index 62bbe0f3ca2..248028b9652 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTEqualsInitializer; * Initializer with equals sign (copy initialization) */ public class CASTEqualsInitializer extends ASTEqualsInitializer { - public CASTEqualsInitializer() { + public CASTEqualsInitializer() { } public CASTEqualsInitializer(IASTInitializerClause arg) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java index 01c997a80c9..affb2fd1bea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java @@ -29,8 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; /** * Expression list in C */ -public class CASTExpressionList extends ASTNode implements IASTExpressionList, - IASTAmbiguityParent { +public class CASTExpressionList extends ASTNode implements IASTExpressionList, IASTAmbiguityParent { @Override public CASTExpressionList copy() { @@ -45,86 +44,87 @@ public class CASTExpressionList extends ASTNode implements IASTExpressionList, return copy(copy, style); } - @Override + @Override public IASTExpression[] getExpressions() { - if (expressions == null) - return IASTExpression.EMPTY_EXPRESSION_ARRAY; - return ArrayUtil.trim(IASTExpression.class, expressions); - } + if (expressions == null) + return IASTExpression.EMPTY_EXPRESSION_ARRAY; + return ArrayUtil.trim(IASTExpression.class, expressions); + } - @Override + @Override public void addExpression(IASTExpression expression) { - assertNotFrozen(); - expressions = ArrayUtil.append(IASTExpression.class, expressions, expression); - if (expression != null) { - expression.setParent(this); - expression.setPropertyInParent(NESTED_EXPRESSION); + assertNotFrozen(); + expressions = ArrayUtil.append(IASTExpression.class, expressions, expression); + if (expression != null) { + expression.setParent(this); + expression.setPropertyInParent(NESTED_EXPRESSION); } - } + } - private IASTExpression [] expressions = new IASTExpression[2]; + private IASTExpression[] expressions = new IASTExpression[2]; - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } - IASTExpression[] exps = getExpressions(); - for (int i = 0; i < exps.length; i++) - if (!exps[i].accept(action)) - return false; + IASTExpression[] exps = getExpressions(); + for (int i = 0; i < exps.length; i++) + if (!exps[i].accept(action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } - return true; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (expressions == null) return; - for (int i = 0; i < expressions.length; ++i) { - if (child == expressions[i]) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expressions[i] = (IASTExpression) other; - } - } - } + if (expressions == null) + return; + for (int i = 0; i < expressions.length; ++i) { + if (child == expressions[i]) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expressions[i] = (IASTExpression) other; + } + } + } - @Override + @Override public IType getExpressionType() { - for (int i = expressions.length-1; i >= 0; i--) { - IASTExpression expr= expressions[i]; - if (expr != null) - return expr.getExpressionType(); + for (int i = expressions.length - 1; i >= 0; i--) { + IASTExpression expr = expressions[i]; + if (expr != null) + return expr.getExpressionType(); } - return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); - } + return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); + } @Override public boolean isLValue() { - for (int i = expressions.length-1; i >= 0; i--) { - IASTExpression expr= expressions[i]; - if (expr != null) - return expr.isLValue(); + for (int i = expressions.length - 1; i >= 0; i--) { + IASTExpression expr = expressions[i]; + if (expr != null) + return expr.isLValue(); } - return false; + return false; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java index afc97019d3d..1d3fd3d7b2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java @@ -25,11 +25,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CASTExpressionStatement extends ASTAttributeOwner - implements IASTExpressionStatement, IASTAmbiguityParent { - private IASTExpression expression; +public class CASTExpressionStatement extends ASTAttributeOwner implements IASTExpressionStatement, IASTAmbiguityParent { + private IASTExpression expression; - public CASTExpressionStatement() { + public CASTExpressionStatement() { } public CASTExpressionStatement(IASTExpression expression) { @@ -50,48 +49,56 @@ public class CASTExpressionStatement extends ASTAttributeOwner @Override public IASTExpression getExpression() { - return expression; - } + return expression; + } - @Override + @Override public void setExpression(IASTExpression expression) { - assertNotFrozen(); - this.expression = expression; - if (expression != null) { + assertNotFrozen(); + this.expression = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(EXPRESSION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } - if (!acceptByAttributeSpecifiers(action)) return false; - if (expression != null && !expression.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (expression != null && !expression.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == expression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expression = (IASTExpression) other; - } - } + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expression = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java index ee29850a198..0921089d49f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java @@ -25,9 +25,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * @author jcamelon */ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDeclarator { - private IASTExpression bitFieldSize; + private IASTExpression bitFieldSize; - public CASTFieldDeclarator() { + public CASTFieldDeclarator() { } public CASTFieldDeclarator(IASTName name, IASTExpression bitFieldSize) { @@ -49,20 +49,20 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl @Override public IASTExpression getBitFieldSize() { - return bitFieldSize; - } + return bitFieldSize; + } - @Override + @Override public void setBitFieldSize(IASTExpression size) { - assertNotFrozen(); - bitFieldSize = size; - if (size != null) { + assertNotFrozen(); + bitFieldSize = size; + if (size != null) { size.setParent(this); size.setPropertyInParent(FIELD_SIZE); } - } + } - @Override + @Override protected boolean postAccept(ASTVisitor action) { if (bitFieldSize != null && !bitFieldSize.accept(action)) return false; @@ -70,14 +70,14 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl return super.postAccept(action); } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == bitFieldSize) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - bitFieldSize = (IASTExpression) other; - } else { - super.replace(child, other); - } - } + if (child == bitFieldSize) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + bitFieldSize = (IASTExpression) other; + } else { + super.replace(child, other); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java index 90edbaaadda..0906f04f6bb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDesignator.java @@ -26,9 +26,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * Implementation of field designator. */ public class CASTFieldDesignator extends ASTNode implements ICASTFieldDesignator, IASTCompletionContext { - private IASTName name; + private IASTName name; - public CASTFieldDesignator() { + public CASTFieldDesignator() { } public CASTFieldDesignator(IASTName name) { @@ -48,35 +48,38 @@ public class CASTFieldDesignator extends ASTNode implements ICASTFieldDesignator @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(FIELD_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDesignators) { + if (action.shouldVisitDesignators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (name != null && !name.accept(action)) return false; if (action.shouldVisitDesignators && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public IBinding[] findBindings(IASTName n, boolean isPrefix) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java index 41511866f8e..92b52a1fe46 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldReference.java @@ -35,11 +35,11 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; */ public class CASTFieldReference extends ASTNode implements IASTFieldReference, IASTAmbiguityParent, IASTCompletionContext { - private IASTExpression owner; - private IASTName name; - private boolean ptr; + private IASTExpression owner; + private IASTName name; + private boolean ptr; - public CASTFieldReference() { + public CASTFieldReference() { } public CASTFieldReference(IASTName name, IASTExpression owner) { @@ -68,92 +68,100 @@ public class CASTFieldReference extends ASTNode @Override public IASTExpression getFieldOwner() { - return owner; - } + return owner; + } - @Override + @Override public void setFieldOwner(IASTExpression expression) { - assertNotFrozen(); - this.owner = expression; - if (expression != null) { + assertNotFrozen(); + this.owner = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(FIELD_OWNER); } - } + } - @Override + @Override public IASTName getFieldName() { - return name; - } + return name; + } - @Override + @Override public void setFieldName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(FIELD_NAME); } - } + } - @Override + @Override public boolean isPointerDereference() { - return ptr; - } + return ptr; + } - @Override + @Override public void setIsPointerDereference(boolean value) { - assertNotFrozen(); - ptr = value; - } + assertNotFrozen(); + ptr = value; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (owner != null && !owner.accept(action)) return false; - if (name != null && !name.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (owner != null && !owner.accept(action)) + return false; + if (name != null && !name.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (n == this.name) + if (n == this.name) return r_reference; return r_unclear; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == owner) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - owner = (IASTExpression) other; - } - } - - @Override + if (child == owner) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + owner = (IASTExpression) other; + } + } + + @Override public IType getExpressionType() { - IBinding binding = getFieldName().resolveBinding(); + IBinding binding = getFieldName().resolveBinding(); if (binding instanceof IVariable) { return ((IVariable) binding).getType(); } - return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); - } + return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java index 01a513acd19..4fccb307dc4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java @@ -29,21 +29,21 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * @author jcamelon */ public class CASTForStatement extends ASTAttributeOwner implements IASTForStatement, IASTAmbiguityParent { - private IScope scope; - private IASTExpression condition; - private IASTExpression iterationExpression; - private IASTStatement body; - private IASTStatement init; + private IScope scope; + private IASTExpression condition; + private IASTExpression iterationExpression; + private IASTStatement body; + private IASTStatement init; - public CASTForStatement() { + public CASTForStatement() { } - public CASTForStatement(IASTStatement init, IASTExpression condition, - IASTExpression iterationExpression, IASTStatement body) { - setInitializerStatement(init); - setConditionExpression(condition); - setIterationExpression(iterationExpression); - setBody(body); + public CASTForStatement(IASTStatement init, IASTExpression condition, IASTExpression iterationExpression, + IASTStatement body) { + setInitializerStatement(init); + setConditionExpression(condition); + setIterationExpression(iterationExpression); + setBody(body); } @Override @@ -60,125 +60,136 @@ public class CASTForStatement extends ASTAttributeOwner implements IASTForStatem protected <T extends CASTForStatement> T copy(T copy, CopyStyle style) { copy.setInitializerStatement(init == null ? null : init.copy(style)); copy.setConditionExpression(condition == null ? null : condition.copy(style)); - copy.setIterationExpression(iterationExpression == null ? - null : iterationExpression.copy(style)); + copy.setIterationExpression(iterationExpression == null ? null : iterationExpression.copy(style)); copy.setBody(body == null ? null : body.copy(style)); return super.copy(copy, style); } @Override public IASTExpression getConditionExpression() { - return condition; - } + return condition; + } - @Override + @Override public void setConditionExpression(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); } - } + } - @Override + @Override public IASTExpression getIterationExpression() { - return iterationExpression; - } + return iterationExpression; + } - @Override + @Override public void setIterationExpression(IASTExpression iterator) { - assertNotFrozen(); - this.iterationExpression = iterator; - if (iterator != null) { + assertNotFrozen(); + this.iterationExpression = iterator; + if (iterator != null) { iterator.setParent(this); iterator.setPropertyInParent(ITERATION); } - } + } - @Override + @Override public IASTStatement getInitializerStatement() { - return init; - } + return init; + } - @Override + @Override public void setInitializerStatement(IASTStatement statement) { - assertNotFrozen(); - init = statement; - if (statement != null) { + assertNotFrozen(); + init = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(INITIALIZER); } - } - @Override + } + + @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement statement) { - assertNotFrozen(); - body = statement; - if (statement != null) { + assertNotFrozen(); + body = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(BODY); } - } + } - @Override + @Override public IScope getScope() { - if (scope == null) - scope = new CScope(this, EScopeKind.eLocal); - return scope; - } + if (scope == null) + scope = new CScope(this, EScopeKind.eLocal); + return scope; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (init != null && !init.accept(action)) return false; - if (condition != null && !condition.accept(action)) return false; - if (iterationExpression != null && !iterationExpression.accept(action)) return false; - if (body != null && !body.accept(action)) return false; - - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + if (init != null && !init.accept(action)) + return false; + if (condition != null && !condition.accept(action)) + return false; + if (iterationExpression != null && !iterationExpression.accept(action)) + return false; + if (body != null && !body.accept(action)) + return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (body == child) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - body = (IASTStatement) other; - } - if (child == init) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - init = (IASTStatement) other; - } - if (child == iterationExpression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - iterationExpression = (IASTExpression) other; - } - if (child == condition) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - condition = (IASTExpression) other; - } - } + if (body == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + body = (IASTStatement) other; + } + if (child == init) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + init = (IASTStatement) other; + } + if (child == iterationExpression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + iterationExpression = (IASTExpression) other; + } + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + condition = (IASTExpression) other; + } + } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java index f1574972c66..6d97b9a00ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java @@ -31,14 +31,12 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; /** * Function call expression in C. */ -public class CASTFunctionCallExpression extends ASTNode - implements IASTFunctionCallExpression, IASTAmbiguityParent { - private IASTExpression functionName; - private IASTInitializerClause[] fArguments; +public class CASTFunctionCallExpression extends ASTNode implements IASTFunctionCallExpression, IASTAmbiguityParent { + private IASTExpression functionName; + private IASTInitializerClause[] fArguments; - - public CASTFunctionCallExpression() { - setArguments(null); + public CASTFunctionCallExpression() { + setArguments(null); } public CASTFunctionCallExpression(IASTExpression functionName, IASTInitializerClause[] args) { @@ -68,46 +66,49 @@ public class CASTFunctionCallExpression extends ASTNode @Override public void setFunctionNameExpression(IASTExpression expression) { - assertNotFrozen(); - this.functionName = expression; - if (expression != null) { + assertNotFrozen(); + this.functionName = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(FUNCTION_NAME); } - } + } - @Override + @Override public IASTExpression getFunctionNameExpression() { - return functionName; - } + return functionName; + } @Override public IASTInitializerClause[] getArguments() { - return fArguments; - } + return fArguments; + } - @Override + @Override public void setArguments(IASTInitializerClause[] arguments) { - assertNotFrozen(); - if (arguments == null) { - fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY; - } else { - fArguments= arguments; - for (IASTInitializerClause arg : arguments) { + assertNotFrozen(); + if (arguments == null) { + fArguments = IASTExpression.EMPTY_EXPRESSION_ARRAY; + } else { + fArguments = arguments; + for (IASTInitializerClause arg : arguments) { arg.setParent(this); arg.setPropertyInParent(ARGUMENT); } } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (functionName != null && !functionName.accept(action)) @@ -122,9 +123,9 @@ public class CASTFunctionCallExpression extends ASTNode return false; return true; - } + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { if (child == functionName) { other.setPropertyInParent(child.getPropertyInParent()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java index 92ce4f549b5..cc2cae9409a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java @@ -31,12 +31,12 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; * A function declarator for plain C. */ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStandardFunctionDeclarator { - private IASTParameterDeclaration[] parameters; - private int parametersPos= -1; - private boolean varArgs; - private IScope scope; + private IASTParameterDeclaration[] parameters; + private int parametersPos = -1; + private boolean varArgs; + private IScope scope; - public CASTFunctionDeclarator() { + public CASTFunctionDeclarator() { } public CASTFunctionDeclarator(IASTName name) { @@ -60,34 +60,34 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda @Override public IASTParameterDeclaration[] getParameters() { - if (parameters == null) - return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY; - parameters = ArrayUtil.trimAt(IASTParameterDeclaration.class, parameters, parametersPos); - return parameters; - } + if (parameters == null) + return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY; + parameters = ArrayUtil.trimAt(IASTParameterDeclaration.class, parameters, parametersPos); + return parameters; + } - @Override + @Override public void addParameterDeclaration(IASTParameterDeclaration parameter) { - assertNotFrozen(); - if (parameter != null) { - parameter.setParent(this); + assertNotFrozen(); + if (parameter != null) { + parameter.setParent(this); parameter.setPropertyInParent(FUNCTION_PARAMETER); - parameters = ArrayUtil.appendAt(IASTParameterDeclaration.class, parameters, ++parametersPos, parameter); - } - } + parameters = ArrayUtil.appendAt(IASTParameterDeclaration.class, parameters, ++parametersPos, parameter); + } + } - @Override + @Override public boolean takesVarArgs() { - return varArgs; - } + return varArgs; + } - @Override + @Override public void setVarArgs(boolean value) { - assertNotFrozen(); - varArgs = value; - } + assertNotFrozen(); + varArgs = value; + } - @Override + @Override protected boolean postAccept(ASTVisitor action) { IASTParameterDeclaration[] params = getParameters(); for (int i = 0; i < params.length; i++) { @@ -99,39 +99,39 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda @Override public void replace(IASTNode child, IASTNode other) { - if (parameters != null) { - for (int i = 0; i < parameters.length; ++i) { - if (child == parameters[i]) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - parameters[i]= (IASTParameterDeclaration) other; - return; - } - } - } - super.replace(child, other); + if (parameters != null) { + for (int i = 0; i < parameters.length; ++i) { + if (child == parameters[i]) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + parameters[i] = (IASTParameterDeclaration) other; + return; + } + } + } + super.replace(child, other); } @Override public IScope getFunctionScope() { - if (scope != null) - return scope; + if (scope != null) + return scope; - // introduce a scope for function declarations and definitions, only. - IASTNode node= getParent(); - while (!(node instanceof IASTDeclaration)) { - if (node==null) - return null; - node= node.getParent(); - } - if (node instanceof IASTParameterDeclaration) - return null; + // introduce a scope for function declarations and definitions, only. + IASTNode node = getParent(); + while (!(node instanceof IASTDeclaration)) { + if (node == null) + return null; + node = node.getParent(); + } + if (node instanceof IASTParameterDeclaration) + return null; - if (node instanceof IASTFunctionDefinition) { - scope= ((IASTFunctionDefinition) node).getScope(); - } else if (ASTQueries.findTypeRelevantDeclarator(this) == this) { - scope = new CScope(this, EScopeKind.eLocal); - } - return scope; + if (node instanceof IASTFunctionDefinition) { + scope = ((IASTFunctionDefinition) node).getScope(); + } else if (ASTQueries.findTypeRelevantDeclarator(this) == this) { + scope = new CScope(this, EScopeKind.eLocal); + } + return scope; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java index 076529de508..83e91b43dbf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java @@ -32,19 +32,19 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; */ public class CASTFunctionDefinition extends ASTNode implements IASTFunctionDefinition, IASTAmbiguityParent { - private IASTDeclSpecifier declSpecifier; - private IASTFunctionDeclarator declarator; - private IASTStatement bodyStatement; - private ICFunctionScope scope; + private IASTDeclSpecifier declSpecifier; + private IASTFunctionDeclarator declarator; + private IASTStatement bodyStatement; + private ICFunctionScope scope; - public CASTFunctionDefinition() { + public CASTFunctionDefinition() { } public CASTFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, IASTStatement bodyStatement) { - setDeclSpecifier(declSpecifier); - setDeclarator(declarator); - setBody(bodyStatement); + setDeclSpecifier(declSpecifier); + setDeclarator(declarator); + setBody(bodyStatement); } @Override @@ -69,49 +69,49 @@ public class CASTFunctionDefinition extends ASTNode implements IASTFunctionDefin @Override public IASTDeclSpecifier getDeclSpecifier() { - return declSpecifier; - } + return declSpecifier; + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); - declSpecifier = declSpec; - if (declSpec != null) { + assertNotFrozen(); + declSpecifier = declSpec; + if (declSpec != null) { declSpec.setParent(this); declSpec.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public IASTFunctionDeclarator getDeclarator() { - return declarator; - } + return declarator; + } - @Override + @Override public void setDeclarator(IASTFunctionDeclarator declarator) { - assertNotFrozen(); - this.declarator = declarator; - if (declarator != null) { - IASTDeclarator outerDtor= ASTQueries.findOutermostDeclarator(declarator); - outerDtor.setParent(this); - outerDtor.setPropertyInParent(DECLARATOR); + assertNotFrozen(); + this.declarator = declarator; + if (declarator != null) { + IASTDeclarator outerDtor = ASTQueries.findOutermostDeclarator(declarator); + outerDtor.setParent(this); + outerDtor.setPropertyInParent(DECLARATOR); } - } + } - @Override + @Override public IASTStatement getBody() { - return bodyStatement; - } + return bodyStatement; + } - @Override + @Override public void setBody(IASTStatement statement) { - assertNotFrozen(); - bodyStatement = statement; - if (statement != null) { + assertNotFrozen(); + bodyStatement = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(FUNCTION_BODY); } - } + } @Override public IScope getScope() { @@ -120,37 +120,46 @@ public class CASTFunctionDefinition extends ASTNode implements IASTFunctionDefin return scope; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declSpecifier != null && !declSpecifier.accept(action)) return false; - final IASTDeclarator outerDtor= ASTQueries.findOutermostDeclarator(declarator); - if (outerDtor != null && !outerDtor.accept(action)) return false; - if (bodyStatement != null && !bodyStatement.accept(action)) return false; - - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (declSpecifier != null && !declSpecifier.accept(action)) + return false; + final IASTDeclarator outerDtor = ASTQueries.findOutermostDeclarator(declarator); + if (outerDtor != null && !outerDtor.accept(action)) + return false; + if (bodyStatement != null && !bodyStatement.accept(action)) + return false; + + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (bodyStatement == child) { - other.setPropertyInParent(bodyStatement.getPropertyInParent()); - other.setParent(bodyStatement.getParent()); - bodyStatement = (IASTStatement) other; - } - } + if (bodyStatement == child) { + other.setPropertyInParent(bodyStatement.getPropertyInParent()); + other.setParent(bodyStatement.getParent()); + bodyStatement = (IASTStatement) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java index be0bb7b2112..2a9483824fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java @@ -24,9 +24,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; * @author jcamelon */ public class CASTGotoStatement extends ASTAttributeOwner implements IASTGotoStatement { - private IASTName name; + private IASTName name; - public CASTGotoStatement() { + public CASTGotoStatement() { } public CASTGotoStatement(IASTName name) { @@ -46,45 +46,54 @@ public class CASTGotoStatement extends ASTAttributeOwner implements IASTGotoStat @Override public IASTName getName() { - return this.name; - } + return this.name; + } - @Override - public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { - name.setParent(this); - name.setPropertyInParent(NAME); - } - } + @Override + public void setName(IASTName name) { + assertNotFrozen(); + this.name = name; + if (name != null) { + name.setParent(this); + name.setPropertyInParent(NAME); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (name != null && !name.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (n == name) return r_reference; + if (n == name) + return r_reference; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java index ddb3d114440..87a66e9d22a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java @@ -37,9 +37,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; * ID Expression in C. */ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTCompletionContext { - private IASTName name; + private IASTName name; - public CASTIdExpression() { + public CASTIdExpression() { } public CASTIdExpression(IASTName name) { @@ -59,44 +59,52 @@ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTC @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(ID_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (name != null && !name.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (name != null && !name.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (n == name) return r_reference; + if (n == name) + return r_reference; return r_unclear; } @@ -134,7 +142,7 @@ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTC for (int i = 0; i < bindings.length; i++) { if (bindings[i] instanceof IEnumeration || bindings[i] instanceof ICompositeType) { - bindings[i]= null; + bindings[i] = null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java index 195627386e2..8360ca32ee8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java @@ -28,11 +28,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * If statements for C. */ public class CASTIfStatement extends ASTAttributeOwner implements IASTIfStatement, IASTAmbiguityParent { - private IASTExpression condition; - private IASTStatement thenClause; - private IASTStatement elseClause; + private IASTExpression condition; + private IASTStatement thenClause; + private IASTStatement elseClause; - public CASTIfStatement() { + public CASTIfStatement() { } public CASTIfStatement(IASTExpression condition, IASTStatement thenClause) { @@ -61,48 +61,48 @@ public class CASTIfStatement extends ASTAttributeOwner implements IASTIfStatemen @Override public IASTExpression getConditionExpression() { - return condition; - } + return condition; + } - @Override + @Override public void setConditionExpression(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); } - } + } - @Override + @Override public IASTStatement getThenClause() { - return thenClause; - } + return thenClause; + } - @Override + @Override public void setThenClause(IASTStatement thenClause) { - assertNotFrozen(); - this.thenClause = thenClause; - if (thenClause != null) { + assertNotFrozen(); + this.thenClause = thenClause; + if (thenClause != null) { thenClause.setParent(this); thenClause.setPropertyInParent(THEN); } - } + } - @Override + @Override public IASTStatement getElseClause() { - return elseClause; - } + return elseClause; + } - @Override + @Override public void setElseClause(IASTStatement elseClause) { - assertNotFrozen(); - this.elseClause = elseClause; - if (elseClause != null) { + assertNotFrozen(); + this.elseClause = elseClause; + if (elseClause != null) { elseClause.setParent(this); elseClause.setPropertyInParent(ELSE); } - } + } private static class N { final IASTIfStatement fIfStatement; @@ -113,71 +113,74 @@ public class CASTIfStatement extends ASTAttributeOwner implements IASTIfStatemen } } - @Override + @Override public boolean accept(ASTVisitor action) { - N stack= null; - IASTIfStatement stmt= this; - loop: for (;;) { - if (action.shouldVisitStatements) { - switch (action.visit(stmt)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: - stmt= null; - break loop; - default: break; - } - } - - if (!((CASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false; - - IASTNode child = stmt.getConditionExpression(); - if (child != null && !child.accept(action)) - return false; - child= stmt.getThenClause(); - if (child != null && !child.accept(action)) - return false; - child= stmt.getElseClause(); - if (child instanceof IASTIfStatement) { - if (action.shouldVisitStatements) { - N n= new N(stmt); - n.fNext= stack; - stack= n; - } - stmt= (IASTIfStatement) child; - } else { - if (child != null && !child.accept(action)) - return false; - break loop; - } - } - if (action.shouldVisitStatements) { - if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) - return false; - while (stack != null) { - if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) - return false; - stack= stack.fNext; - } - } - return true; - } - - @Override + N stack = null; + IASTIfStatement stmt = this; + loop: for (;;) { + if (action.shouldVisitStatements) { + switch (action.visit(stmt)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + stmt = null; + break loop; + default: + break; + } + } + + if (!((CASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) + return false; + + IASTNode child = stmt.getConditionExpression(); + if (child != null && !child.accept(action)) + return false; + child = stmt.getThenClause(); + if (child != null && !child.accept(action)) + return false; + child = stmt.getElseClause(); + if (child instanceof IASTIfStatement) { + if (action.shouldVisitStatements) { + N n = new N(stmt); + n.fNext = stack; + stack = n; + } + stmt = (IASTIfStatement) child; + } else { + if (child != null && !child.accept(action)) + return false; + break loop; + } + } + if (action.shouldVisitStatements) { + if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) + return false; + while (stack != null) { + if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) + return false; + stack = stack.fNext; + } + } + return true; + } + + @Override public void replace(IASTNode child, IASTNode other) { - if (thenClause == child) { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - thenClause = (IASTStatement) other; - } - if (elseClause == child) { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - elseClause = (IASTStatement) other; - } - if (child == condition) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - condition = (IASTExpression) other; - } - } + if (thenClause == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + thenClause = (IASTStatement) other; + } + if (elseClause == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + elseClause = (IASTStatement) other; + } + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + condition = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInactiveCompletionName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInactiveCompletionName.java index 11922f0b1dd..6a84d6124b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInactiveCompletionName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInactiveCompletionName.java @@ -23,21 +23,21 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInactiveCompletionName; public class CASTInactiveCompletionName extends CASTName implements IASTInactiveCompletionName { private IASTTranslationUnit fAst; - + public CASTInactiveCompletionName(char[] name, IASTTranslationUnit ast) { super(name); fAst = ast; } - + @Override public IASTCompletionContext getCompletionContext() { return this; } - + @Override public IBinding[] findBindings(IASTName name, boolean isPrefix) { // 'name' (which is the same as 'this') is not hooked up to the AST, but it - // does have a location (offset and length) which we use to compute the + // does have a location (offset and length) which we use to compute the // containing scope. IASTNodeSelector sel = fAst.getNodeSelector(null); IASTNode node = sel.findEnclosingNode(getOffset(), getLength()); @@ -45,7 +45,7 @@ public class CASTInactiveCompletionName extends CASTName implements IASTInactive if (lookupScope == null) { lookupScope = fAst.getScope(); } - IBinding[] result = null; + IBinding[] result = null; try { if (isPrefix) { result = CVisitor.lookupPrefix(lookupScope, name); @@ -53,7 +53,7 @@ public class CASTInactiveCompletionName extends CASTName implements IASTInactive result = new IBinding[] { CVisitor.lookup(lookupScope, name) }; } } catch (DOMException e) { - } + } return ArrayUtil.trim(IBinding.class, result); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java index 44a2f792a5f..2db1fa01042 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; @Deprecated public class CASTInitializerExpression extends CASTEqualsInitializer implements IASTInitializerExpression { - public CASTInitializerExpression() { + public CASTInitializerExpression() { } public CASTInitializerExpression(IASTExpression expression) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java index 6b4089c0144..9ba82b19771 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java @@ -30,9 +30,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * e.g.: int a[]= {1,2,3}; */ public class CASTInitializerList extends ASTNode implements IASTInitializerList, IASTAmbiguityParent { - private IASTInitializerClause[] initializers; - private int initializersPos = -1; - private int actualSize; + private IASTInitializerClause[] initializers; + private int initializersPos = -1; + private int actualSize; @Override public CASTInitializerList copy() { @@ -65,20 +65,20 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList, @Override @Deprecated public IASTInitializer[] getInitializers() { - IASTInitializerClause[] clauses= getClauses(); + IASTInitializerClause[] clauses = getClauses(); if (clauses.length == 0) return IASTInitializer.EMPTY_INITIALIZER_ARRAY; - IASTInitializer[] inits= new IASTInitializer[clauses.length]; + IASTInitializer[] inits = new IASTInitializer[clauses.length]; for (int i = 0; i < inits.length; i++) { - IASTInitializerClause clause= clauses[i]; + IASTInitializerClause clause = clauses[i]; if (clause instanceof IASTInitializer) { - inits[i]= (IASTInitializer) clause; + inits[i] = (IASTInitializer) clause; } else if (clause instanceof IASTExpression) { final CASTEqualsInitializer initExpr = new CASTEqualsInitializer(((IASTExpression) clause).copy()); initExpr.setParent(this); initExpr.setPropertyInParent(NESTED_INITIALIZER); - inits[i]= initExpr; + inits[i] = initExpr; } } return inits; @@ -86,51 +86,57 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList, @Override public void addClause(IASTInitializerClause d) { - assertNotFrozen(); - if (d != null) { - initializers = ArrayUtil.appendAt(IASTInitializerClause.class, initializers, ++initializersPos, d); - d.setParent(this); + assertNotFrozen(); + if (d != null) { + initializers = ArrayUtil.appendAt(IASTInitializerClause.class, initializers, ++initializersPos, d); + d.setParent(this); d.setPropertyInParent(NESTED_INITIALIZER); - } - actualSize++; - } + } + actualSize++; + } @Override @Deprecated public void addInitializer(IASTInitializer d) { - assertNotFrozen(); - if (d instanceof IASTInitializerClause) { - addClause((IASTInitializerClause) d); - } else if (d instanceof IASTEqualsInitializer) { - addClause(((IASTEqualsInitializer) d).getInitializerClause()); - } else { - addClause(null); - } - } + assertNotFrozen(); + if (d instanceof IASTInitializerClause) { + addClause((IASTInitializerClause) d); + } else if (d instanceof IASTEqualsInitializer) { + addClause(((IASTEqualsInitializer) d).getInitializerClause()); + } else { + addClause(null); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitInitializers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default : break; - } + if (action.shouldVisitInitializers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } IASTInitializerClause[] list = getClauses(); for (IASTInitializerClause clause : list) { if (!clause.accept(action)) return false; } - if (action.shouldVisitInitializers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java index e8f3d4209f1..7e7ebeed399 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java @@ -71,7 +71,7 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn @Override public void setParameterNames(IASTName[] names) { - assertNotFrozen(); + assertNotFrozen(); parameterNames = names; if (names != null) { for (IASTName name : names) { @@ -90,7 +90,7 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn @Override public void setParameterDeclarations(IASTDeclaration[] decls) { - assertNotFrozen(); + assertNotFrozen(); parameterDeclarations = decls; if (decls != null) { for (IASTDeclaration decl : decls) { @@ -107,7 +107,7 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn return parameterDeclarations; } - @Override + @Override protected boolean postAccept(ASTVisitor action) { IASTName[] ns = getParameterNames(); for (int i = 0; i < ns.length; i++) { @@ -126,18 +126,18 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn @Override public IASTDeclarator getDeclaratorForParameterName(IASTName name) { - boolean found= false; - for (int i= 0; i < parameterNames.length; i++) { + boolean found = false; + for (int i = 0; i < parameterNames.length; i++) { if (parameterNames[i] == name) found = true; } if (!found) return null; - for (int i= 0; i < parameterDeclarations.length; i++) { + for (int i = 0; i < parameterDeclarations.length; i++) { if (parameterDeclarations[i] instanceof IASTSimpleDeclaration) { IASTDeclarator[] decltors = ((IASTSimpleDeclaration) parameterDeclarations[i]).getDeclarators(); - for (int j= 0; j < decltors.length; j++) { + for (int j = 0; j < decltors.length; j++) { if (decltors[j].getName().toString().equals(name.toString())) return decltors[j]; } @@ -149,7 +149,7 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn @Override public int getRoleForName(IASTName name) { - IASTName [] n = getParameterNames(); + IASTName[] n = getParameterNames(); for (int i = 0; i < n.length; ++i) { if (n[i] == name) return r_unclear; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java index 1c3d786b298..8cfc14fee3d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java @@ -27,10 +27,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * @author jcamelon */ public class CASTLabelStatement extends ASTAttributeOwner implements IASTLabelStatement, IASTAmbiguityParent { - private IASTName name; - private IASTStatement nestedStatement; + private IASTName name; + private IASTStatement nestedStatement; - public CASTLabelStatement() { + public CASTLabelStatement() { } public CASTLabelStatement(IASTName name, IASTStatement nestedStatement) { @@ -53,42 +53,51 @@ public class CASTLabelStatement extends ASTAttributeOwner implements IASTLabelSt @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (name != null && !name.accept(action)) return false; - if (nestedStatement != null && !nestedStatement.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; + if (nestedStatement != null && !nestedStatement.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -97,27 +106,27 @@ public class CASTLabelStatement extends ASTAttributeOwner implements IASTLabelSt return r_unclear; } - @Override + @Override public IASTStatement getNestedStatement() { - return nestedStatement; - } + return nestedStatement; + } - @Override + @Override public void setNestedStatement(IASTStatement s) { - assertNotFrozen(); - nestedStatement = s; - if (s != null) { + assertNotFrozen(); + nestedStatement = s; + if (s != null) { s.setParent(this); s.setPropertyInParent(NESTED_STATEMENT); } - } + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == nestedStatement) { - other.setParent(this); - other.setPropertyInParent(child.getPropertyInParent()); - setNestedStatement((IASTStatement) other); - } - } + if (child == nestedStatement) { + other.setParent(this); + other.setPropertyInParent(child.getPropertyInParent()); + setNestedStatement((IASTStatement) other); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java index 0c3b01ae6b4..c138fd24dea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java @@ -29,10 +29,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; * Represents a literal */ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpression { - private int kind; - private char[] value = CharArrayUtils.EMPTY; + private int kind; + private char[] value = CharArrayUtils.EMPTY; - public CASTLiteralExpression() { + public CASTLiteralExpression() { } public CASTLiteralExpression(int kind, char[] value) { @@ -53,49 +53,55 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress @Override public int getKind() { - return kind; - } + return kind; + } - @Override + @Override public void setKind(int value) { - assertNotFrozen(); - kind = value; - } + assertNotFrozen(); + kind = value; + } - @Override + @Override public char[] getValue() { - return value; - } + return value; + } - @Override + @Override public void setValue(char[] value) { - assertNotFrozen(); - this.value= value; - } + assertNotFrozen(); + this.value = value; + } - @Override + @Override public String toString() { - return new String(value); - } + return new String(value); + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public IType getExpressionType() { @@ -125,16 +131,18 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress } private IType classifyTypeOfFloatLiteral() { - final char[] lit= getValue(); - final int len= lit.length; - IBasicType.Kind kind= IBasicType.Kind.eDouble; - int flags= 0; + final char[] lit = getValue(); + final int len = lit.length; + IBasicType.Kind kind = IBasicType.Kind.eDouble; + int flags = 0; if (len > 0) { switch (lit[len - 1]) { - case 'f': case 'F': - kind= Kind.eFloat; + case 'f': + case 'F': + kind = Kind.eFloat; break; - case 'l': case 'L': + case 'l': + case 'L': flags |= IBasicType.IS_LONG; break; } @@ -144,12 +152,12 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress } private IType classifyTypeOfIntLiteral() { - int makelong= 0; - boolean unsigned= false; + int makelong = 0; + boolean unsigned = false; - final char[] lit= getValue(); - for (int i= lit.length - 1; i >= 0; i--) { - final char c= lit[i]; + final char[] lit = getValue(); + for (int i = lit.length - 1; i >= 0; i--) { + final char c = lit[i]; if (!(c > 'f' && c <= 'z') && !(c > 'F' && c <= 'Z')) { break; } @@ -165,7 +173,7 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress } } - int flags= 0; + int flags = 0; if (unsigned) { flags |= IBasicType.IS_UNSIGNED; } @@ -178,20 +186,19 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress return new CBasicType(IBasicType.Kind.eInt, flags, this); } - - /** - * @deprecated, use {@link #setValue(char[])}, instead. - */ - @Override + /** + * @deprecated, use {@link #setValue(char[])}, instead. + */ + @Override @Deprecated public void setValue(String value) { - assertNotFrozen(); - this.value = value.toCharArray(); - } + assertNotFrozen(); + this.value = value.toCharArray(); + } - /** - * @deprecated use {@link #CASTLiteralExpression(int, char[])}, instead. - */ + /** + * @deprecated use {@link #CASTLiteralExpression(int, char[])}, instead. + */ @Deprecated public CASTLiteralExpression(int kind, String value) { this(kind, value.toCharArray()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java index 04b8f4bc270..f9832a357bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java @@ -35,21 +35,21 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalNameOwner; * Implementation for names in C translation units. */ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext { - private final char[] name; + private final char[] name; - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private IBinding binding; + private IBinding binding; - public CASTName(char[] name) { - this.name = name; - } + public CASTName(char[] name) { + this.name = name; + } - public CASTName() { - name = CharArrayUtils.EMPTY_CHAR_ARRAY; - } + public CASTName() { + name = CharArrayUtils.EMPTY_CHAR_ARRAY; + } - @Override + @Override public CASTName copy() { return copy(CopyStyle.withoutLocations); } @@ -60,61 +60,61 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext return copy(copy, style); } - @Override + @Override public IBinding resolveBinding() { - if (binding == null) { - CVisitor.createBinding(this); - } + if (binding == null) { + CVisitor.createBinding(this); + } - return binding; - } + return binding; + } - @Override + @Override public IBinding resolvePreBinding() { - return resolveBinding(); - } + return resolveBinding(); + } - @Override + @Override public IBinding getBinding() { - return binding; - } + return binding; + } - @Override + @Override public IBinding getPreBinding() { - return binding; - } + return binding; + } - @Override + @Override public IASTCompletionContext getCompletionContext() { - IASTNode node = getParent(); - while (node != null) { - if (node instanceof IASTCompletionContext) { - return (IASTCompletionContext) node; - } - node = node.getParent(); - } - if (getLength() > 0) { - return this; - } - return null; - } - - @Override + IASTNode node = getParent(); + while (node != null) { + if (node instanceof IASTCompletionContext) { + return (IASTCompletionContext) node; + } + node = node.getParent(); + } + if (getLength() > 0) { + return this; + } + return null; + } + + @Override public void setBinding(IBinding binding) { - this.binding = binding; - } + this.binding = binding; + } - @Override + @Override public String toString() { - if (name == CharArrayUtils.EMPTY_CHAR_ARRAY) - return EMPTY_STRING; - return new String(name); - } + if (name == CharArrayUtils.EMPTY_CHAR_ARRAY) + return EMPTY_STRING; + return new String(name); + } - @Override + @Override public char[] toCharArray() { - return name; - } + return name; + } @Override public char[] getSimpleID() { @@ -126,89 +126,89 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext return name; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitNames) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } - - if (action.shouldVisitNames) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } - return true; - } + if (action.shouldVisitNames) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + if (action.shouldVisitNames) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } @Override public int getRoleOfName(boolean allowResolution) { - IASTNode parent = getParent(); - if (parent instanceof IASTInternalNameOwner) { - return ((IASTInternalNameOwner) parent).getRoleForName(this, allowResolution); - } - if (parent instanceof IASTNameOwner) { - return ((IASTNameOwner) parent).getRoleForName(this); - } - return IASTNameOwner.r_unclear; + IASTNode parent = getParent(); + if (parent instanceof IASTInternalNameOwner) { + return ((IASTInternalNameOwner) parent).getRoleForName(this, allowResolution); + } + if (parent instanceof IASTNameOwner) { + return ((IASTNameOwner) parent).getRoleForName(this); + } + return IASTNameOwner.r_unclear; } - @Override + @Override public boolean isDeclaration() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - switch (role) { - case IASTNameOwner.r_reference: - case IASTNameOwner.r_unclear: - return false; - default: - return true; - } - } - return false; - } - - @Override + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + case IASTNameOwner.r_unclear: + return false; + default: + return true; + } + } + return false; + } + + @Override public boolean isReference() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - switch (role) { - case IASTNameOwner.r_reference: - return true; - default: - return false; - } - } - return false; - } - - @Override + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + return true; + default: + return false; + } + } + return false; + } + + @Override public boolean isDefinition() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - switch (role) { - case IASTNameOwner.r_definition: - return true; - default: - return false; - } - } - return false; - } + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_definition: + return true; + default: + return false; + } + } + return false; + } @Override public ILinkage getLinkage() { @@ -253,7 +253,7 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext break; } } else { - bindings[i]= null; + bindings[i] = null; } } return ArrayUtil.removeNulls(bindings); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java index 96b1a8630f9..499a481efcc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java @@ -23,29 +23,36 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; * @author jcamelon */ public class CASTNullStatement extends ASTAttributeOwner implements IASTNullStatement { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public CASTNullStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java index 97fa2d9d2aa..59619d2eb92 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTParameterDeclaration.java @@ -28,10 +28,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; */ public class CASTParameterDeclaration extends ASTNode implements IASTParameterDeclaration, IASTAmbiguityParent { - private IASTDeclSpecifier declSpec; - private IASTDeclarator declarator; + private IASTDeclSpecifier declSpec; + private IASTDeclarator declarator; - public CASTParameterDeclaration() { + public CASTParameterDeclaration() { } public CASTParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) { @@ -54,62 +54,72 @@ public class CASTParameterDeclaration extends ASTNode implements IASTParameterDe @Override public IASTDeclSpecifier getDeclSpecifier() { - return declSpec; - } + return declSpec; + } - @Override + @Override public IASTDeclarator getDeclarator() { - return declarator; - } + return declarator; + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); - this.declSpec = declSpec; - if (declSpec != null) { + assertNotFrozen(); + this.declSpec = declSpec; + if (declSpec != null) { declSpec.setParent(this); declSpec.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public void setDeclarator(IASTDeclarator declarator) { - assertNotFrozen(); - this.declarator = declarator; - if (declarator != null) { + assertNotFrozen(); + this.declarator = declarator; + if (declarator != null) { declarator.setParent(this); declarator.setPropertyInParent(DECLARATOR); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitParameterDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitParameterDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declSpec != null) if (!declSpec.accept(action)) return false; - if (declarator != null) if (!declarator.accept(action)) return false; - if (action.shouldVisitParameterDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (declSpec != null) + if (!declSpec.accept(action)) + return false; + if (declarator != null) + if (!declarator.accept(action)) + return false; + if (action.shouldVisitParameterDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { - if (child == declarator) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - declarator= (IASTDeclarator) other; - } + if (child == declarator) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + declarator = (IASTDeclarator) other; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java index 0423cd126f1..f00738f95f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java @@ -21,11 +21,11 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; public class CASTPointer extends ASTAttributeOwner implements ICASTPointer { - private boolean isRestrict; - private boolean isVolatile; - private boolean isConst; + private boolean isRestrict; + private boolean isVolatile; + private boolean isConst; - @Override + @Override public CASTPointer copy() { return copy(CopyStyle.withoutLocations); } @@ -41,44 +41,46 @@ public class CASTPointer extends ASTAttributeOwner implements ICASTPointer { @Override public boolean isRestrict() { - return isRestrict; - } + return isRestrict; + } - @Override + @Override public void setRestrict(boolean value) { - assertNotFrozen(); - isRestrict = value; - } + assertNotFrozen(); + isRestrict = value; + } - @Override + @Override public boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public void setConst(boolean value) { - assertNotFrozen(); - isConst = value; - } + assertNotFrozen(); + isConst = value; + } - @Override + @Override public void setVolatile(boolean value) { - assertNotFrozen(); - isVolatile = value; - } + assertNotFrozen(); + isVolatile = value; + } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitPointerOperators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } } if (!acceptByAttributeSpecifiers(action)) @@ -87,7 +89,7 @@ public class CASTPointer extends ASTAttributeOwner implements ICASTPointer { if (action.shouldVisitPointerOperators) { if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - } + } return true; - } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java index da247e90ae9..66fe5359a1e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java @@ -24,38 +24,44 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem; */ public class CASTProblem extends ASTProblem { - public CASTProblem(int id, char[] arg, boolean isError) { - super(id, arg, isError); - } + public CASTProblem(int id, char[] arg, boolean isError) { + super(id, arg, isError); + } - @Override + @Override public CASTProblem copy() { return copy(CopyStyle.withoutLocations); } @Override public CASTProblem copy(CopyStyle style) { - char[] arg = getArgument(); - CASTProblem copy = new CASTProblem(getID(), arg == null ? null : arg.clone(), isError()); + char[] arg = getArgument(); + CASTProblem copy = new CASTProblem(getID(), arg == null ? null : arg.clone(), isError()); return copy(copy, style); } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitProblems) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitProblems) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitProblems) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitProblems) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java index bc33be9b632..d664ea23150 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; */ public class CASTProblemDeclaration extends CASTProblemOwner implements IASTProblemDeclaration { - public CASTProblemDeclaration() { + public CASTProblemDeclaration() { super(); } @@ -45,23 +45,29 @@ public class CASTProblemDeclaration extends CASTProblemOwner implements IASTProb @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - super.accept(action); // Visit the problem. + super.accept(action); // Visit the problem. - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java index 5f7e04bf7ef..e835d017604 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java @@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; public class CASTProblemExpression extends CASTProblemOwner implements IASTProblemExpression { - public CASTProblemExpression() { + public CASTProblemExpression() { super(); } @@ -45,30 +45,36 @@ public class CASTProblemExpression extends CASTProblemOwner implements IASTProbl @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - super.accept(action); // visits the problem + super.accept(action); // visits the problem - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public IType getExpressionType() { return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); - } + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java index f25ab6ae964..358bc69291c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java @@ -23,49 +23,55 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ abstract class CASTProblemOwner extends ASTNode implements IASTProblemHolder { - private IASTProblem problem; + private IASTProblem problem; - public CASTProblemOwner() { + public CASTProblemOwner() { } public CASTProblemOwner(IASTProblem problem) { setProblem(problem); } - protected <T extends CASTProblemOwner> T copy(T copy, CopyStyle style) { + protected <T extends CASTProblemOwner> T copy(T copy, CopyStyle style) { copy.setProblem(problem == null ? null : problem.copy(style)); return super.copy(copy, style); } @Override public IASTProblem getProblem() { - return problem; - } + return problem; + } - @Override + @Override public void setProblem(IASTProblem p) { - assertNotFrozen(); - problem = p; - if (p != null) { + assertNotFrozen(); + problem = p; + if (p != null) { p.setParent(this); p.setPropertyInParent(PROBLEM); } - } + } @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitProblems) { - switch (action.visit(getProblem())) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - switch (action.leave(getProblem())) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitProblems) { + switch (action.visit(getProblem())) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + switch (action.leave(getProblem())) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java index 5a199b29dd6..a712d43a241 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java @@ -48,25 +48,31 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - super.accept(action); // visits the problem + super.accept(action); // visits the problem - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public IASTAttribute[] getAttributes() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java index 691984b13e6..65d192cc09d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java @@ -25,9 +25,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; public class CASTReturnStatement extends ASTAttributeOwner implements IASTReturnStatement, IASTAmbiguityParent { - private IASTExpression retValue; + private IASTExpression retValue; - public CASTReturnStatement() { + public CASTReturnStatement() { } public CASTReturnStatement(IASTExpression retValue) { @@ -41,29 +41,28 @@ public class CASTReturnStatement extends ASTAttributeOwner implements IASTReturn @Override public CASTReturnStatement copy(CopyStyle style) { - CASTReturnStatement copy = - new CASTReturnStatement(retValue == null ? null : retValue.copy(style)); + CASTReturnStatement copy = new CASTReturnStatement(retValue == null ? null : retValue.copy(style)); return copy(copy, style); } @Override public IASTExpression getReturnValue() { - return retValue; - } + return retValue; + } - @Override + @Override public void setReturnValue(IASTExpression returnValue) { - assertNotFrozen(); - retValue = returnValue; - if (returnValue != null) { + assertNotFrozen(); + retValue = returnValue; + if (returnValue != null) { returnValue.setParent(this); returnValue.setPropertyInParent(RETURNVALUE); } - } + } - @Override + @Override public IASTInitializerClause getReturnArgument() { - return getReturnValue(); + return getReturnValue(); } @Override @@ -77,33 +76,41 @@ public class CASTReturnStatement extends ASTAttributeOwner implements IASTReturn @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (retValue != null && !retValue.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (retValue != null && !retValue.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == retValue) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - retValue = (IASTExpression) other; - } - } + if (child == retValue) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + retValue = (IASTExpression) other; + } + } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java index a5c46ffdbe7..d75fc3a11b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclSpecifier.java @@ -22,17 +22,17 @@ import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements ICASTSimpleDeclSpecifier { - private int simpleType; - private boolean isSigned; - private boolean isUnsigned; - private boolean isShort; - private boolean isLong; - private boolean longlong; - private boolean complex; - private boolean imaginary; + private int simpleType; + private boolean isSigned; + private boolean isUnsigned; + private boolean isShort; + private boolean isLong; + private boolean longlong; + private boolean complex; + private boolean imaginary; private IASTExpression fDeclTypeExpression; - @Override + @Override public CASTSimpleDeclSpecifier copy() { return copy(CopyStyle.withoutLocations); } @@ -45,59 +45,59 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC protected <T extends CASTSimpleDeclSpecifier> T copy(T copy, CopyStyle style) { CASTSimpleDeclSpecifier target = copy; - target.simpleType = simpleType; - target.isSigned = isSigned; - target.isUnsigned = isUnsigned; - target.isShort = isShort; - target.isLong = isLong; - target.longlong = longlong; - target.complex = complex; - target.imaginary = imaginary; - if (fDeclTypeExpression != null) + target.simpleType = simpleType; + target.isSigned = isSigned; + target.isUnsigned = isUnsigned; + target.isShort = isShort; + target.isLong = isLong; + target.longlong = longlong; + target.complex = complex; + target.imaginary = imaginary; + if (fDeclTypeExpression != null) copy.setDeclTypeExpression(fDeclTypeExpression.copy(style)); - return super.copy(copy, style); - } + return super.copy(copy, style); + } - @Override + @Override public int getType() { - return simpleType; - } + return simpleType; + } - @Override + @Override public boolean isSigned() { - return isSigned; - } + return isSigned; + } - @Override + @Override public boolean isUnsigned() { - return isUnsigned; - } + return isUnsigned; + } - @Override + @Override public boolean isShort() { - return isShort; - } + return isShort; + } - @Override + @Override public boolean isLong() { - return isLong; - } + return isLong; + } - @Override + @Override public void setType(int type) { - assertNotFrozen(); - simpleType = type; - } + assertNotFrozen(); + simpleType = type; + } - @Override + @Override public void setType(Kind kind) { - setType(getType(kind)); - } + setType(getType(kind)); + } - private int getType(Kind kind) { - switch (kind) { - case eBoolean: - return t_bool; + private int getType(Kind kind) { + switch (kind) { + case eBoolean: + return t_bool; case eChar: case eWChar: case eChar16: @@ -126,71 +126,77 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC case eNullPtr: // Null pointer type cannot be expressed with a simple declaration specifier. break; - } - return t_unspecified; - } + } + return t_unspecified; + } - @Override + @Override public void setShort(boolean value) { - assertNotFrozen(); - isShort = value; - } + assertNotFrozen(); + isShort = value; + } - @Override + @Override public void setLong(boolean value) { - assertNotFrozen(); - isLong = value; - } + assertNotFrozen(); + isLong = value; + } - @Override + @Override public void setUnsigned(boolean value) { - assertNotFrozen(); - isUnsigned = value; - } + assertNotFrozen(); + isUnsigned = value; + } - @Override + @Override public void setSigned(boolean value) { - assertNotFrozen(); - isSigned = value; - } + assertNotFrozen(); + isSigned = value; + } - @Override + @Override public boolean isLongLong() { - return longlong; - } + return longlong; + } - @Override + @Override public void setLongLong(boolean value) { - assertNotFrozen(); - longlong = value; - } + assertNotFrozen(); + longlong = value; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!visitAlignmentSpecifiers(action)) { - return false; - } + if (!visitAlignmentSpecifiers(action)) { + return false; + } - if (fDeclTypeExpression != null && !fDeclTypeExpression.accept(action)) + if (fDeclTypeExpression != null && !fDeclTypeExpression.accept(action)) return false; - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public boolean isComplex() { @@ -199,7 +205,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC @Override public void setComplex(boolean value) { - assertNotFrozen(); + assertNotFrozen(); this.complex = value; } @@ -210,7 +216,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC @Override public void setImaginary(boolean value) { - assertNotFrozen(); + assertNotFrozen(); this.imaginary = value; } @@ -221,12 +227,12 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC @Override public void setDeclTypeExpression(IASTExpression expression) { - assertNotFrozen(); - fDeclTypeExpression= expression; - if (expression != null) { - expression.setPropertyInParent(DECLTYPE_EXPRESSION); - expression.setParent(this); - } + assertNotFrozen(); + fDeclTypeExpression = expression; + if (expression != null) { + expression.setPropertyInParent(DECLTYPE_EXPRESSION); + expression.setParent(this); + } } @Override @@ -234,7 +240,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC if (child == fDeclTypeExpression) { other.setPropertyInParent(child.getPropertyInParent()); other.setParent(child.getParent()); - fDeclTypeExpression= (IASTExpression) other; + fDeclTypeExpression = (IASTExpression) other; return; } super.replace(child, other); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java index ab34e74ad29..4ff87d5f077 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java @@ -29,11 +29,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * Models a simple declaration. */ public class CASTSimpleDeclaration extends ASTAttributeOwner implements IASTSimpleDeclaration, IASTAmbiguityParent { - private IASTDeclarator[] declarators; - private int declaratorsPos = -1; - private IASTDeclSpecifier declSpecifier; + private IASTDeclarator[] declarators; + private int declaratorsPos = -1; + private IASTDeclSpecifier declSpecifier; - public CASTSimpleDeclaration() { + public CASTSimpleDeclaration() { } public CASTSimpleDeclaration(IASTDeclSpecifier declSpecifier) { @@ -57,82 +57,90 @@ public class CASTSimpleDeclaration extends ASTAttributeOwner implements IASTSimp @Override public IASTDeclSpecifier getDeclSpecifier() { - return declSpecifier; - } + return declSpecifier; + } - @Override + @Override public IASTDeclarator[] getDeclarators() { - if (declarators == null) - return IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - declarators = ArrayUtil.trimAt(IASTDeclarator.class, declarators, declaratorsPos); - return declarators; - } + if (declarators == null) + return IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + declarators = ArrayUtil.trimAt(IASTDeclarator.class, declarators, declaratorsPos); + return declarators; + } - @Override + @Override public void addDeclarator(IASTDeclarator d) { - assertNotFrozen(); - if (d != null) { - d.setParent(this); + assertNotFrozen(); + if (d != null) { + d.setParent(this); d.setPropertyInParent(DECLARATOR); - declarators = ArrayUtil.appendAt(IASTDeclarator.class, declarators, ++declaratorsPos, d); - } - } + declarators = ArrayUtil.appendAt(IASTDeclarator.class, declarators, ++declaratorsPos, d); + } + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) { - assertNotFrozen(); - this.declSpecifier = declSpecifier; - if (declSpecifier != null) { + assertNotFrozen(); + this.declSpecifier = declSpecifier; + if (declSpecifier != null) { declSpecifier.setParent(this); declSpecifier.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (declSpecifier != null && !declSpecifier.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (declSpecifier != null && !declSpecifier.accept(action)) + return false; - IASTDeclarator[] dtors = getDeclarators(); - for (int i = 0; i < dtors.length; i++) { - if (!dtors[i].accept(action)) - return false; - } + IASTDeclarator[] dtors = getDeclarators(); + for (int i = 0; i < dtors.length; i++) { + if (!dtors[i].accept(action)) + return false; + } - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (declSpecifier == child) { + if (declSpecifier == child) { other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); - declSpecifier= (IASTDeclSpecifier) other; - } else { - IASTDeclarator[] declarators = getDeclarators(); - for (int i = 0; i < declarators.length; i++) { - if (declarators[i] == child) { - declarators[i] = (IASTDeclarator) other; - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - break; - } - } - } + declSpecifier = (IASTDeclSpecifier) other; + } else { + IASTDeclarator[] declarators = getDeclarators(); + for (int i = 0; i < declarators.length; i++) { + if (declarators[i] == child) { + declarators[i] = (IASTDeclarator) other; + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + break; + } + } + } } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java index 4d8017d7cd4..de683cc6842 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java @@ -26,12 +26,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CASTSwitchStatement extends ASTAttributeOwner - implements IASTSwitchStatement, IASTAmbiguityParent { - private IASTExpression controller; - private IASTStatement body; +public class CASTSwitchStatement extends ASTAttributeOwner implements IASTSwitchStatement, IASTAmbiguityParent { + private IASTExpression controller; + private IASTStatement body; - public CASTSwitchStatement() { + public CASTSwitchStatement() { } public CASTSwitchStatement(IASTExpression controller, IASTStatement body) { @@ -54,69 +53,78 @@ public class CASTSwitchStatement extends ASTAttributeOwner @Override public IASTExpression getControllerExpression() { - return controller; - } + return controller; + } - @Override + @Override public void setControllerExpression(IASTExpression controller) { - assertNotFrozen(); - this.controller = controller; - if (controller != null) { + assertNotFrozen(); + this.controller = controller; + if (controller != null) { controller.setParent(this); controller.setPropertyInParent(CONTROLLER_EXP); } - } + } - @Override + @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement body) { - assertNotFrozen(); - this.body = body; - if (body != null) { + assertNotFrozen(); + this.body = body; + if (body != null) { body.setParent(this); body.setPropertyInParent(BODY); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (controller != null && !controller.accept(action)) return false; - if (body != null && !body.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (controller != null && !controller.accept(action)) + return false; + if (body != null && !body.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (body == child) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - body = (IASTStatement) other; - } - if (child == controller) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - controller = (IASTExpression) other; - } - } + if (body == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + body = (IASTStatement) other; + } + if (child == controller) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + controller = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index c303c3c301e..ded9b111154 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -41,7 +41,7 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig private final CStructMapper fStructMapper; public CASTTranslationUnit() { - fStructMapper= new CStructMapper(this); + fStructMapper = new CStructMapper(this); } @Override @@ -66,7 +66,7 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig public IASTName[] getDeclarationsInAST(IBinding binding) { if (binding instanceof IMacroBinding) { return getMacroDefinitionsInAST((IMacroBinding) binding); - } + } return CVisitor.getDeclarations(this, binding); } @@ -74,34 +74,34 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig public IASTName[] getDefinitionsInAST(IBinding binding) { return getDefinitionsInAST(binding, false); } - - @Override + + @Override public IASTName[] getDefinitionsInAST(IBinding binding, boolean permissive) { if (binding instanceof IMacroBinding) { return getMacroDefinitionsInAST((IMacroBinding) binding); - } + } // TODO: Implement support for permissive=true. - IASTName[] names = CVisitor.getDeclarations(this, binding); - for (int i = 0; i < names.length; i++) { - if (!names[i].isDefinition()) - names[i] = null; - } - // nulls can be anywhere, don't use trim() - return ArrayUtil.removeNulls(IASTName.class, names); - } + IASTName[] names = CVisitor.getDeclarations(this, binding); + for (int i = 0; i < names.length; i++) { + if (!names[i].isDefinition()) + names[i] = null; + } + // nulls can be anywhere, don't use trim() + return ArrayUtil.removeNulls(IASTName.class, names); + } @Override public IASTName[] getReferences(IBinding binding) { - if (binding instanceof IMacroBinding) - return getMacroReferencesInAST((IMacroBinding) binding); + if (binding instanceof IMacroBinding) + return getMacroReferencesInAST((IMacroBinding) binding); return CVisitor.getReferences(this, binding); } @Override @Deprecated - public ParserLanguage getParserLanguage() { - return ParserLanguage.C; - } + public ParserLanguage getParserLanguage() { + return ParserLanguage.C; + } @Override public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java index de197f84d23..b9cb69aef2a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeId.java @@ -24,10 +24,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ public class CASTTypeId extends ASTNode implements IASTTypeId { - private IASTDeclSpecifier declSpecifier; - private IASTDeclarator declarator; + private IASTDeclSpecifier declSpecifier; + private IASTDeclarator declarator; - public CASTTypeId() { + public CASTTypeId() { } public CASTTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) { @@ -50,54 +50,62 @@ public class CASTTypeId extends ASTNode implements IASTTypeId { @Override public IASTDeclSpecifier getDeclSpecifier() { - return declSpecifier; - } + return declSpecifier; + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); - this.declSpecifier = declSpec; - if (declSpec != null) { + assertNotFrozen(); + this.declSpecifier = declSpec; + if (declSpec != null) { declSpec.setParent(this); declSpec.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public IASTDeclarator getAbstractDeclarator() { - return declarator; - } + return declarator; + } - @Override + @Override public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) { - assertNotFrozen(); - declarator = abstractDeclarator; - if (abstractDeclarator != null) { + assertNotFrozen(); + declarator = abstractDeclarator; + if (abstractDeclarator != null) { abstractDeclarator.setParent(this); abstractDeclarator.setPropertyInParent(ABSTRACT_DECLARATOR); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitTypeIds) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTypeIds) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declSpecifier != null && !declSpecifier.accept(action)) return false; - if (declarator != null && !declarator.accept(action)) return false; + if (declSpecifier != null && !declSpecifier.accept(action)) + return false; + if (declarator != null && !declarator.accept(action)) + return false; - if (action.shouldVisitTypeIds) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTypeIds) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java index 26a0088e5a7..77d9cf1aac7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdExpression.java @@ -26,10 +26,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; */ public class CASTTypeIdExpression extends ASTNode implements IASTTypeIdExpression { - private int op; - private IASTTypeId typeId; + private int op; + private IASTTypeId typeId; - public CASTTypeIdExpression() { + public CASTTypeIdExpression() { } public CASTTypeIdExpression(int op, IASTTypeId typeId) { @@ -44,66 +44,73 @@ public class CASTTypeIdExpression extends ASTNode implements IASTTypeIdExpressio @Override public CASTTypeIdExpression copy(CopyStyle style) { - CASTTypeIdExpression copy = new CASTTypeIdExpression(op, typeId == null ? null - : typeId.copy(style)); + CASTTypeIdExpression copy = new CASTTypeIdExpression(op, typeId == null ? null : typeId.copy(style)); return copy(copy, style); } @Override public int getOperator() { - return op; - } + return op; + } - @Override + @Override public void setOperator(int value) { - assertNotFrozen(); - this.op = value; - } + assertNotFrozen(); + this.op = value; + } - @Override + @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.typeId = typeId; - if (typeId != null) { + assertNotFrozen(); + this.typeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); } - } + } - @Override + @Override public IASTTypeId getTypeId() { - return typeId; - } + return typeId; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (typeId != null) if (!typeId.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (typeId != null) + if (!typeId.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public IType getExpressionType() { - if (getOperator() == op_sizeof) { + if (getOperator() == op_sizeof) { return CVisitor.get_SIZE_T(this); } - return CVisitor.createType(typeId.getAbstractDeclarator()); - } + return CVisitor.createType(typeId.getAbstractDeclarator()); + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java index 68a0ccb8fb4..bb8fe385649 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypeIdInitializerExpression.java @@ -27,10 +27,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * Type id initializer expression for C, type-id { initializer } */ public class CASTTypeIdInitializerExpression extends ASTNode implements ICASTTypeIdInitializerExpression { - private IASTTypeId fTypeId; - private IASTInitializer fInitializer; + private IASTTypeId fTypeId; + private IASTInitializer fInitializer; - public CASTTypeIdInitializerExpression() { + public CASTTypeIdInitializerExpression() { } public CASTTypeIdInitializerExpression(IASTTypeId t, IASTInitializer i) { @@ -40,56 +40,64 @@ public class CASTTypeIdInitializerExpression extends ASTNode implements ICASTTyp @Override public IASTTypeId getTypeId() { - return fTypeId; - } + return fTypeId; + } - @Override + @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.fTypeId = typeId; - if (typeId != null) { + assertNotFrozen(); + this.fTypeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); } - } + } - @Override + @Override public IASTInitializer getInitializer() { - return fInitializer; - } + return fInitializer; + } - @Override + @Override public void setInitializer(IASTInitializer initializer) { - assertNotFrozen(); - this.fInitializer = initializer; - if (initializer != null) { + assertNotFrozen(); + this.fInitializer = initializer; + if (initializer != null) { initializer.setParent(this); initializer.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fTypeId != null && !fTypeId.accept(action)) return false; - if (fInitializer != null && !fInitializer.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (fTypeId != null && !fTypeId.accept(action)) + return false; + if (fInitializer != null && !fInitializer.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public final boolean isLValue() { @@ -114,8 +122,7 @@ public class CASTTypeIdInitializerExpression extends ASTNode implements ICASTTyp @Override public CASTTypeIdInitializerExpression copy(CopyStyle style) { CASTTypeIdInitializerExpression copy = new CASTTypeIdInitializerExpression( - fTypeId == null ? null : fTypeId.copy(style), - fInitializer == null ? null : fInitializer.copy(style)); + fTypeId == null ? null : fTypeId.copy(style), fInitializer == null ? null : fInitializer.copy(style)); return copy(copy, style); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java index f9e7ff30c58..cd34a2b45c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java @@ -29,9 +29,9 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; */ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements ICASTTypedefNameSpecifier, IASTCompletionContext { - private IASTName name; + private IASTName name; - public CASTTypedefNameSpecifier() { + public CASTTypedefNameSpecifier() { } public CASTTypedefNameSpecifier(IASTName name) { @@ -45,49 +45,54 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier @Override public CASTTypedefNameSpecifier copy(CopyStyle style) { - CASTTypedefNameSpecifier copy = - new CASTTypedefNameSpecifier(name == null ? null : name.copy(style)); + CASTTypedefNameSpecifier copy = new CASTTypedefNameSpecifier(name == null ? null : name.copy(style)); return copy(copy, style); } @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!visitAlignmentSpecifiers(action)) - return false; - if (name != null && !name.accept(action)) - return false; + if (!visitAlignmentSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -102,7 +107,7 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier for (int i = 0; i < bindings.length; i++) { if (!(bindings[i] instanceof ITypedef)) { - bindings[i]= null; + bindings[i] = null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java index f2014127d8f..c8d928e140f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTUnaryExpression.java @@ -33,10 +33,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; * Unary expression in C. */ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, IASTAmbiguityParent { - private int operator; - private IASTExpression operand; + private int operator; + private IASTExpression operand; - public CASTUnaryExpression() { + public CASTUnaryExpression() { } public CASTUnaryExpression(int operator, IASTExpression operand) { @@ -51,67 +51,73 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, @Override public CASTUnaryExpression copy(CopyStyle style) { - CASTUnaryExpression copy = - new CASTUnaryExpression(operator, operand == null ? null : operand.copy(style)); + CASTUnaryExpression copy = new CASTUnaryExpression(operator, operand == null ? null : operand.copy(style)); return copy(copy, style); } @Override public int getOperator() { - return operator; - } + return operator; + } - @Override + @Override public void setOperator(int value) { - assertNotFrozen(); - this.operator = value; - } + assertNotFrozen(); + this.operator = value; + } - @Override + @Override public IASTExpression getOperand() { - return operand; - } + return operand; + } - @Override + @Override public void setOperand(IASTExpression expression) { - assertNotFrozen(); - operand = expression; - if (expression != null) { + assertNotFrozen(); + operand = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (operand != null && !operand.accept(action)) return false; + if (operand != null && !operand.accept(action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == operand) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - operand = (IASTExpression) other; - } - } + if (child == operand) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + operand = (IASTExpression) other; + } + } @Override public IType getExpressionType() { @@ -132,7 +138,7 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression, case op_minus: case op_plus: case op_tilde: - IType t= CArithmeticConversion.promoteCType(type); + IType t = CArithmeticConversion.promoteCType(type); if (t != null) { return restoreTypedefs(t, exprType); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java index 87d3371abd5..7c8df5d2fa4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java @@ -26,12 +26,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CASTWhileStatement extends ASTAttributeOwner - implements IASTWhileStatement, IASTAmbiguityParent { - private IASTExpression condition; - private IASTStatement body; +public class CASTWhileStatement extends ASTAttributeOwner implements IASTWhileStatement, IASTAmbiguityParent { + private IASTExpression condition; + private IASTStatement body; - public CASTWhileStatement() { + public CASTWhileStatement() { } public CASTWhileStatement(IASTExpression condition, IASTStatement body) { @@ -54,69 +53,78 @@ public class CASTWhileStatement extends ASTAttributeOwner @Override public IASTExpression getCondition() { - return condition; - } + return condition; + } - @Override + @Override public void setCondition(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITIONEXPRESSION); } - } + } - @Override + @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement body) { - assertNotFrozen(); - this.body = body; - if (body != null) { + assertNotFrozen(); + this.body = body; + if (body != null) { body.setParent(this); body.setPropertyInParent(BODY); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (condition != null && !condition.accept(action)) return false; - if (body != null && !body.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (condition != null && !condition.accept(action)) + return false; + if (body != null && !body.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (body == child) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - body = (IASTStatement) other; - } - if (child == condition) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - condition = (IASTExpression) other; - } - } + if (body == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + body = (IASTStatement) other; + } + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + condition = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArithmeticConversion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArithmeticConversion.java index a076fa8d6b3..2ec8b3efda9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArithmeticConversion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArithmeticConversion.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; public class CArithmeticConversion extends ArithmeticConversion { - private static CArithmeticConversion sInstance= new CArithmeticConversion(); + private static CArithmeticConversion sInstance = new CArithmeticConversion(); public static IType convertCOperandTypes(int operator, IType t1, IType t2) { return sInstance.convertOperandTypes(operator, t1, t2); @@ -29,7 +29,8 @@ public class CArithmeticConversion extends ArithmeticConversion { return sInstance.promoteType(type); } - private CArithmeticConversion() {} + private CArithmeticConversion() { + } @Override protected IBasicType createBasicType(Kind kind, int modifiers) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java index 3b77f95aa0d..407bd5ee660 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java @@ -32,12 +32,12 @@ import org.eclipse.core.runtime.CoreException; public class CArrayType implements ICArrayType, ITypeContainer, ISerializableType { IType type; - private IASTExpression sizeExpression; - private IValue value= IntegralValue.NOT_INITIALIZED; - private boolean isConst; - private boolean isVolatile; - private boolean isRestrict; - private boolean isStatic; + private IASTExpression sizeExpression; + private IValue value = IntegralValue.NOT_INITIALIZED; + private boolean isConst; + private boolean isVolatile; + private boolean isRestrict; + private boolean isStatic; private boolean isVariableSized; public CArrayType(IType type) { @@ -45,38 +45,44 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp } public CArrayType(IType type, boolean isConst, boolean isVolatile, boolean isRestrict, IValue size) { - this.type= type; - this.isConst= isConst; - this.isVolatile= isVolatile; - this.isRestrict= isRestrict; - this.value= size; + this.type = type; + this.isConst = isConst; + this.isVolatile = isVolatile; + this.isRestrict = isRestrict; + this.value = size; } public void setIsStatic(boolean val) { - isStatic= val; + isStatic = val; } + public void setIsVariableLength(boolean val) { - isVariableSized= val; + isVariableSized = val; } - @Override + @Override public boolean isSameType(IType obj) { - if (obj == this) - return true; - if (obj instanceof ITypedef) - return obj.isSameType(this); - if (obj instanceof ICArrayType) { - ICArrayType at = (ICArrayType) obj; - if (isConst() != at.isConst()) return false; - if (isRestrict() != at.isRestrict()) return false; - if (isStatic() != at.isStatic()) return false; - if (isVolatile() != at.isVolatile()) return false; - if (isVariableLength() != at.isVariableLength()) return false; + if (obj == this) + return true; + if (obj instanceof ITypedef) + return obj.isSameType(this); + if (obj instanceof ICArrayType) { + ICArrayType at = (ICArrayType) obj; + if (isConst() != at.isConst()) + return false; + if (isRestrict() != at.isRestrict()) + return false; + if (isStatic() != at.isStatic()) + return false; + if (isVolatile() != at.isVolatile()) + return false; + if (isVariableLength() != at.isVariableLength()) + return false; return at.getType().isSameType(type) && hasSameSize(at); - } - return false; - } + } + return false; + } private boolean hasSameSize(IArrayType rhs) { IValue s1 = getSize(); @@ -95,16 +101,16 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp @Override public void setType(IType t) { - this.type = t; + this.type = t; } public void setModifier(ICASTArrayModifier mod) { - isConst= mod.isConst(); - isVolatile= mod.isVolatile(); - isRestrict= mod.isRestrict(); - isStatic= mod.isStatic(); - isVariableSized= mod.isVariableSized(); - sizeExpression= mod.getConstantExpression(); + isConst = mod.isConst(); + isVolatile = mod.isVolatile(); + isRestrict = mod.isRestrict(); + isStatic = mod.isStatic(); + isVariableSized = mod.isVariableSized(); + sizeExpression = mod.getConstantExpression(); } @Override @@ -132,32 +138,32 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp return isVariableSized; } - @Override + @Override public IValue getSize() { - if (value != IntegralValue.NOT_INITIALIZED) - return value; + if (value != IntegralValue.NOT_INITIALIZED) + return value; - if (sizeExpression == null) - return value= null; + if (sizeExpression == null) + return value = null; - return value= ValueFactory.create(sizeExpression); - } + return value = ValueFactory.create(sizeExpression); + } - @Override - public boolean hasSize() { - return value == IntegralValue.NOT_INITIALIZED ? sizeExpression != null : value != null; - } + @Override + public boolean hasSize() { + return value == IntegralValue.NOT_INITIALIZED ? sizeExpression != null : value != null; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen + } + return t; + } @Override public String toString() { @@ -167,21 +173,26 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { short firstBytes = ITypeMarshalBuffer.ARRAY_TYPE; - long nval= -1; - IValue val= null; - - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; - if (isStatic()) firstBytes |= ITypeMarshalBuffer.FLAG4; - if (isVariableLength()) firstBytes |= ITypeMarshalBuffer.FLAG5; - - val= getSize(); + long nval = -1; + IValue val = null; + + if (isConst()) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) + firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) + firstBytes |= ITypeMarshalBuffer.FLAG3; + if (isStatic()) + firstBytes |= ITypeMarshalBuffer.FLAG4; + if (isVariableLength()) + firstBytes |= ITypeMarshalBuffer.FLAG5; + + val = getSize(); if (val != null) { firstBytes |= ITypeMarshalBuffer.FLAG6; - Number num= val.numberValue(); + Number num = val.numberValue(); if (num != null) { - nval= num.longValue(); + nval = num.longValue(); if (nval >= 0) { firstBytes |= ITypeMarshalBuffer.FLAG7; } @@ -197,17 +208,15 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IValue value= null; + IValue value = null; if ((firstBytes & ITypeMarshalBuffer.FLAG7) != 0) { value = IntegralValue.create(buffer.getLong()); } else if ((firstBytes & ITypeMarshalBuffer.FLAG6) != 0) { value = buffer.unmarshalValue(); } - IType nested= buffer.unmarshalType(); - CArrayType result= new CArrayType(nested, - (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, - (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, - (firstBytes & ITypeMarshalBuffer.FLAG3) != 0, value); + IType nested = buffer.unmarshalType(); + CArrayType result = new CArrayType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, (firstBytes & ITypeMarshalBuffer.FLAG3) != 0, value); result.setIsStatic((firstBytes & ITypeMarshalBuffer.FLAG4) != 0); result.setIsVariableLength((firstBytes & ITypeMarshalBuffer.FLAG5) != 0); return result; @@ -215,7 +224,7 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp @Override @Deprecated - public IASTExpression getArraySizeExpression() { - return sizeExpression; - } + public IASTExpression getArraySizeExpression() { + return sizeExpression; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java index 8c341480cfa..c87754de3ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java @@ -36,12 +36,12 @@ public class CBasicType implements ICBasicType, ISerializableType { public CBasicType(Kind kind, int modifiers, IASTExpression value) { if (kind == Kind.eUnspecified) { if ((modifiers & (IS_COMPLEX | IS_IMAGINARY)) != 0) { - fKind= Kind.eFloat; + fKind = Kind.eFloat; } else { - fKind= Kind.eInt; + fKind = Kind.eInt; } } else { - fKind= kind; + fKind = kind; } fModifiers = modifiers; this.value = value; @@ -52,17 +52,13 @@ public class CBasicType implements ICBasicType, ISerializableType { } public CBasicType(ICASTSimpleDeclSpecifier sds) { - this (getKind(sds), getQualifiers(sds), null); + this(getKind(sds), getQualifiers(sds), null); } private static int getQualifiers(ICASTSimpleDeclSpecifier sds) { - return (sds.isLong() ? IS_LONG : 0) | - (sds.isShort() ? IS_SHORT : 0) | - (sds.isSigned() ? IS_SIGNED: 0) | - (sds.isUnsigned() ? IS_UNSIGNED : 0) | - (sds.isLongLong() ? IS_LONG_LONG : 0) | - (sds.isComplex() ? IS_COMPLEX : 0) | - (sds.isImaginary() ? IS_IMAGINARY : 0); + return (sds.isLong() ? IS_LONG : 0) | (sds.isShort() ? IS_SHORT : 0) | (sds.isSigned() ? IS_SIGNED : 0) + | (sds.isUnsigned() ? IS_UNSIGNED : 0) | (sds.isLongLong() ? IS_LONG_LONG : 0) + | (sds.isComplex() ? IS_COMPLEX : 0) | (sds.isImaginary() ? IS_IMAGINARY : 0); } private static Kind getKind(ICASTSimpleDeclSpecifier sds) { @@ -153,18 +149,18 @@ public class CBasicType implements ICBasicType, ISerializableType { } } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen - } - return t; - } - - @Override + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen + } + return t; + } + + @Override @Deprecated public IASTExpression getValue() { return value; @@ -182,9 +178,9 @@ public class CBasicType implements ICBasicType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - final int kind= getKind().ordinal(); - final int shiftedKind= kind * ITypeMarshalBuffer.FIRST_FLAG; - final int modifiers= getModifiers(); + final int kind = getKind().ordinal(); + final int shiftedKind = kind * ITypeMarshalBuffer.FIRST_FLAG; + final int modifiers = getModifiers(); if (modifiers == 0) { buffer.putShort((short) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); } else { @@ -194,11 +190,11 @@ public class CBasicType implements ICBasicType, ISerializableType { } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - final boolean haveModifiers= (firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0; - int modifiers= 0; - int kind= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG-1))/ITypeMarshalBuffer.FIRST_FLAG; + final boolean haveModifiers = (firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0; + int modifiers = 0; + int kind = (firstBytes & (ITypeMarshalBuffer.LAST_FLAG - 1)) / ITypeMarshalBuffer.FIRST_FLAG; if (haveModifiers) { - modifiers= buffer.getByte(); + modifiers = buffer.getByte(); } return new CBasicType(Kind.values()[kind], modifiers); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java index c7a0029a5f9..6a91048d614 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java @@ -32,15 +32,15 @@ public class CBuiltinParameter extends PlatformObject implements IParameter { return IParameter.EMPTY_PARAMETER_ARRAY; } assert !(ft instanceof ICPPFunctionType); - IType[] ptypes= ft.getParameterTypes(); - IParameter[] result= new IParameter[ptypes.length]; + IType[] ptypes = ft.getParameterTypes(); + IParameter[] result = new IParameter[ptypes.length]; for (int i = 0; i < result.length; i++) { - result[i]= new CBuiltinParameter(ptypes[i]); + result[i] = new CBuiltinParameter(ptypes[i]); } return result; } - private IType type= null; + private IType type = null; public CBuiltinParameter(IType type) { this.type = type; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinVariable.java index 0e899caf46b..f141a6c9ffa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinVariable.java @@ -25,53 +25,52 @@ import org.eclipse.cdt.core.dom.ast.IType; * An example is the built-in variable __func__. */ public class CBuiltinVariable extends CVariable { - private IType type=null; - private char[] name=null; - private IScope scope=null; + private IType type = null; + private char[] name = null; + private IScope scope = null; - public CBuiltinVariable(IType type, char[] name, IScope scope) { - super(null); - this.type = type; - this.name = name; - this.scope = scope; - } + public CBuiltinVariable(IType type, char[] name, IScope scope) { + super(null); + this.type = type; + this.name = name; + this.scope = scope; + } - @Override + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public String getName() { - return String.valueOf(name); - } + return String.valueOf(name); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() { - return scope; - } + return scope; + } - /** - * returns null - */ - @Override + /** + * returns null + */ + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - /** - * returns null - */ - @Override + /** + * returns null + */ + @Override public IASTNode getDefinition() { - return null; - } - + return null; + } @Override public IBinding getOwner() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java index c96ddacfb53..f0a86400012 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CCompositeTypeScope.java @@ -35,34 +35,35 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; * Implementation of scope for structs and unions. */ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope { - public CCompositeTypeScope(ICASTCompositeTypeSpecifier compTypeSpec) { - super(compTypeSpec, EScopeKind.eClassType); - } + public CCompositeTypeScope(ICASTCompositeTypeSpecifier compTypeSpec) { + super(compTypeSpec, EScopeKind.eClassType); + } - @Override + @Override public IBinding getBinding(char[] name) { - return super.getBinding(NAMESPACE_TYPE_OTHER, name); - } + return super.getBinding(NAMESPACE_TYPE_OTHER, name); + } - @Override + @Override public IBinding[] find(String name) { - CollectNamesAction action = new CollectNamesAction(name.toCharArray()); - getPhysicalNode().accept(action); + CollectNamesAction action = new CollectNamesAction(name.toCharArray()); + getPhysicalNode().accept(action); - IASTName[] names = action.getNames(); - IBinding[] result = null; - for (IASTName astName : names) { - IBinding b = astName.resolveBinding(); - if (b == null) continue; - try { - if (b.getScope() == this) - result = ArrayUtil.append(IBinding.class, result, b); - } catch (DOMException e) { - } - } + IASTName[] names = action.getNames(); + IBinding[] result = null; + for (IASTName astName : names) { + IBinding b = astName.resolveBinding(); + if (b == null) + continue; + try { + if (b.getScope() == this) + result = ArrayUtil.append(IBinding.class, result, b); + } catch (DOMException e) { + } + } - return ArrayUtil.trim(IBinding.class, result); - } + return ArrayUtil.trim(IBinding.class, result); + } @Override public ICompositeType getCompositeType() { @@ -71,7 +72,8 @@ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope if (binding instanceof ICompositeType) return (ICompositeType) binding; - return new CStructure.CStructureProblem(compSpec.getName(), ISemanticProblem.BINDING_NO_CLASS, compSpec.getName().toCharArray()); + return new CStructure.CStructureProblem(compSpec.getName(), ISemanticProblem.BINDING_NO_CLASS, + compSpec.getName().toCharArray()); } @Override @@ -91,8 +93,10 @@ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope ASTInternal.addName(this, dtorName); } // anonymous structures and unions - if (declarators.length == 0 && ((IASTSimpleDeclaration) node).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) { - ICASTCompositeTypeSpecifier declSpec = (ICASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier(); + if (declarators.length == 0 && ((IASTSimpleDeclaration) node) + .getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) { + ICASTCompositeTypeSpecifier declSpec = (ICASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node) + .getDeclSpecifier(); IASTName n = declSpec.getName(); if (n.toCharArray().length == 0) { specStack = ArrayUtil.append(ICASTCompositeTypeSpecifier.class, specStack, declSpec); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java index abd3c676a51..6fb435ef8d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java @@ -40,55 +40,56 @@ import org.eclipse.core.runtime.PlatformObject; * Binding for enumerations in C. */ public class CEnumeration extends PlatformObject implements IEnumeration, ICInternalBinding { - private IASTName[] declarations = null; - private IASTName definition = null; + private IASTName[] declarations = null; + private IASTName definition = null; private Long fMinValue; private Long fMaxValue; - public CEnumeration(IASTName enumeration) { - ASTNodeProperty prop = enumeration.getPropertyInParent(); - if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) - declarations = new IASTName[] { enumeration }; - else - definition = enumeration; - enumeration.setBinding(this); + + public CEnumeration(IASTName enumeration) { + ASTNodeProperty prop = enumeration.getPropertyInParent(); + if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) + declarations = new IASTName[] { enumeration }; + else + definition = enumeration; + enumeration.setBinding(this); } public void addDeclaration(IASTName decl) { if (!decl.isActive()) return; - if (decl.getPropertyInParent() != IASTElaboratedTypeSpecifier.TYPE_NAME) - return; - - decl.setBinding(this); - if (declarations == null) { - declarations = new IASTName[] { decl }; - return; - } - for (int i = 0; i < declarations.length; i++) { - if (declarations[i] == null) { - declarations[i] = decl; - return; - } - } - IASTName tmp[] = new IASTName[declarations.length * 2]; - System.arraycopy(declarations, 0, tmp, 0, declarations.length); - tmp[declarations.length] = decl; - declarations = tmp; - } - - @Override + if (decl.getPropertyInParent() != IASTElaboratedTypeSpecifier.TYPE_NAME) + return; + + decl.setBinding(this); + if (declarations == null) { + declarations = new IASTName[] { decl }; + return; + } + for (int i = 0; i < declarations.length; i++) { + if (declarations[i] == null) { + declarations[i] = decl; + return; + } + } + IASTName tmp[] = new IASTName[declarations.length * 2]; + System.arraycopy(declarations, 0, tmp, 0, declarations.length); + tmp[declarations.length] = decl; + declarations = tmp; + } + + @Override public IASTNode getPhysicalNode() { - if (definition != null) - return definition; + if (definition != null) + return definition; - return declarations[0]; - } + return declarations[0]; + } private void checkForDefinition() { IASTDeclSpecifier spec = CVisitor.findDefinition((ICASTElaboratedTypeSpecifier) declarations[0].getParent()); if (spec != null && spec instanceof ICASTEnumerationSpecifier) { - ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) spec; + ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) spec; enumSpec.getName().setBinding(this); definition = enumSpec.getName(); @@ -96,81 +97,83 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte return; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + @Override public String getName() { - if (definition != null) - return definition.toString(); + if (definition != null) + return definition.toString(); - return declarations[0].toString(); - } - @Override + return declarations[0].toString(); + } + + @Override public char[] getNameCharArray() { - if (definition != null) - return definition.toCharArray(); + if (definition != null) + return definition.toCharArray(); - return declarations[0].toCharArray(); - } + return declarations[0].toCharArray(); + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + @Override public IScope getScope() { - return CVisitor.getContainingScope(definition != null ? definition : declarations[0].getParent()); - } + return CVisitor.getContainingScope(definition != null ? definition : declarations[0].getParent()); + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators() - */ - @Override + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators() + */ + @Override public IEnumerator[] getEnumerators() { - if (definition == null) { - checkForDefinition(); - if (definition == null) - return new IEnumerator[] { new CEnumerator.CEnumeratorProblem(declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, declarations[0].toCharArray()) }; - } - - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) definition.getParent(); - IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpec.getEnumerators(); - IEnumerator[] bindings = new IEnumerator[enums.length]; - - for (int i = 0; i < enums.length; i++) { - bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); - } - return bindings; - } + if (definition == null) { + checkForDefinition(); + if (definition == null) + return new IEnumerator[] { new CEnumerator.CEnumeratorProblem(declarations[0], + IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, declarations[0].toCharArray()) }; + } + + IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) definition.getParent(); + IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpec.getEnumerators(); + IEnumerator[] bindings = new IEnumerator[enums.length]; + + for (int i = 0; i < enums.length; i++) { + bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); + } + return bindings; + } public void addDefinition(IASTName name) { if (name.isActive()) definition = name; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) + */ + @Override public boolean isSameType(IType type) { - if (type == this) - return true; - if (type instanceof ITypedef || type instanceof IIndexBinding) - return type.isSameType(this); + if (type == this) + return true; + if (type instanceof ITypedef || type instanceof IIndexBinding) + return type.isSameType(this); - return false; - } + return false; + } @Override public ILinkage getLinkage() { @@ -189,9 +192,9 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte @Override public IBinding getOwner() { - IASTNode node= definition; + IASTNode node = definition; if (node == null && declarations != null && declarations.length > 0) { - node= declarations[0]; + node = declarations[0]; } // either local or global, never part of structs return CVisitor.findEnclosingFunction(node); @@ -208,7 +211,7 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte return fMinValue.longValue(); long minValue = SemanticUtil.computeMinValue(this); - fMinValue= minValue; + fMinValue = minValue; return minValue; } @@ -218,7 +221,7 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte return fMaxValue.longValue(); long maxValue = SemanticUtil.computeMaxValue(this); - fMaxValue= maxValue; + fMaxValue = maxValue; return maxValue; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java index ce81ebee688..99c36696da2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java @@ -34,47 +34,48 @@ import org.eclipse.core.runtime.PlatformObject; * C-specific binding for enumerators. */ public class CEnumerator extends PlatformObject implements IEnumerator { - public static class CEnumeratorProblem extends ProblemBinding implements IEnumerator { - public CEnumeratorProblem(IASTNode node, int id, char[] arg) { - super(node, id, arg); - } + public static class CEnumeratorProblem extends ProblemBinding implements IEnumerator { + public CEnumeratorProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); + } + @Override public IValue getValue() { return IntegralValue.UNKNOWN; } - } + } - private final IASTName enumeratorName; + private final IASTName enumeratorName; - public CEnumerator(IASTEnumerator enumtor) { + public CEnumerator(IASTEnumerator enumtor) { this.enumeratorName = enumtor.getName(); enumeratorName.setBinding(this); } - public IASTNode getPhysicalNode() { - return enumeratorName; - } + public IASTNode getPhysicalNode() { + return enumeratorName; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + @Override public String getName() { - return enumeratorName.toString(); - } + return enumeratorName.toString(); + } - @Override + @Override public char[] getNameCharArray() { - return enumeratorName.toCharArray(); - } + return enumeratorName.toCharArray(); + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + @Override public IScope getScope() { - return CVisitor.getContainingScope(enumeratorName.getParent()); - } + return CVisitor.getContainingScope(enumeratorName.getParent()); + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IEnumerator#getType() @@ -91,14 +92,14 @@ public class CEnumerator extends PlatformObject implements IEnumerator { @Override public IBinding getOwner() { - IASTEnumerator etor = (IASTEnumerator) enumeratorName.getParent(); + IASTEnumerator etor = (IASTEnumerator) enumeratorName.getParent(); IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) etor.getParent(); return enumSpec.getName().resolveBinding(); } @Override public IValue getValue() { - IASTNode parent= enumeratorName.getParent(); + IASTNode parent = enumeratorName.getParent(); if (parent instanceof ASTEnumerator) return ((ASTEnumerator) parent).getIntegralValue(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java index 6cccb00f165..01161731339 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java @@ -28,18 +28,18 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; * Models functions used without declarations. */ public class CExternalFunction extends CFunction implements ICExternalBinding { - private static final IType VOID_TYPE = new CBasicType(Kind.eVoid, 0); + private static final IType VOID_TYPE = new CBasicType(Kind.eVoid, 0); private IASTName name; - private IASTTranslationUnit tu; + private IASTTranslationUnit tu; - public CExternalFunction(IASTTranslationUnit tu, IASTName name) { - super(null); - this.name = name; - this.tu = tu; - } + public CExternalFunction(IASTTranslationUnit tu, IASTName name) { + super(null); + this.name = name; + this.tu = tu; + } - @Override + @Override public IFunctionType getType() { if (type == null) { // Bug 321856: Prevent recursions @@ -52,33 +52,33 @@ public class CExternalFunction extends CFunction implements ICExternalBinding { return type; } - @Override + @Override public IParameter[] getParameters() { - return IParameter.EMPTY_PARAMETER_ARRAY; + return IParameter.EMPTY_PARAMETER_ARRAY; } @Override protected IASTTranslationUnit getTranslationUnit() { return tu; - } + } - @Override + @Override public String getName() { - return name.toString(); - } + return name.toString(); + } - @Override + @Override public char[] getNameCharArray() { - return name.toCharArray(); - } + return name.toCharArray(); + } - @Override + @Override public IScope getScope() { - return tu.getScope(); - } + return tu.getScope(); + } - @Override + @Override public boolean isExtern() { - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 2d07e1bd9da..6fb3529f223 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -51,7 +51,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu private IASTDeclarator[] declarators; private IASTFunctionDeclarator definition; - private static final int FULLY_RESOLVED = 1; + private static final int FULLY_RESOLVED = 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private int bits; @@ -95,31 +95,31 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu storeDeclarator(fnDeclarator); } - protected IASTTranslationUnit getTranslationUnit() { + protected IASTTranslationUnit getTranslationUnit() { if (definition != null) { - return definition.getTranslationUnit(); + return definition.getTranslationUnit(); } else if (declarators != null) { - return declarators[0].getTranslationUnit(); + return declarators[0].getTranslationUnit(); } return null; - } - - private void resolveAllDeclarations() { - if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { - bits |= RESOLUTION_IN_PROGRESS; - IASTTranslationUnit tu = getTranslationUnit(); - if (tu != null) { - CVisitor.getDeclarations(tu, this); - } + } + + private void resolveAllDeclarations() { + if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { + bits |= RESOLUTION_IN_PROGRESS; + IASTTranslationUnit tu = getTranslationUnit(); + if (tu != null) { + CVisitor.getDeclarations(tu, this); + } declarators = ArrayUtil.trim(IASTDeclarator.class, declarators); - bits |= FULLY_RESOLVED; - bits &= ~RESOLUTION_IN_PROGRESS; - } + bits |= FULLY_RESOLVED; + bits &= ~RESOLUTION_IN_PROGRESS; + } } @Override public IParameter[] getParameters() { - int j= -1; + int j = -1; int len = declarators != null ? declarators.length : 0; for (IASTDeclarator dtor = definition; j < len; j++) { if (j >= 0) { @@ -132,8 +132,8 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu if (size > 0) { for (int i = 0; i < size; i++) { IASTParameterDeclaration p = params[i]; - result[i] = (IParameter) ASTQueries.findInnermostDeclarator(p.getDeclarator()) - .getName().resolveBinding(); + result[i] = (IParameter) ASTQueries.findInnermostDeclarator(p.getDeclarator()).getName() + .resolveBinding(); } if (result.length == 1 && SemanticUtil.isVoidType(result[0].getType())) @@ -148,8 +148,8 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu // Ensures that the list of parameters is created in the same order as // the K&R C parameter names for (int i = 0; i < names.length; i++) { - IASTDeclarator decl = CVisitor.getKnRParameterDeclarator( - (ICASTKnRFunctionDeclarator) dtor, names[i]); + IASTDeclarator decl = CVisitor.getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) dtor, + names[i]); if (decl != null) { result[i] = (IParameter) decl.getName().resolveBinding(); } else { @@ -187,10 +187,10 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu @Override public IScope getScope() { - IASTDeclarator dtor = getPhysicalNode(); + IASTDeclarator dtor = getPhysicalNode(); if (dtor != null) return CVisitor.getContainingScope(ASTQueries.findOutermostDeclarator(dtor).getParent()); - return null; + return null; } @Override @@ -202,13 +202,13 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu return null; } - @Override + @Override public IFunctionType getType() { if (type == null) { type = createType(); } - return type; - } + return type; + } protected IFunctionType createType() { IASTDeclarator declarator = getPhysicalNode(); @@ -224,220 +224,220 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu return null; } - public IBinding resolveParameter(IASTName paramName) { - if (paramName.getBinding() != null) - return paramName.getBinding(); - - IBinding binding = null; - int idx = 0; - IASTNode parent = paramName.getParent(); - while (parent instanceof IASTDeclarator && !(parent instanceof ICASTKnRFunctionDeclarator)) - parent = parent.getParent(); - - ICASTKnRFunctionDeclarator fKnRDtor = null; - IASTDeclarator knrParamDtor = null; - if (parent instanceof IASTParameterDeclaration) { - IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) parent.getParent(); - IASTParameterDeclaration[] ps = fdtor.getParameters(); - for (; idx < ps.length; idx++) { - if (parent == ps[idx]) - break; - } - } else if (parent instanceof IASTSimpleDeclaration) { - //KnR: name in declaration list - fKnRDtor = (ICASTKnRFunctionDeclarator) parent.getParent(); - IASTName[] ps = fKnRDtor.getParameterNames(); - char[] n = paramName.toCharArray(); - for (; idx < ps.length; idx++) { - if (CharArrayUtils.equals(ps[idx].toCharArray(), n)) - break; - } - } else { - //KnR: name in name list - fKnRDtor = (ICASTKnRFunctionDeclarator) parent; - IASTName[] ps = fKnRDtor.getParameterNames(); - for (; idx < ps.length; idx++) { - if (ps[idx] == paramName) - break; - } - knrParamDtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, paramName); - if (knrParamDtor != null) - paramName = knrParamDtor.getName(); - } - - //create a new binding and set it for the corresponding parameter in all known defns and decls - binding = new CParameter(paramName); - IASTParameterDeclaration temp = null; - if (definition != null) { - if (definition instanceof IASTStandardFunctionDeclarator) { - IASTParameterDeclaration[] parameters = ((IASTStandardFunctionDeclarator) definition).getParameters(); - if (parameters.length > idx) { - temp = parameters[idx]; - ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding); - } - } else if (definition instanceof ICASTKnRFunctionDeclarator) { - fKnRDtor = (ICASTKnRFunctionDeclarator) definition; - IASTName[] parameterNames = fKnRDtor.getParameterNames(); - if (parameterNames.length > idx) { - IASTName n = parameterNames[idx]; - n.setBinding(binding); - IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, n); - if (dtor != null) { - dtor.getName().setBinding(binding); - } - } - } - } - if (declarators != null) { - for (IASTDeclarator dtor : declarators) { - if (dtor instanceof IASTStandardFunctionDeclarator) { - IASTStandardFunctionDeclarator fdtor= (IASTStandardFunctionDeclarator) dtor; - if (fdtor.getParameters().length > idx) { - temp = fdtor.getParameters()[idx]; - ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding); - } - } - } - } - return binding; - } - - protected void updateParameterBindings(IASTFunctionDeclarator fdtor) { - IParameter[] params = getParameters(); - if (fdtor instanceof IASTStandardFunctionDeclarator) { - IASTParameterDeclaration[] nps = ((IASTStandardFunctionDeclarator) fdtor).getParameters(); - if (params.length < nps.length) - return; - for (int i = 0; i < nps.length; i++) { - IASTName name = ASTQueries.findInnermostDeclarator(nps[i].getDeclarator()).getName(); - name.setBinding(params[i]); - if (params[i] instanceof CParameter) - ((CParameter) params[i]).addDeclaration(name); - } - } else { - IASTName[] ns = ((ICASTKnRFunctionDeclarator) fdtor).getParameterNames(); - if (params.length > 0 && params.length != ns.length) - return; //problem - - for (int i = 0; i < params.length; i++) { - IASTName name = ns[i]; - name.setBinding(params[i]); - IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) fdtor, name); - if (dtor != null) { - dtor.getName().setBinding(params[i]); - if (params[i] instanceof CParameter) - ((CParameter) params[i]).addDeclaration(dtor.getName()); - } - } - } - } - - @Override + public IBinding resolveParameter(IASTName paramName) { + if (paramName.getBinding() != null) + return paramName.getBinding(); + + IBinding binding = null; + int idx = 0; + IASTNode parent = paramName.getParent(); + while (parent instanceof IASTDeclarator && !(parent instanceof ICASTKnRFunctionDeclarator)) + parent = parent.getParent(); + + ICASTKnRFunctionDeclarator fKnRDtor = null; + IASTDeclarator knrParamDtor = null; + if (parent instanceof IASTParameterDeclaration) { + IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) parent.getParent(); + IASTParameterDeclaration[] ps = fdtor.getParameters(); + for (; idx < ps.length; idx++) { + if (parent == ps[idx]) + break; + } + } else if (parent instanceof IASTSimpleDeclaration) { + //KnR: name in declaration list + fKnRDtor = (ICASTKnRFunctionDeclarator) parent.getParent(); + IASTName[] ps = fKnRDtor.getParameterNames(); + char[] n = paramName.toCharArray(); + for (; idx < ps.length; idx++) { + if (CharArrayUtils.equals(ps[idx].toCharArray(), n)) + break; + } + } else { + //KnR: name in name list + fKnRDtor = (ICASTKnRFunctionDeclarator) parent; + IASTName[] ps = fKnRDtor.getParameterNames(); + for (; idx < ps.length; idx++) { + if (ps[idx] == paramName) + break; + } + knrParamDtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, paramName); + if (knrParamDtor != null) + paramName = knrParamDtor.getName(); + } + + //create a new binding and set it for the corresponding parameter in all known defns and decls + binding = new CParameter(paramName); + IASTParameterDeclaration temp = null; + if (definition != null) { + if (definition instanceof IASTStandardFunctionDeclarator) { + IASTParameterDeclaration[] parameters = ((IASTStandardFunctionDeclarator) definition).getParameters(); + if (parameters.length > idx) { + temp = parameters[idx]; + ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding); + } + } else if (definition instanceof ICASTKnRFunctionDeclarator) { + fKnRDtor = (ICASTKnRFunctionDeclarator) definition; + IASTName[] parameterNames = fKnRDtor.getParameterNames(); + if (parameterNames.length > idx) { + IASTName n = parameterNames[idx]; + n.setBinding(binding); + IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, n); + if (dtor != null) { + dtor.getName().setBinding(binding); + } + } + } + } + if (declarators != null) { + for (IASTDeclarator dtor : declarators) { + if (dtor instanceof IASTStandardFunctionDeclarator) { + IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) dtor; + if (fdtor.getParameters().length > idx) { + temp = fdtor.getParameters()[idx]; + ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding); + } + } + } + } + return binding; + } + + protected void updateParameterBindings(IASTFunctionDeclarator fdtor) { + IParameter[] params = getParameters(); + if (fdtor instanceof IASTStandardFunctionDeclarator) { + IASTParameterDeclaration[] nps = ((IASTStandardFunctionDeclarator) fdtor).getParameters(); + if (params.length < nps.length) + return; + for (int i = 0; i < nps.length; i++) { + IASTName name = ASTQueries.findInnermostDeclarator(nps[i].getDeclarator()).getName(); + name.setBinding(params[i]); + if (params[i] instanceof CParameter) + ((CParameter) params[i]).addDeclaration(name); + } + } else { + IASTName[] ns = ((ICASTKnRFunctionDeclarator) fdtor).getParameterNames(); + if (params.length > 0 && params.length != ns.length) + return; //problem + + for (int i = 0; i < params.length; i++) { + IASTName name = ns[i]; + name.setBinding(params[i]); + IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) fdtor, name); + if (dtor != null) { + dtor.getName().setBinding(params[i]); + if (params[i] instanceof CParameter) + ((CParameter) params[i]).addDeclaration(dtor.getName()); + } + } + } + } + + @Override public boolean isStatic() { - return isStatic(true); - } + return isStatic(true); + } - @Override + @Override public boolean isStatic(boolean resolveAll) { - if (resolveAll && (bits & FULLY_RESOLVED) == 0) { - resolveAllDeclarations(); - } + if (resolveAll && (bits & FULLY_RESOLVED) == 0) { + resolveAllDeclarations(); + } return hasStorageClass(IASTDeclSpecifier.sc_static); - } + } public boolean hasStorageClass(int storage) { - IASTDeclarator dtor = definition; - IASTDeclarator[] ds = declarators; - - int i = -1; - do { - if (dtor != null) { - IASTNode parent = dtor.getParent(); - while (!(parent instanceof IASTDeclaration)) - parent = parent.getParent(); - - IASTDeclSpecifier declSpec = null; - if (parent instanceof IASTSimpleDeclaration) { - declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); - } else if (parent instanceof IASTFunctionDefinition) - declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); - - if (declSpec != null && declSpec.getStorageClass() == storage) { - return true; - } - } - - if (ds != null && ++i < ds.length) { - dtor = ds[i]; - } else { - break; - } - } while (dtor != null); - return false; - } - - @Override + IASTDeclarator dtor = definition; + IASTDeclarator[] ds = declarators; + + int i = -1; + do { + if (dtor != null) { + IASTNode parent = dtor.getParent(); + while (!(parent instanceof IASTDeclaration)) + parent = parent.getParent(); + + IASTDeclSpecifier declSpec = null; + if (parent instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTFunctionDefinition) + declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); + + if (declSpec != null && declSpec.getStorageClass() == storage) { + return true; + } + } + + if (ds != null && ++i < ds.length) { + dtor = ds[i]; + } else { + break; + } + } while (dtor != null); + return false; + } + + @Override public boolean isExtern() { - return isExtern(true); - } + return isExtern(true); + } - public boolean isExtern(boolean resolveAll) { - if (resolveAll && (bits & FULLY_RESOLVED) == 0) { - resolveAllDeclarations(); - } - return hasStorageClass(IASTDeclSpecifier.sc_extern); - } + public boolean isExtern(boolean resolveAll) { + if (resolveAll && (bits & FULLY_RESOLVED) == 0) { + resolveAllDeclarations(); + } + return hasStorageClass(IASTDeclSpecifier.sc_extern); + } - @Override + @Override public boolean isAuto() { - if ((bits & FULLY_RESOLVED) == 0) { - resolveAllDeclarations(); - } - return hasStorageClass(IASTDeclSpecifier.sc_auto); - } + if ((bits & FULLY_RESOLVED) == 0) { + resolveAllDeclarations(); + } + return hasStorageClass(IASTDeclSpecifier.sc_auto); + } - @Override + @Override public boolean isRegister() { - if ((bits & FULLY_RESOLVED) == 0) { - resolveAllDeclarations(); - } - return hasStorageClass(IASTDeclSpecifier.sc_register); - } + if ((bits & FULLY_RESOLVED) == 0) { + resolveAllDeclarations(); + } + return hasStorageClass(IASTDeclSpecifier.sc_register); + } - @Override + @Override public boolean isInline() { - if ((bits & FULLY_RESOLVED) == 0) { - resolveAllDeclarations(); - } - IASTDeclarator dtor = definition; - IASTDeclarator[] ds = declarators; - int i = -1; - do { - if (dtor != null) { - IASTNode parent = dtor.getParent(); - while (!(parent instanceof IASTDeclaration)) { - parent = parent.getParent(); - } - - IASTDeclSpecifier declSpec = null; - if (parent instanceof IASTSimpleDeclaration) { - declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); - } else if (parent instanceof IASTFunctionDefinition) { - declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); - } - - if (declSpec != null && declSpec.isInline()) - return true; - } - if (ds != null && ++i < ds.length) { - dtor = ds[i]; - } else { - break; - } - } while (dtor != null); - - return false; - } + if ((bits & FULLY_RESOLVED) == 0) { + resolveAllDeclarations(); + } + IASTDeclarator dtor = definition; + IASTDeclarator[] ds = declarators; + int i = -1; + do { + if (dtor != null) { + IASTNode parent = dtor.getParent(); + while (!(parent instanceof IASTDeclaration)) { + parent = parent.getParent(); + } + + IASTDeclSpecifier declSpec = null; + if (parent instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTFunctionDefinition) { + declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); + } + + if (declSpec != null && declSpec.isInline()) + return true; + } + if (ds != null && ++i < ds.length) { + dtor = ds[i]; + } else { + break; + } + } while (dtor != null); + + return false; + } @Override public boolean takesVarArgs() { @@ -498,17 +498,17 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu protected IASTFunctionDeclarator getPreferredDtor() { IASTFunctionDeclarator dtor = getDefinition(); - if (dtor != null) - return dtor; - - IASTDeclarator[] dtors = getDeclarations(); - if (dtors != null) { - for (IASTDeclarator declarator : dtors) { - if (declarator instanceof IASTFunctionDeclarator) - return (IASTFunctionDeclarator) declarator; - } - } - return null; + if (dtor != null) + return dtor; + + IASTDeclarator[] dtors = getDeclarations(); + if (dtors != null) { + for (IASTDeclarator declarator : dtors) { + if (declarator instanceof IASTFunctionDeclarator) + return (IASTFunctionDeclarator) declarator; + } + } + return null; } /** For debugging only. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java index 86f4b08eaf3..1d914d061d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionScope.java @@ -24,25 +24,24 @@ import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope; public class CFunctionScope extends CScope implements ICFunctionScope { public CFunctionScope(IASTFunctionDefinition function) { - super(function, EScopeKind.eLocal); + super(function, EScopeKind.eLocal); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICFunctionScope#getBinding(char[]) - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICFunctionScope#getBinding(char[]) + */ + @Override public IBinding getBinding(char[] name) { - return super.getBinding(NAMESPACE_TYPE_OTHER, name); - } - + return super.getBinding(NAMESPACE_TYPE_OTHER, name); + } @Override public IScope getBodyScope() { - IASTNode node = getPhysicalNode(); - IASTStatement statement = ((IASTFunctionDefinition) node).getBody(); - if (statement instanceof IASTCompoundStatement) { - return ((IASTCompoundStatement) statement).getScope(); - } - return null; + IASTNode node = getPhysicalNode(); + IASTStatement statement = ((IASTFunctionDefinition) node).getBody(); + if (statement instanceof IASTCompoundStatement) { + return ((IASTCompoundStatement) statement).getScope(); + } + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java index 84df107de21..37b433cb9bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java @@ -23,71 +23,72 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.core.runtime.CoreException; public class CFunctionType implements IFunctionType, ISerializableType { - private final IType[] parameters; - private final IType returnType; - private final boolean takesVarargs; + private final IType[] parameters; + private final IType returnType; + private final boolean takesVarargs; - public CFunctionType(IType returnType, IType[] parameters) { - this(returnType, parameters, false); - } + public CFunctionType(IType returnType, IType[] parameters) { + this(returnType, parameters, false); + } - public CFunctionType(IType returnType, IType[] parameters, boolean takesVarargs) { - this.returnType = returnType; - this.parameters = parameters; - this.takesVarargs = takesVarargs; - } + public CFunctionType(IType returnType, IType[] parameters, boolean takesVarargs) { + this.returnType = returnType; + this.parameters = parameters; + this.takesVarargs = takesVarargs; + } - @Override + @Override public boolean isSameType(IType o) { - if (o == this) - return true; - if (o instanceof ITypedef) - return o.isSameType(this); - if (o instanceof IFunctionType) { - IFunctionType ft = (IFunctionType) o; - IType[] fps; - fps = ft.getParameterTypes(); - if (fps.length != parameters.length) - return false; - if (!returnType.isSameType(ft.getReturnType())) - return false; - for (int i = 0; i < parameters.length; i++) { - if (!parameters[i].isSameType(fps[i])) - return false; - } - return true; - } - return false; - } + if (o == this) + return true; + if (o instanceof ITypedef) + return o.isSameType(this); + if (o instanceof IFunctionType) { + IFunctionType ft = (IFunctionType) o; + IType[] fps; + fps = ft.getParameterTypes(); + if (fps.length != parameters.length) + return false; + if (!returnType.isSameType(ft.getReturnType())) + return false; + for (int i = 0; i < parameters.length; i++) { + if (!parameters[i].isSameType(fps[i])) + return false; + } + return true; + } + return false; + } - @Override + @Override public IType getReturnType() { - return returnType; - } + return returnType; + } - @Override + @Override public IType[] getParameterTypes() { - return parameters; - } + return parameters; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { short firstBytes = ITypeMarshalBuffer.FUNCTION_TYPE; - if (takesVarargs) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (takesVarargs) + firstBytes |= ITypeMarshalBuffer.FLAG1; - int len= parameters.length & 0xffff; - int codedLen= len * ITypeMarshalBuffer.FLAG2; + int len = parameters.length & 0xffff; + int codedLen = len * ITypeMarshalBuffer.FLAG2; if (codedLen < ITypeMarshalBuffer.LAST_FLAG) { firstBytes |= codedLen; buffer.putShort(firstBytes); @@ -106,17 +107,16 @@ public class CFunctionType implements IFunctionType, ISerializableType { public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len; if (((firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0)) { - len= buffer.getInt(); + len = buffer.getInt(); } else { - len= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG - 1)) / ITypeMarshalBuffer.FLAG2; + len = (firstBytes & (ITypeMarshalBuffer.LAST_FLAG - 1)) / ITypeMarshalBuffer.FLAG2; } - IType rt= buffer.unmarshalType(); - IType[] pars= new IType[len]; + IType rt = buffer.unmarshalType(); + IType[] pars = new IType[len]; for (int i = 0; i < pars.length; i++) { - pars[i]= buffer.unmarshalType(); + pars[i] = buffer.unmarshalType(); } - return new CFunctionType(rt, pars, - (firstBytes & ITypeMarshalBuffer.FLAG1) != 0); // takes varargs + return new CFunctionType(rt, pars, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0); // takes varargs } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitFunction.java index fad8d095f05..6e2ddc8bf92 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitFunction.java @@ -27,49 +27,48 @@ import org.eclipse.cdt.core.dom.ast.IScope; */ public class CImplicitFunction extends CExternalFunction { - private IParameter[] parms=null; - private IScope scope=null; - private boolean takesVarArgs=false; - private char[] name=null; + private IParameter[] parms = null; + private IScope scope = null; + private boolean takesVarArgs = false; + private char[] name = null; - public CImplicitFunction(char[] name, IScope scope, IFunctionType type, IParameter[] parms, boolean takesVarArgs) { - super(null, null); - this.name=name; - this.scope=scope; - this.type=type; - this.parms=parms; - this.takesVarArgs=takesVarArgs; - } + public CImplicitFunction(char[] name, IScope scope, IFunctionType type, IParameter[] parms, boolean takesVarArgs) { + super(null, null); + this.name = name; + this.scope = scope; + this.type = type; + this.parms = parms; + this.takesVarArgs = takesVarArgs; + } - - @Override + @Override public IParameter[] getParameters() { - return parms; - } + return parms; + } - @Override + @Override public IFunctionType getType() { - return type; - } + return type; + } - @Override + @Override public boolean takesVarArgs() { - return takesVarArgs; - } + return takesVarArgs; + } - @Override + @Override public String getName() { - return String.valueOf(name); - } + return String.valueOf(name); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() { - return scope; - } + return scope; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitTypedef.java index 190bfd5a321..e0b7117283e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CImplicitTypedef.java @@ -26,74 +26,74 @@ import org.eclipse.cdt.core.dom.ast.IType; * @author dsteffle */ public class CImplicitTypedef extends CTypedef { - private IType type=null; - private char[] name=null; - private IScope scope=null; + private IType type = null; + private char[] name = null; + private IScope scope = null; - public CImplicitTypedef(IType type, char[] name, IScope scope) { - super(null); - this.type = type; - this.name = name; - this.scope = scope; - } + public CImplicitTypedef(IType type, char[] name, IScope scope) { + super(null); + this.type = type; + this.name = name; + this.scope = scope; + } - @Override + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public String getName() { - return String.valueOf(name); - } + return String.valueOf(name); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() { - return scope; - } + return scope; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) - */ -// public boolean isSameType(IType t) { -// if (t == this) -// return true; -// if (t instanceof ITypedef) -// try { -// IType temp = getType(); -// if (temp != null) -// return temp.isSameType(((ITypedef) t).getType()); -// return false; -// } catch (DOMException e) { -// return false; -// } -// -// IType temp; -// temp = getType(); -// if (temp != null) -// return temp.isSameType(t); -// return false; -// } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) + */ + // public boolean isSameType(IType t) { + // if (t == this) + // return true; + // if (t instanceof ITypedef) + // try { + // IType temp = getType(); + // if (temp != null) + // return temp.isSameType(((ITypedef) t).getType()); + // return false; + // } catch (DOMException e) { + // return false; + // } + // + // IType temp; + // temp = getType(); + // if (temp != null) + // return temp.isSameType(t); + // return false; + // } - /* - * (non-Javadoc) - * @see java.lang.Object#clone() - */ -// public Object clone() { -// IType t = null; -// t = (IType) super.clone(); -// return t; -// } + /* + * (non-Javadoc) + * @see java.lang.Object#clone() + */ + // public Object clone() { + // IType t = null; + // t = (IType) super.clone(); + // return t; + // } - @Override + @Override public IASTNode getPhysicalNode() { - return null; - } + return null; + } @Override public IASTNode[] getDeclarations() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java index 99c6094cbbb..92285332ead 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java @@ -93,41 +93,43 @@ public class CKnRParameter extends PlatformObject implements IParameter { return declaration; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic() + */ + @Override public boolean isStatic() { - return false; - } + return false; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() + */ + @Override public boolean isExtern() { - return false; - } + return false; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() - */ - @Override + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() + */ + @Override public boolean isAuto() { - if (declaration instanceof IASTSimpleDeclaration) - return ((IASTSimpleDeclaration) declaration).getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_auto; - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() - */ - @Override + if (declaration instanceof IASTSimpleDeclaration) + return ((IASTSimpleDeclaration) declaration).getDeclSpecifier() + .getStorageClass() == IASTDeclSpecifier.sc_auto; + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() + */ + @Override public boolean isRegister() { - if (declaration instanceof IASTSimpleDeclaration) - return ((IASTSimpleDeclaration) declaration).getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_register; - return false; - } + if (declaration instanceof IASTSimpleDeclaration) + return ((IASTSimpleDeclaration) declaration).getDeclSpecifier() + .getStorageClass() == IASTDeclSpecifier.sc_register; + return false; + } @Override public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java index 36724bb0c0b..d08b77582cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java @@ -137,7 +137,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { } @Override - public IASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) { + public IASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, + IASTExpression subscript) { return new CASTArraySubscriptExpression(arrayExpr, subscript); } @@ -150,6 +151,7 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { public IASTAttribute newAttribute(char[] name, IASTToken argumentClause) { return new CASTAttribute(name, argumentClause); } + @Override public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) { return new CASTBinaryExpression(op, expr1, expr2); @@ -184,7 +186,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { } @Override - public IASTConditionalExpression newConditionalExpession(IASTExpression condition, IASTExpression positive, IASTExpression negative) { + public IASTConditionalExpression newConditionalExpession(IASTExpression condition, IASTExpression positive, + IASTExpression negative) { return new CASTConditionalExpression(condition, positive, negative); } @@ -281,18 +284,19 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { @Deprecated public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) { CASTFunctionCallExpression result = new CASTFunctionCallExpression(idExpr, null); - if (argList == null) { - result.setArguments(null); - } else if (argList instanceof IASTExpressionList) { - result.setArguments(((IASTExpressionList) argList).getExpressions()); - } else { - result.setArguments(new IASTExpression[] {argList}); - } + if (argList == null) { + result.setArguments(null); + } else if (argList instanceof IASTExpressionList) { + result.setArguments(((IASTExpressionList) argList).getExpressions()); + } else { + result.setArguments(new IASTExpression[] { argList }); + } return result; } @Override - public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments) { + public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, + IASTInitializerClause[] arguments) { return new CASTFunctionCallExpression(idExpr, arguments); } @@ -308,7 +312,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { } @Override - public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) { + public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression( + IASTCompoundStatement compoundStatement) { return new CASTCompoundStatementExpression(compoundStatement); } @@ -339,7 +344,7 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { @Override @Deprecated - public org.eclipse.cdt.core.dom.ast.IASTInitializerExpression newInitializerExpression(IASTExpression expression) { + public org.eclipse.cdt.core.dom.ast.IASTInitializerExpression newInitializerExpression(IASTExpression expression) { return new CASTInitializerExpression(expression); } @@ -349,7 +354,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { } @Override - public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations) { + public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, + IASTDeclaration[] parameterDeclarations) { return new CASTKnRFunctionDeclarator(parameterNames, parameterDeclarations); } @@ -430,7 +436,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { @Override @Deprecated - public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) { + public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC( + IASTExpression typeofExpression) { return new GCCASTSimpleDeclSpecifier(typeofExpression); } @@ -482,7 +489,8 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { } @Override - public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) { + public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, + IASTInitializer initializer) { return new CASTTypeIdInitializerExpression(typeId, initializer); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java index 84f6f71ddc9..d123da76ddb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java @@ -25,14 +25,15 @@ import org.eclipse.core.runtime.CoreException; public class CPointerType implements ICPointerType, ITypeContainer, ISerializableType { static public final CPointerType VOID_POINTER = new CPointerType(CBasicType.VOID, 0); - static public final int IS_CONST = 1; + static public final int IS_CONST = 1; static public final int IS_RESTRICT = 1 << 1; static public final int IS_VOLATILE = 1 << 2; IType nextType = null; private int qualifiers = 0; - public CPointerType() {} + public CPointerType() { + } public CPointerType(IType next, int qualifiers) { this.nextType = next; @@ -41,20 +42,23 @@ public class CPointerType implements ICPointerType, ITypeContainer, ISerializabl @Override public boolean isSameType(IType obj) { - if (obj == this) - return true; - if (obj instanceof ITypedef) - return obj.isSameType(this); - - if (obj instanceof ICPointerType) { - ICPointerType pt = (ICPointerType) obj; - if (isConst() != pt.isConst()) return false; - if (isRestrict() != pt.isRestrict()) return false; - if (isVolatile() != pt.isVolatile()) return false; + if (obj == this) + return true; + if (obj instanceof ITypedef) + return obj.isSameType(this); + + if (obj instanceof ICPointerType) { + ICPointerType pt = (ICPointerType) obj; + if (isConst() != pt.isConst()) + return false; + if (isRestrict() != pt.isRestrict()) + return false; + if (isVolatile() != pt.isVolatile()) + return false; return pt.getType().isSameType(nextType); - } - return false; + } + return false; } @Override @@ -82,16 +86,16 @@ public class CPointerType implements ICPointerType, ITypeContainer, ISerializabl return (qualifiers & IS_VOLATILE) != 0; } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen. - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen. + } + return t; + } public void setQualifiers(int qualifiers) { this.qualifiers = qualifiers; @@ -100,16 +104,19 @@ public class CPointerType implements ICPointerType, ITypeContainer, ISerializabl @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { short firstBytes = ITypeMarshalBuffer.POINTER_TYPE; - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + if (isConst()) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) + firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) + firstBytes |= ITypeMarshalBuffer.FLAG3; buffer.putShort(firstBytes); buffer.marshalType(getType()); } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); - return new CPointerType(nested, firstBytes/ITypeMarshalBuffer.FLAG1); + IType nested = buffer.unmarshalType(); + return new CPointerType(nested, firstBytes / ITypeMarshalBuffer.FLAG1); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java index 265dd2addaa..3b1a526fc78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java @@ -47,22 +47,25 @@ public class CQualifierType implements ICQualifierType, ITypeContainer, ISeriali @Override public boolean isSameType(IType obj) { - if (obj == this) - return true; - if (obj instanceof ITypedef) - return obj.isSameType(this); + if (obj == this) + return true; + if (obj instanceof ITypedef) + return obj.isSameType(this); - if (obj instanceof ICQualifierType) { - ICQualifierType qt = (ICQualifierType) obj; - if (isConst() != qt.isConst()) return false; - if (isRestrict() != qt.isRestrict()) return false; - if (isVolatile() != qt.isVolatile()) return false; + if (obj instanceof ICQualifierType) { + ICQualifierType qt = (ICQualifierType) obj; + if (isConst() != qt.isConst()) + return false; + if (isRestrict() != qt.isRestrict()) + return false; + if (isVolatile() != qt.isVolatile()) + return false; if (type == null) return false; return type.isSameType(qt.getType()); - } - return false; + } + return false; } /* (non-Javadoc) @@ -96,32 +99,35 @@ public class CQualifierType implements ICQualifierType, ITypeContainer, ISeriali @Override public void setType(IType t) { - type = t; + type = t; } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.CVQUALIFIER_TYPE; - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + short firstBytes = ITypeMarshalBuffer.CVQUALIFIER_TYPE; + if (isConst()) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) + firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) + firstBytes |= ITypeMarshalBuffer.FLAG3; buffer.putShort(firstBytes); buffer.marshalType(getType()); } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); return new CQualifierType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java index 662d381a274..7b7ead2be1a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java @@ -85,87 +85,86 @@ public class CScope implements ICScope, IASTInternalScope { public static final int NAMESPACE_TYPE_OTHER = 1; public static final int NAMESPACE_TYPE_BOTH = 2; - private static final IndexFilter[] INDEX_FILTERS = { - new IndexFilter() { // namespace type tag - @Override - public boolean acceptBinding(IBinding binding) throws CoreException { - return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptBinding(binding) && - (binding instanceof ICompositeType || binding instanceof IEnumeration); - } - @Override - public boolean acceptLinkage(ILinkage linkage) { - return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptLinkage(linkage); - } - }, - new IndexFilter() { // namespace type other - @Override - public boolean acceptBinding(IBinding binding) throws CoreException { - return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptBinding(binding) && - !(binding instanceof ICompositeType || binding instanceof IEnumeration); - } - @Override - public boolean acceptLinkage(ILinkage linkage) { - return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptLinkage(linkage); - } - }, - // namespace type both - IndexFilter.C_DECLARED_OR_IMPLICIT - }; + private static final IndexFilter[] INDEX_FILTERS = { new IndexFilter() { // namespace type tag + @Override + public boolean acceptBinding(IBinding binding) throws CoreException { + return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptBinding(binding) + && (binding instanceof ICompositeType || binding instanceof IEnumeration); + } - private IASTNode physicalNode; - private boolean isCached; + @Override + public boolean acceptLinkage(ILinkage linkage) { + return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptLinkage(linkage); + } + }, new IndexFilter() { // namespace type other + @Override + public boolean acceptBinding(IBinding binding) throws CoreException { + return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptBinding(binding) + && !(binding instanceof ICompositeType || binding instanceof IEnumeration); + } + + @Override + public boolean acceptLinkage(ILinkage linkage) { + return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptLinkage(linkage); + } + }, + // namespace type both + IndexFilter.C_DECLARED_OR_IMPLICIT }; - private final CharArrayObjectMap<?> mapsToNameOrBinding[] = { CharArrayObjectMap.EMPTY_MAP, CharArrayObjectMap.EMPTY_MAP }; + private IASTNode physicalNode; + private boolean isCached; + + private final CharArrayObjectMap<?> mapsToNameOrBinding[] = { CharArrayObjectMap.EMPTY_MAP, + CharArrayObjectMap.EMPTY_MAP }; private final EScopeKind kind; public CScope(IASTNode physical, EScopeKind eKind) { - physicalNode = physical; - kind= eKind; - } + physicalNode = physical; + kind = eKind; + } @Override public EScopeKind getKind() { return kind; } - @Override + @Override public IScope getParent() { - return CVisitor.getContainingScope(physicalNode); - } + return CVisitor.getContainingScope(physicalNode); + } - protected static class CollectNamesAction extends ASTVisitor { - private final char[] name; - private IASTName[] result; + protected static class CollectNamesAction extends ASTVisitor { + private final char[] name; + private IASTName[] result; - CollectNamesAction(char[] n) { - name = n; - shouldVisitNames = true; - } + CollectNamesAction(char[] n) { + name = n; + shouldVisitNames = true; + } - @Override + @Override public int visit(IASTName n) { - ASTNodeProperty prop = n.getPropertyInParent(); - if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME || - prop == IASTCompositeTypeSpecifier.TYPE_NAME || - prop == IASTDeclarator.DECLARATOR_NAME) { - if (CharArrayUtils.equals(n.toCharArray(), name)) - result = ArrayUtil.append(IASTName.class, result, n); - } - - return PROCESS_CONTINUE; - } - - @Override + ASTNodeProperty prop = n.getPropertyInParent(); + if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME || prop == IASTCompositeTypeSpecifier.TYPE_NAME + || prop == IASTDeclarator.DECLARATOR_NAME) { + if (CharArrayUtils.equals(n.toCharArray(), name)) + result = ArrayUtil.append(IASTName.class, result, n); + } + + return PROCESS_CONTINUE; + } + + @Override public int visit(IASTStatement statement) { - if (statement instanceof IASTDeclarationStatement) - return PROCESS_CONTINUE; - return PROCESS_SKIP; - } + if (statement instanceof IASTDeclarationStatement) + return PROCESS_CONTINUE; + return PROCESS_SKIP; + } - public IASTName[] getNames() { - return ArrayUtil.trim(IASTName.class, result); - } - } + public IASTName[] getNames() { + return ArrayUtil.trim(IASTName.class, result); + } + } @Override public IBinding[] find(String name, IASTTranslationUnit tu) { @@ -177,24 +176,24 @@ public class CScope implements ICScope, IASTInternalScope { return CVisitor.findBindings(this, name); } - public IBinding getBinding(int namespaceType, char[] name) { - Object o= mapsToNameOrBinding[namespaceType].get(name); - if (o instanceof IBinding) - return (IBinding) o; + public IBinding getBinding(int namespaceType, char[] name) { + Object o = mapsToNameOrBinding[namespaceType].get(name); + if (o instanceof IBinding) + return (IBinding) o; - if (o instanceof IASTName) - return ((IASTName) o).resolveBinding(); + if (o instanceof IASTName) + return ((IASTName) o).resolveBinding(); - if (o instanceof IASTName[]) { - return ((IASTName[]) o)[0].resolveBinding(); - } - return null; - } + if (o instanceof IASTName[]) { + return ((IASTName[]) o)[0].resolveBinding(); + } + return null; + } - @Override + @Override public IASTNode getPhysicalNode() { - return physicalNode; - } + return physicalNode; + } @Override public void addName(IASTName name, boolean adlOnly) { @@ -208,10 +207,10 @@ public class CScope implements ICScope, IASTInternalScope { if (map == CharArrayObjectMap.EMPTY_MAP) mapsToNameOrBinding[type] = map = new CharArrayObjectMap<Object>(1); - Object o= map.get(nchars); + Object o = map.get(nchars); if (o instanceof IASTName) { if (o != name) { - map.put(nchars, new IASTName[] {(IASTName) o, name}); + map.put(nchars, new IASTName[] { (IASTName) o, name }); } } else if (o instanceof IASTName[]) { final IASTName[] names = (IASTName[]) o; @@ -221,7 +220,7 @@ public class CScope implements ICScope, IASTInternalScope { if (n == name) return; } - final IASTName[] newNames= ArrayUtil.append(IASTName.class, names, name); + final IASTName[] newNames = ArrayUtil.append(IASTName.class, names, name); if (newNames != names) map.put(nchars, newNames); } else { @@ -229,22 +228,20 @@ public class CScope implements ICScope, IASTInternalScope { } } - private int getNamespaceType(IASTName name) { - ASTNodeProperty prop = name.getPropertyInParent(); - if (prop == IASTCompositeTypeSpecifier.TYPE_NAME || - prop == IASTElaboratedTypeSpecifier.TYPE_NAME || - prop == IASTEnumerationSpecifier.ENUMERATION_NAME || - prop == CVisitor.STRING_LOOKUP_TAGS_PROPERTY) { - return NAMESPACE_TYPE_TAG; - } + private int getNamespaceType(IASTName name) { + ASTNodeProperty prop = name.getPropertyInParent(); + if (prop == IASTCompositeTypeSpecifier.TYPE_NAME || prop == IASTElaboratedTypeSpecifier.TYPE_NAME + || prop == IASTEnumerationSpecifier.ENUMERATION_NAME || prop == CVisitor.STRING_LOOKUP_TAGS_PROPERTY) { + return NAMESPACE_TYPE_TAG; + } - return NAMESPACE_TYPE_OTHER; - } + return NAMESPACE_TYPE_OTHER; + } - @Override + @Override public final IBinding getBinding(IASTName name, boolean resolve) { - return getBinding(name, resolve, IIndexFileSet.EMPTY); - } + return getBinding(name, resolve, IIndexFileSet.EMPTY); + } @Override public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) { @@ -254,48 +251,49 @@ public class CScope implements ICScope, IASTInternalScope { @Override public final IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) { char[] c = name.toCharArray(); - if (c.length == 0) { - return null; - } + if (c.length == 0) { + return null; + } - populateCache(); + populateCache(); final int type = getNamespaceType(name); Object o = mapsToNameOrBinding[type].get(name.toCharArray()); if (o instanceof IBinding) return (IBinding) o; - if (o instanceof IASTName) { - IBinding b= extractBinding((IASTName) o, resolve, name); - if (b != null) - return b; - } else if (o instanceof IASTName[]) { - for (IASTName n: ((IASTName[]) o)) { + if (o instanceof IASTName) { + IBinding b = extractBinding((IASTName) o, resolve, name); + if (b != null) + return b; + } else if (o instanceof IASTName[]) { + for (IASTName n : ((IASTName[]) o)) { if (n == null) break; - IBinding b= extractBinding(n, resolve, name); + IBinding b = extractBinding(n, resolve, name); if (b != null) return b; } - } - - IBinding result= null; - if (resolve && physicalNode instanceof IASTTranslationUnit) { - final IASTTranslationUnit tu = (IASTTranslationUnit) physicalNode; - IIndex index= tu.getIndex(); - if (index != null) { - try { - IBinding[] bindings= index.findBindings(name.toCharArray(), INDEX_FILTERS[type], new NullProgressMonitor()); - if (fileSet != null) { - bindings= fileSet.filterFileLocalBindings(bindings); - } - result= processIndexResults(name, bindings); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - } - return result; + } + + IBinding result = null; + if (resolve && physicalNode instanceof IASTTranslationUnit) { + final IASTTranslationUnit tu = (IASTTranslationUnit) physicalNode; + IIndex index = tu.getIndex(); + if (index != null) { + try { + IBinding[] bindings = index.findBindings(name.toCharArray(), INDEX_FILTERS[type], + new NullProgressMonitor()); + if (fileSet != null) { + bindings = fileSet.filterFileLocalBindings(bindings); + } + result = processIndexResults(name, bindings); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + } + return result; } private IBinding extractBinding(final IASTName candidate, boolean resolve, IASTName forName) { @@ -308,30 +306,30 @@ public class CScope implements ICScope, IASTInternalScope { return null; } - private boolean acceptDeclaredAfter(IASTName name, IASTName candidate) { - // Functions may be declared after the point of use. - if (!(candidate.getParent() instanceof IASTFunctionDeclarator)) - return false; - if (getKind() != EScopeKind.eGlobal) - return false; - final ASTNodeProperty propertyInParent = name.getPropertyInParent(); - if (propertyInParent==IASTNamedTypeSpecifier.NAME || - propertyInParent == IASTElaboratedTypeSpecifier.TYPE_NAME) { - return false; - } - IASTNode parent= name.getParent(); - while (parent != null) { - if (parent instanceof IASTSimpleDeclSpecifier) { - if (((IASTSimpleDeclSpecifier) parent).getDeclTypeExpression() != null) - return false; - } else if (parent instanceof IASTTypeIdExpression) { - if (((IASTTypeIdExpression) parent).getOperator() == IASTTypeIdExpression.op_typeof) - return false; - } - parent= parent.getParent(); - } - return true; - } + private boolean acceptDeclaredAfter(IASTName name, IASTName candidate) { + // Functions may be declared after the point of use. + if (!(candidate.getParent() instanceof IASTFunctionDeclarator)) + return false; + if (getKind() != EScopeKind.eGlobal) + return false; + final ASTNodeProperty propertyInParent = name.getPropertyInParent(); + if (propertyInParent == IASTNamedTypeSpecifier.NAME + || propertyInParent == IASTElaboratedTypeSpecifier.TYPE_NAME) { + return false; + } + IASTNode parent = name.getParent(); + while (parent != null) { + if (parent instanceof IASTSimpleDeclSpecifier) { + if (((IASTSimpleDeclSpecifier) parent).getDeclTypeExpression() != null) + return false; + } else if (parent instanceof IASTTypeIdExpression) { + if (((IASTTypeIdExpression) parent).getOperator() == IASTTypeIdExpression.op_typeof) + return false; + } + parent = parent.getParent(); + } + return true; + } /** * @deprecated Use {@link #getBindings(ScopeLookupData)} instead @@ -344,32 +342,33 @@ public class CScope implements ICScope, IASTInternalScope { @Override public final IBinding[] getBindings(ScopeLookupData lookup) { - char[] c = lookup.getLookupKey(); - Object[] obj = null; - - populateCache(); - for (CharArrayObjectMap<?> map : mapsToNameOrBinding) { - if (lookup.isPrefixLookup()) { - IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(c); - char[][] keys = map.keys(); - for (char[] key : keys) { + char[] c = lookup.getLookupKey(); + Object[] obj = null; + + populateCache(); + for (CharArrayObjectMap<?> map : mapsToNameOrBinding) { + if (lookup.isPrefixLookup()) { + IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(c); + char[][] keys = map.keys(); + for (char[] key : keys) { if (matcher.match(key)) { - obj = ArrayUtil.append(obj, map.get(key)); - } - } - } else { - obj = ArrayUtil.append(obj, map.get(c)); - } - } + obj = ArrayUtil.append(obj, map.get(key)); + } + } + } else { + obj = ArrayUtil.append(obj, map.get(c)); + } + } if (physicalNode instanceof IASTTranslationUnit) { final IASTTranslationUnit tu = (IASTTranslationUnit) physicalNode; IIndex index = tu.getIndex(); if (index != null) { try { - IBinding[] bindings = lookup.isPrefixLookup() ? - index.findBindingsForContentAssist(lookup.getLookupKey(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) : - index.findBindings(lookup.getLookupKey(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null); + IBinding[] bindings = lookup.isPrefixLookup() + ? index.findBindingsForContentAssist(lookup.getLookupKey(), true, + INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) + : index.findBindings(lookup.getLookupKey(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null); IIndexFileSet filter = lookup.getIncludedFiles(); if (filter != null) { bindings = filter.filterFileLocalBindings(bindings); @@ -381,16 +380,16 @@ public class CScope implements ICScope, IASTInternalScope { } } } - obj = ArrayUtil.trim(Object.class, obj); - IBinding[] result = null; + obj = ArrayUtil.trim(Object.class, obj); + IBinding[] result = null; for (Object element : obj) { if (element instanceof IBinding) { result = ArrayUtil.append(IBinding.class, result, (IBinding) element); } else { - IASTName n= null; + IASTName n = null; if (element instanceof IASTName) { - n= (IASTName) element; + n = (IASTName) element; } else if (element instanceof IASTName[]) { n = ((IASTName[]) element)[0]; } @@ -408,31 +407,31 @@ public class CScope implements ICScope, IASTInternalScope { } } - return ArrayUtil.trim(IBinding.class, result); - } + return ArrayUtil.trim(IBinding.class, result); + } - /** - * Index results from global scope, differ from ast results from translation unit scope. This routine - * is intended to fix results from the index to be consistent with ast scope behavior. - * @param name the name as it occurs in the ast - * @param bindings the set of candidate bindings - * @return the appropriate binding, or null if no binding is appropriate for the ast name - */ - private IBinding processIndexResults(IASTName name, IBinding[] bindings) { - if (bindings.length != 1) - return null; + /** + * Index results from global scope, differ from ast results from translation unit scope. This routine + * is intended to fix results from the index to be consistent with ast scope behavior. + * @param name the name as it occurs in the ast + * @param bindings the set of candidate bindings + * @return the appropriate binding, or null if no binding is appropriate for the ast name + */ + private IBinding processIndexResults(IASTName name, IBinding[] bindings) { + if (bindings.length != 1) + return null; - return bindings[0]; - } + return bindings[0]; + } - @Override + @Override public void populateCache() { - if (isCached) - return; + if (isCached) + return; - doPopulateCache(); - isCached= true; - } + doPopulateCache(); + isCached = true; + } @Override public void removeNestedFromCache(IASTNode container) { @@ -444,7 +443,7 @@ public class CScope implements ICScope, IASTInternalScope { private void removeFromMap(CharArrayObjectMap<?> map, IASTNode container) { for (int i = 0; i < map.size(); i++) { - Object o= map.getAt(i); + Object o = map.getAt(i); if (o instanceof IASTName) { if (container.contains((IASTNode) o)) { final char[] key = map.keyAt(i); @@ -459,16 +458,16 @@ public class CScope implements ICScope, IASTInternalScope { } private void removeFromSet(IASTName[] set, IASTNode container) { - int j= 0; + int j = 0; for (int i = 0; i < set.length; i++) { - IASTName n= set[i]; + IASTName n = set[i]; if (n == null) break; if (container.contains(n)) { - set[i]= null; + set[i] = null; } else if (i != j) { - set[j++]= n; - set[i]= null; + set[j++] = n; + set[i] = null; } } } @@ -500,7 +499,7 @@ public class CScope implements ICScope, IASTInternalScope { nodes = dtor.getParameterDeclarations(); } else if (scopeNode instanceof IASTForStatement) { final IASTForStatement forStmt = (IASTForStatement) scopeNode; - nodes= new IASTNode[] { forStmt.getInitializerStatement() }; + nodes = new IASTNode[] { forStmt.getInitializerStatement() }; } if (nodes != null) { @@ -540,32 +539,32 @@ public class CScope implements ICScope, IASTInternalScope { } public void collectNames(IASTNode node) { - if (node instanceof IASTDeclaration) { - collectNames((IASTDeclaration) node); - } else if (node instanceof IASTParameterDeclaration) { - collectNames((IASTParameterDeclaration) node); - } else if (node instanceof IASTDeclarationStatement) { + if (node instanceof IASTDeclaration) { + collectNames((IASTDeclaration) node); + } else if (node instanceof IASTParameterDeclaration) { + collectNames((IASTParameterDeclaration) node); + } else if (node instanceof IASTDeclarationStatement) { collectNames(((IASTDeclarationStatement) node).getDeclaration()); } } private void collectNames(IASTParameterDeclaration paramDecl) { - if (paramDecl == null || paramDecl instanceof IASTAmbiguousParameterDeclaration) - return; + if (paramDecl == null || paramDecl instanceof IASTAmbiguousParameterDeclaration) + return; collectNames(paramDecl.getDeclarator()); collectNames(paramDecl.getDeclSpecifier(), false); } private void collectNames(IASTDeclarator dtor) { - IASTDeclarator innermost= null; + IASTDeclarator innermost = null; while (dtor != null) { if (dtor instanceof IASTAmbiguousDeclarator) { - innermost= null; + innermost = null; break; } - innermost= dtor; - dtor= dtor.getNestedDeclarator(); + innermost = dtor; + dtor = dtor.getNestedDeclarator(); } if (innermost != null) ASTInternal.addName(this, innermost.getName()); @@ -598,7 +597,7 @@ public class CScope implements ICScope, IASTInternalScope { } } else if (declSpec instanceof ICASTCompositeTypeSpecifier) { tempName = ((ICASTCompositeTypeSpecifier) declSpec).getName(); - ASTInternal.addName(this, tempName); + ASTInternal.addName(this, tempName); // Also have to check for any nested structs. IASTDeclaration[] nested = ((ICASTCompositeTypeSpecifier) declSpec).getMembers(); @@ -611,17 +610,18 @@ public class CScope implements ICScope, IASTInternalScope { } } } else if (declSpec instanceof ICASTEnumerationSpecifier) { - ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec; - tempName = enumeration.getName(); - ASTInternal.addName(this, tempName); - - // Check enumerators. - IASTEnumerator[] list = ((ICASTEnumerationSpecifier) declSpec).getEnumerators(); - for (IASTEnumerator enumerator : list) { - if (enumerator == null) break; - tempName = enumerator.getName(); - ASTInternal.addName(this, tempName); - } + ICASTEnumerationSpecifier enumeration = (ICASTEnumerationSpecifier) declSpec; + tempName = enumeration.getName(); + ASTInternal.addName(this, tempName); + + // Check enumerators. + IASTEnumerator[] list = ((ICASTEnumerationSpecifier) declSpec).getEnumerators(); + for (IASTEnumerator enumerator : list) { + if (enumerator == null) + break; + tempName = enumerator.getName(); + ASTInternal.addName(this, tempName); + } } } @@ -643,7 +643,7 @@ public class CScope implements ICScope, IASTInternalScope { @SuppressWarnings("unchecked") CharArrayObjectMap<Object> map = (CharArrayObjectMap<Object>) mapsToNameOrBinding[type]; if (map == CharArrayObjectMap.EMPTY_MAP) - mapsToNameOrBinding[type] = map= new CharArrayObjectMap<Object>(2); + mapsToNameOrBinding[type] = map = new CharArrayObjectMap<Object>(2); map.put(binding.getNameCharArray(), binding); } @@ -653,6 +653,6 @@ public class CScope implements ICScope, IASTInternalScope { * However, we do not clear any names in order not to loose bindings. */ public void markAsUncached() { - isCached= false; + isCached = false; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java index 4de1940f44b..69bf58513b9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayMap; public class CStructMapper { private class Visitor extends ASTVisitor { Visitor() { - shouldVisitDeclarations= true; + shouldVisitDeclarations = true; } @Override @@ -38,7 +38,7 @@ public class CStructMapper { if (declaration instanceof IASTSimpleDeclaration) { IASTDeclSpecifier declspec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); if (declspec instanceof IASTCompositeTypeSpecifier) { - IASTCompositeTypeSpecifier cts= (IASTCompositeTypeSpecifier) declspec; + IASTCompositeTypeSpecifier cts = (IASTCompositeTypeSpecifier) declspec; final IASTName name = cts.getName(); final char[] nameChars = name.toCharArray(); if (nameChars.length > 0) { @@ -55,17 +55,17 @@ public class CStructMapper { protected CharArrayMap<IASTName> fStructs; public CStructMapper(IASTTranslationUnit tu) { - fTranslationUnit= tu; + fTranslationUnit = tu; } public ICompositeType mapToAST(ICompositeType type) { if (fStructs == null) { - fStructs= new CharArrayMap<IASTName>(); + fStructs = new CharArrayMap<IASTName>(); fTranslationUnit.accept(new Visitor()); } - IASTName name= fStructs.get(type.getNameCharArray()); + IASTName name = fStructs.get(type.getNameCharArray()); if (name != null) { - IBinding b= name.resolveBinding(); + IBinding b = name.resolveBinding(); if (b instanceof ICompositeType) { final ICompositeType mapped = (ICompositeType) b; if (mapped.isSameType(type)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index e64459efafa..f1c725d8b47 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -135,8 +135,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte @Override public IScope getScope() throws DOMException { - IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ((definition != null) ? - (IASTNode) definition.getParent() : declarations[0].getParent()); + IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ((definition != null) ? (IASTNode) definition.getParent() + : declarations[0].getParent()); IScope scope = CVisitor.getContainingScope(declSpec); while (scope instanceof ICCompositeTypeScope) { scope = scope.getParent(); @@ -187,8 +187,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte public IField findField(String name) { IScope scope = getCompositeScope(); if (scope == null) { - return new CField.CFieldProblem(this, declarations[0], - IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray()); + return new CField.CFieldProblem(this, declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, + getNameCharArray()); } final CASTName astName = new CASTName(name.toCharArray()); @@ -202,9 +202,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte @Override public int getKey() { - return definition != null ? - ((IASTCompositeTypeSpecifier) definition.getParent()).getKey() : - ((IASTElaboratedTypeSpecifier) declarations[0].getParent()).getKind(); + return definition != null ? ((IASTCompositeTypeSpecifier) definition.getParent()).getKey() + : ((IASTElaboratedTypeSpecifier) declarations[0].getParent()).getKind(); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java index 7d1a26db6ed..ab360d22f71 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java @@ -38,10 +38,10 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer this.name = name; } - @Override + @Override public IASTNode getPhysicalNode() { - return name; - } + return name; + } @Override public IType getType() { @@ -52,7 +52,7 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer @Override public void setType(IType t) { - type = t; + type = t; } @Override @@ -62,7 +62,7 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer @Override public char[] getNameCharArray() { - return name.toCharArray(); + return name.toCharArray(); } @Override @@ -71,33 +71,33 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer return CVisitor.getContainingScope(declarator.getParent()); } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } - - @Override + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } + + @Override public boolean isSameType(IType t) { - if (t == this) - return true; - if (t instanceof ITypedef) { + if (t == this) + return true; + if (t instanceof ITypedef) { IType temp = getType(); if (temp != null) - return temp.isSameType(((ITypedef) t).getType()); + return temp.isSameType(((ITypedef) t).getType()); return false; } - IType temp = getType(); - if (temp != null) - return temp.isSameType(t); - return false; - } + IType temp = getType(); + if (temp != null) + return temp.isSameType(t); + return false; + } @Override public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java index f337a3acd2e..576190d1363 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java @@ -187,8 +187,7 @@ public class CVariable extends PlatformObject implements ICInternalBinding, IVar if (dtor != null) { IASTInitializer init = dtor.getInitializer(); if (init instanceof IASTEqualsInitializer) { - final IASTInitializerClause initClause = ((IASTEqualsInitializer) init) - .getInitializerClause(); + final IASTInitializerClause initClause = ((IASTEqualsInitializer) init).getInitializerClause(); if (initClause instanceof IASTExpression) { return ValueFactory.create((IASTExpression) initClause); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariableReadWriteFlags.java index 2a18546f51d..62f8baa7a67 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariableReadWriteFlags.java @@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.VariableReadWriteFlags; * with the variable. */ public final class CVariableReadWriteFlags extends VariableReadWriteFlags { - private static CVariableReadWriteFlags INSTANCE= new CVariableReadWriteFlags(); + private static CVariableReadWriteFlags INSTANCE = new CVariableReadWriteFlags(); public static int getReadWriteFlags(IASTName variable) { return INSTANCE.rwAnyNode(variable, 0); @@ -39,9 +39,9 @@ public final class CVariableReadWriteFlags extends VariableReadWriteFlags { @Override protected int rwAnyNode(IASTNode node, int indirection) { - final IASTNode parent= node.getParent(); + final IASTNode parent = node.getParent(); if (parent instanceof ICASTFieldDesignator) { - return WRITE; // node is initialized via designated initializer + return WRITE; // node is initialized via designated initializer } return super.rwAnyNode(node, indirection); } @@ -76,7 +76,7 @@ public final class CVariableReadWriteFlags extends VariableReadWriteFlags { return READ; } while (indirection > 0 && (type instanceof IPointerType)) { - type= ((IPointerType) type).getType(); + type = ((IPointerType) type).getType(); indirection--; } if (indirection == 0) { @@ -86,6 +86,6 @@ public final class CVariableReadWriteFlags extends VariableReadWriteFlags { return ((IPointerType) type).isConst() ? READ : READ | WRITE; } } - return READ | WRITE; // fallback + return READ | WRITE; // fallback } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 43c6a500df0..cfd4de9336d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -121,14 +121,15 @@ import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory; * Collection of methods to find information in an AST. */ public class CVisitor extends ASTQueries { - private static final CBasicType UNSIGNED_LONG_INT = new CBasicType(Kind.eInt, IBasicType.IS_LONG | IBasicType.IS_UNSIGNED); + private static final CBasicType UNSIGNED_LONG_INT = new CBasicType(Kind.eInt, + IBasicType.IS_LONG | IBasicType.IS_UNSIGNED); // Flags for createType(). - + // Given a function declarator, compute only the return type rather than // the entire function type. public static final int ONLY_RETURN_TYPE = 0x1; - + public static class CollectProblemsAction extends ASTVisitor { { shouldVisitDeclarations = true; @@ -147,27 +148,27 @@ public class CVisitor extends ASTQueries { private void addProblem(IASTProblem problem) { if (problems.length == numFound) { // if the found array is full, then double the array - IASTProblem[] old = problems; - problems = new IASTProblem[old.length * 2]; - for (int j = 0; j < old.length; ++j) - problems[j] = old[j]; - } + IASTProblem[] old = problems; + problems = new IASTProblem[old.length * 2]; + for (int j = 0; j < old.length; ++j) + problems[j] = old[j]; + } problems[numFound++] = problem; } - private IASTProblem[] removeNullFromProblems() { - if (problems[problems.length - 1] != null) { // if the last element in the list is not null then return the list + private IASTProblem[] removeNullFromProblems() { + if (problems[problems.length - 1] != null) { // if the last element in the list is not null then return the list return problems; } else if (problems[0] == null) { // if the first element in the list is null, then return empty list return new IASTProblem[0]; } IASTProblem[] results = new IASTProblem[numFound]; - for (int i=0; i<results.length; i++) + for (int i = 0; i < results.length; i++) results[i] = problems[i]; return results; - } + } public IASTProblem[] getProblems() { return removeNullFromProblems(); @@ -234,27 +235,27 @@ public class CVisitor extends ASTQueries { private void addName(IASTName name) { if (declsFound.length == numFound) { // if the found array is full, then double the array - IASTName[] old = declsFound; - declsFound = new IASTName[old.length * 2]; - for (int j = 0; j < old.length; ++j) - declsFound[j] = old[j]; - } + IASTName[] old = declsFound; + declsFound = new IASTName[old.length * 2]; + for (int j = 0; j < old.length; ++j) + declsFound[j] = old[j]; + } declsFound[numFound++] = name; } - private IASTName[] removeNullFromNames() { - if (declsFound[declsFound.length - 1] != null) { // if the last element in the list is not null then return the list + private IASTName[] removeNullFromNames() { + if (declsFound[declsFound.length - 1] != null) { // if the last element in the list is not null then return the list return declsFound; } else if (declsFound[0] == null) { // if the first element in the list is null, then return empty list return new IASTName[0]; } IASTName[] results = new IASTName[numFound]; - for (int i= 0; i < results.length; i++) + for (int i = 0; i < results.length; i++) results[i] = declsFound[i]; return results; - } + } public IASTName[] getDeclarationNames() { return removeNullFromNames(); @@ -272,7 +273,8 @@ public class CVisitor extends ASTQueries { public int visit(IASTDeclarator declarator) { //GCC allows declarations in expressions, so we have to continue from the //declarator in case there is something in the initializer expression - if (declarator == null || declarator.getName() == null || declarator.getName().toCharArray().length == 0) return PROCESS_CONTINUE; + if (declarator == null || declarator.getName() == null || declarator.getName().toCharArray().length == 0) + return PROCESS_CONTINUE; //if the binding is something not declared in a declarator, continue if (binding instanceof ICompositeType) @@ -291,8 +293,8 @@ public class CVisitor extends ASTQueries { } } else if (parent instanceof IASTSimpleDeclaration) { // prototype parameter with no identifier isn't a declaration of the K&R C parameter -// if (binding instanceof CKnRParameter && declarator.getName().toCharArray().length == 0) -// return PROCESS_CONTINUE; + // if (binding instanceof CKnRParameter && declarator.getName().toCharArray().length == 0) + // return PROCESS_CONTINUE; if ((declarator.getName() != null && declarator.getName().resolveBinding() == binding)) { addName(declarator.getName()); @@ -316,11 +318,11 @@ public class CVisitor extends ASTQueries { return PROCESS_CONTINUE; //if the binding isn't declared in a decl spec, skip it - if (!(binding instanceof ICompositeType) && !(binding instanceof IEnumeration)) + if (!(binding instanceof ICompositeType) && !(binding instanceof IEnumeration)) return PROCESS_CONTINUE; if (binding instanceof ICompositeType && declSpec instanceof IASTCompositeTypeSpecifier) { - if (((IASTCompositeTypeSpecifier) declSpec).getName().resolveBinding() == binding) { + if (((IASTCompositeTypeSpecifier) declSpec).getName().resolveBinding() == binding) { compositeTypeDeclared = true; addName(((IASTCompositeTypeSpecifier) declSpec).getName()); } @@ -330,12 +332,13 @@ public class CVisitor extends ASTQueries { addName(((IASTEnumerationSpecifier) declSpec).getName()); } } else if (declSpec instanceof IASTElaboratedTypeSpecifier) { - if (compositeTypeDeclared) { - IASTNode parent = declSpec.getParent(); - if (!(parent instanceof IASTSimpleDeclaration) || ((IASTSimpleDeclaration) parent).getDeclarators().length > 0) { - return PROCESS_CONTINUE; - } - } + if (compositeTypeDeclared) { + IASTNode parent = declSpec.getParent(); + if (!(parent instanceof IASTSimpleDeclaration) + || ((IASTSimpleDeclaration) parent).getDeclarators().length > 0) { + return PROCESS_CONTINUE; + } + } if (((IASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding() == binding) { compositeTypeDeclared = true; addName(((IASTElaboratedTypeSpecifier) declSpec).getName()); @@ -379,9 +382,9 @@ public class CVisitor extends ASTQueries { private int idx = 0; private int kind; - private static final int KIND_LABEL = 1; + private static final int KIND_LABEL = 1; private static final int KIND_OBJ_FN = 2; - private static final int KIND_TYPE = 3; + private static final int KIND_TYPE = 3; public CollectReferencesAction(IBinding binding) { this.binding = binding; @@ -390,9 +393,8 @@ public class CVisitor extends ASTQueries { shouldVisitNames = true; if (binding instanceof ILabel) { kind = KIND_LABEL; - } else if (binding instanceof ICompositeType || - binding instanceof ITypedef || - binding instanceof IEnumeration) { + } else if (binding instanceof ICompositeType || binding instanceof ITypedef + || binding instanceof IEnumeration) { kind = KIND_TYPE; } else { kind = KIND_OBJ_FN; @@ -412,16 +414,15 @@ public class CVisitor extends ASTQueries { break; } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { IASTNode p = name.getParent().getParent(); - if (!(p instanceof IASTSimpleDeclaration) || - ((IASTSimpleDeclaration) p).getDeclarators().length > 0) { + if (!(p instanceof IASTSimpleDeclaration) + || ((IASTSimpleDeclaration) p).getDeclarators().length > 0) { break; } } return PROCESS_CONTINUE; case KIND_OBJ_FN: - if (prop == IASTIdExpression.ID_NAME || - prop == IASTFieldReference.FIELD_NAME || - prop == ICASTFieldDesignator.FIELD_NAME) { + if (prop == IASTIdExpression.ID_NAME || prop == IASTFieldReference.FIELD_NAME + || prop == ICASTFieldDesignator.FIELD_NAME) { break; } return PROCESS_CONTINUE; @@ -458,8 +459,10 @@ public class CVisitor extends ASTQueries { } } - protected static final ASTNodeProperty STRING_LOOKUP_PROPERTY = new ASTNodeProperty("CVisitor.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$ - protected static final ASTNodeProperty STRING_LOOKUP_TAGS_PROPERTY = new ASTNodeProperty("CVisitor.STRING_LOOKUP_TAGS_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$ + protected static final ASTNodeProperty STRING_LOOKUP_PROPERTY = new ASTNodeProperty( + "CVisitor.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$ + protected static final ASTNodeProperty STRING_LOOKUP_TAGS_PROPERTY = new ASTNodeProperty( + "CVisitor.STRING_LOOKUP_TAGS_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$ private static final String SIZE_T = "size_t"; //$NON-NLS-1$ private static final String PTRDIFF_T = "ptrdiff_t"; //$NON-NLS-1$ public static final String EMPTY_STRING = ""; //$NON-NLS-1$ @@ -487,13 +490,13 @@ public class CVisitor extends ASTQueries { } else if (parent instanceof ICASTElaboratedTypeSpecifier) { binding = createBinding((ICASTElaboratedTypeSpecifier) parent); } else if (parent instanceof IASTGotoStatement) { - binding = resolveBinding((IASTGotoStatement) parent); + binding = resolveBinding((IASTGotoStatement) parent); } else if (parent instanceof IASTLabelStatement) { binding = createBinding((IASTLabelStatement) parent); } else if (parent instanceof ICASTEnumerationSpecifier) { - binding = createBinding((ICASTEnumerationSpecifier) parent); + binding = createBinding((ICASTEnumerationSpecifier) parent); } else if (parent instanceof IASTEnumerator) { - binding = createBinding((IASTEnumerator) parent); + binding = createBinding((IASTEnumerator) parent); } else if (parent instanceof ICASTFieldDesignator) { binding = resolveBinding(parent); } @@ -501,95 +504,95 @@ public class CVisitor extends ASTQueries { } private static IBinding createBinding(ICASTEnumerationSpecifier enumeration) { - IASTName name = enumeration.getName(); - IScope scope = getContainingScope(enumeration); - IBinding binding= null; - if (scope != null) { - binding = scope.getBinding(name, false); - } - if (binding != null && !(binding instanceof IIndexBinding) && name.isActive()) { - if (binding instanceof IEnumeration) { - if (binding instanceof CEnumeration) { - ((CEnumeration) binding).addDefinition(name); - } - } else { - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD, name.toCharArray()); - } - } else { - binding = new CEnumeration(name); - ASTInternal.addName(scope, name); - } - return binding; + IASTName name = enumeration.getName(); + IScope scope = getContainingScope(enumeration); + IBinding binding = null; + if (scope != null) { + binding = scope.getBinding(name, false); + } + if (binding != null && !(binding instanceof IIndexBinding) && name.isActive()) { + if (binding instanceof IEnumeration) { + if (binding instanceof CEnumeration) { + ((CEnumeration) binding).addDefinition(name); + } + } else { + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD, name.toCharArray()); + } + } else { + binding = new CEnumeration(name); + ASTInternal.addName(scope, name); + } + return binding; } private static IBinding createBinding(IASTEnumerator enumerator) { - IEnumerator binding = new CEnumerator(enumerator); - try { - ASTInternal.addName(binding.getScope(), enumerator.getName()); - } catch (DOMException e) { - } - return binding; + IEnumerator binding = new CEnumerator(enumerator); + try { + ASTInternal.addName(binding.getScope(), enumerator.getName()); + } catch (DOMException e) { + } + return binding; } private static IBinding resolveBinding(IASTGotoStatement statement) { - return resolveLabel(statement.getName()); + return resolveLabel(statement.getName()); } private static IBinding createBinding(IASTLabelStatement statement) { - IASTName name = statement.getName(); - IBinding binding = new CLabel(name); - try { - IScope scope = binding.getScope(); - if (scope instanceof ICFunctionScope) - ASTInternal.addName(binding.getScope(), name); - } catch (DOMException e) { - } - return binding; + IASTName name = statement.getName(); + IBinding binding = new CLabel(name); + try { + IScope scope = binding.getScope(); + if (scope instanceof ICFunctionScope) + ASTInternal.addName(binding.getScope(), name); + } catch (DOMException e) { + } + return binding; } private static IBinding createBinding(ICASTElaboratedTypeSpecifier elabTypeSpec) { IASTNode parent = elabTypeSpec.getParent(); IASTName name = elabTypeSpec.getName(); if (parent instanceof IASTDeclaration) { - IBinding binding= null; - IScope insertIntoScope= null; + IBinding binding = null; + IScope insertIntoScope = null; if (parent instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration) parent).getDeclarators().length == 0) { - IScope scope= getContainingScope(elabTypeSpec); + IScope scope = getContainingScope(elabTypeSpec); try { while (scope instanceof ICCompositeTypeScope) - scope= scope.getParent(); + scope = scope.getParent(); - binding= scope.getBinding(name, false); + binding = scope.getBinding(name, false); } catch (DOMException e) { } if (binding != null && name.isActive()) { if (binding instanceof CEnumeration) { - ((CEnumeration) binding).addDeclaration(name); - } else if (binding instanceof CStructure) { - ((CStructure) binding).addDeclaration(name); - } + ((CEnumeration) binding).addDeclaration(name); + } else if (binding instanceof CStructure) { + ((CStructure) binding).addDeclaration(name); + } } } else { - binding= resolveBinding(elabTypeSpec); + binding = resolveBinding(elabTypeSpec); if (binding == null) { - insertIntoScope= elabTypeSpec.getTranslationUnit().getScope(); - binding= insertIntoScope.getBinding(name, false); + insertIntoScope = elabTypeSpec.getTranslationUnit().getScope(); + binding = insertIntoScope.getBinding(name, false); if (binding != null && name.isActive()) { if (binding instanceof CEnumeration) { - ((CEnumeration) binding).addDeclaration(name); - } else if (binding instanceof CStructure) { - ((CStructure) binding).addDeclaration(name); - } + ((CEnumeration) binding).addDeclaration(name); + } else if (binding instanceof CStructure) { + ((CStructure) binding).addDeclaration(name); + } } } } if (binding == null) { if (elabTypeSpec.getKind() == IASTElaboratedTypeSpecifier.k_enum) { - binding = new CEnumeration(name); - } else { - binding = new CStructure(name); - } + binding = new CEnumeration(name); + } else { + binding = new CStructure(name); + } if (insertIntoScope != null) { ASTInternal.addName(insertIntoScope, name); } @@ -615,26 +618,26 @@ public class CVisitor extends ASTQueries { boolean isPointerDeref = fieldReference.isPointerDereference(); IType type = fieldOwner.getExpressionType(); - while (type != null && type instanceof ITypeContainer) { - if (type instanceof IPointerType) { - if (isPointerDeref) { - isPointerDeref = false; - } else { - return null; - } - } - type = ((ITypeContainer) type).getType(); - } + while (type != null && type instanceof ITypeContainer) { + if (type instanceof IPointerType) { + if (isPointerDeref) { + isPointerDeref = false; + } else { + return null; + } + } + type = ((ITypeContainer) type).getType(); + } if (type != null && type instanceof ICompositeType) { ICompositeType ct = (ICompositeType) type; if (ct instanceof IIndexBinding) { - ct= ((CASTTranslationUnit) fieldReference.getTranslationUnit()).mapToASTType(ct); + ct = ((CASTTranslationUnit) fieldReference.getTranslationUnit()).mapToASTType(ct); + } + if (prefix) { + char[] p = fieldReference.getFieldName().toCharArray(); + return findFieldsByPrefix(ct, p); } - if (prefix) { - char[] p = fieldReference.getFieldName().toCharArray(); - return findFieldsByPrefix(ct, p); - } return ct.findField(fieldReference.getFieldName().toString()); } return null; @@ -646,8 +649,8 @@ public class CVisitor extends ASTQueries { IField[] fields = ct.getFields(); for (IField field : fields) { if (matcher.match(field.getNameCharArray())) { - result = ArrayUtil.append(IBinding.class, result, field); - } + result = ArrayUtil.append(IBinding.class, result, field); + } } return ArrayUtil.trim(IBinding.class, result); } @@ -657,8 +660,8 @@ public class CVisitor extends ASTQueries { IBinding[] bs = scope.find(PTRDIFF_T, expr.getTranslationUnit()); for (IBinding b : bs) { if (b instanceof IType) { - if (!(b instanceof ICInternalBinding) || - CVisitor.declaredBefore(((ICInternalBinding) b).getPhysicalNode(), expr)) { + if (!(b instanceof ICInternalBinding) + || CVisitor.declaredBefore(((ICInternalBinding) b).getPhysicalNode(), expr)) { return (IType) b; } } @@ -668,13 +671,13 @@ public class CVisitor extends ASTQueries { } static IType get_SIZE_T(IASTExpression expr) { - IASTTranslationUnit tu= expr.getTranslationUnit(); + IASTTranslationUnit tu = expr.getTranslationUnit(); if (tu != null) { IBinding[] bs = tu.getScope().find(SIZE_T, expr.getTranslationUnit()); for (IBinding b : bs) { if (b instanceof IType) { - if (!(b instanceof ICInternalBinding) || - CVisitor.declaredBefore(((ICInternalBinding) b).getPhysicalNode(), expr)) { + if (!(b instanceof ICInternalBinding) + || CVisitor.declaredBefore(((ICInternalBinding) b).getPhysicalNode(), expr)) { return (IType) b; } } @@ -685,7 +688,7 @@ public class CVisitor extends ASTQueries { static IType unwrapTypedefs(IType type) { while (type instanceof ITypedef) { - type= ((ITypedef) type).getType(); + type = ((ITypedef) type).getType(); } return type; } @@ -708,86 +711,90 @@ public class CVisitor extends ASTQueries { IBinding binding = null; if (declarator instanceof ICASTKnRFunctionDeclarator) { if (CharArrayUtils.equals(declarator.getName().toCharArray(), name.toCharArray())) { - IScope scope= CVisitor.getContainingScope(declarator); + IScope scope = CVisitor.getContainingScope(declarator); binding = scope.getBinding(name, false); if (binding != null && !(binding instanceof IIndexBinding) && name.isActive()) { - if (binding instanceof ICInternalFunction) { - ((ICInternalFunction) binding).addDeclarator(declarator); - } else { - binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD, name.toCharArray()); - } + if (binding instanceof ICInternalFunction) { + ((ICInternalFunction) binding).addDeclarator(declarator); + } else { + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD, + name.toCharArray()); + } } else { binding = createBinding(declarator); } } else { // createBinding for one of the ICASTKnRFunctionDeclarator's parameterNames - IBinding f = declarator.getName().resolveBinding(); - if (f instanceof CFunction) { - binding = ((CFunction) f).resolveParameter(name); - } + IBinding f = declarator.getName().resolveBinding(); + if (f instanceof CFunction) { + binding = ((CFunction) f).resolveParameter(name); + } } } else { - binding = createBinding(declarator); + binding = createBinding(declarator); } return binding; } private static IBinding createBinding(IASTDeclarator declarator) { IASTNode parent = ASTQueries.findOutermostDeclarator(declarator).getParent(); - declarator= ASTQueries.findInnermostDeclarator(declarator); - IASTDeclarator typeRelevant= ASTQueries.findTypeRelevantDeclarator(declarator); + declarator = ASTQueries.findInnermostDeclarator(declarator); + IASTDeclarator typeRelevant = ASTQueries.findTypeRelevantDeclarator(declarator); - IScope scope= getContainingScope(parent); + IScope scope = getContainingScope(parent); ASTNodeProperty prop = parent.getPropertyInParent(); if (prop == IASTDeclarationStatement.DECLARATION) { - //implicit scope, see 6.8.4-3 - prop = parent.getParent().getPropertyInParent(); - if (prop != IASTCompoundStatement.NESTED_STATEMENT) - scope = null; + //implicit scope, see 6.8.4-3 + prop = parent.getParent().getPropertyInParent(); + if (prop != IASTCompoundStatement.NESTED_STATEMENT) + scope = null; } IASTName name = declarator.getName(); IBinding binding = (scope != null) ? scope.getBinding(name, false) : null; - boolean isFunction= false; - if (parent instanceof IASTParameterDeclaration || parent.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER) { - IASTDeclarator fdtor = (IASTDeclarator) parent.getParent(); + boolean isFunction = false; + if (parent instanceof IASTParameterDeclaration + || parent.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER) { + IASTDeclarator fdtor = (IASTDeclarator) parent.getParent(); // Create parameter bindings only if the declarator declares a function - if (ASTQueries.findTypeRelevantDeclarator(fdtor) == fdtor) { - IASTName n = ASTQueries.findInnermostDeclarator(fdtor).getName(); - IBinding temp = n.resolveBinding(); - if (temp != null && temp instanceof CFunction) { - binding = ((CFunction) temp).resolveParameter(name); - } else if (temp instanceof IFunction) { - //problems with the function, still create binding for the parameter - binding = new CParameter(name); - } - return binding; - } + if (ASTQueries.findTypeRelevantDeclarator(fdtor) == fdtor) { + IASTName n = ASTQueries.findInnermostDeclarator(fdtor).getName(); + IBinding temp = n.resolveBinding(); + if (temp != null && temp instanceof CFunction) { + binding = ((CFunction) temp).resolveParameter(name); + } else if (temp instanceof IFunction) { + //problems with the function, still create binding for the parameter + binding = new CParameter(name); + } + return binding; + } } else if (parent instanceof IASTFunctionDefinition) { - isFunction= true; + isFunction = true; } else if (parent instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; if (simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { binding = new CTypedef(name); } else { - isFunction= typeRelevant instanceof IASTFunctionDeclarator; + isFunction = typeRelevant instanceof IASTFunctionDeclarator; if (!isFunction) { IType t1 = createType(declarator), t2 = null; if (CVisitor.unwrapTypedefs(t1) instanceof IFunctionType) { - isFunction= true; + isFunction = true; } else { if (binding != null && !(binding instanceof IIndexBinding) && name.isActive()) { if (binding instanceof IParameter) { - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray()); + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, + name.toCharArray()); } else if (binding instanceof IVariable) { t2 = ((IVariable) binding).getType(); - if (t1 != null && t2 != null && - (areArraysOfTheSameElementType(t1, t2) || t1.isSameType(t2))) { + if (t1 != null && t2 != null + && (areArraysOfTheSameElementType(t1, t2) || t1.isSameType(t2))) { if (binding instanceof CVariable) ((CVariable) binding).addDeclaration(name); } else { - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray()); + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, + name.toCharArray()); } } } else if (simpleDecl.getParent() instanceof ICASTCompositeTypeSpecifier) { @@ -822,9 +829,9 @@ public class CVisitor extends ASTQueries { IBinding binding = null; IASTName name = compositeTypeSpec.getName(); try { - scope = getContainingScope(compositeTypeSpec); + scope = getContainingScope(compositeTypeSpec); while (scope instanceof ICCompositeTypeScope) - scope = scope.getParent(); + scope = scope.getParent(); if (scope != null) { binding = scope.getBinding(name, false); @@ -836,7 +843,7 @@ public class CVisitor extends ASTQueries { } } catch (DOMException e) { } - return new CStructure(name); + return new CStructure(name); } protected static IBinding resolveBinding(IASTNode node) { @@ -853,13 +860,13 @@ public class CVisitor extends ASTQueries { IScope scope = getContainingScope(node); IBinding binding = lookup(scope, ((IASTIdExpression) node).getName()); if (binding instanceof IType && !(binding instanceof IProblemBinding)) { - return new ProblemBinding(node, IProblemBinding.SEMANTIC_INVALID_TYPE, - binding.getNameCharArray(), new IBinding[] { binding }); + return new ProblemBinding(node, IProblemBinding.SEMANTIC_INVALID_TYPE, binding.getNameCharArray(), + new IBinding[] { binding }); } return binding; } else if (node instanceof ICASTTypedefNameSpecifier) { IScope scope = getContainingScope(node); - IASTName name= ((ICASTTypedefNameSpecifier) node).getName(); + IASTName name = ((ICASTTypedefNameSpecifier) node).getName(); IBinding binding = lookup(scope, name); if (binding == null) return new ProblemBinding(node, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray()); @@ -889,20 +896,20 @@ public class CVisitor extends ASTQueries { if (binding instanceof IType) { return binding; } else if (binding != null) { - return new ProblemBinding(node, IProblemBinding.SEMANTIC_INVALID_TYPE, - binding.getNameCharArray(), new IBinding[] { binding }); - } + return new ProblemBinding(node, IProblemBinding.SEMANTIC_INVALID_TYPE, binding.getNameCharArray(), + new IBinding[] { binding }); + } return null; } } else if (node instanceof ICASTFieldDesignator) { IASTNode blockItem = getContainingBlockItem(node); - if ((blockItem instanceof IASTSimpleDeclaration || - (blockItem instanceof IASTDeclarationStatement && ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration))) { + if ((blockItem instanceof IASTSimpleDeclaration || (blockItem instanceof IASTDeclarationStatement + && ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration))) { IASTSimpleDeclaration simpleDecl = null; - if (blockItem instanceof IASTDeclarationStatement && - ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration) { - simpleDecl = (IASTSimpleDeclaration)((IASTDeclarationStatement) blockItem).getDeclaration(); + if (blockItem instanceof IASTDeclarationStatement + && ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration) { + simpleDecl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) blockItem).getDeclaration(); } else if (blockItem instanceof IASTSimpleDeclaration) { simpleDecl = (IASTSimpleDeclaration) blockItem; } @@ -912,15 +919,17 @@ public class CVisitor extends ASTQueries { if (simpleDecl.getDeclSpecifier() instanceof IASTNamedTypeSpecifier) struct = ((IASTNamedTypeSpecifier) simpleDecl.getDeclSpecifier()).getName().resolveBinding(); else if (simpleDecl.getDeclSpecifier() instanceof IASTElaboratedTypeSpecifier) - struct = ((IASTElaboratedTypeSpecifier) simpleDecl.getDeclSpecifier()).getName().resolveBinding(); + struct = ((IASTElaboratedTypeSpecifier) simpleDecl.getDeclSpecifier()).getName() + .resolveBinding(); else if (simpleDecl.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) - struct = ((IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier()).getName().resolveBinding(); + struct = ((IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier()).getName() + .resolveBinding(); if (struct instanceof ICompositeType) { return ((ICompositeType) struct).findField(((ICASTFieldDesignator) node).getName().toString()); } else if (struct instanceof ITypeContainer) { IType type; - type = ((ITypeContainer) struct).getType(); + type = ((ITypeContainer) struct).getType(); while (type instanceof ITypeContainer && !(type instanceof CStructure)) { type = ((ITypeContainer) type).getType(); } @@ -938,79 +947,80 @@ public class CVisitor extends ASTQueries { * May return <code>null</code>, e.g. for parameter names in function-prototypes. */ public static IScope getContainingScope(IASTNode node) { - if (node == null) + if (node == null) return null; while (node != null) { - if (node instanceof IASTDeclaration) { + if (node instanceof IASTDeclaration) { IASTNode parent = node.getParent(); if (parent instanceof IASTTranslationUnit) { return ((IASTTranslationUnit) parent).getScope(); } else if (parent instanceof IASTDeclarationStatement) { return getContainingScope((IASTStatement) parent); } else if (parent instanceof IASTForStatement) { - return ((IASTForStatement) parent).getScope(); + return ((IASTForStatement) parent).getScope(); } else if (parent instanceof IASTCompositeTypeSpecifier) { - return ((IASTCompositeTypeSpecifier) parent).getScope(); + return ((IASTCompositeTypeSpecifier) parent).getScope(); } else if (parent instanceof ICASTKnRFunctionDeclarator) { parent = ((IASTDeclarator) parent).getParent(); if (parent instanceof IASTFunctionDefinition) { - return ((IASTCompoundStatement)((IASTFunctionDefinition) parent).getBody()).getScope(); + return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent).getBody()).getScope(); } } - } else if (node instanceof IASTStatement) { - return getContainingScope((IASTStatement) node); - } else if (node instanceof IASTExpression) { + } else if (node instanceof IASTStatement) { + return getContainingScope((IASTStatement) node); + } else if (node instanceof IASTExpression) { IASTNode parent = node.getParent(); if (parent instanceof IASTForStatement) { - return ((IASTForStatement) parent).getScope(); + return ((IASTForStatement) parent).getScope(); } - } else if (node instanceof IASTParameterDeclaration) { + } else if (node instanceof IASTParameterDeclaration) { IASTNode parent = node.getParent(); if (parent instanceof IASTStandardFunctionDeclarator) { IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) parent; if (ASTQueries.findTypeRelevantDeclarator(dtor) == dtor) { - parent= ASTQueries.findOutermostDeclarator(dtor); + parent = ASTQueries.findOutermostDeclarator(dtor); ASTNodeProperty prop = parent.getPropertyInParent(); if (prop == IASTSimpleDeclaration.DECLARATOR) - return dtor.getFunctionScope(); + return dtor.getFunctionScope(); else if (prop == IASTFunctionDefinition.DECLARATOR) - return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody()).getScope(); + return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody()) + .getScope(); + } + } + } else if (node instanceof IASTEnumerator) { + //put the enumerators in the same scope as the enumeration + node = node.getParent(); + } else if (node instanceof IASTName) { + ASTNodeProperty prop = node.getPropertyInParent(); + if (prop == IASTLabelStatement.NAME) { + IScope scope = getContainingScope(node.getParent()); + //labels have function scope + while (scope != null && !(scope instanceof ICFunctionScope)) { + try { + scope = scope.getParent(); + } catch (DOMException e) { + scope = e.getProblem(); + break; + } } + return scope; } - } else if (node instanceof IASTEnumerator) { - //put the enumerators in the same scope as the enumeration - node = node.getParent(); - } else if (node instanceof IASTName) { - ASTNodeProperty prop = node.getPropertyInParent(); - if (prop == IASTLabelStatement.NAME) { - IScope scope= getContainingScope(node.getParent()); - //labels have function scope - while (scope != null && !(scope instanceof ICFunctionScope)) { - try { - scope = scope.getParent(); - } catch (DOMException e) { - scope = e.getProblem(); - break; - } - } - return scope; - } - } - - node = node.getParent(); - } - return null; + } + + node = node.getParent(); + } + return null; } public static IScope getContainingScope(IASTStatement statement) { IASTNode parent = statement.getParent(); IScope scope = null; if (parent instanceof IASTCompoundStatement) { - IASTCompoundStatement compound = (IASTCompoundStatement) parent; - scope = compound.getScope(); + IASTCompoundStatement compound = (IASTCompoundStatement) parent; + scope = compound.getScope(); } else if (parent instanceof IASTStatement) { if (parent instanceof IASTForStatement) { - scope= ((IASTForStatement) parent).getScope(); + scope = ((IASTForStatement) parent).getScope(); } else { scope = getContainingScope((IASTStatement) parent); } @@ -1021,15 +1031,15 @@ public class CVisitor extends ASTQueries { } if (statement instanceof IASTGotoStatement) { - // labels have function scope - while (scope != null && !(scope instanceof ICFunctionScope)) { - try { - scope = scope.getParent(); - } catch (DOMException e) { - scope = e.getProblem(); - break; - } - } + // labels have function scope + while (scope != null && !(scope instanceof ICFunctionScope)) { + try { + scope = scope.getParent(); + } catch (DOMException e) { + scope = e.getProblem(); + break; + } + } } return scope; @@ -1044,9 +1054,8 @@ public class CVisitor extends ASTQueries { return parent; } if (parent instanceof IASTCompoundStatement || // parent is something that can contain a declaration - parent instanceof IASTTranslationUnit || - parent instanceof IASTForStatement || - parent instanceof IASTFunctionDeclarator) { + parent instanceof IASTTranslationUnit || parent instanceof IASTForStatement + || parent instanceof IASTFunctionDeclarator) { return node; } node = parent; @@ -1061,15 +1070,15 @@ public class CVisitor extends ASTQueries { if (scope == null) return null; - IIndexFileSet fileSet= IIndexFileSet.EMPTY; - IASTTranslationUnit tu= name.getTranslationUnit(); + IIndexFileSet fileSet = IIndexFileSet.EMPTY; + IASTTranslationUnit tu = name.getTranslationUnit(); if (tu == null && scope instanceof IASTInternalScope) { - tu= ((IASTInternalScope) scope).getPhysicalNode().getTranslationUnit(); + tu = ((IASTInternalScope) scope).getPhysicalNode().getTranslationUnit(); } if (tu != null) { - final IIndexFileSet fs= tu.getAdapter(IIndexFileSet.class); + final IIndexFileSet fs = tu.getAdapter(IIndexFileSet.class); if (fs != null) { - fileSet= fs; + fileSet = fs; } } @@ -1080,9 +1089,9 @@ public class CVisitor extends ASTQueries { return binding; } try { - scope= scope.getParent(); + scope = scope.getParent(); } catch (DOMException e) { - scope= null; + scope = null; } } @@ -1093,54 +1102,54 @@ public class CVisitor extends ASTQueries { * if (bits & PREFIX_LOOKUP) then returns IBinding[] * otherwise returns IBinding */ - protected static IBinding[] lookupPrefix(IScope scope, IASTName name) throws DOMException{ + protected static IBinding[] lookupPrefix(IScope scope, IASTName name) throws DOMException { if (scope == null) return null; IBinding[] result = null; - CharArraySet handled= new CharArraySet(1); + CharArraySet handled = new CharArraySet(1); while (scope != null) { if (!(scope instanceof ICCompositeTypeScope)) { - IBinding[] bindings= scope.getBindings(new ScopeLookupData(name, true, true)); + IBinding[] bindings = scope.getBindings(new ScopeLookupData(name, true, true)); for (IBinding b : bindings) { - final char[] n= b.getNameCharArray(); + final char[] n = b.getNameCharArray(); // consider binding only if no binding with the same name was found in another scope. if (!handled.containsKey(n)) { - result= ArrayUtil.append(IBinding.class, result, b); + result = ArrayUtil.append(IBinding.class, result, b); } } // store names of bindings for (IBinding b : bindings) { - final char[] n= b.getNameCharArray(); + final char[] n = b.getNameCharArray(); handled.put(n); } } - scope= scope.getParent(); + scope = scope.getParent(); } return ArrayUtil.trim(IBinding.class, result); } private static IBinding externalBinding(IASTTranslationUnit tu, IASTName name) { - IASTNode parent = name.getParent(); - IBinding external = null; - if (parent instanceof IASTIdExpression) { - if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { - //external function - external = new CExternalFunction(tu, name); - ASTInternal.addName(tu.getScope(), name); - } else { - //external variable - //external = new CExternalVariable(tu, name); - //((CScope) tu.getScope()).addName(name); - external = new ProblemBinding(name, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray()); - } - } - return external; + IASTNode parent = name.getParent(); + IBinding external = null; + if (parent instanceof IASTIdExpression) { + if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { + //external function + external = new CExternalFunction(tu, name); + ASTInternal.addName(tu.getScope(), name); + } else { + //external variable + //external = new CExternalVariable(tu, name); + //((CScope) tu.getScope()).addName(name); + external = new ProblemBinding(name, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray()); + } + } + return external; } protected static IASTDeclarator findDefinition(IASTDeclarator declarator, int beginAtLoc) { - return (IASTDeclarator) findDefinition(declarator, declarator.getName().toCharArray(), beginAtLoc); + return (IASTDeclarator) findDefinition(declarator, declarator.getName().toCharArray(), beginAtLoc); } protected static IASTFunctionDeclarator findDefinition(IASTFunctionDeclarator declarator) { @@ -1157,7 +1166,7 @@ public class CVisitor extends ASTQueries { if (parent instanceof IASTCompositeTypeSpecifier) { // C does not have a notion of structure scope. // Types names declared in a structure have file scope. - parent = parent.getParent(); // This will be the declaration + parent = parent.getParent(); // This will be the declaration if (parent != null) { parent = parent.getParent(); } @@ -1174,7 +1183,7 @@ public class CVisitor extends ASTQueries { if (list != null) { for (IASTNode node : list) { if (node == blockItem) { - begun = true; + begun = true; continue; } @@ -1195,23 +1204,23 @@ public class CVisitor extends ASTQueries { IASTName name = null; if (declSpec instanceof ICASTCompositeTypeSpecifier) { - name = ((ICASTCompositeTypeSpecifier) declSpec).getName(); + name = ((ICASTCompositeTypeSpecifier) declSpec).getName(); } else if (declSpec instanceof ICASTEnumerationSpecifier) { - name = ((ICASTEnumerationSpecifier) declSpec).getName(); + name = ((ICASTEnumerationSpecifier) declSpec).getName(); } - if (name != null) { - if (CharArrayUtils.equals(name.toCharArray(), declName)) { + if (name != null) { + if (CharArrayUtils.equals(name.toCharArray(), declName)) { return declSpec; } } } else if (node instanceof IASTSimpleDeclaration && decl instanceof IASTDeclarator) { - IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node; - IASTDeclarator[] dtors = simpleDecl.getDeclarators(); - for (int j = 0; dtors != null && j < dtors.length; j++) { - if (CharArrayUtils.equals(dtors[j].getName().toCharArray(), declName)) { - return dtors[j]; - } - } + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node; + IASTDeclarator[] dtors = simpleDecl.getDeclarators(); + for (int j = 0; dtors != null && j < dtors.length; j++) { + if (CharArrayUtils.equals(dtors[j].getName().toCharArray(), declName)) { + return dtors[j]; + } + } } } } @@ -1228,8 +1237,9 @@ public class CVisitor extends ASTQueries { public static IType createType(IASTDeclarator declarator) { return createType(declarator, 0); } + public static IType createType(IASTDeclarator declarator, int flags) { - IASTDeclSpecifier declSpec = null; + IASTDeclSpecifier declSpec = null; IASTNode node = declarator.getParent(); while (node instanceof IASTDeclarator) { @@ -1244,66 +1254,71 @@ public class CVisitor extends ASTQueries { } else if (node instanceof IASTFunctionDefinition) { declSpec = ((IASTFunctionDefinition) node).getDeclSpecifier(); } else if (node instanceof IASTTypeId) { - declSpec = ((IASTTypeId) node).getDeclSpecifier(); + declSpec = ((IASTTypeId) node).getDeclSpecifier(); } - boolean isParameter = (node instanceof IASTParameterDeclaration || node.getParent() instanceof ICASTKnRFunctionDeclarator); + boolean isParameter = (node instanceof IASTParameterDeclaration + || node.getParent() instanceof ICASTKnRFunctionDeclarator); IType type = createType((ICASTDeclSpecifier) declSpec); type = createType(type, declarator, flags); - if (isParameter) { - IType paramType = type; - // Remove typedefs ready for subsequent processing. - while (paramType instanceof ITypedef) { - paramType = ((ITypedef) paramType).getType(); - } - - //C99: 6.7.5.3-7 a declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the - //type qualifiers (if any) are those specified within the[and] of the array type derivation - if (paramType instanceof IArrayType) { // the index does not yet return ICArrayTypes - IArrayType at = (IArrayType) paramType; - int q= 0; + if (isParameter) { + IType paramType = type; + // Remove typedefs ready for subsequent processing. + while (paramType instanceof ITypedef) { + paramType = ((ITypedef) paramType).getType(); + } + + //C99: 6.7.5.3-7 a declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the + //type qualifiers (if any) are those specified within the[and] of the array type derivation + if (paramType instanceof IArrayType) { // the index does not yet return ICArrayTypes + IArrayType at = (IArrayType) paramType; + int q = 0; if (at instanceof ICArrayType) { - ICArrayType cat= (ICArrayType) at; - if (cat.isConst()) q |= CPointerType.IS_CONST; - if (cat.isVolatile()) q |= CPointerType.IS_VOLATILE; - if (cat.isRestrict()) q |= CPointerType.IS_RESTRICT; + ICArrayType cat = (ICArrayType) at; + if (cat.isConst()) + q |= CPointerType.IS_CONST; + if (cat.isVolatile()) + q |= CPointerType.IS_VOLATILE; + if (cat.isRestrict()) + q |= CPointerType.IS_RESTRICT; } type = new CPointerType(at.getType(), q); - } else if (paramType instanceof IFunctionType) { - //-8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type" - type = new CPointerType(paramType, 0); - } - } + } else if (paramType instanceof IFunctionType) { + //-8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type" + type = new CPointerType(paramType, 0); + } + } return type; } + private static IType createType(IASTTypeId typeId) { return createType(typeId.getAbstractDeclarator()); } public static IType createType(IType baseType, IASTDeclarator declarator, int flags) { - if (((flags & ONLY_RETURN_TYPE) == 0) && declarator instanceof IASTFunctionDeclarator) - return createType(baseType, (IASTFunctionDeclarator) declarator); + if (((flags & ONLY_RETURN_TYPE) == 0) && declarator instanceof IASTFunctionDeclarator) + return createType(baseType, (IASTFunctionDeclarator) declarator); IType type = baseType; type = applyAttributes(type, declarator); type = setupPointerChain(declarator.getPointerOperators(), type); type = setupArrayChain(declarator, type); - IASTDeclarator nested = declarator.getNestedDeclarator(); - if (nested != null) { - return createType(type, nested, flags); - } - return type; + IASTDeclarator nested = declarator.getNestedDeclarator(); + if (nested != null) { + return createType(type, nested, flags); + } + return type; } private static IType applyAttributes(IType type, IASTDeclarator declarator) { if (type instanceof IBasicType) { IBasicType basicType = (IBasicType) type; if (basicType.getKind() == IBasicType.Kind.eInt) { - IASTAttribute[] attributes = declarator.getAttributes(); + IASTAttribute[] attributes = declarator.getAttributes(); for (IASTAttribute attribute : attributes) { char[] name = attribute.getName(); if (CharArrayUtils.equals(name, "__mode__") || CharArrayUtils.equals(name, "mode")) { //$NON-NLS-1$ //$NON-NLS-2$ @@ -1319,14 +1334,13 @@ public class CVisitor extends ASTQueries { } else if (CharArrayUtils.equals(mode, "__DI__") || CharArrayUtils.equals(mode, "DI")) { //$NON-NLS-1$ //$NON-NLS-2$ SizeofCalculator sizeofs = new SizeofCalculator(declarator.getTranslationUnit()); int modifier; - if (sizeofs.sizeof_long != null && sizeofs.sizeof_int != null && - sizeofs.sizeof_long.size == 2 * sizeofs.sizeof_int.size) { + if (sizeofs.sizeof_long != null && sizeofs.sizeof_int != null + && sizeofs.sizeof_long.size == 2 * sizeofs.sizeof_int.size) { modifier = IBasicType.IS_LONG; } else { modifier = IBasicType.IS_LONG_LONG; } - type = new CBasicType(IBasicType.Kind.eInt, - modifier | getSignModifiers(basicType)); + type = new CBasicType(IBasicType.Kind.eInt, modifier | getSignModifiers(basicType)); } else if (CharArrayUtils.equals(mode, "__word__") || CharArrayUtils.equals(mode, "word")) { //$NON-NLS-1$ //$NON-NLS-2$ type = new CBasicType(IBasicType.Kind.eInt, IBasicType.IS_LONG | getSignModifiers(basicType)); @@ -1343,18 +1357,18 @@ public class CVisitor extends ASTQueries { } public static IType createType(IType returnType, IASTFunctionDeclarator declarator) { - IType[] pTypes = getParmTypes(declarator); - returnType = setupPointerChain(declarator.getPointerOperators(), returnType); - - boolean takesVarargs = declarator instanceof IASTStandardFunctionDeclarator && - ((IASTStandardFunctionDeclarator) declarator).takesVarArgs(); - IType type = new CFunctionType(returnType, pTypes, takesVarargs); - - IASTDeclarator nested = declarator.getNestedDeclarator(); - if (nested != null) { - return createType(type, nested, 0); - } - return type; + IType[] pTypes = getParmTypes(declarator); + returnType = setupPointerChain(declarator.getPointerOperators(), returnType); + + boolean takesVarargs = declarator instanceof IASTStandardFunctionDeclarator + && ((IASTStandardFunctionDeclarator) declarator).takesVarArgs(); + IType type = new CFunctionType(returnType, pTypes, takesVarargs); + + IASTDeclarator nested = declarator.getNestedDeclarator(); + if (nested != null) { + return createType(type, nested, 0); + } + return type; } /** @@ -1394,17 +1408,17 @@ public class CVisitor extends ASTQueries { binding = name.resolveBinding(); if (binding instanceof IType && !(binding instanceof IProblemBinding)) - return (IType) binding; + return (IType) binding; return new ProblemType(ISemanticProblem.TYPE_UNRESOLVED_NAME); } public static IType createType(ICASTDeclSpecifier declSpec) { - if (declSpec.isConst() || declSpec.isVolatile() || declSpec.isRestrict()) { + if (declSpec.isConst() || declSpec.isVolatile() || declSpec.isRestrict()) { return new CQualifierType(declSpec); } - return createBaseType(declSpec); + return createBaseType(declSpec); } /** @@ -1418,44 +1432,44 @@ public class CVisitor extends ASTQueries { IASTParameterDeclaration parms[] = ((IASTStandardFunctionDeclarator) decltor).getParameters(); IType parmTypes[] = new IType[parms.length]; - for (int i = 0; i < parms.length; i++) { - parmTypes[i] = createType(parms[i].getDeclarator()); - } + for (int i = 0; i < parms.length; i++) { + parmTypes[i] = createType(parms[i].getDeclarator()); + } - if (parmTypes.length == 1 && SemanticUtil.isVoidType(parmTypes[0])) + if (parmTypes.length == 1 && SemanticUtil.isVoidType(parmTypes[0])) return IType.EMPTY_TYPE_ARRAY; // f(void) is the same as f() - return parmTypes; + return parmTypes; } else if (decltor instanceof ICASTKnRFunctionDeclarator) { IASTName parms[] = ((ICASTKnRFunctionDeclarator) decltor).getParameterNames(); IType parmTypes[] = new IType[parms.length]; - for (int i = 0; i < parms.length; i++) { - IASTDeclarator dtor = getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) decltor, parms[i]); - if (dtor != null) - parmTypes[i] = createType(dtor); - } - return parmTypes; + for (int i = 0; i < parms.length; i++) { + IASTDeclarator dtor = getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) decltor, parms[i]); + if (dtor != null) + parmTypes[i] = createType(dtor); + } + return parmTypes; } else { throw new IllegalArgumentException(); } } - protected static IASTDeclarator getKnRParameterDeclarator(ICASTKnRFunctionDeclarator fKnRDtor, IASTName name) { - IASTDeclaration[] decls = fKnRDtor.getParameterDeclarations(); - char[] n = name.toCharArray(); - for (int i = 0; i < decls.length; i++) { - if (!(decls[i] instanceof IASTSimpleDeclaration)) - continue; - - IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decls[i]).getDeclarators(); - for (IASTDeclarator dtor : dtors) { - if (CharArrayUtils.equals(dtor.getName().toCharArray(), n)) { - return dtor; - } - } - } - return null; - } + protected static IASTDeclarator getKnRParameterDeclarator(ICASTKnRFunctionDeclarator fKnRDtor, IASTName name) { + IASTDeclaration[] decls = fKnRDtor.getParameterDeclarations(); + char[] n = name.toCharArray(); + for (int i = 0; i < decls.length; i++) { + if (!(decls[i] instanceof IASTSimpleDeclaration)) + continue; + + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decls[i]).getDeclarators(); + for (IASTDeclarator dtor : dtors) { + if (CharArrayUtils.equals(dtor.getName().toCharArray(), n)) { + return dtor; + } + } + } + return null; + } /** * Traverse through an array of IASTArrayModifier[] corresponding to the IASTDeclarator decl parameter. @@ -1475,7 +1489,7 @@ public class CVisitor extends ASTQueries { if (mods[i] instanceof ICASTArrayModifier) { arrayType.setModifier((ICASTArrayModifier) mods[i]); } - lastType= arrayType; + lastType = arrayType; } } @@ -1498,31 +1512,27 @@ public class CVisitor extends ASTQueries { if (ptrs.length == 1) { pointerType.setType(lastType); - pointerType.setQualifiers( - (((ICASTPointer) ptrs[0]).isConst() ? CPointerType.IS_CONST : 0) | - (((ICASTPointer) ptrs[0]).isRestrict() ? CPointerType.IS_RESTRICT : 0) | - (((ICASTPointer) ptrs[0]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); + pointerType.setQualifiers((((ICASTPointer) ptrs[0]).isConst() ? CPointerType.IS_CONST : 0) + | (((ICASTPointer) ptrs[0]).isRestrict() ? CPointerType.IS_RESTRICT : 0) + | (((ICASTPointer) ptrs[0]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); } else { CPointerType tempType = new CPointerType(); pointerType.setType(tempType); - pointerType.setQualifiers( - (((ICASTPointer) ptrs[ptrs.length - 1]).isConst() ? CPointerType.IS_CONST : 0) | - (((ICASTPointer) ptrs[ptrs.length - 1]).isRestrict() ? CPointerType.IS_RESTRICT : 0) | - (((ICASTPointer) ptrs[ptrs.length - 1]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); + pointerType.setQualifiers((((ICASTPointer) ptrs[ptrs.length - 1]).isConst() ? CPointerType.IS_CONST : 0) + | (((ICASTPointer) ptrs[ptrs.length - 1]).isRestrict() ? CPointerType.IS_RESTRICT : 0) + | (((ICASTPointer) ptrs[ptrs.length - 1]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); int i = ptrs.length - 2; for (; i > 0; i--) { tempType.setType(new CPointerType()); - tempType.setQualifiers( - (((ICASTPointer) ptrs[i]).isConst() ? CPointerType.IS_CONST : 0) | - (((ICASTPointer) ptrs[i]).isRestrict() ? CPointerType.IS_RESTRICT : 0) | - (((ICASTPointer) ptrs[i]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); + tempType.setQualifiers((((ICASTPointer) ptrs[i]).isConst() ? CPointerType.IS_CONST : 0) + | (((ICASTPointer) ptrs[i]).isRestrict() ? CPointerType.IS_RESTRICT : 0) + | (((ICASTPointer) ptrs[i]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); tempType = (CPointerType) tempType.getType(); } tempType.setType(lastType); - tempType.setQualifiers( - (((ICASTPointer) ptrs[i]).isConst() ? CPointerType.IS_CONST : 0) | - (((ICASTPointer) ptrs[i]).isRestrict() ? CPointerType.IS_RESTRICT : 0) | - (((ICASTPointer) ptrs[i]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); + tempType.setQualifiers((((ICASTPointer) ptrs[i]).isConst() ? CPointerType.IS_CONST : 0) + | (((ICASTPointer) ptrs[i]).isRestrict() ? CPointerType.IS_RESTRICT : 0) + | (((ICASTPointer) ptrs[i]).isVolatile() ? CPointerType.IS_VOLATILE : 0)); } return pointerType; @@ -1551,25 +1561,25 @@ public class CVisitor extends ASTQueries { return action.getReferences(); } - public static IBinding[] findBindingsForContentAssist(IASTName name, boolean isPrefix) { - ASTNodeProperty prop = name.getPropertyInParent(); - - IBinding[] result = null; - - if (prop == IASTFieldReference.FIELD_NAME) { - Object res = findBinding((IASTFieldReference) name.getParent(), isPrefix); - if (isPrefix) { - result = (IBinding[]) res; - } else { - IBinding binding = (IBinding) res; - if (binding != null) { - result = new IBinding[] { binding }; - } - } - } else if (prop == ICASTFieldDesignator.FIELD_NAME) { - result = findBindingForContentAssist((ICASTFieldDesignator) name.getParent(), isPrefix); - } else { - IScope scope= getContainingScope(name); + public static IBinding[] findBindingsForContentAssist(IASTName name, boolean isPrefix) { + ASTNodeProperty prop = name.getPropertyInParent(); + + IBinding[] result = null; + + if (prop == IASTFieldReference.FIELD_NAME) { + Object res = findBinding((IASTFieldReference) name.getParent(), isPrefix); + if (isPrefix) { + result = (IBinding[]) res; + } else { + IBinding binding = (IBinding) res; + if (binding != null) { + result = new IBinding[] { binding }; + } + } + } else if (prop == ICASTFieldDesignator.FIELD_NAME) { + result = findBindingForContentAssist((ICASTFieldDesignator) name.getParent(), isPrefix); + } else { + IScope scope = getContainingScope(name); try { if (isPrefix) { result = lookupPrefix(scope, name); @@ -1577,25 +1587,26 @@ public class CVisitor extends ASTQueries { result = new IBinding[] { lookup(scope, name) }; } } catch (DOMException e) { - } - } - return ArrayUtil.trim(IBinding.class, result); - } + } + } + return ArrayUtil.trim(IBinding.class, result); + } private static IBinding[] findBindingForContentAssist(ICASTFieldDesignator fd, boolean isPrefix) { IASTNode blockItem = getContainingBlockItem(fd); IASTNode declarationNode = blockItem; - if (blockItem instanceof IASTDeclarationStatement && ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration) { + if (blockItem instanceof IASTDeclarationStatement + && ((IASTDeclarationStatement) blockItem).getDeclaration() instanceof IASTSimpleDeclaration) { declarationNode = ((IASTDeclarationStatement) blockItem).getDeclaration(); } else { while (declarationNode != null && !(declarationNode instanceof IASTSimpleDeclaration)) - declarationNode= declarationNode.getParent(); + declarationNode = declarationNode.getParent(); } if (declarationNode instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declarationNode; - IBinding struct= null; + IBinding struct = null; if (simpleDecl.getDeclSpecifier() instanceof IASTNamedTypeSpecifier) { struct = ((IASTNamedTypeSpecifier) simpleDecl.getDeclSpecifier()).getName().resolveBinding(); } else if (simpleDecl.getDeclSpecifier() instanceof IASTElaboratedTypeSpecifier) { @@ -1604,7 +1615,7 @@ public class CVisitor extends ASTQueries { struct = ((IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier()).getName().resolveBinding(); } if (struct instanceof IType) { - IType t= unwrapTypedefs((IType) struct); + IType t = unwrapTypedefs((IType) struct); if (t instanceof ICompositeType) { return findFieldsByPrefix((ICompositeType) t, fd.getName().toCharArray()); @@ -1616,106 +1627,109 @@ public class CVisitor extends ASTQueries { } public static IBinding[] findBindings(IScope scope, String name) { - CASTName astName = new CASTName(name.toCharArray()); - - // normal names - astName.setPropertyInParent(STRING_LOOKUP_PROPERTY); - Object o1 = lookup(scope, astName); - - IBinding[] b1 = null; - if (o1 instanceof IBinding) { - b1 = new IBinding[] { (IBinding) o1 }; - } else { - b1 = (IBinding[]) o1; - } - - // structure names - astName.setPropertyInParent(STRING_LOOKUP_TAGS_PROPERTY); - Object o2 = lookup(scope, astName); - - IBinding[] b2 = null; - if (o2 instanceof IBinding) { - b2 = new IBinding[] { (IBinding) o2 }; - } else { - b2 = (IBinding[]) o2; - } - - // label names - List<ILabel> b3 = new ArrayList<>(); - do { - char[] n = name.toCharArray(); - if (scope instanceof CFunctionScope) { - IASTFunctionDefinition def = ASTQueries.findAncestorWithType( - ((CFunctionScope) scope).getPhysicalNode(), IASTFunctionDefinition.class); - ILabel[] labels = getLabels(def); - for (ILabel label : labels) { - if (CharArrayUtils.equals(label.getNameCharArray(), n)) { - b3.add(label); - break; - } - } - break; - } - try { + CASTName astName = new CASTName(name.toCharArray()); + + // normal names + astName.setPropertyInParent(STRING_LOOKUP_PROPERTY); + Object o1 = lookup(scope, astName); + + IBinding[] b1 = null; + if (o1 instanceof IBinding) { + b1 = new IBinding[] { (IBinding) o1 }; + } else { + b1 = (IBinding[]) o1; + } + + // structure names + astName.setPropertyInParent(STRING_LOOKUP_TAGS_PROPERTY); + Object o2 = lookup(scope, astName); + + IBinding[] b2 = null; + if (o2 instanceof IBinding) { + b2 = new IBinding[] { (IBinding) o2 }; + } else { + b2 = (IBinding[]) o2; + } + + // label names + List<ILabel> b3 = new ArrayList<>(); + do { + char[] n = name.toCharArray(); + if (scope instanceof CFunctionScope) { + IASTFunctionDefinition def = ASTQueries.findAncestorWithType(((CFunctionScope) scope).getPhysicalNode(), + IASTFunctionDefinition.class); + ILabel[] labels = getLabels(def); + for (ILabel label : labels) { + if (CharArrayUtils.equals(label.getNameCharArray(), n)) { + b3.add(label); + break; + } + } + break; + } + try { scope = scope.getParent(); } catch (DOMException e) { - scope= null; + scope = null; } - } while (scope != null); + } while (scope != null); - int c = (b1 == null ? 0 : b1.length) + (b2 == null ? 0 : b2.length) + b3.size(); + int c = (b1 == null ? 0 : b1.length) + (b2 == null ? 0 : b2.length) + b3.size(); - IBinding[] result = new IBinding[c]; + IBinding[] result = new IBinding[c]; - if (b1 != null) - ArrayUtil.addAll(IBinding.class, result, b1); + if (b1 != null) + ArrayUtil.addAll(IBinding.class, result, b1); - if (b2 != null) - ArrayUtil.addAll(IBinding.class, result, b2); + if (b2 != null) + ArrayUtil.addAll(IBinding.class, result, b2); - ArrayUtil.addAll(IBinding.class, result, b3.toArray(new IBinding[b3.size()])); + ArrayUtil.addAll(IBinding.class, result, b3.toArray(new IBinding[b3.size()])); - return result; - } + return result; + } static public boolean declaredBefore(IASTNode nodeA, IASTNode nodeB) { - if (nodeB == null) return true; - if (nodeB.getPropertyInParent() == STRING_LOOKUP_PROPERTY) return true; - if (nodeB.getPropertyInParent() == STRING_LOOKUP_TAGS_PROPERTY) return true; - - if (nodeA instanceof ASTNode) { - ASTNode nd= (ASTNode) nodeA; - int pointOfDecl = 0; - - ASTNodeProperty prop = nd.getPropertyInParent(); - // point of declaration for a name is immediately after its complete declarator and before its initializer - if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) { - IASTDeclarator dtor = (IASTDeclarator)((nd instanceof IASTDeclarator) ? nd : nd.getParent()); - while (dtor.getParent() instanceof IASTDeclarator) - dtor = (IASTDeclarator) dtor.getParent(); - IASTInitializer init = dtor.getInitializer(); - if (init != null) - pointOfDecl = ((ASTNode) init).getOffset() - 1; - else - pointOfDecl = ((ASTNode) dtor).getOffset() + ((ASTNode) dtor).getLength(); - } - // point of declaration for an enumerator is immediately after it enumerator-definition - else if (prop == IASTEnumerator.ENUMERATOR_NAME) { - IASTEnumerator enumtor = (IASTEnumerator) nd.getParent(); - if (enumtor.getValue() != null) { - ASTNode exp = (ASTNode) enumtor.getValue(); - pointOfDecl = exp.getOffset() + exp.getLength(); - } else { - pointOfDecl = nd.getOffset() + nd.getLength(); - } - } else { - pointOfDecl = nd.getOffset() + nd.getLength(); - } - - return pointOfDecl < ((ASTNode) nodeB).getOffset(); - } - - return true; + if (nodeB == null) + return true; + if (nodeB.getPropertyInParent() == STRING_LOOKUP_PROPERTY) + return true; + if (nodeB.getPropertyInParent() == STRING_LOOKUP_TAGS_PROPERTY) + return true; + + if (nodeA instanceof ASTNode) { + ASTNode nd = (ASTNode) nodeA; + int pointOfDecl = 0; + + ASTNodeProperty prop = nd.getPropertyInParent(); + // point of declaration for a name is immediately after its complete declarator and before its initializer + if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) { + IASTDeclarator dtor = (IASTDeclarator) ((nd instanceof IASTDeclarator) ? nd : nd.getParent()); + while (dtor.getParent() instanceof IASTDeclarator) + dtor = (IASTDeclarator) dtor.getParent(); + IASTInitializer init = dtor.getInitializer(); + if (init != null) + pointOfDecl = ((ASTNode) init).getOffset() - 1; + else + pointOfDecl = ((ASTNode) dtor).getOffset() + ((ASTNode) dtor).getLength(); + } + // point of declaration for an enumerator is immediately after it enumerator-definition + else if (prop == IASTEnumerator.ENUMERATOR_NAME) { + IASTEnumerator enumtor = (IASTEnumerator) nd.getParent(); + if (enumtor.getValue() != null) { + ASTNode exp = (ASTNode) enumtor.getValue(); + pointOfDecl = exp.getOffset() + exp.getLength(); + } else { + pointOfDecl = nd.getOffset() + nd.getLength(); + } + } else { + pointOfDecl = nd.getOffset() + nd.getLength(); + } + + return pointOfDecl < ((ASTNode) nodeB).getOffset(); + } + + return true; } /** @@ -1729,25 +1743,25 @@ public class CVisitor extends ASTQueries { if (node == null) return null; - node= node.getParent(); + node = node.getParent(); } // search for enclosing binding - IASTName name= null; - node= node.getParent(); - for (; node != null; node= node.getParent()) { + IASTName name = null; + node = node.getParent(); + for (; node != null; node = node.getParent()) { if (node instanceof IASTFunctionDefinition) { if (!allowFunction) continue; - IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + IASTDeclarator dtor = findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); if (dtor != null) { - name= dtor.getName(); + name = dtor.getName(); } break; } if (node instanceof IASTCompositeTypeSpecifier) { - name= ((IASTCompositeTypeSpecifier) node).getName(); + name = ((IASTCompositeTypeSpecifier) node).getName(); break; } } @@ -1760,25 +1774,25 @@ public class CVisitor extends ASTQueries { /** * Determine whether an expression is a null pointer constant. */ - public static boolean isNullPointerConstant(IASTExpression expression) { - // [6.3.2.3] p3: An integer constant expression with the value 0, or such an expression cast - // to void*, is called a null pointer constant. - - // Unwrap extra parentheses. - if (expression instanceof IASTUnaryExpression) { - IASTUnaryExpression unaryExpression = (IASTUnaryExpression) expression; - if (unaryExpression.getOperator() == IASTUnaryExpression.op_bracketedPrimary) { - return isNullPointerConstant(unaryExpression.getOperand()); - } - } - - if (expression instanceof IASTCastExpression) { - IASTCastExpression castExpression = (IASTCastExpression) expression; + public static boolean isNullPointerConstant(IASTExpression expression) { + // [6.3.2.3] p3: An integer constant expression with the value 0, or such an expression cast + // to void*, is called a null pointer constant. + + // Unwrap extra parentheses. + if (expression instanceof IASTUnaryExpression) { + IASTUnaryExpression unaryExpression = (IASTUnaryExpression) expression; + if (unaryExpression.getOperator() == IASTUnaryExpression.op_bracketedPrimary) { + return isNullPointerConstant(unaryExpression.getOperand()); + } + } + + if (expression instanceof IASTCastExpression) { + IASTCastExpression castExpression = (IASTCastExpression) expression; IType castType = createType(castExpression.getTypeId()); - if (castType.isSameType(CPointerType.VOID_POINTER)) { - return isNullPointerConstant(castExpression.getOperand()); - } - } + if (castType.isSameType(CPointerType.VOID_POINTER)) { + return isNullPointerConstant(castExpression.getOperand()); + } + } IType expressionType = expression.getExpressionType(); if (expressionType instanceof IBasicType) { @@ -1789,6 +1803,6 @@ public class CVisitor extends ASTQueries { } return false; - } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/Conversions.java index f1df367481d..ffde9ec1273 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/Conversions.java @@ -22,8 +22,7 @@ public class Conversions { */ public static IType arrayTypeToPointerType(ICArrayType type) { return new CPointerType(type.getType(), - (type.isConst() ? CPointerType.IS_CONST : 0) | - (type.isRestrict() ? CPointerType.IS_RESTRICT : 0) | - (type.isVolatile() ? CPointerType.IS_VOLATILE : 0)); + (type.isConst() ? CPointerType.IS_CONST : 0) | (type.isRestrict() ? CPointerType.IS_RESTRICT : 0) + | (type.isVolatile() ? CPointerType.IS_VOLATILE : 0)); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index e165c46e8d6..78e0b3ebf80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -109,174 +109,172 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; * Source parser for gnu-c syntax. */ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { - private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4; - private static final int DEFAULT_PARAMETERS_LIST_SIZE = 4; + private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4; + private static final int DEFAULT_PARAMETERS_LIST_SIZE = 4; - private final boolean supportGCCStyleDesignators; + private final boolean supportGCCStyleDesignators; private IIndex index; - protected IASTTranslationUnit translationUnit; - - private int fPreventKnrCheck= 0; - - public GNUCSourceParser(IScanner scanner, ParserMode parserMode, - IParserLogService logService, ICParserExtensionConfiguration config) { - this(scanner, parserMode, logService, config, null); - } - - public GNUCSourceParser(IScanner scanner, ParserMode parserMode, - IParserLogService logService, ICParserExtensionConfiguration config, - IIndex index) { - super(scanner, logService, parserMode, CNodeFactory.getDefault(), - config.supportStatementsInExpressions(), - config.supportTypeofUnaryExpressions(), - config.supportAlignOfUnaryExpression(), - config.supportKnRC(), - config.supportAttributeSpecifiers(), - config.supportDeclspecSpecifiers(), - config.getBuiltinBindingsProvider()); - supportGCCStyleDesignators = config.supportGCCStyleDesignators(); - supportParameterInfoBlock= config.supportParameterInfoBlock(); - supportExtendedSizeofOperator= config.supportExtendedSizeofOperator(); - supportFunctionStyleAsm= config.supportFunctionStyleAssembler(); - this.index= index; - } - - @Override - protected ICNodeFactory getNodeFactory() { - return (ICNodeFactory) super.getNodeFactory(); - } - - @Override - protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions options) throws EndOfFileException, BacktrackException { - if (options.fAllowInitializer && LTcatchEOF(1) == IToken.tASSIGN) { - final int offset= consume().getOffset(); - IASTInitializerClause initClause = initClause(); - IASTEqualsInitializer result= getNodeFactory().newEqualsInitializer(initClause); - return setRange(result, offset, calculateEndOffset(initClause)); - } - return null; - } - - private IASTInitializerClause initClause() throws EndOfFileException, BacktrackException { - final int offset = LA(1).getOffset(); - if (LT(1) != IToken.tLBRACE) - return expression(ExprKind.eAssignment); - - // it's an aggregate initializer - consume(IToken.tLBRACE); - IASTInitializerList result = getNodeFactory().newInitializerList(); - - // bug 196468, gcc accepts empty braces. - if (supportGCCStyleDesignators && LT(1) == IToken.tRBRACE) { - int endOffset= consume().getEndOffset(); - setRange(result, offset, endOffset); - return result; - } - - for (;;) { - final int checkOffset= LA(1).getOffset(); - // required at least one initializer list - // get designator list - List<? extends ICASTDesignator> designator= designatorList(); - if (designator == null) { - IASTInitializerClause clause= initClause(); - if (result.getSize() >= maximumTrivialExpressionsInAggregateInitializers && !ASTQueries.canContainName(clause)) { - translationUnit.setHasNodesOmitted(true); - clause= null; - } - // depending on value of skipTrivialItemsInCompoundInitializers initializer may be null - // in any way add the initializer such that the actual size can be tracked. - result.addClause(clause); - } else { - ICASTDesignatedInitializer desigInitializer = getNodeFactory().newDesignatedInitializer((IASTInitializerClause) null); - setRange(desigInitializer, designator.get(0)); - for (ICASTDesignator d : designator) { - desigInitializer.addDesignator(d); - } - - if (LT(1) != IToken.tEOC) { - // Gnu extension: the assign operator is optional - if (LT(1) == IToken.tASSIGN) - consume(IToken.tASSIGN); - - IASTInitializerClause clause= initClause(); - desigInitializer.setOperand(clause); - adjustLength(desigInitializer, clause); - } - result.addClause(desigInitializer); - } - - // can end with ", }" or "}" - boolean canContinue= LT(1) == IToken.tCOMMA; - if (canContinue) - consume(); - - switch (LT(1)) { - case IToken.tRBRACE: - int lastOffset = consume().getEndOffset(); - setRange(result, offset, lastOffset); - return result; - - case IToken.tEOC: - setRange(result, offset, LA(1).getOffset()); - return result; - } - - if (!canContinue || LA(1).getOffset() == checkOffset) { - throwBacktrack(offset, LA(1).getEndOffset() - offset); - } - } - // consume the closing brace - } - - - private List<? extends ICASTDesignator> designatorList() throws EndOfFileException, BacktrackException { - final int lt1= LT(1); - if (lt1 == IToken.tDOT || lt1 == IToken.tLBRACKET) { - List<ICASTDesignator> designatorList= null; - while (true) { - switch (LT(1)) { - case IToken.tDOT: - int offset = consume().getOffset(); - IASTName n = identifier(); - ICASTFieldDesignator fieldDesignator = getNodeFactory().newFieldDesignator(n); - setRange(fieldDesignator, offset, calculateEndOffset(n)); - if (designatorList == null) - designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); - designatorList.add(fieldDesignator); - break; - - case IToken.tLBRACKET: - offset = consume().getOffset(); - IASTExpression constantExpression = expression(); - if (supportGCCStyleDesignators && LT(1) == IToken.tELLIPSIS) { - consume(IToken.tELLIPSIS); - IASTExpression constantExpression2 = expression(); - int lastOffset = consume(IToken.tRBRACKET).getEndOffset(); - IGCCASTArrayRangeDesignator designator = getNodeFactory().newArrayRangeDesignatorGCC(constantExpression, constantExpression2); - setRange(designator, offset, lastOffset); - if (designatorList == null) - designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); - designatorList.add(designator); - } else { - int lastOffset = consume(IToken.tRBRACKET).getEndOffset(); - ICASTArrayDesignator designator = getNodeFactory().newArrayDesignator(constantExpression); - setRange(designator, offset, lastOffset); - if (designatorList == null) - designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); - designatorList.add(designator); - } - break; - - default: - return designatorList; - } - } - } + protected IASTTranslationUnit translationUnit; + + private int fPreventKnrCheck = 0; + + public GNUCSourceParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, + ICParserExtensionConfiguration config) { + this(scanner, parserMode, logService, config, null); + } + + public GNUCSourceParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, + ICParserExtensionConfiguration config, IIndex index) { + super(scanner, logService, parserMode, CNodeFactory.getDefault(), config.supportStatementsInExpressions(), + config.supportTypeofUnaryExpressions(), config.supportAlignOfUnaryExpression(), config.supportKnRC(), + config.supportAttributeSpecifiers(), config.supportDeclspecSpecifiers(), + config.getBuiltinBindingsProvider()); + supportGCCStyleDesignators = config.supportGCCStyleDesignators(); + supportParameterInfoBlock = config.supportParameterInfoBlock(); + supportExtendedSizeofOperator = config.supportExtendedSizeofOperator(); + supportFunctionStyleAsm = config.supportFunctionStyleAssembler(); + this.index = index; + } + + @Override + protected ICNodeFactory getNodeFactory() { + return (ICNodeFactory) super.getNodeFactory(); + } + + @Override + protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions options) + throws EndOfFileException, BacktrackException { + if (options.fAllowInitializer && LTcatchEOF(1) == IToken.tASSIGN) { + final int offset = consume().getOffset(); + IASTInitializerClause initClause = initClause(); + IASTEqualsInitializer result = getNodeFactory().newEqualsInitializer(initClause); + return setRange(result, offset, calculateEndOffset(initClause)); + } + return null; + } + + private IASTInitializerClause initClause() throws EndOfFileException, BacktrackException { + final int offset = LA(1).getOffset(); + if (LT(1) != IToken.tLBRACE) + return expression(ExprKind.eAssignment); + + // it's an aggregate initializer + consume(IToken.tLBRACE); + IASTInitializerList result = getNodeFactory().newInitializerList(); + + // bug 196468, gcc accepts empty braces. + if (supportGCCStyleDesignators && LT(1) == IToken.tRBRACE) { + int endOffset = consume().getEndOffset(); + setRange(result, offset, endOffset); + return result; + } + + for (;;) { + final int checkOffset = LA(1).getOffset(); + // required at least one initializer list + // get designator list + List<? extends ICASTDesignator> designator = designatorList(); + if (designator == null) { + IASTInitializerClause clause = initClause(); + if (result.getSize() >= maximumTrivialExpressionsInAggregateInitializers + && !ASTQueries.canContainName(clause)) { + translationUnit.setHasNodesOmitted(true); + clause = null; + } + // depending on value of skipTrivialItemsInCompoundInitializers initializer may be null + // in any way add the initializer such that the actual size can be tracked. + result.addClause(clause); + } else { + ICASTDesignatedInitializer desigInitializer = getNodeFactory() + .newDesignatedInitializer((IASTInitializerClause) null); + setRange(desigInitializer, designator.get(0)); + for (ICASTDesignator d : designator) { + desigInitializer.addDesignator(d); + } + + if (LT(1) != IToken.tEOC) { + // Gnu extension: the assign operator is optional + if (LT(1) == IToken.tASSIGN) + consume(IToken.tASSIGN); + + IASTInitializerClause clause = initClause(); + desigInitializer.setOperand(clause); + adjustLength(desigInitializer, clause); + } + result.addClause(desigInitializer); + } + + // can end with ", }" or "}" + boolean canContinue = LT(1) == IToken.tCOMMA; + if (canContinue) + consume(); + + switch (LT(1)) { + case IToken.tRBRACE: + int lastOffset = consume().getEndOffset(); + setRange(result, offset, lastOffset); + return result; + + case IToken.tEOC: + setRange(result, offset, LA(1).getOffset()); + return result; + } + + if (!canContinue || LA(1).getOffset() == checkOffset) { + throwBacktrack(offset, LA(1).getEndOffset() - offset); + } + } + // consume the closing brace + } + + private List<? extends ICASTDesignator> designatorList() throws EndOfFileException, BacktrackException { + final int lt1 = LT(1); + if (lt1 == IToken.tDOT || lt1 == IToken.tLBRACKET) { + List<ICASTDesignator> designatorList = null; + while (true) { + switch (LT(1)) { + case IToken.tDOT: + int offset = consume().getOffset(); + IASTName n = identifier(); + ICASTFieldDesignator fieldDesignator = getNodeFactory().newFieldDesignator(n); + setRange(fieldDesignator, offset, calculateEndOffset(n)); + if (designatorList == null) + designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(fieldDesignator); + break; + + case IToken.tLBRACKET: + offset = consume().getOffset(); + IASTExpression constantExpression = expression(); + if (supportGCCStyleDesignators && LT(1) == IToken.tELLIPSIS) { + consume(IToken.tELLIPSIS); + IASTExpression constantExpression2 = expression(); + int lastOffset = consume(IToken.tRBRACKET).getEndOffset(); + IGCCASTArrayRangeDesignator designator = getNodeFactory() + .newArrayRangeDesignatorGCC(constantExpression, constantExpression2); + setRange(designator, offset, lastOffset); + if (designatorList == null) + designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); + } else { + int lastOffset = consume(IToken.tRBRACKET).getEndOffset(); + ICASTArrayDesignator designator = getNodeFactory().newArrayDesignator(constantExpression); + setRange(designator, offset, lastOffset); + if (designatorList == null) + designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); + } + break; + + default: + return designatorList; + } + } + } // fix for 84176: if reach identifier and it's not a designator then return empty designator list if (supportGCCStyleDesignators && lt1 == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { - int offset= LA(1).getOffset(); + int offset = LA(1).getOffset(); IASTName n = identifier(); int lastOffset = consume(IToken.tCOLON).getEndOffset(); ICASTFieldDesignator designator = getNodeFactory().newFieldDesignator(n); @@ -284,161 +282,164 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return Collections.singletonList(designator); } - return null; - } + return null; + } @Override - protected IASTDeclaration declaration(final DeclarationOptions declOption) throws EndOfFileException, BacktrackException { - switch (LT(1)) { - case IToken.t_asm: - return asmDeclaration(); - case IToken.tSEMI: - IToken semi= consume(); - IASTDeclSpecifier declspec= getNodeFactory().newSimpleDeclSpecifier(); - IASTSimpleDeclaration decl= getNodeFactory().newSimpleDeclaration(declspec); - decl.setDeclSpecifier(declspec); - ((ASTNode) declspec).setOffsetAndLength(semi.getOffset(), 0); - ((ASTNode) decl).setOffsetAndLength(semi.getOffset(), semi.getLength()); - return decl; - } - - return simpleDeclaration(declOption); - } - - private IASTDeclaration simpleDeclaration(final DeclarationOptions declOption) throws BacktrackException, EndOfFileException { - if (LT(1) == IToken.tLBRACE) - throwBacktrack(LA(1)); - - final int firstOffset= LA(1).getOffset(); - int endOffset= firstOffset; - boolean insertSemi= false; - - IASTDeclSpecifier declSpec= null; - IASTDeclarator dtor= null; - IASTDeclSpecifier altDeclSpec= null; - IASTDeclarator altDtor= null; - IToken markBeforDtor= null; - try { - Decl decl= declSpecifierSequence_initDeclarator(declOption, true); - markBeforDtor= decl.fDtorToken1; - declSpec= decl.fDeclSpec1; - dtor= decl.fDtor1; - altDeclSpec= decl.fDeclSpec2; - altDtor= decl.fDtor2; - } catch (FoundAggregateInitializer lie) { - declSpec= lie.fDeclSpec; - // scalability: don't keep references to tokens, initializer may be large - declarationMark= null; - dtor= addInitializer(lie, declOption); - } catch (BacktrackException e) { - IASTNode node= e.getNodeBeforeProblem(); - if (node instanceof IASTDeclSpecifier) { - IASTSimpleDeclaration d= getNodeFactory().newSimpleDeclaration((IASTDeclSpecifier) node); - setRange(d, node); - throwBacktrack(e.getProblem(), d); - } - throw e; - } - - IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - if (dtor != null) { - declarators= new IASTDeclarator[]{dtor}; - while (LTcatchEOF(1) == IToken.tCOMMA) { - consume(); - try { - dtor= initDeclarator(declSpec, declOption); - } catch (FoundAggregateInitializer e) { - // scalability: don't keep references to tokens, initializer may be large - declarationMark= null; - markBeforDtor= null; - dtor= addInitializer(e, declOption); - } - declarators= ArrayUtil.append(IASTDeclarator.class, declarators, dtor); - } - declarators= ArrayUtil.removeNulls(IASTDeclarator.class, declarators); - } - - final int lt1= LTcatchEOF(1); - switch (lt1) { - case IToken.tEOC: - endOffset= figureEndOffset(declSpec, declarators); - break; - case IToken.tSEMI: - endOffset= consume().getEndOffset(); - break; - case IToken.tLBRACE: - return functionDefinition(firstOffset, declSpec, declarators); - - default: - insertSemi= true; - if (declOption == DeclarationOptions.LOCAL) { - endOffset= figureEndOffset(declSpec, declarators); - if (firstOffset != endOffset) { - break; - } - } else { - if (markBeforDtor != null) { - endOffset= calculateEndOffset(declSpec); - if (firstOffset != endOffset && !isOnSameLine(endOffset, markBeforDtor.getOffset())) { - backup(markBeforDtor); - declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - break; - } - } - endOffset= figureEndOffset(declSpec, declarators); - if (lt1 == 0) { - break; - } - if (firstOffset != endOffset) { - if (!isOnSameLine(endOffset, LA(1).getOffset())) { - break; - } - if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { - break; - } - } - } - throwBacktrack(LA(1)); - } - - // no function body - IASTSimpleDeclaration simpleDeclaration = getNodeFactory().newSimpleDeclaration(declSpec); - for (IASTDeclarator declarator : declarators) - simpleDeclaration.addDeclarator(declarator); - - setRange(simpleDeclaration, firstOffset, endOffset); + protected IASTDeclaration declaration(final DeclarationOptions declOption) + throws EndOfFileException, BacktrackException { + switch (LT(1)) { + case IToken.t_asm: + return asmDeclaration(); + case IToken.tSEMI: + IToken semi = consume(); + IASTDeclSpecifier declspec = getNodeFactory().newSimpleDeclSpecifier(); + IASTSimpleDeclaration decl = getNodeFactory().newSimpleDeclaration(declspec); + decl.setDeclSpecifier(declspec); + ((ASTNode) declspec).setOffsetAndLength(semi.getOffset(), 0); + ((ASTNode) decl).setOffsetAndLength(semi.getOffset(), semi.getLength()); + return decl; + } + + return simpleDeclaration(declOption); + } + + private IASTDeclaration simpleDeclaration(final DeclarationOptions declOption) + throws BacktrackException, EndOfFileException { + if (LT(1) == IToken.tLBRACE) + throwBacktrack(LA(1)); + + final int firstOffset = LA(1).getOffset(); + int endOffset = firstOffset; + boolean insertSemi = false; + + IASTDeclSpecifier declSpec = null; + IASTDeclarator dtor = null; + IASTDeclSpecifier altDeclSpec = null; + IASTDeclarator altDtor = null; + IToken markBeforDtor = null; + try { + Decl decl = declSpecifierSequence_initDeclarator(declOption, true); + markBeforDtor = decl.fDtorToken1; + declSpec = decl.fDeclSpec1; + dtor = decl.fDtor1; + altDeclSpec = decl.fDeclSpec2; + altDtor = decl.fDtor2; + } catch (FoundAggregateInitializer lie) { + declSpec = lie.fDeclSpec; + // scalability: don't keep references to tokens, initializer may be large + declarationMark = null; + dtor = addInitializer(lie, declOption); + } catch (BacktrackException e) { + IASTNode node = e.getNodeBeforeProblem(); + if (node instanceof IASTDeclSpecifier) { + IASTSimpleDeclaration d = getNodeFactory().newSimpleDeclaration((IASTDeclSpecifier) node); + setRange(d, node); + throwBacktrack(e.getProblem(), d); + } + throw e; + } + + IASTDeclarator[] declarators = IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + if (dtor != null) { + declarators = new IASTDeclarator[] { dtor }; + while (LTcatchEOF(1) == IToken.tCOMMA) { + consume(); + try { + dtor = initDeclarator(declSpec, declOption); + } catch (FoundAggregateInitializer e) { + // scalability: don't keep references to tokens, initializer may be large + declarationMark = null; + markBeforDtor = null; + dtor = addInitializer(e, declOption); + } + declarators = ArrayUtil.append(IASTDeclarator.class, declarators, dtor); + } + declarators = ArrayUtil.removeNulls(IASTDeclarator.class, declarators); + } + + final int lt1 = LTcatchEOF(1); + switch (lt1) { + case IToken.tEOC: + endOffset = figureEndOffset(declSpec, declarators); + break; + case IToken.tSEMI: + endOffset = consume().getEndOffset(); + break; + case IToken.tLBRACE: + return functionDefinition(firstOffset, declSpec, declarators); + + default: + insertSemi = true; + if (declOption == DeclarationOptions.LOCAL) { + endOffset = figureEndOffset(declSpec, declarators); + if (firstOffset != endOffset) { + break; + } + } else { + if (markBeforDtor != null) { + endOffset = calculateEndOffset(declSpec); + if (firstOffset != endOffset && !isOnSameLine(endOffset, markBeforDtor.getOffset())) { + backup(markBeforDtor); + declarators = IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + break; + } + } + endOffset = figureEndOffset(declSpec, declarators); + if (lt1 == 0) { + break; + } + if (firstOffset != endOffset) { + if (!isOnSameLine(endOffset, LA(1).getOffset())) { + break; + } + if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { + break; + } + } + } + throwBacktrack(LA(1)); + } + + // no function body + IASTSimpleDeclaration simpleDeclaration = getNodeFactory().newSimpleDeclaration(declSpec); + for (IASTDeclarator declarator : declarators) + simpleDeclaration.addDeclarator(declarator); + + setRange(simpleDeclaration, firstOffset, endOffset); if (altDeclSpec != null && altDtor != null) { simpleDeclaration = new CASTAmbiguousSimpleDeclaration(simpleDeclaration, altDeclSpec, altDtor); setRange(simpleDeclaration, firstOffset, endOffset); } - if (insertSemi) { - IASTProblem problem= createProblem(IProblem.MISSING_SEMICOLON, endOffset-1, 1); - throwBacktrack(problem, simpleDeclaration); - } - return simpleDeclaration; - } + if (insertSemi) { + IASTProblem problem = createProblem(IProblem.MISSING_SEMICOLON, endOffset - 1, 1); + throwBacktrack(problem, simpleDeclaration); + } + return simpleDeclaration; + } private IASTDeclaration functionDefinition(int firstOffset, IASTDeclSpecifier declSpec, IASTDeclarator[] declarators) throws BacktrackException, EndOfFileException { if (declarators.length != 1) - throwBacktrack(firstOffset, LA(1).getEndOffset()); + throwBacktrack(firstOffset, LA(1).getEndOffset()); - final IASTDeclarator outerDtor= declarators[0]; - final IASTDeclarator fdtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); + final IASTDeclarator outerDtor = declarators[0]; + final IASTDeclarator fdtor = ASTQueries.findTypeRelevantDeclarator(outerDtor); if (!(fdtor instanceof IASTFunctionDeclarator)) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); - IASTFunctionDefinition funcDefinition = getNodeFactory().newFunctionDefinition(declSpec, (IASTFunctionDeclarator) fdtor, null); + IASTFunctionDefinition funcDefinition = getNodeFactory().newFunctionDefinition(declSpec, + (IASTFunctionDeclarator) fdtor, null); try { - IASTStatement s= handleFunctionBody(); + IASTStatement s = handleFunctionBody(); funcDefinition.setBody(s); ((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, calculateEndOffset(s) - firstOffset); return funcDefinition; } catch (BacktrackException bt) { - final IASTNode n= bt.getNodeBeforeProblem(); + final IASTNode n = bt.getNodeBeforeProblem(); if (n instanceof IASTCompoundStatement) { funcDefinition.setBody((IASTCompoundStatement) n); ((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, calculateEndOffset(n) - firstOffset); @@ -448,7 +449,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } } - @Override protected void setupTranslationUnit() throws DOMException { translationUnit = getNodeFactory().newTranslationUnit(scanner); @@ -469,31 +469,31 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTExpression constantExpression() throws BacktrackException, EndOfFileException { - return expression(ExprKind.eConstant); - } + return expression(ExprKind.eConstant); + } - private IASTExpression expression(final ExprKind kind) throws EndOfFileException, BacktrackException { - final boolean allowComma= kind == ExprKind.eExpression; - boolean allowAssignment= kind != ExprKind.eConstant; + private IASTExpression expression(final ExprKind kind) throws EndOfFileException, BacktrackException { + final boolean allowComma = kind == ExprKind.eExpression; + boolean allowAssignment = kind != ExprKind.eConstant; int lt1; - int conditionCount= 0; - BinaryOperator lastOperator= null; - IASTExpression lastExpression= castExpression(CastExprCtx.eDirectlyInBExpr, null); + int conditionCount = 0; + BinaryOperator lastOperator = null; + IASTExpression lastExpression = castExpression(CastExprCtx.eDirectlyInBExpr, null); loop: while (true) { - lt1= LT(1); + lt1 = LT(1); switch (lt1) { - case IToken.tQUESTION: + case IToken.tQUESTION: conditionCount++; // <logical-or> ? <expression> : <assignment-expression> // Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 25, 0); + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 25, 0); if (LT(2) == IToken.tCOLON) { // Gnu extension: The expression after '?' can be omitted. - consume(); // Consume operator - lastExpression= null; // Next cast expression is just null + consume(); // Consume operator + lastExpression = null; // Next cast expression is just null continue; } - allowAssignment= true; // assignment expressions will be subsumed by the conditional expression + allowAssignment = true; // assignment expressions will be subsumed by the conditional expression break; case IToken.tCOLON: @@ -502,166 +502,169 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // <logical-or> ? <expression> : <assignment-expression> // Precedence: 0 is lower than precedence of expression; 15 is lower than precedence of assignment; - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 0, 15); - allowAssignment= true; // assignment expressions will be subsumed by the conditional expression - break; + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 0, 15); + allowAssignment = true; // assignment expressions will be subsumed by the conditional expression + break; case IToken.tCOMMA: if (!allowComma && conditionCount == 0) break loop; // Lowest precedence except inside the conditional expression - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 10, 11); - break; - - case IToken.tASSIGN: - case IToken.tSTARASSIGN: - case IToken.tDIVASSIGN: - case IToken.tMODASSIGN: - case IToken.tPLUSASSIGN: - case IToken.tMINUSASSIGN: - case IToken.tSHIFTRASSIGN: - case IToken.tSHIFTLASSIGN: - case IToken.tAMPERASSIGN: - case IToken.tXORASSIGN: - case IToken.tBITORASSIGN: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 10, 11); + break; + + case IToken.tASSIGN: + case IToken.tSTARASSIGN: + case IToken.tDIVASSIGN: + case IToken.tMODASSIGN: + case IToken.tPLUSASSIGN: + case IToken.tMINUSASSIGN: + case IToken.tSHIFTRASSIGN: + case IToken.tSHIFTLASSIGN: + case IToken.tAMPERASSIGN: + case IToken.tXORASSIGN: + case IToken.tBITORASSIGN: if (!allowAssignment && conditionCount == 0) break loop; - // Assignments group right to left - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 21, 20); - break; - - case IToken.tOR: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 30, 31); - break; - case IToken.tAND: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 40, 41); - break; - case IToken.tBITOR: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 50, 51); - break; - case IToken.tXOR: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 60, 61); - break; - case IToken.tAMPER: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 70, 71); - break; - case IToken.tEQUAL: - case IToken.tNOTEQUAL: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 80, 81); - break; - case IToken.tGT: - case IToken.tLT: - case IToken.tLTEQUAL: - case IToken.tGTEQUAL: - case IGCCToken.tMAX: - case IGCCToken.tMIN: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 90, 91); - break; - case IToken.tSHIFTL: - case IToken.tSHIFTR: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 100, 101); - break; - case IToken.tPLUS: - case IToken.tMINUS: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 110, 111); - break; - case IToken.tSTAR: - case IToken.tDIV: - case IToken.tMOD: - lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 120, 121); - break; - default: - break loop; + // Assignments group right to left + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 21, 20); + break; + + case IToken.tOR: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 30, 31); + break; + case IToken.tAND: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 40, 41); + break; + case IToken.tBITOR: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 50, 51); + break; + case IToken.tXOR: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 60, 61); + break; + case IToken.tAMPER: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 70, 71); + break; + case IToken.tEQUAL: + case IToken.tNOTEQUAL: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 80, 81); + break; + case IToken.tGT: + case IToken.tLT: + case IToken.tLTEQUAL: + case IToken.tGTEQUAL: + case IGCCToken.tMAX: + case IGCCToken.tMIN: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 90, 91); + break; + case IToken.tSHIFTL: + case IToken.tSHIFTR: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 100, 101); + break; + case IToken.tPLUS: + case IToken.tMINUS: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 110, 111); + break; + case IToken.tSTAR: + case IToken.tDIV: + case IToken.tMOD: + lastOperator = new BinaryOperator(lastOperator, lastExpression, lt1, 120, 121); + break; + default: + break loop; } - consume(); // consume operator - lastExpression= castExpression(CastExprCtx.eDirectlyInBExpr, null); // next cast expression + consume(); // consume operator + lastExpression = castExpression(CastExprCtx.eDirectlyInBExpr, null); // next cast expression } - // Check for incomplete conditional expression - if (lt1 != IToken.tEOC && conditionCount > 0) - throwBacktrack(LA(1)); + // Check for incomplete conditional expression + if (lt1 != IToken.tEOC && conditionCount > 0) + throwBacktrack(LA(1)); - return buildExpression(lastOperator, lastExpression); + return buildExpression(lastOperator, lastExpression); + } + + @Override + protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, + int lastOffset) { + IASTBinaryExpression result = getNodeFactory().newBinaryExpression(operator, expr1, (IASTExpression) expr2); + int o = ((ASTNode) expr1).getOffset(); + ((ASTNode) result).setOffsetAndLength(o, lastOffset - o); + return result; } - @Override - protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset) { - IASTBinaryExpression result = getNodeFactory().newBinaryExpression(operator, expr1, (IASTExpression) expr2); - int o = ((ASTNode) expr1).getOffset(); - ((ASTNode) result).setOffsetAndLength(o, lastOffset - o); - return result; - } - - @Override - protected IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { - switch (LT(1)) { - case IToken.tSTAR: - return unaryExpression(IASTUnaryExpression.op_star, ctx, strat); - case IToken.tAMPER: - return unaryExpression(IASTUnaryExpression.op_amper, ctx, strat); - case IToken.tAND: - return unaryExpression(IASTUnaryExpression.op_labelReference, ctx, strat); - case IToken.tPLUS: - return unaryExpression(IASTUnaryExpression.op_plus, ctx, strat); - case IToken.tMINUS: - return unaryExpression(IASTUnaryExpression.op_minus, ctx, strat); - case IToken.tNOT: - return unaryExpression(IASTUnaryExpression.op_not, ctx, strat); - case IToken.tBITCOMPLEMENT: - return unaryExpression(IASTUnaryExpression.op_tilde, ctx, strat); - case IToken.tINCR: - return unaryExpression(IASTUnaryExpression.op_prefixIncr, ctx, strat); - case IToken.tDECR: - return unaryExpression(IASTUnaryExpression.op_prefixDecr, ctx, strat); - case IToken.t_sizeof: - return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), - IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat); - case IToken.t__Alignof: - case IGCCToken.t___alignof__: - return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), - IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat); - default: - return postfixExpression(ctx, strat); - } - } - - private IASTExpression postfixExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { - IASTExpression firstExpression = null; - switch (LT(1)) { - case IToken.tLPAREN: - // (type-name) { initializer-list } - // (type-name) { initializer-list , } - IToken m = mark(); - try { - int offset = consume().getOffset(); - IASTTypeId t= typeId(DeclarationOptions.TYPEID); - consume(IToken.tRPAREN); - if (LT(1) == IToken.tLBRACE) { - IASTInitializer i = (IASTInitializerList) initClause(); - firstExpression= getNodeFactory().newTypeIdInitializerExpression(t, i); - setRange(firstExpression, offset, calculateEndOffset(i)); - break; - } - } catch (BacktrackException bt) { - } - backup(m); - firstExpression= primaryExpression(ctx, strat); - break; - - default: - firstExpression = primaryExpression(ctx, strat); - break; - } - - IASTExpression secondExpression = null; - for (;;) { - switch (LT(1)) { - case IToken.tLBRACKET: - // array access - consume(); - secondExpression = expression(); - int last; + @Override + protected IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { + switch (LT(1)) { + case IToken.tSTAR: + return unaryExpression(IASTUnaryExpression.op_star, ctx, strat); + case IToken.tAMPER: + return unaryExpression(IASTUnaryExpression.op_amper, ctx, strat); + case IToken.tAND: + return unaryExpression(IASTUnaryExpression.op_labelReference, ctx, strat); + case IToken.tPLUS: + return unaryExpression(IASTUnaryExpression.op_plus, ctx, strat); + case IToken.tMINUS: + return unaryExpression(IASTUnaryExpression.op_minus, ctx, strat); + case IToken.tNOT: + return unaryExpression(IASTUnaryExpression.op_not, ctx, strat); + case IToken.tBITCOMPLEMENT: + return unaryExpression(IASTUnaryExpression.op_tilde, ctx, strat); + case IToken.tINCR: + return unaryExpression(IASTUnaryExpression.op_prefixIncr, ctx, strat); + case IToken.tDECR: + return unaryExpression(IASTUnaryExpression.op_prefixDecr, ctx, strat); + case IToken.t_sizeof: + return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), + IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat); + case IToken.t__Alignof: + case IGCCToken.t___alignof__: + return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), + IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat); + default: + return postfixExpression(ctx, strat); + } + } + + private IASTExpression postfixExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { + IASTExpression firstExpression = null; + switch (LT(1)) { + case IToken.tLPAREN: + // (type-name) { initializer-list } + // (type-name) { initializer-list , } + IToken m = mark(); + try { + int offset = consume().getOffset(); + IASTTypeId t = typeId(DeclarationOptions.TYPEID); + consume(IToken.tRPAREN); + if (LT(1) == IToken.tLBRACE) { + IASTInitializer i = (IASTInitializerList) initClause(); + firstExpression = getNodeFactory().newTypeIdInitializerExpression(t, i); + setRange(firstExpression, offset, calculateEndOffset(i)); + break; + } + } catch (BacktrackException bt) { + } + backup(m); + firstExpression = primaryExpression(ctx, strat); + break; + + default: + firstExpression = primaryExpression(ctx, strat); + break; + } + + IASTExpression secondExpression = null; + for (;;) { + switch (LT(1)) { + case IToken.tLBRACKET: + // array access + consume(); + secondExpression = expression(); + int last; switch (LT(1)) { case IToken.tRBRACKET: last = consume().getEndOffset(); @@ -673,583 +676,587 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { throw backtrack; } - IASTArraySubscriptExpression s = getNodeFactory().newArraySubscriptExpression(firstExpression, secondExpression); - ((ASTNode) s).setOffsetAndLength(((ASTNode) firstExpression).getOffset(), - last - ((ASTNode) firstExpression).getOffset()); - firstExpression = s; - break; - case IToken.tLPAREN: - // function call - int endOffset; - List<IASTExpression> argList= null; - consume(IToken.tLPAREN); - boolean isFirst= true; - while (true) { - final int lt1= LT(1); - if (lt1 == IToken.tRPAREN) { - endOffset= consume().getEndOffset(); - break; - } else if (lt1 == IToken.tEOC) { - endOffset= LA(1).getEndOffset(); - break; - } - if (isFirst) { - isFirst= false; - } else { - consume(IToken.tCOMMA); - } - - IASTExpression expr= expression(ExprKind.eAssignment); - if (argList == null) { - argList= new ArrayList<>(); - } - argList.add(expr); - } + IASTArraySubscriptExpression s = getNodeFactory().newArraySubscriptExpression(firstExpression, + secondExpression); + ((ASTNode) s).setOffsetAndLength(((ASTNode) firstExpression).getOffset(), + last - ((ASTNode) firstExpression).getOffset()); + firstExpression = s; + break; + case IToken.tLPAREN: + // function call + int endOffset; + List<IASTExpression> argList = null; + consume(IToken.tLPAREN); + boolean isFirst = true; + while (true) { + final int lt1 = LT(1); + if (lt1 == IToken.tRPAREN) { + endOffset = consume().getEndOffset(); + break; + } else if (lt1 == IToken.tEOC) { + endOffset = LA(1).getEndOffset(); + break; + } + if (isFirst) { + isFirst = false; + } else { + consume(IToken.tCOMMA); + } + + IASTExpression expr = expression(ExprKind.eAssignment); + if (argList == null) { + argList = new ArrayList<>(); + } + argList.add(expr); + } final IASTExpression[] args; if (argList == null) { - args= IASTExpression.EMPTY_EXPRESSION_ARRAY; + args = IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { - args= argList.toArray(new IASTExpression[argList.size()]); + args = argList.toArray(new IASTExpression[argList.size()]); } IASTFunctionCallExpression f = getNodeFactory().newFunctionCallExpression(firstExpression, args); - firstExpression = setRange(f, firstExpression, endOffset); - break; - case IToken.tINCR: - int offset = consume().getEndOffset(); - firstExpression = buildUnaryExpression( - IASTUnaryExpression.op_postFixIncr, firstExpression, - ((ASTNode) firstExpression).getOffset(), offset); - break; - case IToken.tDECR: - offset = consume().getEndOffset(); - firstExpression = buildUnaryExpression( - IASTUnaryExpression.op_postFixDecr, firstExpression, - ((ASTNode) firstExpression).getOffset(), offset); - break; - case IToken.tDOT: - // member access - IToken dot = consume(); - IASTName name = identifier(); - if (name == null) - throwBacktrack(((ASTNode) firstExpression).getOffset(), - ((ASTNode) firstExpression).getLength() + dot.getLength()); - IASTFieldReference result = getNodeFactory().newFieldReference(name, firstExpression); - result.setIsPointerDereference(false); - ((ASTNode) result).setOffsetAndLength( - ((ASTNode) firstExpression).getOffset(), - calculateEndOffset(name) - ((ASTNode) firstExpression).getOffset()); - firstExpression = result; - break; - case IToken.tARROW: - // member access - IToken arrow = consume(); - name = identifier(); - if (name == null) - throwBacktrack(((ASTNode) firstExpression).getOffset(), - ((ASTNode) firstExpression).getLength() + arrow.getLength()); - result = getNodeFactory().newFieldReference(name, firstExpression); - result.setIsPointerDereference(true); - ((ASTNode) result).setOffsetAndLength( - ((ASTNode) firstExpression).getOffset(), - calculateEndOffset(name) - ((ASTNode) firstExpression).getOffset()); - firstExpression = result; - break; - default: - return firstExpression; - } - } - } - - @Override - protected IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { - IToken t = null; - IASTLiteralExpression literalExpression = null; - switch (LT(1)) { - // TO DO: we need more literals... - case IToken.tINTEGER: - t = consume(); - literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage()); - ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); - return literalExpression; - case IToken.tFLOATINGPT: - t = consume(); - literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage()); - ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); - return literalExpression; - case IToken.tSTRING: - case IToken.tLSTRING: - case IToken.tUTF16STRING: - case IToken.tUTF32STRING: - t = consume(); - literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_string_literal, t.getImage()); - ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); - return literalExpression; - case IToken.tCHAR: - case IToken.tLCHAR: - case IToken.tUTF16CHAR: - case IToken.tUTF32CHAR: - t = consume(); - literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_char_constant, t.getImage()); - ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getLength()); - return literalExpression; - case IToken.tLPAREN: - if (supportStatementsInExpressions && LT(2) == IToken.tLBRACE) { - return compoundStatementExpression(); - } - t = consume(); - IASTExpression lhs = expression(ExprKind.eExpression); // instead of expression(), to keep the stack smaller - int finalOffset = 0; - switch (LT(1)) { - case IToken.tRPAREN: - case IToken.tEOC: - finalOffset = consume().getEndOffset(); - break; - default: - throwBacktrack(LA(1)); - } - return buildUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset); - case IToken.tIDENTIFIER: - case IToken.tCOMPLETION: - case IToken.tEOC: - int startingOffset = LA(1).getOffset(); - IASTName name = identifier(); - IASTIdExpression idExpression = getNodeFactory().newIdExpression(name); - ((ASTNode) idExpression).setOffsetAndLength((ASTNode) name); - return idExpression; - default: - IToken la = LA(1); - startingOffset = la.getOffset(); - throwBacktrack(startingOffset, la.getLength()); - return null; - } - - } - - - @Override + firstExpression = setRange(f, firstExpression, endOffset); + break; + case IToken.tINCR: + int offset = consume().getEndOffset(); + firstExpression = buildUnaryExpression(IASTUnaryExpression.op_postFixIncr, firstExpression, + ((ASTNode) firstExpression).getOffset(), offset); + break; + case IToken.tDECR: + offset = consume().getEndOffset(); + firstExpression = buildUnaryExpression(IASTUnaryExpression.op_postFixDecr, firstExpression, + ((ASTNode) firstExpression).getOffset(), offset); + break; + case IToken.tDOT: + // member access + IToken dot = consume(); + IASTName name = identifier(); + if (name == null) + throwBacktrack(((ASTNode) firstExpression).getOffset(), + ((ASTNode) firstExpression).getLength() + dot.getLength()); + IASTFieldReference result = getNodeFactory().newFieldReference(name, firstExpression); + result.setIsPointerDereference(false); + ((ASTNode) result).setOffsetAndLength(((ASTNode) firstExpression).getOffset(), + calculateEndOffset(name) - ((ASTNode) firstExpression).getOffset()); + firstExpression = result; + break; + case IToken.tARROW: + // member access + IToken arrow = consume(); + name = identifier(); + if (name == null) + throwBacktrack(((ASTNode) firstExpression).getOffset(), + ((ASTNode) firstExpression).getLength() + arrow.getLength()); + result = getNodeFactory().newFieldReference(name, firstExpression); + result.setIsPointerDereference(true); + ((ASTNode) result).setOffsetAndLength(((ASTNode) firstExpression).getOffset(), + calculateEndOffset(name) - ((ASTNode) firstExpression).getOffset()); + firstExpression = result; + break; + default: + return firstExpression; + } + } + } + + @Override + protected IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { + IToken t = null; + IASTLiteralExpression literalExpression = null; + switch (LT(1)) { + // TO DO: we need more literals... + case IToken.tINTEGER: + t = consume(); + literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_integer_constant, + t.getImage()); + ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); + return literalExpression; + case IToken.tFLOATINGPT: + t = consume(); + literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_float_constant, + t.getImage()); + ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); + return literalExpression; + case IToken.tSTRING: + case IToken.tLSTRING: + case IToken.tUTF16STRING: + case IToken.tUTF32STRING: + t = consume(); + literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_string_literal, + t.getImage()); + ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); + return literalExpression; + case IToken.tCHAR: + case IToken.tLCHAR: + case IToken.tUTF16CHAR: + case IToken.tUTF32CHAR: + t = consume(); + literalExpression = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_char_constant, + t.getImage()); + ((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getLength()); + return literalExpression; + case IToken.tLPAREN: + if (supportStatementsInExpressions && LT(2) == IToken.tLBRACE) { + return compoundStatementExpression(); + } + t = consume(); + IASTExpression lhs = expression(ExprKind.eExpression); // instead of expression(), to keep the stack smaller + int finalOffset = 0; + switch (LT(1)) { + case IToken.tRPAREN: + case IToken.tEOC: + finalOffset = consume().getEndOffset(); + break; + default: + throwBacktrack(LA(1)); + } + return buildUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset); + case IToken.tIDENTIFIER: + case IToken.tCOMPLETION: + case IToken.tEOC: + int startingOffset = LA(1).getOffset(); + IASTName name = identifier(); + IASTIdExpression idExpression = getNodeFactory().newIdExpression(name); + ((ASTNode) idExpression).setOffsetAndLength((ASTNode) name); + return idExpression; + default: + IToken la = LA(1); + startingOffset = la.getOffset(); + throwBacktrack(startingOffset, la.getLength()); + return null; + } + + } + + @Override protected IASTTypeId typeId(DeclarationOptions option) throws EndOfFileException, BacktrackException { - if (!canBeTypeSpecifier()) { - return null; - } - final int offset = mark().getOffset(); - IASTDeclSpecifier declSpecifier = null; - IASTDeclarator declarator = null; - - fPreventKnrCheck++; - try { - Decl decl= declSpecifierSequence_initDeclarator(option, false); - declSpecifier= decl.fDeclSpec1; - declarator= decl.fDtor1; - } catch (FoundAggregateInitializer lie) { - // type-ids have not compound initializers - throwBacktrack(lie.fDeclarator); - } finally { - fPreventKnrCheck--; - } - - IASTTypeId result = getNodeFactory().newTypeId(declSpecifier, declarator); - setRange(result, offset, figureEndOffset(declSpecifier, declarator)); - return result; - } - - /** - * Parse a Pointer Operator. - * - * ptrOperator : "*" (cvQualifier)* | "&" | ::? nestedNameSpecifier "*" - * (cvQualifier)* - * - * @throws BacktrackException to request a backtrack - */ - protected void consumePointerOperators(List<IASTPointerOperator> pointerOps) - throws EndOfFileException, BacktrackException { - for (;;) { - // __attribute__ in-between pointers - __attribute_decl_seq(supportAttributeSpecifiers, false); - - IToken mark = mark(); - IToken last = null; - - boolean isConst = false, isVolatile = false, isRestrict = false; - - if (LT(1) != IToken.tSTAR) { - backup(mark); - break; - } - - last = consume(); - int startOffset = mark.getOffset(); - for (;;) { - IToken t = LA(1); - switch (LT(1)) { - case IToken.t_const: - last = consume(); - isConst = true; - break; - case IToken.t_volatile: - last = consume(); - isVolatile = true; - break; - case IToken.t_restrict: - last = consume(); - isRestrict = true; - break; - } - - if (t == LA(1)) - break; - } - - ICASTPointer po = getNodeFactory().newPointer(); - ((ASTNode) po).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset); - po.setConst(isConst); - po.setVolatile(isVolatile); - po.setRestrict(isRestrict); - pointerOps.add(po); - } - } - - - private final static int INLINE=0x1, CONST=0x2, RESTRICT=0x4, VOLATILE=0x8, - SHORT=0x10, UNSIGNED= 0x20, SIGNED=0x40, COMPLEX=0x80, IMAGINARY=0x100; - - @Override - protected Decl declSpecifierSeq(final DeclarationOptions declOption, ITemplateIdStrategy strat) + if (!canBeTypeSpecifier()) { + return null; + } + final int offset = mark().getOffset(); + IASTDeclSpecifier declSpecifier = null; + IASTDeclarator declarator = null; + + fPreventKnrCheck++; + try { + Decl decl = declSpecifierSequence_initDeclarator(option, false); + declSpecifier = decl.fDeclSpec1; + declarator = decl.fDtor1; + } catch (FoundAggregateInitializer lie) { + // type-ids have not compound initializers + throwBacktrack(lie.fDeclarator); + } finally { + fPreventKnrCheck--; + } + + IASTTypeId result = getNodeFactory().newTypeId(declSpecifier, declarator); + setRange(result, offset, figureEndOffset(declSpecifier, declarator)); + return result; + } + + /** + * Parse a Pointer Operator. + * + * ptrOperator : "*" (cvQualifier)* | "&" | ::? nestedNameSpecifier "*" + * (cvQualifier)* + * + * @throws BacktrackException to request a backtrack + */ + protected void consumePointerOperators(List<IASTPointerOperator> pointerOps) + throws EndOfFileException, BacktrackException { + for (;;) { + // __attribute__ in-between pointers + __attribute_decl_seq(supportAttributeSpecifiers, false); + + IToken mark = mark(); + IToken last = null; + + boolean isConst = false, isVolatile = false, isRestrict = false; + + if (LT(1) != IToken.tSTAR) { + backup(mark); + break; + } + + last = consume(); + int startOffset = mark.getOffset(); + for (;;) { + IToken t = LA(1); + switch (LT(1)) { + case IToken.t_const: + last = consume(); + isConst = true; + break; + case IToken.t_volatile: + last = consume(); + isVolatile = true; + break; + case IToken.t_restrict: + last = consume(); + isRestrict = true; + break; + } + + if (t == LA(1)) + break; + } + + ICASTPointer po = getNodeFactory().newPointer(); + ((ASTNode) po).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset); + po.setConst(isConst); + po.setVolatile(isVolatile); + po.setRestrict(isRestrict); + pointerOps.add(po); + } + } + + private final static int INLINE = 0x1, CONST = 0x2, RESTRICT = 0x4, VOLATILE = 0x8, SHORT = 0x10, UNSIGNED = 0x20, + SIGNED = 0x40, COMPLEX = 0x80, IMAGINARY = 0x100; + + @Override + protected Decl declSpecifierSeq(final DeclarationOptions declOption, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { - int storageClass= IASTDeclSpecifier.sc_unspecified; - int simpleType= IASTSimpleDeclSpecifier.t_unspecified; - int options= 0; - int isLong= 0; - - IToken returnToken= null; - ICASTDeclSpecifier result= null; - ICASTDeclSpecifier altResult= null; - IASTAlignmentSpecifier[] alignmentSpecifiers = IASTAlignmentSpecifier.EMPTY_ALIGNMENT_SPECIFIER_ARRAY; - List<IASTAttributeSpecifier> attributes = null; - try { - IASTName identifier= null; - IASTExpression typeofExpression= null; - IASTProblem problem= null; - - boolean encounteredRawType= false; - boolean encounteredTypename= false; - - final int offset= LA(1).getOffset(); - int endOffset= offset; - - declSpecifiers: for (;;) { - final int lt1= LTcatchEOF(1); - switch (lt1) { - case 0: // eof - break declSpecifiers; - // storage class specifiers - case IToken.t_auto: - storageClass = IASTDeclSpecifier.sc_auto; - endOffset= consume().getEndOffset(); - break; - case IToken.t_register: - storageClass = IASTDeclSpecifier.sc_register; - endOffset= consume().getEndOffset(); - break; - case IToken.t_static: - storageClass = IASTDeclSpecifier.sc_static; - endOffset= consume().getEndOffset(); - break; - case IToken.t_extern: - storageClass = IASTDeclSpecifier.sc_extern; - endOffset= consume().getEndOffset(); - break; - case IToken.t_typedef: - storageClass = IASTDeclSpecifier.sc_typedef; - endOffset= consume().getEndOffset(); - break; - - // Function Specifier - case IToken.t_inline: - options |= INLINE; - endOffset= consume().getEndOffset(); - break; - - // Type Qualifiers - case IToken.t_const: - options |= CONST; - endOffset= consume().getEndOffset(); - break; - case IToken.t_volatile: - options |= VOLATILE; - endOffset= consume().getEndOffset(); - break; - case IToken.t_restrict: - options |= RESTRICT; - endOffset= consume().getEndOffset(); - break; - - // Type Specifiers - case IToken.t_void: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_void; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_char: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_char; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_short: - if (encounteredTypename) - break declSpecifiers; - options |= SHORT; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_int: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_int; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IGCCToken.t__int128: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_int128; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_long: - if (encounteredTypename) - break declSpecifiers; - isLong++; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_float: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_float; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_double: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_double; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IGCCToken.t__float128: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_float128; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IGCCToken.t_decimal32: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_decimal32; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IGCCToken.t_decimal64: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_decimal64; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IGCCToken.t_decimal128: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_decimal128; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_signed: - if (encounteredTypename) - break declSpecifiers; - options |= SIGNED; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_unsigned: - if (encounteredTypename) - break declSpecifiers; - options |= UNSIGNED; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t__Bool: - if (encounteredTypename) - break declSpecifiers; - simpleType = IASTSimpleDeclSpecifier.t_bool; - encounteredRawType= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t__Complex: - if (encounteredTypename) - break declSpecifiers; - options |= COMPLEX; - endOffset= consume().getEndOffset(); - break; - case IToken.t__Imaginary: - if (encounteredTypename) - break declSpecifiers; - options |= IMAGINARY; - endOffset= consume().getEndOffset(); - break; - - case IToken.tIDENTIFIER: - case IToken.tCOMPLETION: - case IToken.tEOC: - if (encounteredTypename || encounteredRawType) - break declSpecifiers; - - if ((endOffset != offset || declOption.fAllowEmptySpecifier) && LT(1) != IToken.tCOMPLETION) { - altResult= buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); - returnToken= mark(); - } - - identifier = identifier(); - endOffset= calculateEndOffset(identifier); - encounteredTypename= true; - break; - case IToken.t_struct: - case IToken.t_union: - if (encounteredTypename || encounteredRawType) - break declSpecifiers; - try { - result= structOrUnionSpecifier(); - } catch (BacktrackException bt) { - result= elaboratedTypeSpecifier(); - } - endOffset= calculateEndOffset(result); - encounteredTypename= true; - break; - case IToken.t_enum: - if (encounteredTypename || encounteredRawType) - break declSpecifiers; - try { - result= (ICASTEnumerationSpecifier) enumSpecifier(); - } catch (BacktrackException bt) { - if (bt.getNodeBeforeProblem() instanceof ICASTDeclSpecifier) { - result= (ICASTDeclSpecifier) bt.getNodeBeforeProblem(); - problem = bt.getProblem(); - break declSpecifiers; - } else { - result= elaboratedTypeSpecifier(); - } - } - endOffset= calculateEndOffset(result); - encounteredTypename= true; - break; - - case IToken.t__Alignas: - alignmentSpecifiers = ArrayUtil.append(alignmentSpecifiers, alignmentSpecifier()); - break; - - case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec - if (!supportAttributeSpecifiers) - throwBacktrack(LA(1)); - attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, false)); - break; - case IGCCToken.t__declspec: // __declspec precedes the identifier - if (identifier != null || !supportDeclspecSpecifiers) - throwBacktrack(LA(1)); - __attribute_decl_seq(false, true); - break; - - case IGCCToken.t_typeof: - if (encounteredRawType || encounteredTypename) - throwBacktrack(LA(1)); - - simpleType= IASTSimpleDeclSpecifier.t_typeof; - consume(IGCCToken.t_typeof); - typeofExpression = parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), - IASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotInBExpr, null); - - encounteredTypename= true; - endOffset= calculateEndOffset(typeofExpression); - break; - - default: - if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) { - handleOtherDeclSpecModifier(); - endOffset= LA(1).getOffset(); - break; - } - break declSpecifiers; - } - - if (encounteredRawType && encounteredTypename) - throwBacktrack(LA(1)); - } - - // check for empty specification - if (!encounteredRawType && !encounteredTypename && LT(1) != IToken.tEOC && !declOption.fAllowEmptySpecifier) { - if (offset == endOffset) { - throwBacktrack(LA(1)); - } - } - - if (result != null) { - configureDeclSpec(result, storageClass, options); - if ((options & RESTRICT) != 0) { - if (result instanceof ICASTCompositeTypeSpecifier) { - ((ICASTCompositeTypeSpecifier) result).setRestrict(true); - } else if (result instanceof CASTEnumerationSpecifier) { - ((CASTEnumerationSpecifier) result).setRestrict(true); - } else if (result instanceof CASTElaboratedTypeSpecifier) { - ((CASTElaboratedTypeSpecifier) result).setRestrict(true); - } - } - setRange(result, offset, endOffset); - if (problem != null) - throwBacktrack(problem, result); - } else if (identifier != null) { - result= buildNamedTypeSpecifier(identifier, storageClass, options, offset, endOffset); - } else { - result= buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); - } - result.setAlignmentSpecifiers(ArrayUtil.trim(alignmentSpecifiers)); + int storageClass = IASTDeclSpecifier.sc_unspecified; + int simpleType = IASTSimpleDeclSpecifier.t_unspecified; + int options = 0; + int isLong = 0; + + IToken returnToken = null; + ICASTDeclSpecifier result = null; + ICASTDeclSpecifier altResult = null; + IASTAlignmentSpecifier[] alignmentSpecifiers = IASTAlignmentSpecifier.EMPTY_ALIGNMENT_SPECIFIER_ARRAY; + List<IASTAttributeSpecifier> attributes = null; + try { + IASTName identifier = null; + IASTExpression typeofExpression = null; + IASTProblem problem = null; + + boolean encounteredRawType = false; + boolean encounteredTypename = false; + + final int offset = LA(1).getOffset(); + int endOffset = offset; + + declSpecifiers: for (;;) { + final int lt1 = LTcatchEOF(1); + switch (lt1) { + case 0: // eof + break declSpecifiers; + // storage class specifiers + case IToken.t_auto: + storageClass = IASTDeclSpecifier.sc_auto; + endOffset = consume().getEndOffset(); + break; + case IToken.t_register: + storageClass = IASTDeclSpecifier.sc_register; + endOffset = consume().getEndOffset(); + break; + case IToken.t_static: + storageClass = IASTDeclSpecifier.sc_static; + endOffset = consume().getEndOffset(); + break; + case IToken.t_extern: + storageClass = IASTDeclSpecifier.sc_extern; + endOffset = consume().getEndOffset(); + break; + case IToken.t_typedef: + storageClass = IASTDeclSpecifier.sc_typedef; + endOffset = consume().getEndOffset(); + break; + + // Function Specifier + case IToken.t_inline: + options |= INLINE; + endOffset = consume().getEndOffset(); + break; + + // Type Qualifiers + case IToken.t_const: + options |= CONST; + endOffset = consume().getEndOffset(); + break; + case IToken.t_volatile: + options |= VOLATILE; + endOffset = consume().getEndOffset(); + break; + case IToken.t_restrict: + options |= RESTRICT; + endOffset = consume().getEndOffset(); + break; + + // Type Specifiers + case IToken.t_void: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_void; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_char: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_char; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_short: + if (encounteredTypename) + break declSpecifiers; + options |= SHORT; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_int: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_int; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IGCCToken.t__int128: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_int128; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_long: + if (encounteredTypename) + break declSpecifiers; + isLong++; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_float: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_float; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_double: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_double; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IGCCToken.t__float128: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_float128; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IGCCToken.t_decimal32: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_decimal32; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IGCCToken.t_decimal64: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_decimal64; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IGCCToken.t_decimal128: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_decimal128; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_signed: + if (encounteredTypename) + break declSpecifiers; + options |= SIGNED; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t_unsigned: + if (encounteredTypename) + break declSpecifiers; + options |= UNSIGNED; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t__Bool: + if (encounteredTypename) + break declSpecifiers; + simpleType = IASTSimpleDeclSpecifier.t_bool; + encounteredRawType = true; + endOffset = consume().getEndOffset(); + break; + case IToken.t__Complex: + if (encounteredTypename) + break declSpecifiers; + options |= COMPLEX; + endOffset = consume().getEndOffset(); + break; + case IToken.t__Imaginary: + if (encounteredTypename) + break declSpecifiers; + options |= IMAGINARY; + endOffset = consume().getEndOffset(); + break; + + case IToken.tIDENTIFIER: + case IToken.tCOMPLETION: + case IToken.tEOC: + if (encounteredTypename || encounteredRawType) + break declSpecifiers; + + if ((endOffset != offset || declOption.fAllowEmptySpecifier) && LT(1) != IToken.tCOMPLETION) { + altResult = buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, + offset, endOffset); + returnToken = mark(); + } + + identifier = identifier(); + endOffset = calculateEndOffset(identifier); + encounteredTypename = true; + break; + case IToken.t_struct: + case IToken.t_union: + if (encounteredTypename || encounteredRawType) + break declSpecifiers; + try { + result = structOrUnionSpecifier(); + } catch (BacktrackException bt) { + result = elaboratedTypeSpecifier(); + } + endOffset = calculateEndOffset(result); + encounteredTypename = true; + break; + case IToken.t_enum: + if (encounteredTypename || encounteredRawType) + break declSpecifiers; + try { + result = (ICASTEnumerationSpecifier) enumSpecifier(); + } catch (BacktrackException bt) { + if (bt.getNodeBeforeProblem() instanceof ICASTDeclSpecifier) { + result = (ICASTDeclSpecifier) bt.getNodeBeforeProblem(); + problem = bt.getProblem(); + break declSpecifiers; + } else { + result = elaboratedTypeSpecifier(); + } + } + endOffset = calculateEndOffset(result); + encounteredTypename = true; + break; + + case IToken.t__Alignas: + alignmentSpecifiers = ArrayUtil.append(alignmentSpecifiers, alignmentSpecifier()); + break; + + case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec + if (!supportAttributeSpecifiers) + throwBacktrack(LA(1)); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, false)); + break; + case IGCCToken.t__declspec: // __declspec precedes the identifier + if (identifier != null || !supportDeclspecSpecifiers) + throwBacktrack(LA(1)); + __attribute_decl_seq(false, true); + break; + + case IGCCToken.t_typeof: + if (encounteredRawType || encounteredTypename) + throwBacktrack(LA(1)); + + simpleType = IASTSimpleDeclSpecifier.t_typeof; + consume(IGCCToken.t_typeof); + typeofExpression = parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), + IASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotInBExpr, null); + + encounteredTypename = true; + endOffset = calculateEndOffset(typeofExpression); + break; + + default: + if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst + && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) { + handleOtherDeclSpecModifier(); + endOffset = LA(1).getOffset(); + break; + } + break declSpecifiers; + } + + if (encounteredRawType && encounteredTypename) + throwBacktrack(LA(1)); + } + + // check for empty specification + if (!encounteredRawType && !encounteredTypename && LT(1) != IToken.tEOC + && !declOption.fAllowEmptySpecifier) { + if (offset == endOffset) { + throwBacktrack(LA(1)); + } + } + + if (result != null) { + configureDeclSpec(result, storageClass, options); + if ((options & RESTRICT) != 0) { + if (result instanceof ICASTCompositeTypeSpecifier) { + ((ICASTCompositeTypeSpecifier) result).setRestrict(true); + } else if (result instanceof CASTEnumerationSpecifier) { + ((CASTEnumerationSpecifier) result).setRestrict(true); + } else if (result instanceof CASTElaboratedTypeSpecifier) { + ((CASTElaboratedTypeSpecifier) result).setRestrict(true); + } + } + setRange(result, offset, endOffset); + if (problem != null) + throwBacktrack(problem, result); + } else if (identifier != null) { + result = buildNamedTypeSpecifier(identifier, storageClass, options, offset, endOffset); + } else { + result = buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, + endOffset); + } + result.setAlignmentSpecifiers(ArrayUtil.trim(alignmentSpecifiers)); addAttributeSpecifiers(attributes, result); endOffset = attributesEndOffset(endOffset, attributes); setRange(result, offset, endOffset); - } catch (BacktrackException e) { - if (returnToken != null) { - backup(returnToken); - result= altResult; - altResult= null; - returnToken= null; - } else { - throw e; - } - } - Decl target= new Decl(); - target.fDeclSpec1= result; - target.fDeclSpec2= altResult; - target.fDtorToken1= returnToken; - return target; - } - - private ICASTTypedefNameSpecifier buildNamedTypeSpecifier(IASTName name, int storageClass, - int options, int offset, int endOffset) { + } catch (BacktrackException e) { + if (returnToken != null) { + backup(returnToken); + result = altResult; + altResult = null; + returnToken = null; + } else { + throw e; + } + } + Decl target = new Decl(); + target.fDeclSpec1 = result; + target.fDeclSpec2 = altResult; + target.fDtorToken1 = returnToken; + return target; + } + + private ICASTTypedefNameSpecifier buildNamedTypeSpecifier(IASTName name, int storageClass, int options, int offset, + int endOffset) { ICASTTypedefNameSpecifier declSpec = getNodeFactory().newTypedefNameSpecifier(name); configureDeclSpec(declSpec, storageClass, options); declSpec.setRestrict((options & RESTRICT) != 0); - ((ASTNode) declSpec).setOffsetAndLength(offset, endOffset - offset); - return declSpec; + ((ASTNode) declSpec).setOffsetAndLength(offset, endOffset - offset); + return declSpec; } - private ICASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType, - int options, int isLong, IASTExpression typeofExpression, int offset, int endOffset) { - ICASTSimpleDeclSpecifier declSpec= getNodeFactory().newSimpleDeclSpecifier(); + private ICASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType, int options, int isLong, + IASTExpression typeofExpression, int offset, int endOffset) { + ICASTSimpleDeclSpecifier declSpec = getNodeFactory().newSimpleDeclSpecifier(); - configureDeclSpec(declSpec, storageClass, options); + configureDeclSpec(declSpec, storageClass, options); declSpec.setType(simpleType); declSpec.setLong(isLong == 1); declSpec.setLongLong(isLong > 1); @@ -1275,274 +1282,271 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { declSpec.setInline((options & INLINE) != 0); } - /** - * Parse a class/struct/union definition. - * - * classSpecifier : classKey name (baseClause)? "{" (memberSpecification)* - * "}" - * - * @throws BacktrackException to request a backtrack - */ - protected ICASTCompositeTypeSpecifier structOrUnionSpecifier() throws BacktrackException, EndOfFileException { - int classKind = 0; - IToken mark= mark(); - final int offset= mark.getOffset(); - - // class key - switch (LT(1)) { - case IToken.t_struct: - consume(); - classKind = IASTCompositeTypeSpecifier.k_struct; - break; - case IToken.t_union: - consume(); - classKind = IASTCompositeTypeSpecifier.k_union; - break; - default: - throwBacktrack(LA(1)); - return null; // line never reached, hint for the parser. - } - - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - - // class name - IASTName name = null; - if (LT(1) == IToken.tIDENTIFIER) { - name = identifier(); - } - - // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ; - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - - if (LT(1) != IToken.tLBRACE) { - IToken errorPoint = LA(1); - backup(mark); - throwBacktrack(errorPoint); - } - - if (name == null) { - name= getNodeFactory().newName(); - } - ICASTCompositeTypeSpecifier result = getNodeFactory().newCompositeTypeSpecifier(classKind, name); - declarationListInBraces(result, offset, DeclarationOptions.C_MEMBER); - return result; - } - - protected ICASTElaboratedTypeSpecifier elaboratedTypeSpecifier() throws BacktrackException, EndOfFileException { - // this is an elaborated class specifier - IToken t = consume(); - int eck = 0; - - switch (t.getType()) { - case IToken.t_struct: - eck = IASTElaboratedTypeSpecifier.k_struct; - break; - case IToken.t_union: - eck = IASTElaboratedTypeSpecifier.k_union; - break; - case IToken.t_enum: - eck = IASTElaboratedTypeSpecifier.k_enum; - break; - default: - backup(t); - throwBacktrack(t.getOffset(), t.getLength()); - } - - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - - IASTName name = identifier(); - ICASTElaboratedTypeSpecifier result = getNodeFactory().newElaboratedTypeSpecifier(eck, name); - ((ASTNode) result).setOffsetAndLength(t.getOffset(), calculateEndOffset(name) - t.getOffset()); - return result; - } - - @Override + /** + * Parse a class/struct/union definition. + * + * classSpecifier : classKey name (baseClause)? "{" (memberSpecification)* + * "}" + * + * @throws BacktrackException to request a backtrack + */ + protected ICASTCompositeTypeSpecifier structOrUnionSpecifier() throws BacktrackException, EndOfFileException { + int classKind = 0; + IToken mark = mark(); + final int offset = mark.getOffset(); + + // class key + switch (LT(1)) { + case IToken.t_struct: + consume(); + classKind = IASTCompositeTypeSpecifier.k_struct; + break; + case IToken.t_union: + consume(); + classKind = IASTCompositeTypeSpecifier.k_union; + break; + default: + throwBacktrack(LA(1)); + return null; // line never reached, hint for the parser. + } + + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + + // class name + IASTName name = null; + if (LT(1) == IToken.tIDENTIFIER) { + name = identifier(); + } + + // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ; + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + + if (LT(1) != IToken.tLBRACE) { + IToken errorPoint = LA(1); + backup(mark); + throwBacktrack(errorPoint); + } + + if (name == null) { + name = getNodeFactory().newName(); + } + ICASTCompositeTypeSpecifier result = getNodeFactory().newCompositeTypeSpecifier(classKind, name); + declarationListInBraces(result, offset, DeclarationOptions.C_MEMBER); + return result; + } + + protected ICASTElaboratedTypeSpecifier elaboratedTypeSpecifier() throws BacktrackException, EndOfFileException { + // this is an elaborated class specifier + IToken t = consume(); + int eck = 0; + + switch (t.getType()) { + case IToken.t_struct: + eck = IASTElaboratedTypeSpecifier.k_struct; + break; + case IToken.t_union: + eck = IASTElaboratedTypeSpecifier.k_union; + break; + case IToken.t_enum: + eck = IASTElaboratedTypeSpecifier.k_enum; + break; + default: + backup(t); + throwBacktrack(t.getOffset(), t.getLength()); + } + + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + + IASTName name = identifier(); + ICASTElaboratedTypeSpecifier result = getNodeFactory().newElaboratedTypeSpecifier(eck, name); + ((ASTNode) result).setOffsetAndLength(t.getOffset(), calculateEndOffset(name) - t.getOffset()); + return result; + } + + @Override protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, final DeclarationOptions option) - throws EndOfFileException, BacktrackException, FoundAggregateInitializer { - IASTDeclarator d = declarator(declspec, option); + throws EndOfFileException, BacktrackException, FoundAggregateInitializer { + IASTDeclarator d = declarator(declspec, option); - final int lt1= LTcatchEOF(1); + final int lt1 = LTcatchEOF(1); if (lt1 == IToken.tLBRACE) { if (!(ASTQueries.findTypeRelevantDeclarator(d) instanceof IASTFunctionDeclarator)) { throwBacktrack(LA(1)); } } - if (lt1 == IToken.tASSIGN && LT(2) == IToken.tLBRACE) - throw new FoundAggregateInitializer(declspec, d); - - IASTInitializer i = optionalInitializer(d, option); - if (i != null) { - d.setInitializer(i); - ((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset()); - } - return d; - } - - protected IASTDeclarator declarator(IASTDeclSpecifier declSpec, DeclarationOptions option) throws EndOfFileException, BacktrackException { - final int startingOffset = LA(1).getOffset(); - int endOffset = startingOffset; - - List<IASTPointerOperator> pointerOps = new ArrayList<>(DEFAULT_POINTEROPS_LIST_SIZE); - consumePointerOperators(pointerOps); - if (!pointerOps.isEmpty()) { - endOffset = calculateEndOffset(pointerOps.get(pointerOps.size() - 1)); - } - - // Accept __attribute__ or __declspec between pointer operators and declarator. - List<IASTAttributeSpecifier> attributes = - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - - // Look for identifier or nested declarator - final int lt1= LT(1); - if (lt1 == IToken.tIDENTIFIER) { - if (option.fRequireAbstract) - throwBacktrack(LA(1)); - - final IASTName declaratorName = identifier(); - endOffset= calculateEndOffset(declaratorName); - return declarator(pointerOps, attributes, declaratorName, null, startingOffset, - endOffset, option); - } - - if (lt1 == IToken.tLPAREN) { - IASTDeclarator cand1= null; - IToken cand1End= null; - // try an abstract function declarator - if (option.fAllowAbstract) { - final IToken mark= mark(); - try { - cand1= declarator(pointerOps, attributes, getNodeFactory().newName(), null, - startingOffset, endOffset, option); - if (option.fRequireAbstract) - return cand1; - - cand1End= LA(1); - } catch (BacktrackException e) { - } - backup(mark); - } - // try a nested declarator - try { - consume(); - if (LT(1) == IToken.tRPAREN) - throwBacktrack(LA(1)); - - final IASTDeclarator nested= declarator(declSpec, option); - endOffset= consume(IToken.tRPAREN).getEndOffset(); - final IASTDeclarator cand2= declarator(pointerOps, attributes, null, nested, - startingOffset, endOffset, option); - if (cand1 == null || cand1End == null) - return cand2; - final IToken cand2End= LA(1); - if (cand1End == cand2End) { - CASTAmbiguousDeclarator result= new CASTAmbiguousDeclarator(cand1, cand2); - ((ASTNode) result).setOffsetAndLength((ASTNode) cand1); - return result; - } - // use the longer variant - if (cand1End.getOffset() < cand2End.getOffset()) - return cand2; - - } catch (BacktrackException e) { - if (cand1 == null) - throw e; - } - backup(cand1End); - return cand1; - } - - // try abstract declarator - if (!option.fAllowAbstract) { - throwBacktrack(LA(1)); - } - return declarator(pointerOps, attributes, getNodeFactory().newName(), null, startingOffset, - endOffset, option); - } + if (lt1 == IToken.tASSIGN && LT(2) == IToken.tLBRACE) + throw new FoundAggregateInitializer(declspec, d); + + IASTInitializer i = optionalInitializer(d, option); + if (i != null) { + d.setInitializer(i); + ((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset()); + } + return d; + } + + protected IASTDeclarator declarator(IASTDeclSpecifier declSpec, DeclarationOptions option) + throws EndOfFileException, BacktrackException { + final int startingOffset = LA(1).getOffset(); + int endOffset = startingOffset; + + List<IASTPointerOperator> pointerOps = new ArrayList<>(DEFAULT_POINTEROPS_LIST_SIZE); + consumePointerOperators(pointerOps); + if (!pointerOps.isEmpty()) { + endOffset = calculateEndOffset(pointerOps.get(pointerOps.size() - 1)); + } + + // Accept __attribute__ or __declspec between pointer operators and declarator. + List<IASTAttributeSpecifier> attributes = __attribute_decl_seq(supportAttributeSpecifiers, + supportDeclspecSpecifiers); + + // Look for identifier or nested declarator + final int lt1 = LT(1); + if (lt1 == IToken.tIDENTIFIER) { + if (option.fRequireAbstract) + throwBacktrack(LA(1)); + + final IASTName declaratorName = identifier(); + endOffset = calculateEndOffset(declaratorName); + return declarator(pointerOps, attributes, declaratorName, null, startingOffset, endOffset, option); + } + + if (lt1 == IToken.tLPAREN) { + IASTDeclarator cand1 = null; + IToken cand1End = null; + // try an abstract function declarator + if (option.fAllowAbstract) { + final IToken mark = mark(); + try { + cand1 = declarator(pointerOps, attributes, getNodeFactory().newName(), null, startingOffset, + endOffset, option); + if (option.fRequireAbstract) + return cand1; + + cand1End = LA(1); + } catch (BacktrackException e) { + } + backup(mark); + } + // try a nested declarator + try { + consume(); + if (LT(1) == IToken.tRPAREN) + throwBacktrack(LA(1)); + + final IASTDeclarator nested = declarator(declSpec, option); + endOffset = consume(IToken.tRPAREN).getEndOffset(); + final IASTDeclarator cand2 = declarator(pointerOps, attributes, null, nested, startingOffset, endOffset, + option); + if (cand1 == null || cand1End == null) + return cand2; + final IToken cand2End = LA(1); + if (cand1End == cand2End) { + CASTAmbiguousDeclarator result = new CASTAmbiguousDeclarator(cand1, cand2); + ((ASTNode) result).setOffsetAndLength((ASTNode) cand1); + return result; + } + // use the longer variant + if (cand1End.getOffset() < cand2End.getOffset()) + return cand2; + + } catch (BacktrackException e) { + if (cand1 == null) + throw e; + } + backup(cand1End); + return cand1; + } + + // try abstract declarator + if (!option.fAllowAbstract) { + throwBacktrack(LA(1)); + } + return declarator(pointerOps, attributes, getNodeFactory().newName(), null, startingOffset, endOffset, option); + } private IASTDeclarator declarator(final List<IASTPointerOperator> pointerOps, List<IASTAttributeSpecifier> attributes, final IASTName declaratorName, final IASTDeclarator nestedDeclarator, final int startingOffset, int endOffset, final DeclarationOptions option) throws EndOfFileException, BacktrackException { - IASTDeclarator result= null; - int lt1; - loop: while (true) { - lt1= LTcatchEOF(1); - switch (lt1) { - case IToken.tLPAREN: - result= functionDeclarator(isAbstract(declaratorName, nestedDeclarator) - ? DeclarationOptions.PARAMETER : DeclarationOptions.C_PARAMETER_NON_ABSTRACT); - setDeclaratorID(result, declaratorName, nestedDeclarator); - break loop; - - case IToken.tLBRACKET: - result= arrayDeclarator(); - setDeclaratorID(result, declaratorName, nestedDeclarator); - break loop; - - case IToken.tCOLON: - if (!option.fAllowBitField) - throwBacktrack(LA(1)); - - result= bitFieldDeclarator(); - setDeclaratorID(result, declaratorName, nestedDeclarator); - break loop; - - case IGCCToken.t__attribute__: // if __attribute__ is after a declarator - if (!supportAttributeSpecifiers) - throwBacktrack(LA(1)); - attributes = CollectionUtils.merge(attributes, - __attribute_decl_seq(true, supportDeclspecSpecifiers)); - break; - case IGCCToken.t__declspec: - if (!supportDeclspecSpecifiers) - throwBacktrack(LA(1)); - attributes = CollectionUtils.merge(attributes, - __attribute_decl_seq(supportAttributeSpecifiers, true)); - break; - default: - break loop; - } - } - if (lt1 != 0) { - attributes = CollectionUtils.merge(attributes, - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); - } - - if (result == null) { - result= getNodeFactory().newDeclarator(null); - setDeclaratorID(result, declaratorName, nestedDeclarator); - } else { - endOffset= calculateEndOffset(result); - } - - if (lt1 != 0 && LT(1) == IToken.t_asm) { // asm labels bug 226121 - consume(); - endOffset= asmExpression(null).getEndOffset(); - - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - } - - for (IASTPointerOperator po : pointerOps) { + IASTDeclarator result = null; + int lt1; + loop: while (true) { + lt1 = LTcatchEOF(1); + switch (lt1) { + case IToken.tLPAREN: + result = functionDeclarator(isAbstract(declaratorName, nestedDeclarator) ? DeclarationOptions.PARAMETER + : DeclarationOptions.C_PARAMETER_NON_ABSTRACT); + setDeclaratorID(result, declaratorName, nestedDeclarator); + break loop; + + case IToken.tLBRACKET: + result = arrayDeclarator(); + setDeclaratorID(result, declaratorName, nestedDeclarator); + break loop; + + case IToken.tCOLON: + if (!option.fAllowBitField) + throwBacktrack(LA(1)); + + result = bitFieldDeclarator(); + setDeclaratorID(result, declaratorName, nestedDeclarator); + break loop; + + case IGCCToken.t__attribute__: // if __attribute__ is after a declarator + if (!supportAttributeSpecifiers) + throwBacktrack(LA(1)); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, supportDeclspecSpecifiers)); + break; + case IGCCToken.t__declspec: + if (!supportDeclspecSpecifiers) + throwBacktrack(LA(1)); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, true)); + break; + default: + break loop; + } + } + if (lt1 != 0) { + attributes = CollectionUtils.merge(attributes, + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); + } + + if (result == null) { + result = getNodeFactory().newDeclarator(null); + setDeclaratorID(result, declaratorName, nestedDeclarator); + } else { + endOffset = calculateEndOffset(result); + } + + if (lt1 != 0 && LT(1) == IToken.t_asm) { // asm labels bug 226121 + consume(); + endOffset = asmExpression(null).getEndOffset(); + + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + } + + for (IASTPointerOperator po : pointerOps) { result.addPointerOperator(po); } - if (attributes != null) { - for (IASTAttributeSpecifier specifier : attributes) { - result.addAttributeSpecifier(specifier); - } - } + if (attributes != null) { + for (IASTAttributeSpecifier specifier : attributes) { + result.addAttributeSpecifier(specifier); + } + } - ((ASTNode) result).setOffsetAndLength(startingOffset, endOffset - startingOffset); - return result; - } + ((ASTNode) result).setOffsetAndLength(startingOffset, endOffset - startingOffset); + return result; + } private boolean isAbstract(IASTName declaratorName, IASTDeclarator nestedDeclarator) { - nestedDeclarator= ASTQueries.findInnermostDeclarator(nestedDeclarator); + nestedDeclarator = ASTQueries.findInnermostDeclarator(nestedDeclarator); if (nestedDeclarator != null) { - declaratorName= nestedDeclarator.getName(); + declaratorName = nestedDeclarator.getName(); } return declaratorName == null || declaratorName.toCharArray().length == 0; } @@ -1556,9 +1560,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } } - private IASTDeclarator functionDeclarator(DeclarationOptions paramOption) throws EndOfFileException, BacktrackException { + private IASTDeclarator functionDeclarator(DeclarationOptions paramOption) + throws EndOfFileException, BacktrackException { IToken last = consume(IToken.tLPAREN); - int startOffset= last.getOffset(); + int startOffset = last.getOffset(); // check for K&R C parameters (0 means it's not K&R C) if (fPreventKnrCheck == 0 && supportKnRC) { @@ -1569,7 +1574,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTName[] parmNames = new IASTName[numKnRCParms]; IASTDeclaration[] parmDeclarations = new IASTDeclaration[numKnRCParms]; - boolean seenParameter= false; + boolean seenParameter = false; for (int i = 0; i <= parmNames.length; i++) { switch (LT(1)) { case IToken.tCOMMA: @@ -1594,52 +1599,53 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // now that the parameter names are parsed, parse the parameter declarations // count for parameter declarations <= count for parameter names. - int endOffset= last.getEndOffset(); + int endOffset = last.getEndOffset(); for (int i = 0; i < numKnRCParms && LT(1) != IToken.tLBRACE; i++) { try { - IASTDeclaration decl= simpleDeclaration(DeclarationOptions.LOCAL); - IASTSimpleDeclaration ok= checkKnrParameterDeclaration(decl, parmNames); + IASTDeclaration decl = simpleDeclaration(DeclarationOptions.LOCAL); + IASTSimpleDeclaration ok = checkKnrParameterDeclaration(decl, parmNames); if (ok != null) { - parmDeclarations[i]= ok; - endOffset= calculateEndOffset(ok); + parmDeclarations[i] = ok; + endOffset = calculateEndOffset(ok); } else { final ASTNode node = (ASTNode) decl; parmDeclarations[i] = createKnRCProblemDeclaration(node.getOffset(), node.getLength()); - endOffset= calculateEndOffset(node); + endOffset = calculateEndOffset(node); } } catch (BacktrackException b) { parmDeclarations[i] = createKnRCProblemDeclaration(b.getOffset(), b.getLength()); - endOffset= b.getOffset() + b.getLength(); + endOffset = b.getOffset() + b.getLength(); } } parmDeclarations = ArrayUtil.removeNulls(IASTDeclaration.class, parmDeclarations); - ICASTKnRFunctionDeclarator functionDecltor = getNodeFactory().newKnRFunctionDeclarator(parmNames, parmDeclarations); - ((ASTNode) functionDecltor).setOffsetAndLength(startOffset, endOffset-startOffset); - return functionDecltor; + ICASTKnRFunctionDeclarator functionDecltor = getNodeFactory().newKnRFunctionDeclarator(parmNames, + parmDeclarations); + ((ASTNode) functionDecltor).setOffsetAndLength(startOffset, endOffset - startOffset); + return functionDecltor; } } finally { fPreventKnrCheck--; } } - boolean seenParameter= false; - boolean encounteredVarArgs= false; - List<IASTParameterDeclaration> parameters= null; - int endOffset= last.getEndOffset(); + boolean seenParameter = false; + boolean encounteredVarArgs = false; + List<IASTParameterDeclaration> parameters = null; + int endOffset = last.getEndOffset(); paramLoop: while (true) { switch (LT(1)) { case IToken.tRPAREN: case IToken.tEOC: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break paramLoop; case IToken.tELLIPSIS: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); encounteredVarArgs = true; break; case IToken.tCOMMA: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); seenParameter = false; break; default: @@ -1662,22 +1668,22 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { fc.addParameterDeclaration(pd); } } - ((ASTNode) fc).setOffsetAndLength(startOffset, endOffset-startOffset); - return fc; + ((ASTNode) fc).setOffsetAndLength(startOffset, endOffset - startOffset); + return fc; } private IASTSimpleDeclaration checkKnrParameterDeclaration(IASTDeclaration decl, final IASTName[] parmNames) { if (!(decl instanceof IASTSimpleDeclaration)) return null; - IASTSimpleDeclaration declaration= ((IASTSimpleDeclaration) decl); + IASTSimpleDeclaration declaration = ((IASTSimpleDeclaration) decl); IASTDeclarator[] decltors = declaration.getDeclarators(); for (IASTDeclarator decltor : decltors) { boolean decltorOk = false; final char[] nchars = ASTQueries.findInnermostDeclarator(decltor).getName().toCharArray(); for (IASTName parmName : parmNames) { if (CharArrayUtils.equals(nchars, parmName.toCharArray())) { - decltorOk= true; + decltorOk = true; break; } } @@ -1692,7 +1698,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { */ private IASTArrayDeclarator arrayDeclarator() throws EndOfFileException, BacktrackException { ArrayList<IASTArrayModifier> arrayMods = new ArrayList<>(DEFAULT_POINTEROPS_LIST_SIZE); - int start= LA(1).getOffset(); + int start = LA(1).getOffset(); consumeArrayModifiers(arrayMods); if (arrayMods.isEmpty()) throwBacktrack(LA(1)); @@ -1700,104 +1706,103 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { final int endOffset = calculateEndOffset(arrayMods.get(arrayMods.size() - 1)); final IASTArrayDeclarator d = getNodeFactory().newArrayDeclarator(null); for (IASTArrayModifier m : arrayMods) { - d.addArrayModifier(m); - } + d.addArrayModifier(m); + } - ((ASTNode) d).setOffsetAndLength(start, endOffset-start); + ((ASTNode) d).setOffsetAndLength(start, endOffset - start); return d; } - /** * Parses for a bit field declarator starting with the colon */ private IASTFieldDeclarator bitFieldDeclarator() throws EndOfFileException, BacktrackException { - int start= consume(IToken.tCOLON).getOffset(); + int start = consume(IToken.tCOLON).getOffset(); final IASTExpression bitField = constantExpression(); final int endOffset = calculateEndOffset(bitField); - IASTFieldDeclarator d = getNodeFactory().newFieldDeclarator(null, bitField); - d.setBitFieldSize(bitField); + IASTFieldDeclarator d = getNodeFactory().newFieldDeclarator(null, bitField); + d.setBitFieldSize(bitField); - ((ASTNode) d).setOffsetAndLength(start, endOffset-start); + ((ASTNode) d).setOffsetAndLength(start, endOffset - start); return d; } - - @Override + @Override protected IASTName identifier() throws EndOfFileException, BacktrackException { - final IToken t= LA(1); - IASTName n; - switch (t.getType()) { - case IToken.tIDENTIFIER: - consume(); - n = getNodeFactory().newName(t.getCharImage()); - setRange(n, t.getOffset(), t.getEndOffset()); - break; - - case IToken.tCOMPLETION: - case IToken.tEOC: - consume(); - n = getNodeFactory().newName(t.getCharImage()); - setRange(n, t.getOffset(), t.getEndOffset()); - createCompletionNode(t).addName(n); - return n; - - default: - throw backtrack; - } - - return n; - } - - protected void consumeArrayModifiers(List<IASTArrayModifier> arrayMods) throws EndOfFileException, BacktrackException { - while (LT(1) == IToken.tLBRACKET) { - // eat the '[' - int startOffset = consume().getOffset(); - - boolean isStatic = false; - boolean isConst = false; - boolean isRestrict = false; - boolean isVolatile = false; - boolean isVarSized = false; - - outerLoop: do { - switch (LT(1)) { - case IToken.t_static: - isStatic = true; - consume(); - break; - case IToken.t_const: - isConst = true; - consume(); - break; - case IToken.t_volatile: - isVolatile = true; - consume(); - break; - case IToken.t_restrict: - isRestrict = true; - consume(); - break; - case IToken.tSTAR: - isVarSized = true; - consume(); - break outerLoop; - default: - break outerLoop; - } - } while (true); - - IASTExpression exp = null; - - if (LT(1) != IToken.tRBRACKET) { - if (!(isStatic || isRestrict || isConst || isVolatile)) - exp = expression(ExprKind.eAssignment); - else - exp = constantExpression(); - } - int lastOffset; + final IToken t = LA(1); + IASTName n; + switch (t.getType()) { + case IToken.tIDENTIFIER: + consume(); + n = getNodeFactory().newName(t.getCharImage()); + setRange(n, t.getOffset(), t.getEndOffset()); + break; + + case IToken.tCOMPLETION: + case IToken.tEOC: + consume(); + n = getNodeFactory().newName(t.getCharImage()); + setRange(n, t.getOffset(), t.getEndOffset()); + createCompletionNode(t).addName(n); + return n; + + default: + throw backtrack; + } + + return n; + } + + protected void consumeArrayModifiers(List<IASTArrayModifier> arrayMods) + throws EndOfFileException, BacktrackException { + while (LT(1) == IToken.tLBRACKET) { + // eat the '[' + int startOffset = consume().getOffset(); + + boolean isStatic = false; + boolean isConst = false; + boolean isRestrict = false; + boolean isVolatile = false; + boolean isVarSized = false; + + outerLoop: do { + switch (LT(1)) { + case IToken.t_static: + isStatic = true; + consume(); + break; + case IToken.t_const: + isConst = true; + consume(); + break; + case IToken.t_volatile: + isVolatile = true; + consume(); + break; + case IToken.t_restrict: + isRestrict = true; + consume(); + break; + case IToken.tSTAR: + isVarSized = true; + consume(); + break outerLoop; + default: + break outerLoop; + } + } while (true); + + IASTExpression exp = null; + + if (LT(1) != IToken.tRBRACKET) { + if (!(isStatic || isRestrict || isConst || isVolatile)) + exp = expression(ExprKind.eAssignment); + else + exp = constantExpression(); + } + int lastOffset; switch (LT(1)) { case IToken.tRBRACKET: lastOffset = consume().getEndOffset(); @@ -1815,390 +1820,388 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { arrayMod.setVolatile(isVolatile); arrayMod.setRestrict(isRestrict); arrayMod.setVariableSized(isVarSized); - ((ASTNode) arrayMod).setOffsetAndLength(startOffset, lastOffset - startOffset); - arrayMods.add(arrayMod); - } - } - - - protected IASTParameterDeclaration parameterDeclaration(DeclarationOptions option) throws BacktrackException, EndOfFileException { - final IToken current = LA(1); - int startingOffset = current.getOffset(); - if (current.getType() == IToken.tLBRACKET && supportParameterInfoBlock) { - skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET, 0); - } - - IASTDeclSpecifier declSpec = null; - IASTDeclarator declarator = null; - IASTDeclSpecifier altDeclSpec = null; - IASTDeclarator altDeclarator = null; - - try { - fPreventKnrCheck++; - Decl decl= declSpecifierSequence_initDeclarator(option, false); - declSpec= decl.fDeclSpec1; - declarator= decl.fDtor1; - altDeclSpec= decl.fDeclSpec2; - altDeclarator= decl.fDtor2; - } catch (FoundAggregateInitializer lie) { - declSpec= lie.fDeclSpec; - declarator= lie.fDeclarator; - } finally { - fPreventKnrCheck--; - } - - final int length = figureEndOffset(declSpec, declarator) - startingOffset; - IASTParameterDeclaration result = getNodeFactory().newParameterDeclaration(declSpec, declarator); + ((ASTNode) arrayMod).setOffsetAndLength(startOffset, lastOffset - startOffset); + arrayMods.add(arrayMod); + } + } + + protected IASTParameterDeclaration parameterDeclaration(DeclarationOptions option) + throws BacktrackException, EndOfFileException { + final IToken current = LA(1); + int startingOffset = current.getOffset(); + if (current.getType() == IToken.tLBRACKET && supportParameterInfoBlock) { + skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET, 0); + } + + IASTDeclSpecifier declSpec = null; + IASTDeclarator declarator = null; + IASTDeclSpecifier altDeclSpec = null; + IASTDeclarator altDeclarator = null; + + try { + fPreventKnrCheck++; + Decl decl = declSpecifierSequence_initDeclarator(option, false); + declSpec = decl.fDeclSpec1; + declarator = decl.fDtor1; + altDeclSpec = decl.fDeclSpec2; + altDeclarator = decl.fDtor2; + } catch (FoundAggregateInitializer lie) { + declSpec = lie.fDeclSpec; + declarator = lie.fDeclarator; + } finally { + fPreventKnrCheck--; + } + + final int length = figureEndOffset(declSpec, declarator) - startingOffset; + IASTParameterDeclaration result = getNodeFactory().newParameterDeclaration(declSpec, declarator); ((ASTNode) result).setOffsetAndLength(startingOffset, length); - if (altDeclarator != null && altDeclSpec != null) { - IASTParameterDeclaration alt = getNodeFactory().newParameterDeclaration(altDeclSpec, altDeclarator); - ((ASTNode) alt).setOffsetAndLength(startingOffset, length); - // order is important, prefer variant with declspec over the one without - result= new CASTAmbiguousParameterDeclaration(result, alt); - ((ASTNode) result).setOffsetAndLength((ASTNode) alt); - } - return result; - } - - - @Override - protected IASTTranslationUnit getTranslationUnit() { - return translationUnit; - } + if (altDeclarator != null && altDeclSpec != null) { + IASTParameterDeclaration alt = getNodeFactory().newParameterDeclaration(altDeclSpec, altDeclarator); + ((ASTNode) alt).setOffsetAndLength(startingOffset, length); + // order is important, prefer variant with declspec over the one without + result = new CASTAmbiguousParameterDeclaration(result, alt); + ((ASTNode) result).setOffsetAndLength((ASTNode) alt); + } + return result; + } + @Override + protected IASTTranslationUnit getTranslationUnit() { + return translationUnit; + } - @Override + @Override protected IASTStatement statement() throws EndOfFileException, BacktrackException { - switch (LT(1)) { - // labeled statements - case IToken.t_case: - return parseCaseStatement(); - case IToken.t_default: - return parseDefaultStatement(); - // compound statement - case IToken.tLBRACE: - return parseCompoundStatement(); - // selection statement - case IToken.t_if: - return parseIfStatement(); - case IToken.t_switch: - return parseSwitchStatement(); - // iteration statements - case IToken.t_while: - return parseWhileStatement(); - case IToken.t_do: - return parseDoStatement(); - case IToken.t_for: - return parseForStatement(); - // jump statement - case IToken.t_break: - return parseBreakStatement(); - case IToken.t_continue: - return parseContinueStatement(); - case IToken.t_return: - return parseReturnStatement(); - case IToken.t_goto: - return parseGotoStatement(); - case IToken.tSEMI: - return parseNullStatement(); - default: - // can be many things: - // label - if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { - return parseLabelStatement(); - } - - return parseDeclarationOrExpressionStatement(); - } - } - - @Override + switch (LT(1)) { + // labeled statements + case IToken.t_case: + return parseCaseStatement(); + case IToken.t_default: + return parseDefaultStatement(); + // compound statement + case IToken.tLBRACE: + return parseCompoundStatement(); + // selection statement + case IToken.t_if: + return parseIfStatement(); + case IToken.t_switch: + return parseSwitchStatement(); + // iteration statements + case IToken.t_while: + return parseWhileStatement(); + case IToken.t_do: + return parseDoStatement(); + case IToken.t_for: + return parseForStatement(); + // jump statement + case IToken.t_break: + return parseBreakStatement(); + case IToken.t_continue: + return parseContinueStatement(); + case IToken.t_return: + return parseReturnStatement(); + case IToken.t_goto: + return parseGotoStatement(); + case IToken.tSEMI: + return parseNullStatement(); + default: + // can be many things: + // label + if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { + return parseLabelStatement(); + } + + return parseDeclarationOrExpressionStatement(); + } + } + + @Override protected void nullifyTranslationUnit() { - translationUnit = null; - } - - - private int countKnRCParms() { - IToken mark = null; - int parmCount = 0; - boolean previousWasIdentifier = false; - - try { - mark = mark(); - - // starts at the beginning of the parameter list - for (;;) { - if (LT(1) == IToken.tCOMMA) { - consume(); - previousWasIdentifier = false; - } else if (LT(1) == IToken.tIDENTIFIER) { - consume(); - if (previousWasIdentifier) { - backup(mark); - return 0; // i.e. KnR C won't have int f(typedef x) - // char - // x; {} - } - previousWasIdentifier = true; - parmCount++; - } else if (LT(1) == IToken.tRPAREN) { - if (!previousWasIdentifier) { - // if the first token encountered is tRPAREN then it's not K&R C - // the first token when counting K&R C parms is always an identifier - backup(mark); - return 0; - } - consume(); - break; - } else { - backup(mark); - return 0; // i.e. KnR C won't have int f(char) char x; {} - } - } - - // if the next token is a tSEMI then the declaration was a regular - // declaration statement i.e. int f(type_def); - final int lt1= LT(1); - if (lt1 == IToken.tSEMI || lt1 == IToken.tLBRACE) { - backup(mark); - return 0; - } - - // look ahead for the start of the function body, if end of file is - // found then return 0 parameters found (implies not KnR C) - int previous=-1; - while (LT(1) != IToken.tLBRACE) { - // fix for 100104: check if the parameter declaration is a valid one - try { - simpleDeclaration(DeclarationOptions.LOCAL); + translationUnit = null; + } + + private int countKnRCParms() { + IToken mark = null; + int parmCount = 0; + boolean previousWasIdentifier = false; + + try { + mark = mark(); + + // starts at the beginning of the parameter list + for (;;) { + if (LT(1) == IToken.tCOMMA) { + consume(); + previousWasIdentifier = false; + } else if (LT(1) == IToken.tIDENTIFIER) { + consume(); + if (previousWasIdentifier) { + backup(mark); + return 0; // i.e. KnR C won't have int f(typedef x) + // char + // x; {} + } + previousWasIdentifier = true; + parmCount++; + } else if (LT(1) == IToken.tRPAREN) { + if (!previousWasIdentifier) { + // if the first token encountered is tRPAREN then it's not K&R C + // the first token when counting K&R C parms is always an identifier + backup(mark); + return 0; + } + consume(); + break; + } else { + backup(mark); + return 0; // i.e. KnR C won't have int f(char) char x; {} + } + } + + // if the next token is a tSEMI then the declaration was a regular + // declaration statement i.e. int f(type_def); + final int lt1 = LT(1); + if (lt1 == IToken.tSEMI || lt1 == IToken.tLBRACE) { + backup(mark); + return 0; + } + + // look ahead for the start of the function body, if end of file is + // found then return 0 parameters found (implies not KnR C) + int previous = -1; + while (LT(1) != IToken.tLBRACE) { + // fix for 100104: check if the parameter declaration is a valid one + try { + simpleDeclaration(DeclarationOptions.LOCAL); } catch (BacktrackException e) { backup(mark); return 0; } - final IToken t = LA(1); - if (t.getType() == IToken.tEOC) - break; - - final int next = t.hashCode(); - if (next == previous) { // infinite loop detected - break; - } - previous = next; - } - - backup(mark); - return parmCount; - } catch (EndOfFileException eof) { - if (mark != null) - backup(mark); - - return 0; - } - } - - private IASTProblemDeclaration createKnRCProblemDeclaration(int offset, int length) throws EndOfFileException { - IASTProblem p = createProblem(IProblem.SYNTAX_ERROR, offset, length); - IASTProblemDeclaration pd = getNodeFactory().newProblemDeclaration(p); - ((ASTNode) pd).setOffsetAndLength((ASTNode) p); - - // consume until LBRACE is found (to leave off at the function body and - // continue from there) - IToken previous=null; - IToken next=null; - while (LT(1) != IToken.tLBRACE) { - next = consume(); - if (next == previous || next.getType() == IToken.tEOC) { // infinite loop detected - break; - } - previous = next; - } - - return pd; - } - - @Override + final IToken t = LA(1); + if (t.getType() == IToken.tEOC) + break; + + final int next = t.hashCode(); + if (next == previous) { // infinite loop detected + break; + } + previous = next; + } + + backup(mark); + return parmCount; + } catch (EndOfFileException eof) { + if (mark != null) + backup(mark); + + return 0; + } + } + + private IASTProblemDeclaration createKnRCProblemDeclaration(int offset, int length) throws EndOfFileException { + IASTProblem p = createProblem(IProblem.SYNTAX_ERROR, offset, length); + IASTProblemDeclaration pd = getNodeFactory().newProblemDeclaration(p); + ((ASTNode) pd).setOffsetAndLength((ASTNode) p); + + // consume until LBRACE is found (to leave off at the function body and + // continue from there) + IToken previous = null; + IToken next = null; + while (LT(1) != IToken.tLBRACE) { + next = consume(); + if (next == previous || next.getType() == IToken.tEOC) { // infinite loop detected + break; + } + previous = next; + } + + return pd; + } + + @Override protected ASTVisitor createAmbiguityNodeVisitor() { - return new CASTAmbiguityResolver(); - } + return new CASTAmbiguityResolver(); + } - @Override + @Override protected IASTAmbiguousStatement createAmbiguousStatement() { - return new CASTAmbiguousStatement(); - } + return new CASTAmbiguousStatement(); + } - @Override + @Override protected IASTAmbiguousExpression createAmbiguousExpression() { - return new CASTAmbiguousExpression(); - } + return new CASTAmbiguousExpression(); + } @Override - protected IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, IASTCastExpression castExpr) { + protected IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, + IASTCastExpression castExpr) { return new CASTAmbiguousBinaryVsCastExpression(binary, castExpr); } @Override - protected IASTAmbiguousExpression createAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall) { + protected IASTAmbiguousExpression createAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, + IASTFunctionCallExpression funcCall) { return new CASTAmbiguousCastVsFunctionCallExpression(castExpr, funcCall); } - protected IASTStatement parseIfStatement() throws EndOfFileException, BacktrackException { - IASTIfStatement result = null; - IASTIfStatement if_statement = null; - int start = LA(1).getOffset(); - if_loop: while (true) { - int so = consume(IToken.t_if).getOffset(); - consume(IToken.tLPAREN); - // condition - IASTExpression condition= condition(true); - if (LT(1) == IToken.tEOC) { - // Completing in the condition - IASTIfStatement new_if = getNodeFactory().newIfStatement(condition, null, null); - - if (if_statement != null) { - if_statement.setElseClause(new_if); - } - return result != null ? result : new_if; - } - consume(IToken.tRPAREN); - - IASTStatement thenClause = statement(); - IASTIfStatement new_if_statement = getNodeFactory().newIfStatement(null, null, null); - ((ASTNode) new_if_statement).setOffset(so); - if (condition != null) // shouldn't be possible but failure in condition() makes it so - { - new_if_statement.setConditionExpression(condition); - } - if (thenClause != null) { - new_if_statement.setThenClause(thenClause); - ((ASTNode) new_if_statement).setLength(calculateEndOffset(thenClause) - - ((ASTNode) new_if_statement).getOffset()); - } - if (LT(1) == IToken.t_else) { - consume(); - if (LT(1) == IToken.t_if) { - // an else if, don't recurse, just loop and do another if - - if (if_statement != null) { - if_statement.setElseClause(new_if_statement); - ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement) - - ((ASTNode) if_statement).getOffset()); - } - if (result == null && if_statement != null) - result = if_statement; - if (result == null) - result = new_if_statement; - - if_statement = new_if_statement; - continue if_loop; - } - IASTStatement elseStatement = statement(); - new_if_statement.setElseClause(elseStatement); - if (if_statement != null) { - if_statement.setElseClause(new_if_statement); - ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement) - - ((ASTNode) if_statement).getOffset()); - } else { - if (result == null) - result = new_if_statement; - if_statement = new_if_statement; - } - } else { - if (thenClause != null) - ((ASTNode) new_if_statement).setLength(calculateEndOffset(thenClause) - start); - if (if_statement != null) { - if_statement.setElseClause(new_if_statement); - ((ASTNode) new_if_statement).setLength(calculateEndOffset(new_if_statement) - start); - } - if (result == null && if_statement != null) - result = if_statement; - if (result == null) - result = new_if_statement; - - if_statement = new_if_statement; - } - break if_loop; - } - - reconcileLengths(result); - return result; - } - - - protected IASTStatement parseSwitchStatement() throws EndOfFileException, BacktrackException { - int startOffset; - startOffset = consume().getOffset(); - consume(IToken.tLPAREN); - IASTExpression switch_condition = condition(true); - switch (LT(1)) { - case IToken.tRPAREN: - consume(); - break; - case IToken.tEOC: - break; - default: - throwBacktrack(LA(1)); - } - - IASTStatement switch_body = parseSwitchBody(); - IASTSwitchStatement switch_statement = getNodeFactory().newSwitchStatement(switch_condition, switch_body); - ((ASTNode) switch_statement).setOffsetAndLength(startOffset, - (switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset); - return switch_statement; - } - - protected IASTStatement parseForStatement() throws EndOfFileException, BacktrackException { - int startOffset; - startOffset = consume().getOffset(); - consume(IToken.tLPAREN); - IASTStatement init = initStatement(); - IASTExpression for_condition = null; - switch (LT(1)) { - case IToken.tSEMI: - case IToken.tEOC: - break; - default: - for_condition = condition(false); - } - switch (LT(1)) { - case IToken.tSEMI: - consume(); - break; - case IToken.tEOC: - break; - default: - throw backtrack; - } - IASTExpression iterationExpression = null; - switch (LT(1)) { - case IToken.tRPAREN: - case IToken.tEOC: - break; - default: - iterationExpression = expression(); - } - switch (LT(1)) { - case IToken.tRPAREN: - consume(); - break; - case IToken.tEOC: - break; - default: - throw backtrack; - } - - IASTForStatement for_statement = getNodeFactory().newForStatement(init, for_condition, iterationExpression, null); - if (LT(1) != IToken.tEOC) { - IASTStatement for_body = statement(); - ((ASTNode) for_statement).setOffsetAndLength(startOffset, calculateEndOffset(for_body) - startOffset); - for_statement.setBody(for_body); - } - return for_statement; - } + protected IASTStatement parseIfStatement() throws EndOfFileException, BacktrackException { + IASTIfStatement result = null; + IASTIfStatement if_statement = null; + int start = LA(1).getOffset(); + if_loop: while (true) { + int so = consume(IToken.t_if).getOffset(); + consume(IToken.tLPAREN); + // condition + IASTExpression condition = condition(true); + if (LT(1) == IToken.tEOC) { + // Completing in the condition + IASTIfStatement new_if = getNodeFactory().newIfStatement(condition, null, null); + + if (if_statement != null) { + if_statement.setElseClause(new_if); + } + return result != null ? result : new_if; + } + consume(IToken.tRPAREN); + + IASTStatement thenClause = statement(); + IASTIfStatement new_if_statement = getNodeFactory().newIfStatement(null, null, null); + ((ASTNode) new_if_statement).setOffset(so); + if (condition != null) // shouldn't be possible but failure in condition() makes it so + { + new_if_statement.setConditionExpression(condition); + } + if (thenClause != null) { + new_if_statement.setThenClause(thenClause); + ((ASTNode) new_if_statement) + .setLength(calculateEndOffset(thenClause) - ((ASTNode) new_if_statement).getOffset()); + } + if (LT(1) == IToken.t_else) { + consume(); + if (LT(1) == IToken.t_if) { + // an else if, don't recurse, just loop and do another if + + if (if_statement != null) { + if_statement.setElseClause(new_if_statement); + ((ASTNode) if_statement) + .setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset()); + } + if (result == null && if_statement != null) + result = if_statement; + if (result == null) + result = new_if_statement; + + if_statement = new_if_statement; + continue if_loop; + } + IASTStatement elseStatement = statement(); + new_if_statement.setElseClause(elseStatement); + if (if_statement != null) { + if_statement.setElseClause(new_if_statement); + ((ASTNode) if_statement) + .setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset()); + } else { + if (result == null) + result = new_if_statement; + if_statement = new_if_statement; + } + } else { + if (thenClause != null) + ((ASTNode) new_if_statement).setLength(calculateEndOffset(thenClause) - start); + if (if_statement != null) { + if_statement.setElseClause(new_if_statement); + ((ASTNode) new_if_statement).setLength(calculateEndOffset(new_if_statement) - start); + } + if (result == null && if_statement != null) + result = if_statement; + if (result == null) + result = new_if_statement; + + if_statement = new_if_statement; + } + break if_loop; + } + + reconcileLengths(result); + return result; + } + + protected IASTStatement parseSwitchStatement() throws EndOfFileException, BacktrackException { + int startOffset; + startOffset = consume().getOffset(); + consume(IToken.tLPAREN); + IASTExpression switch_condition = condition(true); + switch (LT(1)) { + case IToken.tRPAREN: + consume(); + break; + case IToken.tEOC: + break; + default: + throwBacktrack(LA(1)); + } + + IASTStatement switch_body = parseSwitchBody(); + IASTSwitchStatement switch_statement = getNodeFactory().newSwitchStatement(switch_condition, switch_body); + ((ASTNode) switch_statement).setOffsetAndLength(startOffset, + (switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset); + return switch_statement; + } + + protected IASTStatement parseForStatement() throws EndOfFileException, BacktrackException { + int startOffset; + startOffset = consume().getOffset(); + consume(IToken.tLPAREN); + IASTStatement init = initStatement(); + IASTExpression for_condition = null; + switch (LT(1)) { + case IToken.tSEMI: + case IToken.tEOC: + break; + default: + for_condition = condition(false); + } + switch (LT(1)) { + case IToken.tSEMI: + consume(); + break; + case IToken.tEOC: + break; + default: + throw backtrack; + } + IASTExpression iterationExpression = null; + switch (LT(1)) { + case IToken.tRPAREN: + case IToken.tEOC: + break; + default: + iterationExpression = expression(); + } + switch (LT(1)) { + case IToken.tRPAREN: + consume(); + break; + case IToken.tEOC: + break; + default: + throw backtrack; + } + + IASTForStatement for_statement = getNodeFactory().newForStatement(init, for_condition, iterationExpression, + null); + if (LT(1) != IToken.tEOC) { + IASTStatement for_body = statement(); + ((ASTNode) for_statement).setOffsetAndLength(startOffset, calculateEndOffset(for_body) - startOffset); + for_statement.setBody(for_body); + } + return for_statement; + } @Override - protected IASTExpression expressionWithOptionalTrailingEllipsis() throws BacktrackException, - EndOfFileException { + protected IASTExpression expressionWithOptionalTrailingEllipsis() throws BacktrackException, EndOfFileException { // No pack expansions in C. return expression(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java index 142d793a295..94ee2124e22 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalBinding.java @@ -19,17 +19,17 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * Methods needed by CVisitor but not meant for public interface */ public interface ICInternalBinding { - public IASTNode getPhysicalNode(); + public IASTNode getPhysicalNode(); - /** - * Returns the declarations for this binding. - * @since 5.0 - */ + /** + * Returns the declarations for this binding. + * @since 5.0 + */ public IASTNode[] getDeclarations(); - /** - * Returns the definitions for this binding. - * @since 5.0 - */ + /** + * Returns the definitions for this binding. + * @since 5.0 + */ public IASTNode getDefinition(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index fe6bbe8ca9b..6119aebacb2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -62,7 +62,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat }; public AbstractCPPClassSpecializationScope(ICPPClassSpecialization specialization) { - this.specialClass= specialization; + this.specialClass = specialization; } @Override @@ -91,8 +91,8 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat ICPPClassType specialized = specialClass.getSpecializedBinding(); IScope classScope = specialized.getCompositeScope(); - IBinding[] bindings = classScope != null ? - classScope.getBindings(new ScopeLookupData(name, resolve, false)) : null; + IBinding[] bindings = classScope != null ? classScope.getBindings(new ScopeLookupData(name, resolve, false)) + : null; if (bindings == null) return null; @@ -107,13 +107,12 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat CPPSemantics.popLookupPoint(); } specs = ArrayUtil.trim(specs); - return CPPSemantics.resolveAmbiguities(name, specs); + return CPPSemantics.resolveAmbiguities(name, specs); } @Deprecated @Override - final public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, - IIndexFileSet fileSet) { + final public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) { return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); } @@ -124,18 +123,18 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat if (classScope == null) return IBinding.EMPTY_BINDING_ARRAY; - IBinding[] bindings= classScope.getBindings(lookup); - IBinding[] result= IBinding.EMPTY_BINDING_ARRAY; + IBinding[] bindings = classScope.getBindings(lookup); + IBinding[] result = IBinding.EMPTY_BINDING_ARRAY; if (bindings == null) { return result; } int n = 0; for (IBinding binding : bindings) { - if (binding == specialized || - (binding instanceof ICPPClassType && areSameTypesModuloPartialSpecialization(specialized, (IType) binding))) { - binding= specialClass; + if (binding == specialized || (binding instanceof ICPPClassType + && areSameTypesModuloPartialSpecialization(specialized, (IType) binding))) { + binding = specialClass; } else { - binding= specialClass.specializeMember(binding); + binding = specialClass.specializeMember(binding); } if (binding != null) result = ArrayUtil.appendAt(result, n++, binding); @@ -162,23 +161,23 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat public ICPPBase[] getBases() { if (fBases == null) { if (fComputingBases.get()) { - return ICPPBase.EMPTY_BASE_ARRAY; // avoid recursion + return ICPPBase.EMPTY_BASE_ARRAY; // avoid recursion } fComputingBases.set(true); try { ICPPBase[] result = ICPPBase.EMPTY_BASE_ARRAY; ICPPBase[] bases = specialClass.getSpecializedBinding().getBases(); if (bases.length == 0) { - fBases= bases; + fBases = bases; } else { final ICPPTemplateParameterMap tpmap = specialClass.getTemplateParameterMap(); for (ICPPBase base : bases) { IType baseType = base.getBaseClassType(); if (baseType instanceof ICPPParameterPackType) { - IType[] specClasses= CPPTemplates.instantiateTypes(new IType[] { baseType }, + IType[] specClasses = CPPTemplates.instantiateTypes(new IType[] { baseType }, new InstantiationContext(tpmap, specialClass)); if (specClasses.length == 1 && specClasses[0] instanceof ICPPParameterPackType) { - result= ArrayUtil.append(result, base); + result = ArrayUtil.append(result, base); } else { for (IType specClass : specClasses) { ICPPBase specBase = base.clone(); @@ -189,15 +188,14 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat } } } - } - else if (baseType != null) { + } else if (baseType != null) { ICPPBase specBase = base.clone(); ICPPClassSpecialization specializationContext = specialClass; IBinding owner = specialClass.getOwner(); if (owner instanceof ICPPClassSpecialization) { specializationContext = (ICPPClassSpecialization) owner; } - IType specClass= CPPTemplates.instantiateType(baseType, + IType specClass = CPPTemplates.instantiateType(baseType, new InstantiationContext(tpmap, specializationContext)); specClass = SemanticUtil.getUltimateType(specClass, false); if (specClass instanceof IBinding && !(specClass instanceof IProblemBinding)) { @@ -206,8 +204,8 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat result = ArrayUtil.append(result, specBase); } } - result= ArrayUtil.trim(result); - fBases= result; + result = ArrayUtil.trim(result); + fBases = result; return result; } } finally { @@ -222,24 +220,24 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat if (array == null || array.length == 0) return array; - T[] newArray= array.clone(); + T[] newArray = array.clone(); for (int i = 0; i < newArray.length; i++) { IBinding specializedMember = specialClass.specializeMember(array[i]); - newArray[i]= (T) specializedMember; + newArray[i] = (T) specializedMember; } return newArray; } @Override public ICPPField[] getDeclaredFields() { - ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); + ICPPField[] fields = specialClass.getSpecializedBinding().getDeclaredFields(); return specializeMembers(fields); } @Override public ICPPMethod[] getImplicitMethods() { ICPPClassType origClass = specialClass.getSpecializedBinding(); - ICPPMethod[] methods= ClassTypeHelper.getImplicitMethods(origClass); + ICPPMethod[] methods = ClassTypeHelper.getImplicitMethods(origClass); ICPPMethod[] specializedMembers = specializeMembers(methods); // Add inherited constructors. ICPPMethod[] inheritedConstructors = getOwnInheritedConstructors(); @@ -255,7 +253,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPConstructor[] getConstructors() { - ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); + ICPPConstructor[] ctors = specialClass.getSpecializedBinding().getConstructors(); ICPPConstructor[] specializedCtors = specializeMembers(ctors); // Add inherited constructors. ICPPMethod[] inheritedConstructors = getOwnInheritedConstructors(specializedCtors); @@ -268,10 +266,10 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat */ private ICPPMethod[] getOwnInheritedConstructors(ICPPConstructor[] existingConstructors) { if (ownInheritedConstructors == null) { - if (!hasInheritedConstructorsSources()) - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + if (!hasInheritedConstructorsSources()) + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - IType[][] existingConstructorParamTypes = new IType[existingConstructors.length][]; + IType[][] existingConstructorParamTypes = new IType[existingConstructors.length][]; for (int i = 0; i < existingConstructors.length; i++) { ICPPParameter[] params = existingConstructors[i].getParameters(); IType[] types = new IType[params.length]; @@ -290,7 +288,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat private ICPPMethod[] getOwnInheritedConstructors() { if (ownInheritedConstructors != null) return ownInheritedConstructors; - ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); + ICPPConstructor[] ctors = specialClass.getSpecializedBinding().getConstructors(); ICPPConstructor[] specializedCtors = specializeMembers(ctors); return getOwnInheritedConstructors(specializedCtors); } @@ -314,7 +312,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); return specializeMembers(bindings); } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { ICPPUsingDeclaration[] bindings = specialClass.getSpecializedBinding().getUsingDeclarations(); @@ -329,7 +327,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public IScope getParent() throws DOMException { - IBinding binding= specialClass.getOwner(); + IBinding binding = specialClass.getOwner(); if (binding instanceof ICPPClassType) { return ((ICPPClassType) binding).getCompositeScope(); } @@ -341,7 +339,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public IBinding[] find(String name, IASTTranslationUnit tu) { - return find(name); + return find(name); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java index 89497dd7741..9dd12b8c9f7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTASMDeclaration.java @@ -21,9 +21,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ public class CPPASTASMDeclaration extends ASTNode implements IASTASMDeclaration { - char [] assembly = null; + char[] assembly = null; - public CPPASTASMDeclaration() { + public CPPASTASMDeclaration() { } public CPPASTASMDeclaration(String assembly) { @@ -44,34 +44,40 @@ public class CPPASTASMDeclaration extends ASTNode implements IASTASMDeclaration @Override public String getAssembly() { - if (assembly == null) - return ""; //$NON-NLS-1$ - return new String(assembly); - } + if (assembly == null) + return ""; //$NON-NLS-1$ + return new String(assembly); + } - @Override + @Override public void setAssembly(String assembly) { - assertNotFrozen(); - this.assembly = assembly.toCharArray(); - } + assertNotFrozen(); + this.assembly = assembly.toCharArray(); + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java index f39a62a8b9f..86993e21f22 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java @@ -30,8 +30,10 @@ public class CPPASTAliasDeclaration extends CPPASTAttributeOwner implements ICPP @Override public int getRoleForName(IASTName name) { - if (aliasName == name) return r_definition; - if (mappingTypeId == name) return r_reference; + if (aliasName == name) + return r_definition; + if (mappingTypeId == name) + return r_reference; return r_unclear; } @@ -72,8 +74,7 @@ public class CPPASTAliasDeclaration extends CPPASTAttributeOwner implements ICPP @Override public ICPPASTAliasDeclaration copy(CopyStyle style) { - CPPASTAliasDeclaration copy = new CPPASTAliasDeclaration( - aliasName == null ? null : aliasName.copy(style), + CPPASTAliasDeclaration copy = new CPPASTAliasDeclaration(aliasName == null ? null : aliasName.copy(style), mappingTypeId == null ? null : mappingTypeId.copy(style)); return copy(copy, style); } @@ -82,21 +83,30 @@ public class CPPASTAliasDeclaration extends CPPASTAttributeOwner implements ICPP public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclarations) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } - if (aliasName != null && !aliasName.accept(action)) return false; - if (!acceptByAttributeSpecifiers(action)) return false; - if (mappingTypeId != null && !mappingTypeId.accept(action)) return false; + if (aliasName != null && !aliasName.accept(action)) + return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (mappingTypeId != null && !mappingTypeId.accept(action)) + return false; if (action.shouldVisitDeclarations) { switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } return true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAlignmentSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAlignmentSpecifier.java index b97c039b6c1..b145adad4b9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAlignmentSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAlignmentSpecifier.java @@ -22,8 +22,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAlignmentSpecifier; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; -public class CPPASTAlignmentSpecifier extends ASTNode implements ICPPASTAlignmentSpecifier, - IASTAmbiguityParent { +public class CPPASTAlignmentSpecifier extends ASTNode implements ICPPASTAlignmentSpecifier, IASTAmbiguityParent { // Precisely one of these is null. private IASTExpression fExpression; private IASTTypeId fTypeId; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java index 03d0f354d62..0c375a0d887 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java @@ -50,14 +50,14 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * Visitor to resolve AST ambiguities in the right order */ final class CPPASTAmbiguityResolver extends ASTVisitor { - private int fSkipInitializers= 0; + private int fSkipInitializers = 0; /* * The current nesting level of class definitions. * Used to handle processing of method bodies, which are deferred * until the end of the outermost class definition. */ - private int fClassNestingLevel= 0; - private HashSet<IASTDeclaration> fRepopulate= new HashSet<>(); + private int fClassNestingLevel = 0; + private HashSet<IASTDeclaration> fRepopulate = new HashSet<>(); /* * Nodes that have been deferred for later processing. * Currently used only for method bodies. @@ -74,17 +74,17 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { public CPPASTAmbiguityResolver() { super(false); - includeInactiveNodes= true; - shouldVisitAmbiguousNodes= true; - shouldVisitDeclarations= true; - shouldVisitDeclSpecifiers= true; - shouldVisitInitializers= true; - shouldVisitTranslationUnit= true; + includeInactiveNodes = true; + shouldVisitAmbiguousNodes = true; + shouldVisitDeclarations = true; + shouldVisitDeclSpecifiers = true; + shouldVisitInitializers = true; + shouldVisitTranslationUnit = true; } @Override public int visit(ASTAmbiguousNode astAmbiguousNode) { - IASTNode node= astAmbiguousNode.resolveAmbiguity(this); + IASTNode node = astAmbiguousNode.resolveAmbiguity(this); if (node instanceof IASTDeclarator) { while (node != null) { if (node instanceof IASTDeclaration) { @@ -94,11 +94,11 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { if (node instanceof IASTParameterDeclaration) { // If the parameter declaration belongs to a function declaration or // function definition we need to update the scope. - IASTNode parent= node.getParent(); + IASTNode parent = node.getParent(); if (parent instanceof IASTDeclarator) { - IASTDeclarator dtor= (IASTDeclarator) parent; - if (dtor == ASTQueries.findTypeRelevantDeclarator(dtor) && - ASTQueries.findOutermostDeclarator(dtor).getParent() instanceof IASTDeclaration) { + IASTDeclarator dtor = (IASTDeclarator) parent; + if (dtor == ASTQueries.findTypeRelevantDeclarator(dtor) + && ASTQueries.findOutermostDeclarator(dtor).getParent() instanceof IASTDeclaration) { repopulateScope((IASTParameterDeclaration) node); } } @@ -107,7 +107,7 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { if (node instanceof IASTExpression) { break; } - node= node.getParent(); + node = node.getParent(); } } else if (node instanceof IASTDeclaration) { repopulateScope((IASTDeclaration) node); @@ -154,7 +154,7 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { @Override public int visit(IASTDeclaration decl) { if (decl instanceof IASTFunctionDefinition && !shouldProcessNow((IASTFunctionDefinition) decl)) { - final IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl; + final IASTFunctionDefinition fdef = (IASTFunctionDefinition) decl; // Visit the declarator first, it may contain ambiguous template arguments needed // for associating the template declarations. @@ -194,21 +194,20 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { // We need to create class bindings for all definitions and for the specializations. // Otherwise, name resolution cannot access members or correct specialization. if (declaration instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration sdecl= (IASTSimpleDeclaration) declaration; - IASTName name= null; + IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) declaration; + IASTName name = null; IASTDeclSpecifier declspec = sdecl.getDeclSpecifier(); if (declspec instanceof IASTCompositeTypeSpecifier) { // Definition of a class[template[specialization]] - name= ((IASTCompositeTypeSpecifier) declspec).getName().getLastName(); - } else if (declspec instanceof ICPPASTElaboratedTypeSpecifier - && sdecl.getDeclarators().length == 0) { + name = ((IASTCompositeTypeSpecifier) declspec).getName().getLastName(); + } else if (declspec instanceof ICPPASTElaboratedTypeSpecifier && sdecl.getDeclarators().length == 0) { ASTNodeProperty prop = declaration.getPropertyInParent(); if (prop == ICPPASTTemplateDeclaration.OWNED_DECLARATION || prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION) { - ICPPASTElaboratedTypeSpecifier elab= (ICPPASTElaboratedTypeSpecifier) declspec; + ICPPASTElaboratedTypeSpecifier elab = (ICPPASTElaboratedTypeSpecifier) declspec; if (!elab.isFriend()) { // Declaration of a class template specialization. - name= elab.getName().getLastName(); + name = elab.getName().getLastName(); } } } @@ -238,14 +237,14 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { } private void repopulateScope(IASTDeclaration declaration) { - IScope scope= CPPVisitor.getContainingNonTemplateScope(declaration); + IScope scope = CPPVisitor.getContainingNonTemplateScope(declaration); if (scope instanceof ICPPASTInternalScope) { CPPSemantics.populateCache((ICPPASTInternalScope) scope, declaration); } } private void repopulateScope(IASTParameterDeclaration declaration) { - IScope scope= CPPVisitor.getContainingNonTemplateScope(declaration); + IScope scope = CPPVisitor.getContainingNonTemplateScope(declaration); if (scope instanceof ICPPASTInternalScope) { CPPSemantics.populateCache((ICPPASTInternalScope) scope, declaration); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java index c41d6f83099..306d913936a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousBinaryVsCastExpression.java @@ -20,10 +20,11 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitDestructorName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousBinaryVsCastExpression; -public class CPPASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsCastExpression implements ICPPASTExpression { +public class CPPASTAmbiguousBinaryVsCastExpression extends ASTAmbiguousBinaryVsCastExpression + implements ICPPASTExpression { - public CPPASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression bexp, IASTCastExpression castExpr) { - super(bexp, castExpr); + public CPPASTAmbiguousBinaryVsCastExpression(IASTBinaryExpression bexp, IASTCastExpression castExpr) { + super(bexp, castExpr); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java index 490767d9550..49ec3e17ed7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCastVsFunctionCallExpression.java @@ -20,11 +20,12 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitDestructorName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousCastVsFunctionCallExpression; -public class CPPASTAmbiguousCastVsFunctionCallExpression - extends ASTAmbiguousCastVsFunctionCallExpression implements ICPPASTExpression { +public class CPPASTAmbiguousCastVsFunctionCallExpression extends ASTAmbiguousCastVsFunctionCallExpression + implements ICPPASTExpression { - public CPPASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall) { - super(castExpr, funcCall); + public CPPASTAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, + IASTFunctionCallExpression funcCall) { + super(castExpr, funcCall); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java index e2abae7f50c..395ded437c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java @@ -29,8 +29,8 @@ public class CPPASTAmbiguousCondition extends ASTAmbiguousNode implements IASTAm private IASTDeclaration fDeclaration; public CPPASTAmbiguousCondition(IASTExpression expression, IASTSimpleDeclaration declaration) { - fExpression= expression; - fDeclaration= declaration; + fExpression = expression; + fDeclaration = declaration; expression.setParent(this); expression.setPropertyInParent(SUBCONDITION); @@ -40,13 +40,13 @@ public class CPPASTAmbiguousCondition extends ASTAmbiguousNode implements IASTAm @Override public IASTNode[] getNodes() { - return new IASTNode[] {fExpression, fDeclaration}; + return new IASTNode[] { fExpression, fDeclaration }; } @Override protected void beforeResolution() { // populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CPPVisitor.getContainingNonTemplateScope(this); + IScope scope = CPPVisitor.getContainingNonTemplateScope(this); if (scope instanceof ICPPASTInternalScope) { ((ICPPASTInternalScope) scope).populateCache(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java index ec9e0db34d4..7c78e4d0bae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java @@ -36,13 +36,12 @@ import org.eclipse.core.runtime.Assert; * <br> * Example: void f(int (D)); // is D a type? */ -public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode - implements IASTAmbiguousDeclarator, ICPPASTDeclarator { - private IASTDeclarator[] dtors = new IASTDeclarator[2]; - private int dtorPos= -1; +public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmbiguousDeclarator, ICPPASTDeclarator { + private IASTDeclarator[] dtors = new IASTDeclarator[2]; + private int dtorPos = -1; private IASTInitializer fInitializer; - public CPPASTAmbiguousDeclarator(IASTDeclarator... decls) { + public CPPASTAmbiguousDeclarator(IASTDeclarator... decls) { for (IASTDeclarator d : decls) { if (d != null) { addDeclarator(d); @@ -53,20 +52,20 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode @Override protected void beforeResolution() { // populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CPPVisitor.getContainingNonTemplateScope(this); + IScope scope = CPPVisitor.getContainingNonTemplateScope(this); if (scope instanceof ICPPASTInternalScope) { ((ICPPASTInternalScope) scope).populateCache(); } } - @Override + @Override protected void afterResolution(ASTVisitor resolver, IASTNode best) { - // if we have an initializer it needs to be added to the chosen alternative. - // we also need to resolve ambiguities in the initializer. - if (fInitializer != null) { - ((IASTDeclarator) best).setInitializer(fInitializer); - fInitializer.accept(resolver); - } + // if we have an initializer it needs to be added to the chosen alternative. + // we also need to resolve ambiguities in the initializer. + if (fInitializer != null) { + ((IASTDeclarator) best).setInitializer(fInitializer); + fInitializer.accept(resolver); + } } @Override @@ -81,24 +80,24 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode @Override public void addDeclarator(IASTDeclarator d) { - assertNotFrozen(); - if (d != null) { - dtors = ArrayUtil.appendAt(IASTDeclarator.class, dtors, ++dtorPos, d); - d.setParent(this); + assertNotFrozen(); + if (d != null) { + dtors = ArrayUtil.appendAt(IASTDeclarator.class, dtors, ++dtorPos, d); + d.setParent(this); d.setPropertyInParent(SUBDECLARATOR); - } - } + } + } - @Override + @Override public IASTDeclarator[] getDeclarators() { - dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos); - return dtors; - } + dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos); + return dtors; + } - @Override + @Override public IASTNode[] getNodes() { - return getDeclarators(); - } + return getDeclarators(); + } @Override public IASTInitializer getInitializer() { @@ -122,7 +121,7 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode @Override public void addPointerOperator(IASTPointerOperator operator) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @@ -134,7 +133,7 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode @Override @Deprecated public void addAttribute(IASTAttribute attribute) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @@ -157,18 +156,18 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode @Override public void setInitializer(IASTInitializer initializer) { // store the initializer until the ambiguity is resolved - fInitializer= initializer; + fInitializer = initializer; } @Override public void setName(IASTName name) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @Override public void setNestedDeclarator(IASTDeclarator nested) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } @@ -179,7 +178,7 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode @Override public void setDeclaresParameterPack(boolean val) { - assertNotFrozen(); + assertNotFrozen(); Assert.isLegal(false); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java index 0f0406d8ea6..55379995592 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousExpression.java @@ -23,18 +23,17 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; -public class CPPASTAmbiguousExpression extends ASTAmbiguousNode - implements IASTAmbiguousExpression, ICPPASTExpression { - private IASTExpression[] exp = new IASTExpression[2]; - private int expPos; +public class CPPASTAmbiguousExpression extends ASTAmbiguousNode implements IASTAmbiguousExpression, ICPPASTExpression { + private IASTExpression[] exp = new IASTExpression[2]; + private int expPos; - public CPPASTAmbiguousExpression(IASTExpression... expressions) { + public CPPASTAmbiguousExpression(IASTExpression... expressions) { for (IASTExpression e : expressions) { addExpression(e); } } - @Override + @Override public IASTExpression copy() { throw new UnsupportedOperationException(); } @@ -46,24 +45,24 @@ public class CPPASTAmbiguousExpression extends ASTAmbiguousNode @Override public void addExpression(IASTExpression e) { - assertNotFrozen(); - if (e != null) { - exp = ArrayUtil.appendAt(exp, expPos++, e); - e.setParent(this); + assertNotFrozen(); + if (e != null) { + exp = ArrayUtil.appendAt(exp, expPos++, e); + e.setParent(this); e.setPropertyInParent(SUBEXPRESSION); - } - } + } + } - @Override + @Override public IASTExpression[] getExpressions() { - exp = ArrayUtil.trim(exp, expPos); - return exp; - } + exp = ArrayUtil.trim(exp, expPos); + return exp; + } - @Override + @Override public IASTNode[] getNodes() { - return getExpressions(); - } + return getExpressions(); + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java index 93a05adb6a5..b64d00ba25d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousParameterDeclaration.java @@ -41,28 +41,28 @@ import org.eclipse.core.runtime.Assert; */ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implements IASTAmbiguousParameterDeclaration, ICPPASTParameterDeclaration { - private ICPPASTParameterDeclaration fParameterDecl; + private ICPPASTParameterDeclaration fParameterDecl; - public CPPASTAmbiguousParameterDeclaration(ICPPASTParameterDeclaration decl) { - fParameterDecl= decl; + public CPPASTAmbiguousParameterDeclaration(ICPPASTParameterDeclaration decl) { + fParameterDecl = decl; } @Override public void addParameterDeclaration(IASTParameterDeclaration d) { assert false; - } + } - @Override + @Override protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) { - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); // Setup the ast to use the alternative owner.replace(this, fParameterDecl); fParameterDecl.accept(resolver); - IType t= CPPVisitor.createType(fParameterDecl, true); - if (!(t instanceof ICPPParameterPackType) || - !CPPTemplates.containsParameterPack(((ICPPParameterPackType) t).getType())) { + IType t = CPPVisitor.createType(fParameterDecl, true); + if (!(t instanceof ICPPParameterPackType) + || !CPPTemplates.containsParameterPack(((ICPPParameterPackType) t).getType())) { final ICPPASTDeclarator dtor = fParameterDecl.getDeclarator(); dtor.setDeclaresParameterPack(false); adjustOffsets(dtor); @@ -72,7 +72,7 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode } private void adjustOffsets(final ICPPASTDeclarator dtor) { - IASTPointerOperator[] ptrOps= dtor.getPointerOperators(); + IASTPointerOperator[] ptrOps = dtor.getPointerOperators(); final ASTNode asNode = (ASTNode) dtor; if (ptrOps.length > 0) { final ASTNode first = (ASTNode) ptrOps[0]; @@ -85,13 +85,13 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode @Override public IASTParameterDeclaration[] getParameterDeclarations() { - return new IASTParameterDeclaration[] { fParameterDecl }; - } + return new IASTParameterDeclaration[] { fParameterDecl }; + } - @Override + @Override public IASTNode[] getNodes() { - return getParameterDeclarations(); - } + return getParameterDeclarations(); + } @Override public IASTDeclSpecifier getDeclSpecifier() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java index ff95bc78a17..52b3fd21efc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java @@ -41,29 +41,30 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * </pre> */ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration { - private IASTSimpleDeclaration fSimpleDecl; - private IASTDeclSpecifier fAltDeclSpec; - private IASTDeclarator fAltDtor; - - public CPPASTAmbiguousSimpleDeclaration(IASTSimpleDeclaration decl, IASTDeclSpecifier declSpec, IASTDeclarator dtor) { - fSimpleDecl= decl; - fAltDeclSpec= declSpec; - fAltDtor= dtor; + private IASTSimpleDeclaration fSimpleDecl; + private IASTDeclSpecifier fAltDeclSpec; + private IASTDeclarator fAltDtor; + + public CPPASTAmbiguousSimpleDeclaration(IASTSimpleDeclaration decl, IASTDeclSpecifier declSpec, + IASTDeclarator dtor) { + fSimpleDecl = decl; + fAltDeclSpec = declSpec; + fAltDtor = dtor; } @Override protected void beforeResolution() { // Populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CPPVisitor.getContainingScope(this); + IScope scope = CPPVisitor.getContainingScope(this); if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).populateCache(); } } - @Override + @Override public IASTNode[] getNodes() { - return new IASTNode[] { fSimpleDecl, fAltDeclSpec, fAltDtor }; - } + return new IASTNode[] { fSimpleDecl, fAltDeclSpec, fAltDtor }; + } @Override public IASTSimpleDeclaration copy() { @@ -97,30 +98,30 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement @Override protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) { - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); - IASTNode nodeToReplace= this; + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace = this; // Handle nested ambiguities first. owner.replace(nodeToReplace, fSimpleDecl); - IASTDeclarator dtor= fSimpleDecl.getDeclarators()[0]; + IASTDeclarator dtor = fSimpleDecl.getDeclarators()[0]; dtor.accept(resolver); // Find nested names. - final NameCollector nameCollector= new NameCollector(); + final NameCollector nameCollector = new NameCollector(); dtor.accept(nameCollector); - final IASTName[] names= nameCollector.getNames(); + final IASTName[] names = nameCollector.getNames(); // Resolve names. - boolean hasIssue= false; + boolean hasIssue = false; for (IASTName name : names) { try { IBinding b = name.resolveBinding(); if (b instanceof IProblemBinding) { - hasIssue= true; + hasIssue = true; break; } } catch (Exception t) { - hasIssue= true; + hasIssue = true; break; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java index f17957d6fba..45197a107a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java @@ -31,12 +31,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement { - private IASTStatement[] stmts = new IASTStatement[2]; - private int stmtsPos= -1; + private IASTStatement[] stmts = new IASTStatement[2]; + private int stmtsPos = -1; private IScope fScope; private IASTDeclaration fDeclaration; - public CPPASTAmbiguousStatement(IASTStatement... statements) { + public CPPASTAmbiguousStatement(IASTStatement... statements) { for (IASTStatement s : statements) { addStatement(s); } @@ -46,7 +46,7 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm protected void beforeResolution() { // Populate containing scope, so that it will not be affected by the alternative // branches. - fScope= CPPVisitor.getContainingScope(this); + fScope = CPPVisitor.getContainingScope(this); if (fScope instanceof ICPPASTInternalScope) { ((ICPPASTInternalScope) fScope).populateCache(); } @@ -72,14 +72,14 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm @Override protected void afterResolution(ASTVisitor resolver, IASTNode best) { beforeAlternative(best); - fDeclaration= null; - fScope= null; + fDeclaration = null; + fScope = null; } - @Override + @Override public IASTStatement copy() { - throw new UnsupportedOperationException(); - } + throw new UnsupportedOperationException(); + } @Override public IASTStatement copy(CopyStyle style) { @@ -88,24 +88,24 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm @Override public void addStatement(IASTStatement s) { - assertNotFrozen(); - if (s != null) { - stmts = ArrayUtil.appendAt(IASTStatement.class, stmts, ++stmtsPos, s); - s.setParent(this); + assertNotFrozen(); + if (s != null) { + stmts = ArrayUtil.appendAt(IASTStatement.class, stmts, ++stmtsPos, s); + s.setParent(this); s.setPropertyInParent(STATEMENT); - } - } + } + } - @Override + @Override public IASTStatement[] getStatements() { - stmts = ArrayUtil.trimAt(IASTStatement.class, stmts, stmtsPos); - return stmts; - } + stmts = ArrayUtil.trimAt(IASTStatement.class, stmts, stmtsPos); + return stmts; + } - @Override + @Override public IASTNode[] getNodes() { - return getStatements(); - } + return getStatements(); + } @Override public IASTAttribute[] getAttributes() { @@ -114,7 +114,7 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm @Override public void addAttribute(IASTAttribute attribute) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java index e143de6a3bc..b8b6fd82250 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java @@ -44,7 +44,7 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements * or {@link ICPPASTPackExpansionExpression}. */ public CPPASTAmbiguousTemplateArgument(IASTNode... nodes) { - fNodes= new ArrayList<IASTNode>(2); + fNodes = new ArrayList<IASTNode>(2); for (IASTNode node : nodes) { if (node instanceof IASTTypeId || node instanceof IASTExpression) { fNodes.add(node); @@ -62,7 +62,7 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements if (node instanceof IASTTypeId) { IASTDeclSpecifier declSpec = ((IASTTypeId) node).getDeclSpecifier(); if (declSpec instanceof IASTNamedTypeSpecifier) { - IASTNamedTypeSpecifier namedTypeSpec= (IASTNamedTypeSpecifier) declSpec; + IASTNamedTypeSpecifier namedTypeSpec = (IASTNamedTypeSpecifier) declSpec; final IASTName name = namedTypeSpec.getName(); name.setBinding(null); namedTypeSpec.setName(name); @@ -70,10 +70,10 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements } else { // Unwrap variadic pack expansion if necessary. if (node instanceof ICPPASTPackExpansionExpression) - node= ((ICPPASTPackExpansionExpression) node).getPattern(); + node = ((ICPPASTPackExpansionExpression) node).getPattern(); if (node instanceof IASTIdExpression) { - IASTIdExpression id= (IASTIdExpression) node; + IASTIdExpression id = (IASTIdExpression) node; final IASTName name = id.getName(); name.setBinding(null); id.setName(name); @@ -116,7 +116,7 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements @Override public void addTypeId(IASTTypeId typeId) { - assertNotFrozen(); + assertNotFrozen(); addNode(typeId); } @@ -128,13 +128,13 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements @Override public void addIdExpression(IASTIdExpression idExpression) { - addExpression(idExpression); + addExpression(idExpression); } @Deprecated @Override public void addIdExpression(IASTExpression idExpression) { - addExpression(idExpression); + addExpression(idExpression); } private void addNode(IASTNode node) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java index ac928fe22c0..828776854d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java @@ -25,10 +25,10 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; * Array declarator for c++. */ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTArrayDeclarator { - private IASTArrayModifier[] arrayMods = null; - private int arrayModsPos = -1; + private IASTArrayModifier[] arrayMods = null; + private int arrayModsPos = -1; - public CPPASTArrayDeclarator(IASTName name, IASTInitializer initializer) { + public CPPASTArrayDeclarator(IASTName name, IASTInitializer initializer) { super(name, initializer); } @@ -36,10 +36,10 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr super(name); } - public CPPASTArrayDeclarator() { + public CPPASTArrayDeclarator() { } - @Override + @Override public CPPASTArrayDeclarator copy() { return copy(CopyStyle.withoutLocations); } @@ -55,25 +55,23 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr @Override public IASTArrayModifier[] getArrayModifiers() { - if (arrayMods == null) - return IASTArrayModifier.EMPTY_ARRAY; - arrayMods = ArrayUtil.trimAt(IASTArrayModifier.class, - arrayMods, arrayModsPos); - return arrayMods; - } + if (arrayMods == null) + return IASTArrayModifier.EMPTY_ARRAY; + arrayMods = ArrayUtil.trimAt(IASTArrayModifier.class, arrayMods, arrayModsPos); + return arrayMods; + } - @Override + @Override public void addArrayModifier(IASTArrayModifier arrayModifier) { - assertNotFrozen(); - if (arrayModifier != null) { - arrayMods = ArrayUtil.appendAt(IASTArrayModifier.class, arrayMods, - ++arrayModsPos, arrayModifier); - arrayModifier.setParent(this); + assertNotFrozen(); + if (arrayModifier != null) { + arrayMods = ArrayUtil.appendAt(IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier); + arrayModifier.setParent(this); arrayModifier.setPropertyInParent(ARRAY_MODIFIER); - } - } + } + } - @Override + @Override protected boolean postAccept(ASTVisitor action) { IASTArrayModifier[] mods = getArrayModifiers(); for (int i = 0; i < mods.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDesignator.java index 89879951760..6f9081041c7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDesignator.java @@ -24,9 +24,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * Implementation of array designator. */ public class CPPASTArrayDesignator extends ASTNode implements ICPPASTArrayDesignator, IASTAmbiguityParent { - private ICPPASTExpression expression; + private ICPPASTExpression expression; - public CPPASTArrayDesignator() { + public CPPASTArrayDesignator() { } public CPPASTArrayDesignator(ICPPASTExpression exp) { @@ -45,29 +45,32 @@ public class CPPASTArrayDesignator extends ASTNode implements ICPPASTArrayDesign return copy(copy, style); } - @Override + @Override public ICPPASTExpression getSubscriptExpression() { - return expression; - } + return expression; + } - @Override + @Override public void setSubscriptExpression(ICPPASTExpression value) { - assertNotFrozen(); - expression = value; - if (value != null) { - value.setParent(this); - value.setPropertyInParent(SUBSCRIPT_EXPRESSION); - } - } + assertNotFrozen(); + expression = value; + if (value != null) { + value.setParent(this); + value.setPropertyInParent(SUBSCRIPT_EXPRESSION); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDesignators) { + if (action.shouldVisitDesignators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (expression != null && !expression.accept(action)) return false; @@ -76,14 +79,14 @@ public class CPPASTArrayDesignator extends ASTNode implements ICPPASTArrayDesign return false; return true; - } + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == expression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expression = (ICPPASTExpression) other; - } - } + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expression = (ICPPASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java index 8e7060b5520..1d7e0b17af5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java @@ -24,9 +24,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * @author jcamelon */ public class CPPASTArrayModifier extends CPPASTAttributeOwner implements IASTArrayModifier { - private IASTExpression exp; + private IASTExpression exp; - public CPPASTArrayModifier() { + public CPPASTArrayModifier() { } public CPPASTArrayModifier(IASTExpression exp) { @@ -35,8 +35,8 @@ public class CPPASTArrayModifier extends CPPASTAttributeOwner implements IASTArr @Override public IASTExpression getConstantExpression() { - return exp; - } + return exp; + } @Override public CPPASTArrayModifier copy() { @@ -49,27 +49,30 @@ public class CPPASTArrayModifier extends CPPASTAttributeOwner implements IASTArr return copy(copy, style); } - @Override + @Override public void setConstantExpression(IASTExpression expression) { - assertNotFrozen(); - exp = expression; - if (expression != null) { + assertNotFrozen(); + exp = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(CONSTANT_EXPRESSION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitArrayModifiers) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - if (exp != null && !exp.accept(action)) - return false; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + if (exp != null && !exp.accept(action)) + return false; if (!acceptByAttributeSpecifiers(action)) return false; @@ -78,16 +81,16 @@ public class CPPASTArrayModifier extends CPPASTAttributeOwner implements IASTArr return false; return true; - } + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == exp) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - exp = (IASTExpression) other; - return; - } - super.replace(child, other); - } + if (child == exp) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + exp = (IASTExpression) other; + return; + } + super.replace(child, other); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayRangeDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayRangeDesignator.java index b438a1f59b4..88f6c2b5963 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayRangeDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayRangeDesignator.java @@ -23,8 +23,7 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Implementation of array range designator. */ -public class CPPASTArrayRangeDesignator extends ASTNode - implements IGPPASTArrayRangeDesignator, IASTAmbiguityParent { +public class CPPASTArrayRangeDesignator extends ASTNode implements IGPPASTArrayRangeDesignator, IASTAmbiguityParent { private ICPPASTExpression floor; private ICPPASTExpression ceiling; @@ -83,9 +82,12 @@ public class CPPASTArrayRangeDesignator extends ASTNode public boolean accept(ASTVisitor action) { if (action.shouldVisitDesignators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } if (floor != null && !floor.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java index 538bc613f26..7f10d2e0dfa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java @@ -38,12 +38,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent { - private ICPPASTExpression arrayExpression; - private ICPPASTInitializerClause subscriptExp; - private ICPPEvaluation evaluation; - private IASTImplicitName[] implicitNames; + private ICPPASTExpression arrayExpression; + private ICPPASTInitializerClause subscriptExp; + private ICPPEvaluation evaluation; + private IASTImplicitName[] implicitNames; - public CPPASTArraySubscriptExpression() { + public CPPASTArraySubscriptExpression() { } public CPPASTArraySubscriptExpression(IASTExpression arrayExpression, IASTInitializerClause operand) { @@ -66,53 +66,53 @@ public class CPPASTArraySubscriptExpression extends ASTNode @Override public ICPPASTExpression getArrayExpression() { - return arrayExpression; - } + return arrayExpression; + } - @Override + @Override public void setArrayExpression(IASTExpression expression) { - assertNotFrozen(); - if (expression != null) { - if (!(expression instanceof ICPPASTExpression)) - throw new IllegalArgumentException(expression.getClass().getName()); + assertNotFrozen(); + if (expression != null) { + if (!(expression instanceof ICPPASTExpression)) + throw new IllegalArgumentException(expression.getClass().getName()); expression.setParent(this); expression.setPropertyInParent(ARRAY); } - arrayExpression = (ICPPASTExpression) expression; - } + arrayExpression = (ICPPASTExpression) expression; + } - @Override + @Override public ICPPASTInitializerClause getArgument() { - return subscriptExp; - } + return subscriptExp; + } - @Override + @Override public void setArgument(IASTInitializerClause arg) { - assertNotFrozen(); - if (arg != null) { - if (!(arg instanceof ICPPASTInitializerClause)) - throw new IllegalArgumentException(arg.getClass().getName()); - arg.setParent(this); - arg.setPropertyInParent(SUBSCRIPT); + assertNotFrozen(); + if (arg != null) { + if (!(arg instanceof ICPPASTInitializerClause)) + throw new IllegalArgumentException(arg.getClass().getName()); + arg.setParent(this); + arg.setPropertyInParent(SUBSCRIPT); } - subscriptExp = (ICPPASTInitializerClause) arg; - } + subscriptExp = (ICPPASTInitializerClause) arg; + } - @Override + @Override @Deprecated - public IASTExpression getSubscriptExpression() { - if (subscriptExp instanceof IASTExpression) - return (IASTExpression) subscriptExp; - return null; - } + public IASTExpression getSubscriptExpression() { + if (subscriptExp instanceof IASTExpression) + return (IASTExpression) subscriptExp; + return null; + } - @Override + @Override @Deprecated - public void setSubscriptExpression(IASTExpression expression) { - setArgument(expression); - } + public void setSubscriptExpression(IASTExpression expression) { + setArgument(expression); + } - @Override + @Override public IASTImplicitName[] getImplicitNames() { if (implicitNames == null) { ICPPFunction overload = getOverload(); @@ -150,55 +150,61 @@ public class CPPASTArraySubscriptExpression extends ASTNode @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (arrayExpression != null && !arrayExpression.accept(action)) - return false; + if (arrayExpression != null && !arrayExpression.accept(action)) + return false; - IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; + IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; - if (implicits != null && implicits.length > 0 && !implicits[0].accept(action)) - return false; + if (implicits != null && implicits.length > 0 && !implicits[0].accept(action)) + return false; - if (subscriptExp != null && !subscriptExp.accept(action)) - return false; + if (subscriptExp != null && !subscriptExp.accept(action)) + return false; - if (implicits != null && implicits.length > 0 && !implicits[1].accept(action)) - return false; + if (implicits != null && implicits.length > 0 && !implicits[1].accept(action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == subscriptExp) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - subscriptExp = (ICPPASTExpression) other; - } - if (child == arrayExpression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - arrayExpression = (ICPPASTExpression) other; - } - } + if (child == subscriptExp) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + subscriptExp = (ICPPASTExpression) other; + } + if (child == arrayExpression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + arrayExpression = (ICPPASTExpression) other; + } + } @Override public ICPPEvaluation getEvaluation() { if (evaluation == null) - evaluation= computeEvaluation(); + evaluation = computeEvaluation(); return evaluation; } @@ -206,16 +212,14 @@ public class CPPASTArraySubscriptExpression extends ASTNode private ICPPEvaluation computeEvaluation() { if (arrayExpression == null || subscriptExp == null) return EvalFixed.INCOMPLETE; - return new EvalBinary(EvalBinary.op_arrayAccess, - arrayExpression.getEvaluation(), - subscriptExp.getEvaluation(), - this); + return new EvalBinary(EvalBinary.op_arrayAccess, arrayExpression.getEvaluation(), subscriptExp.getEvaluation(), + this); } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java index 70d3ab75a19..46eb0d85083 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java @@ -28,7 +28,7 @@ public class CPPASTAttribute extends ASTAttribute implements ICPPASTAttribute { public CPPASTAttribute(char[] name, char[] scope, IASTToken argumentsClause, boolean packExpansion) { super(name, argumentsClause); this.scope = scope; - this.packExpansion = packExpansion; + this.packExpansion = packExpansion; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java index 9650f135121..c55d980685f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java @@ -22,150 +22,150 @@ import org.eclipse.cdt.internal.core.model.ASTStringUtil; * Base for all C++ declaration specifiers. */ public abstract class CPPASTBaseDeclSpecifier extends CPPASTAttributeOwner implements ICPPASTDeclSpecifier { - private boolean isConst; - private boolean isConstexpr; - private boolean isExplicit; - private boolean isFriend; - private boolean isInline; - private boolean isRestrict; - private boolean isThreadLocal; - private boolean isVirtual; - private boolean isVolatile; - private int storageClass; - - @Override + private boolean isConst; + private boolean isConstexpr; + private boolean isExplicit; + private boolean isFriend; + private boolean isInline; + private boolean isRestrict; + private boolean isThreadLocal; + private boolean isVirtual; + private boolean isVolatile; + private int storageClass; + + @Override public final boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public final void setConst(boolean value) { - assertNotFrozen(); - isConst = value; - } + assertNotFrozen(); + isConst = value; + } - @Override + @Override public final boolean isConstexpr() { - return isConstexpr; - } + return isConstexpr; + } - @Override + @Override public final void setConstexpr(boolean value) { - assertNotFrozen(); - isConstexpr = value; - } + assertNotFrozen(); + isConstexpr = value; + } - @Override + @Override public final boolean isFriend() { - return isFriend; - } + return isFriend; + } - @Override + @Override public final void setFriend(boolean value) { - assertNotFrozen(); - isFriend = value; - } + assertNotFrozen(); + isFriend = value; + } - @Override + @Override public final int getStorageClass() { - return storageClass; - } + return storageClass; + } - @Override + @Override public final void setStorageClass(int storageClass) { - assertNotFrozen(); - this.storageClass = storageClass; - } + assertNotFrozen(); + this.storageClass = storageClass; + } - @Override + @Override public final boolean isThreadLocal() { - return isThreadLocal; - } + return isThreadLocal; + } - @Override + @Override public final void setThreadLocal(boolean value) { - assertNotFrozen(); - isThreadLocal = value; - } + assertNotFrozen(); + isThreadLocal = value; + } - @Override + @Override public final boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public final void setVolatile(boolean value) { - assertNotFrozen(); - isVolatile = value; - } + assertNotFrozen(); + isVolatile = value; + } - @Override + @Override public final boolean isRestrict() { - return isRestrict; - } + return isRestrict; + } - @Override + @Override public final void setRestrict(boolean value) { - assertNotFrozen(); - isRestrict = value; - } + assertNotFrozen(); + isRestrict = value; + } - @Override + @Override public final boolean isInline() { - return isInline; - } + return isInline; + } - @Override + @Override public final void setInline(boolean value) { - assertNotFrozen(); - this.isInline = value; - } + assertNotFrozen(); + this.isInline = value; + } - @Override + @Override public final boolean isVirtual() { - return isVirtual; - } + return isVirtual; + } - @Override + @Override public final void setVirtual(boolean value) { - assertNotFrozen(); - isVirtual = value; - } + assertNotFrozen(); + isVirtual = value; + } - @Override + @Override public final boolean isExplicit() { - return isExplicit; - } + return isExplicit; + } - @Override + @Override public final void setExplicit(boolean value) { - assertNotFrozen(); - this.isExplicit = value; - } + assertNotFrozen(); + this.isExplicit = value; + } - @Deprecated - @Override - public IASTAlignmentSpecifier[] getAlignmentSpecifiers() { - return null; - } + @Deprecated + @Override + public IASTAlignmentSpecifier[] getAlignmentSpecifiers() { + return null; + } - @Deprecated - @Override - public void setAlignmentSpecifiers(IASTAlignmentSpecifier[] alignmentSpecifiers) { - } + @Deprecated + @Override + public void setAlignmentSpecifiers(IASTAlignmentSpecifier[] alignmentSpecifiers) { + } protected <T extends CPPASTBaseDeclSpecifier> T copy(T copy, CopyStyle style) { CPPASTBaseDeclSpecifier target = copy; - target.isExplicit = isExplicit; - target.isFriend = isFriend; - target.isInline = isInline; - target.isConst = isConst; - target.isConstexpr = isConstexpr; - target.isRestrict= isRestrict; - target.isThreadLocal = isThreadLocal; - target.isVolatile = isVolatile; - target.storageClass = storageClass; - target.isVirtual = isVirtual; + target.isExplicit = isExplicit; + target.isFriend = isFriend; + target.isInline = isInline; + target.isConst = isConst; + target.isConstexpr = isConstexpr; + target.isRestrict = isRestrict; + target.isThreadLocal = isThreadLocal; + target.isVolatile = isVolatile; + target.storageClass = storageClass; + target.isVirtual = isVirtual; return super.copy(copy, style); } @@ -174,6 +174,6 @@ public abstract class CPPASTBaseDeclSpecifier extends CPPASTAttributeOwner imple */ @Override public String toString() { - return ASTStringUtil.getSignatureString(this, null); - } + return ASTStringUtil.getSignatureString(this, null); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java index 57aa5379147..145f38be9f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java @@ -37,15 +37,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; * Base class specifier */ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier, ICPPASTCompletionContext { - private boolean isVirtual; - private int visibility; - private ICPPASTNameSpecifier nameSpecifier; + private boolean isVirtual; + private int visibility; + private ICPPASTNameSpecifier nameSpecifier; private boolean fIsPackExpansion; - public CPPASTBaseSpecifier() { + public CPPASTBaseSpecifier() { } - public CPPASTBaseSpecifier(ICPPASTNameSpecifier nameSpecifier) { + public CPPASTBaseSpecifier(ICPPASTNameSpecifier nameSpecifier) { setNameSpecifier(nameSpecifier); } @@ -65,47 +65,47 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier CPPASTBaseSpecifier copy = new CPPASTBaseSpecifier(nameSpecifier == null ? null : nameSpecifier.copy(style)); copy.isVirtual = isVirtual; copy.visibility = visibility; - copy.fIsPackExpansion= fIsPackExpansion; + copy.fIsPackExpansion = fIsPackExpansion; return copy(copy, style); } @Override public boolean isVirtual() { - return isVirtual; - } + return isVirtual; + } - @Override + @Override public void setVirtual(boolean value) { - assertNotFrozen(); - isVirtual = value; - } + assertNotFrozen(); + isVirtual = value; + } - @Override + @Override public int getVisibility() { - return visibility; - } + return visibility; + } - @Override + @Override public void setVisibility(int visibility) { - assertNotFrozen(); - this.visibility = visibility; - } + assertNotFrozen(); + this.visibility = visibility; + } - @Override - @Deprecated + @Override + @Deprecated public IASTName getName() { - if (nameSpecifier instanceof IASTName) { - return (IASTName) nameSpecifier; - } - throw new UnsupportedOperationException("Cannot call getName() on base-specifier whose name-specifier " //$NON-NLS-1$ - + "is not a name. Use getNameSpecifier() instead."); //$NON-NLS-1$ - } - - @Override - @Deprecated + if (nameSpecifier instanceof IASTName) { + return (IASTName) nameSpecifier; + } + throw new UnsupportedOperationException("Cannot call getName() on base-specifier whose name-specifier " //$NON-NLS-1$ + + "is not a name. Use getNameSpecifier() instead."); //$NON-NLS-1$ + } + + @Override + @Deprecated public void setName(IASTName name) { - setNameSpecifier((ICPPASTName) name); - } + setNameSpecifier((ICPPASTName) name); + } @Override public ICPPASTNameSpecifier getNameSpecifier() { @@ -115,21 +115,24 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier @Override public void setNameSpecifier(ICPPASTNameSpecifier nameSpecifier) { assertNotFrozen(); - this.nameSpecifier = nameSpecifier; - if (nameSpecifier != null) { + this.nameSpecifier = nameSpecifier; + if (nameSpecifier != null) { nameSpecifier.setParent(this); nameSpecifier.setPropertyInParent(NAME_SPECIFIER); } } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitBaseSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitBaseSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (nameSpecifier != null && !nameSpecifier.accept(action)) @@ -138,12 +141,13 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier if (action.shouldVisitBaseSpecifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (nameSpecifier == n) return r_reference; + if (nameSpecifier == n) + return r_reference; return r_unclear; } @@ -167,8 +171,8 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier IType type = (IType) binding; while (type instanceof ITypedef || type instanceof ICPPAliasTemplate) { - type = type instanceof ITypedef ? - ((ITypedef) type).getType() : ((ICPPAliasTemplate) type).getType(); + type = type instanceof ITypedef ? ((ITypedef) type).getType() + : ((ICPPAliasTemplate) type).getType(); } if (type instanceof ICPPClassType) { @@ -206,6 +210,6 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier @Override public void setIsPackExpansion(boolean val) { assertNotFrozen(); - fIsPackExpansion= val; + fIsPackExpansion = val; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java index f4dcb3c8480..6238c869cdb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java @@ -40,17 +40,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.DestructorCallColl import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinary; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; - public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpression, IASTAmbiguityParent { private int fOperator; - private ICPPASTExpression fOperand1; - private ICPPASTInitializerClause fOperand2; + private ICPPASTExpression fOperand1; + private ICPPASTInitializerClause fOperand2; - private ICPPEvaluation fEvaluation; - private IASTImplicitName[] fImplicitNames; - private IASTImplicitDestructorName[] fImplicitDestructorNames; + private ICPPEvaluation fEvaluation; + private IASTImplicitName[] fImplicitNames; + private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTBinaryExpression() { + public CPPASTBinaryExpression() { } public CPPASTBinaryExpression(int op, IASTExpression operand1, IASTInitializerClause operand2) { @@ -67,67 +66,66 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr @Override public CPPASTBinaryExpression copy(CopyStyle style) { CPPASTBinaryExpression copy = new CPPASTBinaryExpression(fOperator, - fOperand1 == null ? null : fOperand1.copy(style), - fOperand2 == null ? null : fOperand2.copy(style)); + fOperand1 == null ? null : fOperand1.copy(style), fOperand2 == null ? null : fOperand2.copy(style)); return copy(copy, style); } @Override public int getOperator() { - return fOperator; - } + return fOperator; + } - @Override + @Override public IASTExpression getOperand1() { - return fOperand1; - } + return fOperand1; + } - @Override + @Override public IASTInitializerClause getInitOperand2() { - return fOperand2; - } + return fOperand2; + } - @Override + @Override public IASTExpression getOperand2() { - if (fOperand2 instanceof IASTExpression) - return (IASTExpression) fOperand2; - return null; - } + if (fOperand2 instanceof IASTExpression) + return (IASTExpression) fOperand2; + return null; + } - @Override + @Override public void setOperator(int op) { - assertNotFrozen(); - this.fOperator = op; - } + assertNotFrozen(); + this.fOperator = op; + } - @Override + @Override public void setOperand1(IASTExpression expression) { - assertNotFrozen(); - if (expression != null) { - if (!(expression instanceof ICPPASTExpression)) - throw new IllegalArgumentException(expression.getClass().getName()); + assertNotFrozen(); + if (expression != null) { + if (!(expression instanceof ICPPASTExpression)) + throw new IllegalArgumentException(expression.getClass().getName()); expression.setParent(this); expression.setPropertyInParent(OPERAND_ONE); } - fOperand1 = (ICPPASTExpression) expression; - } - - public void setInitOperand2(IASTInitializerClause operand) { - assertNotFrozen(); - if (operand != null) { - if (!(operand instanceof ICPPASTInitializerClause)) - throw new IllegalArgumentException(operand.getClass().getName()); - operand.setParent(this); - operand.setPropertyInParent(OPERAND_TWO); + fOperand1 = (ICPPASTExpression) expression; + } + + public void setInitOperand2(IASTInitializerClause operand) { + assertNotFrozen(); + if (operand != null) { + if (!(operand instanceof ICPPASTInitializerClause)) + throw new IllegalArgumentException(operand.getClass().getName()); + operand.setParent(this); + operand.setPropertyInParent(OPERAND_TWO); } - fOperand2 = (ICPPASTInitializerClause) operand; - } + fOperand2 = (ICPPASTInitializerClause) operand; + } - @Override + @Override public void setOperand2(IASTExpression expression) { - setInitOperand2(expression); - } + setInitOperand2(expression); + } @Override public IASTImplicitName[] getImplicitNames() { @@ -156,18 +154,21 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (fOperand1 instanceof IASTBinaryExpression || fOperand2 instanceof IASTBinaryExpression) { - return acceptWithoutRecursion(this, action); - } + if (fOperand1 instanceof IASTBinaryExpression || fOperand2 instanceof IASTBinaryExpression) { + return acceptWithoutRecursion(this, action); + } if (action.shouldVisitExpressions) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fOperand1 != null && !fOperand1.accept(action)) @@ -186,9 +187,9 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr return false; return true; - } + } - private static class N { + private static class N { final IASTBinaryExpression fExpression; int fState; N fNext; @@ -199,42 +200,42 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr } private static boolean acceptWithoutRecursion(IASTBinaryExpression bexpr, ASTVisitor action) { - N stack= new N(bexpr); + N stack = new N(bexpr); while (stack != null) { - IASTBinaryExpression expr= stack.fExpression; + IASTBinaryExpression expr = stack.fExpression; if (stack.fState == 0) { if (action.shouldVisitExpressions) { switch (action.visit(expr)) { case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_SKIP: - stack= stack.fNext; + stack = stack.fNext; continue; } } - stack.fState= 1; + stack.fState = 1; IASTExpression op1 = expr.getOperand1(); if (op1 instanceof IASTBinaryExpression) { - N n= new N((IASTBinaryExpression) op1); - n.fNext= stack; - stack= n; + N n = new N((IASTBinaryExpression) op1); + n.fNext = stack; + stack = n; continue; } if (op1 != null && !op1.accept(action)) return false; } if (stack.fState == 1) { - if (action.shouldVisitImplicitNames && - !acceptByNodes(((IASTImplicitNameOwner) expr).getImplicitNames(), action)) { + if (action.shouldVisitImplicitNames + && !acceptByNodes(((IASTImplicitNameOwner) expr).getImplicitNames(), action)) { return false; } - stack.fState= 2; + stack.fState = 2; IASTInitializerClause op2 = expr.getInitOperand2(); if (op2 instanceof IASTBinaryExpression) { - N n= new N((IASTBinaryExpression) op2); - n.fNext= stack; - stack= n; + N n = new N((IASTBinaryExpression) op2); + n.fNext = stack; + stack = n; continue; } if (op2 != null && !op2.accept(action)) @@ -244,7 +245,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr if (action.shouldVisitExpressions && action.leave(expr) == ASTVisitor.PROCESS_ABORT) return false; - stack= stack.fNext; + stack = stack.fNext; } return true; @@ -264,8 +265,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr } } - - @Override + @Override public ICPPFunction getOverload() { ICPPEvaluation eval = getEvaluation(); if (eval instanceof EvalBinary) { @@ -277,12 +277,12 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr } } return null; - } + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) - fEvaluation= computeEvaluation(); + fEvaluation = computeEvaluation(); return fEvaluation; } @@ -296,10 +296,10 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr return new EvalBinary(fOperator, eval1, eval2, this); } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java index 29fb627cd4e..5c9229b0731 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java @@ -30,12 +30,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinaryTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; public class CPPASTBinaryTypeIdExpression extends ASTNode implements ICPPASTExpression, IASTBinaryTypeIdExpression { - private Operator fOperator; - private IASTTypeId fOperand1; - private IASTTypeId fOperand2; - private ICPPEvaluation fEvaluation; + private Operator fOperator; + private IASTTypeId fOperand1; + private IASTTypeId fOperand2; + private ICPPEvaluation fEvaluation; - public CPPASTBinaryTypeIdExpression() { + public CPPASTBinaryTypeIdExpression() { } public CPPASTBinaryTypeIdExpression(Operator op, IASTTypeId typeId1, IASTTypeId typeId2) { @@ -52,85 +52,87 @@ public class CPPASTBinaryTypeIdExpression extends ASTNode implements ICPPASTExpr @Override public CPPASTBinaryTypeIdExpression copy(CopyStyle style) { CPPASTBinaryTypeIdExpression copy = new CPPASTBinaryTypeIdExpression(fOperator, - fOperand1 == null ? null : fOperand1.copy(style), - fOperand2 == null ? null : fOperand2.copy(style)); + fOperand1 == null ? null : fOperand1.copy(style), fOperand2 == null ? null : fOperand2.copy(style)); return copy(copy, style); } @Override public Operator getOperator() { - return fOperator; - } + return fOperator; + } - @Override + @Override public void setOperator(Operator value) { - assertNotFrozen(); - fOperator = value; - } + assertNotFrozen(); + fOperator = value; + } - @Override + @Override public void setOperand1(IASTTypeId typeId) { - assertNotFrozen(); - fOperand1 = typeId; - if (typeId != null) { - typeId.setParent(this); - typeId.setPropertyInParent(OPERAND1); - } - } - - @Override + assertNotFrozen(); + fOperand1 = typeId; + if (typeId != null) { + typeId.setParent(this); + typeId.setPropertyInParent(OPERAND1); + } + } + + @Override public void setOperand2(IASTTypeId typeId) { - assertNotFrozen(); - fOperand2 = typeId; - if (typeId != null) { - typeId.setParent(this); - typeId.setPropertyInParent(OPERAND2); - } - } - - @Override + assertNotFrozen(); + fOperand2 = typeId; + if (typeId != null) { + typeId.setParent(this); + typeId.setPropertyInParent(OPERAND2); + } + } + + @Override public IASTTypeId getOperand1() { - return fOperand1; - } + return fOperand1; + } - @Override + @Override public IASTTypeId getOperand2() { - return fOperand2; - } + return fOperand2; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fOperand1 != null && !fOperand1.accept(action)) - return false; - if (fOperand2 != null && !fOperand2.accept(action)) - return false; + if (fOperand1 != null && !fOperand1.accept(action)) + return false; + if (fOperand2 != null && !fOperand2.accept(action)) + return false; - if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; - return true; - } + return true; + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { if (fOperand1 == null || fOperand2 == null) { - fEvaluation= EvalFixed.INCOMPLETE; + fEvaluation = EvalFixed.INCOMPLETE; } else { - IType t1= CPPVisitor.createType(fOperand1); - IType t2= CPPVisitor.createType(fOperand2); + IType t1 = CPPVisitor.createType(fOperand1); + IType t2 = CPPVisitor.createType(fOperand2); if (t1 == null || t2 == null) { - fEvaluation= EvalFixed.INCOMPLETE; + fEvaluation = EvalFixed.INCOMPLETE; } else { - fEvaluation= new EvalBinaryTypeId(fOperator, t1, t2, this); + fEvaluation = new EvalBinaryTypeId(fOperator, t1, t2, this); } } } @@ -139,7 +141,7 @@ public class CPPASTBinaryTypeIdExpression extends ASTNode implements ICPPASTExpr @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); + return CPPEvaluation.getType(this); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java index 1e134376df8..a7d8552f3c1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java @@ -22,29 +22,36 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecBreak; * @author jcamelon */ public class CPPASTBreakStatement extends CPPASTAttributeOwner implements IASTBreakStatement, ICPPExecutionOwner { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public CPPASTBreakStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCapture.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCapture.java index c137c768c89..3ef2cf61fa4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCapture.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCapture.java @@ -78,7 +78,7 @@ public class CPPASTCapture extends CPPASTCaptureBase { identifier.setParent(this); identifier.setPropertyInParent(IDENTIFIER); } - fIdentifier= identifier; + fIdentifier = identifier; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java index a3507d3ade1..45757d4e0fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecCase; public class CPPASTCaseStatement extends CPPASTAttributeOwner implements IASTCaseStatement, ICPPExecutionOwner { private IASTExpression expression; - public CPPASTCaseStatement() { + public CPPASTCaseStatement() { } public CPPASTCaseStatement(IASTExpression expression) { @@ -41,59 +41,66 @@ public class CPPASTCaseStatement extends CPPASTAttributeOwner implements IASTCas @Override public CPPASTCaseStatement copy(CopyStyle style) { - CPPASTCaseStatement copy = - new CPPASTCaseStatement(expression == null ? null : expression.copy(style)); + CPPASTCaseStatement copy = new CPPASTCaseStatement(expression == null ? null : expression.copy(style)); return copy(copy, style); } @Override public IASTExpression getExpression() { - return expression; - } + return expression; + } - @Override + @Override public void setExpression(IASTExpression expression) { - assertNotFrozen(); - this.expression = expression; - if (expression != null) { + assertNotFrozen(); + this.expression = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(EXPRESSION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (expression != null && !expression.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (expression != null && !expression.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } - return true; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == expression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expression = (IASTExpression) other; - return; - } - super.replace(child, other); - } + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expression = (IASTExpression) other; + return; + } + super.replace(child, other); + } @Override public ICPPExecution getExecution() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java index 4779aa2a592..dc89075e969 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java @@ -38,16 +38,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; * Cast expression for C++ */ public class CPPASTCastExpression extends ASTNode implements ICPPASTCastExpression, IASTAmbiguityParent { - private int fOperator; - private ICPPASTExpression fOperand; + private int fOperator; + private ICPPASTExpression fOperand; private IASTTypeId fTypeId; private ICPPEvaluation fEvaluation; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTCastExpression() { + public CPPASTCastExpression() { } - public CPPASTCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) { + public CPPASTCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) { fOperator = operator; setOperand(operand); setTypeId(typeId); @@ -70,44 +70,44 @@ public class CPPASTCastExpression extends ASTNode implements ICPPASTCastExpressi @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.fTypeId = typeId; - if (typeId != null) { + assertNotFrozen(); + this.fTypeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); } - } + } - @Override + @Override public IASTTypeId getTypeId() { - return fTypeId; - } + return fTypeId; + } @Override public int getOperator() { - return fOperator; - } + return fOperator; + } - @Override + @Override public void setOperator(int operator) { - assertNotFrozen(); - fOperator = operator; - } + assertNotFrozen(); + fOperator = operator; + } - @Override + @Override public IASTExpression getOperand() { - return fOperand; - } + return fOperand; + } - @Override + @Override public void setOperand(IASTExpression expression) { - assertNotFrozen(); - fOperand = (ICPPASTExpression) expression; - if (expression != null) { + assertNotFrozen(); + fOperand = (ICPPASTExpression) expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND); } - } + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -118,47 +118,54 @@ public class CPPASTCastExpression extends ASTNode implements ICPPASTCastExpressi return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fTypeId != null && !fTypeId.accept(action)) return false; - IASTExpression op = getOperand(); - if (op != null && !op.accept(action)) return false; - - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (fTypeId != null && !fTypeId.accept(action)) + return false; + IASTExpression op = getOperand(); + if (op != null && !op.accept(action)) + return false; + + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == fOperand) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - fOperand = (ICPPASTExpression) other; - } - } - + if (child == fOperand) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + fOperand = (ICPPASTExpression) other; + } + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) - fEvaluation= computeEvaluation(); + fEvaluation = computeEvaluation(); return fEvaluation; } @@ -167,21 +174,21 @@ public class CPPASTCastExpression extends ASTNode implements ICPPASTCastExpressi if (fOperand == null) return EvalFixed.INCOMPLETE; - IType type= CPPVisitor.createType(getTypeId()); + IType type = CPPVisitor.createType(getTypeId()); if (type == null || type instanceof IProblemType) return EvalFixed.INCOMPLETE; return new EvalTypeId(type, this, false, fOperand.getEvaluation()); } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { - return CPPEvaluation.getValueCategory(this); + return CPPEvaluation.getValueCategory(this); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java index 7fa2529078e..bcb98aee6a5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java @@ -28,13 +28,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.DestructorCallColl * @author jcamelon */ public class CPPASTCatchHandler extends CPPASTAttributeOwner implements ICPPASTCatchHandler { - private boolean fIsCatchAll; - private IASTStatement fBody; - private IASTDeclaration fDeclaration; + private boolean fIsCatchAll; + private IASTStatement fBody; + private IASTDeclaration fDeclaration; private IScope fScope; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTCatchHandler() { + public CPPASTCatchHandler() { } public CPPASTCatchHandler(IASTDeclaration declaration, IASTStatement body) { @@ -58,44 +58,44 @@ public class CPPASTCatchHandler extends CPPASTAttributeOwner implements ICPPASTC @Override public void setIsCatchAll(boolean isEllipsis) { - assertNotFrozen(); - fIsCatchAll = isEllipsis; - } + assertNotFrozen(); + fIsCatchAll = isEllipsis; + } - @Override + @Override public boolean isCatchAll() { - return fIsCatchAll; - } + return fIsCatchAll; + } - @Override + @Override public void setCatchBody(IASTStatement compoundStatement) { - assertNotFrozen(); - fBody = compoundStatement; - if (compoundStatement != null) { + assertNotFrozen(); + fBody = compoundStatement; + if (compoundStatement != null) { compoundStatement.setParent(this); compoundStatement.setPropertyInParent(CATCH_BODY); } - } + } - @Override + @Override public IASTStatement getCatchBody() { - return fBody; - } + return fBody; + } - @Override + @Override public void setDeclaration(IASTDeclaration decl) { - assertNotFrozen(); - fDeclaration = decl; - if (decl != null) { + assertNotFrozen(); + fDeclaration = decl; + if (decl != null) { decl.setParent(this); decl.setPropertyInParent(DECLARATION); } - } + } - @Override + @Override public IASTDeclaration getDeclaration() { - return fDeclaration; - } + return fDeclaration; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -106,49 +106,58 @@ public class CPPASTCatchHandler extends CPPASTAttributeOwner implements ICPPASTC return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (fDeclaration != null && !fDeclaration.accept(action)) return false; - if (fBody != null && !fBody.accept(action)) return false; - - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; - - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + if (fDeclaration != null && !fDeclaration.accept(action)) + return false; + if (fBody != null && !fBody.accept(action)) + return false; + + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (fBody == child) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - fBody = (IASTStatement) other; - return; - } - if (fDeclaration == child) { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - fDeclaration = (IASTDeclaration) other; - return; - } - super.replace(child, other); - } + if (fBody == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + fBody = (IASTStatement) other; + return; + } + if (fDeclaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + fDeclaration = (IASTDeclaration) other; + return; + } + super.replace(child, other); + } @Override public IScope getScope() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTClassVirtSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTClassVirtSpecifier.java index 82c20af17b2..96b6eb7d070 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTClassVirtSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTClassVirtSpecifier.java @@ -36,23 +36,29 @@ public class CPPASTClassVirtSpecifier extends ASTNode implements ICPPASTClassVir return copy(copy, style); } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitVirtSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } + if (action.shouldVisitVirtSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } - if (action.shouldVisitVirtSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitVirtSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index ca162e08fb1..78c45155f31 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -29,20 +29,19 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; /** * c++ specific composite type specifier */ -public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier - implements ICPPASTCompositeTypeSpecifier { - private int fKey; - private IASTName fName; - private CPPClassScope fScope; +public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTCompositeTypeSpecifier { + private int fKey; + private IASTName fName; + private CPPClassScope fScope; private IASTDeclaration[] fAllDeclarations; private IASTDeclaration[] fActiveDeclarations; - private int fDeclarationsPos = -1; + private int fDeclarationsPos = -1; private ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier[] baseSpecs; private int baseSpecsPos = -1; private boolean fAmbiguitiesResolved; private ICPPASTClassVirtSpecifier virtSpecifier; - public CPPASTCompositeTypeSpecifier() { + public CPPASTCompositeTypeSpecifier() { } public CPPASTCompositeTypeSpecifier(int k, IASTName n) { @@ -54,7 +53,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier if (!fAmbiguitiesResolved && fScope != null) { fScope.createImplicitMembers(); } - fAmbiguitiesResolved= true; + fAmbiguitiesResolved = true; } @Override @@ -64,8 +63,8 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier @Override public CPPASTCompositeTypeSpecifier copy(CopyStyle style) { - CPPASTCompositeTypeSpecifier copy = - new CPPASTCompositeTypeSpecifier(fKey, fName == null ? null : fName.copy(style)); + CPPASTCompositeTypeSpecifier copy = new CPPASTCompositeTypeSpecifier(fKey, + fName == null ? null : fName.copy(style)); for (IASTDeclaration member : getMembers()) copy.addMemberDeclaration(member == null ? null : member.copy(style)); for (ICPPASTBaseSpecifier baseSpecifier : getBaseSpecifiers()) @@ -74,57 +73,56 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier return super.copy(copy, style); } - @Override + @Override public ICPPASTBaseSpecifier[] getBaseSpecifiers() { - if (baseSpecs == null) - return ICPPASTBaseSpecifier.EMPTY_BASESPECIFIER_ARRAY; - baseSpecs = ArrayUtil.trimAt(ICPPASTBaseSpecifier.class, baseSpecs, baseSpecsPos); - return baseSpecs; - } + if (baseSpecs == null) + return ICPPASTBaseSpecifier.EMPTY_BASESPECIFIER_ARRAY; + baseSpecs = ArrayUtil.trimAt(ICPPASTBaseSpecifier.class, baseSpecs, baseSpecsPos); + return baseSpecs; + } - @Override + @Override public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) { - assertNotFrozen(); - if (baseSpec != null) { - baseSpec.setParent(this); + assertNotFrozen(); + if (baseSpec != null) { + baseSpec.setParent(this); baseSpec.setPropertyInParent(BASE_SPECIFIER); - baseSpecs = ArrayUtil.appendAt(ICPPASTBaseSpecifier.class, baseSpecs, ++baseSpecsPos, - baseSpec); - } - } + baseSpecs = ArrayUtil.appendAt(ICPPASTBaseSpecifier.class, baseSpecs, ++baseSpecsPos, baseSpec); + } + } - @Override + @Override public int getKey() { - return fKey; - } + return fKey; + } - @Override + @Override public void setKey(int key) { - assertNotFrozen(); - fKey = key; - } + assertNotFrozen(); + fKey = key; + } - @Override + @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName = name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(TYPE_NAME); } - } + } @Override public IASTDeclaration[] getMembers() { - IASTDeclaration[] active= fActiveDeclarations; + IASTDeclaration[] active = fActiveDeclarations; if (active == null) { active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fDeclarationsPos + 1); - fActiveDeclarations= active; + fActiveDeclarations = active; } return active; } @@ -132,8 +130,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier @Override public final IASTDeclaration[] getDeclarations(boolean includeInactive) { if (includeInactive) { - fAllDeclarations= ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, - fDeclarationsPos); + fAllDeclarations = ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fDeclarationsPos); return fAllDeclarations; } return getMembers(); @@ -151,15 +148,14 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier assertNotFrozen(); decl.setParent(this); decl.setPropertyInParent(decl instanceof ICPPASTVisibilityLabel ? VISIBILITY_LABEL : MEMBER_DECLARATION); - fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, - ++fDeclarationsPos, decl); - fActiveDeclarations= null; + fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fDeclarationsPos, decl); + fActiveDeclarations = null; } - @Override + @Override public final void addDeclaration(IASTDeclaration decl) { - addMemberDeclaration(decl); - } + addMemberDeclaration(decl); + } @Override public ICPPClassScope getScope() { @@ -172,13 +168,16 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier return fScope; } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclSpecifiers) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } @@ -224,7 +223,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); fAllDeclarations[i] = (IASTDeclaration) other; - fActiveDeclarations= null; + fActiveDeclarations = null; return; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java index f70ead2f4e9..65e83d90cae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java @@ -28,12 +28,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecCompoundStatem /** * @author jcamelon */ -public class CPPASTCompoundStatement extends CPPASTAttributeOwner implements ICPPASTCompoundStatement, ICPPExecutionOwner { - private IASTStatement[] statements = new IASTStatement[2]; - private ICPPScope scope; +public class CPPASTCompoundStatement extends CPPASTAttributeOwner + implements ICPPASTCompoundStatement, ICPPExecutionOwner { + private IASTStatement[] statements = new IASTStatement[2]; + private ICPPScope scope; private IASTImplicitDestructorName[] fImplicitDestructorNames; - @Override + @Override public CPPASTCompoundStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -49,28 +50,28 @@ public class CPPASTCompoundStatement extends CPPASTAttributeOwner implements ICP return copy(copy, style); } - @Override + @Override public IASTStatement[] getStatements() { - statements = ArrayUtil.trim(statements); - return statements; - } + statements = ArrayUtil.trim(statements); + return statements; + } - @Override + @Override public void addStatement(IASTStatement statement) { - assertNotFrozen(); - statements = ArrayUtil.append(statements, statement); - if (statement != null) { + assertNotFrozen(); + statements = ArrayUtil.append(statements, statement); + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(NESTED_STATEMENT); } - } + } - @Override + @Override public IScope getScope() { - if (scope == null) - scope = new CPPBlockScope(this); - return scope; - } + if (scope == null) + scope = new CPPBlockScope(this); + return scope; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -81,52 +82,59 @@ public class CPPASTCompoundStatement extends CPPASTAttributeOwner implements ICP return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - for (IASTStatement statement : statements) { - if (statement == null) - break; - if (!statement.accept(action)) - return false; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + for (IASTStatement statement : statements) { + if (statement == null) + break; + if (!statement.accept(action)) + return false; + } - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - for (int i = 0; i < statements.length; ++i) { - if (statements[i] == child) { - other.setParent(statements[i].getParent()); - other.setPropertyInParent(statements[i].getPropertyInParent()); - statements[i] = (IASTStatement) other; - return; - } - } - super.replace(child, other); - } + for (int i = 0; i < statements.length; ++i) { + if (statements[i] == child) { + other.setParent(statements[i].getParent()); + other.setPropertyInParent(statements[i].getPropertyInParent()); + statements[i] = (IASTStatement) other; + return; + } + } + super.replace(child, other); + } - @Override + @Override public ICPPExecution getExecution() { - return new ExecCompoundStatement(this.statements); + return new ExecCompoundStatement(this.statements); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java index 7dddbc8d153..0a161fc2347 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatementExpression.java @@ -36,11 +36,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; */ public class CPPASTCompoundStatementExpression extends ASTNode implements IGNUASTCompoundStatementExpression, ICPPASTExpression { - private IASTCompoundStatement fStatement; - private ICPPEvaluation fEval; + private IASTCompoundStatement fStatement; + private ICPPEvaluation fEval; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTCompoundStatementExpression() { + public CPPASTCompoundStatementExpression() { } public CPPASTCompoundStatementExpression(IASTCompoundStatement statement) { @@ -54,25 +54,25 @@ public class CPPASTCompoundStatementExpression extends ASTNode @Override public CPPASTCompoundStatementExpression copy(CopyStyle style) { - CPPASTCompoundStatementExpression copy = - new CPPASTCompoundStatementExpression(fStatement == null ? null : fStatement.copy(style)); + CPPASTCompoundStatementExpression copy = new CPPASTCompoundStatementExpression( + fStatement == null ? null : fStatement.copy(style)); return copy(copy, style); } @Override public IASTCompoundStatement getCompoundStatement() { - return fStatement; - } + return fStatement; + } - @Override + @Override public void setCompoundStatement(IASTCompoundStatement statement) { - assertNotFrozen(); - this.fStatement = statement; - if (statement != null) { + assertNotFrozen(); + this.fStatement = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(STATEMENT); } - } + } @Override public ICPPEvaluation getEvaluation() { @@ -84,12 +84,12 @@ public class CPPASTCompoundStatementExpression extends ASTNode if (st instanceof IASTExpressionStatement) { IASTExpressionStatement exprStmt = (IASTExpressionStatement) st; ICPPASTExpression expr = (ICPPASTExpression) exprStmt.getExpression(); - fEval= new EvalCompoundStatementExpression(expr.getEvaluation(), this); + fEval = new EvalCompoundStatementExpression(expr.getEvaluation(), this); } } } if (fEval == null) - fEval= EvalFixed.INCOMPLETE; + fEval = EvalFixed.INCOMPLETE; } return fEval; } @@ -103,35 +103,41 @@ public class CPPASTCompoundStatementExpression extends ASTNode return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fStatement != null && !fStatement.accept(action)) - return false; + if (fStatement != null && !fStatement.accept(action)) + return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); + return CPPEvaluation.getType(this); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java index ecf4b4f896d..25d7dc0272f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConditionalExpression.java @@ -34,19 +34,19 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; public class CPPASTConditionalExpression extends ASTNode implements IASTConditionalExpression, ICPPASTExpression, IASTAmbiguityParent { - private ICPPASTExpression fCondition; - private ICPPASTExpression fPositive; - private ICPPASTExpression fNegative; - private ICPPEvaluation fEval; + private ICPPASTExpression fCondition; + private ICPPASTExpression fPositive; + private ICPPASTExpression fNegative; + private ICPPEvaluation fEval; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTConditionalExpression() { + public CPPASTConditionalExpression() { } public CPPASTConditionalExpression(IASTExpression condition, IASTExpression postive, IASTExpression negative) { - setLogicalConditionExpression(condition); - setPositiveResultExpression(postive); - setNegativeResultExpression(negative); + setLogicalConditionExpression(condition); + setPositiveResultExpression(postive); + setNegativeResultExpression(negative); } @Override @@ -65,48 +65,48 @@ public class CPPASTConditionalExpression extends ASTNode @Override public IASTExpression getLogicalConditionExpression() { - return fCondition; - } + return fCondition; + } - @Override + @Override public void setLogicalConditionExpression(IASTExpression expression) { - assertNotFrozen(); - fCondition = (ICPPASTExpression) expression; - if (expression != null) { + assertNotFrozen(); + fCondition = (ICPPASTExpression) expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(LOGICAL_CONDITION); } - } + } - @Override + @Override public IASTExpression getPositiveResultExpression() { - return fPositive; - } + return fPositive; + } - @Override + @Override public void setPositiveResultExpression(IASTExpression expression) { - assertNotFrozen(); - this.fPositive = (ICPPASTExpression) expression; - if (expression != null) { + assertNotFrozen(); + this.fPositive = (ICPPASTExpression) expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(POSITIVE_RESULT); } - } + } - @Override + @Override public IASTExpression getNegativeResultExpression() { - return fNegative; - } + return fNegative; + } - @Override + @Override public void setNegativeResultExpression(IASTExpression expression) { - assertNotFrozen(); - this.fNegative = (ICPPASTExpression) expression; - if (expression != null) { + assertNotFrozen(); + this.fNegative = (ICPPASTExpression) expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(NEGATIVE_RESULT); } - } + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -117,14 +117,17 @@ public class CPPASTConditionalExpression extends ASTNode return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fCondition != null && !fCondition.accept(action)) @@ -135,13 +138,13 @@ public class CPPASTConditionalExpression extends ASTNode return false; if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + return false; if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -169,7 +172,7 @@ public class CPPASTConditionalExpression extends ASTNode if (op == IASTUnaryExpression.op_throw) { return true; } else if (op == IASTUnaryExpression.op_bracketedPrimary) { - expr= unaryExpr.getOperand(); + expr = unaryExpr.getOperand(); } else { return false; } @@ -181,27 +184,27 @@ public class CPPASTConditionalExpression extends ASTNode public ICPPEvaluation getEvaluation() { if (fEval == null) { if (fCondition == null || fNegative == null) { - fEval= EvalFixed.INCOMPLETE; + fEval = EvalFixed.INCOMPLETE; } else { final ICPPEvaluation condEval = fCondition.getEvaluation(); final ICPPEvaluation posEval = fPositive == null ? null : fPositive.getEvaluation(); final ICPPEvaluation negEval = fNegative.getEvaluation(); - fEval= new EvalConditional(condEval, posEval, negEval, - isThrowExpression(fPositive), isThrowExpression(fNegative), this); + fEval = new EvalConditional(condEval, posEval, negEval, isThrowExpression(fPositive), + isThrowExpression(fNegative), this); } } return fEval; } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { - return CPPEvaluation.getValueCategory(this); - } + return CPPEvaluation.getValueCategory(this); + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index a502bf4379b..776eb8f548c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -48,14 +48,14 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; * </code><br> * {@code Base()} and {@code field()} are the constructor chain initializers.<br> */ -public class CPPASTConstructorChainInitializer extends ASTNode implements - ICPPASTConstructorChainInitializer, IASTImplicitNameOwner, ICPPASTCompletionContext { - private IASTName name; +public class CPPASTConstructorChainInitializer extends ASTNode + implements ICPPASTConstructorChainInitializer, IASTImplicitNameOwner, ICPPASTCompletionContext { + private IASTName name; private IASTImplicitName[] implicitNames; - private IASTInitializer initializer; + private IASTInitializer initializer; private boolean fIsPackExpansion; - public CPPASTConstructorChainInitializer() { + public CPPASTConstructorChainInitializer() { } public CPPASTConstructorChainInitializer(IASTName id, IASTInitializer initializer) { @@ -79,69 +79,69 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements @Override public IASTName getMemberInitializerId() { - return name; - } + return name; + } - @Override + @Override public void setMemberInitializerId(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(MEMBER_ID); } - } + } - @Override + @Override public IASTInitializer getInitializer() { - return initializer; - } + return initializer; + } - @Override + @Override public void setInitializer(IASTInitializer init) { - assertNotFrozen(); - initializer = init; - if (init != null) { - init.setParent(this); - init.setPropertyInParent(INITIALIZER); + assertNotFrozen(); + initializer = init; + if (init != null) { + init.setParent(this); + init.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitInitializers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - } - } - if (name != null && !name.accept(action)) - return false; + if (action.shouldVisitInitializers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } + } + if (name != null && !name.accept(action)) + return false; - if (action.shouldVisitImplicitNames) { - for (IASTImplicitName implicitName : getImplicitNames()) { - if (!implicitName.accept(action)) - return false; - } - } + if (action.shouldVisitImplicitNames) { + for (IASTImplicitName implicitName : getImplicitNames()) { + if (!implicitName.accept(action)) + return false; + } + } - if (initializer != null && !initializer.accept(action)) - return false; + if (initializer != null && !initializer.accept(action)) + return false; if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } - @Override + @Override public int getRoleForName(IASTName n) { - if (name == n) - return r_reference; - return r_unclear; - } + if (name == n) + return r_reference; + return r_unclear; + } @Override public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) { @@ -173,15 +173,15 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements } private CharArraySet getBaseClasses(IASTName name) { - CharArraySet result= new CharArraySet(2); + CharArraySet result = new CharArraySet(2); for (IASTNode parent = name.getParent(); parent != null; parent = parent.getParent()) { if (parent instanceof ICPPASTFunctionDefinition) { - ICPPASTFunctionDefinition fdef= (ICPPASTFunctionDefinition) parent; - IBinding method= fdef.getDeclarator().getName().resolveBinding(); + ICPPASTFunctionDefinition fdef = (ICPPASTFunctionDefinition) parent; + IBinding method = fdef.getDeclarator().getName().resolveBinding(); if (method instanceof ICPPMethod) { - ICPPClassType cls= ((ICPPMethod) method).getClassOwner(); + ICPPClassType cls = ((ICPPMethod) method).getClassOwner(); for (ICPPBase base : cls.getBases()) { - IType baseType= base.getBaseClassType(); + IType baseType = base.getBaseClassType(); if (baseType instanceof IBinding) result.put(((IBinding) baseType).getNameCharArray()); } @@ -200,45 +200,45 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements @Override public void setIsPackExpansion(boolean val) { assertNotFrozen(); - fIsPackExpansion= val; + fIsPackExpansion = val; } @Override @Deprecated - public IASTExpression getInitializerValue() { - if (initializer == null || initializer instanceof IASTExpression) { - return (IASTExpression) initializer; - } - if (initializer instanceof ICPPASTConstructorInitializer) { - IASTExpression expr= ((ICPPASTConstructorInitializer) initializer).getExpression(); - if (expr != null) { - expr= expr.copy(); - expr.setParent(this); - expr.setPropertyInParent(INITIALIZER); - } - return expr; - } - return null; - } + public IASTExpression getInitializerValue() { + if (initializer == null || initializer instanceof IASTExpression) { + return (IASTExpression) initializer; + } + if (initializer instanceof ICPPASTConstructorInitializer) { + IASTExpression expr = ((ICPPASTConstructorInitializer) initializer).getExpression(); + if (expr != null) { + expr = expr.copy(); + expr.setParent(this); + expr.setPropertyInParent(INITIALIZER); + } + return expr; + } + return null; + } @Override @Deprecated - public void setInitializerValue(IASTExpression expression) { - assertNotFrozen(); - //CDT_70_FIX_FROM_50-#6 - CPPASTConstructorInitializer ctorInit= new CPPASTConstructorInitializer(); - if (expression == null) { - //add an empty initializer, fix test testBug89539 for xlc parser - setInitializer(ctorInit); - } else if (expression instanceof IASTInitializer) { - setInitializer((IASTInitializer) expression); - } else { + public void setInitializerValue(IASTExpression expression) { + assertNotFrozen(); + //CDT_70_FIX_FROM_50-#6 + CPPASTConstructorInitializer ctorInit = new CPPASTConstructorInitializer(); + if (expression == null) { + //add an empty initializer, fix test testBug89539 for xlc parser + setInitializer(ctorInit); + } else if (expression instanceof IASTInitializer) { + setInitializer((IASTInitializer) expression); + } else { - ctorInit.setExpression(expression); - ctorInit.setOffsetAndLength((ASTNode) expression); - setInitializer(ctorInit); - } - } + ctorInit.setExpression(expression); + ctorInit.setOffsetAndLength((ASTNode) expression); + setInitializer(ctorInit); + } + } /** * @see IASTImplicitNameOwner#getImplicitNames() @@ -256,9 +256,9 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements ctorName.setOffsetAndLength((ASTNode) id); implicitNames = new IASTImplicitName[] { ctorName }; } - } + } - return implicitNames; + return implicitNames; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java index 1876d68c877..ef202634f5b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java @@ -28,10 +28,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; */ public class CPPASTConstructorInitializer extends ASTNode implements ICPPASTConstructorInitializer, IASTAmbiguityParent { - private IASTInitializerClause[] fArguments; + private IASTInitializerClause[] fArguments; - public CPPASTConstructorInitializer() { - setArguments(null); + public CPPASTConstructorInitializer() { + setArguments(null); } public CPPASTConstructorInitializer(IASTInitializerClause[] args) { @@ -58,43 +58,46 @@ public class CPPASTConstructorInitializer extends ASTNode @Override public IASTInitializerClause[] getArguments() { - return fArguments; - } + return fArguments; + } - @Override + @Override public void setArguments(IASTInitializerClause[] arguments) { - assertNotFrozen(); - if (arguments == null) { - fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY; - } else { - fArguments= arguments; - for (IASTInitializerClause arg : arguments) { + assertNotFrozen(); + if (arguments == null) { + fArguments = IASTExpression.EMPTY_EXPRESSION_ARRAY; + } else { + fArguments = arguments; + for (IASTInitializerClause arg : arguments) { arg.setParent(this); arg.setPropertyInParent(ARGUMENT); } } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitInitializers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - for (IASTInitializerClause arg : fArguments) { - if (!arg.accept(action)) - return false; - } + for (IASTInitializerClause arg : fArguments) { + if (!arg.accept(action)) + return false; + } if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; return true; - } + } @Override public void replace(IASTNode child, IASTNode other) { @@ -107,39 +110,39 @@ public class CPPASTConstructorInitializer extends ASTNode } } - @Override + @Override @Deprecated public IASTExpression getExpression() { - if (fArguments.length == 0) - return null; - if (fArguments.length == 1) { - IASTInitializerClause arg = fArguments[0]; - if (arg instanceof IASTExpression) - return (IASTExpression) arg; - return null; - } - - CPPASTExpressionList result= new CPPASTExpressionList(); - for (IASTInitializerClause arg : fArguments) { - if (arg instanceof IASTExpression) { - result.addExpression(((IASTExpression) arg).copy()); - } - } - result.setParent(this); - result.setPropertyInParent(EXPRESSION); - return result; - } - - @Override + if (fArguments.length == 0) + return null; + if (fArguments.length == 1) { + IASTInitializerClause arg = fArguments[0]; + if (arg instanceof IASTExpression) + return (IASTExpression) arg; + return null; + } + + CPPASTExpressionList result = new CPPASTExpressionList(); + for (IASTInitializerClause arg : fArguments) { + if (arg instanceof IASTExpression) { + result.addExpression(((IASTExpression) arg).copy()); + } + } + result.setParent(this); + result.setPropertyInParent(EXPRESSION); + return result; + } + + @Override @Deprecated public void setExpression(IASTExpression expression) { - assertNotFrozen(); - if (expression == null) { - setArguments(null); - } else if (expression instanceof ICPPASTExpressionList) { - setArguments(((ICPPASTExpressionList) expression).getExpressions()); - } else { - setArguments(new IASTExpression[] {expression}); - } - } + assertNotFrozen(); + if (expression == null) { + setArguments(null); + } else if (expression instanceof ICPPASTExpressionList) { + setArguments(((ICPPASTExpressionList) expression).getExpressions()); + } else { + setArguments(new IASTExpression[] { expression }); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java index 40d040e81d4..7e76fcfd181 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java @@ -22,29 +22,36 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecContinue; * @author jcamelon */ public class CPPASTContinueStatement extends CPPASTAttributeOwner implements IASTContinueStatement, ICPPExecutionOwner { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public CPPASTContinueStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConversionName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConversionName.java index 8ad86ae27ef..41776e2ecb9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConversionName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConversionName.java @@ -58,8 +58,8 @@ public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConve @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.typeId= typeId; + assertNotFrozen(); + this.typeId = typeId; if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); @@ -103,11 +103,11 @@ public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConve @Override public char[] toCharArray() { if (fName == null) { - IType t= null; + IType t = null; if (typeId != null) { - t= CPPVisitor.createType(typeId); + t = CPPVisitor.createType(typeId); } - fName= createName(t, typeId); + fName = createName(t, typeId); } return fName; } @@ -117,14 +117,14 @@ public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConve buf.append(Keywords.cOPERATOR); buf.append(' '); buf.append(targetName); - final int len= buf.length(); - char[] name= new char[len]; + final int len = buf.length(); + char[] name = new char[len]; buf.getChars(0, len, name, 0); return name; } - + public static char[] createName(IType t, IASTNode typeId) { - StringBuilder buf= new StringBuilder(); + StringBuilder buf = new StringBuilder(); buf.append(Keywords.cOPERATOR); buf.append(' '); if (t != null) { @@ -133,8 +133,8 @@ public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConve buf.append(typeId.getRawSignature()); WHITESPACE_SEQ.matcher(buf).replaceAll(" "); //$NON-NLS-1$ } - final int len= buf.length(); - char[] name= new char[len]; + final int len = buf.length(); + char[] name = new char[len]; buf.getChars(0, len, name, 0); return name; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java index 78db191431b..93e262a0067 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java @@ -30,9 +30,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecDeclarationSta */ public class CPPASTDeclarationStatement extends ASTNode implements IASTDeclarationStatement, IASTAmbiguityParent, ICPPExecutionOwner { - private IASTDeclaration declaration; + private IASTDeclaration declaration; - public CPPASTDeclarationStatement() { + public CPPASTDeclarationStatement() { } public CPPASTDeclarationStatement(IASTDeclaration declaration) { @@ -53,49 +53,56 @@ public class CPPASTDeclarationStatement extends ASTNode @Override public IASTDeclaration getDeclaration() { - return declaration; - } + return declaration; + } - @Override + @Override public void setDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - this.declaration = declaration; - if (declaration != null) { + assertNotFrozen(); + this.declaration = declaration; + if (declaration != null) { declaration.setParent(this); declaration.setPropertyInParent(DECLARATION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declaration != null && !declaration.accept(action)) return false; - - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (declaration != null && !declaration.accept(action)) + return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (declaration == child) { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - declaration = (IASTDeclaration) other; - } - } + if (declaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + declaration = (IASTDeclaration) other; + } + } @Override public IASTAttribute[] getAttributes() { @@ -106,7 +113,7 @@ public class CPPASTDeclarationStatement extends ASTNode @Override public void addAttribute(IASTAttribute attribute) { // Declaration statements don't have attributes. - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java index af5e16a0338..046ff4d4bf2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java @@ -49,28 +49,28 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecIncomplete; /** * C++ specific declarator. */ -public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDeclarator, - IASTImplicitNameOwner, ICPPExecutionOwner { - private IASTInitializer initializer; - private IASTName name; +public class CPPASTDeclarator extends CPPASTAttributeOwner + implements ICPPASTDeclarator, IASTImplicitNameOwner, ICPPExecutionOwner { + private IASTInitializer initializer; + private IASTName name; private IASTImplicitName[] implicitNames; - private IASTDeclarator nested; - private IASTPointerOperator[] pointerOps; - private boolean isPackExpansion; + private IASTDeclarator nested; + private IASTPointerOperator[] pointerOps; + private boolean isPackExpansion; - public CPPASTDeclarator() { + public CPPASTDeclarator() { } public CPPASTDeclarator(IASTName name) { setName(name); } - public CPPASTDeclarator(IASTName name, IASTInitializer initializer) { + public CPPASTDeclarator(IASTName name, IASTInitializer initializer) { this(name); setInitializer(initializer); } - @Override + @Override public CPPASTDeclarator copy() { return copy(CopyStyle.withoutLocations); } @@ -85,7 +85,7 @@ public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDec copy.setName(name == null ? null : name.copy(style)); copy.setInitializer(initializer == null ? null : initializer.copy(style)); copy.setNestedDeclarator(nested == null ? null : nested.copy(style)); - ((CPPASTDeclarator) copy).isPackExpansion= isPackExpansion; + ((CPPASTDeclarator) copy).isPackExpansion = isPackExpansion; for (IASTPointerOperator pointer : getPointerOperators()) { copy.addPointerOperator(pointer.copy(style)); } @@ -99,45 +99,46 @@ public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDec @Override public IASTPointerOperator[] getPointerOperators() { - if (pointerOps == null) return IASTPointerOperator.EMPTY_ARRAY; - pointerOps = ArrayUtil.trim(IASTPointerOperator.class, pointerOps); - return pointerOps; - } + if (pointerOps == null) + return IASTPointerOperator.EMPTY_ARRAY; + pointerOps = ArrayUtil.trim(IASTPointerOperator.class, pointerOps); + return pointerOps; + } - @Override + @Override public IASTDeclarator getNestedDeclarator() { - return nested; - } + return nested; + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public IASTInitializer getInitializer() { - return initializer; - } + return initializer; + } - @Override + @Override public void setInitializer(IASTInitializer initializer) { - assertNotFrozen(); - this.initializer = initializer; - if (initializer != null) { + assertNotFrozen(); + this.initializer = initializer; + if (initializer != null) { initializer.setParent(this); initializer.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public void addPointerOperator(IASTPointerOperator operator) { - assertNotFrozen(); - if (operator != null) { - operator.setParent(this); + assertNotFrozen(); + if (operator != null) { + operator.setParent(this); operator.setPropertyInParent(POINTER_OPERATOR); - pointerOps = ArrayUtil.append(IASTPointerOperator.class, pointerOps, operator); - } - } + pointerOps = ArrayUtil.append(IASTPointerOperator.class, pointerOps, operator); + } + } /** * Remove a pointer operator from the pointer operators @@ -148,135 +149,140 @@ public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDec ArrayUtil.remove(pointerOps, operator); } - @Override + @Override public void setNestedDeclarator(IASTDeclarator nested) { - assertNotFrozen(); - this.nested = nested; - if (nested != null) { + assertNotFrozen(); + this.nested = nested; + if (nested != null) { nested.setParent(this); nested.setPropertyInParent(NESTED_DECLARATOR); } - } + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(DECLARATOR_NAME); } - } + } - @Override + @Override public void setDeclaresParameterPack(boolean val) { - assertNotFrozen(); - isPackExpansion= val; + assertNotFrozen(); + isPackExpansion = val; } @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarators) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarators) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + if (pointerOps != null) { + for (IASTPointerOperator op : pointerOps) { + if (op == null) + break; + if (!op.accept(action)) + return false; + } } - if (pointerOps != null) { - for (IASTPointerOperator op : pointerOps) { - if (op == null) - break; - if (!op.accept(action)) - return false; - } - } - - if (!acceptByAttributeSpecifiers(action)) - return false; - - if (nested == null && name != null) { - IASTDeclarator outermost= ASTQueries.findOutermostDeclarator(this); - if (outermost.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR) { - if (!name.accept(action)) - return false; - if (action.shouldVisitImplicitNames) { - for (IASTImplicitName implicitName : getImplicitNames()) { - if (!implicitName.accept(action)) - return false; - } - } - } + if (!acceptByAttributeSpecifiers(action)) + return false; + + if (nested == null && name != null) { + IASTDeclarator outermost = ASTQueries.findOutermostDeclarator(this); + if (outermost.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR) { + if (!name.accept(action)) + return false; + if (action.shouldVisitImplicitNames) { + for (IASTImplicitName implicitName : getImplicitNames()) { + if (!implicitName.accept(action)) + return false; + } + } + } } - if (nested != null && !nested.accept(action)) - return false; + if (nested != null && !nested.accept(action)) + return false; - if (!postAccept(action)) - return false; + if (!postAccept(action)) + return false; - if (action.shouldVisitDeclarators && action.leave(this) == ASTVisitor.PROCESS_ABORT) + if (action.shouldVisitDeclarators && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } - protected boolean postAccept(ASTVisitor action) { + protected boolean postAccept(ASTVisitor action) { return initializer == null || initializer.accept(action); - } + } @Override public int getRoleForName(IASTName n) { // 3.1.2 - IASTNode parent = ASTQueries.findOutermostDeclarator(this).getParent(); - if (parent instanceof IASTDeclaration) { - // a declaration is a definition unless ... - if (parent instanceof IASTFunctionDefinition) - return r_definition; + IASTNode parent = ASTQueries.findOutermostDeclarator(this).getParent(); + if (parent instanceof IASTDeclaration) { + // a declaration is a definition unless ... + if (parent instanceof IASTFunctionDefinition) + return r_definition; + + if (parent instanceof IASTSimpleDeclaration) { + final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent; + + // unless it declares a function without body + if (this instanceof IASTFunctionDeclarator) { + return r_declaration; + } - if (parent instanceof IASTSimpleDeclaration) { - final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent; + final int storage = sdecl.getDeclSpecifier().getStorageClass(); + // unless it contains the extern specifier or a linkage-specification and neither initializer nor function-body + if (getInitializer() == null + && (storage == IASTDeclSpecifier.sc_extern || isSimpleLinkageSpec(sdecl))) { + return r_declaration; + } + // unless it declares a static data member in a class declaration + if (storage == IASTDeclSpecifier.sc_static + && CPPVisitor.getContainingScope(parent) instanceof ICPPClassScope) { + return r_declaration; + } + // unless it is a class name declaration: no declarator in this case + // unless it is a typedef declaration + if (storage == IASTDeclSpecifier.sc_typedef) + return r_definition; // should actually be a declaration - // unless it declares a function without body - if (this instanceof IASTFunctionDeclarator) { - return r_declaration; - } + // unless it is a using-declaration or using-directive: no declarator in this case + } - final int storage = sdecl.getDeclSpecifier().getStorageClass(); - // unless it contains the extern specifier or a linkage-specification and neither initializer nor function-body - if (getInitializer() == null && (storage == IASTDeclSpecifier.sc_extern || isSimpleLinkageSpec(sdecl))) { - return r_declaration; - } - // unless it declares a static data member in a class declaration - if (storage == IASTDeclSpecifier.sc_static && CPPVisitor.getContainingScope(parent) instanceof ICPPClassScope) { - return r_declaration; - } - // unless it is a class name declaration: no declarator in this case - // unless it is a typedef declaration - if (storage == IASTDeclSpecifier.sc_typedef) - return r_definition; // should actually be a declaration - - // unless it is a using-declaration or using-directive: no declarator in this case - } - - // all other cases - return r_definition; - } - - if (parent instanceof IASTTypeId) - return r_reference; - - if (parent instanceof IASTParameterDeclaration) - return (n.getLookupKey().length > 0) ? r_definition : r_declaration; - - return r_unclear; + // all other cases + return r_definition; + } + + if (parent instanceof IASTTypeId) + return r_reference; + + if (parent instanceof IASTParameterDeclaration) + return (n.getLookupKey().length > 0) ? r_definition : r_declaration; + + return r_unclear; } private boolean isSimpleLinkageSpec(IASTSimpleDeclaration sdecl) { - IASTNode parent= sdecl.getParent(); + IASTNode parent = sdecl.getParent(); if (parent instanceof ICPPASTLinkageSpecification) { - ICPPASTLinkageSpecification spec= (ICPPASTLinkageSpecification) parent; + ICPPASTLinkageSpecification spec = (ICPPASTLinkageSpecification) parent; // todo distinction between braced enclose and simple linkage specification if (spec.getDeclarations().length == 1) { return true; @@ -304,9 +310,9 @@ public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDec ctorName.setOffsetAndLength((ASTNode) id); implicitNames = new IASTImplicitName[] { ctorName }; } - } + } - return implicitNames; + return implicitNames; } @Override @@ -314,7 +320,7 @@ public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDec if (child == nested) { other.setPropertyInParent(child.getPropertyInParent()); other.setParent(child.getParent()); - nested= (IASTDeclarator) other; + nested = (IASTDeclarator) other; return; } super.replace(child, other); @@ -323,7 +329,7 @@ public class CPPASTDeclarator extends CPPASTAttributeOwner implements ICPPASTDec @Override public ICPPExecution getExecution() { final IBinding binding = getName().resolveBinding(); - if (!(binding instanceof ICPPBinding)) // ProblemBinding + if (!(binding instanceof ICPPBinding)) // ProblemBinding return ExecIncomplete.INSTANCE; ICPPEvaluation initializerEval = null; if (binding instanceof CPPVariable) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDecltypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDecltypeSpecifier.java index db5d01214bf..713b8e38aa9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDecltypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDecltypeSpecifier.java @@ -28,8 +28,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * Implementation of ICPPASTDecltypeSpecifier. */ -public class CPPASTDecltypeSpecifier extends ASTNode - implements ICPPASTDecltypeSpecifier, IASTAmbiguityParent { +public class CPPASTDecltypeSpecifier extends ASTNode implements ICPPASTDecltypeSpecifier, IASTAmbiguityParent { private ICPPASTExpression fDecltypeExpression; private char[] fSignature; @@ -73,9 +72,12 @@ public class CPPASTDecltypeSpecifier extends ASTNode public boolean accept(ASTVisitor visitor) { if (visitor.shouldVisitDecltypeSpecifiers) { switch (visitor.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } @@ -84,9 +86,12 @@ public class CPPASTDecltypeSpecifier extends ASTNode if (visitor.shouldVisitDecltypeSpecifiers) { switch (visitor.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java index e29eff9bd78..6706fd5380f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java @@ -22,29 +22,36 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecDefault; * @author jcamelon */ public class CPPASTDefaultStatement extends CPPASTAttributeOwner implements IASTDefaultStatement, ICPPExecutionOwner { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public CPPASTDefaultStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java index 57d24b872aa..4802418ad11 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeleteExpression.java @@ -35,18 +35,18 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.DestructorCallCollector; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; - public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpression, IASTAmbiguityParent { - private static final ICPPEvaluation EVALUATION = new EvalFixed(CPPSemantics.VOID_TYPE, PRVALUE, IntegralValue.UNKNOWN); + private static final ICPPEvaluation EVALUATION = new EvalFixed(CPPSemantics.VOID_TYPE, PRVALUE, + IntegralValue.UNKNOWN); - private IASTExpression operand; - private boolean isGlobal; - private boolean isVectored; + private IASTExpression operand; + private boolean isGlobal; + private boolean isVectored; - private IASTImplicitName[] implicitNames; + private IASTImplicitName[] implicitNames; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTDeleteExpression() { + public CPPASTDeleteExpression() { } public CPPASTDeleteExpression(IASTExpression operand) { @@ -64,8 +64,7 @@ public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpr @Override public CPPASTDeleteExpression copy(CopyStyle style) { - CPPASTDeleteExpression copy = - new CPPASTDeleteExpression(operand == null ? null : operand.copy(style)); + CPPASTDeleteExpression copy = new CPPASTDeleteExpression(operand == null ? null : operand.copy(style)); copy.isGlobal = isGlobal; copy.isVectored = isVectored; return copy(copy, style); @@ -73,78 +72,78 @@ public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpr @Override public IASTExpression getOperand() { - return operand; - } + return operand; + } - @Override + @Override public void setOperand(IASTExpression expression) { - assertNotFrozen(); - operand = expression; - if (expression != null) { + assertNotFrozen(); + operand = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND); } - } + } - @Override + @Override public void setIsGlobal(boolean global) { - assertNotFrozen(); - isGlobal = global; - } + assertNotFrozen(); + isGlobal = global; + } - @Override + @Override public boolean isGlobal() { - return isGlobal; - } + return isGlobal; + } - @Override + @Override public void setIsVectored(boolean vectored) { - assertNotFrozen(); - isVectored = vectored; - } + assertNotFrozen(); + isVectored = vectored; + } - @Override + @Override public boolean isVectored() { - return isVectored; - } + return isVectored; + } - /** - * Tries to resolve both the destructor and operator delete. - */ - @Override + /** + * Tries to resolve both the destructor and operator delete. + */ + @Override public IASTImplicitName[] getImplicitNames() { - if (implicitNames == null) { - List<IASTImplicitName> names = new ArrayList<>(); - - if (!isVectored) { - ICPPFunction destructor = CPPSemantics.findImplicitlyCalledDestructor(this); - if (destructor != null) { - CPPASTImplicitName destructorName = new CPPASTImplicitName(destructor.getNameCharArray(), this); - destructorName.setBinding(destructor); - destructorName.computeOperatorOffsets(operand, false); - names.add(destructorName); - } - } - - if (!isGlobal) { - ICPPFunction deleteOperator = CPPSemantics.findOverloadedOperator(this); - if (deleteOperator != null && !(deleteOperator instanceof CPPImplicitFunction)) { - CPPASTImplicitName deleteName = new CPPASTImplicitName(deleteOperator.getNameCharArray(), this); - deleteName.setOperator(true); - deleteName.setBinding(deleteOperator); - deleteName.computeOperatorOffsets(operand, false); - names.add(deleteName); - } - } - - if (names.isEmpty()) { - implicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; - } else { - implicitNames = names.toArray(new IASTImplicitName[names.size()]); - } - } - - return implicitNames; + if (implicitNames == null) { + List<IASTImplicitName> names = new ArrayList<>(); + + if (!isVectored) { + ICPPFunction destructor = CPPSemantics.findImplicitlyCalledDestructor(this); + if (destructor != null) { + CPPASTImplicitName destructorName = new CPPASTImplicitName(destructor.getNameCharArray(), this); + destructorName.setBinding(destructor); + destructorName.computeOperatorOffsets(operand, false); + names.add(destructorName); + } + } + + if (!isGlobal) { + ICPPFunction deleteOperator = CPPSemantics.findOverloadedOperator(this); + if (deleteOperator != null && !(deleteOperator instanceof CPPImplicitFunction)) { + CPPASTImplicitName deleteName = new CPPASTImplicitName(deleteOperator.getNameCharArray(), this); + deleteName.setOperator(true); + deleteName.setBinding(deleteOperator); + deleteName.computeOperatorOffsets(operand, false); + names.add(deleteName); + } + } + + if (names.isEmpty()) { + implicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; + } else { + implicitNames = names.toArray(new IASTImplicitName[names.size()]); + } + } + + return implicitNames; } @Override @@ -156,44 +155,50 @@ public class CPPASTDeleteExpression extends ASTNode implements ICPPASTDeleteExpr return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitImplicitNames && !acceptByNodes(getImplicitNames(), action)) - return false; + if (action.shouldVisitImplicitNames && !acceptByNodes(getImplicitNames(), action)) + return false; - if (operand != null && !operand.accept(action)) - return false; + if (operand != null && !operand.accept(action)) + return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public ICPPEvaluation getEvaluation() { return EVALUATION; } - @Override + @Override public IType getExpressionType() { - return CPPSemantics.VOID_TYPE; - } + return CPPSemantics.VOID_TYPE; + } @Override public boolean isLValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDesignatedInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDesignatedInitializer.java index 7490a9a5741..98a12f7b038 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDesignatedInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDesignatedInitializer.java @@ -25,13 +25,12 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Implementation for designated initializers. */ -public class CPPASTDesignatedInitializer extends ASTNode - implements ICPPASTDesignatedInitializer, IASTAmbiguityParent { - private ICPPASTInitializerClause rhs; - private ICPPASTDesignator[] designators = ICPPASTDesignator.EMPTY_ARRAY; - private int designatorsPos; +public class CPPASTDesignatedInitializer extends ASTNode implements ICPPASTDesignatedInitializer, IASTAmbiguityParent { + private ICPPASTInitializerClause rhs; + private ICPPASTDesignator[] designators = ICPPASTDesignator.EMPTY_ARRAY; + private int designatorsPos; - public CPPASTDesignatedInitializer() { + public CPPASTDesignatedInitializer() { } public CPPASTDesignatedInitializer(ICPPASTInitializerClause init) { @@ -45,8 +44,8 @@ public class CPPASTDesignatedInitializer extends ASTNode @Override public CPPASTDesignatedInitializer copy(CopyStyle style) { - CPPASTDesignatedInitializer copy = - new CPPASTDesignatedInitializer(rhs == null ? null : (ICPPASTInitializerClause) rhs.copy(style)); + CPPASTDesignatedInitializer copy = new CPPASTDesignatedInitializer( + rhs == null ? null : (ICPPASTInitializerClause) rhs.copy(style)); for (ICPPASTDesignator designator : getDesignators()) { copy.addDesignator(designator == null ? null : designator.copy(style)); } @@ -55,30 +54,30 @@ public class CPPASTDesignatedInitializer extends ASTNode @Override public void addDesignator(ICPPASTDesignator designator) { - assertNotFrozen(); - if (designator != null) { - designator.setParent(this); - designator.setPropertyInParent(DESIGNATOR); - designators = ArrayUtil.appendAt(designators, designatorsPos++, designator); - } - } + assertNotFrozen(); + if (designator != null) { + designator.setParent(this); + designator.setPropertyInParent(DESIGNATOR); + designators = ArrayUtil.appendAt(designators, designatorsPos++, designator); + } + } - @Override + @Override public ICPPASTDesignator[] getDesignators() { - designators = ArrayUtil.trim(designators, designatorsPos); - return designators; - } + designators = ArrayUtil.trim(designators, designatorsPos); + return designators; + } - @Override + @Override public ICPPASTInitializerClause getOperand() { - return rhs; + return rhs; } @Override public void setOperand(ICPPASTInitializerClause operand) { - assertNotFrozen(); - this.rhs = operand; - if (rhs != null) { + assertNotFrozen(); + this.rhs = operand; + if (rhs != null) { rhs.setParent(this); rhs.setPropertyInParent(OPERAND); } @@ -91,36 +90,43 @@ public class CPPASTDesignatedInitializer extends ASTNode @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitInitializers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - ICPPASTDesignator[] ds = getDesignators(); - for (int i = 0; i < ds.length; i++) { - if (!ds[i].accept(action)) - return false; - } - if (rhs != null && !rhs.accept(action)) return false; + ICPPASTDesignator[] ds = getDesignators(); + for (int i = 0; i < ds.length; i++) { + if (!ds[i].accept(action)) + return false; + } + if (rhs != null && !rhs.accept(action)) + return false; - if (action.shouldVisitInitializers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitInitializers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == rhs) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - rhs = (ICPPASTInitializerClause) other; - } - } + if (child == rhs) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + rhs = (ICPPASTInitializerClause) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java index a83329ba630..c8ce24585d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java @@ -28,9 +28,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecDo; */ public class CPPASTDoStatement extends CPPASTAttributeOwner implements IASTDoStatement, ICPPExecutionOwner { private IASTStatement body; - private IASTExpression condition; + private IASTExpression condition; - public CPPASTDoStatement() { + public CPPASTDoStatement() { } public CPPASTDoStatement(IASTStatement body, IASTExpression condition) { @@ -53,74 +53,83 @@ public class CPPASTDoStatement extends CPPASTAttributeOwner implements IASTDoSta @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement body) { - assertNotFrozen(); - this.body = body; - if (body != null) { + assertNotFrozen(); + this.body = body; + if (body != null) { body.setParent(this); body.setPropertyInParent(BODY); } - } + } - @Override + @Override public IASTExpression getCondition() { - return condition; - } + return condition; + } - @Override + @Override public void setCondition(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (body != null && !body.accept(action)) return false; - if (condition != null && !condition.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (body != null && !body.accept(action)) + return false; + if (condition != null && !condition.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (body == child) { - other.setPropertyInParent(body.getPropertyInParent()); - other.setParent(body.getParent()); - body = (IASTStatement) other; - return; - } - if (child == condition) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - condition = (IASTExpression) other; - return; - } - super.replace(child, other); - } + if (body == child) { + other.setPropertyInParent(body.getPropertyInParent()); + other.setParent(body.getParent()); + body = (IASTStatement) other; + return; + } + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + condition = (IASTExpression) other; + return; + } + super.replace(child, other); + } @Override public ICPPExecution getExecution() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java index c8541d0018b..d5476856019 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java @@ -30,11 +30,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalNameOwner; * @author jcamelon */ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier - implements ICPPASTElaboratedTypeSpecifier, IASTInternalNameOwner { - private int kind; - private IASTName name; + implements ICPPASTElaboratedTypeSpecifier, IASTInternalNameOwner { + private int kind; + private IASTName name; - public CPPASTElaboratedTypeSpecifier() { + public CPPASTElaboratedTypeSpecifier() { } public CPPASTElaboratedTypeSpecifier(int kind, IASTName name) { @@ -49,60 +49,68 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier @Override public CPPASTElaboratedTypeSpecifier copy(CopyStyle style) { - CPPASTElaboratedTypeSpecifier copy = - new CPPASTElaboratedTypeSpecifier(kind, name == null ? null : name.copy(style)); + CPPASTElaboratedTypeSpecifier copy = new CPPASTElaboratedTypeSpecifier(kind, + name == null ? null : name.copy(style)); return super.copy(copy, style); } @Override public int getKind() { - return kind; - } + return kind; + } - @Override + @Override public void setKind(int value) { - assertNotFrozen(); - this.kind = value; - } + assertNotFrozen(); + this.kind = value; + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(TYPE_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (!acceptByAttributeSpecifiers(action)) return false; - if (name != null) if (!name.accept(action)) return false; - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (name != null) + if (!name.accept(action)) + return false; + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -111,7 +119,8 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier @Override public int getRoleForName(IASTName n, boolean allowResolution) { - if (n != name) return r_unclear; + if (n != name) + return r_unclear; IASTNode parent = getParent(); if (parent instanceof IASTSimpleDeclaration) { @@ -121,10 +130,9 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier } // 7.1.5.3.2: check for simple form <class-key> <identifier>, then it may be a declaration - final int kind= getKind(); + final int kind = getKind(); if (kind == k_class || kind == k_union || kind == k_struct) { - if (name instanceof ICPPASTQualifiedName == false - && name instanceof ICPPASTTemplateId == false) { + if (name instanceof ICPPASTQualifiedName == false && name instanceof ICPPASTTemplateId == false) { IBinding binding = allowResolution ? name.resolveBinding() : name.getBinding(); if (binding != null) { if (binding instanceof ICPPInternalBinding) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index 4fdf2db0450..53674262609 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -54,7 +54,6 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier setBaseType(baseType); } - @Override public CPPASTEnumerationSpecifier copy() { return copy(CopyStyle.withoutLocations); @@ -63,8 +62,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier @Override public CPPASTEnumerationSpecifier copy(CopyStyle style) { CPPASTEnumerationSpecifier copy = new CPPASTEnumerationSpecifier(fScopeStyle, - fName == null ? null : fName.copy(style), - fBaseType == null ? null : fBaseType.copy(style)); + fName == null ? null : fName.copy(style), fBaseType == null ? null : fBaseType.copy(style)); copy.fIsOpaque = fIsOpaque; for (IASTEnumerator enumerator : getEnumerators()) { copy.addEnumerator(enumerator == null ? null : enumerator.copy(style)); @@ -77,13 +75,13 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier if (fValuesComputed != null) return false; - fValuesComputed= Boolean.FALSE; + fValuesComputed = Boolean.FALSE; return true; } @Override public void finishValueComputation() { - fValuesComputed= Boolean.TRUE; + fValuesComputed = Boolean.TRUE; } @Override @@ -93,7 +91,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier @Override public void addEnumerator(IASTEnumerator enumerator) { - assertNotFrozen(); + assertNotFrozen(); if (enumerator != null) { enumerator.setParent(this); enumerator.setPropertyInParent(ENUMERATOR); @@ -109,7 +107,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier @Override public void setName(IASTName name) { - assertNotFrozen(); + assertNotFrozen(); fName = name; if (name != null) { name.setParent(this); @@ -187,7 +185,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier @Override public void setBaseType(ICPPASTDeclSpecifier baseType) { assertNotFrozen(); - fBaseType= baseType; + fBaseType = baseType; if (baseType != null) { baseType.setParent(this); baseType.setPropertyInParent(BASE_TYPE); @@ -202,7 +200,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier @Override public void setIsOpaque(boolean isOpaque) { assertNotFrozen(); - fIsOpaque= isOpaque; + fIsOpaque = isOpaque; } @Override @@ -215,7 +213,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier if (isOpaque()) return null; if (fScope == null) { - fScope= new CPPEnumScope(this); + fScope = new CPPEnumScope(this); } return fScope; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java index a6a0655ef5c..fc5b7208777 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java @@ -23,8 +23,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator; */ public class CPPASTEnumerator extends ASTEnumerator { - public CPPASTEnumerator() { - super(); + public CPPASTEnumerator() { + super(); } public CPPASTEnumerator(IASTName name, IASTExpression value) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java index ae3502c9c33..85d4b163043 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTEqualsInitializer; * Initializer with equals sign (copy initialization) */ public class CPPASTEqualsInitializer extends ASTEqualsInitializer { - public CPPASTEqualsInitializer() { + public CPPASTEqualsInitializer() { } public CPPASTEqualsInitializer(IASTInitializerClause arg) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java index 5d4393f9cbe..78ef92fb184 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExplicitTemplateInstantiation.java @@ -24,14 +24,13 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Models explicit instantiations. */ -public class CPPASTExplicitTemplateInstantiation extends ASTNode implements - ICPPASTExplicitTemplateInstantiation, IASTAmbiguityParent { +public class CPPASTExplicitTemplateInstantiation extends ASTNode + implements ICPPASTExplicitTemplateInstantiation, IASTAmbiguityParent { - private IASTDeclaration declaration; - private int modifier; + private IASTDeclaration declaration; + private int modifier; - - public CPPASTExplicitTemplateInstantiation() { + public CPPASTExplicitTemplateInstantiation() { } public CPPASTExplicitTemplateInstantiation(IASTDeclaration declaration) { @@ -53,21 +52,20 @@ public class CPPASTExplicitTemplateInstantiation extends ASTNode implements @Override public IASTDeclaration getDeclaration() { - return declaration; - } + return declaration; + } - @Override + @Override public void setDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - this.declaration = declaration; - if (declaration != null) { + assertNotFrozen(); + this.declaration = declaration; + if (declaration != null) { declaration.setParent(this); declaration.setPropertyInParent(OWNED_DECLARATION); } - } - + } - @Override + @Override public int getModifier() { return modifier; } @@ -75,39 +73,45 @@ public class CPPASTExplicitTemplateInstantiation extends ASTNode implements @Override public void setModifier(int mod) { assertNotFrozen(); - modifier= mod; + modifier = mod; } @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declaration != null) if (!declaration.accept(action)) return false; - - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (declaration != null) + if (!declaration.accept(action)) + return false; + + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } - + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (declaration == child) - { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - declaration = (IASTDeclaration) other; - } - } + if (declaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + declaration = (IASTDeclaration) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java index ea6cc9445a4..a46e1f5bbbd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java @@ -37,7 +37,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalComma; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionList, IASTAmbiguityParent { - private IASTExpression[] expressions = new IASTExpression[2]; + private IASTExpression[] expressions = new IASTExpression[2]; /** * Caution: may contain nulls. @@ -65,63 +65,70 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi @Override public IASTExpression[] getExpressions() { - if (expressions == null) return IASTExpression.EMPTY_EXPRESSION_ARRAY; - return ArrayUtil.trim(IASTExpression.class, expressions); - } + if (expressions == null) + return IASTExpression.EMPTY_EXPRESSION_ARRAY; + return ArrayUtil.trim(IASTExpression.class, expressions); + } - @Override + @Override public void addExpression(IASTExpression expression) { - assertNotFrozen(); + assertNotFrozen(); expressions = ArrayUtil.append(expressions, expression); - if (expression != null) { + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(NESTED_EXPRESSION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + IASTExpression[] exps = getExpressions(); + IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? computeImplicitNames() : null; + + for (int i = 0, n = exps.length; i < n; i++) { + if (!exps[i].accept(action)) { + return false; + } + if (i < n - 1 && implicits != null && implicits[i] != null) { + if (!implicits[i].accept(action)) { + return false; + } + } } - IASTExpression[] exps = getExpressions(); - IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? computeImplicitNames() : null; - - for (int i = 0, n = exps.length; i < n; i++) { - if (!exps[i].accept(action)) { - return false; - } - if (i < n - 1 && implicits != null && implicits[i] != null) { - if (!implicits[i].accept(action)) { - return false; - } - } - } - - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } - - /** - * Returns an array of implicit names where each element of the array represents a comma between - * the expression in the same index and the next expression. This array contains null elements - * as placeholders for commas that do not resolve to overloaded operators. - */ - private IASTImplicitName[] computeImplicitNames() { + return true; + } + + /** + * Returns an array of implicit names where each element of the array represents a comma between + * the expression in the same index and the next expression. This array contains null elements + * as placeholders for commas that do not resolve to overloaded operators. + */ + private IASTImplicitName[] computeImplicitNames() { if (fImplicitNames == null) { IASTExpression[] exprs = getExpressions(); // has to be at least two if (exprs.length < 2) @@ -144,10 +151,10 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi return fImplicitNames; } - @Override + @Override public IASTImplicitName[] getImplicitNames() { - return ArrayUtil.removeNulls(IASTImplicitName.class, computeImplicitNames()); - } + return ArrayUtil.removeNulls(IASTImplicitName.class, computeImplicitNames()); + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -158,35 +165,36 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi return fImplicitDestructorNames; } - private ICPPFunction[] getOverloads() { - ICPPEvaluation eval = getEvaluation(); - if (eval instanceof EvalComma) { - CPPSemantics.pushLookupPoint(this); - try { - return ((EvalComma) eval).getOverloads(); - } finally { - CPPSemantics.popLookupPoint(); - } - } - return null; - } - - @Override + private ICPPFunction[] getOverloads() { + ICPPEvaluation eval = getEvaluation(); + if (eval instanceof EvalComma) { + CPPSemantics.pushLookupPoint(this); + try { + return ((EvalComma) eval).getOverloads(); + } finally { + CPPSemantics.popLookupPoint(); + } + } + return null; + } + + @Override public void replace(IASTNode child, IASTNode other) { - if (expressions == null) return; - for (int i = 0; i < expressions.length; ++i) { - if (child == expressions[i]) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expressions[i] = (IASTExpression) other; - } - } - } + if (expressions == null) + return; + for (int i = 0; i < expressions.length; ++i) { + if (child == expressions[i]) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expressions[i] = (IASTExpression) other; + } + } + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) - fEvaluation= computeEvaluation(); + fEvaluation = computeEvaluation(); return fEvaluation; } @@ -196,21 +204,21 @@ public class CPPASTExpressionList extends ASTNode implements ICPPASTExpressionLi if (exprs.length < 2) return EvalFixed.INCOMPLETE; - ICPPEvaluation[] evals= new ICPPEvaluation[exprs.length]; + ICPPEvaluation[] evals = new ICPPEvaluation[exprs.length]; for (int i = 0; i < evals.length; i++) { - evals[i]= ((ICPPASTExpression) exprs[i]).getEvaluation(); + evals[i] = ((ICPPASTExpression) exprs[i]).getEvaluation(); } return new EvalComma(evals, this); } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { - return CPPEvaluation.getValueCategory(this); + return CPPEvaluation.getValueCategory(this); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java index e5463fe5612..fb8024ab9f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java @@ -24,10 +24,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecExpressionStat /** * @author jcamelon */ -public class CPPASTExpressionStatement extends CPPASTAttributeOwner implements IASTExpressionStatement, ICPPExecutionOwner { - private IASTExpression expression; +public class CPPASTExpressionStatement extends CPPASTAttributeOwner + implements IASTExpressionStatement, ICPPExecutionOwner { + private IASTExpression expression; - public CPPASTExpressionStatement() { + public CPPASTExpressionStatement() { } public CPPASTExpressionStatement(IASTExpression expression) { @@ -48,52 +49,60 @@ public class CPPASTExpressionStatement extends CPPASTAttributeOwner implements I @Override public IASTExpression getExpression() { - return expression; - } + return expression; + } - @Override + @Override public void setExpression(IASTExpression expression) { - assertNotFrozen(); - this.expression = expression; - if (expression != null) { + assertNotFrozen(); + this.expression = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(EXPRESSION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (expression != null && !expression.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (expression != null && !expression.accept(action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == expression) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - expression = (IASTExpression) other; - return; - } - super.replace(child, other); - } + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + expression = (IASTExpression) other; + return; + } + super.replace(child, other); + } @Override public ICPPExecution getExecution() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java index cbe63a97e87..3398b53632d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDeclarator.java @@ -24,12 +24,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDeclarator; * Field declarator for c++. */ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements ICPPASTFieldDeclarator { - private IASTExpression bitField; + private IASTExpression bitField; - public CPPASTFieldDeclarator() { + public CPPASTFieldDeclarator() { } - public CPPASTFieldDeclarator(IASTName name) { + public CPPASTFieldDeclarator(IASTName name) { super(name); } @@ -52,20 +52,20 @@ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements ICPPASTFi @Override public IASTExpression getBitFieldSize() { - return bitField; - } + return bitField; + } - @Override + @Override public void setBitFieldSize(IASTExpression size) { - assertNotFrozen(); - this.bitField = size; - if (size != null) { + assertNotFrozen(); + this.bitField = size; + if (size != null) { size.setParent(this); size.setPropertyInParent(FIELD_SIZE); } - } + } - @Override + @Override protected boolean postAccept(ASTVisitor action) { if (bitField != null && !bitField.accept(action)) return false; @@ -73,12 +73,12 @@ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements ICPPASTFi return super.postAccept(action); } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == bitField) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - bitField = (IASTExpression) other; - } - } + if (child == bitField) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + bitField = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDesignator.java index b6782c05087..fc9c91bf1e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDesignator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldDesignator.java @@ -24,8 +24,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; /** * Implementation of field designator. */ -public class CPPASTFieldDesignator extends ASTNode - implements ICPPASTFieldDesignator, ICPPASTCompletionContext { +public class CPPASTFieldDesignator extends ASTNode implements ICPPASTFieldDesignator, ICPPASTCompletionContext { private IASTName name; public CPPASTFieldDesignator() { @@ -65,9 +64,12 @@ public class CPPASTFieldDesignator extends ASTNode public boolean accept(ASTVisitor action) { if (action.shouldVisitDesignators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } if (name != null && !name.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java index e5966c0418c..89d24112b7c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java @@ -146,34 +146,33 @@ public class CPPASTFieldReference extends ASTNode @Override public IASTImplicitName[] getImplicitNames() { - if (fImplicitNames == null) { - if (!fIsDeref) - return fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; + if (fImplicitNames == null) { + if (!fIsDeref) + return fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; - CPPSemantics.pushLookupPoint(this); - try { - // Collect the function bindings + CPPSemantics.pushLookupPoint(this); + try { + // Collect the function bindings List<ICPPFunction> functionBindings = new ArrayList<>(); EvalMemberAccess.getFieldOwnerType(fOwner.getExpressionType(), fIsDeref, functionBindings, false); if (functionBindings.isEmpty()) return fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; - + // Create a name to wrap each binding fImplicitNames = new IASTImplicitName[functionBindings.size()]; int i = -1; for (ICPPFunction op : functionBindings) { if (op != null && !(op instanceof CPPImplicitFunction)) { - CPPASTImplicitName operatorName = new CPPASTImplicitName(OverloadableOperator.ARROW, - this); + CPPASTImplicitName operatorName = new CPPASTImplicitName(OverloadableOperator.ARROW, this); operatorName.setBinding(op); operatorName.computeOperatorOffsets(fOwner, true); fImplicitNames[++i] = operatorName; } } fImplicitNames = ArrayUtil.trimAt(IASTImplicitName.class, fImplicitNames, i); - } finally { - CPPSemantics.popLookupPoint(); - } + } finally { + CPPSemantics.popLookupPoint(); + } } return fImplicitNames; @@ -251,7 +250,7 @@ public class CPPASTFieldReference extends ASTNode CPPSemantics.pushLookupPoint(this); try { IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces); - + int j = 0; for (int i = 0; i < bindings.length; i++) { IBinding binding = bindings[i]; @@ -259,10 +258,9 @@ public class CPPASTFieldReference extends ASTNode if (i != j) bindings[j] = binding; j++; - } } - - + } + if (j < bindings.length) return Arrays.copyOfRange(bindings, 0, j); return bindings; @@ -299,36 +297,38 @@ public class CPPASTFieldReference extends ASTNode CPPSemantics.pushLookupPoint(this); ICPPEvaluation ownerEval = fOwner.getEvaluation(); if (!ownerEval.isTypeDependent()) { - IType ownerType= EvalMemberAccess.getFieldOwnerType(ownerEval.getType(), fIsDeref, null, false); + IType ownerType = EvalMemberAccess.getFieldOwnerType(ownerEval.getType(), fIsDeref, null, false); if (ownerType != null) { IBinding binding = fName.resolvePreBinding(); if (binding instanceof CPPFunctionSet) - binding= fName.resolveBinding(); - - if (binding instanceof IProblemBinding || binding instanceof IType || binding instanceof ICPPConstructor) { + binding = fName.resolveBinding(); + + if (binding instanceof IProblemBinding || binding instanceof IType + || binding instanceof ICPPConstructor) { return EvalFixed.INCOMPLETE; } - - return new EvalMemberAccess(ownerType, ownerEval.getValueCategory(), binding, ownerEval, fIsDeref, this); + + return new EvalMemberAccess(ownerType, ownerEval.getValueCategory(), binding, ownerEval, fIsDeref, + this); } } - - IBinding qualifier= null; - ICPPTemplateArgument[] args= null; - IASTName n= fName; + + IBinding qualifier = null; + ICPPTemplateArgument[] args = null; + IASTName n = fName; if (n instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qn= (ICPPASTQualifiedName) n; - ICPPASTNameSpecifier[] ns= qn.getQualifier(); + ICPPASTQualifiedName qn = (ICPPASTQualifiedName) n; + ICPPASTNameSpecifier[] ns = qn.getQualifier(); if (ns.length < 1) return EvalFixed.INCOMPLETE; - qualifier= ns[ns.length - 1].resolveBinding(); + qualifier = ns[ns.length - 1].resolveBinding(); if (qualifier instanceof IProblemBinding) return EvalFixed.INCOMPLETE; - n= qn.getLastName(); + n = qn.getLastName(); } if (n instanceof ICPPASTTemplateId) { try { - args= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) n); + args = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) n); } catch (DOMException e) { return EvalFixed.INCOMPLETE; } @@ -363,7 +363,7 @@ public class CPPASTFieldReference extends ASTNode @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); + return CPPEvaluation.getType(this); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java index bf0e087aae9..1c67f88bdb4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java @@ -34,35 +34,35 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecSimpleDeclarat * For statement in C++ */ public class CPPASTForStatement extends CPPASTAttributeOwner implements ICPPASTForStatement, ICPPExecutionOwner { - private IScope fScope; + private IScope fScope; - private IASTStatement fInit; - private IASTExpression fCondition; - private IASTDeclaration fCondDeclaration; - private IASTExpression fIterationExpression; - private IASTStatement fBody; + private IASTStatement fInit; + private IASTExpression fCondition; + private IASTDeclaration fCondDeclaration; + private IASTExpression fIterationExpression; + private IASTStatement fBody; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTForStatement() { + public CPPASTForStatement() { } - public CPPASTForStatement(IASTStatement init, IASTDeclaration condDeclaration, - IASTExpression iterationExpression, IASTStatement body) { - setInitializerStatement(init); - setConditionDeclaration(condDeclaration); - setIterationExpression(iterationExpression); - setBody(body); + public CPPASTForStatement(IASTStatement init, IASTDeclaration condDeclaration, IASTExpression iterationExpression, + IASTStatement body) { + setInitializerStatement(init); + setConditionDeclaration(condDeclaration); + setIterationExpression(iterationExpression); + setBody(body); } - public CPPASTForStatement(IASTStatement init, IASTExpression condition, - IASTExpression iterationExpression, IASTStatement body) { - setInitializerStatement(init); - setConditionExpression(condition); - setIterationExpression(iterationExpression); - setBody(body); + public CPPASTForStatement(IASTStatement init, IASTExpression condition, IASTExpression iterationExpression, + IASTStatement body) { + setInitializerStatement(init); + setConditionExpression(condition); + setIterationExpression(iterationExpression); + setBody(body); } - @Override + @Override public CPPASTForStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -73,64 +73,63 @@ public class CPPASTForStatement extends CPPASTAttributeOwner implements ICPPASTF copy.setInitializerStatement(fInit == null ? null : fInit.copy(style)); copy.setConditionDeclaration(fCondDeclaration == null ? null : fCondDeclaration.copy(style)); copy.setConditionExpression(fCondition == null ? null : fCondition.copy(style)); - copy.setIterationExpression(fIterationExpression == null ? - null : fIterationExpression.copy(style)); + copy.setIterationExpression(fIterationExpression == null ? null : fIterationExpression.copy(style)); copy.setBody(fBody == null ? null : fBody.copy(style)); return copy(copy, style); } @Override public IASTExpression getConditionExpression() { - return fCondition; - } + return fCondition; + } - @Override + @Override public void setConditionExpression(IASTExpression condition) { - assertNotFrozen(); - this.fCondition = condition; - if (condition != null) { + assertNotFrozen(); + this.fCondition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); - fCondDeclaration= null; + fCondDeclaration = null; } - } + } - @Override + @Override public IASTExpression getIterationExpression() { - return fIterationExpression; - } + return fIterationExpression; + } - @Override + @Override public void setIterationExpression(IASTExpression iterator) { - assertNotFrozen(); - this.fIterationExpression = iterator; - if (iterator != null) { + assertNotFrozen(); + this.fIterationExpression = iterator; + if (iterator != null) { iterator.setParent(this); iterator.setPropertyInParent(ITERATION); } - } + } - @Override + @Override public IASTStatement getBody() { - return fBody; - } + return fBody; + } - @Override + @Override public void setBody(IASTStatement statement) { - assertNotFrozen(); - fBody = statement; - if (statement != null) { + assertNotFrozen(); + fBody = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(BODY); } - } + } - @Override + @Override public IScope getScope() { - if (fScope == null) - fScope = new CPPBlockScope(this); - return fScope; - } + if (fScope == null) + fScope = new CPPBlockScope(this); + return fScope; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -141,35 +140,47 @@ public class CPPASTForStatement extends CPPASTAttributeOwner implements ICPPASTF return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (fInit != null && !fInit.accept(action)) return false; - if (fCondition != null && !fCondition.accept(action)) return false; - if (fCondDeclaration != null && !fCondDeclaration.accept(action)) return false; - if (fIterationExpression != null && !fIterationExpression.accept(action)) return false; - if (fBody != null && !fBody.accept(action)) return false; - - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; - - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + if (fInit != null && !fInit.accept(action)) + return false; + if (fCondition != null && !fCondition.accept(action)) + return false; + if (fCondDeclaration != null && !fCondDeclaration.accept(action)) + return false; + if (fIterationExpression != null && !fIterationExpression.accept(action)) + return false; + if (fBody != null && !fBody.accept(action)) + return false; + + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -199,36 +210,36 @@ public class CPPASTForStatement extends CPPASTAttributeOwner implements ICPPASTF super.replace(child, other); } - @Override + @Override public IASTStatement getInitializerStatement() { - return fInit; - } + return fInit; + } - @Override + @Override public void setInitializerStatement(IASTStatement statement) { - assertNotFrozen(); - fInit = statement; - if (statement != null) { + assertNotFrozen(); + fInit = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public void setConditionDeclaration(IASTDeclaration d) { - assertNotFrozen(); - fCondDeclaration = d; - if (d != null) { + assertNotFrozen(); + fCondDeclaration = d; + if (d != null) { d.setParent(this); d.setPropertyInParent(CONDITION_DECLARATION); - fCondition= null; + fCondition = null; } - } + } - @Override + @Override public IASTDeclaration getConditionDeclaration() { - return fCondDeclaration; - } + return fCondDeclaration; + } @Override public ICPPExecution getExecution() { @@ -236,7 +247,9 @@ public class CPPASTForStatement extends CPPASTAttributeOwner implements ICPPASTF ICPPASTExpression conditionExpr = (ICPPASTExpression) getConditionExpression(); ICPPExecutionOwner conditionDecl = (ICPPExecutionOwner) getConditionDeclaration(); ICPPEvaluation conditionExprEval = conditionExpr != null ? conditionExpr.getEvaluation() : null; - ExecSimpleDeclaration conditionDeclExec = conditionDecl != null ? (ExecSimpleDeclaration) conditionDecl.getExecution() : null; + ExecSimpleDeclaration conditionDeclExec = conditionDecl != null + ? (ExecSimpleDeclaration) conditionDecl.getExecution() + : null; ICPPASTExpression iterationExpr = (ICPPASTExpression) getIterationExpression(); ICPPEvaluation iterationEval = iterationExpr != null ? iterationExpr.getEvaluation() : null; ICPPExecution bodyExec = EvalUtil.getExecutionFromStatement(getBody()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 5c2de825645..3917785ac1f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -55,15 +55,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData; public class CPPASTFunctionCallExpression extends ASTNode implements ICPPASTFunctionCallExpression, IASTAmbiguityParent { - private ICPPASTExpression fFunctionName; - private IASTInitializerClause[] fArguments; + private ICPPASTExpression fFunctionName; + private IASTInitializerClause[] fArguments; - private IASTImplicitName[] fImplicitNames; + private IASTImplicitName[] fImplicitNames; private ICPPEvaluation fEvaluation; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTFunctionCallExpression() { - setArguments(null); + public CPPASTFunctionCallExpression() { + setArguments(null); } public CPPASTFunctionCallExpression(IASTExpression functionName, IASTInitializerClause[] args) { @@ -80,7 +80,7 @@ public class CPPASTFunctionCallExpression extends ASTNode public CPPASTFunctionCallExpression copy(CopyStyle style) { IASTInitializerClause[] args = null; if (fArguments.length > 0) { - args= new IASTInitializerClause[fArguments.length]; + args = new IASTInitializerClause[fArguments.length]; for (int i = 0; i < fArguments.length; i++) { args[i] = fArguments[i].copy(style); } @@ -91,44 +91,44 @@ public class CPPASTFunctionCallExpression extends ASTNode return copy(copy, style); } - @Override + @Override public IASTExpression getFunctionNameExpression() { - return fFunctionName; - } + return fFunctionName; + } @Override public void setFunctionNameExpression(IASTExpression expression) { - assertNotFrozen(); - this.fFunctionName = (ICPPASTExpression) expression; - if (expression != null) { + assertNotFrozen(); + this.fFunctionName = (ICPPASTExpression) expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(FUNCTION_NAME); } - } + } @Override public IASTInitializerClause[] getArguments() { - return fArguments; - } + return fArguments; + } - @Override + @Override public void setArguments(IASTInitializerClause[] arguments) { - assertNotFrozen(); - if (arguments == null) { - fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY; - } else { - fArguments= arguments; - for (IASTInitializerClause arg : arguments) { + assertNotFrozen(); + if (arguments == null) { + fArguments = IASTExpression.EMPTY_EXPRESSION_ARRAY; + } else { + fArguments = arguments; + for (IASTInitializerClause arg : arguments) { arg.setParent(this); arg.setPropertyInParent(ARGUMENT); } } - } + } - @Override + @Override public IASTImplicitName[] getImplicitNames() { - if (fImplicitNames == null) { - ICPPFunction overload = getOverload(); + if (fImplicitNames == null) { + ICPPFunction overload = getOverload(); if (overload == null) return fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; @@ -136,7 +136,7 @@ public class CPPASTFunctionCallExpression extends ASTNode CPPASTImplicitName n1 = new CPPASTImplicitName(overload.getNameCharArray(), this); n1.setOffsetAndLength((ASTNode) fFunctionName); n1.setBinding(overload); - return fImplicitNames= new IASTImplicitName[] {n1}; + return fImplicitNames = new IASTImplicitName[] { n1 }; } if (overload instanceof CPPImplicitFunction) { @@ -180,9 +180,9 @@ public class CPPASTFunctionCallExpression extends ASTNode } fImplicitNames = new IASTImplicitName[] { n1, n2 }; - } - return fImplicitNames; - } + } + return fImplicitNames; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -193,20 +193,23 @@ public class CPPASTFunctionCallExpression extends ASTNode return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fFunctionName != null && !fFunctionName.accept(action)) return false; - IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; + IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; if (implicits != null && implicits.length > 0 && !implicits[0].accept(action)) return false; @@ -219,14 +222,14 @@ public class CPPASTFunctionCallExpression extends ASTNode if (implicits != null && implicits.length > 1 && !implicits[1].accept(action)) return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -251,16 +254,16 @@ public class CPPASTFunctionCallExpression extends ASTNode ICPPEvaluation eval = getEvaluation(); if (eval instanceof EvalFunctionCall) return ((EvalFunctionCall) eval).getOverload(); - + if (eval instanceof EvalTypeId) { if (!eval.isTypeDependent()) { - IType t= getNestedType(((EvalTypeId) eval).getInputType(), TDEF | CVTYPE | REF); + IType t = getNestedType(((EvalTypeId) eval).getInputType(), TDEF | CVTYPE | REF); if (t instanceof ICPPClassType && !(t instanceof ICPPUnknownBinding)) { - ICPPClassType cls= (ICPPClassType) t; - LookupData data= CPPSemantics.createLookupData(((IASTIdExpression) fFunctionName).getName()); + ICPPClassType cls = (ICPPClassType) t; + LookupData data = CPPSemantics.createLookupData(((IASTIdExpression) fFunctionName).getName()); try { ICPPConstructor[] constructors = cls.getConstructors(); - IBinding b= CPPSemantics.resolveFunction(data, constructors, true, false); + IBinding b = CPPSemantics.resolveFunction(data, constructors, true, false); if (b instanceof ICPPFunction) return (ICPPFunction) b; } catch (DOMException e) { @@ -272,12 +275,12 @@ public class CPPASTFunctionCallExpression extends ASTNode } finally { CPPSemantics.popLookupPoint(); } - } + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) - fEvaluation= computeEvaluation(); + fEvaluation = computeEvaluation(); return fEvaluation; } @@ -286,14 +289,14 @@ public class CPPASTFunctionCallExpression extends ASTNode if (fFunctionName == null || fArguments == null) return EvalFixed.INCOMPLETE; - ICPPEvaluation conversion= checkForExplicitTypeConversion(); + ICPPEvaluation conversion = checkForExplicitTypeConversion(); if (conversion != null) return conversion; - ICPPEvaluation[] args= new ICPPEvaluation[fArguments.length + 1]; - args[0]= fFunctionName.getEvaluation(); + ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length + 1]; + args[0] = fFunctionName.getEvaluation(); for (int i = 1; i < args.length; i++) { - args[i]= ((ICPPASTInitializerClause) fArguments[i - 1]).getEvaluation(); + args[i] = ((ICPPASTInitializerClause) fArguments[i - 1]).getEvaluation(); } ICPPEvaluation fieldOwnerEval = null; if (fFunctionName instanceof ICPPASTFieldReference) { @@ -307,11 +310,11 @@ public class CPPASTFunctionCallExpression extends ASTNode private ICPPEvaluation checkForExplicitTypeConversion() { if (fFunctionName instanceof IASTIdExpression) { final IASTName name = ((IASTIdExpression) fFunctionName).getName(); - IBinding b= name.resolvePreBinding(); + IBinding b = name.resolvePreBinding(); if (b instanceof IType) { - ICPPEvaluation[] args= new ICPPEvaluation[fArguments.length]; + ICPPEvaluation[] args = new ICPPEvaluation[fArguments.length]; for (int i = 0; i < args.length; i++) { - args[i]= ((ICPPASTInitializerClause) fArguments[i]).getEvaluation(); + args[i] = ((ICPPASTInitializerClause) fArguments[i]).getEvaluation(); } return new EvalTypeId((IType) b, this, false, args); @@ -320,10 +323,10 @@ public class CPPASTFunctionCallExpression extends ASTNode return null; } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java index c2610b63e28..f5276b31079 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java @@ -36,22 +36,22 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; * Represents a function declarator. */ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPASTFunctionDeclarator { - private ICPPASTParameterDeclaration[] parameters; - private IASTTypeId[] typeIds = NO_EXCEPTION_SPECIFICATION; - private ICPPASTExpression noexceptExpression; - private IASTTypeId trailingReturnType; - private ICPPASTVirtSpecifier[] virtSpecifiers = NO_VIRT_SPECIFIERS; - - private boolean varArgs; - private boolean pureVirtual; - private boolean isVolatile; - private boolean isConst; - private boolean isMutable; - private RefQualifier refQualifier; - - private ICPPFunctionScope scope; - - public CPPASTFunctionDeclarator() { + private ICPPASTParameterDeclaration[] parameters; + private IASTTypeId[] typeIds = NO_EXCEPTION_SPECIFICATION; + private ICPPASTExpression noexceptExpression; + private IASTTypeId trailingReturnType; + private ICPPASTVirtSpecifier[] virtSpecifiers = NO_VIRT_SPECIFIERS; + + private boolean varArgs; + private boolean pureVirtual; + private boolean isVolatile; + private boolean isConst; + private boolean isMutable; + private RefQualifier refQualifier; + + private ICPPFunctionScope scope; + + public CPPASTFunctionDeclarator() { } public CPPASTFunctionDeclarator(IASTName name) { @@ -80,8 +80,8 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS copy.addExceptionSpecificationTypeId(typeId == null ? null : typeId.copy(style)); } if (noexceptExpression != null) { - copy.setNoexceptExpression(noexceptExpression == NOEXCEPT_DEFAULT ? - noexceptExpression : (ICPPASTExpression) noexceptExpression.copy(style)); + copy.setNoexceptExpression(noexceptExpression == NOEXCEPT_DEFAULT ? noexceptExpression + : (ICPPASTExpression) noexceptExpression.copy(style)); } if (trailingReturnType != null) { copy.setTrailingReturnType(trailingReturnType.copy(style)); @@ -94,87 +94,88 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS @Override public ICPPASTParameterDeclaration[] getParameters() { - if (parameters == null) - return ICPPASTParameterDeclaration.EMPTY_CPPPARAMETERDECLARATION_ARRAY; + if (parameters == null) + return ICPPASTParameterDeclaration.EMPTY_CPPPARAMETERDECLARATION_ARRAY; - return parameters= ArrayUtil.trim(parameters); - } + return parameters = ArrayUtil.trim(parameters); + } - @Override + @Override public void addParameterDeclaration(IASTParameterDeclaration parameter) { - assertNotFrozen(); - if (parameter != null) { - parameter.setParent(this); + assertNotFrozen(); + if (parameter != null) { + parameter.setParent(this); parameter.setPropertyInParent(FUNCTION_PARAMETER); - parameters = ArrayUtil.append(ICPPASTParameterDeclaration.class, parameters, (ICPPASTParameterDeclaration) parameter); - } - } + parameters = ArrayUtil.append(ICPPASTParameterDeclaration.class, parameters, + (ICPPASTParameterDeclaration) parameter); + } + } - @Override + @Override public boolean takesVarArgs() { - return varArgs; - } + return varArgs; + } - @Override + @Override public void setVarArgs(boolean value) { - assertNotFrozen(); - varArgs = value; - } + assertNotFrozen(); + varArgs = value; + } - @Override + @Override public boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public void setConst(boolean value) { - assertNotFrozen(); - this.isConst = value; - } + assertNotFrozen(); + this.isConst = value; + } - @Override + @Override public boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public void setVolatile(boolean value) { - assertNotFrozen(); - this.isVolatile = value; - } + assertNotFrozen(); + this.isVolatile = value; + } - @Override + @Override public boolean isMutable() { - return isMutable; - } + return isMutable; + } - @Override + @Override public void setMutable(boolean value) { - assertNotFrozen(); - this.isMutable = value; - } + assertNotFrozen(); + this.isMutable = value; + } - @Override + @Override public IASTTypeId[] getExceptionSpecification() { - return typeIds= ArrayUtil.trim(typeIds); - } + return typeIds = ArrayUtil.trim(typeIds); + } - @Override + @Override public void setEmptyExceptionSpecification() { - assertNotFrozen(); - typeIds= IASTTypeId.EMPTY_TYPEID_ARRAY; - } + assertNotFrozen(); + typeIds = IASTTypeId.EMPTY_TYPEID_ARRAY; + } - @Override + @Override public void addExceptionSpecificationTypeId(IASTTypeId typeId) { - assertNotFrozen(); - if (typeId != null) { - assert typeIds != null; - typeIds = ArrayUtil.append(typeIds, typeId); - typeId.setParent(this); + assertNotFrozen(); + if (typeId != null) { + assert typeIds != null; + typeIds = ArrayUtil.append(typeIds, typeId); + typeId.setParent(this); typeId.setPropertyInParent(EXCEPTION_TYPEID); - } - } + } + } @Override public ICPPASTExpression getNoexceptExpression() { @@ -199,7 +200,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS @Override public void setTrailingReturnType(IASTTypeId typeId) { assertNotFrozen(); - trailingReturnType= typeId; + trailingReturnType = typeId; if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TRAILING_RETURN_TYPE); @@ -208,71 +209,71 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS @Override public boolean isPureVirtual() { - return pureVirtual; - } + return pureVirtual; + } - @Override + @Override public void setPureVirtual(boolean isPureVirtual) { - assertNotFrozen(); - this.pureVirtual = isPureVirtual; - } + assertNotFrozen(); + this.pureVirtual = isPureVirtual; + } - @Override + @Override public RefQualifier getRefQualifier() { return refQualifier; } - @Override + @Override public void setRefQualifier(RefQualifier value) { - assertNotFrozen(); + assertNotFrozen(); refQualifier = value; } @Override @Deprecated - public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer[] getConstructorChain() { - if (ASTQueries.findTypeRelevantDeclarator(this) == this) { - IASTNode parent= getParent(); - while (!(parent instanceof IASTDeclaration)) { - if (parent == null) - break; - parent= parent.getParent(); - } - if (parent instanceof ICPPASTFunctionDefinition) { - return ((ICPPASTFunctionDefinition) parent).getMemberInitializers(); - } - } - return org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY; - } - - @Override + public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer[] getConstructorChain() { + if (ASTQueries.findTypeRelevantDeclarator(this) == this) { + IASTNode parent = getParent(); + while (!(parent instanceof IASTDeclaration)) { + if (parent == null) + break; + parent = parent.getParent(); + } + if (parent instanceof ICPPASTFunctionDefinition) { + return ((ICPPASTFunctionDefinition) parent).getMemberInitializers(); + } + } + return org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY; + } + + @Override @Deprecated - public void addConstructorToChain(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer initializer) { - assertNotFrozen(); - } + public void addConstructorToChain(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer initializer) { + assertNotFrozen(); + } - @Override + @Override public ICPPFunctionScope getFunctionScope() { - if (scope != null) - return scope; - - // introduce a scope for function declarations and definitions, only. - IASTNode node= getParent(); - while (!(node instanceof IASTDeclaration)) { - if (node==null) - return null; - node= node.getParent(); - } - if (node instanceof IASTParameterDeclaration) - return null; - - if (ASTQueries.findTypeRelevantDeclarator(this) == this) { - scope = new CPPFunctionScope(this); - } - return scope; - } - - @Override + if (scope != null) + return scope; + + // introduce a scope for function declarations and definitions, only. + IASTNode node = getParent(); + while (!(node instanceof IASTDeclaration)) { + if (node == null) + return null; + node = node.getParent(); + } + if (node instanceof IASTParameterDeclaration) + return null; + + if (ASTQueries.findTypeRelevantDeclarator(this) == this) { + scope = new CPPFunctionScope(this); + } + return scope; + } + + @Override protected boolean postAccept(ASTVisitor action) { IASTParameterDeclaration[] params = getParameters(); for (int i = 0; i < params.length; i++) { @@ -360,7 +361,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS @Override public ICPPASTVirtSpecifier[] getVirtSpecifiers() { - return virtSpecifiers = ArrayUtil.trim(virtSpecifiers); + return virtSpecifiers = ArrayUtil.trim(virtSpecifiers); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java index f5c6e5e98cf..55aeaee9c30 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java @@ -47,20 +47,20 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; */ public class CPPASTFunctionDefinition extends CPPASTAttributeOwner implements ICPPASTFunctionDefinition, IASTImplicitNameOwner { - private IASTDeclSpecifier declSpecifier; - private IASTFunctionDeclarator declarator; - private IASTStatement bodyStatement; - private ICPPASTConstructorChainInitializer[] memInits; - private IASTImplicitName[] implicitNames; // for constructors: base constructors called implicitly - private int memInitPos= -1; - private boolean fDeleted; - private boolean fDefaulted; - - public CPPASTFunctionDefinition() { + private IASTDeclSpecifier declSpecifier; + private IASTFunctionDeclarator declarator; + private IASTStatement bodyStatement; + private ICPPASTConstructorChainInitializer[] memInits; + private IASTImplicitName[] implicitNames; // for constructors: base constructors called implicitly + private int memInitPos = -1; + private boolean fDeleted; + private boolean fDefaulted; + + public CPPASTFunctionDefinition() { } - public CPPASTFunctionDefinition(IASTDeclSpecifier declSpecifier, - IASTFunctionDeclarator declarator, IASTStatement bodyStatement) { + public CPPASTFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, + IASTStatement bodyStatement) { setDeclSpecifier(declSpecifier); setDeclarator(declarator); setBody(bodyStatement); @@ -95,67 +95,67 @@ public class CPPASTFunctionDefinition extends CPPASTAttributeOwner @Override public IASTDeclSpecifier getDeclSpecifier() { - return declSpecifier; - } + return declSpecifier; + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); - declSpecifier = declSpec; - if (declSpec != null) { + assertNotFrozen(); + declSpecifier = declSpec; + if (declSpec != null) { declSpec.setParent(this); declSpec.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public IASTFunctionDeclarator getDeclarator() { - return declarator; - } + return declarator; + } - @Override + @Override public void setDeclarator(IASTFunctionDeclarator declarator) { - assertNotFrozen(); - this.declarator = declarator; - if (declarator != null) { - IASTDeclarator outerDtor= ASTQueries.findOutermostDeclarator(declarator); - outerDtor.setParent(this); - outerDtor.setPropertyInParent(DECLARATOR); + assertNotFrozen(); + this.declarator = declarator; + if (declarator != null) { + IASTDeclarator outerDtor = ASTQueries.findOutermostDeclarator(declarator); + outerDtor.setParent(this); + outerDtor.setPropertyInParent(DECLARATOR); } - } + } - @Override + @Override public IASTStatement getBody() { - return bodyStatement; - } + return bodyStatement; + } - @Override + @Override public void setBody(IASTStatement statement) { - assertNotFrozen(); - bodyStatement = statement; - if (statement != null) { + assertNotFrozen(); + bodyStatement = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(FUNCTION_BODY); } - } + } @Override public void addMemberInitializer(ICPPASTConstructorChainInitializer initializer) { - assertNotFrozen(); - if (initializer != null) { - memInits= ArrayUtil.appendAt(ICPPASTConstructorChainInitializer.class, memInits, ++memInitPos, initializer); - initializer.setParent(this); + assertNotFrozen(); + if (initializer != null) { + memInits = ArrayUtil.appendAt(ICPPASTConstructorChainInitializer.class, memInits, ++memInitPos, + initializer); + initializer.setParent(this); initializer.setPropertyInParent(MEMBER_INITIALIZER); - } + } } @Override public ICPPASTConstructorChainInitializer[] getMemberInitializers() { - if (memInits == null) - return ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY; + if (memInits == null) + return ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY; - return memInits= ArrayUtil.trimAt( - ICPPASTConstructorChainInitializer.class, memInits, memInitPos); + return memInits = ArrayUtil.trimAt(ICPPASTConstructorChainInitializer.class, memInits, memInitPos); } @Override @@ -176,13 +176,13 @@ public class CPPASTFunctionDefinition extends CPPASTAttributeOwner @Override public void setIsDefaulted(boolean isDefaulted) { assertNotFrozen(); - fDefaulted= isDefaulted; + fDefaulted = isDefaulted; } @Override public void setIsDeleted(boolean isDeleted) { assertNotFrozen(); - fDeleted= isDeleted; + fDeleted = isDeleted; } @Override @@ -234,23 +234,23 @@ public class CPPASTFunctionDefinition extends CPPASTAttributeOwner return true; } - /** - * Allows subclasses to visit catch handlers, returns whether the visit should continue. - */ + /** + * Allows subclasses to visit catch handlers, returns whether the visit should continue. + */ protected boolean acceptCatchHandlers(ASTVisitor action) { return true; } @Override public void replace(IASTNode child, IASTNode other) { - if (bodyStatement == child) { - other.setPropertyInParent(bodyStatement.getPropertyInParent()); - other.setParent(bodyStatement.getParent()); - bodyStatement = (IASTStatement) other; - return; - } - super.replace(child, other); - } + if (bodyStatement == child) { + other.setPropertyInParent(bodyStatement.getPropertyInParent()); + other.setParent(bodyStatement.getParent()); + bodyStatement = (IASTStatement) other; + return; + } + super.replace(child, other); + } @Override public IASTImplicitName[] getImplicitNames() { @@ -262,7 +262,7 @@ public class CPPASTFunctionDefinition extends CPPASTAttributeOwner CPPSemantics.pushLookupPoint(this); try { ICPPClassType classOwner = ((ICPPConstructor) function).getClassOwner(); - + // Determine the bases of 'classOwner' that need to be initialized by this constructor. Set<ICPPClassType> basesThatNeedInitialization = new HashSet<>(); for (ICPPBase base : classOwner.getBases()) { @@ -274,16 +274,16 @@ public class CPPASTFunctionDefinition extends CPPASTAttributeOwner for (ICPPClassType virtualBase : ClassTypeHelper.getVirtualBases(classOwner)) { basesThatNeedInitialization.add(virtualBase); } - + // Go through the bases determined above, and see which ones aren't initialized // explicitly in the mem-initializer list. for (ICPPClassType base : basesThatNeedInitialization) { if (!isInitializedExplicitly(base)) { // Try to find a default constructor to create an implicit name for. for (ICPPConstructor constructor : base.getConstructors()) { - if (constructor.getRequiredArgumentCount() == 0) { // default constructor - CPPASTImplicitName ctorName = new CPPASTImplicitName( - constructor.getNameCharArray(), this); + if (constructor.getRequiredArgumentCount() == 0) { // default constructor + CPPASTImplicitName ctorName = new CPPASTImplicitName(constructor.getNameCharArray(), + this); ctorName.setBinding(constructor); ctorName.setOffsetAndLength((ASTNode) functionName); implicitNames = ArrayUtil.append(implicitNames, ctorName); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionWithTryBlock.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionWithTryBlock.java index 2242208f96d..1c8663b47fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionWithTryBlock.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionWithTryBlock.java @@ -27,14 +27,14 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; * @see ICPPASTFunctionWithTryBlock */ public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition implements ICPPASTFunctionWithTryBlock { - private ICPPASTCatchHandler[] catchHandlers; - private int catchHandlersPos= -1; + private ICPPASTCatchHandler[] catchHandlers; + private int catchHandlersPos = -1; - public CPPASTFunctionWithTryBlock() { + public CPPASTFunctionWithTryBlock() { } - public CPPASTFunctionWithTryBlock(IASTDeclSpecifier declSpecifier, - IASTFunctionDeclarator declarator, IASTStatement bodyStatement) { + public CPPASTFunctionWithTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, + IASTStatement bodyStatement) { super(declSpecifier, declarator, bodyStatement); } @@ -66,28 +66,29 @@ public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition impleme @Override public void addCatchHandler(ICPPASTCatchHandler statement) { - assertNotFrozen(); - if (statement != null) { - catchHandlers = ArrayUtil.appendAt(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement); - statement.setParent(this); + assertNotFrozen(); + if (statement != null) { + catchHandlers = ArrayUtil.appendAt(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement); + statement.setParent(this); statement.setPropertyInParent(CATCH_HANDLER); - } - } + } + } - @Override + @Override public ICPPASTCatchHandler[] getCatchHandlers() { - if (catchHandlers == null) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY; - catchHandlers = ArrayUtil.trimAt(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos); - return catchHandlers; - } + if (catchHandlers == null) + return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY; + catchHandlers = ArrayUtil.trimAt(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos); + return catchHandlers; + } - @Override + @Override protected boolean acceptCatchHandlers(ASTVisitor action) { - final ICPPASTCatchHandler[] handlers = getCatchHandlers(); - for (int i= 0; i < handlers.length; i++) { - if (!handlers[i].accept(action)) - return false; - } - return true; - } + final ICPPASTCatchHandler[] handlers = getCatchHandlers(); + for (int i = 0; i < handlers.length; i++) { + if (!handlers[i].accept(action)) + return false; + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java index aebfda8a5b4..9a72bada291 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; public class CPPASTGotoStatement extends CPPASTAttributeOwner implements IASTGotoStatement { private IASTName name; - public CPPASTGotoStatement() { + public CPPASTGotoStatement() { } public CPPASTGotoStatement(IASTName name) { @@ -44,45 +44,54 @@ public class CPPASTGotoStatement extends CPPASTAttributeOwner implements IASTGot @Override public IASTName getName() { - return this.name; - } + return this.name; + } - @Override - public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { - name.setParent(this); - name.setPropertyInParent(NAME); - } - } + @Override + public void setName(IASTName name) { + assertNotFrozen(); + this.name = name; + if (name != null) { + name.setParent(this); + name.setPropertyInParent(NAME); + } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (name != null && !name.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (name == n) return r_reference; + if (name == n) + return r_reference; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java index f5c8925778b..c0d6c03d0cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java @@ -42,7 +42,7 @@ public class CPPASTIdExpression extends ASTNode private ICPPEvaluation fEvaluation; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTIdExpression() { + public CPPASTIdExpression() { } public CPPASTIdExpression(IASTName name) { @@ -62,18 +62,18 @@ public class CPPASTIdExpression extends ASTNode @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName = name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(ID_NAME); } - } + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -84,30 +84,37 @@ public class CPPASTIdExpression extends ASTNode return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fName != null && !fName.accept(action)) return false; + if (fName != null && !fName.accept(action)) + return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -134,7 +141,7 @@ public class CPPASTIdExpression extends ASTNode @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { - fEvaluation= EvalID.create(this); + fEvaluation = EvalID.create(this); } return fEvaluation; } @@ -143,9 +150,9 @@ public class CPPASTIdExpression extends ASTNode public IType getExpressionType() { CPPSemantics.pushLookupPoint(this); try { - IType type= getEvaluation().getType(); + IType type = getEvaluation().getType(); if (type instanceof FunctionSetType) { - IBinding binding= fName.resolveBinding(); + IBinding binding = fName.resolveBinding(); if (binding instanceof IFunction) { return SemanticUtil.mapToAST(((IFunction) binding).getType()); } @@ -164,6 +171,6 @@ public class CPPASTIdExpression extends ASTNode @Override public ValueCategory getValueCategory() { - return CPPEvaluation.getValueCategory(this); + return CPPEvaluation.getValueCategory(this); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java index b7dcd5bca34..20c9d082469 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java @@ -32,15 +32,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecSimpleDeclarat * If statement in C++ */ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIfStatement, ICPPExecutionOwner { - private boolean isConstexpr; - private IASTStatement initStatement; - private IASTExpression condition; - private IASTStatement thenClause; - private IASTStatement elseClause; - private IASTDeclaration condDecl; - private IScope scope; - - public CPPASTIfStatement() { + private boolean isConstexpr; + private IASTStatement initStatement; + private IASTExpression condition; + private IASTStatement thenClause; + private IASTStatement elseClause; + private IASTDeclaration condDecl; + private IScope scope; + + public CPPASTIfStatement() { } public CPPASTIfStatement(IASTDeclaration condition, IASTStatement thenClause, IASTStatement elseClause) { @@ -55,7 +55,7 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf setElseClause(elseClause); } - @Override + @Override public CPPASTIfStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -74,49 +74,49 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf @Override public IASTExpression getConditionExpression() { - return condition; - } + return condition; + } - @Override + @Override public void setConditionExpression(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); - condDecl= null; + condDecl = null; } - } + } - @Override + @Override public IASTStatement getThenClause() { - return thenClause; - } + return thenClause; + } - @Override + @Override public void setThenClause(IASTStatement thenClause) { - assertNotFrozen(); - this.thenClause = thenClause; - if (thenClause != null) { + assertNotFrozen(); + this.thenClause = thenClause; + if (thenClause != null) { thenClause.setParent(this); thenClause.setPropertyInParent(THEN); } - } + } - @Override + @Override public IASTStatement getElseClause() { - return elseClause; - } + return elseClause; + } - @Override + @Override public void setElseClause(IASTStatement elseClause) { - assertNotFrozen(); - this.elseClause = elseClause; - if (elseClause != null) { + assertNotFrozen(); + this.elseClause = elseClause; + if (elseClause != null) { elseClause.setParent(this); elseClause.setPropertyInParent(ELSE); } - } + } private static class N { final IASTIfStatement fIfStatement; @@ -127,61 +127,64 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf } } - @Override + @Override public boolean accept(ASTVisitor action) { - N stack= null; - ICPPASTIfStatement stmt= this; - loop: for (;;) { - if (action.shouldVisitStatements) { - switch (action.visit(stmt)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: - stmt= null; - break loop; - default: break; - } - } - - if (!((CPPASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false; - - IASTNode child = stmt.getInitializerStatement(); - if (child != null && !child.accept(action)) - return false; - child = stmt.getConditionExpression(); - if (child != null && !child.accept(action)) - return false; - child= stmt.getConditionDeclaration(); - if (child != null && !child.accept(action)) - return false; - child= stmt.getThenClause(); - if (child != null && !child.accept(action)) - return false; - child= stmt.getElseClause(); - if (child instanceof ICPPASTIfStatement) { - if (action.shouldVisitStatements) { - N n= new N(stmt); - n.fNext= stack; - stack= n; - } - stmt= (ICPPASTIfStatement) child; - } else { - if (child != null && !child.accept(action)) - return false; - break loop; - } - } - - if (action.shouldVisitStatements) { - if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) - return false; - while (stack != null) { - if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) - return false; - stack= stack.fNext; - } - } - return true; - } + N stack = null; + ICPPASTIfStatement stmt = this; + loop: for (;;) { + if (action.shouldVisitStatements) { + switch (action.visit(stmt)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + stmt = null; + break loop; + default: + break; + } + } + + if (!((CPPASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) + return false; + + IASTNode child = stmt.getInitializerStatement(); + if (child != null && !child.accept(action)) + return false; + child = stmt.getConditionExpression(); + if (child != null && !child.accept(action)) + return false; + child = stmt.getConditionDeclaration(); + if (child != null && !child.accept(action)) + return false; + child = stmt.getThenClause(); + if (child != null && !child.accept(action)) + return false; + child = stmt.getElseClause(); + if (child instanceof ICPPASTIfStatement) { + if (action.shouldVisitStatements) { + N n = new N(stmt); + n.fNext = stack; + stack = n; + } + stmt = (ICPPASTIfStatement) child; + } else { + if (child != null && !child.accept(action)) + return false; + break loop; + } + } + + if (action.shouldVisitStatements) { + if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) + return false; + while (stack != null) { + if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) + return false; + stack = stack.fNext; + } + } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -190,22 +193,22 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf other.setPropertyInParent(child.getPropertyInParent()); initStatement = (IASTStatement) other; return; - } - + } + if (thenClause == child) { other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); thenClause = (IASTStatement) other; return; - } - + } + if (elseClause == child) { other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); elseClause = (IASTStatement) other; return; - } - + } + if (condition == child || condDecl == child) { if (other instanceof IASTExpression) { setConditionExpression((IASTExpression) other); @@ -214,25 +217,25 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf } return; } - + super.replace(child, other); } - @Override + @Override public IASTDeclaration getConditionDeclaration() { - return condDecl; - } + return condDecl; + } - @Override + @Override public void setConditionDeclaration(IASTDeclaration d) { - assertNotFrozen(); - condDecl = d; - if (d != null) { + assertNotFrozen(); + condDecl = d; + if (d != null) { d.setParent(this); d.setPropertyInParent(CONDITION); - condition= null; + condition = null; } - } + } @Override public boolean isConstexpr() { @@ -252,21 +255,21 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf @Override public void setInitializerStatement(IASTStatement statement) { - assertNotFrozen(); - this.initStatement = statement; - if (statement != null) { - statement.setParent(this); - statement.setPropertyInParent(INIT_STATEMENT); - statement = null; + assertNotFrozen(); + this.initStatement = statement; + if (statement != null) { + statement.setParent(this); + statement.setPropertyInParent(INIT_STATEMENT); + statement = null; } } @Override public IScope getScope() { if (scope == null) - scope = new CPPBlockScope(this); - return scope; - } + scope = new CPPBlockScope(this); + return scope; + } @Override public ICPPExecution getExecution() { @@ -274,9 +277,12 @@ public class CPPASTIfStatement extends CPPASTAttributeOwner implements ICPPASTIf ICPPASTExpression conditionExpr = (ICPPASTExpression) getConditionExpression(); ICPPExecutionOwner conditionDecl = (ICPPExecutionOwner) getConditionDeclaration(); ICPPEvaluation conditionExprEval = conditionExpr != null ? conditionExpr.getEvaluation() : null; - ExecSimpleDeclaration conditionDeclExec = conditionDecl != null ? (ExecSimpleDeclaration) conditionDecl.getExecution() : null; + ExecSimpleDeclaration conditionDeclExec = conditionDecl != null + ? (ExecSimpleDeclaration) conditionDecl.getExecution() + : null; ICPPExecution thenClauseExec = EvalUtil.getExecutionFromStatement(getThenClause()); ICPPExecution elseClauseExec = EvalUtil.getExecutionFromStatement(getElseClause()); - return new ExecIf(isConstexpr, initStmtExec, conditionExprEval, conditionDeclExec, thenClauseExec, elseClauseExec); + return new ExecIf(isConstexpr, initStmtExec, conditionExprEval, conditionDeclExec, thenClauseExec, + elseClauseExec); } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitDestructorName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitDestructorName.java index d312cb9de4e..71916bc94bd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitDestructorName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitDestructorName.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitDestructorNameOwner; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; - public class CPPASTImplicitDestructorName extends CPPASTImplicitName implements IASTImplicitDestructorName { private final IASTName constructionPoint; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitName.java index 88948324bb4..e8d638ce2b9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTImplicitName.java @@ -67,19 +67,23 @@ public class CPPASTImplicitName extends CPPASTName implements IASTImplicitName { @Override public boolean accept(ASTVisitor action) { - if ((!alternate && action.shouldVisitImplicitNames) || - (alternate && action.shouldVisitImplicitNameAlternates)) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - } - - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - } - } - return true; + if ((!alternate && action.shouldVisitImplicitNames) + || (alternate && action.shouldVisitImplicitNameAlternates)) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } + + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } + } + return true; } @Override @@ -98,7 +102,7 @@ public class CPPASTImplicitName extends CPPASTName implements IASTImplicitName { } public void setIsDefinition(boolean val) { - isDefinition= val; + isDefinition = val; } /** @@ -119,9 +123,8 @@ public class CPPASTImplicitName extends CPPASTName implements IASTImplicitName { offset += ((ASTNode) relativeNode).getLength(); OverloadableOperator oo = OverloadableOperator.valueOf(first); - if ((first.getNext() == null && oo != null) || - Arrays.equals(first.getCharImage(), Keywords.cDELETE) || - Arrays.equals(first.getCharImage(), Keywords.cNEW)) { + if ((first.getNext() == null && oo != null) || Arrays.equals(first.getCharImage(), Keywords.cDELETE) + || Arrays.equals(first.getCharImage(), Keywords.cNEW)) { int length = first.getLength(); setOffsetAndLength(offset, length); } else { @@ -134,7 +137,7 @@ public class CPPASTImplicitName extends CPPASTName implements IASTImplicitName { setOffsetAndLength(parent.getOffset() + parent.getLength(), 0); } } - } + } // Fallback algorithm to use in computeOperatorOffsets() when the operator is // in a macro expansion. @@ -151,23 +154,19 @@ public class CPPASTImplicitName extends CPPASTName implements IASTImplicitName { ASTNodeSearch visitor = new ASTNodeSearch(relativeNode); IASTNode sibling = trailing ? visitor.findRightSibling() : visitor.findLeftSibling(); IASTNode parent = sibling == null ? relativeNode.getParent() : null; - if (!((sibling == null || sibling instanceof ASTNode) && - (parent == null || parent instanceof ASTNode))) { + if (!((sibling == null || sibling instanceof ASTNode) && (parent == null || parent instanceof ASTNode))) { return false; } ASTNode sib = (ASTNode) sibling; ASTNode par = (ASTNode) parent; @SuppressWarnings("null") int start = trailing ? relative.getOffset() + relative.getLength() - : sib != null ? sib.getOffset() + sib.getLength() - : par.getOffset(); - @SuppressWarnings("null") - int end = trailing ? sib != null ? sib.getOffset() - : par.getOffset() + par.getLength() - : relative.getOffset(); - - // If there is only one token within the bounds, it must be the - // operator token, and we have our answer. + : sib != null ? sib.getOffset() + sib.getLength() : par.getOffset(); + @SuppressWarnings("null") + int end = trailing ? sib != null ? sib.getOffset() : par.getOffset() + par.getLength() : relative.getOffset(); + + // If there is only one token within the bounds, it must be the + // operator token, and we have our answer. if (end == start + 1) { setOffsetAndLength(start, 1); return true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInactiveCompletionName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInactiveCompletionName.java index f2e55d02671..bb7e6a61414 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInactiveCompletionName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInactiveCompletionName.java @@ -23,12 +23,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; public class CPPASTInactiveCompletionName extends CPPASTName implements IASTInactiveCompletionName { private IASTTranslationUnit fAst; - + public CPPASTInactiveCompletionName(char[] name, IASTTranslationUnit ast) { super(name); fAst = ast; } - + @Override public IASTCompletionContext getCompletionContext() { return this; @@ -37,7 +37,7 @@ public class CPPASTInactiveCompletionName extends CPPASTName implements IASTInac @Override public IBinding[] findBindings(IASTName name, boolean isPrefix) { // 'name' (which is the same as 'this') is not hooked up to the AST, but it - // does have a location (offset and length) which we use to compute the + // does have a location (offset and length) which we use to compute the // containing scope. IASTNodeSelector sel = fAst.getNodeSelector(null); IASTNode node = sel.findEnclosingNode(getOffset(), getLength()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java index 53f4caeec5f..d0292ac7ad2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; @Deprecated public class CPPASTInitializerExpression extends CPPASTEqualsInitializer implements IASTInitializerExpression { - public CPPASTInitializerExpression() { + public CPPASTInitializerExpression() { } public CPPASTInitializerExpression(IASTExpression expression) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java index 098c2b86353..9c6429d5d75 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java @@ -33,8 +33,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalInitList; public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializerList, IASTAmbiguityParent { private static final ICPPASTInitializerClause[] NO_CLAUSES = {}; private ICPPASTInitializerClause[] initializers; - private int initializersPos= -1; - private int actualSize; + private int initializersPos = -1; + private int actualSize; private boolean fIsPackExpansion; private ICPPEvaluation fEvaluation; @@ -70,20 +70,20 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer @Override @Deprecated public IASTInitializer[] getInitializers() { - IASTInitializerClause[] clauses= getClauses(); + IASTInitializerClause[] clauses = getClauses(); if (clauses.length == 0) return IASTInitializer.EMPTY_INITIALIZER_ARRAY; - IASTInitializer[] inits= new IASTInitializer[clauses.length]; + IASTInitializer[] inits = new IASTInitializer[clauses.length]; for (int i = 0; i < inits.length; i++) { - IASTInitializerClause clause= clauses[i]; + IASTInitializerClause clause = clauses[i]; if (clause instanceof IASTInitializer) { - inits[i]= (IASTInitializer) clause; + inits[i] = (IASTInitializer) clause; } else if (clause instanceof IASTExpression) { final CPPASTEqualsInitializer initExpr = new CPPASTEqualsInitializer(((IASTExpression) clause).copy()); initExpr.setParent(this); initExpr.setPropertyInParent(NESTED_INITIALIZER); - inits[i]= initExpr; + inits[i] = initExpr; } } return inits; @@ -91,36 +91,40 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer @Override public void addClause(IASTInitializerClause d) { - assertNotFrozen(); - if (d != null) { - initializers = ArrayUtil.appendAt(ICPPASTInitializerClause.class, initializers, ++initializersPos, (ICPPASTInitializerClause) d); - d.setParent(this); + assertNotFrozen(); + if (d != null) { + initializers = ArrayUtil.appendAt(ICPPASTInitializerClause.class, initializers, ++initializersPos, + (ICPPASTInitializerClause) d); + d.setParent(this); d.setPropertyInParent(NESTED_INITIALIZER); - } - actualSize++; - } + } + actualSize++; + } @Override @Deprecated public void addInitializer(IASTInitializer d) { - assertNotFrozen(); - if (d instanceof IASTInitializerClause) { - addClause((IASTInitializerClause) d); - } else if (d instanceof IASTEqualsInitializer) { - addClause(((IASTEqualsInitializer) d).getInitializerClause()); - } else { - addClause(null); - } - } - - @Override + assertNotFrozen(); + if (d instanceof IASTInitializerClause) { + addClause((IASTInitializerClause) d); + } else if (d instanceof IASTEqualsInitializer) { + addClause(((IASTEqualsInitializer) d).getInitializerClause()); + } else { + addClause(null); + } + } + + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitInitializers) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } IASTInitializerClause[] list = getClauses(); for (IASTInitializerClause clause : list) { @@ -132,7 +136,7 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer return false; return true; - } + } @Override public boolean isPackExpansion() { @@ -142,7 +146,7 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer @Override public void setIsPackExpansion(boolean val) { assertNotFrozen(); - fIsPackExpansion= val; + fIsPackExpansion = val; } @Override @@ -161,15 +165,15 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) - fEvaluation= createEvaluation(); + fEvaluation = createEvaluation(); return fEvaluation; } private ICPPEvaluation createEvaluation() { final ICPPASTInitializerClause[] clauses = getClauses(); - ICPPEvaluation[] evals= new ICPPEvaluation[clauses.length]; + ICPPEvaluation[] evals = new ICPPEvaluation[clauses.length]; for (int i = 0; i < evals.length; i++) { - evals[i]= clauses[i].getEvaluation(); + evals[i] = clauses[i].getEvaluation(); } return new EvalInitList(evals, this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java index 04526a15729..9adc8bdf994 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java @@ -24,10 +24,10 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; * @author jcamelon */ public class CPPASTLabelStatement extends CPPASTAttributeOwner implements IASTLabelStatement { - private IASTName name; - private IASTStatement nestedStatement; + private IASTName name; + private IASTStatement nestedStatement; - public CPPASTLabelStatement() { + public CPPASTLabelStatement() { } public CPPASTLabelStatement(IASTName name, IASTStatement nestedStatement) { @@ -50,72 +50,82 @@ public class CPPASTLabelStatement extends CPPASTAttributeOwner implements IASTLa @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (name != null && !name.accept(action)) return false; - if (nestedStatement != null && !nestedStatement.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; + if (nestedStatement != null && !nestedStatement.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (n == name) return r_declaration; + if (n == name) + return r_declaration; return r_unclear; } - @Override + @Override public IASTStatement getNestedStatement() { - return nestedStatement; - } + return nestedStatement; + } - @Override + @Override public void setNestedStatement(IASTStatement s) { - assertNotFrozen(); - nestedStatement = s; - if (s != null) { + assertNotFrozen(); + nestedStatement = s; + if (s != null) { s.setParent(this); s.setPropertyInParent(NESTED_STATEMENT); } - } + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == nestedStatement) { - other.setParent(this); - other.setPropertyInParent(child.getPropertyInParent()); - setNestedStatement((IASTStatement) other); - return; - } - super.replace(child, other); - } + if (child == nestedStatement) { + other.setParent(this); + other.setPropertyInParent(child.getPropertyInParent()); + setNestedStatement((IASTStatement) other); + return; + } + super.replace(child, other); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java index 54377d0f4f5..e1caa004fd8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLambdaExpression.java @@ -49,7 +49,7 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr private ICPPEvaluation fEvaluation; public CPPASTLambdaExpression() { - fCaptureDefault= CaptureDefault.UNSPECIFIED; + fCaptureDefault = CaptureDefault.UNSPECIFIED; } @Override @@ -81,36 +81,36 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr @Override public IASTImplicitName getClosureTypeName() { if (fClosureTypeName == null) { - final CPPClosureType closureType = getExpressionType(); + final CPPClosureType closureType = getExpressionType(); CPPASTImplicitName name = new CPPASTImplicitName(closureType.getNameCharArray(), this); name.setBinding(closureType); name.setIsDefinition(true); name.setOffsetAndLength(getOffset(), 1); - fClosureTypeName= name; - } + fClosureTypeName = name; + } return fClosureTypeName; } @Override public IASTImplicitName getFunctionCallOperatorName() { if (fImplicitFunctionCallName == null) { - final CPPClosureType closureType = getExpressionType(); - ICPPFunction callOperator= closureType.getFunctionCallOperator(); + final CPPClosureType closureType = getExpressionType(); + ICPPFunction callOperator = closureType.getFunctionCallOperator(); CPPASTImplicitName name = new CPPASTImplicitName(closureType.getNameCharArray(), this); name.setBinding(callOperator); name.setIsDefinition(true); if (fBody instanceof ASTNode) { - ASTNode bodyNode= (ASTNode) fBody; + ASTNode bodyNode = (ASTNode) fBody; name.setOffsetAndLength(bodyNode.getOffset(), 1); } - fImplicitFunctionCallName= name; - } + fImplicitFunctionCallName = name; + } return fImplicitFunctionCallName; } - + private IASTImplicitName getConversionOperatorName() { if (fImplicitConversionOperatorName == null) { final CPPClosureType closureType = getExpressionType(); @@ -119,7 +119,7 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr CPPASTImplicitName name = new CPPASTImplicitName(closureType.getNameCharArray(), this); name.setBinding(conversionOperator); name.setIsDefinition(true); - + if (fBody instanceof ASTNode) { name.setOffsetAndLength(((ASTNode) fBody).getOffset(), 1); } @@ -129,14 +129,14 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr return fImplicitConversionOperatorName; } - @Override + @Override public IASTImplicitName[] getImplicitNames() { - IASTImplicitName conversionOperatorName = getConversionOperatorName(); - if (conversionOperatorName == null) { - return new IASTImplicitName[] { getFunctionCallOperatorName() }; - } - return new IASTImplicitName[] { getFunctionCallOperatorName(), getConversionOperatorName() }; - } + IASTImplicitName conversionOperatorName = getConversionOperatorName(); + if (conversionOperatorName == null) { + return new IASTImplicitName[] { getFunctionCallOperatorName() }; + } + return new IASTImplicitName[] { getFunctionCallOperatorName(), getConversionOperatorName() }; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -145,12 +145,15 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr @Override public boolean accept(ASTVisitor visitor) { - if (visitor.shouldVisitExpressions) { - switch (visitor.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (visitor.shouldVisitExpressions) { + switch (visitor.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (visitor.shouldVisitImplicitNames && !getClosureTypeName().accept(visitor)) @@ -179,8 +182,8 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr if (visitor.shouldVisitExpressions && visitor.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public IASTCompoundStatement getBody() { @@ -196,7 +199,7 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr public ICPPASTCapture[] getCaptures() { if (fCaptures == null) return NO_CAPTURES; - return fCaptures= ArrayUtil.trim(fCaptures); + return fCaptures = ArrayUtil.trim(fCaptures); } @Override @@ -210,9 +213,9 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr capture.setParent(this); capture.setPropertyInParent(CAPTURE); if (fCaptures == null) { - fCaptures= new ICPPASTCapture[] {capture, null}; + fCaptures = new ICPPASTCapture[] { capture, null }; } else { - fCaptures= ArrayUtil.append(fCaptures, capture); + fCaptures = ArrayUtil.append(fCaptures, capture); } } @@ -221,12 +224,12 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr assertNotFrozen(); body.setParent(this); body.setPropertyInParent(BODY); - fBody= body; + fBody = body; } @Override public void setCaptureDefault(CaptureDefault value) { - fCaptureDefault= value; + fCaptureDefault = value; } @Override @@ -234,20 +237,20 @@ public class CPPASTLambdaExpression extends ASTNode implements ICPPASTLambdaExpr assertNotFrozen(); dtor.setParent(this); dtor.setPropertyInParent(DECLARATOR); - fDeclarator= dtor; + fDeclarator = dtor; } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { - fEvaluation= new EvalFixed(new CPPClosureType(this), PRVALUE, IntegralValue.UNKNOWN); + fEvaluation = new EvalFixed(new CPPClosureType(this), PRVALUE, IntegralValue.UNKNOWN); } return fEvaluation; } @Override public CPPClosureType getExpressionType() { - return (CPPClosureType) CPPEvaluation.getType(this); + return (CPPClosureType) CPPEvaluation.getType(this); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java index 5fde344dcb8..44af3bb2250 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java @@ -25,14 +25,13 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Extern "C" construct. */ -public class CPPASTLinkageSpecification extends ASTNode - implements ICPPASTLinkageSpecification, IASTAmbiguityParent { - private String fLiteral; +public class CPPASTLinkageSpecification extends ASTNode implements ICPPASTLinkageSpecification, IASTAmbiguityParent { + private String fLiteral; private IASTDeclaration[] fAllDeclarations; private IASTDeclaration[] fActiveDeclarations; - private int fLastDeclaration = -1; + private int fLastDeclaration = -1; - public CPPASTLinkageSpecification() { + public CPPASTLinkageSpecification() { } public CPPASTLinkageSpecification(String literal) { @@ -55,14 +54,14 @@ public class CPPASTLinkageSpecification extends ASTNode @Override public String getLiteral() { - return fLiteral; - } + return fLiteral; + } - @Override + @Override public void setLiteral(String value) { - assertNotFrozen(); - this.fLiteral = value; - } + assertNotFrozen(); + this.fLiteral = value; + } @Override public final void addDeclaration(IASTDeclaration decl) { @@ -70,16 +69,16 @@ public class CPPASTLinkageSpecification extends ASTNode decl.setParent(this); decl.setPropertyInParent(OWNED_DECLARATION); fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl); - fActiveDeclarations= null; + fActiveDeclarations = null; } } @Override public final IASTDeclaration[] getDeclarations() { - IASTDeclaration[] active= fActiveDeclarations; + IASTDeclaration[] active = fActiveDeclarations; if (active == null) { - active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fLastDeclaration+1); - fActiveDeclarations= active; + active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fLastDeclaration + 1); + fActiveDeclarations = active; } return active; } @@ -87,35 +86,38 @@ public class CPPASTLinkageSpecification extends ASTNode @Override public final IASTDeclaration[] getDeclarations(boolean includeInactive) { if (includeInactive) { - fAllDeclarations= ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration); + fAllDeclarations = ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration); return fAllDeclarations; } return getDeclarations(); } - - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclarations) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } IASTDeclaration[] decls = getDeclarations(action.includeInactiveNodes); for (IASTDeclaration decl : decls) { - if (!decl.accept(action)) return false; + if (!decl.accept(action)) + return false; } if (action.shouldVisitDeclarations && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } - @Override + @Override public final void replace(IASTNode child, IASTNode other) { assert child.isActive() == other.isActive(); for (int i = 0; i <= fLastDeclaration; ++i) { @@ -123,7 +125,7 @@ public class CPPASTLinkageSpecification extends ASTNode other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); fAllDeclarations[i] = (IASTDeclaration) other; - fActiveDeclarations= null; + fActiveDeclarations = null; return; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java index c22b037d615..00af41d0976 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java @@ -58,15 +58,18 @@ import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalExce */ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralExpression { private static final EvalFixed EVAL_TRUE = new EvalFixed(CPPBasicType.BOOLEAN, PRVALUE, IntegralValue.create(true)); - private static final EvalFixed EVAL_FALSE = new EvalFixed(CPPBasicType.BOOLEAN, PRVALUE, IntegralValue.create(false)); - private static final EvalFixed EVAL_NULL_PTR = new EvalFixed(CPPBasicType.NULL_PTR, PRVALUE, IntegralValue.create(0)); + private static final EvalFixed EVAL_FALSE = new EvalFixed(CPPBasicType.BOOLEAN, PRVALUE, + IntegralValue.create(false)); + private static final EvalFixed EVAL_NULL_PTR = new EvalFixed(CPPBasicType.NULL_PTR, PRVALUE, + IntegralValue.create(0)); - public static final CPPASTLiteralExpression INT_ZERO = new CPPASTLiteralExpression(lk_integer_constant, new char[] {'0'}); + public static final CPPASTLiteralExpression INT_ZERO = new CPPASTLiteralExpression(lk_integer_constant, + new char[] { '0' }); private int fKind; /** * The value of a CPPASTLiteralExpression consists of a literal and a suffix. - * + * * E.g. 1f -> literal: 1 suffix: f * 1ull -> literal: 1 suffix: ull * 10.0_udl -> literal: 10.0 suffix: _udl @@ -77,7 +80,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx private char[] fSuffix; private final char[] fNumericCompilerSuffixes; - private int fStringLiteralSize; // Accounting for escape sequences and the null terminator. + private int fStringLiteralSize; // Accounting for escape sequences and the null terminator. private ICPPEvaluation fEvaluation; private IBinding fUserDefinedLiteralOperator; private IASTImplicitName[] fImplicitNames; @@ -139,7 +142,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx /** * Sets the kind, suffix and literal fields of this expression. - * + * * @param kind the kind of this literal expression * @param value the value of this literal expression, * this gets split into a literal and a suffix @@ -150,10 +153,10 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx fLiteral = getLiteral(value, fSuffix); resetLazyFields(); } - + /** * Adds a suffix to this literal expression. - * + * * @param suffix the suffix to be added. */ public void setSuffix(char[] suffix) { @@ -233,26 +236,33 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx * treated as the latter" */ if (len == 1) { - switch(fSuffix[0]) { - case 'u': case 'U': - case 'f': case 'F': - case 'l': case 'L': + switch (fSuffix[0]) { + case 'u': + case 'U': + case 'f': + case 'F': + case 'l': + case 'L': return true; } } if (len == 2) { - switch(fSuffix[0]) { - case 'u': case 'U': + switch (fSuffix[0]) { + case 'u': + case 'U': return Character.toLowerCase(fSuffix[1]) == 'l'; - case 'l': case 'L': + case 'l': + case 'L': return Character.toLowerCase(fSuffix[1]) == 'l' || Character.toLowerCase(fSuffix[1]) == 'u'; } } if (len == 3) { - switch(fSuffix[0]) { - case 'u': case 'U': + switch (fSuffix[0]) { + case 'u': + case 'U': return Character.toLowerCase(fSuffix[1]) == 'l' && Character.toLowerCase(fSuffix[2]) == 'l'; - case 'l': case 'L': + case 'l': + case 'L': return Character.toLowerCase(fSuffix[1]) == 'l' && Character.toLowerCase(fSuffix[2]) == 'u'; } } @@ -273,23 +283,30 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx public boolean accept(ASTVisitor action) { if (action.shouldVisitExpressions) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } if (action.shouldVisitImplicitNames) { for (IASTImplicitName name : getImplicitNames()) { - if (!name.accept(action)) return false; + if (!name.accept(action)) + return false; } } if (action.shouldVisitExpressions) { switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } return true; @@ -305,7 +322,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx // Skip past a prefix affecting the character type. if (fLiteral[0] == 'L' || fLiteral[0] == 'u' || fLiteral[0] == 'U') { - if(fLiteral[1] == '8') { + if (fLiteral[1] == '8') { ++start; } ++start; @@ -435,10 +452,12 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx if (hasSuffix()) { if (hasNumericSuffix()) { switch (fSuffix[0]) { - case 'f': case 'F': + case 'f': + case 'F': kind = Kind.eFloat; break; - case 'l': case 'L': + case 'l': + case 'L': flags |= IBasicType.IS_LONG; break; } @@ -446,7 +465,8 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx IType type = getUserDefinedLiteralOperatorType(); if (type instanceof IProblemType && hasNumericCompilerSuffix()) { switch (fSuffix[0]) { - case 'i': case 'j': + case 'i': + case 'j': flags |= IBasicType.IS_IMAGINARY; break; } @@ -467,10 +487,12 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx int makelong = 0; for (char c : fSuffix) { switch (c) { - case 'u': case 'U': + case 'u': + case 'U': flags |= IBasicType.IS_UNSIGNED; break; - case 'l': case 'L': + case 'l': + case 'L': makelong++; break; } @@ -484,7 +506,8 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx IType type = getUserDefinedLiteralOperatorType(); if (type instanceof IProblemType && hasNumericCompilerSuffix()) { switch (fSuffix[0]) { - case 'i': case 'j': + case 'i': + case 'j': flags |= IBasicType.IS_IMAGINARY; break; } @@ -508,8 +531,14 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx return probablyHex(value, i); case 'b': return probablyBinary(value, i); - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': /* octal-literal: * 0 * octal-literal octal-digit @@ -774,7 +803,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx int paramCount = params.length; if (paramCount == 0) { // TODO: Support literal operator templates. - args = new ICPPEvaluation[]{op}; + args = new ICPPEvaluation[] { op }; } else if (paramCount == 1) { //this means that we need to fall back to the raw literal operator if (params[0].getType() instanceof IPointerType) { @@ -787,16 +816,16 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx IType type = new CPPBasicType(Kind.eChar, 0, this); type = new CPPQualifierType(type, true, false); - type = new CPPArrayType(type, IntegralValue.create(numLen+1)); + type = new CPPArrayType(type, IntegralValue.create(numLen + 1)); EvalFixed strEval = new EvalFixed(type, LVALUE, CStringValue.create(strValue)); - args = new ICPPEvaluation[]{op, strEval}; + args = new ICPPEvaluation[] { op, strEval }; } else { - args = new ICPPEvaluation[]{op, literalEval}; + args = new ICPPEvaluation[] { op, literalEval }; } } else if (paramCount == 2) { IValue sizeValue = IntegralValue.create(computeStringLiteralSize() - 1); EvalFixed literalSizeEval = new EvalFixed(CPPBasicType.INT, PRVALUE, sizeValue); - args = new ICPPEvaluation[]{op, literalEval, literalSizeEval}; + args = new ICPPEvaluation[] { op, literalEval, literalSizeEval }; } return new EvalFunctionCall(args, null, this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java index 29a319b72c8..9dbafd7a5f7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java @@ -37,19 +37,19 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * Unqualified name, also base class for operator and conversion name. */ public class CPPASTName extends CPPASTNameBase implements ICPPASTCompletionContext { - public static final IASTName NOT_INITIALIZED= new CPPASTName(null); + public static final IASTName NOT_INITIALIZED = new CPPASTName(null); private char[] name; - public CPPASTName(char[] name) { - this.name = name; - } + public CPPASTName(char[] name) { + this.name = name; + } - public CPPASTName() { - name = CharArrayUtils.EMPTY; - } + public CPPASTName() { + name = CharArrayUtils.EMPTY; + } - @Override + @Override public CPPASTName copy() { return copy(CopyStyle.withoutLocations); } @@ -70,20 +70,20 @@ public class CPPASTName extends CPPASTNameBase implements ICPPASTCompletionConte } } - @Override + @Override public IASTCompletionContext getCompletionContext() { - IASTNode node = getParent(); - while (node != null) { - if (node instanceof IASTCompletionContext) { - return (IASTCompletionContext) node; - } - node = node.getParent(); - } - if (getLength() > 0) { - return this; - } - return null; - } + IASTNode node = getParent(); + while (node != null) { + if (node instanceof IASTCompletionContext) { + return (IASTCompletionContext) node; + } + node = node.getParent(); + } + if (getLength() > 0) { + return this; + } + return null; + } @Override public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) { @@ -112,32 +112,32 @@ public class CPPASTName extends CPPASTNameBase implements ICPPASTCompletionConte } } else if (bindings.length == 0) { // The lookup did not find the binding that is defined by this name. - bindings= new IBinding[] { n.resolveBinding() }; + bindings = new IBinding[] { n.resolveBinding() }; } return ArrayUtil.removeNulls(IBinding.class, bindings); } return null; } - private IBinding[] filterByElaboratedTypeSpecifier(int kind, IBinding[] bindings) { + private IBinding[] filterByElaboratedTypeSpecifier(int kind, IBinding[] bindings) { for (int i = 0; i < bindings.length; i++) { IBinding binding = bindings[i]; if (binding instanceof ICPPClassType) { if (((ICPPClassType) binding).getKey() != kind) bindings[i] = null; } else if (!(binding instanceof ICPPNamespace)) { - bindings[i]= null; + bindings[i] = null; } } return ArrayUtil.removeNulls(IBinding.class, bindings); } - @Override + @Override public char[] toCharArray() { - return name; - } + return name; + } - @Override + @Override public final char[] getSimpleID() { return name; } @@ -148,35 +148,35 @@ public class CPPASTName extends CPPASTNameBase implements ICPPASTCompletionConte } public void setName(char[] name) { - assertNotFrozen(); - this.name = name; - } + assertNotFrozen(); + this.name = name; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitNames) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } - - if (action.shouldVisitNames) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } - return true; - } + if (action.shouldVisitNames) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + if (action.shouldVisitNames) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } @Override public IBinding[] findBindings(IASTName n, boolean isPrefix) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java index c9b813aed7d..b60d9905e17 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java @@ -44,9 +44,10 @@ public abstract class CPPASTNameBase extends ASTNode implements ICPPASTName { */ public static boolean sAllowRecursionBindings = true; public static boolean sAllowNameComputation = true; - private static final byte MAX_RESOLUTION_DEPTH= 6; + private static final byte MAX_RESOLUTION_DEPTH = 6; - protected final static class RecursionResolvingBinding extends ProblemBinding implements IRecursionResolvingBinding { + protected final static class RecursionResolvingBinding extends ProblemBinding + implements IRecursionResolvingBinding { public RecursionResolvingBinding(IASTName node, char[] arg) { super(node, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, arg); Assert.isTrue(sAllowRecursionBindings, getMessage()); @@ -64,7 +65,7 @@ public abstract class CPPASTNameBase extends ASTNode implements ICPPASTName { // resolution to build an argument string if one wasn't provided in the // ProblemBinding constructor. To break the recursion in a case // like, this we provide the argument string "(unknown)" instead. - char[] args = (fResolutionDepth > MAX_RESOLUTION_DEPTH + 1) ? "(unknown)".toCharArray() : null; //$NON-NLS-1$ + char[] args = (fResolutionDepth > MAX_RESOLUTION_DEPTH + 1) ? "(unknown)".toCharArray() : null; //$NON-NLS-1$ return new RecursionResolvingBinding(this, args); } @@ -90,83 +91,83 @@ public abstract class CPPASTNameBase extends ASTNode implements ICPPASTName { */ @Override public IBinding resolvePreBinding() { - if (fBinding == null) { - if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { - setBinding(createRecursionResolvingBinding()); - } else { - setBinding(createIntermediateBinding()); - } - } - return fBinding; + if (fBinding == null) { + if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { + setBinding(createRecursionResolvingBinding()); + } else { + setBinding(createIntermediateBinding()); + } + } + return fBinding; } - @Override + @Override public IBinding resolveBinding() { - if (fBinding == null) { - if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { - setBinding(createRecursionResolvingBinding()); - } else { - fIsFinal= false; - final IBinding b= createIntermediateBinding(); - if (b instanceof ProblemBinding) { - ProblemBinding pb= (ProblemBinding) b; - final IASTNode node= pb.getASTNode(); - if (node == null || node.getParent() == null) { - pb.setASTNode(this); - } - } - setBinding(b); - } - } - if (!fIsFinal) - resolveFinalBinding(this); + if (fBinding == null) { + if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { + setBinding(createRecursionResolvingBinding()); + } else { + fIsFinal = false; + final IBinding b = createIntermediateBinding(); + if (b instanceof ProblemBinding) { + ProblemBinding pb = (ProblemBinding) b; + final IASTNode node = pb.getASTNode(); + if (node == null || node.getParent() == null) { + pb.setASTNode(this); + } + } + setBinding(b); + } + } + if (!fIsFinal) + resolveFinalBinding(this); - return fBinding; - } + return fBinding; + } - /** - * If this name has not yet been resolved at all, <code>null</code> will be returned. - * Otherwise the intermediate or final binding for this name is returned. - * @see ICPPTwoPhaseBinding - */ - @Override + /** + * If this name has not yet been resolved at all, <code>null</code> will be returned. + * Otherwise the intermediate or final binding for this name is returned. + * @see ICPPTwoPhaseBinding + */ + @Override public IBinding getPreBinding() { - return fBinding; - } + return fBinding; + } - /** - * If this name has not yet been resolved at all, <code>null</code> will be returned. - * Otherwise the final binding for this name is returned. - * @see ICPPTwoPhaseBinding - */ - @Override + /** + * If this name has not yet been resolved at all, <code>null</code> will be returned. + * Otherwise the final binding for this name is returned. + * @see ICPPTwoPhaseBinding + */ + @Override public IBinding getBinding() { - final IBinding cand= fBinding; - if (cand == null) - return null; + final IBinding cand = fBinding; + if (cand == null) + return null; - if (!fIsFinal) - resolveFinalBinding(this); + if (!fIsFinal) + resolveFinalBinding(this); - return fBinding; - } + return fBinding; + } private void resolveFinalBinding(CPPASTNameBase astName) { if (fBinding instanceof ICPPTwoPhaseBinding) { - ICPPTwoPhaseBinding intermediateBinding= (ICPPTwoPhaseBinding) fBinding; - if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { - setBinding(createRecursionResolvingBinding()); - } else { - setBinding(intermediateBinding.resolveFinalBinding(astName)); - } - } - fIsFinal= true; + ICPPTwoPhaseBinding intermediateBinding = (ICPPTwoPhaseBinding) fBinding; + if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { + setBinding(createRecursionResolvingBinding()); + } else { + setBinding(intermediateBinding.resolveFinalBinding(astName)); + } + } + fIsFinal = true; } @Override public void setBinding(IBinding binding) { - fBinding= binding; - fResolutionDepth= 0; + fBinding = binding; + fResolutionDepth = 0; } @Override @@ -176,9 +177,9 @@ public abstract class CPPASTNameBase extends ASTNode implements ICPPASTName { @Override public boolean isQualified() { - IASTNode parent= getParent(); + IASTNode parent = getParent(); if (parent instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qn= (ICPPASTQualifiedName) parent; + ICPPASTQualifiedName qn = (ICPPASTQualifiedName) parent; if (qn.isFullyQualified()) return true; ICPPASTNameSpecifier[] qualifier = qn.getQualifier(); @@ -196,64 +197,64 @@ public abstract class CPPASTNameBase extends ASTNode implements ICPPASTName { @Override public IASTCompletionContext getCompletionContext() { - IASTNode node = getParent(); - while (node != null) { - if (node instanceof IASTCompletionContext) { - return (IASTCompletionContext) node; - } - node = node.getParent(); - } + IASTNode node = getParent(); + while (node != null) { + if (node instanceof IASTCompletionContext) { + return (IASTCompletionContext) node; + } + node = node.getParent(); + } - return null; + return null; } @Override public int getRoleOfName(boolean allowResolution) { - IASTNode parent = getParent(); - if (parent instanceof IASTInternalNameOwner) { - return ((IASTInternalNameOwner) parent).getRoleForName(this, allowResolution); - } - if (parent instanceof IASTNameOwner) { - return ((IASTNameOwner) parent).getRoleForName(this); - } - return IASTNameOwner.r_unclear; + IASTNode parent = getParent(); + if (parent instanceof IASTInternalNameOwner) { + return ((IASTInternalNameOwner) parent).getRoleForName(this, allowResolution); + } + if (parent instanceof IASTNameOwner) { + return ((IASTNameOwner) parent).getRoleForName(this); + } + return IASTNameOwner.r_unclear; } - @Override + @Override public boolean isDeclaration() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - switch (role) { - case IASTNameOwner.r_reference: - case IASTNameOwner.r_unclear: - return false; - default: - return true; - } - } - return false; - } + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + case IASTNameOwner.r_unclear: + return false; + default: + return true; + } + } + return false; + } - @Override + @Override public boolean isReference() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - return role == IASTNameOwner.r_reference; - } - return false; - } + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + return role == IASTNameOwner.r_reference; + } + return false; + } - @Override + @Override public boolean isDefinition() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - return role == IASTNameOwner.r_definition; - } - return false; - } + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + return role == IASTNameOwner.r_definition; + } + return false; + } @Override public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java index 5b44067cc4c..abb9b12da5e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java @@ -31,10 +31,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTNamedTypeSpecifier, ICPPASTCompletionContext { - private boolean typename; - private IASTName name; + private boolean typename; + private IASTName name; - public CPPASTNamedTypeSpecifier() { + public CPPASTNamedTypeSpecifier() { } public CPPASTNamedTypeSpecifier(IASTName name) { @@ -48,66 +48,65 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier @Override public CPPASTNamedTypeSpecifier copy(CopyStyle style) { - CPPASTNamedTypeSpecifier copy = - new CPPASTNamedTypeSpecifier(name == null ? null : name.copy(style)); + CPPASTNamedTypeSpecifier copy = new CPPASTNamedTypeSpecifier(name == null ? null : name.copy(style)); copy.typename = typename; return super.copy(copy, style); } @Override public boolean isTypename() { - return typename; - } + return typename; + } - @Override + @Override public void setIsTypename(boolean value) { - assertNotFrozen(); - typename = value; - } + assertNotFrozen(); + typename = value; + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (name != null && !name.accept(action)) - return false; - - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } + if (name != null && !name.accept(action)) + return false; + + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -123,11 +122,8 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier int j = 0; for (int i = 0; i < bindings.length; i++) { IBinding binding = bindings[i]; - if (binding instanceof ICPPClassType - || binding instanceof IEnumeration - || binding instanceof ICPPNamespace - || binding instanceof ITypedef - || binding instanceof ICPPAliasTemplate + if (binding instanceof ICPPClassType || binding instanceof IEnumeration || binding instanceof ICPPNamespace + || binding instanceof ITypedef || binding instanceof ICPPAliasTemplate || binding instanceof ICPPTemplateTypeParameter) { if (i != j) bindings[j] = binding; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java index b9b7a8ecc81..bd400bff3fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java @@ -22,8 +22,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ public class CPPASTNamespaceAlias extends ASTNode implements ICPPASTNamespaceAlias { - private IASTName alias; - private IASTName qualifiedName; + private IASTName alias; + private IASTName qualifiedName; public CPPASTNamespaceAlias(IASTName alias, IASTName qualifiedName) { setAlias(alias); @@ -37,69 +37,78 @@ public class CPPASTNamespaceAlias extends ASTNode implements ICPPASTNamespaceAli @Override public CPPASTNamespaceAlias copy(CopyStyle style) { - CPPASTNamespaceAlias copy = new CPPASTNamespaceAlias( - alias == null ? null : alias.copy(style), + CPPASTNamespaceAlias copy = new CPPASTNamespaceAlias(alias == null ? null : alias.copy(style), qualifiedName == null ? null : qualifiedName.copy(style)); return copy(copy, style); } @Override public IASTName getAlias() { - return alias; - } + return alias; + } - @Override + @Override public void setAlias(IASTName name) { - assertNotFrozen(); - this.alias = name; - if (name != null) { + assertNotFrozen(); + this.alias = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(ALIAS_NAME); } - } + } - @Override + @Override public IASTName getMappingName() { - return qualifiedName; - } + return qualifiedName; + } - @Override + @Override public void setMappingName(IASTName qualifiedName) { - assertNotFrozen(); - this.qualifiedName = qualifiedName; - if (qualifiedName != null) { + assertNotFrozen(); + this.qualifiedName = qualifiedName; + if (qualifiedName != null) { qualifiedName.setParent(this); qualifiedName.setPropertyInParent(MAPPING_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (alias != null && !alias.accept(action)) return false; - if (qualifiedName != null && !qualifiedName.accept(action)) return false; + if (alias != null && !alias.accept(action)) + return false; + if (qualifiedName != null && !qualifiedName.accept(action)) + return false; - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { - if (alias == n) return r_definition; - if (qualifiedName == n) return r_reference; + if (alias == n) + return r_definition; + if (qualifiedName == n) + return r_reference; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index 606ec8ffceb..fe259693edf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -29,13 +29,13 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; * Definition of a namespace. */ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements ICPPASTNamespaceDefinition { - private IASTName fName; + private IASTName fName; private IASTDeclaration[] fAllDeclarations; private IASTDeclaration[] fActiveDeclarations; - private int fLastDeclaration= -1; - private boolean fIsInline; + private int fLastDeclaration = -1; + private boolean fIsInline; - public CPPASTNamespaceDefinition() { + public CPPASTNamespaceDefinition() { } public CPPASTNamespaceDefinition(IASTName name) { @@ -49,8 +49,7 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I @Override public CPPASTNamespaceDefinition copy(CopyStyle style) { - CPPASTNamespaceDefinition copy = - new CPPASTNamespaceDefinition(fName == null ? null : fName.copy(style)); + CPPASTNamespaceDefinition copy = new CPPASTNamespaceDefinition(fName == null ? null : fName.copy(style)); copy.fIsInline = fIsInline; for (IASTDeclaration declaration : getDeclarations()) { copy.addDeclaration(declaration == null ? null : declaration.copy(style)); @@ -60,23 +59,23 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName = name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAMESPACE_NAME); } - } + } @Override public void setIsInline(boolean isInline) { assertNotFrozen(); - fIsInline= isInline; + fIsInline = isInline; } @Override @@ -90,16 +89,16 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I decl.setParent(this); decl.setPropertyInParent(OWNED_DECLARATION); fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl); - fActiveDeclarations= null; + fActiveDeclarations = null; } } @Override public final IASTDeclaration[] getDeclarations() { - IASTDeclaration[] active= fActiveDeclarations; + IASTDeclaration[] active = fActiveDeclarations; if (active == null) { - active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fLastDeclaration+1); - fActiveDeclarations= active; + active = ASTQueries.extractActiveDeclarations(fAllDeclarations, fLastDeclaration + 1); + fActiveDeclarations = active; } return active; } @@ -107,25 +106,28 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I @Override public final IASTDeclaration[] getDeclarations(boolean includeInactive) { if (includeInactive) { - fAllDeclarations= ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration); + fAllDeclarations = ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration); return fAllDeclarations; } return getDeclarations(); } - @Override + @Override public IScope getScope() { - return ((ICPPNamespace) fName.resolveBinding()).getNamespaceScope(); + return ((ICPPNamespace) fName.resolveBinding()).getNamespaceScope(); } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitNamespaces) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (!acceptByCPPAttributeSpecifiers(action)) @@ -137,7 +139,7 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I if (!acceptByGCCAttributeSpecifiers(action)) return false; - IASTDeclaration [] decls = getDeclarations(action.includeInactiveNodes); + IASTDeclaration[] decls = getDeclarations(action.includeInactiveNodes); for (IASTDeclaration decl : decls) { if (!decl.accept(action)) return false; @@ -146,8 +148,8 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I if (action.shouldVisitNamespaces && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -156,7 +158,7 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I return r_unclear; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { assert child.isActive() == other.isActive(); for (int i = 0; i <= fLastDeclaration; ++i) { @@ -164,10 +166,10 @@ public class CPPASTNamespaceDefinition extends CPPASTAttributeOwner implements I other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent()); fAllDeclarations[i] = (IASTDeclaration) other; - fActiveDeclarations= null; + fActiveDeclarations = null; return; } } super.replace(child, other); - } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNaryTypeIdExpression.java index 815c99436b4..cefbf7672b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNaryTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNaryTypeIdExpression.java @@ -67,9 +67,12 @@ public class CPPASTNaryTypeIdExpression extends ASTNode implements ICPPASTNaryTy public boolean accept(ASTVisitor action) { if (action.shouldVisitExpressions) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java index fb1e48ea020..b4f9b5d7915 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java @@ -54,18 +54,18 @@ import org.eclipse.core.runtime.Assert; * Represents a new expression [expr.new]. */ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression, IASTAmbiguityParent { - private IASTInitializerClause[] fPlacement; - private IASTTypeId fTypeId; - private IASTInitializer fInitializer; - private boolean fIsGlobal; - private boolean fIsNewTypeId; + private IASTInitializerClause[] fPlacement; + private IASTTypeId fTypeId; + private IASTInitializer fInitializer; + private boolean fIsGlobal; + private boolean fIsNewTypeId; - private IASTExpression[] fCachedArraySizes; + private IASTExpression[] fCachedArraySizes; private ICPPEvaluation fEvaluation; - private IASTImplicitName[] fImplicitNames; + private IASTImplicitName[] fImplicitNames; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTNewExpression() { + public CPPASTNewExpression() { } public CPPASTNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId) { @@ -98,80 +98,80 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression @Override public boolean isGlobal() { - return fIsGlobal; - } + return fIsGlobal; + } - @Override + @Override public void setIsGlobal(boolean value) { - assertNotFrozen(); - fIsGlobal = value; - } + assertNotFrozen(); + fIsGlobal = value; + } - @Override + @Override public IASTInitializerClause[] getPlacementArguments() { - return fPlacement; - } + return fPlacement; + } - @Override + @Override public void setPlacementArguments(IASTInitializerClause[] args) { - assertNotFrozen(); - fPlacement = args; - if (args != null) { - for (IASTInitializerClause arg : args) { + assertNotFrozen(); + fPlacement = args; + if (args != null) { + for (IASTInitializerClause arg : args) { arg.setParent(this); arg.setPropertyInParent(NEW_PLACEMENT); } } - } + } - @Override + @Override public IASTInitializer getInitializer() { - return fInitializer; - } + return fInitializer; + } - @Override + @Override public void setInitializer(IASTInitializer expression) { - assertNotFrozen(); - fInitializer = expression; - if (expression != null) { + assertNotFrozen(); + fInitializer = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(NEW_INITIALIZER); } - } + } - @Override + @Override public IASTTypeId getTypeId() { - return fTypeId; - } + return fTypeId; + } - @Override + @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - fTypeId = typeId; - if (typeId != null) { + assertNotFrozen(); + fTypeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); } - } + } - @Override + @Override public boolean isNewTypeId() { - return fIsNewTypeId; - } + return fIsNewTypeId; + } - @Override + @Override public void setIsNewTypeId(boolean value) { - assertNotFrozen(); - fIsNewTypeId = value; - } - - /** - * @see org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner#getImplicitNames() - */ - @Override + assertNotFrozen(); + fIsNewTypeId = value; + } + + /** + * @see org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner#getImplicitNames() + */ + @Override public IASTImplicitName[] getImplicitNames() { - if (fImplicitNames == null) { - CPPASTImplicitName operatorName = null; + if (fImplicitNames == null) { + CPPASTImplicitName operatorName = null; ICPPFunction operatorFunction = CPPSemantics.findOverloadedOperator(this); if (operatorFunction != null && !(operatorFunction instanceof CPPImplicitFunction)) { operatorName = new CPPASTImplicitName(operatorFunction.getNameCharArray(), this); @@ -201,10 +201,10 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; } } - } + } - return fImplicitNames; - } + return fImplicitNames; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -215,38 +215,42 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression return fImplicitDestructorNames; } - /** + /** * Returns true if this expression is allocating an array. * @since 5.1 */ @Override public boolean isArrayAllocation() { - IASTTypeId typeId= getTypeId(); + IASTTypeId typeId = getTypeId(); if (typeId != null) { - IASTDeclarator dtor= typeId.getAbstractDeclarator(); + IASTDeclarator dtor = typeId.getAbstractDeclarator(); if (dtor != null) { - dtor= ASTQueries.findTypeRelevantDeclarator(dtor); + dtor = ASTQueries.findTypeRelevantDeclarator(dtor); return dtor instanceof IASTArrayDeclarator; } } return false; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitImplicitNames) { - for (IASTImplicitName name : getImplicitNames()) { - if (!name.accept(action)) return false; - } - } + if (action.shouldVisitImplicitNames) { + for (IASTImplicitName name : getImplicitNames()) { + if (!name.accept(action)) + return false; + } + } if (fPlacement != null) { for (IASTInitializerClause arg : fPlacement) { @@ -260,18 +264,21 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression if (fInitializer != null && !fInitializer.accept(action)) return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -296,7 +303,7 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression ICPPEvaluation[] arguments = ICPPEvaluation.EMPTY_ARRAY; if (fInitializer instanceof ICPPASTConstructorInitializer) { IASTInitializerClause[] args = ((ICPPASTConstructorInitializer) fInitializer).getArguments(); - arguments= new ICPPEvaluation[args.length]; + arguments = new ICPPEvaluation[args.length]; for (int i = 0; i < arguments.length; i++) { arguments[i] = ((ICPPASTInitializerClause) args[i]).getEvaluation(); } @@ -306,10 +313,10 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression return fEvaluation; } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public boolean isLValue() { @@ -343,96 +350,96 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression return fCachedArraySizes; } - @Override + @Override @Deprecated - public void addNewTypeIdArrayExpression(IASTExpression expression) { - assertNotFrozen(); - Assert.isNotNull(fTypeId); - IASTDeclarator dtor= ASTQueries.findInnermostDeclarator(fTypeId.getAbstractDeclarator()); - if (dtor instanceof IASTArrayDeclarator == false) { - Assert.isNotNull(dtor); - Assert.isTrue(dtor.getParent() == fTypeId); - IASTArrayDeclarator adtor= new CPPASTArrayDeclarator(dtor.getName()); - IASTPointerOperator[] ptrOps= dtor.getPointerOperators(); - for (IASTPointerOperator ptr : ptrOps) { - adtor.addPointerOperator(ptr); + public void addNewTypeIdArrayExpression(IASTExpression expression) { + assertNotFrozen(); + Assert.isNotNull(fTypeId); + IASTDeclarator dtor = ASTQueries.findInnermostDeclarator(fTypeId.getAbstractDeclarator()); + if (dtor instanceof IASTArrayDeclarator == false) { + Assert.isNotNull(dtor); + Assert.isTrue(dtor.getParent() == fTypeId); + IASTArrayDeclarator adtor = new CPPASTArrayDeclarator(dtor.getName()); + IASTPointerOperator[] ptrOps = dtor.getPointerOperators(); + for (IASTPointerOperator ptr : ptrOps) { + adtor.addPointerOperator(ptr); } - fTypeId.setAbstractDeclarator(adtor); - dtor= adtor; - } - IASTArrayModifier mod= new CPPASTArrayModifier(expression); - ((ASTNode) mod).setOffsetAndLength((ASTNode) expression); - ((IASTArrayDeclarator) dtor).addArrayModifier(mod); - } + fTypeId.setAbstractDeclarator(adtor); + dtor = adtor; + } + IASTArrayModifier mod = new CPPASTArrayModifier(expression); + ((ASTNode) mod).setOffsetAndLength((ASTNode) expression); + ((IASTArrayDeclarator) dtor).addArrayModifier(mod); + } @Override @Deprecated - public IASTExpression getNewPlacement() { - if (fPlacement == null || fPlacement.length == 0) - return null; - if (fPlacement.length == 1) { - if (fPlacement[0] instanceof IASTExpression) - return (IASTExpression) fPlacement[0]; - return null; - } - - CASTExpressionList result= new CASTExpressionList(); - for (IASTInitializerClause arg : fPlacement) { - if (arg instanceof IASTExpression) { - result.addExpression(((IASTExpression) arg).copy()); - } - } - result.setParent(this); - result.setPropertyInParent(NEW_PLACEMENT); - return result; - } + public IASTExpression getNewPlacement() { + if (fPlacement == null || fPlacement.length == 0) + return null; + if (fPlacement.length == 1) { + if (fPlacement[0] instanceof IASTExpression) + return (IASTExpression) fPlacement[0]; + return null; + } + + CASTExpressionList result = new CASTExpressionList(); + for (IASTInitializerClause arg : fPlacement) { + if (arg instanceof IASTExpression) { + result.addExpression(((IASTExpression) arg).copy()); + } + } + result.setParent(this); + result.setPropertyInParent(NEW_PLACEMENT); + return result; + } @Override @Deprecated - public void setNewPlacement(IASTExpression expression) { - assertNotFrozen(); - if (expression == null) { - setPlacementArguments(null); - } else if (expression instanceof IASTExpressionList) { - setPlacementArguments(((IASTExpressionList) expression).getExpressions()); - } else { - setPlacementArguments(new IASTExpression[] {expression}); - } - } + public void setNewPlacement(IASTExpression expression) { + assertNotFrozen(); + if (expression == null) { + setPlacementArguments(null); + } else if (expression instanceof IASTExpressionList) { + setPlacementArguments(((IASTExpressionList) expression).getExpressions()); + } else { + setPlacementArguments(new IASTExpression[] { expression }); + } + } @Override @Deprecated - public IASTExpression getNewInitializer() { - if (fInitializer == null || fInitializer instanceof IASTExpression) { - return (IASTExpression) fInitializer; - } - if (fInitializer instanceof ICPPASTConstructorInitializer) { - IASTExpression expr= ((ICPPASTConstructorInitializer) fInitializer).getExpression(); - if (expr == null) { - expr= new CPPASTExpressionList(); - } else { - expr= expr.copy(); - } - expr.setParent(this); - expr.setPropertyInParent(NEW_INITIALIZER); - return expr; - } - return null; - } + public IASTExpression getNewInitializer() { + if (fInitializer == null || fInitializer instanceof IASTExpression) { + return (IASTExpression) fInitializer; + } + if (fInitializer instanceof ICPPASTConstructorInitializer) { + IASTExpression expr = ((ICPPASTConstructorInitializer) fInitializer).getExpression(); + if (expr == null) { + expr = new CPPASTExpressionList(); + } else { + expr = expr.copy(); + } + expr.setParent(this); + expr.setPropertyInParent(NEW_INITIALIZER); + return expr; + } + return null; + } @Override @Deprecated - public void setNewInitializer(IASTExpression expression) { - assertNotFrozen(); - if (expression == null) { - setInitializer(null); - } else if (expression instanceof IASTInitializer) { - setInitializer((IASTInitializer) expression); - } else { - CPPASTConstructorInitializer ctorInit= new CPPASTConstructorInitializer(); - ctorInit.setExpression(expression); - ctorInit.setOffsetAndLength((ASTNode) expression); - setInitializer(ctorInit); - } - } + public void setNewInitializer(IASTExpression expression) { + assertNotFrozen(); + if (expression == null) { + setInitializer(null); + } else if (expression instanceof IASTInitializer) { + setInitializer((IASTInitializer) expression); + } else { + CPPASTConstructorInitializer ctorInit = new CPPASTConstructorInitializer(); + ctorInit.setExpression(expression); + ctorInit.setOffsetAndLength((ASTNode) expression); + setInitializer(ctorInit); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java index 85ac3041ce6..8695a946648 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java @@ -21,29 +21,36 @@ import org.eclipse.cdt.core.dom.ast.IASTNullStatement; * @author jcamelon */ public class CPPASTNullStatement extends CPPASTAttributeOwner implements IASTNullStatement { - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public CPPASTNullStatement copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java index 107dd983640..c574f6d92a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java @@ -30,7 +30,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalPackExpansion; /** * Implementation of pack expansion expression. */ -public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPackExpansionExpression, IASTAmbiguityParent { +public class CPPASTPackExpansionExpression extends ASTNode + implements ICPPASTPackExpansionExpression, IASTAmbiguityParent { private IASTExpression fPattern; private ICPPEvaluation fEvaluation; @@ -42,7 +43,7 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac public void setPattern(IASTExpression pattern) { assertNotFrozen(); - fPattern= pattern; + fPattern = pattern; if (pattern != null) { pattern.setParent(this); pattern.setPropertyInParent(ICPPASTPackExpansionExpression.PATTERN); @@ -75,7 +76,7 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); + return CPPEvaluation.getType(this); } @Override @@ -95,28 +96,31 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac @Override public boolean accept(ASTVisitor visitor) { - if (visitor.shouldVisitExpressions) { - switch (visitor.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default : break; - } + if (visitor.shouldVisitExpressions) { + switch (visitor.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!fPattern.accept(visitor)) { - return false; - } - if (visitor.shouldVisitExpressions && visitor.leave(this) == ASTVisitor.PROCESS_ABORT) { - return false; - } - return true; - } + if (!fPattern.accept(visitor)) { + return false; + } + if (visitor.shouldVisitExpressions && visitor.leave(this) == ASTVisitor.PROCESS_ABORT) { + return false; + } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { if (child == fPattern) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - fPattern = (IASTExpression) other; + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + fPattern = (IASTExpression) other; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java index 636d11d9f2b..9897e33a2f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTParameterDeclaration.java @@ -27,10 +27,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * Function parameter or non-type template parameter declaration. */ public class CPPASTParameterDeclaration extends CPPASTAttributeOwner implements ICPPASTParameterDeclaration { - private IASTDeclSpecifier fDeclSpec; - private ICPPASTDeclarator fDeclarator; + private IASTDeclSpecifier fDeclSpec; + private ICPPASTDeclarator fDeclarator; - public CPPASTParameterDeclaration() { + public CPPASTParameterDeclaration() { } public CPPASTParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) { @@ -58,44 +58,47 @@ public class CPPASTParameterDeclaration extends CPPASTAttributeOwner implements @Override public IASTDeclSpecifier getDeclSpecifier() { - return fDeclSpec; - } + return fDeclSpec; + } - @Override + @Override public ICPPASTDeclarator getDeclarator() { - return fDeclarator; - } + return fDeclarator; + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); - this.fDeclSpec = declSpec; - if (declSpec != null) { + assertNotFrozen(); + this.fDeclSpec = declSpec; + if (declSpec != null) { declSpec.setParent(this); declSpec.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public void setDeclarator(IASTDeclarator declarator) { - assertNotFrozen(); - if (declarator instanceof ICPPASTDeclarator) { - fDeclarator = (ICPPASTDeclarator) declarator; + assertNotFrozen(); + if (declarator instanceof ICPPASTDeclarator) { + fDeclarator = (ICPPASTDeclarator) declarator; declarator.setParent(this); declarator.setPropertyInParent(DECLARATOR); } else { - fDeclarator= null; + fDeclarator = null; } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitParameterDeclarations) { switch (action.visit((IASTParameterDeclaration) this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (!acceptByAttributeSpecifiers(action)) @@ -105,19 +108,19 @@ public class CPPASTParameterDeclaration extends CPPASTAttributeOwner implements if (fDeclarator != null && !fDeclarator.accept(action)) return false; - if (action.shouldVisitParameterDeclarations && - action.leave((IASTParameterDeclaration) this) == ASTVisitor.PROCESS_ABORT) { + if (action.shouldVisitParameterDeclarations + && action.leave((IASTParameterDeclaration) this) == ASTVisitor.PROCESS_ABORT) { return false; } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { - if (child == fDeclarator) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - fDeclarator= (ICPPASTDeclarator) other; - } + if (child == fDeclarator) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + fDeclarator = (ICPPASTDeclarator) other; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java index 65b4fb2dfe3..0759ce540b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java @@ -22,14 +22,14 @@ import org.eclipse.cdt.core.dom.ast.IASTPointer; * A pointer operator of a declarator */ public class CPPASTPointer extends CPPASTAttributeOwner implements IASTPointer { - private boolean isConst; - private boolean isVolatile; - private boolean isRestrict; + private boolean isConst; + private boolean isVolatile; + private boolean isRestrict; - public CPPASTPointer() { - } + public CPPASTPointer() { + } - @Override + @Override public CPPASTPointer copy() { return copy(CopyStyle.withoutLocations); } @@ -43,46 +43,48 @@ public class CPPASTPointer extends CPPASTAttributeOwner implements IASTPointer { return copy(copy, style); } - @Override + @Override public boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public boolean isRestrict() { - return isRestrict; - } + return isRestrict; + } - @Override + @Override public void setConst(boolean value) { - assertNotFrozen(); - isConst = value; - } + assertNotFrozen(); + isConst = value; + } - @Override + @Override public void setVolatile(boolean value) { - assertNotFrozen(); - isVolatile = value; - } + assertNotFrozen(); + isVolatile = value; + } - @Override + @Override public void setRestrict(boolean value) { - assertNotFrozen(); - isRestrict = value; - } + assertNotFrozen(); + isRestrict = value; + } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitPointerOperators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } } if (!acceptByAttributeSpecifiers(action)) @@ -91,7 +93,7 @@ public class CPPASTPointer extends CPPASTAttributeOwner implements IASTPointer { if (action.shouldVisitPointerOperators) { if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - } + } return true; - } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java index 6eb8e3e5bf5..6f6eeaa2159 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java @@ -20,9 +20,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; public class CPPASTPointerToMember extends CPPASTPointer implements ICPPASTPointerToMember { - private IASTName n; + private IASTName n; - public CPPASTPointerToMember() { + public CPPASTPointerToMember() { } public CPPASTPointerToMember(IASTName n) { @@ -45,39 +45,40 @@ public class CPPASTPointerToMember extends CPPASTPointer implements ICPPASTPoint @Override public void setName(IASTName name) { - assertNotFrozen(); - n = name; - if (name != null) { + assertNotFrozen(); + n = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAME); } - } - + } - @Override + @Override public IASTName getName() { - return n; - } + return n; + } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitPointerOperators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - } - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } + } if (n != null && !n.accept(action)) return false; if (action.shouldVisitPointerOperators && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; return true; - } + } @Override public int getRoleForName(IASTName name) { - if (name == this.n) + if (name == this.n) return r_reference; return r_unclear; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java index 1fbe6e54e2a..eca7e2ea9a3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java @@ -23,38 +23,44 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem; */ public class CPPASTProblem extends ASTProblem { - public CPPASTProblem(int id, char[] arg, boolean isError) { - super(id, arg, isError); - } + public CPPASTProblem(int id, char[] arg, boolean isError) { + super(id, arg, isError); + } - @Override + @Override public CPPASTProblem copy() { return copy(CopyStyle.withoutLocations); } @Override public CPPASTProblem copy(CopyStyle style) { - char[] arg = getArgument(); - CPPASTProblem copy = new CPPASTProblem(getID(), arg == null ? null : arg.clone(), isError()); + char[] arg = getArgument(); + CPPASTProblem copy = new CPPASTProblem(getID(), arg == null ? null : arg.clone(), isError()); return copy(copy, style); } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitProblems) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitProblems) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (action.shouldVisitProblems) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitProblems) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java index e08a08d1599..5e645d9aa4f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; */ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IASTProblemDeclaration { - public CPPASTProblemDeclaration() { + public CPPASTProblemDeclaration() { super(); } @@ -44,21 +44,27 @@ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IAST @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - super.accept(action); // visits the problem - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + super.accept(action); // visits the problem + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java index ac1b0ef4439..cbbeb91fb26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTProblemExpression, ICPPASTExpression { - public CPPASTProblemExpression() { + public CPPASTProblemExpression() { super(); } @@ -54,33 +54,39 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTP @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - super.accept(action); // visits the problem - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + super.accept(action); // visits the problem + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public ICPPEvaluation getEvaluation() { return EvalFixed.INCOMPLETE; } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public boolean isLValue() { @@ -89,6 +95,6 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTP @Override public ValueCategory getValueCategory() { - return CPPEvaluation.getValueCategory(this); + return CPPEvaluation.getValueCategory(this); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java index 4ef2d2956d9..feedd54a62d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java @@ -24,9 +24,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder { - private IASTProblem problem; + private IASTProblem problem; - public CPPASTProblemOwner() { + public CPPASTProblemOwner() { } public CPPASTProblemOwner(IASTProblem problem) { @@ -40,33 +40,39 @@ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder { @Override public IASTProblem getProblem() { - return problem; - } + return problem; + } - @Override + @Override public void setProblem(IASTProblem p) { - assertNotFrozen(); - problem = p; - if (p != null) { + assertNotFrozen(); + problem = p; + if (p != null) { p.setParent(this); p.setPropertyInParent(PROBLEM); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitProblems) { - switch (action.visit(getProblem())) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - switch (action.leave(getProblem())) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitProblems) { + switch (action.visit(getProblem())) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + switch (action.leave(getProblem())) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java index 4c949b16c1c..1a8c3e478a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; */ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTProblemStatement { - public CPPASTProblemStatement() { + public CPPASTProblemStatement() { super(); } @@ -48,23 +48,29 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - super.accept(action); // visits the problem - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + super.accept(action); // visits the problem + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public IASTAttribute[] getAttributes() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java index 603e3827996..25a544b4937 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java @@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; */ public class CPPASTProblemTypeId extends CPPASTProblemOwner implements IASTProblemTypeId { - public CPPASTProblemTypeId() { + public CPPASTProblemTypeId() { } public CPPASTProblemTypeId(IASTProblem problem) { @@ -43,24 +43,27 @@ public class CPPASTProblemTypeId extends CPPASTProblemOwner implements IASTProbl return copy(copy, style); } - @Override - public final boolean accept (ASTVisitor action) { - if (action.shouldVisitTypeIds) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + @Override + public final boolean accept(ASTVisitor action) { + if (action.shouldVisitTypeIds) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } - // Visit the problem - if (!super.accept(action)) - return false; + // Visit the problem + if (!super.accept(action)) + return false; - if (action.shouldVisitTypeIds && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; - } - return true; - } + if (action.shouldVisitTypeIds && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; + } + return true; + } @Override public IASTDeclSpecifier getDeclSpecifier() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index c15dbb577c2..b8971514149 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -65,8 +65,7 @@ import org.eclipse.core.runtime.Assert; * Qualified name, which can contain any other name (unqualified, operator-name, conversion name, * template id). */ -public class CPPASTQualifiedName extends CPPASTNameBase - implements ICPPASTQualifiedName, ICPPASTCompletionContext { +public class CPPASTQualifiedName extends CPPASTNameBase implements ICPPASTQualifiedName, ICPPASTCompletionContext { private ICPPASTNameSpecifier[] fQualifier; private int fQualifierPos = -1; private ICPPASTName fLastName; @@ -92,8 +91,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase @Override public CPPASTQualifiedName copy(CopyStyle style) { - CPPASTQualifiedName copy = - new CPPASTQualifiedName(fLastName == null ? null : fLastName.copy(style)); + CPPASTQualifiedName copy = new CPPASTQualifiedName(fLastName == null ? null : fLastName.copy(style)); for (ICPPASTNameSpecifier nameSpecifier : getQualifier()) { copy.addNameSpecifier(nameSpecifier == null ? null : nameSpecifier.copy(style)); } @@ -110,15 +108,15 @@ public class CPPASTQualifiedName extends CPPASTNameBase @Override public IBinding resolveBinding() { // The whole qualified name resolves to the same thing as the last name. - IASTName lastName= getLastName(); + IASTName lastName = getLastName(); return lastName == null ? null : lastName.resolveBinding(); } - @Override + @Override public final IBinding getPreBinding() { // The whole qualified name resolves to the same thing as the last name. return getLastName().getPreBinding(); - } + } @Override public IBinding getBinding() { @@ -195,7 +193,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase @Override public char[] toCharArray() { if (fSignature == null) { - StringBuilder buf= new StringBuilder(); + StringBuilder buf = new StringBuilder(); for (int i = 0; i <= fQualifierPos; i++) { if (i > 0 || fIsFullyQualified) { buf.append(Keywords.cpCOLONCOLON); @@ -207,8 +205,8 @@ public class CPPASTQualifiedName extends CPPASTNameBase } buf.append(fLastName.toCharArray()); - final int len= buf.length(); - fSignature= new char[len]; + final int len = buf.length(); + fSignature = new char[len]; buf.getChars(0, len, fSignature, 0); } return fSignature; @@ -221,7 +219,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase @Override public void setFullyQualified(boolean isFullyQualified) { - assertNotFrozen(); + assertNotFrozen(); this.fIsFullyQualified = isFullyQualified; } @@ -269,19 +267,19 @@ public class CPPASTQualifiedName extends CPPASTNameBase @Override public int getRoleOfName(boolean allowResolution) { - IASTNode parent = getParent(); - if (parent instanceof IASTInternalNameOwner) { - return ((IASTInternalNameOwner) parent).getRoleForName(this, allowResolution); - } - if (parent instanceof IASTNameOwner) { - return ((IASTNameOwner) parent).getRoleForName(this); - } - return IASTNameOwner.r_unclear; + IASTNode parent = getParent(); + if (parent instanceof IASTInternalNameOwner) { + return ((IASTInternalNameOwner) parent).getRoleForName(this, allowResolution); + } + if (parent instanceof IASTNameOwner) { + return ((IASTNameOwner) parent).getRoleForName(this); + } + return IASTNameOwner.r_unclear; } @Override public int getRoleForName(IASTName n) { - for (int i=0; i <= fQualifierPos; ++i) { + for (int i = 0; i <= fQualifierPos; ++i) { if (fQualifier[i] == n) return r_reference; } @@ -296,7 +294,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase @Override public boolean isConversionOrOperator() { - final IASTName lastName= getLastName(); + final IASTName lastName = getLastName(); if (lastName instanceof ICPPASTConversionName || lastName instanceof ICPPASTOperatorName) { return true; } @@ -321,8 +319,8 @@ public class CPPASTQualifiedName extends CPPASTNameBase final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration; final boolean isUsingDecl = getParent() instanceof ICPPASTUsingDeclaration; List<IBinding> filtered = filterClassScopeBindings(classQualifier, bindings, isDeclaration); - if ((isDeclaration || isUsingDecl) && nameMatches(classQualifier.getNameCharArray(), - n.getLookupKey(), isPrefix)) { + if ((isDeclaration || isUsingDecl) + && nameMatches(classQualifier.getNameCharArray(), n.getLookupKey(), isPrefix)) { ICPPConstructor[] constructors = classQualifier.getConstructors(); for (int i = 0; i < constructors.length; i++) { if (!constructors[i].isImplicit()) { @@ -338,23 +336,22 @@ public class CPPASTQualifiedName extends CPPASTNameBase // Are we taking the address of a qualified name? private boolean isAddressOf() { - return getParent() instanceof IASTIdExpression - && getParent().getParent() instanceof IASTUnaryExpression - && ((IASTUnaryExpression) getParent().getParent()).getOperator() == IASTUnaryExpression.op_amper; + return getParent() instanceof IASTIdExpression && getParent().getParent() instanceof IASTUnaryExpression + && ((IASTUnaryExpression) getParent().getParent()).getOperator() == IASTUnaryExpression.op_amper; } - + // Are we inside a using-declaration? private boolean inUsingDecl() { return getParent() instanceof ICPPASTUsingDeclaration; } - + private boolean canBeFieldAccess(ICPPClassType baseClass) { - IASTNode parent= getParent(); + IASTNode parent = getParent(); if (parent instanceof IASTFieldReference) { return true; } if (parent instanceof IASTIdExpression) { - IScope scope= CPPVisitor.getContainingScope(this); + IScope scope = CPPVisitor.getContainingScope(this); try { while (scope != null) { if (scope instanceof ICPPClassScope) { @@ -363,19 +360,19 @@ public class CPPASTQualifiedName extends CPPASTNameBase return true; } } - scope= scope.getParent(); + scope = scope.getParent(); } } catch (DOMException e) { } } return false; } - + private ICPPClassType getClassQualifier() { if (fQualifierPos < 0) { return null; } - + IBinding binding = fQualifier[fQualifierPos].resolveBinding(); while (binding instanceof ITypedef) { @@ -387,10 +384,10 @@ public class CPPASTQualifiedName extends CPPASTNameBase binding = null; } } - + return binding instanceof ICPPClassType ? (ICPPClassType) binding : null; } - + public static boolean canBeFieldAccess(CPPASTQualifiedName qname) { ICPPClassType classQualifier = qname.getClassQualifier(); if (classQualifier == null) { @@ -404,7 +401,8 @@ public class CPPASTQualifiedName extends CPPASTNameBase List<IBinding> filtered = new ArrayList<IBinding>(); final boolean allowNonstatic = canBeFieldAccess(classType) || isAddressOf() || inUsingDecl(); final IBinding templateDefinition = (classType instanceof ICPPTemplateInstance) - ? ((ICPPTemplateInstance) classType).getTemplateDefinition() : null; + ? ((ICPPTemplateInstance) classType).getTemplateDefinition() + : null; for (final IBinding binding : bindings) { if (binding instanceof IField) { @@ -427,15 +425,13 @@ public class CPPASTQualifiedName extends CPPASTNameBase // This solves bug 456101 (template instance refering to itself). // A<T>:: should not get a binding to its own template definition. continue; - } else if (classType instanceof ICPPDeferredClassInstance - && binding instanceof ICPPClassSpecialization) { + } else if (classType instanceof ICPPDeferredClassInstance && binding instanceof ICPPClassSpecialization) { // during heuristic resolution of ICPPDeferredClassInstance's we // might have found a partial specialization; those have their own template // definition but share the same primary template as the ICPPDeferredClassInstance ICPPClassType template = ((ICPPClassSpecialization) binding).getSpecializedBinding(); if (template instanceof ICPPClassTemplatePartialSpecialization) { - template = (ICPPClassType) ((ICPPClassTemplatePartialSpecialization) template) - .getPrimaryTemplate(); + template = (ICPPClassType) ((ICPPClassTemplatePartialSpecialization) template).getPrimaryTemplate(); } if (template.isSameType((IType) templateDefinition)) continue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java index a68717da640..a94df0dfc90 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java @@ -46,20 +46,21 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * Range based 'for' loop in C++. */ -public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implements ICPPASTRangeBasedForStatement, ICPPExecutionOwner { - private IScope fScope; - private IASTDeclaration fDeclaration; - private IASTInitializerClause fInitClause; - private IASTStatement fBody; - private IASTImplicitName[] fImplicitNames; +public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner + implements ICPPASTRangeBasedForStatement, ICPPExecutionOwner { + private IScope fScope; + private IASTDeclaration fDeclaration; + private IASTInitializerClause fInitClause; + private IASTStatement fBody; + private IASTImplicitName[] fImplicitNames; private IASTImplicitDestructorName[] fImplicitDestructorNames; - - private static final char[] RANGE_EXPR = "__range".toCharArray(); //$NON-NLS-1$ - public CPPASTRangeBasedForStatement() { + private static final char[] RANGE_EXPR = "__range".toCharArray(); //$NON-NLS-1$ + + public CPPASTRangeBasedForStatement() { } - @Override + @Override public CPPASTRangeBasedForStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -75,38 +76,38 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement @Override public IASTDeclaration getDeclaration() { - return fDeclaration; - } + return fDeclaration; + } - @Override + @Override public void setDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - this.fDeclaration = declaration; - if (declaration != null) { - declaration.setParent(this); - declaration.setPropertyInParent(DECLARATION); + assertNotFrozen(); + this.fDeclaration = declaration; + if (declaration != null) { + declaration.setParent(this); + declaration.setPropertyInParent(DECLARATION); } - } + } - @Override + @Override public IASTInitializerClause getInitializerClause() { - return fInitClause; - } + return fInitClause; + } - @Override + @Override public void setInitializerClause(IASTInitializerClause initClause) { - assertNotFrozen(); - fInitClause = initClause; - if (initClause != null) { + assertNotFrozen(); + fInitClause = initClause; + if (initClause != null) { initClause.setParent(this); initClause.setPropertyInParent(INITIALIZER); } - } + } - @Override + @Override public IASTStatement getBody() { - return fBody; - } + return fBody; + } @Override public void setBody(IASTStatement statement) { @@ -132,32 +133,33 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement final ASTNode position = (ASTNode) forInit; if (forInit instanceof IASTExpression) { final IASTExpression forInitExpr = (IASTExpression) forInit; - IType type= SemanticUtil.getNestedType(forInitExpr.getExpressionType(), TDEF|CVTYPE); + IType type = SemanticUtil.getNestedType(forInitExpr.getExpressionType(), TDEF | CVTYPE); if (type instanceof IArrayType) { - fImplicitNames= IASTImplicitName.EMPTY_NAME_ARRAY; + fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY; } else if (type instanceof ICPPClassType) { - ICPPClassType ct= (ICPPClassType) type; + ICPPClassType ct = (ICPPClassType) type; CPPSemantics.pushLookupPoint(this); try { - if (CPPSemantics.findBindings(ct.getCompositeScope(), CPPVisitor.BEGIN, true, this).length > 0) { + if (CPPSemantics.findBindings(ct.getCompositeScope(), CPPVisitor.BEGIN, true, + this).length > 0) { CPPASTName name = new CPPASTName(CPPVisitor.BEGIN); name.setOffset(position.getOffset()); CPPASTFieldReference fieldRef = new CPPASTFieldReference(name, forInitExpr.copy()); - IASTExpression expr= new CPPASTFunctionCallExpression(fieldRef, CPPVisitor.NO_ARGS); + IASTExpression expr = new CPPASTFunctionCallExpression(fieldRef, CPPVisitor.NO_ARGS); expr.setParent(this); expr.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER); - CPPASTImplicitName begin= new CPPASTImplicitName(name.toCharArray(), this); + CPPASTImplicitName begin = new CPPASTImplicitName(name.toCharArray(), this); begin.setBinding(name.resolveBinding()); begin.setOffsetAndLength(position); - + name = new CPPASTName(CPPVisitor.END); name.setOffset(position.getOffset()); fieldRef.setFieldName(name); - CPPASTImplicitName end= new CPPASTImplicitName(name.toCharArray(), this); + CPPASTImplicitName end = new CPPASTImplicitName(name.toCharArray(), this); end.setBinding(name.resolveBinding()); end.setOffsetAndLength(position); - - fImplicitNames= new IASTImplicitName[] {begin, end}; + + fImplicitNames = new IASTImplicitName[] { begin, end }; } } finally { CPPSemantics.popLookupPoint(); @@ -177,7 +179,7 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement CPPASTSimpleDeclaration rangeVarDecl = new CPPASTSimpleDeclaration(); rangeVarDecl.setDeclSpecifier(rangeVarDeclSpec); // Make the notional declaration of '__range_ a child of the range-for - // statement's body, so that name resolution in its initializer has + // statement's body, so that name resolution in its initializer has // a scope to work with. rangeVarDecl.setParent(fBody); CPPASTDeclarator rangeVarDeclarator = new CPPASTDeclarator(rangeVarDeclName); @@ -186,27 +188,27 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement CPPASTName rangeVarRefName = new CPPASTName(RANGE_EXPR); rangeVarRefName.setBinding(rangeVar); CPPASTIdExpression rangeExpr = new CPPASTIdExpression(rangeVarRefName); - + CPPASTName name = new CPPASTName(CPPVisitor.BEGIN); name.setOffset(position.getOffset()); CPPASTIdExpression fname = new CPPASTIdExpression(name); - IASTExpression expr= new CPPASTFunctionCallExpression(fname, + IASTExpression expr = new CPPASTFunctionCallExpression(fname, new IASTInitializerClause[] { rangeExpr }); expr.setParent(this); expr.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER); - CPPASTImplicitName begin= new CPPASTImplicitName(name.toCharArray(), this); + CPPASTImplicitName begin = new CPPASTImplicitName(name.toCharArray(), this); begin.setBinding(name.resolveBinding()); begin.setOffsetAndLength(position); name = new CPPASTName(CPPVisitor.END); name.setOffset(position.getOffset()); fname.setName(name); - CPPASTImplicitName end= new CPPASTImplicitName(name.toCharArray(), this); + CPPASTImplicitName end = new CPPASTImplicitName(name.toCharArray(), this); end.setBinding(name.resolveBinding()); end.setOffsetAndLength(position); - fImplicitNames= new IASTImplicitName[] {begin, end}; + fImplicitNames = new IASTImplicitName[] { begin, end }; } } return fImplicitNames; @@ -221,22 +223,26 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitStatements) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; if (fDeclaration != null && !fDeclaration.accept(action)) return false; if (fInitClause != null && !fInitClause.accept(action)) return false; - IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; + IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; if (implicits != null) { for (IASTImplicitName implicit : implicits) { if (!implicit.accept(action)) @@ -247,13 +253,13 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement if (fBody != null && !fBody.accept(action)) return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; if (action.shouldVisitStatements && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; return true; - } + } @Override public void replace(IASTNode child, IASTNode other) { @@ -272,7 +278,8 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement @Override public ICPPExecution getExecution() { - ExecSimpleDeclaration declarationExec = (ExecSimpleDeclaration)((ICPPExecutionOwner) fDeclaration).getExecution(); + ExecSimpleDeclaration declarationExec = (ExecSimpleDeclaration) ((ICPPExecutionOwner) fDeclaration) + .getExecution(); ICPPEvaluation initClauseEval = ((ICPPASTInitializerClause) fInitClause).getEvaluation(); ICPPExecution bodyExec = EvalUtil.getExecutionFromStatement(fBody); IASTImplicitName[] implicitNames = getImplicitNames(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java index e2d1139ed00..e6c4ca6a094 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java @@ -25,7 +25,7 @@ public class CPPASTReferenceOperator extends CPPASTAttributeOwner implements ICP private final boolean fIsRValue; public CPPASTReferenceOperator(boolean isRValueReference) { - fIsRValue= isRValueReference; + fIsRValue = isRValueReference; } @Override @@ -44,12 +44,14 @@ public class CPPASTReferenceOperator extends CPPASTAttributeOwner implements ICP return copy(copy, style); } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitPointerOperators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; } } @@ -59,7 +61,7 @@ public class CPPASTReferenceOperator extends CPPASTAttributeOwner implements ICP if (action.shouldVisitPointerOperators) { if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - } + } return true; - } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java index 32c6ba91a8a..8dc3691d2ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecReturn; public class CPPASTReturnStatement extends CPPASTAttributeOwner implements IASTReturnStatement, ICPPExecutionOwner { private IASTInitializerClause retValue; - public CPPASTReturnStatement() { + public CPPASTReturnStatement() { } public CPPASTReturnStatement(IASTInitializerClause retValue) { @@ -41,8 +41,7 @@ public class CPPASTReturnStatement extends CPPASTAttributeOwner implements IASTR @Override public CPPASTReturnStatement copy(CopyStyle style) { - CPPASTReturnStatement copy = - new CPPASTReturnStatement(retValue == null ? null : retValue.copy(style)); + CPPASTReturnStatement copy = new CPPASTReturnStatement(retValue == null ? null : retValue.copy(style)); return copy(copy, style); } @@ -53,60 +52,68 @@ public class CPPASTReturnStatement extends CPPASTAttributeOwner implements IASTR @Override public IASTExpression getReturnValue() { - if (retValue instanceof IASTExpression) { - return (IASTExpression) retValue; - } - return null; - } + if (retValue instanceof IASTExpression) { + return (IASTExpression) retValue; + } + return null; + } - @Override + @Override public void setReturnValue(IASTExpression returnValue) { - setReturnArgument(returnValue); - } + setReturnArgument(returnValue); + } - @Override + @Override public void setReturnArgument(IASTInitializerClause arg) { - assertNotFrozen(); - retValue = arg; - if (arg != null) { + assertNotFrozen(); + retValue = arg; + if (arg != null) { arg.setParent(this); arg.setPropertyInParent(RETURNVALUE); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } - if (!acceptByAttributeSpecifiers(action)) return false; - if (retValue != null && !retValue.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (retValue != null && !retValue.accept(action)) + return false; - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == retValue) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - retValue = (IASTInitializerClause) other; - return; - } - super.replace(child, other); - } + if (child == retValue) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + retValue = (IASTInitializerClause) other; + return; + } + super.replace(child, other); + } @Override public ICPPExecution getExecution() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java index db9179b8cfa..409127bfaeb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java @@ -21,19 +21,18 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; -public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier - implements ICPPASTSimpleDeclSpecifier { - private int type; - private boolean isSigned; - private boolean isUnsigned; - private boolean isShort; - private boolean isLong; - private boolean isLonglong; - private boolean isComplex; - private boolean isImaginary; +public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTSimpleDeclSpecifier { + private int type; + private boolean isSigned; + private boolean isUnsigned; + private boolean isShort; + private boolean isLong; + private boolean isLonglong; + private boolean isComplex; + private boolean isImaginary; private IASTExpression fDeclTypeExpression; - @Override + @Override public CPPASTSimpleDeclSpecifier copy() { return copy(CopyStyle.withoutLocations); } @@ -45,43 +44,43 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier protected <T extends CPPASTSimpleDeclSpecifier> T copy(T copy, CopyStyle style) { CPPASTSimpleDeclSpecifier target = copy; - target.type = type; - target.isSigned = isSigned; - target.isUnsigned = isUnsigned; - target.isShort = isShort; - target.isLong = isLong; - target.isLonglong= isLonglong; - target.isComplex= isComplex; - target.isImaginary= isImaginary; - if (fDeclTypeExpression != null) { + target.type = type; + target.isSigned = isSigned; + target.isUnsigned = isUnsigned; + target.isShort = isShort; + target.isLong = isLong; + target.isLonglong = isLonglong; + target.isComplex = isComplex; + target.isImaginary = isImaginary; + if (fDeclTypeExpression != null) { copy.setDeclTypeExpression(fDeclTypeExpression.copy(style)); - } - return super.copy(copy, style); - } + } + return super.copy(copy, style); + } /** - * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier - */ - @Override + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier + */ + @Override public int getType() { - return type; - } + return type; + } - @Override + @Override public void setType(int type) { - assertNotFrozen(); - this.type = type; - } + assertNotFrozen(); + this.type = type; + } - @Override + @Override public void setType(Kind kind) { - setType(getType(kind)); - } + setType(getType(kind)); + } - private int getType(Kind kind) { - switch (kind) { - case eBoolean: - return t_bool; + private int getType(Kind kind) { + switch (kind) { + case eBoolean: + return t_bool; case eChar: return t_char; case eWChar: @@ -113,31 +112,31 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier case eNullPtr: // Null pointer type cannot be expressed with a simple decl specifier. break; - } - return t_unspecified; - } + } + return t_unspecified; + } - @Override + @Override public boolean isSigned() { - return isSigned; - } + return isSigned; + } - @Override + @Override public boolean isUnsigned() { - return isUnsigned; - } + return isUnsigned; + } - @Override + @Override public boolean isShort() { - return isShort; - } + return isShort; + } - @Override + @Override public boolean isLong() { - return isLong; - } + return isLong; + } - @Override + @Override public boolean isLongLong() { return isLonglong; } @@ -159,64 +158,67 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier @Override public void setSigned(boolean value) { - assertNotFrozen(); - isSigned = value; - } + assertNotFrozen(); + isSigned = value; + } - @Override + @Override public void setUnsigned(boolean value) { - assertNotFrozen(); - isUnsigned = value; - } + assertNotFrozen(); + isUnsigned = value; + } - @Override + @Override public void setLong(boolean value) { - assertNotFrozen(); - isLong = value; - } + assertNotFrozen(); + isLong = value; + } - @Override + @Override public void setShort(boolean value) { - assertNotFrozen(); - isShort = value; - } + assertNotFrozen(); + isShort = value; + } - @Override + @Override public void setLongLong(boolean value) { - assertNotFrozen(); - isLonglong = value; + assertNotFrozen(); + isLonglong = value; } @Override public void setComplex(boolean value) { - assertNotFrozen(); - isComplex = value; + assertNotFrozen(); + isComplex = value; } @Override public void setImaginary(boolean value) { - assertNotFrozen(); - isImaginary = value; + assertNotFrozen(); + isImaginary = value; } @Override public void setDeclTypeExpression(IASTExpression expression) { - assertNotFrozen(); - fDeclTypeExpression = expression; - if (expression != null) { - expression.setPropertyInParent(DECLTYPE_EXPRESSION); - expression.setParent(this); - } + assertNotFrozen(); + fDeclTypeExpression = expression; + if (expression != null) { + expression.setPropertyInParent(DECLTYPE_EXPRESSION); + expression.setParent(this); + } } @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fDeclTypeExpression != null && !fDeclTypeExpression.accept(action)) @@ -225,22 +227,25 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier if (!acceptByAttributeSpecifiers(action)) return false; - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { if (child == fDeclTypeExpression) { other.setPropertyInParent(child.getPropertyInParent()); other.setParent(child.getParent()); - fDeclTypeExpression= (IASTExpression) other; + fDeclTypeExpression = (IASTExpression) other; return; } super.replace(child, other); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java index 826b412483b..a7d76c5f1ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java @@ -26,8 +26,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecSimpleDeclarat /** * @author jcamelon */ -public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner - implements IASTSimpleDeclaration, ICPPExecutionOwner { +public class CPPASTSimpleDeclaration extends CPPASTAttributeOwner implements IASTSimpleDeclaration, ICPPExecutionOwner { private IASTDeclarator[] declarators; private int declaratorsPos = -1; private IASTDeclSpecifier declSpecifier; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java index 56747615edb..15497c2544b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java @@ -44,9 +44,9 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode private IASTInitializer fInitializer; private ICPPEvaluation fEvaluation; private IASTImplicitDestructorName[] fImplicitDestructorNames; - private IASTImplicitName[] fImplicitNames; // for class types: the constructor being called + private IASTImplicitName[] fImplicitNames; // for class types: the constructor being called - public CPPASTSimpleTypeConstructorExpression() { + public CPPASTSimpleTypeConstructorExpression() { } public CPPASTSimpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec, IASTInitializer init) { @@ -79,47 +79,48 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode @Override public void setDeclSpecifier(ICPPASTDeclSpecifier declSpec) { - assertNotFrozen(); - fDeclSpec = declSpec; - if (declSpec != null) { - declSpec.setParent(this); - declSpec.setPropertyInParent(TYPE_SPECIFIER); - } - } + assertNotFrozen(); + fDeclSpec = declSpec; + if (declSpec != null) { + declSpec.setParent(this); + declSpec.setPropertyInParent(TYPE_SPECIFIER); + } + } @Override public void setInitializer(IASTInitializer initializer) { - assertNotFrozen(); - fInitializer = initializer; - if (initializer != null) { - initializer.setParent(this); - initializer.setPropertyInParent(INITIALIZER); - } - } + assertNotFrozen(); + fInitializer = initializer; + if (initializer != null) { + initializer.setParent(this); + initializer.setPropertyInParent(INITIALIZER); + } + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { final IType type = CPPVisitor.createType(fDeclSpec); - if (fInitializer instanceof ICPPASTConstructorInitializer || fInitializer instanceof ICPPASTInitializerList) { + if (fInitializer instanceof ICPPASTConstructorInitializer + || fInitializer instanceof ICPPASTInitializerList) { boolean usesBracedInitList = (fInitializer instanceof ICPPASTInitializerList); - fEvaluation= new EvalTypeId(type, this, usesBracedInitList, + fEvaluation = new EvalTypeId(type, this, usesBracedInitList, EvalConstructor.extractArguments(fInitializer)); } else { - fEvaluation= EvalFixed.INCOMPLETE; + fEvaluation = EvalFixed.INCOMPLETE; } } return fEvaluation; } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { - return CPPEvaluation.getValueCategory(this); + return CPPEvaluation.getValueCategory(this); } @Override @@ -138,12 +139,15 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fDeclSpec != null && !fDeclSpec.accept(action)) @@ -160,27 +164,30 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode if (fInitializer != null && !fInitializer.accept(action)) return false; - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Deprecated - @Override - public int getSimpleType() { - IType type= getExpressionType(); - if (type instanceof ICPPBasicType) { - ICPPBasicType bt= (ICPPBasicType) type; - Kind kind = bt.getKind(); - switch (kind) { + @Override + public int getSimpleType() { + IType type = getExpressionType(); + if (type instanceof ICPPBasicType) { + ICPPBasicType bt = (ICPPBasicType) type; + Kind kind = bt.getKind(); + switch (kind) { case eBoolean: return t_bool; case eChar: @@ -205,76 +212,76 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode return t_wchar_t; default: break; - } - } + } + } return t_unspecified; - } + } @Deprecated - @Override - public void setSimpleType(int value) { + @Override + public void setSimpleType(int value) { CPPASTSimpleDeclSpecifier declspec = new CPPASTSimpleDeclSpecifier(); - switch (value) { - case t_bool: - declspec.setType(Kind.eBoolean); - break; - case t_char: - declspec.setType(Kind.eChar); - break; - case t_double: - declspec.setType(Kind.eDouble); - break; - case t_float: - declspec.setType(Kind.eFloat); - break; - case t_int: - declspec.setType(Kind.eInt); - break; - case t_long: - declspec.setType(Kind.eInt); - declspec.setLong(true); - break; - case t_short: - declspec.setType(Kind.eInt); - declspec.setShort(true); - break; - case t_signed: - declspec.setType(Kind.eInt); - declspec.setSigned(true); - break; - case t_unsigned: - declspec.setType(Kind.eInt); - declspec.setUnsigned(true); - break; - case t_void: - declspec.setType(Kind.eVoid); - break; - case t_wchar_t: - declspec.setType(Kind.eWChar); - break; - default: - declspec.setType(Kind.eUnspecified); - break; - } - setDeclSpecifier(declspec); - } + switch (value) { + case t_bool: + declspec.setType(Kind.eBoolean); + break; + case t_char: + declspec.setType(Kind.eChar); + break; + case t_double: + declspec.setType(Kind.eDouble); + break; + case t_float: + declspec.setType(Kind.eFloat); + break; + case t_int: + declspec.setType(Kind.eInt); + break; + case t_long: + declspec.setType(Kind.eInt); + declspec.setLong(true); + break; + case t_short: + declspec.setType(Kind.eInt); + declspec.setShort(true); + break; + case t_signed: + declspec.setType(Kind.eInt); + declspec.setSigned(true); + break; + case t_unsigned: + declspec.setType(Kind.eInt); + declspec.setUnsigned(true); + break; + case t_void: + declspec.setType(Kind.eVoid); + break; + case t_wchar_t: + declspec.setType(Kind.eWChar); + break; + default: + declspec.setType(Kind.eUnspecified); + break; + } + setDeclSpecifier(declspec); + } @Deprecated - @Override - public IASTExpression getInitialValue() { - if (fInitializer instanceof ICPPASTConstructorInitializer) { - return ((ICPPASTConstructorInitializer) fInitializer).getExpression(); - } - return null; - } + @Override + public IASTExpression getInitialValue() { + if (fInitializer instanceof ICPPASTConstructorInitializer) { + return ((ICPPASTConstructorInitializer) fInitializer).getExpression(); + } + return null; + } @Deprecated - @Override - public void setInitialValue(IASTExpression expression) { - ICPPASTConstructorInitializer init= new CPPASTConstructorInitializer(); - init.setExpression(expression); - setInitializer(init); - } + @Override + public void setInitialValue(IASTExpression expression) { + ICPPASTConstructorInitializer init = new CPPASTConstructorInitializer(); + init.setExpression(expression); + setInitializer(init); + } @Override public IASTImplicitName[] getImplicitNames() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java index ec655bfa6e5..370f5aa3972 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeTemplateParameter.java @@ -25,16 +25,16 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; */ public class CPPASTSimpleTypeTemplateParameter extends ASTNode implements ICPPASTSimpleTypeTemplateParameter { - private IASTName fName; - private IASTTypeId fTypeId; - private boolean fUsesKeywordClass; - private boolean fIsParameterPack; + private IASTName fName; + private IASTTypeId fTypeId; + private boolean fUsesKeywordClass; + private boolean fIsParameterPack; - public CPPASTSimpleTypeTemplateParameter() { + public CPPASTSimpleTypeTemplateParameter() { } public CPPASTSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) { - fUsesKeywordClass= type == st_class; + fUsesKeywordClass = type == st_class; setName(name); setDefaultType(typeId); } @@ -62,58 +62,61 @@ public class CPPASTSimpleTypeTemplateParameter extends ASTNode implements ICPPAS @Override public void setIsParameterPack(boolean val) { assertNotFrozen(); - fIsParameterPack= val; + fIsParameterPack = val; } @Override public int getParameterType() { - return fUsesKeywordClass ? st_class : st_typename; - } + return fUsesKeywordClass ? st_class : st_typename; + } - @Override + @Override public void setParameterType(int value) { - assertNotFrozen(); - fUsesKeywordClass = value == st_class; - } + assertNotFrozen(); + fUsesKeywordClass = value == st_class; + } - @Override + @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName = name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(PARAMETER_NAME); } - } + } - @Override + @Override public IASTTypeId getDefaultType() { - return fTypeId; - } + return fTypeId; + } - @Override + @Override public void setDefaultType(IASTTypeId typeId) { - assertNotFrozen(); - this.fTypeId = typeId; - if (typeId != null) { + assertNotFrozen(); + this.fTypeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(DEFAULT_TYPE); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitTemplateParameters) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default : break; - } + if (action.shouldVisitTemplateParameters) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } if (fName != null && !fName.accept(action)) @@ -124,8 +127,8 @@ public class CPPASTSimpleTypeTemplateParameter extends ASTNode implements ICPPAS if (action.shouldVisitTemplateParameters && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTStaticAssertionDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTStaticAssertionDeclaration.java index 3b3a317085c..ba8f8857db6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTStaticAssertionDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTStaticAssertionDeclaration.java @@ -21,14 +21,15 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTStaticAssertDeclaration; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; -public class CPPASTStaticAssertionDeclaration extends ASTNode implements ICPPASTStaticAssertDeclaration, IASTAmbiguityParent { +public class CPPASTStaticAssertionDeclaration extends ASTNode + implements ICPPASTStaticAssertDeclaration, IASTAmbiguityParent { private IASTExpression fCondition; private final ICPPASTLiteralExpression fMessage; /** * Constructor for C++17 static_assert with only a condition. - * + * * @param condition The condition of the static assertion */ public CPPASTStaticAssertionDeclaration(IASTExpression condition) { @@ -36,15 +37,15 @@ public class CPPASTStaticAssertionDeclaration extends ASTNode implements ICPPAST } public CPPASTStaticAssertionDeclaration(IASTExpression condition, ICPPASTLiteralExpression message) { - fCondition= condition; - fMessage= message; - if (condition != null) { + fCondition = condition; + fMessage = message; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITION); } - if (message != null) { - message.setParent(this); - message.setPropertyInParent(MESSAGE); + if (message != null) { + message.setParent(this); + message.setPropertyInParent(MESSAGE); } } @@ -58,7 +59,6 @@ public class CPPASTStaticAssertionDeclaration extends ASTNode implements ICPPAST return fMessage; } - @Override public CPPASTStaticAssertionDeclaration copy() { return copy(CopyStyle.withoutLocations); @@ -68,18 +68,19 @@ public class CPPASTStaticAssertionDeclaration extends ASTNode implements ICPPAST public CPPASTStaticAssertionDeclaration copy(CopyStyle style) { final IASTExpression condCopy = fCondition == null ? null : fCondition.copy(style); final ICPPASTLiteralExpression msgCopy = fMessage == null ? null : fMessage.copy(style); - CPPASTStaticAssertionDeclaration copy = new CPPASTStaticAssertionDeclaration(condCopy, - msgCopy); + CPPASTStaticAssertionDeclaration copy = new CPPASTStaticAssertionDeclaration(condCopy, msgCopy); return copy(copy, style); } - @Override + @Override public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclarations) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } } if (fCondition != null && !fCondition.accept(action)) @@ -89,15 +90,15 @@ public class CPPASTStaticAssertionDeclaration extends ASTNode implements ICPPAST if (action.shouldVisitDeclarations && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == fCondition) { - fCondition= (IASTExpression) other; - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - } + if (child == fCondition) { + fCondition = (IASTExpression) other; + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java index 8734bbf1995..26daf6cbd3d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java @@ -34,11 +34,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecSwitch; public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPASTSwitchStatement, ICPPExecutionOwner { private IScope scope; private IASTStatement initStatement; - private IASTExpression controllerExpression; - private IASTDeclaration controllerDeclaration; - private IASTStatement body; + private IASTExpression controllerExpression; + private IASTDeclaration controllerDeclaration; + private IASTStatement body; - public CPPASTSwitchStatement() { + public CPPASTSwitchStatement() { } public CPPASTSwitchStatement(IASTDeclaration controller, IASTStatement body) { @@ -46,12 +46,12 @@ public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPA setBody(body); } - public CPPASTSwitchStatement(IASTExpression controller, IASTStatement body) { + public CPPASTSwitchStatement(IASTExpression controller, IASTStatement body) { setControllerExpression(controller); setBody(body); } - @Override + @Override public CPPASTSwitchStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -59,12 +59,9 @@ public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPA @Override public CPPASTSwitchStatement copy(CopyStyle style) { CPPASTSwitchStatement copy = new CPPASTSwitchStatement(); - copy.setInitializerStatement(initStatement == null ? - null : initStatement.copy(style)); - copy.setControllerDeclaration(controllerDeclaration == null ? - null : controllerDeclaration.copy(style)); - copy.setControllerExpression(controllerExpression == null ? - null : controllerExpression.copy(style)); + copy.setInitializerStatement(initStatement == null ? null : initStatement.copy(style)); + copy.setControllerDeclaration(controllerDeclaration == null ? null : controllerDeclaration.copy(style)); + copy.setControllerExpression(controllerExpression == null ? null : controllerExpression.copy(style)); copy.setBody(body == null ? null : body.copy(style)); return copy(copy, style); } @@ -76,9 +73,9 @@ public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPA @Override public void setInitializerStatement(IASTStatement statement) { - assertNotFrozen(); - this.initStatement = statement; - if (statement != null) { + assertNotFrozen(); + this.initStatement = statement; + if (statement != null) { statement.setParent(this); statement.setPropertyInParent(INIT_STATEMENT); statement = null; @@ -87,62 +84,73 @@ public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPA @Override public IASTExpression getControllerExpression() { - return controllerExpression; - } + return controllerExpression; + } - @Override + @Override public void setControllerExpression(IASTExpression controller) { - assertNotFrozen(); - this.controllerExpression = controller; - if (controller != null) { + assertNotFrozen(); + this.controllerExpression = controller; + if (controller != null) { controller.setParent(this); controller.setPropertyInParent(CONTROLLER_EXP); - controllerDeclaration= null; + controllerDeclaration = null; } - } + } - @Override + @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement body) { - assertNotFrozen(); - this.body = body; - if (body != null) { + assertNotFrozen(); + this.body = body; + if (body != null) { body.setParent(this); body.setPropertyInParent(BODY); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (initStatement != null && !initStatement.accept(action)) return false; - if (controllerExpression != null && !controllerExpression.accept(action)) return false; - if (controllerDeclaration != null && !controllerDeclaration.accept(action)) return false; - if (body != null && !body.accept(action)) return false; - - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (!acceptByAttributeSpecifiers(action)) + return false; + if (initStatement != null && !initStatement.accept(action)) + return false; + if (controllerExpression != null && !controllerExpression.accept(action)) + return false; + if (controllerDeclaration != null && !controllerDeclaration.accept(action)) + return false; + if (body != null && !body.accept(action)) + return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { if (initStatement == child) { other.setParent(child.getParent()); @@ -166,28 +174,28 @@ public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPA super.replace(child, other); } - @Override + @Override public IASTDeclaration getControllerDeclaration() { - return controllerDeclaration; - } + return controllerDeclaration; + } - @Override + @Override public void setControllerDeclaration(IASTDeclaration d) { - assertNotFrozen(); - controllerDeclaration = d; - if (d != null) { + assertNotFrozen(); + controllerDeclaration = d; + if (d != null) { d.setParent(this); d.setPropertyInParent(CONTROLLER_DECLARATION); - controllerExpression= null; + controllerExpression = null; } - } + } @Override public IScope getScope() { if (scope == null) - scope = new CPPBlockScope(this); - return scope; - } + scope = new CPPBlockScope(this); + return scope; + } @Override public ICPPExecution getExecution() { @@ -195,13 +203,15 @@ public class CPPASTSwitchStatement extends CPPASTAttributeOwner implements ICPPA ICPPASTExpression controllerExpr = (ICPPASTExpression) getControllerExpression(); ICPPExecutionOwner controllerDecl = (ICPPExecutionOwner) getControllerDeclaration(); ICPPEvaluation controllerExprEval = controllerExpr != null ? controllerExpr.getEvaluation() : null; - ExecSimpleDeclaration controllerDeclExec = controllerDecl != null ? (ExecSimpleDeclaration) controllerDecl.getExecution() : null; + ExecSimpleDeclaration controllerDeclExec = controllerDecl != null + ? (ExecSimpleDeclaration) controllerDecl.getExecution() + : null; IASTStatement[] bodyStmts = null; if (body instanceof ICPPASTCompoundStatement) { ICPPASTCompoundStatement compoundStmt = (ICPPASTCompoundStatement) body; bodyStmts = compoundStmt.getStatements(); } else { - bodyStmts = new IASTStatement[]{body}; + bodyStmts = new IASTStatement[] { body }; } ICPPExecution[] bodyStmtExecutions = new ICPPExecution[bodyStmts.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java index 6ae368e7b38..d048194b3da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java @@ -29,15 +29,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; */ public class CPPASTTemplateDeclaration extends ASTNode implements ICPPASTInternalTemplateDeclaration, IASTAmbiguityParent { - private boolean exported; - private byte isAssociatedWithLastName= -1; - private short nestingLevel= -1; - private IASTDeclaration declaration; - private ICPPTemplateScope templateScope; - private ICPPASTTemplateParameter[] parameters; - private int parametersPos= -1; - - public CPPASTTemplateDeclaration() { + private boolean exported; + private byte isAssociatedWithLastName = -1; + private short nestingLevel = -1; + private IASTDeclaration declaration; + private ICPPTemplateScope templateScope; + private ICPPASTTemplateParameter[] parameters; + private int parametersPos = -1; + + public CPPASTTemplateDeclaration() { } public CPPASTTemplateDeclaration(IASTDeclaration declaration) { @@ -61,46 +61,47 @@ public class CPPASTTemplateDeclaration extends ASTNode @Override public boolean isExported() { - return exported; - } + return exported; + } - @Override + @Override public void setExported(boolean value) { - assertNotFrozen(); - exported = value; - } + assertNotFrozen(); + exported = value; + } - @Override + @Override public IASTDeclaration getDeclaration() { - return declaration; - } + return declaration; + } - @Override + @Override public void setDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - this.declaration = declaration; - if (declaration != null) { + assertNotFrozen(); + this.declaration = declaration; + if (declaration != null) { declaration.setParent(this); declaration.setPropertyInParent(OWNED_DECLARATION); } - } + } - @Override + @Override public ICPPASTTemplateParameter[] getTemplateParameters() { - if (parameters == null) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; - parameters = ArrayUtil.trimAt(ICPPASTTemplateParameter.class, parameters, parametersPos); - return parameters; - } + if (parameters == null) + return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; + parameters = ArrayUtil.trimAt(ICPPASTTemplateParameter.class, parameters, parametersPos); + return parameters; + } - @Override + @Override public void addTemplateParameter(ICPPASTTemplateParameter parm) { - assertNotFrozen(); - if (parm != null) { - parameters = ArrayUtil.appendAt(ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm); - parm.setParent(this); + assertNotFrozen(); + if (parm != null) { + parameters = ArrayUtil.appendAt(ICPPASTTemplateParameter.class, parameters, ++parametersPos, parm); + parm.setParent(this); parm.setPropertyInParent(PARAMETER); - } - } + } + } @Deprecated @Override @@ -108,32 +109,40 @@ public class CPPASTTemplateDeclaration extends ASTNode addTemplateParameter(param); } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - ICPPASTTemplateParameter[] params = getTemplateParameters(); - for (int i = 0; i < params.length; i++) { - if (!params[i].accept(action)) return false; - } - - if (declaration != null && !declaration.accept(action)) return false; + ICPPASTTemplateParameter[] params = getTemplateParameters(); + for (int i = 0; i < params.length; i++) { + if (!params[i].accept(action)) + return false; + } - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (declaration != null && !declaration.accept(action)) + return false; + + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public ICPPTemplateScope getScope() { @@ -142,14 +151,14 @@ public class CPPASTTemplateDeclaration extends ASTNode return templateScope; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (declaration == child) { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - declaration = (IASTDeclaration) other; - } - } + if (declaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + declaration = (IASTDeclaration) other; + } + } @Override public short getNestingLevel() { @@ -171,12 +180,12 @@ public class CPPASTTemplateDeclaration extends ASTNode @Override public void setAssociatedWithLastName(boolean value) { - isAssociatedWithLastName= value ? (byte) 1 : (byte) 0; + isAssociatedWithLastName = value ? (byte) 1 : (byte) 0; } @Override public void setNestingLevel(short level) { assert level >= 0; - nestingLevel= level; + nestingLevel = level; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java index 95bf114ca08..86ff521f3d3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java @@ -45,8 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.NameOrTemplateIDVariants.Var /** * Models expression variants for the ambiguity of a template id. */ -public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode - implements IASTAmbiguousExpression, ICPPASTExpression { +public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode implements IASTAmbiguousExpression, ICPPASTExpression { private final BinaryOperator fEndOperator; private final BranchPoint fVariants; private IASTNode[] fNodes; @@ -54,23 +53,23 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode public CPPASTTemplateIDAmbiguity(AbstractGNUSourceCodeParser parser, BinaryOperator endOperator, BranchPoint variants) { - fParser= parser; - fEndOperator= endOperator; - fVariants= variants; + fParser = parser; + fEndOperator = endOperator; + fVariants = variants; } @Override protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) { - final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); - IASTNode nodeToReplace= this; + final IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent(); + IASTNode nodeToReplace = this; // Try all variants and under the ones with correct template-ids select the one with // the most template-ids. - int minOffset= -1; - for (BranchPoint v= fVariants; v != null; v= v.getNext()) { - Variant selected= null; - int bestCount= 0; - for (Variant q= v.getFirstVariant(); q != null ; q= q.getNext()) { + int minOffset = -1; + for (BranchPoint v = fVariants; v != null; v = v.getNext()) { + Variant selected = null; + int bestCount = 0; + for (Variant q = v.getFirstVariant(); q != null; q = q.getNext()) { final IASTName[] templateNames = q.getTemplateNames(); if (templateNames.length > bestCount) { // Don't check branch-points inside of a selected variant. @@ -80,19 +79,19 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode // Setup the AST to use the alternative. owner.replace(nodeToReplace, expression); - nodeToReplace= resolveNestedAmbiguities(expression, resolver); + nodeToReplace = resolveNestedAmbiguities(expression, resolver); - int count= checkNames(templateNames); + int count = checkNames(templateNames); if (count > bestCount) { - selected= q; - bestCount= count; + selected = q; + bestCount = count; } } } // Adjust the operator sequence. if (selected != null) { - minOffset= selected.getRightOffset(); + minOffset = selected.getRightOffset(); BinaryOperator targetOp = selected.getTargetOperator(); if (targetOp != null) { targetOp.exchange(selected.getExpression()); @@ -114,7 +113,7 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode } private int checkNames(final IASTName[] templateNames) { - int count= 0; + int count = 0; for (IASTName templateName : templateNames) { if (templateName.getTranslationUnit() != null) { // It's sufficient to perform the first phase of binding resolution here, @@ -122,7 +121,7 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode // The second phase of binding resolution, when performed for an incorrect // variant, can cause incorrect bindings to be cached in places where they // are hard to clear. - IBinding b= templateName.resolvePreBinding(); + IBinding b = templateName.resolvePreBinding(); if (b instanceof IProblemBinding) { if (!containsFunctionTemplate(((IProblemBinding) b).getCandidateBindings())) return -1; @@ -141,8 +140,8 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode private boolean containsFunctionTemplate(IBinding[] candidateBindings) { for (IBinding cand : candidateBindings) { - if (cand instanceof ICPPFunctionTemplate || - (cand instanceof ICPPFunction && cand instanceof ICPPSpecialization)) { + if (cand instanceof ICPPFunctionTemplate + || (cand instanceof ICPPFunction && cand instanceof ICPPSpecialization)) { return true; } } @@ -152,14 +151,14 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode @Override public IASTNode[] getNodes() { if (fNodes == null) { - List<IASTNode> nl= new ArrayList<>(); - BinaryOperator op= fEndOperator; + List<IASTNode> nl = new ArrayList<>(); + BinaryOperator op = fEndOperator; while (op != null) { nl.add(op.getExpression()); - op= op.getNext(); + op = op.getNext(); } Collections.reverse(nl); - fNodes= nl.toArray(new IASTNode[nl.size()]); + fNodes = nl.toArray(new IASTNode[nl.size()]); } return fNodes; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index 7efa953e635..a63501997c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -43,9 +43,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; */ public class CPPASTTemplateId extends CPPASTNameBase implements ICPPASTTemplateId, IASTAmbiguityParent { private IASTName templateName; - private IASTNode[] templateArguments = IASTNode.EMPTY_NODE_ARRAY; + private IASTNode[] templateArguments = IASTNode.EMPTY_NODE_ARRAY; - public CPPASTTemplateId() { + public CPPASTTemplateId() { } public CPPASTTemplateId(IASTName templateName) { @@ -59,8 +59,7 @@ public class CPPASTTemplateId extends CPPASTNameBase implements ICPPASTTemplateI @Override public CPPASTTemplateId copy(CopyStyle style) { - CPPASTTemplateId copy = - new CPPASTTemplateId(templateName == null ? null : templateName.copy(style)); + CPPASTTemplateId copy = new CPPASTTemplateId(templateName == null ? null : templateName.copy(style)); for (IASTNode arg : getTemplateArguments()) { copy.internalAddTemplateArgument(arg == null ? null : arg.copy(style)); } @@ -79,122 +78,130 @@ public class CPPASTTemplateId extends CPPASTNameBase implements ICPPASTTemplateI @Override public IASTName getTemplateName() { - return templateName; - } + return templateName; + } - @Override + @Override public void setTemplateName(IASTName name) { - assertNotFrozen(); - assert !(name instanceof ICPPASTQualifiedName) && !(name instanceof ICPPASTTemplateId); - templateName = name; - if (name != null) { + assertNotFrozen(); + assert !(name instanceof ICPPASTQualifiedName) && !(name instanceof ICPPASTTemplateId); + templateName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(TEMPLATE_NAME); } - } + } - private void internalAddTemplateArgument(IASTNode node) { + private void internalAddTemplateArgument(IASTNode node) { assertNotFrozen(); - templateArguments = ArrayUtil.append(templateArguments, node); - if (node != null) { - node.setParent(this); - node.setPropertyInParent(TEMPLATE_ID_ARGUMENT); - } - } - - @Override + templateArguments = ArrayUtil.append(templateArguments, node); + if (node != null) { + node.setParent(this); + node.setPropertyInParent(TEMPLATE_ID_ARGUMENT); + } + } + + @Override public void addTemplateArgument(IASTTypeId typeId) { - internalAddTemplateArgument(typeId); - } + internalAddTemplateArgument(typeId); + } - @Override + @Override public void addTemplateArgument(IASTExpression expression) { - internalAddTemplateArgument(expression); - } + internalAddTemplateArgument(expression); + } - @Override + @Override public void addTemplateArgument(ICPPASTAmbiguousTemplateArgument ata) { - internalAddTemplateArgument(ata); - } + internalAddTemplateArgument(ata); + } - @Override + @Override public IASTNode[] getTemplateArguments() { - return ArrayUtil.trim(templateArguments); - } + return ArrayUtil.trim(templateArguments); + } - @Override + @Override protected IBinding createIntermediateBinding() { - return CPPTemplates.createBinding(this); - } + return CPPTemplates.createBinding(this); + } - @Override + @Override public char[] toCharArray() { - assert sAllowNameComputation; - - StringBuilder buf= new StringBuilder(); - buf.append(getTemplateName().toCharArray()); - buf.append('<'); - boolean needComma= false; - boolean cleanupWhitespace= false; - final IASTNode[] args= getTemplateArguments(); - for (IASTNode arg : args) { - if (needComma) - buf.append(", "); //$NON-NLS-1$ - needComma= true; - IASTNodeLocation[] nodeLocs = arg.getNodeLocations(); - if (nodeLocs.length == 1 && nodeLocs[0] instanceof IASTFileLocation) { - buf.append(arg.getRawSignature()); - cleanupWhitespace= true; - } else if (arg instanceof IASTExpression) { - IValue value= ValueFactory.create((IASTExpression) arg); - if (value != IntegralValue.UNKNOWN && !IntegralValue.isDependentValue(value)) { - buf.append(value.getSignature()); - } else { - buf.append(arg.getRawSignature()); - cleanupWhitespace= true; - } - } else if (arg instanceof IASTTypeId) { - IType type= CPPVisitor.createType((IASTTypeId) arg); - if (type instanceof ISemanticProblem) { - buf.append(arg.getRawSignature()); - } else { - ASTTypeUtil.appendType(type, false, buf); - } - } - if (cleanupWhitespace) - WHITESPACE_SEQ.matcher(buf).replaceAll(" "); //$NON-NLS-1$ - } - buf.append('>'); - final int len= buf.length(); - final char[] result= new char[len]; - buf.getChars(0, len, result, 0); - return result; - } - - @Override + assert sAllowNameComputation; + + StringBuilder buf = new StringBuilder(); + buf.append(getTemplateName().toCharArray()); + buf.append('<'); + boolean needComma = false; + boolean cleanupWhitespace = false; + final IASTNode[] args = getTemplateArguments(); + for (IASTNode arg : args) { + if (needComma) + buf.append(", "); //$NON-NLS-1$ + needComma = true; + IASTNodeLocation[] nodeLocs = arg.getNodeLocations(); + if (nodeLocs.length == 1 && nodeLocs[0] instanceof IASTFileLocation) { + buf.append(arg.getRawSignature()); + cleanupWhitespace = true; + } else if (arg instanceof IASTExpression) { + IValue value = ValueFactory.create((IASTExpression) arg); + if (value != IntegralValue.UNKNOWN && !IntegralValue.isDependentValue(value)) { + buf.append(value.getSignature()); + } else { + buf.append(arg.getRawSignature()); + cleanupWhitespace = true; + } + } else if (arg instanceof IASTTypeId) { + IType type = CPPVisitor.createType((IASTTypeId) arg); + if (type instanceof ISemanticProblem) { + buf.append(arg.getRawSignature()); + } else { + ASTTypeUtil.appendType(type, false, buf); + } + } + if (cleanupWhitespace) + WHITESPACE_SEQ.matcher(buf).replaceAll(" "); //$NON-NLS-1$ + } + buf.append('>'); + final int len = buf.length(); + final char[] result = new char[len]; + buf.getChars(0, len, result, 0); + return result; + } + + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitNames) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitNames) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + if (templateName != null && !templateName.accept(action)) + return false; + + IASTNode[] nodes = getTemplateArguments(); + for (int i = 0; i < nodes.length; i++) { + if (!nodes[i].accept(action)) + return false; } - if (templateName != null && !templateName.accept(action)) return false; - - IASTNode[] nodes = getTemplateArguments(); - for (int i = 0; i < nodes.length; i++) { - if (!nodes[i].accept(action)) return false; - } - if (action.shouldVisitNames) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitNames) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { @@ -203,16 +210,16 @@ public class CPPASTTemplateId extends CPPASTNameBase implements ICPPASTTemplateI return r_unclear; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (templateArguments == null) - return; - for (int i = 0; i < templateArguments.length; ++i) { - if (child == templateArguments[i]) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - templateArguments[i] = other; - } - } - } + if (templateArguments == null) + return; + for (int i = 0; i < templateArguments.length; ++i) { + if (child == templateArguments[i]) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + templateArguments[i] = other; + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateName.java index ffe27b9ee22..bb81e266a65 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateName.java @@ -31,8 +31,7 @@ public class CPPASTTemplateName extends CPPASTName implements ICPPASTTemplateNam @Override public CPPASTTemplateName copy(CopyStyle style) { - CPPASTTemplateName copy = new CPPASTTemplateName( - toCharArray() == null ? null : toCharArray().clone()); + CPPASTTemplateName copy = new CPPASTTemplateName(toCharArray() == null ? null : toCharArray().clone()); return copy(copy, style); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java index 2054974a0ce..13766a3aa1f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateSpecialization.java @@ -27,16 +27,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** * Node for template specialization syntax. */ -public class CPPASTTemplateSpecialization extends ASTNode implements - ICPPASTTemplateSpecialization, ICPPASTInternalTemplateDeclaration, IASTAmbiguityParent { +public class CPPASTTemplateSpecialization extends ASTNode + implements ICPPASTTemplateSpecialization, ICPPASTInternalTemplateDeclaration, IASTAmbiguityParent { - private IASTDeclaration declaration; - private ICPPTemplateScope templateScope; - private short nestingLevel= -1; - private byte isAssociatedWithLastName= -1; + private IASTDeclaration declaration; + private ICPPTemplateScope templateScope; + private short nestingLevel = -1; + private byte isAssociatedWithLastName = -1; - - public CPPASTTemplateSpecialization() { + public CPPASTTemplateSpecialization() { } public CPPASTTemplateSpecialization(IASTDeclaration declaration) { @@ -57,40 +56,47 @@ public class CPPASTTemplateSpecialization extends ASTNode implements @Override public IASTDeclaration getDeclaration() { - return declaration; - } + return declaration; + } - @Override + @Override public void setDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); - this.declaration = declaration; - if (declaration != null) { + assertNotFrozen(); + this.declaration = declaration; + if (declaration != null) { declaration.setParent(this); declaration.setPropertyInParent(ICPPASTTemplateSpecialization.OWNED_DECLARATION); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declaration != null && !declaration.accept(action)) return false; - - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (declaration != null && !declaration.accept(action)) + return false; + + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public boolean isExported() { @@ -99,7 +105,7 @@ public class CPPASTTemplateSpecialization extends ASTNode implements @Override public void setExported(boolean value) { - assertNotFrozen(); + assertNotFrozen(); } @Override @@ -109,7 +115,7 @@ public class CPPASTTemplateSpecialization extends ASTNode implements @Override public void addTemplateParameter(ICPPASTTemplateParameter param) { - assertNotFrozen(); + assertNotFrozen(); } @Override @@ -125,14 +131,14 @@ public class CPPASTTemplateSpecialization extends ASTNode implements return templateScope; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (declaration == child) { - other.setParent(child.getParent()); - other.setPropertyInParent(child.getPropertyInParent()); - declaration = (IASTDeclaration) other; - } - } + if (declaration == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); + declaration = (IASTDeclaration) other; + } + } @Override public short getNestingLevel() { @@ -154,12 +160,12 @@ public class CPPASTTemplateSpecialization extends ASTNode implements @Override public void setAssociatedWithLastName(boolean value) { - isAssociatedWithLastName= value ? (byte) 1 : (byte) 0; + isAssociatedWithLastName = value ? (byte) 1 : (byte) 0; } @Override public void setNestingLevel(short level) { assert level >= 0; - nestingLevel= level; + nestingLevel = level; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java index f44cd1daa81..d79b767e5c5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java @@ -28,17 +28,17 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Template template parameter */ -public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements - ICPPASTTemplatedTypeTemplateParameter, IASTAmbiguityParent { - - private ICPPASTTemplateParameter [] fNestedParameters = null; - private boolean fIsParameterPack; - private boolean fUsesKeywordClass; - private IASTName fName; - private IASTExpression fDefaultValue; +public class CPPASTTemplatedTypeTemplateParameter extends ASTNode + implements ICPPASTTemplatedTypeTemplateParameter, IASTAmbiguityParent { + + private ICPPASTTemplateParameter[] fNestedParameters = null; + private boolean fIsParameterPack; + private boolean fUsesKeywordClass; + private IASTName fName; + private IASTExpression fDefaultValue; private CPPTemplateTemplateParameterScope fScope; - public CPPASTTemplatedTypeTemplateParameter() { + public CPPASTTemplatedTypeTemplateParameter() { } public CPPASTTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue) { @@ -86,18 +86,16 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements public void addTemplateParameter(ICPPASTTemplateParameter param) { assertNotFrozen(); if (param != null) { - fNestedParameters = ArrayUtil.append(ICPPASTTemplateParameter.class, - fNestedParameters, param); + fNestedParameters = ArrayUtil.append(ICPPASTTemplateParameter.class, fNestedParameters, param); param.setParent(this); param.setPropertyInParent(PARAMETER); } } - - @Override + @Override public void setIsParameterPack(boolean val) { - assertNotFrozen(); - fIsParameterPack= val; + assertNotFrozen(); + fIsParameterPack = val; } @Override @@ -118,45 +116,48 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements @Override public IASTName getName() { - return fName; - } + return fName; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.fName =name; - if (name != null) { + assertNotFrozen(); + this.fName = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(PARAMETER_NAME); } - } + } - @Override + @Override public IASTExpression getDefaultValue() { - return fDefaultValue; - } + return fDefaultValue; + } - @Override + @Override public void setDefaultValue(IASTExpression expression) { - assertNotFrozen(); - this.fDefaultValue = expression; - if (expression != null) { + assertNotFrozen(); + this.fDefaultValue = expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(DEFAULT_VALUE); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitTemplateParameters) { + if (action.shouldVisitTemplateParameters) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - ICPPASTTemplateParameter [] ps = getTemplateParameters(); + ICPPASTTemplateParameter[] ps = getTemplateParameters(); for (int i = 0; i < ps.length; i++) { if (!ps[i].accept(action)) return false; @@ -170,7 +171,7 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements return false; return true; - } + } @Override public int getRoleForName(IASTName n) { @@ -179,20 +180,19 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements return r_unclear; } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == fDefaultValue) - { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - fDefaultValue = (IASTExpression) other; - } - } + if (child == fDefaultValue) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + fDefaultValue = (IASTExpression) other; + } + } @Override public ICPPScope asScope() { if (fScope == null) { - fScope= new CPPTemplateTemplateParameterScope(this); + fScope = new CPPTemplateTemplateParameterScope(this); } return fScope; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 0a970e03537..7384b9b380b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -52,8 +52,8 @@ import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent; * C++-specific implementation of a translation-unit. */ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPASTTranslationUnit, IASTAmbiguityParent { - private CPPNamespaceScope fScope; - private ICPPNamespace fBinding; + private CPPNamespaceScope fScope; + private ICPPNamespace fBinding; private final CPPScopeMapper fScopeMapper; private CPPASTAmbiguityResolver fAmbiguityResolver; @@ -61,13 +61,13 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST private final Map<ICPPClassType, FinalOverriderMap> fFinalOverriderMapCache = new HashMap<>(); // Cache for type instantiations. This is currently only used for instantiations of // alias template instances, but its use could potentially be expanded to cover other - // instantiations. Note that class template instances are already cached by the - // template definition, so we wouldn't want to double-cache those. (But we could e.g. + // instantiations. Note that class template instances are already cached by the + // template definition, so we wouldn't want to double-cache those. (But we could e.g. // cache instantiations of function types if we found it worthwhile.) private final Map<TypeInstantiationRequest, IType> fInstantiationCache = new HashMap<>(); public CPPASTTranslationUnit() { - fScopeMapper= new CPPScopeMapper(this); + fScopeMapper = new CPPScopeMapper(this); } @Override @@ -81,107 +81,112 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST return copy(copy, style); } - @Override + @Override public CPPNamespaceScope getScope() { - if (fScope == null) { - fScope = new CPPNamespaceScope(this); + if (fScope == null) { + fScope = new CPPNamespaceScope(this); addBuiltinOperators(fScope); - } - return fScope; - } + } + return fScope; + } private void addBuiltinOperators(CPPScope theScope) { - // void - IType cpp_void = new CPPBasicType(Kind.eVoid, 0); - // void* - IType cpp_void_p = new CPPPointerType(new CPPQualifierType(new CPPBasicType(Kind.eVoid, 0), false, false), new CPPASTPointer()); - // size_t // assumed: unsigned long int - IType cpp_size_t = new CPPBasicType(Kind.eInt, IBasicType.IS_LONG & IBasicType.IS_UNSIGNED); + // void + IType cpp_void = new CPPBasicType(Kind.eVoid, 0); + // void* + IType cpp_void_p = new CPPPointerType(new CPPQualifierType(new CPPBasicType(Kind.eVoid, 0), false, false), + new CPPASTPointer()); + // size_t // assumed: unsigned long int + IType cpp_size_t = new CPPBasicType(Kind.eInt, IBasicType.IS_LONG & IBasicType.IS_UNSIGNED); // void* operator new(std::size_t); - IBinding temp = null; - IType[] newParms = new IType[1]; - newParms[0] = cpp_size_t; - ICPPFunctionType newFunctionType = new CPPFunctionType(cpp_void_p, newParms); - ICPPParameter[] newTheParms = new ICPPParameter[1]; - newTheParms[0] = new CPPBuiltinParameter(newParms[0]); - temp = new CPPImplicitFunction(OverloadableOperator.NEW.toCharArray(), theScope, newFunctionType, newTheParms, false, false); - theScope.addBinding(temp); + IBinding temp = null; + IType[] newParms = new IType[1]; + newParms[0] = cpp_size_t; + ICPPFunctionType newFunctionType = new CPPFunctionType(cpp_void_p, newParms); + ICPPParameter[] newTheParms = new ICPPParameter[1]; + newTheParms[0] = new CPPBuiltinParameter(newParms[0]); + temp = new CPPImplicitFunction(OverloadableOperator.NEW.toCharArray(), theScope, newFunctionType, newTheParms, + false, false); + theScope.addBinding(temp); // void* operator new[](std::size_t); temp = null; - temp = new CPPImplicitFunction(OverloadableOperator.NEW_ARRAY.toCharArray(), theScope, newFunctionType, newTheParms, false, false); - theScope.addBinding(temp); + temp = new CPPImplicitFunction(OverloadableOperator.NEW_ARRAY.toCharArray(), theScope, newFunctionType, + newTheParms, false, false); + theScope.addBinding(temp); // void operator delete(void*); - temp = null; - IType[] deleteParms = new IType[1]; - deleteParms[0] = cpp_void_p; - ICPPFunctionType deleteFunctionType = new CPPFunctionType(cpp_void, deleteParms); - ICPPParameter[] deleteTheParms = new ICPPParameter[1]; - deleteTheParms[0] = new CPPBuiltinParameter(deleteParms[0]); - temp = new CPPImplicitFunction(OverloadableOperator.DELETE.toCharArray(), theScope, - deleteFunctionType, deleteTheParms, false, false); - theScope.addBinding(temp); + temp = null; + IType[] deleteParms = new IType[1]; + deleteParms[0] = cpp_void_p; + ICPPFunctionType deleteFunctionType = new CPPFunctionType(cpp_void, deleteParms); + ICPPParameter[] deleteTheParms = new ICPPParameter[1]; + deleteTheParms[0] = new CPPBuiltinParameter(deleteParms[0]); + temp = new CPPImplicitFunction(OverloadableOperator.DELETE.toCharArray(), theScope, deleteFunctionType, + deleteTheParms, false, false); + theScope.addBinding(temp); // void operator delete[](void*); temp = null; - temp = new CPPImplicitFunction(OverloadableOperator.DELETE_ARRAY.toCharArray(), theScope, - deleteFunctionType, deleteTheParms, false, false); - theScope.addBinding(temp); + temp = new CPPImplicitFunction(OverloadableOperator.DELETE_ARRAY.toCharArray(), theScope, deleteFunctionType, + deleteTheParms, false, false); + theScope.addBinding(temp); } - @Override + @Override public IASTName[] getDeclarationsInAST(IBinding binding) { - if (binding instanceof IMacroBinding) { - return getMacroDefinitionsInAST((IMacroBinding) binding); - } - return CPPVisitor.getDeclarations(this, binding); - } - - @Override - public IASTName[] getDefinitionsInAST(IBinding binding) { - return getDefinitionsInAST(binding, false); - } - - @Override + if (binding instanceof IMacroBinding) { + return getMacroDefinitionsInAST((IMacroBinding) binding); + } + return CPPVisitor.getDeclarations(this, binding); + } + + @Override + public IASTName[] getDefinitionsInAST(IBinding binding) { + return getDefinitionsInAST(binding, false); + } + + @Override public IASTName[] getDefinitionsInAST(IBinding binding, boolean permissive) { - if (binding instanceof IMacroBinding) { - return getMacroDefinitionsInAST((IMacroBinding) binding); - } - IASTName[] names = CPPVisitor.getDeclarations(this, binding, permissive); - for (int i = 0; i < names.length; i++) { - if (!names[i].isDefinition()) - names[i] = null; - } - // nulls can be anywhere, don't use trim() - return ArrayUtil.removeNulls(IASTName.class, names); - } - - @Override + if (binding instanceof IMacroBinding) { + return getMacroDefinitionsInAST((IMacroBinding) binding); + } + IASTName[] names = CPPVisitor.getDeclarations(this, binding, permissive); + for (int i = 0; i < names.length; i++) { + if (!names[i].isDefinition()) + names[i] = null; + } + // nulls can be anywhere, don't use trim() + return ArrayUtil.removeNulls(IASTName.class, names); + } + + @Override public IASTName[] getReferences(IBinding binding) { - if (binding instanceof IMacroBinding) { - return getMacroReferencesInAST((IMacroBinding) binding); - } - return CPPVisitor.getReferences(this, binding); - } + if (binding instanceof IMacroBinding) { + return getMacroReferencesInAST((IMacroBinding) binding); + } + return CPPVisitor.getReferences(this, binding); + } - @Override + @Override public ICPPNamespace getGlobalNamespace() { - if (fBinding == null) - fBinding = new CPPNamespace(this); - return fBinding; - } + if (fBinding == null) + fBinding = new CPPNamespace(this); + return fBinding; + } - @Override @Deprecated + @Override + @Deprecated public IBinding resolveBinding() { - return getGlobalNamespace(); - } + return getGlobalNamespace(); + } - @Override @Deprecated - public ParserLanguage getParserLanguage() { - return ParserLanguage.CPP; - } + @Override + @Deprecated + public ParserLanguage getParserLanguage() { + return ParserLanguage.CPP; + } @Override public ILinkage getLinkage() { @@ -224,6 +229,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST public ProblemBindingClearer() { shouldVisitNames = true; } + @Override public int visit(IASTName name) { if (name.getBinding() instanceof IProblemBinding) { @@ -232,7 +238,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST return PROCESS_CONTINUE; } } - + @Override public void resolveAmbiguities() { fAmbiguityResolver = new CPPASTAmbiguityResolver(); @@ -259,7 +265,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST public Map<ICPPClassType, FinalOverriderMap> getFinalOverriderMapCache() { return fFinalOverriderMapCache; } - + public Map<TypeInstantiationRequest, IType> getInstantiationCache() { return fInstantiationCache; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java index fe53a250d92..9b47d882019 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java @@ -26,11 +26,11 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; * @author jcamelon */ public class CPPASTTryBlockStatement extends CPPASTAttributeOwner implements ICPPASTTryBlockStatement { - private ICPPASTCatchHandler[] catchHandlers; - private int catchHandlersPos= -1; - private IASTStatement tryBody; + private ICPPASTCatchHandler[] catchHandlers; + private int catchHandlersPos = -1; + private IASTStatement tryBody; - public CPPASTTryBlockStatement() { + public CPPASTTryBlockStatement() { } public CPPASTTryBlockStatement(IASTStatement tryBody) { @@ -44,8 +44,7 @@ public class CPPASTTryBlockStatement extends CPPASTAttributeOwner implements ICP @Override public CPPASTTryBlockStatement copy(CopyStyle style) { - CPPASTTryBlockStatement copy = - new CPPASTTryBlockStatement(tryBody == null ? null : tryBody.copy(style)); + CPPASTTryBlockStatement copy = new CPPASTTryBlockStatement(tryBody == null ? null : tryBody.copy(style)); for (ICPPASTCatchHandler handler : getCatchHandlers()) copy.addCatchHandler(handler == null ? null : handler.copy(style)); return copy(copy, style); @@ -53,75 +52,82 @@ public class CPPASTTryBlockStatement extends CPPASTAttributeOwner implements ICP @Override public void addCatchHandler(ICPPASTCatchHandler statement) { - assertNotFrozen(); - if (statement != null) { - catchHandlers = ArrayUtil.appendAt(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement); - statement.setParent(this); + assertNotFrozen(); + if (statement != null) { + catchHandlers = ArrayUtil.appendAt(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement); + statement.setParent(this); statement.setPropertyInParent(CATCH_HANDLER); - } - } + } + } - @Override + @Override public ICPPASTCatchHandler[] getCatchHandlers() { - if (catchHandlers == null) - return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY; - catchHandlers = ArrayUtil.trimAt(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos); - return catchHandlers; - } + if (catchHandlers == null) + return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY; + catchHandlers = ArrayUtil.trimAt(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos); + return catchHandlers; + } - @Override + @Override public void setTryBody(IASTStatement tryBlock) { - assertNotFrozen(); - tryBody = tryBlock; - if (tryBlock != null) { + assertNotFrozen(); + tryBody = tryBlock; + if (tryBlock != null) { tryBlock.setParent(this); tryBlock.setPropertyInParent(BODY); } - } + } - @Override + @Override public IASTStatement getTryBody() { - return tryBody; - } + return tryBody; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (tryBody != null && !tryBody.accept(action)) - return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (tryBody != null && !tryBody.accept(action)) + return false; - ICPPASTCatchHandler[] handlers = getCatchHandlers(); - for (int i = 0; i < handlers.length; i++) { - if (!handlers[i].accept(action)) - return false; - } + ICPPASTCatchHandler[] handlers = getCatchHandlers(); + for (int i = 0; i < handlers.length; i++) { + if (!handlers[i].accept(action)) + return false; + } - if (action.shouldVisitStatements) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (tryBody == child) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - tryBody = (IASTStatement) other; - return; - } - super.replace(child, other); - } + if (tryBody == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + tryBody = (IASTStatement) other; + return; + } + super.replace(child, other); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java index c5cab709421..de38ad56543 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeId.java @@ -24,11 +24,11 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * Type id for c++ */ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId { - private IASTDeclSpecifier declSpec; - private IASTDeclarator absDecl; - private boolean isPackExpansion; + private IASTDeclSpecifier declSpec; + private IASTDeclarator absDecl; + private boolean isPackExpansion; - public CPPASTTypeId() { + public CPPASTTypeId() { } public CPPASTTypeId(IASTDeclSpecifier declSpec, IASTDeclarator absDecl) { @@ -52,64 +52,72 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId { @Override public IASTDeclSpecifier getDeclSpecifier() { - return declSpec; - } + return declSpec; + } - @Override + @Override public void setDeclSpecifier(IASTDeclSpecifier declSpec) { - assertNotFrozen(); - this.declSpec = declSpec; - if (declSpec != null) { + assertNotFrozen(); + this.declSpec = declSpec; + if (declSpec != null) { declSpec.setParent(this); declSpec.setPropertyInParent(DECL_SPECIFIER); } - } + } - @Override + @Override public IASTDeclarator getAbstractDeclarator() { - return absDecl; - } + return absDecl; + } - @Override + @Override public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) { - assertNotFrozen(); - this.absDecl = abstractDeclarator; - if (abstractDeclarator != null) { + assertNotFrozen(); + this.absDecl = abstractDeclarator; + if (abstractDeclarator != null) { abstractDeclarator.setParent(this); abstractDeclarator.setPropertyInParent(ABSTRACT_DECLARATOR); } - } + } - @Override + @Override public boolean isPackExpansion() { return isPackExpansion; } @Override public void setIsPackExpansion(boolean val) { - isPackExpansion= val; + isPackExpansion = val; } @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitTypeIds) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTypeIds) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (declSpec != null && !declSpec.accept(action)) return false; - if (absDecl != null && !absDecl.accept(action)) return false; + if (declSpec != null && !declSpec.accept(action)) + return false; + if (absDecl != null && !absDecl.accept(action)) + return false; - if (action.shouldVisitTypeIds) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitTypeIds) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java index 838e95aedea..14425dc0913 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdExpression.java @@ -29,11 +29,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUnaryTypeID; public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpression { - private int fOperator; - private IASTTypeId fTypeId; + private int fOperator; + private IASTTypeId fTypeId; private ICPPEvaluation fEvaluation; - public CPPASTTypeIdExpression() { + public CPPASTTypeIdExpression() { } public CPPASTTypeIdExpression(int op, IASTTypeId typeId) { @@ -48,81 +48,88 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr @Override public CPPASTTypeIdExpression copy(CopyStyle style) { - CPPASTTypeIdExpression copy = - new CPPASTTypeIdExpression(fOperator, fTypeId == null ? null : fTypeId.copy(style)); + CPPASTTypeIdExpression copy = new CPPASTTypeIdExpression(fOperator, + fTypeId == null ? null : fTypeId.copy(style)); return copy(copy, style); } @Override public int getOperator() { - return fOperator; - } + return fOperator; + } - @Override + @Override public void setOperator(int value) { - assertNotFrozen(); - fOperator = value; - } + assertNotFrozen(); + fOperator = value; + } - @Override + @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.fTypeId = typeId; - if (typeId != null) { - typeId.setParent(this); - typeId.setPropertyInParent(TYPE_ID); - } - } - - @Override + assertNotFrozen(); + this.fTypeId = typeId; + if (typeId != null) { + typeId.setParent(this); + typeId.setPropertyInParent(TYPE_ID); + } + } + + @Override public IASTTypeId getTypeId() { - return fTypeId; - } + return fTypeId; + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { return IASTImplicitDestructorName.EMPTY_NAME_ARRAY; // Type-id expression does not call destructors. } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fTypeId != null && !fTypeId.accept(action)) return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (fTypeId != null && !fTypeId.accept(action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { - IType type= CPPVisitor.createType(fTypeId); + IType type = CPPVisitor.createType(fTypeId); if (type == null || type instanceof IProblemType) { - fEvaluation= EvalFixed.INCOMPLETE; + fEvaluation = EvalFixed.INCOMPLETE; } else { - fEvaluation= new EvalUnaryTypeID(fOperator, type, this); + fEvaluation = new EvalUnaryTypeID(fOperator, type, this); } } return fEvaluation; } - @Override + @Override public IType getExpressionType() { - return CPPEvaluation.getType(this); - } + return CPPEvaluation.getType(this); + } @Override public ValueCategory getValueCategory() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java index 6a856d10d7f..9838122c3a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java @@ -37,12 +37,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; */ public class CPPASTTypeIdInitializerExpression extends ASTNode implements IASTTypeIdInitializerExpression, ICPPASTExpression { - private IASTTypeId fTypeId; - private IASTInitializer fInitializer; + private IASTTypeId fTypeId; + private IASTInitializer fInitializer; private ICPPEvaluation fEvaluation; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTTypeIdInitializerExpression() { + public CPPASTTypeIdInitializerExpression() { } public CPPASTTypeIdInitializerExpression(IASTTypeId t, IASTInitializer i) { @@ -52,33 +52,33 @@ public class CPPASTTypeIdInitializerExpression extends ASTNode @Override public IASTTypeId getTypeId() { - return fTypeId; - } + return fTypeId; + } - @Override + @Override public void setTypeId(IASTTypeId typeId) { - assertNotFrozen(); - this.fTypeId = typeId; - if (typeId != null) { + assertNotFrozen(); + this.fTypeId = typeId; + if (typeId != null) { typeId.setParent(this); typeId.setPropertyInParent(TYPE_ID); } - } + } - @Override + @Override public IASTInitializer getInitializer() { - return fInitializer; - } + return fInitializer; + } - @Override + @Override public void setInitializer(IASTInitializer initializer) { - assertNotFrozen(); - this.fInitializer = initializer; - if (initializer != null) { + assertNotFrozen(); + this.fInitializer = initializer; + if (initializer != null) { initializer.setParent(this); initializer.setPropertyInParent(INITIALIZER); } - } + } @Override public IASTImplicitDestructorName[] getImplicitDestructorNames() { @@ -91,29 +91,37 @@ public class CPPASTTypeIdInitializerExpression extends ASTNode @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (fTypeId != null && !fTypeId.accept(action)) return false; - if (fInitializer != null && !fInitializer.accept(action)) return false; + if (fTypeId != null && !fTypeId.accept(action)) + return false; + if (fInitializer != null && !fInitializer.accept(action)) + return false; if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) return false; - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public final boolean isLValue() { @@ -127,16 +135,15 @@ public class CPPASTTypeIdInitializerExpression extends ASTNode @Override public IASTTypeIdInitializerExpression copy(CopyStyle style) { - CPPASTTypeIdInitializerExpression copy =new CPPASTTypeIdInitializerExpression( - fTypeId == null ? null : fTypeId.copy(style), - fInitializer == null ? null : fInitializer.copy(style)); + CPPASTTypeIdInitializerExpression copy = new CPPASTTypeIdInitializerExpression( + fTypeId == null ? null : fTypeId.copy(style), fInitializer == null ? null : fInitializer.copy(style)); return copy(copy, style); } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) - fEvaluation= computeEvaluation(); + fEvaluation = computeEvaluation(); return fEvaluation; } @@ -146,7 +153,7 @@ public class CPPASTTypeIdInitializerExpression extends ASTNode if (!(initializer instanceof ICPPASTInitializerClause)) return EvalFixed.INCOMPLETE; - IType type= CPPVisitor.createType(getTypeId()); + IType type = CPPVisitor.createType(getTypeId()); if (type == null || type instanceof IProblemType) return EvalFixed.INCOMPLETE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeTransformationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeTransformationSpecifier.java index 55f4fe4c5f8..020743e6bb3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeTransformationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeTransformationSpecifier.java @@ -22,7 +22,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation.Operator; /** * Implementation of ICPPASTTypeTransformationSpecifier. */ -public class CPPASTTypeTransformationSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTTypeTransformationSpecifier { +public class CPPASTTypeTransformationSpecifier extends CPPASTBaseDeclSpecifier + implements ICPPASTTypeTransformationSpecifier { private Operator fOperator; private ICPPASTTypeId fOperand; @@ -58,23 +59,29 @@ public class CPPASTTypeTransformationSpecifier extends CPPASTBaseDeclSpecifier i public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclSpecifiers) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; } } - if (!fOperand.accept(action)) - return false; + if (!fOperand.accept(action)) + return false; - if (action.shouldVisitDeclSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; + return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java index 709fc229bdc..ddf8546d30b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java @@ -23,9 +23,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression; @Deprecated -public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpression implements ICPPASTTypenameExpression { +public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpression + implements ICPPASTTypenameExpression { - public CPPASTTypenameExpression() { + public CPPASTTypenameExpression() { } public CPPASTTypenameExpression(IASTName name, IASTExpression expr) { @@ -49,21 +50,21 @@ public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpress return copy(copy, style); } - @Override + @Override public void setName(IASTName name) { - CPPASTNamedTypeSpecifier spec= new CPPASTNamedTypeSpecifier(name); - spec.setOffsetAndLength(this); - setDeclSpecifier(spec); - } + CPPASTNamedTypeSpecifier spec = new CPPASTNamedTypeSpecifier(name); + spec.setOffsetAndLength(this); + setDeclSpecifier(spec); + } - @Override + @Override public IASTName getName() { - IASTDeclSpecifier spec= getDeclSpecifier(); - if (spec instanceof ICPPASTNamedTypeSpecifier) { - return ((ICPPASTNamedTypeSpecifier) spec).getName(); - } - return null; - } + IASTDeclSpecifier spec = getDeclSpecifier(); + if (spec instanceof ICPPASTNamedTypeSpecifier) { + return ((ICPPASTNamedTypeSpecifier) spec).getName(); + } + return null; + } @Override public int getRoleForName(IASTName n) { @@ -75,11 +76,11 @@ public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpress @Override @Deprecated public void setIsTemplate(boolean val) { - } + } @Override @Deprecated - public boolean isTemplate() { - return false; - } + public boolean isTemplate() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java index 1017742a8cb..32ef93f67ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUnaryExpression.java @@ -49,12 +49,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.FunctionSetType; */ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpression, IASTAmbiguityParent { private int fOperator; - private ICPPASTExpression fOperand; + private ICPPASTExpression fOperand; private ICPPEvaluation fEvaluation; - private IASTImplicitName[] fImplicitNames; + private IASTImplicitName[] fImplicitNames; private IASTImplicitDestructorName[] fImplicitDestructorNames; - public CPPASTUnaryExpression() { + public CPPASTUnaryExpression() { } public CPPASTUnaryExpression(int operator, IASTExpression operand) { @@ -69,42 +69,42 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres @Override public CPPASTUnaryExpression copy(CopyStyle style) { - CPPASTUnaryExpression copy = - new CPPASTUnaryExpression(fOperator, fOperand == null ? null : fOperand.copy(style)); + CPPASTUnaryExpression copy = new CPPASTUnaryExpression(fOperator, + fOperand == null ? null : fOperand.copy(style)); return copy(copy, style); } @Override public int getOperator() { - return fOperator; - } + return fOperator; + } - @Override + @Override public void setOperator(int operator) { - assertNotFrozen(); - fOperator = operator; - } + assertNotFrozen(); + fOperator = operator; + } - @Override + @Override public IASTExpression getOperand() { - return fOperand; - } + return fOperand; + } - @Override + @Override public void setOperand(IASTExpression expression) { - assertNotFrozen(); - fOperand = (ICPPASTExpression) expression; - if (expression != null) { + assertNotFrozen(); + fOperand = (ICPPASTExpression) expression; + if (expression != null) { expression.setParent(this); expression.setPropertyInParent(OPERAND); } - } + } - public boolean isPostfixOperator() { - return fOperator == op_postFixDecr || fOperator == op_postFixIncr; - } + public boolean isPostfixOperator() { + return fOperator == op_postFixDecr || fOperator == op_postFixIncr; + } - @Override + @Override public IASTImplicitName[] getImplicitNames() { if (fImplicitNames == null) { ICPPFunction overload = getOverload(); @@ -131,58 +131,64 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres return fImplicitDestructorNames; } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitExpressions) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + final boolean isPostfix = isPostfixOperator(); + + if (!isPostfix && action.shouldVisitImplicitNames) { + for (IASTImplicitName name : getImplicitNames()) { + if (!name.accept(action)) + return false; + } + } + + if (fOperand != null && !fOperand.accept(action)) + return false; + + if (isPostfix && action.shouldVisitImplicitNames) { + for (IASTImplicitName name : getImplicitNames()) { + if (!name.accept(action)) + return false; + } } - final boolean isPostfix = isPostfixOperator(); - - if (!isPostfix && action.shouldVisitImplicitNames) { - for (IASTImplicitName name : getImplicitNames()) { - if (!name.accept(action)) - return false; - } - } - - if (fOperand != null && !fOperand.accept(action)) - return false; - - if (isPostfix && action.shouldVisitImplicitNames) { - for (IASTImplicitName name : getImplicitNames()) { - if (!name.accept(action)) - return false; - } - } - - if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) - return false; - - if (action.shouldVisitExpressions) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitImplicitDestructorNames && !acceptByNodes(getImplicitDestructorNames(), action)) + return false; + + if (action.shouldVisitExpressions) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public void replace(IASTNode child, IASTNode other) { - if (child == fOperand) { - other.setPropertyInParent(child.getPropertyInParent()); - other.setParent(child.getParent()); - fOperand = (ICPPASTExpression) other; - } - } - - @Override + if (child == fOperand) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + fOperand = (ICPPASTExpression) other; + } + } + + @Override public ICPPFunction getOverload() { ICPPEvaluation eval = getEvaluation(); if (eval instanceof EvalUnary) { @@ -194,12 +200,12 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres } } return null; - } + } @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { - fEvaluation= computeEvaluation(); + fEvaluation = computeEvaluation(); } return fEvaluation; } @@ -216,23 +222,23 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres return nestedEval; } - IBinding addressOfQualifiedNameBinding= null; - if (fOperator == op_amper && fOperand instanceof IASTIdExpression) { - IASTName name= ((IASTIdExpression) fOperand).getName(); + IBinding addressOfQualifiedNameBinding = null; + if (fOperator == op_amper && fOperand instanceof IASTIdExpression) { + IASTName name = ((IASTIdExpression) fOperand).getName(); if (name instanceof ICPPASTQualifiedName) { - addressOfQualifiedNameBinding= name.resolveBinding(); + addressOfQualifiedNameBinding = name.resolveBinding(); if (addressOfQualifiedNameBinding instanceof IProblemBinding) return EvalFixed.INCOMPLETE; } } - return new EvalUnary(fOperator, nestedEval, addressOfQualifiedNameBinding, this); + return new EvalUnary(fOperator, nestedEval, addressOfQualifiedNameBinding, this); } - @Override + @Override public IType getExpressionType() { - IType type= CPPEvaluation.getType(this); + IType type = CPPEvaluation.getType(this); if (type instanceof FunctionSetType) { - type= fOperand.getExpressionType(); + type = fOperand.getExpressionType(); if (fOperator == op_amper) { if (fOperand instanceof IASTIdExpression) { IASTIdExpression idExpr = (IASTIdExpression) fOperand; @@ -242,7 +248,8 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres if (binding instanceof ICPPMethod) { ICPPMethod method = (ICPPMethod) binding; if (!method.isStatic()) { - return new CPPPointerToMemberType(method.getType(), method.getClassOwner(), false, false, false); + return new CPPPointerToMemberType(method.getType(), method.getClassOwner(), false, + false, false); } } } @@ -251,7 +258,7 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres } } return type; - } + } @Override public ValueCategory getValueCategory() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java index a9a3e7fb224..248ff9d2eb3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java @@ -31,13 +31,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; public class CPPASTUsingDeclaration extends CPPASTAttributeOwner implements ICPPASTUsingDeclaration, ICPPASTCompletionContext { - private boolean typeName; - private IASTName name; - - // The using-declaration has an implicit name referencing every delegate binding. - private IASTImplicitName[] fImplicitNames; + private boolean typeName; + private IASTName name; - public CPPASTUsingDeclaration() { + // The using-declaration has an implicit name referencing every delegate binding. + private IASTImplicitName[] fImplicitNames; + + public CPPASTUsingDeclaration() { } public CPPASTUsingDeclaration(IASTName name) { @@ -51,66 +51,74 @@ public class CPPASTUsingDeclaration extends CPPASTAttributeOwner @Override public CPPASTUsingDeclaration copy(CopyStyle style) { - CPPASTUsingDeclaration copy = - new CPPASTUsingDeclaration(name == null ? null : name.copy(style)); + CPPASTUsingDeclaration copy = new CPPASTUsingDeclaration(name == null ? null : name.copy(style)); copy.typeName = typeName; return copy(copy, style); } @Override public void setIsTypename(boolean value) { - assertNotFrozen(); - this.typeName = value; - } + assertNotFrozen(); + this.typeName = value; + } - @Override + @Override public boolean isTypename() { - return typeName; - } + return typeName; + } - @Override + @Override public IASTName getName() { - return name; - } + return name; + } - @Override + @Override public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { + assertNotFrozen(); + this.name = name; + if (name != null) { name.setParent(this); name.setPropertyInParent(NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + if (!acceptByAttributeSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; + + if (action.shouldVisitImplicitNames) { + for (IASTImplicitName name : getImplicitNames()) { + if (!name.accept(action)) + return false; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (name != null && !name.accept(action)) return false; - - if (action.shouldVisitImplicitNames) { - for (IASTImplicitName name : getImplicitNames()) { - if (!name.accept(action)) return false; - } - } - - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } @Override public int getRoleForName(IASTName n) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java index 7a6ebf77360..4ee3f4e7c9e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java @@ -28,9 +28,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; public class CPPASTUsingDirective extends CPPASTAttributeOwner implements ICPPASTUsingDirective, ICPPASTCompletionContext { - private IASTName name; + private IASTName name; - public CPPASTUsingDirective() { + public CPPASTUsingDirective() { } public CPPASTUsingDirective(IASTName name) { @@ -50,44 +50,53 @@ public class CPPASTUsingDirective extends CPPASTAttributeOwner @Override public IASTName getQualifiedName() { - return name; - } + return name; + } - @Override + @Override public void setQualifiedName(IASTName qualifiedName) { - assertNotFrozen(); - this.name = qualifiedName; - if (qualifiedName != null) { + assertNotFrozen(); + this.name = qualifiedName; + if (qualifiedName != null) { qualifiedName.setParent(this); qualifiedName.setPropertyInParent(QUALIFIED_NAME); } - } + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByCPPAttributeSpecifiers(action)) return false; - if (name != null && !name.accept(action)) return false; - if (!acceptByGCCAttributeSpecifiers(action)) return false; - - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (!acceptByCPPAttributeSpecifiers(action)) + return false; + if (name != null && !name.accept(action)) + return false; + if (!acceptByGCCAttributeSpecifiers(action)) + return false; + + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - return true; - } + return true; + } - @Override + @Override public int getRoleForName(IASTName n) { if (n == name) return r_reference; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVirtSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVirtSpecifier.java index 0f50fda2297..77c70c874be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVirtSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVirtSpecifier.java @@ -40,23 +40,29 @@ public class CPPASTVirtSpecifier extends ASTNode implements ICPPASTVirtSpecifier return copy(copy, style); } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitVirtSpecifiers) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - - if (action.shouldVisitVirtSpecifiers) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } - } - return true; - } + if (action.shouldVisitVirtSpecifiers) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + + if (action.shouldVisitVirtSpecifiers) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVisibilityLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVisibilityLabel.java index cf373d19f9e..5d7b0824c06 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVisibilityLabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTVisibilityLabel.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ public class CPPASTVisibilityLabel extends ASTNode implements ICPPASTVisibilityLabel { - private int visibility; + private int visibility; public CPPASTVisibilityLabel(int visibility) { this.visibility = visibility; @@ -39,38 +39,38 @@ public class CPPASTVisibilityLabel extends ASTNode implements ICPPASTVisibilityL @Override public int getVisibility() { - return visibility; - } + return visibility; + } - @Override + @Override public void setVisibility(int visibility) { - assertNotFrozen(); - this.visibility = visibility; - } + assertNotFrozen(); + this.visibility = visibility; + } - @Override + @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitDeclarations) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } - if (action.shouldVisitDeclarations) { - switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; - } - } - return true; - } + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java index f8c66514f48..e2e43f73be8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java @@ -31,25 +31,25 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecWhile; * While statement in C++. */ public class CPPASTWhileStatement extends CPPASTAttributeOwner implements ICPPASTWhileStatement, ICPPExecutionOwner { - private IASTExpression condition; - private IASTDeclaration condition2; - private IASTStatement body; - private IScope scope; + private IASTExpression condition; + private IASTDeclaration condition2; + private IASTStatement body; + private IScope scope; - public CPPASTWhileStatement() { + public CPPASTWhileStatement() { } public CPPASTWhileStatement(IASTDeclaration condition, IASTStatement body) { - setConditionDeclaration(condition); + setConditionDeclaration(condition); setBody(body); } - public CPPASTWhileStatement(IASTExpression condition, IASTStatement body) { + public CPPASTWhileStatement(IASTExpression condition, IASTStatement body) { setCondition(condition); setBody(body); } - @Override + @Override public CPPASTWhileStatement copy() { return copy(CopyStyle.withoutLocations); } @@ -65,34 +65,34 @@ public class CPPASTWhileStatement extends CPPASTAttributeOwner implements ICPPAS @Override public IASTExpression getCondition() { - return condition; - } + return condition; + } - @Override + @Override public void setCondition(IASTExpression condition) { - assertNotFrozen(); - this.condition = condition; - if (condition != null) { + assertNotFrozen(); + this.condition = condition; + if (condition != null) { condition.setParent(this); condition.setPropertyInParent(CONDITIONEXPRESSION); - condition2= null; + condition2 = null; } - } + } - @Override + @Override public IASTStatement getBody() { - return body; - } + return body; + } - @Override + @Override public void setBody(IASTStatement body) { - assertNotFrozen(); - this.body = body; - if (body != null) { + assertNotFrozen(); + this.body = body; + if (body != null) { body.setParent(this); body.setPropertyInParent(BODY); } - } + } @Override public IASTDeclaration getConditionDeclaration() { @@ -101,38 +101,42 @@ public class CPPASTWhileStatement extends CPPASTAttributeOwner implements ICPPAS @Override public void setConditionDeclaration(IASTDeclaration declaration) { - assertNotFrozen(); + assertNotFrozen(); condition2 = declaration; if (declaration != null) { declaration.setParent(this); declaration.setPropertyInParent(CONDITIONDECLARATION); - condition= null; + condition = null; } } @Override public boolean accept(ASTVisitor action) { - if (action.shouldVisitStatements) { - switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - default: break; - } + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } } - if (!acceptByAttributeSpecifiers(action)) return false; - if (condition != null && !condition.accept(action)) - return false; - if (condition2 != null && !condition2.accept(action)) - return false; - if (body != null && !body.accept(action)) - return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (condition != null && !condition.accept(action)) + return false; + if (condition2 != null && !condition2.accept(action)) + return false; + if (body != null && !body.accept(action)) + return false; - if (action.shouldVisitStatements && action.leave(this) == ASTVisitor.PROCESS_ABORT) - return false; + if (action.shouldVisitStatements && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; - return true; - } + return true; + } @Override public void replace(IASTNode child, IASTNode other) { @@ -156,16 +160,18 @@ public class CPPASTWhileStatement extends CPPASTAttributeOwner implements ICPPAS @Override public IScope getScope() { if (scope == null) - scope = new CPPBlockScope(this); - return scope; - } + scope = new CPPBlockScope(this); + return scope; + } @Override public ICPPExecution getExecution() { ICPPASTExpression conditionExpr = (ICPPASTExpression) getCondition(); ICPPExecutionOwner conditionDecl = (ICPPExecutionOwner) getConditionDeclaration(); ICPPEvaluation conditionExprEval = conditionExpr != null ? conditionExpr.getEvaluation() : null; - ExecSimpleDeclaration conditionDeclExec = conditionDecl != null ? (ExecSimpleDeclaration) conditionDecl.getExecution() : null; + ExecSimpleDeclaration conditionDeclExec = conditionDecl != null + ? (ExecSimpleDeclaration) conditionDecl.getExecution() + : null; ICPPExecution bodyExec = EvalUtil.getExecutionFromStatement(getBody()); return new ExecWhile(conditionExprEval, conditionDeclExec, bodyExec); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplate.java index 0093592f64b..65d3aa71146 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplate.java @@ -84,16 +84,16 @@ public class CPPAliasTemplate extends PlatformObject return type.isSameType(aliasedType); } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen + } + return t; + } @Override public String[] getQualifiedName() throws DOMException { @@ -120,7 +120,7 @@ public class CPPAliasTemplate extends PlatformObject IBinding p = null; ICPPTemplateParameter[] result = null; for (ICPPASTTemplateParameter param : params) { - p= CPPTemplates.getTemplateParameterName(param).resolveBinding(); + p = CPPTemplates.getTemplateParameterName(param).resolveBinding(); if (p instanceof ICPPTemplateParameter) { result = ArrayUtil.append(ICPPTemplateParameter.class, result, (ICPPTemplateParameter) p); } @@ -132,14 +132,14 @@ public class CPPAliasTemplate extends PlatformObject @Override public IBinding resolveTemplateParameter(ICPPTemplateParameter templateParameter) { - int pos= templateParameter.getParameterPosition(); + int pos = templateParameter.getParameterPosition(); ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(aliasName).getTemplateParameters(); if (pos < params.length) { final IASTName oName = CPPTemplates.getTemplateParameterName(params[pos]); return oName.resolvePreBinding(); } - return templateParameter; + return templateParameter; } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java index b1f53674b70..992aa96c634 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java @@ -31,12 +31,11 @@ import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -public class CPPAliasTemplateInstance extends CPPSpecialization implements ICPPAliasTemplateInstance, - ITypeContainer { +public class CPPAliasTemplateInstance extends CPPSpecialization implements ICPPAliasTemplateInstance, ITypeContainer { private IType aliasedType; private ICPPTemplateArgument[] fArguments; - public CPPAliasTemplateInstance(ICPPAliasTemplate aliasTemplate, IType aliasedType, IBinding owner, + public CPPAliasTemplateInstance(ICPPAliasTemplate aliasTemplate, IType aliasedType, IBinding owner, ICPPTemplateParameterMap argumentMap, ICPPTemplateArgument[] arguments) { super(aliasTemplate, owner, argumentMap); this.aliasedType = aliasedType; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateSpecialization.java index f450891cead..b6f3f2824f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateSpecialization.java @@ -22,17 +22,17 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; public class CPPAliasTemplateSpecialization extends CPPSpecialization implements ICPPAliasTemplate { private ICPPTemplateParameter[] fParameters; private IType fAliasedType; - - public CPPAliasTemplateSpecialization(ICPPAliasTemplate specialized, IBinding owner, + + public CPPAliasTemplateSpecialization(ICPPAliasTemplate specialized, IBinding owner, ICPPTemplateParameterMap argumentMap, IType aliasedType) { super(specialized, owner, argumentMap); fAliasedType = aliasedType; } - + public void setTemplateParameters(ICPPTemplateParameter[] parameters) { fParameters = parameters; } - + @Override public boolean isSameType(IType type) { if (type == null) { @@ -51,14 +51,14 @@ public class CPPAliasTemplateSpecialization extends CPPSpecialization implements return fAliasedType; } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen + } + return t; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java index ae764e5e4f8..8d3b305f067 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArithmeticConversion.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; public class CPPArithmeticConversion extends ArithmeticConversion { - private static CPPArithmeticConversion sInstance= new CPPArithmeticConversion(); + private static CPPArithmeticConversion sInstance = new CPPArithmeticConversion(); public static IType convertCppOperandTypes(int operator, IType t1, IType t2) { return sInstance.convertOperandTypes(operator, t1, t2); @@ -29,7 +29,8 @@ public class CPPArithmeticConversion extends ArithmeticConversion { return sInstance.promoteType(t); } - private CPPArithmeticConversion() {} + private CPPArithmeticConversion() { + } @Override protected IBasicType createBasicType(Kind kind, int modifiers) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java index 76346e76e6b..cec60d52a46 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java @@ -30,45 +30,45 @@ import org.eclipse.cdt.internal.core.dom.parser.ValueFactory; import org.eclipse.core.runtime.CoreException; public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableType { - private IType type; - private IASTExpression sizeExpression; - private IValue value= IntegralValue.NOT_INITIALIZED; + private IType type; + private IASTExpression sizeExpression; + private IValue value = IntegralValue.NOT_INITIALIZED; - public CPPArrayType(IType type, IValue value) { - this.value= value; - setType(type); - } + public CPPArrayType(IType type, IValue value) { + this.value = value; + setType(type); + } - public CPPArrayType(IType type, IASTExpression sizeExp) { - this.sizeExpression = sizeExp; - setType(type); - } + public CPPArrayType(IType type, IASTExpression sizeExp) { + this.sizeExpression = sizeExp; + setType(type); + } - @Override + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public final void setType(IType t) { - assert t != null; - this.type = t; - } + assert t != null; + this.type = t; + } - @Override + @Override public boolean isSameType(IType obj) { - if (obj == this) - return true; - if (obj instanceof ITypedef) - return ((ITypedef) obj).isSameType(this); + if (obj == this) + return true; + if (obj instanceof ITypedef) + return ((ITypedef) obj).isSameType(this); - if (obj instanceof IArrayType) { - final IArrayType rhs = (IArrayType) obj; + if (obj instanceof IArrayType) { + final IArrayType rhs = (IArrayType) obj; IType objType = rhs.getType(); if (objType != null) { if (objType.isSameType(type)) { - IValue s1= getSize(); - IValue s2= rhs.getSize(); + IValue s1 = getSize(); + IValue s2 = rhs.getSize(); if (s1 == s2) return true; if (s1 == null || s2 == null) @@ -76,42 +76,42 @@ public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableTy return CharArrayUtils.equals(s1.getSignature(), s2.getSignature()); } } - } - return false; - } + } + return false; + } - @Override + @Override public IValue getSize() { - if (value != IntegralValue.NOT_INITIALIZED) - return value; + if (value != IntegralValue.NOT_INITIALIZED) + return value; - if (sizeExpression == null) - return value= null; + if (sizeExpression == null) + return value = null; - return value= ValueFactory.create(sizeExpression); - } + return value = ValueFactory.create(sizeExpression); + } - @Override - public boolean hasSize() { - return value == IntegralValue.NOT_INITIALIZED ? sizeExpression != null : value != null; - } + @Override + public boolean hasSize() { + return value == IntegralValue.NOT_INITIALIZED ? sizeExpression != null : value != null; + } - @Override + @Override @Deprecated - public IASTExpression getArraySizeExpression() { - return sizeExpression; - } + public IASTExpression getArraySizeExpression() { + return sizeExpression; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen + } + return t; + } @Override public String toString() { @@ -122,16 +122,16 @@ public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableTy public void marshal(ITypeMarshalBuffer buffer) throws CoreException { final short firstBytes = ITypeMarshalBuffer.ARRAY_TYPE; - IValue val= getSize(); + IValue val = getSize(); if (val == null) { buffer.putShort(firstBytes); buffer.marshalType(getType()); return; } - Number num= val.numberValue(); + Number num = val.numberValue(); if (num != null) { - long lnum= num.longValue(); + long lnum = num.longValue(); if (lnum >= 0) { buffer.putShort((short) (firstBytes | ITypeMarshalBuffer.FLAG1)); buffer.putLong(lnum); @@ -145,13 +145,13 @@ public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableTy } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IValue value= null; + IValue value = null; if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) { value = IntegralValue.create(buffer.getLong()); } else if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) { value = buffer.unmarshalValue(); } - IType nested= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); return new CPPArrayType(nested, value); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java index 50c56041c84..62dc7adfa9c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java @@ -33,47 +33,47 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; public class CPPBaseClause implements ICPPBase, ICPPInternalBase { - private final ICPPASTBaseSpecifier base; + private final ICPPASTBaseSpecifier base; private IType baseClass; private boolean inheritedConstructorsSource; - public CPPBaseClause(ICPPASTBaseSpecifier base) { - this.base = base; - } + public CPPBaseClause(ICPPASTBaseSpecifier base) { + this.base = base; + } - @Override + @Override public IBinding getBaseClass() { - IType type= getBaseClassType(); + IType type = getBaseClassType(); type = getNestedType(type, TDEF); if (type instanceof IBinding) return (IBinding) type; return null; - } + } - @Override - public IType getBaseClassType() { + @Override + public IType getBaseClassType() { if (baseClass == null) { ICPPASTNameSpecifier nameSpec = base.getNameSpecifier(); - IBinding b = nameSpec.resolveBinding(); - if (b instanceof IProblemBinding) { - baseClass = new CPPClassType.CPPClassTypeProblem(nameSpec, ((IProblemBinding) b).getID()); - } else if (!(b instanceof IType)) { - baseClass = new CPPClassType.CPPClassTypeProblem(nameSpec, ISemanticProblem.BINDING_NO_CLASS); - } else { - baseClass= (IType) b; - IType check= getNestedType(baseClass, TDEF); - if (!(check instanceof ICPPClassType || check instanceof ICPPUnknownType)) { - baseClass = new CPPClassType.CPPClassTypeProblem(nameSpec, ISemanticProblem.BINDING_NO_CLASS); - } - } - if (base.isPackExpansion()) { - baseClass = new CPPParameterPackType(baseClass); - } + IBinding b = nameSpec.resolveBinding(); + if (b instanceof IProblemBinding) { + baseClass = new CPPClassType.CPPClassTypeProblem(nameSpec, ((IProblemBinding) b).getID()); + } else if (!(b instanceof IType)) { + baseClass = new CPPClassType.CPPClassTypeProblem(nameSpec, ISemanticProblem.BINDING_NO_CLASS); + } else { + baseClass = (IType) b; + IType check = getNestedType(baseClass, TDEF); + if (!(check instanceof ICPPClassType || check instanceof ICPPUnknownType)) { + baseClass = new CPPClassType.CPPClassTypeProblem(nameSpec, ISemanticProblem.BINDING_NO_CLASS); + } + } + if (base.isPackExpansion()) { + baseClass = new CPPParameterPackType(baseClass); + } } return baseClass; - } + } - @Override + @Override public int getVisibility() { int vis = base.getVisibility(); @@ -81,13 +81,13 @@ public class CPPBaseClause implements ICPPBase, ICPPInternalBase { ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) base.getParent(); vis = compSpec.getKey() == ICPPClassType.k_class ? ICPPBase.v_private : ICPPBase.v_public; } - return vis; - } + return vis; + } - @Override + @Override public boolean isVirtual() { - return base.isVirtual(); - } + return base.isVirtual(); + } @Override public boolean isInheritedConstructorsSource() { @@ -105,14 +105,14 @@ public class CPPBaseClause implements ICPPBase, ICPPInternalBase { @Override public ICPPBase clone() { - ICPPBase t = null; - try { - t = (ICPPBase) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen. - } - return t; - } + ICPPBase t = null; + try { + t = (ICPPBase) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen. + } + return t; + } @Override public void setBaseClass(IBinding cls) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index e0cf3845bc7..c26dde91be6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -41,16 +41,19 @@ import org.eclipse.core.runtime.CoreException; public class CPPBasicType implements ICPPBasicType, ISerializableType { public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null); public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null); - public static final CPPBasicType UNSPECIFIED_TYPE = new CPPBasicType(Kind.eUnspecified, 0); + public static final CPPBasicType UNSPECIFIED_TYPE = new CPPBasicType(Kind.eUnspecified, 0); public static final CPPBasicType SHORT = new CPPBasicType(Kind.eInt, IBasicType.IS_SHORT); public static final CPPBasicType INT = new CPPBasicType(Kind.eInt, 0); public static final CPPBasicType LONG = new CPPBasicType(Kind.eInt, IBasicType.IS_LONG); public static final CPPBasicType LONG_LONG = new CPPBasicType(Kind.eInt, IBasicType.IS_LONG_LONG); public static final CPPBasicType INT128 = new CPPBasicType(Kind.eInt128, 0); - public static final CPPBasicType UNSIGNED_SHORT = new CPPBasicType(Kind.eInt, IBasicType.IS_SHORT | IBasicType.IS_UNSIGNED); + public static final CPPBasicType UNSIGNED_SHORT = new CPPBasicType(Kind.eInt, + IBasicType.IS_SHORT | IBasicType.IS_UNSIGNED); public static final CPPBasicType UNSIGNED_INT = new CPPBasicType(Kind.eInt, IBasicType.IS_UNSIGNED); - public static final CPPBasicType UNSIGNED_LONG = new CPPBasicType(Kind.eInt, IBasicType.IS_LONG | IBasicType.IS_UNSIGNED); - public static final CPPBasicType UNSIGNED_LONG_LONG = new CPPBasicType(Kind.eInt, IBasicType.IS_LONG_LONG | IBasicType.IS_UNSIGNED); + public static final CPPBasicType UNSIGNED_LONG = new CPPBasicType(Kind.eInt, + IBasicType.IS_LONG | IBasicType.IS_UNSIGNED); + public static final CPPBasicType UNSIGNED_LONG_LONG = new CPPBasicType(Kind.eInt, + IBasicType.IS_LONG_LONG | IBasicType.IS_UNSIGNED); public static final CPPBasicType UNSIGNED_INT128 = new CPPBasicType(Kind.eInt128, IBasicType.IS_UNSIGNED); public static final CPPBasicType CHAR = new CPPBasicType(Kind.eChar, 0); public static final CPPBasicType VOID = new CPPBasicType(Kind.eVoid, 0); @@ -65,20 +68,20 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { public CPPBasicType(Kind kind, int qualifiers, IASTExpression expression) { if (kind == Kind.eUnspecified) { if ((qualifiers & (IS_COMPLEX | IS_IMAGINARY)) != 0) { - fKind= Kind.eFloat; + fKind = Kind.eFloat; } else if ((qualifiers & (IS_LONG | IS_SHORT | IS_SIGNED | IS_UNSIGNED | IS_LONG_LONG)) != 0) { - fKind= Kind.eInt; + fKind = Kind.eInt; } else { - fKind= Kind.eUnspecified; + fKind = Kind.eUnspecified; } } else { - fKind= kind; + fKind = kind; } - if (expression instanceof IASTLiteralExpression && - ((IASTLiteralExpression) expression).getKind() == IASTLiteralExpression.lk_string_literal) { + if (expression instanceof IASTLiteralExpression + && ((IASTLiteralExpression) expression).getKind() == IASTLiteralExpression.lk_string_literal) { qualifiers |= FROM_STRING_LITERAL; } - fModifiers= qualifiers; + fModifiers = qualifiers; if (expression instanceof ICPPASTInitializerClause) { Number num = ValueFactory.create(expression).numberValue(); fAssociatedValue = num != null ? num.longValue() : null; @@ -94,14 +97,10 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } private static int getModifiers(ICPPASTSimpleDeclSpecifier sds) { - return - (sds.isLong() ? IBasicType.IS_LONG : 0) | - (sds.isShort() ? IBasicType.IS_SHORT : 0) | - (sds.isSigned() ? IBasicType.IS_SIGNED: 0) | - (sds.isUnsigned() ? IBasicType.IS_UNSIGNED : 0) | - (sds.isLongLong() ? IBasicType.IS_LONG_LONG : 0) | - (sds.isComplex() ? IBasicType.IS_COMPLEX : 0) | - (sds.isImaginary() ? IBasicType.IS_IMAGINARY : 0); + return (sds.isLong() ? IBasicType.IS_LONG : 0) | (sds.isShort() ? IBasicType.IS_SHORT : 0) + | (sds.isSigned() ? IBasicType.IS_SIGNED : 0) | (sds.isUnsigned() ? IBasicType.IS_UNSIGNED : 0) + | (sds.isLongLong() ? IBasicType.IS_LONG_LONG : 0) | (sds.isComplex() ? IBasicType.IS_COMPLEX : 0) + | (sds.isImaginary() ? IBasicType.IS_IMAGINARY : 0); } private static Kind getKind(ICPPASTSimpleDeclSpecifier sds) { @@ -149,8 +148,8 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { if (object == this) return true; - if (object instanceof ITypedef) - return object.isSameType(this); + if (object instanceof ITypedef) + return object.isSameType(this); if (!(object instanceof ICPPBasicType)) return false; @@ -211,13 +210,13 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { @Override public CPPBasicType clone() { CPPBasicType t = null; - try { - t = (CPPBasicType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen. - } - return t; - } + try { + t = (CPPBasicType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen. + } + return t; + } /** * Sets the numerical value this type was created for. @@ -254,9 +253,9 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - final int kind= getKind().ordinal(); - final int shiftedKind= kind * ITypeMarshalBuffer.FIRST_FLAG; - final int modifiers= getModifiers(); + final int kind = getKind().ordinal(); + final int shiftedKind = kind * ITypeMarshalBuffer.FIRST_FLAG; + final int modifiers = getModifiers(); short firstBytes = (short) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind); if (modifiers != 0) firstBytes |= ITypeMarshalBuffer.LAST_FLAG; @@ -270,12 +269,12 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - final boolean haveModifiers= (firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0; - final boolean haveAssociatedNumericalValue= (firstBytes & ITypeMarshalBuffer.SECOND_LAST_FLAG) != 0; - int modifiers= 0; - int kind= (firstBytes & (ITypeMarshalBuffer.SECOND_LAST_FLAG - 1)) / ITypeMarshalBuffer.FIRST_FLAG; + final boolean haveModifiers = (firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0; + final boolean haveAssociatedNumericalValue = (firstBytes & ITypeMarshalBuffer.SECOND_LAST_FLAG) != 0; + int modifiers = 0; + int kind = (firstBytes & (ITypeMarshalBuffer.SECOND_LAST_FLAG - 1)) / ITypeMarshalBuffer.FIRST_FLAG; if (haveModifiers) - modifiers= buffer.getByte(); + modifiers = buffer.getByte(); CPPBasicType result = new CPPBasicType(Kind.values()[kind], modifiers); if (haveAssociatedNumericalValue) result.setAssociatedNumericalValue(buffer.getLong()); @@ -322,9 +321,9 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { return t_unspecified; } - /** - * @deprecated Types don't have values - */ + /** + * @deprecated Types don't have values + */ @Override @Deprecated public IASTExpression getValue() { @@ -336,8 +335,8 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { if (fPseudoDestructor == null) { char[] dtorName = ("~" + toString()).toCharArray(); //$NON-NLS-1$ IScope globalScope = CPPSemantics.getCurrentLookupPoint().getTranslationUnit().getScope(); - fPseudoDestructor = new CPPImplicitFunction(dtorName, globalScope, - CPPClassScope.DESTRUCTOR_FUNCTION_TYPE, EMPTY_CPPPARAMETER_ARRAY, true, false); + fPseudoDestructor = new CPPImplicitFunction(dtorName, globalScope, CPPClassScope.DESTRUCTOR_FUNCTION_TYPE, + EMPTY_CPPPARAMETER_ARRAY, true, false); } return fPseudoDestructor; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java index f15ba200dc6..aea9fd6fb78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java @@ -36,15 +36,15 @@ public class CPPBlockScope extends CPPNamespaceScope implements ICPPBlockScope { @Override public IName getScopeName() { - IASTNode node = getPhysicalNode(); - if (node instanceof IASTCompoundStatement) { - final IASTNode parent= node.getParent(); - if (parent instanceof IASTFunctionDefinition) { - IASTDeclarator dtor= ((IASTFunctionDefinition) parent).getDeclarator(); - dtor = ASTQueries.findInnermostDeclarator(dtor); + IASTNode node = getPhysicalNode(); + if (node instanceof IASTCompoundStatement) { + final IASTNode parent = node.getParent(); + if (parent instanceof IASTFunctionDefinition) { + IASTDeclarator dtor = ((IASTFunctionDefinition) parent).getDeclarator(); + dtor = ASTQueries.findInnermostDeclarator(dtor); return dtor.getName(); - } - } - return null; + } + } + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java index 1c79bbda077..3dd21dc3de9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java @@ -29,99 +29,99 @@ public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter if (ft == null) { return ICPPParameter.EMPTY_CPPPARAMETER_ARRAY; } - IType[] ptypes= ft.getParameterTypes(); - ICPPParameter[] result= new ICPPParameter[ptypes.length]; + IType[] ptypes = ft.getParameterTypes(); + ICPPParameter[] result = new ICPPParameter[ptypes.length]; for (int i = 0; i < result.length; i++) { - result[i]= new CPPBuiltinParameter(ptypes[i]); + result[i] = new CPPBuiltinParameter(ptypes[i]); } return result; } - private IType type; + private IType type; - public CPPBuiltinParameter(IType type) { - this.type = type; - } + public CPPBuiltinParameter(IType type) { + this.type = type; + } - @Override + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public boolean isStatic() { - return false; - } + return false; + } - @Override + @Override public boolean isExtern() { - return false; - } + return false; + } @Override public boolean isExternC() { return false; } - @Override + @Override public boolean isAuto() { - return false; - } + return false; + } - @Override + @Override public boolean isRegister() { - return false; - } + return false; + } - @Override + @Override public String getName() { - return ""; //$NON-NLS-1$ - } + return ""; //$NON-NLS-1$ + } - @Override + @Override public char[] getNameCharArray() { - return CharArrayUtils.EMPTY; - } + return CharArrayUtils.EMPTY; + } - @Override + @Override public IScope getScope() { - return null; - } + return null; + } - @Override + @Override public boolean hasDefaultValue() { - return false; - } + return false; + } @Override public IValue getDefaultValue() { return null; } - @Override + @Override public boolean isMutable() { - return false; - } + return false; + } - @Override + @Override public boolean isConstexpr() { - return false; - } + return false; + } - @Override + @Override public String[] getQualifiedName() { - return new String[0]; - } + return new String[0]; + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return new char[0][]; - } + return new char[0][]; + } - @Override + @Override public boolean isGloballyQualified() { - return false; - } + return false; + } @Override public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinVariable.java index 78e07f77e5b..a68d5249b71 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinVariable.java @@ -26,93 +26,92 @@ import org.eclipse.cdt.core.dom.ast.IType; * An example is the built-in variable __func__. */ public class CPPBuiltinVariable extends CPPVariable { - private IType type; - private char[] name; - private IScope scope; - - public CPPBuiltinVariable(IType type, char[] name, IScope scope) { - super(null); - this.type = type; - this.name = name; - this.scope = scope; - } - - @Override + private IType type; + private char[] name; + private IScope scope; + + public CPPBuiltinVariable(IType type, char[] name, IScope scope) { + super(null); + this.type = type; + this.name = name; + this.scope = scope; + } + + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public String getName() { - return String.valueOf(name); - } + return String.valueOf(name); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() { - return scope; - } + return scope; + } - /** - * Returns null. - */ - @Override + /** + * Returns null. + */ + @Override public IASTName[] getDeclarations() { - return null; - } + return null; + } - /** - * Returns null. - */ - @Override + /** + * Returns null. + */ + @Override public IASTNode getDefinition() { - return null; - } + return null; + } - /** - * Does nothing. - */ - @Override + /** + * Does nothing. + */ + @Override public void addDefinition(IASTNode node) { - // do nothing - } + // do nothing + } - /** - * Does nothing. - */ - @Override + /** + * Does nothing. + */ + @Override public void addDeclaration(IASTNode node) { - // do nothing - } + // do nothing + } - @Override + @Override public String[] getQualifiedName() { - String[] temp = new String[1]; - temp[0] = String.valueOf(name); - - return temp; - } + String[] temp = new String[1]; + temp[0] = String.valueOf(name); + return temp; + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - char[][] temp = new char[1][]; - temp[0] = name; + char[][] temp = new char[1][]; + temp[0] = name; - return temp; - } + return temp; + } - /** - * Returns true. - */ - @Override + /** + * Returns true. + */ + @Override public boolean isGloballyQualified() { - return true; - } + return true; + } @Override public IBinding getOwner() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java index 4d57cac0b41..f29469271b9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java @@ -41,7 +41,7 @@ public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemp public CPPClassInstance(ICPPClassType orig, IBinding owner, ICPPTemplateParameterMap argMap, ICPPTemplateArgument[] args) { super(orig, owner, argMap); - this.arguments= args; + this.arguments = args; } @Override @@ -104,14 +104,14 @@ public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemp assert classInstance instanceof ICPPTemplateInstance; // Require a class instance. - if (!(type instanceof ICPPClassSpecialization) || !(type instanceof ICPPTemplateInstance) || - type instanceof IProblemBinding) { + if (!(type instanceof ICPPClassSpecialization) || !(type instanceof ICPPTemplateInstance) + || type instanceof IProblemBinding) { return false; } final ICPPClassSpecialization classSpec2 = (ICPPClassSpecialization) type; - final ICPPClassType orig1= classInstance.getSpecializedBinding(); - final ICPPClassType orig2= classSpec2.getSpecializedBinding(); + final ICPPClassType orig1 = classInstance.getSpecializedBinding(); + final ICPPClassType orig2 = classSpec2.getSpecializedBinding(); if (!orig1.isSameType(orig2)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index 05fc55ce44f..2aaf8ad52da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -74,8 +74,8 @@ import org.eclipse.core.runtime.IStatus; public class CPPClassScope extends CPPScope implements ICPPClassScope { // Destructors don't have a return type, but the type of a destructor call expression // is void, so it's simpler to model them as having a void return type. - public static final ICPPFunctionType DESTRUCTOR_FUNCTION_TYPE = - CPPVisitor.createImplicitFunctionType(VOID, EMPTY_CPPPARAMETER_ARRAY, false, false); + public static final ICPPFunctionType DESTRUCTOR_FUNCTION_TYPE = CPPVisitor.createImplicitFunctionType(VOID, + EMPTY_CPPPARAMETER_ARRAY, false, false); private ICPPMethod[] implicits; @@ -93,32 +93,31 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { * if appropriate. The method will be called after ambiguity resolution. */ public void createImplicitMembers() { - // Create bindings for the implicit members, if the user declared them then those + // Create bindings for the implicit members, if the user declared them then those // declarations will resolve to these bindings. - ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); + ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName name = compTypeSpec.getName().getLastName(); - IBinding binding = name.resolveBinding(); - if (!(binding instanceof ICPPClassType)) - return; + IASTName name = compTypeSpec.getName().getLastName(); + IBinding binding = name.resolveBinding(); + if (!(binding instanceof ICPPClassType)) + return; - ICPPClassType classType = (ICPPClassType) binding; - if (classType instanceof ICPPClassTemplate) { - classType= (ICPPClassType) ((ICPPClassTemplate) classType).asDeferredInstance(); - } - char[] className = name.getLookupKey(); + ICPPClassType classType = (ICPPClassType) binding; + if (classType instanceof ICPPClassTemplate) { + classType = (ICPPClassType) ((ICPPClassTemplate) classType).asDeferredInstance(); + } + char[] className = name.getLookupKey(); IType pType = new CPPReferenceType(SemanticUtil.constQualify(classType), false); ICPPParameter[] params = new ICPPParameter[] { new CPPParameter(pType, 0) }; - int i= 0; - ImplicitsAnalysis ia= new ImplicitsAnalysis(compTypeSpec, classType); - implicits= new ICPPMethod[ia.getImplicitsToDeclareCount()]; + int i = 0; + ImplicitsAnalysis ia = new ImplicitsAnalysis(compTypeSpec, classType); + implicits = new ICPPMethod[ia.getImplicitsToDeclareCount()]; if (!ia.hasUserDeclaredConstructor()) { // Default constructor: A(void) - ICPPMethod m = new CPPImplicitConstructor(this, className, EMPTY_CPPPARAMETER_ARRAY, - compTypeSpec); + ICPPMethod m = new CPPImplicitConstructor(this, className, EMPTY_CPPPARAMETER_ARRAY, compTypeSpec); implicits[i++] = m; addBinding(m); } @@ -133,16 +132,15 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { if (!ia.hasUserDeclaredCopyAssignmentOperator()) { // Copy assignment operator: A& operator = (const A &) IType refType = new CPPReferenceType(classType, false); - ICPPFunctionType ft= CPPVisitor.createImplicitFunctionType(refType, params, false, false); - ICPPMethod m = - new CPPImplicitMethod(this, OverloadableOperator.ASSIGN.toCharArray(), ft, params, false); + ICPPFunctionType ft = CPPVisitor.createImplicitFunctionType(refType, params, false, false); + ICPPMethod m = new CPPImplicitMethod(this, OverloadableOperator.ASSIGN.toCharArray(), ft, params, false); implicits[i++] = m; addBinding(m); } if (!ia.hasUserDeclaredDestructor()) { // Destructor: ~A() - char[] dtorName = CharArrayUtils.concat("~".toCharArray(), className); //$NON-NLS-1$ + char[] dtorName = CharArrayUtils.concat("~".toCharArray(), className); //$NON-NLS-1$ ICPPMethod m = new CPPImplicitMethod(this, dtorName, DESTRUCTOR_FUNCTION_TYPE, EMPTY_CPPPARAMETER_ARRAY, false); implicits[i++] = m; @@ -160,7 +158,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { if (bases.length == 0) return; IASTDeclaration[] members = compositeTypeSpec.getMembers(); - for (IASTDeclaration member : members) { + for (IASTDeclaration member : members) { if (member instanceof ICPPASTUsingDeclaration) { IASTName name = ((ICPPASTUsingDeclaration) member).getName(); if (!(name instanceof ICPPASTQualifiedName)) @@ -188,7 +186,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { } } } - } + } } private static boolean isConstructorNameForType(char[] lastName, IType type) { @@ -204,18 +202,18 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { @Override public IScope getParent() { - ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName compName = compType.getName().getLastName(); + ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); + IASTName compName = compType.getName().getLastName(); return CPPVisitor.getContainingNonTemplateScope(compName); } @Override public void addBinding(IBinding binding) { - if (binding instanceof ICPPConstructor) { - addConstructor(binding); - return; - } - super.addBinding(binding); + if (binding instanceof ICPPConstructor) { + addConstructor(binding); + return; + } + super.addBinding(binding); } @Override @@ -226,7 +224,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { if (name instanceof ICPPASTQualifiedName) { // Check whether the qualification matches. - IBinding b= getClassType(); + IBinding b = getClassType(); final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name; final ICPPASTNameSpecifier[] qualifier = qname.getQualifier(); for (int i = qualifier.length; --i >= 0;) { @@ -246,7 +244,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { if (!CharArrayUtils.equals(segmentName, b.getNameCharArray())) return; - b= b.getOwner(); + b = b.getOwner(); } if (qname.isFullyQualified() && b != null) return; @@ -264,66 +262,66 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { @SuppressWarnings({ "rawtypes", "unchecked" }) private void addConstructor(Object constructor) { if (bindings == null) - bindings = new CharArrayObjectMap(1); - - Object o = bindings.get(CONSTRUCTOR_KEY); - if (o != null) { - if (o instanceof ObjectSet) { - ((ObjectSet) o).put(constructor); - } else { - ObjectSet set = new ObjectSet(2); - set.put(o); - set.put(constructor); - bindings.put(CONSTRUCTOR_KEY, set); - } - } else { - bindings.put(CONSTRUCTOR_KEY, constructor); - } + bindings = new CharArrayObjectMap(1); + + Object o = bindings.get(CONSTRUCTOR_KEY); + if (o != null) { + if (o instanceof ObjectSet) { + ((ObjectSet) o).put(constructor); + } else { + ObjectSet set = new ObjectSet(2); + set.put(o); + set.put(constructor); + bindings.put(CONSTRUCTOR_KEY, set); + } + } else { + bindings.put(CONSTRUCTOR_KEY, constructor); + } } @Override public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) { - char[] c = name.getLookupKey(); + char[] c = name.getLookupKey(); - ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName compName = compType.getName().getLastName(); + ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); + IASTName compName = compType.getName().getLastName(); if (compName instanceof ICPPASTTemplateId) { - compName= ((ICPPASTTemplateId) compName).getTemplateName(); + compName = ((ICPPASTTemplateId) compName).getTemplateName(); + } + if (CharArrayUtils.equals(c, compName.getLookupKey())) { + // 9.2 ... The class-name is also inserted into the scope of the class itself. + return compName.resolveBinding(); } - if (CharArrayUtils.equals(c, compName.getLookupKey())) { - // 9.2 ... The class-name is also inserted into the scope of the class itself. - return compName.resolveBinding(); - } - return super.getBinding(name, resolve, fileSet); + return super.getBinding(name, resolve, fileSet); } @Override public IBinding[] getBindings(ScopeLookupData lookup) { - char[] c = lookup.getLookupKey(); - final boolean prefixLookup= lookup.isPrefixLookup(); + char[] c = lookup.getLookupKey(); + final boolean prefixLookup = lookup.isPrefixLookup(); - ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName compName = compType.getName().getLastName(); + ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); + IASTName compName = compType.getName().getLastName(); if (compName instanceof ICPPASTTemplateId) { - compName= ((ICPPASTTemplateId) compName).getTemplateName(); + compName = ((ICPPASTTemplateId) compName).getTemplateName(); } - IBinding[] result = IBinding.EMPTY_BINDING_ARRAY; - int n = 0; - if ((!prefixLookup && CharArrayUtils.equals(c, compName.getLookupKey())) + IBinding[] result = IBinding.EMPTY_BINDING_ARRAY; + int n = 0; + if ((!prefixLookup && CharArrayUtils.equals(c, compName.getLookupKey())) || (prefixLookup && ContentAssistMatcherFactory.getInstance().match(c, compName.getLookupKey()))) { - final IASTName lookupName = lookup.getLookupName(); + final IASTName lookupName = lookup.getLookupName(); if (shallReturnConstructors(lookupName, prefixLookup)) { - ICPPConstructor[] constructors = getConstructors(lookupName, lookup.isResolve()); + ICPPConstructor[] constructors = getConstructors(lookupName, lookup.isResolve()); result = addAll(result, constructors); n += constructors.length; - } - // 9.2 ... The class-name is also inserted into the scope of the class itself. - result = appendAt(result, n++, compName.resolveBinding()); - } - IBinding[] bindings = super.getBindings(lookup); + } + // 9.2 ... The class-name is also inserted into the scope of the class itself. + result = appendAt(result, n++, compName.resolveBinding()); + } + IBinding[] bindings = super.getBindings(lookup); result = addAll(result, bindings); n += bindings.length; - return trim(result, n); + return trim(result, n); } static protected boolean shouldResolve(boolean force, IASTName candidate, IASTName forName) { @@ -351,37 +349,37 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { Object o = nameMap.get(CONSTRUCTOR_KEY); if (o != null) { IBinding binding = null; - if (o instanceof ObjectSet<?>) { - ObjectSet<?> set = (ObjectSet<?>) o; - ICPPConstructor[] bs = ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; - int n = 0; - for (int i = 0; i < set.size(); i++) { - Object obj = set.keyAt(i); - if (obj instanceof IASTName) { - IASTName name = (IASTName) obj; - binding = shouldResolve(forceResolve, name, forName) ? - name.resolveBinding() : name.getBinding(); - if (binding instanceof ICPPConstructor) { - bs = appendAt(bs, n++, (ICPPConstructor) binding); - } - } else if (obj instanceof ICPPConstructor) { + if (o instanceof ObjectSet<?>) { + ObjectSet<?> set = (ObjectSet<?>) o; + ICPPConstructor[] bs = ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + int n = 0; + for (int i = 0; i < set.size(); i++) { + Object obj = set.keyAt(i); + if (obj instanceof IASTName) { + IASTName name = (IASTName) obj; + binding = shouldResolve(forceResolve, name, forName) ? name.resolveBinding() + : name.getBinding(); + if (binding instanceof ICPPConstructor) { + bs = appendAt(bs, n++, (ICPPConstructor) binding); + } + } else if (obj instanceof ICPPConstructor) { bs = appendAt(bs, n++, (ICPPConstructor) obj); - } - } - return trim(bs, n); - } else if (o instanceof IASTName) { - if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName) o).getBinding() != null) { - // Always store the name, rather than the binding, so that we can properly flush the scope. - nameMap.put(CONSTRUCTOR_KEY, o); - binding = ((IASTName) o).resolveBinding(); - } - } else if (o instanceof IBinding) { - binding = (IBinding) o; - } - if (binding != null && binding instanceof ICPPConstructor) { - return new ICPPConstructor[] { (ICPPConstructor) binding }; - } - } + } + } + return trim(bs, n); + } else if (o instanceof IASTName) { + if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName) o).getBinding() != null) { + // Always store the name, rather than the binding, so that we can properly flush the scope. + nameMap.put(CONSTRUCTOR_KEY, o); + binding = ((IASTName) o).resolveBinding(); + } + } else if (o instanceof IBinding) { + binding = (IBinding) o; + } + if (binding != null && binding instanceof ICPPConstructor) { + return new ICPPConstructor[] { (ICPPConstructor) binding }; + } + } return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; } @@ -392,18 +390,18 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { @Override public IBinding[] find(String name) { - char[] n = name.toCharArray(); - ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName compName = compType.getName().getLastName(); + char[] n = name.toCharArray(); + ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); + IASTName compName = compType.getName().getLastName(); if (compName instanceof ICPPASTTemplateId) { - compName= ((ICPPASTTemplateId) compName).getTemplateName(); + compName = ((ICPPASTTemplateId) compName).getTemplateName(); } - if (CharArrayUtils.equals(compName.getLookupKey(), n)) { - return new IBinding[] { compName.resolveBinding() }; - } + if (CharArrayUtils.equals(compName.getLookupKey(), n)) { + return new IBinding[] { compName.resolveBinding() }; + } - return super.find(name); + return super.find(name); } public static boolean shallReturnConstructors(IASTName name, boolean isPrefixLookup) { @@ -411,8 +409,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { return false; if (!isPrefixLookup) { - return CPPVisitor.isConstructorDeclaration(name) - || CPPVisitor.isLastNameInUsingDeclaration(name); + return CPPVisitor.isConstructorDeclaration(name) || CPPVisitor.isLastNameInUsingDeclaration(name); } IASTNode node = name.getParent(); @@ -455,12 +452,12 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { return implicits; } - @Override + @Override public IName getScopeName() { - IASTNode node = getPhysicalNode(); - if (node instanceof ICPPASTCompositeTypeSpecifier) { - return ((ICPPASTCompositeTypeSpecifier) node).getName(); - } - return null; - } + IASTNode node = getPhysicalNode(); + if (node instanceof ICPPASTCompositeTypeSpecifier) { + return ((ICPPASTCompositeTypeSpecifier) node).getName(); + } + return null; + } }
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index 2cf44c8c382..39b5ea68087 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -61,7 +61,8 @@ import org.eclipse.core.runtime.Assert; public class CPPClassSpecialization extends CPPSpecialization implements ICPPClassSpecialization, ICPPInternalClassTypeMixinHost { - public static class RecursionResolvingBinding extends ProblemBinding implements ICPPMember, IRecursionResolvingBinding { + public static class RecursionResolvingBinding extends ProblemBinding + implements ICPPMember, IRecursionResolvingBinding { public static RecursionResolvingBinding createFor(IBinding original) { IASTNode point = CPPSemantics.getCurrentLookupPoint(); if (original instanceof ICPPMethod) @@ -137,7 +138,7 @@ public class CPPClassSpecialization extends CPPSpecialization public ICPPFunctionType getDeclaredType() { return new ProblemFunctionType(getID()); } - + @Override public ICPPFunctionType getType() { return new ProblemFunctionType(getID()); @@ -160,17 +161,16 @@ public class CPPClassSpecialization extends CPPSpecialization } private ICPPClassSpecializationScope specScope; - private ObjectMap specializationMap= ObjectMap.EMPTY_MAP; + private ObjectMap specializationMap = ObjectMap.EMPTY_MAP; private ICPPBase[] bases; - private final ThreadLocal<Set<IBinding>> fInProgress= new ThreadLocal<Set<IBinding>>() { + private final ThreadLocal<Set<IBinding>> fInProgress = new ThreadLocal<Set<IBinding>>() { @Override protected Set<IBinding> initialValue() { return new HashSet<>(); } }; - public CPPClassSpecialization(ICPPClassType specialized, IBinding owner, - ICPPTemplateParameterMap argumentMap) { + public CPPClassSpecialization(ICPPClassType specialized, IBinding owner, ICPPTemplateParameterMap argumentMap) { super(specialized, owner, argumentMap); } @@ -182,24 +182,24 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public IBinding specializeMember(IBinding original) { synchronized (this) { - IBinding result= (IBinding) specializationMap.get(original); + IBinding result = (IBinding) specializationMap.get(original); if (result != null) return result; } IBinding result; - Set<IBinding> recursionProtectionSet= fInProgress.get(); + Set<IBinding> recursionProtectionSet = fInProgress.get(); if (!recursionProtectionSet.add(original)) return RecursionResolvingBinding.createFor(original); try { - result= CPPTemplates.createSpecialization(this, original); + result = CPPTemplates.createSpecialization(this, original); } finally { recursionProtectionSet.remove(original); } synchronized (this) { - IBinding concurrent= (IBinding) specializationMap.get(original); + IBinding concurrent = (IBinding) specializationMap.get(original); if (concurrent != null) return concurrent; if (specializationMap == ObjectMap.EMPTY_MAP) @@ -221,11 +221,11 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() { - IASTNode definition= getDefinition(); + IASTNode definition = getDefinition(); if (definition != null) { - IASTNode node= definition; + IASTNode node = definition; while (node instanceof IASTName) - node= node.getParent(); + node = node.getParent(); if (node instanceof ICPPASTCompositeTypeSpecifier) return (ICPPASTCompositeTypeSpecifier) node; } @@ -234,7 +234,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { - ICPPClassSpecializationScope scope= getSpecializationScope(); + ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) { if (bases == null) { bases = ClassTypeHelper.getBases(this); @@ -253,7 +253,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPField[] getDeclaredFields() { - ICPPClassSpecializationScope scope= getSpecializationScope(); + ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) return ClassTypeHelper.getDeclaredFields(this); @@ -268,7 +268,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPMethod[] getDeclaredMethods() { - ICPPClassSpecializationScope scope= getSpecializationScope(); + ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) return ClassTypeHelper.getDeclaredMethods(this); @@ -283,7 +283,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPConstructor[] getConstructors() { - ICPPClassSpecializationScope scope= getSpecializationScope(); + ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) return ClassTypeHelper.getConstructors(this); @@ -298,7 +298,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public IBinding[] getFriends() { - ICPPClassSpecializationScope scope= getSpecializationScope(); + ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) return ClassTypeHelper.getFriends(this); @@ -313,7 +313,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPClassType[] getNestedClasses() { - ICPPClassSpecializationScope scope= getSpecializationScope(); + ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) return ClassTypeHelper.getNestedClasses(this); @@ -325,16 +325,16 @@ public class CPPClassSpecialization extends CPPSpecialization public ICPPClassType[] getNestedClasses(IASTNode point) { return getNestedClasses(); } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { ICPPClassSpecializationScope scope = getSpecializationScope(); if (scope == null) return ClassTypeHelper.getUsingDeclarations(this); - + return scope.getUsingDeclarations(); } - + @Override @Deprecated public ICPPUsingDeclaration[] getUsingDeclarations(IASTNode point) { @@ -389,7 +389,7 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPClassScope getCompositeScope() { - final ICPPClassScope specScope= getSpecializationScope(); + final ICPPClassScope specScope = getSpecializationScope(); if (specScope != null) return specScope; @@ -435,12 +435,12 @@ public class CPPClassSpecialization extends CPPSpecialization if (getNameCharArray().length > 0) return false; - ICPPASTCompositeTypeSpecifier spec= getCompositeTypeSpecifier(); + ICPPASTCompositeTypeSpecifier spec = getCompositeTypeSpecifier(); if (spec == null) { return getSpecializedBinding().isAnonymous(); } - IASTNode node= spec.getParent(); + IASTNode node = spec.getParent(); if (node instanceof IASTSimpleDeclaration) { if (((IASTSimpleDeclaration) node).getDeclarators().length == 0) { return true; @@ -451,8 +451,8 @@ public class CPPClassSpecialization extends CPPSpecialization public static boolean isSameClassSpecialization(ICPPClassSpecialization t1, ICPPClassSpecialization t2) { // Exclude class template specialization or class instance. - if (t2 instanceof ICPPTemplateInstance || t2 instanceof ICPPTemplateDefinition || - t2 instanceof IProblemBinding) { + if (t2 instanceof ICPPTemplateInstance || t2 instanceof ICPPTemplateDefinition + || t2 instanceof IProblemBinding) { return false; } @@ -465,8 +465,8 @@ public class CPPClassSpecialization extends CPPSpecialization // The argument map is not significant for comparing specializations, the map is // determined by the owner of the specialization. This is different for instances, // which have a separate implementation for isSameType(). - final IBinding owner1= t1.getOwner(); - final IBinding owner2= t2.getOwner(); + final IBinding owner1 = t1.getOwner(); + final IBinding owner2 = t2.getOwner(); // For a specialization that is not an instance the owner has to be a class-type. if (!(owner1 instanceof ICPPClassType) || !(owner2 instanceof ICPPClassType)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java index 92585606d1c..17014efb441 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java @@ -32,13 +32,23 @@ public class CPPClassSpecializationScope extends AbstractCPPClassSpecializationS // This scope does not cache its own names @Override - public void addName(IASTName name, boolean adlOnly) {} + public void addName(IASTName name, boolean adlOnly) { + } + @Override - public IASTNode getPhysicalNode() { return null; } + public IASTNode getPhysicalNode() { + return null; + } + @Override - public void addBinding(IBinding binding) {} + public void addBinding(IBinding binding) { + } + @Override - public void populateCache() {} + public void populateCache() { + } + @Override - public void removeNestedFromCache(IASTNode container) {} + public void removeNestedFromCache(IASTNode container) { + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index a9ac2c0eb7e..f83a4e1092d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -49,8 +49,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** * Represents a class template. */ -public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClassTemplate, - ICPPInternalClassTemplate, ICPPInternalClassTypeMixinHost { +public class CPPClassTemplate extends CPPTemplateDefinition + implements ICPPClassTemplate, ICPPInternalClassTemplate, ICPPInternalClassTypeMixinHost { private ICPPClassTemplatePartialSpecialization[] partialSpecializations; private ICPPDeferredClassInstance fDeferredInstance; private boolean addedPartialSpecializationsOfIndex; @@ -67,8 +67,8 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) { - partialSpecializations = ArrayUtil.append( - ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec); + partialSpecializations = ArrayUtil.append(ICPPClassTemplatePartialSpecialization.class, partialSpecializations, + spec); } @Override @@ -111,11 +111,11 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public int getKey() { if (definition != null) { - ICPPASTCompositeTypeSpecifier cts= getCompositeTypeSpecifier(); + ICPPASTCompositeTypeSpecifier cts = getCompositeTypeSpecifier(); if (cts != null) { return cts.getKey(); } - IASTNode n= definition.getParent(); + IASTNode n = definition.getParent(); if (n instanceof ICPPASTElaboratedTypeSpecifier) { return ((ICPPASTElaboratedTypeSpecifier) n).getKind(); } @@ -134,7 +134,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { if (!addedPartialSpecializationsOfIndex) { - addedPartialSpecializationsOfIndex= true; + addedPartialSpecializationsOfIndex = true; ICPPClassTemplate ib = getIndexBinding(); if (ib != null) { IIndexFileSet fs = getTemplateName().getTranslationUnit().getIndexFileSet(); @@ -205,7 +205,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass public ICPPClassType[] getNestedClasses() { return ClassTypeHelper.getNestedClasses(this); } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ClassTypeHelper.getUsingDeclarations(this); @@ -239,7 +239,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public final ICPPDeferredClassInstance asDeferredInstance() { if (fDeferredInstance == null) { - fDeferredInstance= CPPTemplates.createDeferredInstance(this); + fDeferredInstance = CPPTemplates.createDeferredInstance(this); } return fDeferredInstance; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java index a9897d0827b..da2e8330dd6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java @@ -34,7 +34,7 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate public CPPClassTemplatePartialSpecialization(ICPPASTTemplateId name, ICPPTemplateArgument[] arguments) { super(name); - this.arguments= arguments; + this.arguments = arguments; } @Override @@ -61,16 +61,15 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate return false; } - public static boolean isSamePartialClassSpecialization( - ICPPClassTemplatePartialSpecialization lhs, + public static boolean isSamePartialClassSpecialization(ICPPClassTemplatePartialSpecialization lhs, ICPPClassTemplatePartialSpecialization rhs) { - ICPPClassType ct1= lhs.getPrimaryClassTemplate(); - ICPPClassType ct2= rhs.getPrimaryClassTemplate(); + ICPPClassType ct1 = lhs.getPrimaryClassTemplate(); + ICPPClassType ct2 = rhs.getPrimaryClassTemplate(); if (!ct1.isSameType(ct2)) return false; - ICPPTemplateArgument[] args1= lhs.getTemplateArguments(); - ICPPTemplateArgument[] args2= rhs.getTemplateArguments(); + ICPPTemplateArgument[] args1 = lhs.getTemplateArguments(); + ICPPTemplateArgument[] args2 = rhs.getTemplateArguments(); if (args1.length != args2.length) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java index 5152ff0f96d..04ab115c60f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java @@ -40,11 +40,11 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas private final ICPPTemplateArgument[] fArguments; public CPPClassTemplatePartialSpecializationSpecialization(ICPPClassTemplatePartialSpecialization orig, - ICPPTemplateParameterMap argumentMap, ICPPClassTemplate template, - ICPPTemplateArgument[] args) throws DOMException { + ICPPTemplateParameterMap argumentMap, ICPPClassTemplate template, ICPPTemplateArgument[] args) + throws DOMException { super(orig, template.getOwner(), argumentMap); - fClassTemplate= template; - fArguments= args; + fClassTemplate = template; + fArguments = args; } @Override @@ -57,14 +57,14 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas public synchronized final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); instances.put(key, instance); } @Override public synchronized final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); return (ICPPTemplateInstance) instances.get(key); } return null; @@ -73,9 +73,9 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas @Override public synchronized ICPPTemplateInstance[] getAllInstances() { if (instances != null) { - ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i= 0; i < instances.size(); i++) { - result[i]= (ICPPTemplateInstance) instances.getAt(i); + ICPPTemplateInstance[] result = new ICPPTemplateInstance[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + result[i] = (ICPPTemplateInstance) instances.getAt(i); } return result; } @@ -90,7 +90,7 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas @Override public ICPPDeferredClassInstance asDeferredInstance() { if (fDeferredInstance == null) { - fDeferredInstance= CPPTemplates.createDeferredInstance(this); + fDeferredInstance = CPPTemplates.createDeferredInstance(this); } return fDeferredInstance; } @@ -122,7 +122,8 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas return type.isSameType(this); if (type instanceof ICPPClassTemplatePartialSpecializationSpecialization) { - return CPPClassTemplatePartialSpecialization.isSamePartialClassSpecialization(this, (ICPPClassTemplatePartialSpecializationSpecialization) type); + return CPPClassTemplatePartialSpecialization.isSamePartialClassSpecialization(this, + (ICPPClassTemplatePartialSpecializationSpecialization) type); } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 85dab63fd88..bfaa36f559a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -51,12 +51,12 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { if (fPartialSpecs == null) { - ICPPClassTemplate origTemplate= getSpecializedBinding(); + ICPPClassTemplate origTemplate = getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; ICPPClassSpecialization owner = getOwner(); for (int i = 0; i < orig.length; i++) { - spec[i]= (ICPPClassTemplatePartialSpecialization) owner.specializeMember(orig[i]); + spec[i] = (ICPPClassTemplatePartialSpecialization) owner.specializeMember(orig[i]); } fPartialSpecs = spec; } @@ -72,14 +72,14 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization public synchronized final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); instances.put(key, instance); } @Override public synchronized final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); return (ICPPTemplateInstance) instances.get(key); } return null; @@ -88,9 +88,9 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization @Override public synchronized ICPPTemplateInstance[] getAllInstances() { if (instances != null) { - ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i=0; i < instances.size(); i++) { - result[i]= (ICPPTemplateInstance) instances.getAt(i); + ICPPTemplateInstance[] result = new ICPPTemplateInstance[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + result[i] = (ICPPTemplateInstance) instances.getAt(i); } return result; } @@ -114,7 +114,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization @Override public final ICPPDeferredClassInstance asDeferredInstance() { if (fDeferredInstance == null) { - fDeferredInstance= CPPTemplates.createDeferredInstance(this); + fDeferredInstance = CPPTemplates.createDeferredInstance(this); } return fDeferredInstance; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 226863e01e8..681b04811ef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -59,68 +59,85 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp public CPPClassTypeProblem(IASTName name, int id) { super(name, id); } + public CPPClassTypeProblem(ICPPASTNameSpecifier nameSpec, int id) { super(nameSpec, id, nameSpec instanceof IASTName ? null : nameSpec.toCharArray()); } + public CPPClassTypeProblem(IASTNode node, int id, char[] arg) { super(node, id, arg); } + @Override public ICPPBase[] getBases() { return ICPPBase.EMPTY_BASE_ARRAY; } + @Override public IField[] getFields() { return IField.EMPTY_FIELD_ARRAY; } + @Override public ICPPField[] getDeclaredFields() { return ICPPField.EMPTY_CPPFIELD_ARRAY; } + @Override public ICPPMethod[] getMethods() { return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; } + @Override public ICPPMethod[] getAllDeclaredMethods() { return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; } + @Override public ICPPMethod[] getDeclaredMethods() { return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; } + @Override public ICPPConstructor[] getConstructors() { return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; } + @Override public int getKey() { return k_class; } + @Override public IField findField(String name) { return null; } + @Override public IScope getCompositeScope() { return this; } + @Override public IBinding[] getFriends() { return IBinding.EMPTY_BINDING_ARRAY; } + @Override public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ICPPUsingDeclaration.EMPTY_USING_DECL_ARRAY; } + @Override public boolean isFinal() { return false; } + @Override public int getVisibility(IBinding member) { throw new IllegalArgumentException(member.getName() + " is not a member of " + getName()); //$NON-NLS-1$ @@ -147,7 +164,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } name.setBinding(this); if (indexBinding instanceof ICPPClassType && indexBinding instanceof IIndexBinding) { - typeInIndex= (ICPPClassType) indexBinding; + typeInIndex = (ICPPClassType) indexBinding; } } @@ -166,9 +183,9 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp // Ambiguity resolution ensures that definitions are resolved. if (!checked) { if (definition == null && typeInIndex == null) { - IIndex index= getPhysicalNode().getTranslationUnit().getIndex(); + IIndex index = getPhysicalNode().getTranslationUnit().getIndex(); if (index != null) { - typeInIndex= (ICPPClassType) index.adaptBinding(this); + typeInIndex = (ICPPClassType) index.adaptBinding(this); } } checked = true; @@ -376,7 +393,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp public ICPPClassType[] getNestedClasses() { return ClassTypeHelper.getNestedClasses(this); } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ClassTypeHelper.getUsingDeclarations(this); @@ -417,9 +434,9 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp if (getNameCharArray().length > 0) return false; - ICPPASTCompositeTypeSpecifier spec= getCompositeTypeSpecifier(); + ICPPASTCompositeTypeSpecifier spec = getCompositeTypeSpecifier(); if (spec != null) { - IASTNode node= spec.getParent(); + IASTNode node = spec.getParent(); if (node instanceof IASTSimpleDeclaration) { if (((IASTSimpleDeclaration) node).getDeclarators().length == 0) { return true; @@ -440,8 +457,8 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp private IASTName stripQualifier(IASTName name) { if (name instanceof ICPPASTQualifiedName) { - name = ((ICPPASTQualifiedName) name).getLastName(); - } + name = ((ICPPASTQualifiedName) name).getLastName(); + } return name; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureSpecialization.java index 8399bccbba9..25bf900ee21 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureSpecialization.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; public class CPPClosureSpecialization extends CPPClosureType implements ICPPClassSpecialization { private CPPClosureType fSpecialized; private ICPPTemplateParameterMap fMap; - + public CPPClosureSpecialization(ICPPASTLambdaExpression lambda, CPPClosureType specialized, InstantiationContext context) { super(lambda); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index d765bde6922..3f3dc382d92 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -78,70 +78,73 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP private ICPPTemplateParameter[] fInventedTemplateParameters; public CPPClosureType(ICPPASTLambdaExpression lambdaExpr) { - fLambdaExpression= lambdaExpr; + fLambdaExpression = lambdaExpr; } - + private ICPPMethod[] createMethods() { - boolean needConversionOperator= - fLambdaExpression.getCaptureDefault() == CaptureDefault.UNSPECIFIED && - fLambdaExpression.getCaptures().length == 0; + boolean needConversionOperator = fLambdaExpression.getCaptureDefault() == CaptureDefault.UNSPECIFIED + && fLambdaExpression.getCaptures().length == 0; - final ICPPClassScope scope= getCompositeScope(); - ICPPMethod[] result= new ICPPMethod[needConversionOperator ? 6 : 5]; + final ICPPClassScope scope = getCompositeScope(); + ICPPMethod[] result = new ICPPMethod[needConversionOperator ? 6 : 5]; // Deleted default constructor: A() - CPPImplicitConstructor ctor= - new CPPImplicitConstructor(scope, CharArrayUtils.EMPTY, - ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, fLambdaExpression); + CPPImplicitConstructor ctor = new CPPImplicitConstructor(scope, CharArrayUtils.EMPTY, + ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, fLambdaExpression); ctor.setDeleted(true); - result[0]= ctor; + result[0] = ctor; // Copy constructor: A(const A &) IType pType = new CPPReferenceType(SemanticUtil.constQualify(this), false); ICPPParameter[] ps = new ICPPParameter[] { new CPPParameter(pType, 0) }; ctor = new CPPImplicitConstructor(scope, CharArrayUtils.EMPTY, ps, fLambdaExpression); - result[1]= ctor; + result[1] = ctor; // Deleted copy assignment operator: A& operator = (const A &) IType refType = new CPPReferenceType(this, false); - ICPPFunctionType ft= CPPVisitor.createImplicitFunctionType(refType, ps, false, false); + ICPPFunctionType ft = CPPVisitor.createImplicitFunctionType(refType, ps, false, false); ICPPMethod m = new CPPImplicitMethod(scope, OverloadableOperator.ASSIGN.toCharArray(), ft, ps, false); - result[2]= m; + result[2] = m; // Destructor: ~A() - ft= CPPVisitor.createImplicitFunctionType(UNSPECIFIED_TYPE, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, false, false); - m = new CPPImplicitMethod(scope, new char[] {'~'}, ft, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, false); - result[3]= m; + ft = CPPVisitor.createImplicitFunctionType(UNSPECIFIED_TYPE, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, false, + false); + m = new CPPImplicitMethod(scope, new char[] { '~' }, ft, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, false); + result[3] = m; // Function call operator - final IType returnType= getReturnType(); - final IType[] parameterTypes= getParameterTypes(); - ft= new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false, false, false); + final IType returnType = getReturnType(); + final IType[] parameterTypes = getParameterTypes(); + ft = new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false, false, false); ICPPParameter[] params = getParameters(); char[] operatorParensName = OverloadableOperator.PAREN.toCharArray(); if (isGeneric()) { - m = new CPPImplicitMethodTemplate(getInventedTemplateParameterList(), scope, operatorParensName, - ft, params, false) { + m = new CPPImplicitMethodTemplate(getInventedTemplateParameterList(), scope, operatorParensName, ft, params, + false) { @Override - public boolean isImplicit() { return false; } + public boolean isImplicit() { + return false; + } }; } else { - m= new CPPImplicitMethod(scope, operatorParensName, ft, params, false) { + m = new CPPImplicitMethod(scope, operatorParensName, ft, params, false) { @Override - public boolean isImplicit() { return false; } + public boolean isImplicit() { + return false; + } }; } - result[4]= m; + result[4] = m; // Conversion operator if (needConversionOperator) { final CPPFunctionType conversionTarget = new CPPFunctionType(returnType, parameterTypes); - ft= new CPPFunctionType(conversionTarget, IType.EMPTY_TYPE_ARRAY, true, false, false, false, false); - // Calling CPPASTConversionName.createName(IType) would try to stringize the type to - // construct a name, which is unnecessary work (not to mention prone to recursion with - // dependent types). Since the name doesn't matter anyways, just make one up. - char[] conversionOperatorName = CPPASTConversionName.createName("__fptr"); //$NON-NLS-1$ + ft = new CPPFunctionType(conversionTarget, IType.EMPTY_TYPE_ARRAY, true, false, false, false, false); + // Calling CPPASTConversionName.createName(IType) would try to stringize the type to + // construct a name, which is unnecessary work (not to mention prone to recursion with + // dependent types). Since the name doesn't matter anyways, just make one up. + char[] conversionOperatorName = CPPASTConversionName.createName("__fptr"); //$NON-NLS-1$ if (isGeneric()) { ICPPTemplateParameter[] templateParams = getInventedTemplateParameterList(); // Clone the template parameters, since they are used by the function call operator, @@ -150,18 +153,22 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP for (int i = 0; i < templateParams.length; ++i) { templateParamClones[i] = (ICPPTemplateParameter) ((IType) templateParams[i]).clone(); } - m = new CPPImplicitMethodTemplate(templateParamClones, scope, - conversionOperatorName, ft, params, false) { + m = new CPPImplicitMethodTemplate(templateParamClones, scope, conversionOperatorName, ft, params, + false) { @Override - public boolean isImplicit() { return false; } + public boolean isImplicit() { + return false; + } }; } else { - m= new CPPImplicitMethod(scope, conversionOperatorName, ft, params, false) { + m = new CPPImplicitMethod(scope, conversionOperatorName, ft, params, false) { @Override - public boolean isImplicit() { return false; } + public boolean isImplicit() { + return false; + } }; } - result[5]= m; + result[5] = m; } return result; } @@ -200,8 +207,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP } IASTCompoundStatement body = fLambdaExpression.getBody(); if (body != null) { - return CPPVisitor.deduceReturnType(body, declSpecForDeduction, declaratorForDeduction, - placeholder); + return CPPVisitor.deduceReturnType(body, declSpecForDeduction, declaratorForDeduction, placeholder); } return ProblemType.CANNOT_DEDUCE_AUTO_TYPE; } @@ -209,14 +215,14 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP public boolean isGeneric() { return getInventedTemplateParameterList().length > 0; } - + public ICPPTemplateParameter[] getInventedTemplateParameterList() { if (fInventedTemplateParameters == null) { fInventedTemplateParameters = computeInventedTemplateParameterList(); } return fInventedTemplateParameters; } - + public ICPPTemplateParameter[] computeInventedTemplateParameterList() { ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator(); ICPPTemplateParameter[] result = ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY; @@ -230,8 +236,8 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP if (declSpec instanceof IASTSimpleDeclSpecifier) { if (((IASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_auto) { boolean isPack = param.getDeclarator().declaresParameterPack(); - result = ArrayUtil.append(result, new CPPImplicitTemplateTypeParameter( - fLambdaExpression, position, isPack)); + result = ArrayUtil.append(result, + new CPPImplicitTemplateTypeParameter(fLambdaExpression, position, isPack)); position++; } } @@ -239,7 +245,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP } return ArrayUtil.trim(result); } - + private IType[] getParameterTypes() { if (fParameterTypes == null) { ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator(); @@ -251,10 +257,10 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP } return fParameterTypes; } - + public ICPPParameter[] getParameters() { if (fParameters == null) { - final IType[] parameterTypes= getParameterTypes(); + final IType[] parameterTypes = getParameterTypes(); fParameters = new ICPPParameter[parameterTypes.length]; ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator(); if (lambdaDtor != null) { @@ -287,7 +293,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP @Override public ICPPClassScope getCompositeScope() { if (fScope == null) { - fScope= new ClassScope(); + fScope = new ClassScope(); } return fScope; } @@ -346,7 +352,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP @Override public ICPPMethod[] getMethods() { if (fMethods == null) { - fMethods= createMethods(); + fMethods = createMethods(); } return fMethods; } @@ -363,14 +369,14 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP @Override public ICPPConstructor[] getConstructors() { - ICPPMethod[] methods= getMethods(); - int i= 0; + ICPPMethod[] methods = getMethods(); + int i = 0; for (; i < methods.length; i++) { if (!(methods[i] instanceof ICPPConstructor)) { break; } } - ICPPConstructor[] result= new ICPPConstructor[i]; + ICPPConstructor[] result = new ICPPConstructor[i]; System.arraycopy(methods, 0, result, 0, i); return result; } @@ -384,7 +390,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ICPPUsingDeclaration.EMPTY_USING_DECL_ARRAY; @@ -454,7 +460,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP throw new IllegalArgumentException(member.getName() + " is not a member of closure type '" //$NON-NLS-1$ + fLambdaExpression.getRawSignature() + "'"); //$NON-NLS-1$ } - + // A lambda expression can appear in a dependent context, such as in the value of // a variable template, so it needs to be instantiable. public CPPClosureType instantiate(InstantiationContext context) { @@ -487,15 +493,15 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP } private IBinding[] getBindings(char[] name) { - IBinding m= getBinding(name); + IBinding m = getBinding(name); if (m != null) { - return new IBinding[] {m}; + return new IBinding[] { m }; } return IBinding.EMPTY_BINDING_ARRAY; } private IBinding[] getPrefixBindings(char[] name) { - List<IBinding> result= new ArrayList<>(); + List<IBinding> result = new ArrayList<>(); IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(name); for (ICPPMethod m : getMethods()) { if (!(m instanceof ICPPConstructor)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java index 13e16f7113b..c3665fde6cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructor.java @@ -51,7 +51,8 @@ public class CPPConstructor extends CPPMethod implements ICPPConstructor { return getConstructorChainExecution(); } - private static ICPPEvaluation getMemberEvaluation(ICPPField member, ICPPASTConstructorChainInitializer chainInitializer, IASTNode point) { + private static ICPPEvaluation getMemberEvaluation(ICPPField member, + ICPPASTConstructorChainInitializer chainInitializer, IASTNode point) { final IASTInitializer initializer = chainInitializer.getInitializer(); if (initializer instanceof ICPPASTInitializerClause) { return ((ICPPASTInitializerClause) initializer).getEvaluation(); @@ -64,7 +65,7 @@ public class CPPConstructor extends CPPMethod implements ICPPConstructor { } else if (constructor instanceof IProblemBinding) { return EvalFixed.INCOMPLETE; } - return new EvalConstructor(member.getType(), (ICPPConstructor) constructor, + return new EvalConstructor(member.getType(), (ICPPConstructor) constructor, EvalConstructor.extractArguments(initializer), point); } return null; @@ -84,8 +85,8 @@ public class CPPConstructor extends CPPMethod implements ICPPConstructor { } else if (member instanceof ICPPConstructor) { final ICPPConstructor ctorMember = (ICPPConstructor) member; final IASTInitializer initializer = ccInitializer.getInitializer(); - if (initializer instanceof ICPPASTConstructorInitializer || - initializer instanceof ICPPASTInitializerList) { + if (initializer instanceof ICPPASTConstructorInitializer + || initializer instanceof ICPPASTInitializerList) { final ICPPClassType baseClassType = (ICPPClassType) ctorMember.getOwner(); EvalConstructor memberEval = new EvalConstructor(baseClassType, ctorMember, EvalConstructor.extractArguments(initializer, ctorMember), fnDef); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java index d454fad0f27..1dc26ba789d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java @@ -26,15 +26,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** * Specialization of a constructor for a class-template or class-template specialization. */ -public class CPPConstructorSpecialization extends CPPMethodSpecialization - implements ICPPConstructorSpecialization { +public class CPPConstructorSpecialization extends CPPMethodSpecialization implements ICPPConstructorSpecialization { - public CPPConstructorSpecialization(ICPPConstructor orig, ICPPClassType owner, - ICPPTemplateParameterMap argMap, ICPPFunctionType type, IType[] exceptionSpecs) { + public CPPConstructorSpecialization(ICPPConstructor orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, + ICPPFunctionType type, IType[] exceptionSpecs) { super(orig, owner, argMap, type, exceptionSpecs); } - static <T extends ICPPConstructorSpecialization & ICPPInternalBinding> ICPPExecution - getConstructorChainExecution(T functionSpec) { + + static <T extends ICPPConstructorSpecialization & ICPPInternalBinding> ICPPExecution getConstructorChainExecution( + T functionSpec) { if (!functionSpec.isConstexpr()) { return null; } @@ -50,7 +50,7 @@ public class CPPConstructorSpecialization extends CPPMethodSpecialization public ICPPExecution getConstructorChainExecution() { return getConstructorChainExecution(this); } - + @Override public ICPPExecution getConstructorChainExecution(IASTNode point) { return getConstructorChainExecution(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java index 91d95b57dbd..f75807505d3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java @@ -28,8 +28,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; public class CPPConstructorTemplateSpecialization extends CPPMethodTemplateSpecialization implements ICPPConstructorSpecialization { - public CPPConstructorTemplateSpecialization(ICPPConstructor original, - ICPPClassSpecialization owner, ICPPTemplateParameterMap tpmap, ICPPFunctionType type, IType[] exceptionSpecs) { + public CPPConstructorTemplateSpecialization(ICPPConstructor original, ICPPClassSpecialization owner, + ICPPTemplateParameterMap tpmap, ICPPFunctionType type, IType[] exceptionSpecs) { super(original, owner, tpmap, type, exceptionSpecs); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java index fa366287f98..b95497e699e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java @@ -43,7 +43,8 @@ import org.eclipse.core.runtime.CoreException; /** * Represents a instantiation that cannot be performed because of dependent arguments or an unknown template. */ -public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPDeferredClassInstance, ISerializableType { +public class CPPDeferredClassInstance extends CPPUnknownBinding + implements ICPPDeferredClassInstance, ISerializableType { private final ICPPTemplateArgument[] fArguments; private final ICPPClassTemplate fClassTemplate; private final ICPPScope fLookupScope; @@ -53,9 +54,9 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD // With template template parameters the owner must not be calculated, it'd lead to an infinite loop. // Rather than that we override getOwner(). super(template.getNameCharArray()); - fArguments= arguments; - fClassTemplate= template; - fLookupScope= lookupScope; + fArguments = arguments; + fClassTemplate = template; + fLookupScope = lookupScope; } public CPPDeferredClassInstance(ICPPClassTemplate template, ICPPTemplateArgument[] arguments) { @@ -79,8 +80,8 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD @Override public CPPDeferredClassInstance clone() { - return (CPPDeferredClassInstance) super.clone(); - } + return (CPPDeferredClassInstance) super.clone(); + } @Override public boolean isSameType(IType type) { @@ -102,66 +103,66 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD return false; } - @Override + @Override public int getKey() { - return getClassTemplate().getKey(); - } + return getClassTemplate().getKey(); + } - @Override + @Override public ICPPBase[] getBases() { - return ICPPBase.EMPTY_BASE_ARRAY; - } + return ICPPBase.EMPTY_BASE_ARRAY; + } - @Override + @Override public IField[] getFields() { - return IField.EMPTY_FIELD_ARRAY; - } + return IField.EMPTY_FIELD_ARRAY; + } - @Override + @Override public IField findField(String name) { - return null; - } + return null; + } - @Override + @Override public ICPPField[] getDeclaredFields() { - return ICPPField.EMPTY_CPPFIELD_ARRAY; - } + return ICPPField.EMPTY_CPPFIELD_ARRAY; + } - @Override + @Override public ICPPMethod[] getMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } - @Override + @Override public ICPPMethod[] getAllDeclaredMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } - @Override + @Override public ICPPMethod[] getDeclaredMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } - @Override + @Override public ICPPConstructor[] getConstructors() { - return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; - } + return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + } - @Override + @Override public IBinding[] getFriends() { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } - @Override + @Override public final IScope getCompositeScope() { - return asScope(); - } + return asScope(); + } @Override public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ICPPUsingDeclaration.EMPTY_USING_DECL_ARRAY; @@ -223,7 +224,7 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE; + short firstBytes = ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE; buffer.putShort(firstBytes); buffer.marshalBinding(fClassTemplate); buffer.putInt(fArguments.length); @@ -233,12 +234,12 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD } public static ICPPDeferredClassInstance unmarshal(IIndexFragment fragment, short firstBytes, - ITypeMarshalBuffer buffer) throws CoreException { - IBinding template= buffer.unmarshalBinding(); - int argcount= buffer.getInt(); + ITypeMarshalBuffer buffer) throws CoreException { + IBinding template = buffer.unmarshalBinding(); + int argcount = buffer.getInt(); ICPPTemplateArgument[] args = new ICPPTemplateArgument[argcount]; for (int i = 0; i < argcount; i++) { - args[i]= buffer.unmarshalTemplateArgument(); + args[i] = buffer.unmarshalTemplateArgument(); } return new PDOMCPPDeferredClassInstance(fragment, (ICPPClassTemplate) template, args); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java index 4ddf4e164dc..3a277878e41 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java @@ -33,10 +33,10 @@ import org.eclipse.core.runtime.CoreException; * Represents a reference to a (member) function (instance), which cannot be resolved because * an argument depends on a template parameter. A compiler would resolve it during instantiation. */ -public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPDeferredFunction, - ICPPComputableFunction, ISerializableType { - private static final ICPPFunctionType FUNCTION_TYPE= - new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY); +public class CPPDeferredFunction extends CPPUnknownBinding + implements ICPPDeferredFunction, ICPPComputableFunction, ISerializableType { + private static final ICPPFunctionType FUNCTION_TYPE = new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, + IType.EMPTY_TYPE_ARRAY); /** * Creates a CPPDeferredFunction given a set of overloaded functions @@ -70,7 +70,7 @@ public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPDeferr public CPPDeferredFunction(IBinding owner, char[] name, ICPPFunction[] candidates) { super(name); - fOwner= owner; + fOwner = owner; fCandidates = candidates; } @@ -123,7 +123,7 @@ public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPDeferr public ICPPFunctionType getDeclaredType() { return FUNCTION_TYPE; } - + @Override public ICPPFunctionType getType() { return FUNCTION_TYPE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredVariableInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredVariableInstance.java index d57ef1a8a19..cf9b60de848 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredVariableInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredVariableInstance.java @@ -28,17 +28,17 @@ import org.eclipse.core.runtime.CoreException; /** * AST implementation of ICPPDeferredVariableInstance. */ -public class CPPDeferredVariableInstance extends CPPUnknownBinding implements ICPPDeferredVariableInstance, - ISerializableType { +public class CPPDeferredVariableInstance extends CPPUnknownBinding + implements ICPPDeferredVariableInstance, ISerializableType { private final ICPPVariableTemplate fTemplate; private final ICPPTemplateArgument[] fArguments; - + public CPPDeferredVariableInstance(ICPPVariableTemplate template, ICPPTemplateArgument[] arguments) { super(template.getNameCharArray()); fTemplate = template; fArguments = arguments; } - + @Override public IBinding getOwner() { return fTemplate.getOwner(); @@ -124,7 +124,7 @@ public class CPPDeferredVariableInstance extends CPPUnknownBinding implements IC public boolean isExplicitSpecialization() { return false; } - + @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { short firstBytes = ITypeMarshalBuffer.DEFERRED_VARIABLE_INSTANCE; @@ -135,14 +135,14 @@ public class CPPDeferredVariableInstance extends CPPUnknownBinding implements IC buffer.marshalTemplateArgument(arg); } } - + public static ICPPDeferredVariableInstance unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IBinding template= buffer.unmarshalBinding(); - int argcount= buffer.getInt(); + IBinding template = buffer.unmarshalBinding(); + int argcount = buffer.getInt(); ICPPTemplateArgument[] args = new ICPPTemplateArgument[argcount]; for (int i = 0; i < argcount; i++) { - args[i]= buffer.unmarshalTemplateArgument(); + args[i] = buffer.unmarshalTemplateArgument(); } return new PDOMCPPDeferredVariableInstance(fragment, (ICPPVariableTemplate) template, args); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumScope.java index 2a4f98b081b..424a7adb01d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumScope.java @@ -39,7 +39,7 @@ public class CPPEnumScope extends CPPScope implements ICPPEnumScope { public IName getScopeName() { ICPPASTEnumerationSpecifier node = (ICPPASTEnumerationSpecifier) getPhysicalNode(); return node.getName(); - } + } @Override public ICPPEnumeration getEnumerationType() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index 7b88af45230..82db1bb7345 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -60,26 +60,32 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I public CPPEnumerationProblem(IASTNode node, int id, char[] arg) { super(node, id, arg); } + @Override public IEnumerator[] getEnumerators() { return EMPTY_ENUMERATORS; } + @Override public long getMinValue() { return 0; } + @Override public long getMaxValue() { return 0; } + @Override public boolean isScoped() { return false; } + @Override public IType getFixedType() { return null; } + @Override public ICPPScope asScope() { return this; @@ -88,39 +94,39 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I private final boolean fIsScoped; private final IType fFixedType; - private IASTName fDefinition= NOT_INITIALIZED; - private IASTName[] fDeclarations= IASTName.EMPTY_NAME_ARRAY; + private IASTName fDefinition = NOT_INITIALIZED; + private IASTName[] fDeclarations = IASTName.EMPTY_NAME_ARRAY; private Long fMaxValue; private Long fMinValue; private ICPPEnumeration fIndexBinding; private boolean fSearchedIndex; - public CPPEnumeration(ICPPASTEnumerationSpecifier spec, IType fixedType) { - final IASTName name = spec.getName(); - fIsScoped= spec.isScoped(); - fFixedType= fixedType; - if (spec.isOpaque()) { - addDeclaration(name); - } else { - addDefinition(name); - } + public CPPEnumeration(ICPPASTEnumerationSpecifier spec, IType fixedType) { + final IASTName name = spec.getName(); + fIsScoped = spec.isScoped(); + fFixedType = fixedType; + if (spec.isOpaque()) { + addDeclaration(name); + } else { + addDefinition(name); + } name.setBinding(this); - } + } - @Override + @Override public IASTNode[] getDeclarations() { - fDeclarations= ArrayUtil.trim(fDeclarations); - return fDeclarations; - } + fDeclarations = ArrayUtil.trim(fDeclarations); + return fDeclarations; + } - private class FindDefinitionAction extends ASTVisitor { + private class FindDefinitionAction extends ASTVisitor { private char[] nameArray = CPPEnumeration.this.getNameCharArray(); { - shouldVisitNames = true; - shouldVisitDeclarations = true; + shouldVisitNames = true; + shouldVisitDeclarations = true; shouldVisitDeclSpecifiers = true; - shouldVisitDeclarators = true; + shouldVisitDeclarators = true; } @Override @@ -129,9 +135,8 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I return PROCESS_SKIP; char[] c = name.getLookupKey(); final IASTNode parent = name.getParent(); - if (parent instanceof ICPPASTEnumerationSpecifier && - !((ICPPASTEnumerationSpecifier) parent).isOpaque() && - CharArrayUtils.equals(c, nameArray)) { + if (parent instanceof ICPPASTEnumerationSpecifier && !((ICPPASTEnumerationSpecifier) parent).isOpaque() + && CharArrayUtils.equals(c, nameArray)) { IBinding binding = name.resolveBinding(); if (binding == CPPEnumeration.this && getDefinition() == name) { return PROCESS_ABORT; @@ -146,94 +151,96 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I return PROCESS_CONTINUE; return PROCESS_SKIP; } + @Override public int visit(IASTDeclSpecifier declSpec) { return (declSpec instanceof ICPPASTEnumerationSpecifier) ? PROCESS_CONTINUE : PROCESS_SKIP; } + @Override public int visit(IASTDeclarator declarator) { return PROCESS_SKIP; } } - @Override + @Override public IASTName getDefinition() { - if (fDefinition == NOT_INITIALIZED) - return null; - return fDefinition; - } + if (fDefinition == NOT_INITIALIZED) + return null; + return fDefinition; + } - @Override + @Override public String getName() { - return new String(getNameCharArray()); - } + return new String(getNameCharArray()); + } - @Override + @Override public char[] getNameCharArray() { - return getADeclaration().getSimpleID(); - } + return getADeclaration().getSimpleID(); + } private IASTName getADeclaration() { - if (fDefinition != null && fDefinition != NOT_INITIALIZED) - return fDefinition; - return fDeclarations[0]; + if (fDefinition != null && fDefinition != NOT_INITIALIZED) + return fDefinition; + return fDeclarations[0]; } @Override public IScope getScope() { - return CPPVisitor.getContainingScope(getADeclaration()); - } + return CPPVisitor.getContainingScope(getADeclaration()); + } - @Override + @Override public Object clone() { - throw new IllegalArgumentException("Enums must not be cloned"); //$NON-NLS-1$ - } + throw new IllegalArgumentException("Enums must not be cloned"); //$NON-NLS-1$ + } - @Override + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() throws DOMException { - IScope scope = getScope(); - while (scope != null) { - if (scope instanceof ICPPBlockScope) - return false; - scope = scope.getParent(); - } - return true; - } + IScope scope = getScope(); + while (scope != null) { + if (scope instanceof ICPPBlockScope) + return false; + scope = scope.getParent(); + } + return true; + } @Override public void addDefinition(IASTNode node) { assert fDefinition == null || fDefinition == NOT_INITIALIZED; - fDefinition= (IASTName) node; + fDefinition = (IASTName) node; } @Override public void addDeclaration(IASTNode node) { assert node instanceof IASTName; if (fDeclarations == null) { - fDeclarations= new IASTName[] {(IASTName) node}; + fDeclarations = new IASTName[] { (IASTName) node }; } else { - fDeclarations= ArrayUtil.append(fDeclarations, (IASTName) node); + fDeclarations = ArrayUtil.append(fDeclarations, (IASTName) node); } } - @Override + @Override public boolean isSameType(IType type) { - if (type == this) - return true; - if (type instanceof ITypedef || type instanceof IIndexBinding) - return type.isSameType(this); - return false; - } + if (type == this) + return true; + if (type instanceof ITypedef || type instanceof IIndexBinding) + return type.isSameType(this); + return false; + } @Override public ILinkage getLinkage() { @@ -256,7 +263,7 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I return fMinValue.longValue(); long minValue = SemanticUtil.computeMinValue(this); - fMinValue= minValue; + fMinValue = minValue; return minValue; } @@ -266,7 +273,7 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I return fMaxValue.longValue(); long maxValue = SemanticUtil.computeMaxValue(this); - fMaxValue= maxValue; + fMaxValue = maxValue; return maxValue; } @@ -280,32 +287,32 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I return fFixedType; } - @Override + @Override public IEnumerator[] getEnumerators() { - findDefinition(); - final IASTName definition = getDefinition(); + findDefinition(); + final IASTName definition = getDefinition(); if (definition == null) { - ICPPEnumeration typeInIndex= getIndexBinding(); + ICPPEnumeration typeInIndex = getIndexBinding(); if (typeInIndex != null) { return typeInIndex.getEnumerators(); } - return EMPTY_ENUMERATORS; - } + return EMPTY_ENUMERATORS; + } IASTEnumerator[] enums = ((IASTEnumerationSpecifier) definition.getParent()).getEnumerators(); - IEnumerator[] bindings = new IEnumerator[enums.length]; - for (int i = 0; i < enums.length; i++) { - bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); - } - return bindings; - } + IEnumerator[] bindings = new IEnumerator[enums.length]; + for (int i = 0; i < enums.length; i++) { + bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); + } + return bindings; + } private ICPPEnumeration getIndexBinding() { if (!fSearchedIndex) { final IASTTranslationUnit translationUnit = getADeclaration().getTranslationUnit(); - IIndex index= translationUnit.getIndex(); + IIndex index = translationUnit.getIndex(); if (index != null) { - fIndexBinding= (ICPPEnumeration) index.adaptBinding(this); + fIndexBinding = (ICPPEnumeration) index.adaptBinding(this); } } return fIndexBinding; @@ -316,20 +323,20 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I findDefinition(); IASTName def = getDefinition(); if (def == null) { - ICPPEnumeration indexBinding= getIndexBinding(); + ICPPEnumeration indexBinding = getIndexBinding(); if (indexBinding != null) { return indexBinding.asScope(); } - def= getADeclaration(); + def = getADeclaration(); } return ((ICPPASTEnumerationSpecifier) def.getParent()).getScope(); } private void findDefinition() { - if (fDefinition == NOT_INITIALIZED) { - FindDefinitionAction action = new FindDefinitionAction(); - IASTNode node = CPPVisitor.getContainingBlockItem(getADeclaration()).getParent(); - node.accept(action); - } + if (fDefinition == NOT_INITIALIZED) { + FindDefinitionAction action = new FindDefinitionAction(); + IASTNode node = CPPVisitor.getContainingBlockItem(getADeclaration()).getParent(); + node.accept(action); + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java index 858ee2ab373..4bb3faa93ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java @@ -40,16 +40,16 @@ public class CPPEnumerationSpecialization extends CPPSpecialization implements I private final IType fFixedType; private boolean fInitializationComplete; - public static IBinding createInstance(ICPPEnumeration enumeration, - ICPPClassSpecialization owner, ICPPTemplateParameterMap tpMap) { + public static IBinding createInstance(ICPPEnumeration enumeration, ICPPClassSpecialization owner, + ICPPTemplateParameterMap tpMap) { IType fixedType = enumeration.getFixedType(); if (fixedType != null) { ICPPClassSpecialization within = CPPTemplates.getSpecializationContext(owner); InstantiationContext context = new InstantiationContext(tpMap, within); fixedType = CPPTemplates.instantiateType(fixedType, context); } - CPPEnumerationSpecialization specializedEnumeration = - new CPPEnumerationSpecialization(enumeration, owner, tpMap, fixedType); + CPPEnumerationSpecialization specializedEnumeration = new CPPEnumerationSpecialization(enumeration, owner, + tpMap, fixedType); specializedEnumeration.initialize(); return specializedEnumeration; } @@ -68,23 +68,22 @@ public class CPPEnumerationSpecialization extends CPPSpecialization implements I for (int i = 0; i < enumerators.length; ++i) { IEnumerator enumerator = enumerators[i]; InstantiationContext context = new InstantiationContext(tpMap, this); - IValue specializedValue = - CPPTemplates.instantiateValue(enumerator.getValue(), context, IntegralValue.MAX_RECURSION_DEPTH); + IValue specializedValue = CPPTemplates.instantiateValue(enumerator.getValue(), context, + IntegralValue.MAX_RECURSION_DEPTH); IType internalType = null; if (fFixedType == null && enumerator instanceof ICPPInternalEnumerator) { internalType = ((ICPPInternalEnumerator) enumerator).getInternalType(); if (internalType != null) { internalType = CPPTemplates.instantiateType(internalType, context); } else if (previousInternalType instanceof IBasicType) { - internalType = ASTEnumerator.getTypeOfIncrementedValue( - (IBasicType) previousInternalType, specializedValue); + internalType = ASTEnumerator.getTypeOfIncrementedValue((IBasicType) previousInternalType, + specializedValue); } if (internalType != null) { previousInternalType = internalType; } } - fEnumerators[i] = new CPPEnumeratorSpecialization(enumerator, this, tpMap, specializedValue, - internalType); + fEnumerators[i] = new CPPEnumeratorSpecialization(enumerator, this, tpMap, specializedValue, internalType); } fInitializationComplete = true; } @@ -123,7 +122,7 @@ public class CPPEnumerationSpecialization extends CPPSpecialization implements I return false; ICPPEnumerationSpecialization otherEnumSpec = (ICPPEnumerationSpecialization) type; return getSpecializedBinding().isSameType(otherEnumSpec.getSpecializedBinding()) - && ((IType) getOwner()).isSameType((IType) otherEnumSpec.getOwner()); + && ((IType) getOwner()).isSameType((IType) otherEnumSpec.getOwner()); } @Override @@ -144,7 +143,7 @@ public class CPPEnumerationSpecialization extends CPPSpecialization implements I @Override public Object clone() { - throw new IllegalArgumentException("Enums must not be cloned"); //$NON-NLS-1$ + throw new IllegalArgumentException("Enums must not be cloned"); //$NON-NLS-1$ } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java index 57872c009da..f0ab932aafd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java @@ -37,54 +37,53 @@ import org.eclipse.core.runtime.PlatformObject; /** * Binding for a C++ enumerator. */ -public class CPPEnumerator extends PlatformObject - implements ICPPInternalEnumerator, ICPPInternalBinding { - private IASTName enumName; - private IType internalType; - - /** - * @param enumerator - */ - public CPPEnumerator(IASTName enumerator) { - this.enumName = enumerator; - enumerator.setBinding(this); - } - - @Override +public class CPPEnumerator extends PlatformObject implements ICPPInternalEnumerator, ICPPInternalBinding { + private IASTName enumName; + private IType internalType; + + /** + * @param enumerator + */ + public CPPEnumerator(IASTName enumerator) { + this.enumName = enumerator; + enumerator.setBinding(this); + } + + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - @Override + @Override public IASTNode getDefinition() { - return enumName; - } + return enumName; + } - @Override + @Override public String getName() { - return new String(getNameCharArray()); - } + return new String(getNameCharArray()); + } - @Override + @Override public char[] getNameCharArray() { - return enumName.getSimpleID(); - } + return enumName.getSimpleID(); + } - @Override + @Override public IScope getScope() { - return CPPVisitor.getContainingScope(enumName); - } + return CPPVisitor.getContainingScope(enumName); + } - public IASTNode getPhysicalNode() { - return enumName; - } + public IASTNode getPhysicalNode() { + return enumName; + } @Override public IType getType() { - IASTEnumerator etor = (IASTEnumerator) enumName.getParent(); - IASTInternalEnumerationSpecifier enumSpec = (IASTInternalEnumerationSpecifier) etor.getParent(); + IASTEnumerator etor = (IASTEnumerator) enumName.getParent(); + IASTInternalEnumerationSpecifier enumSpec = (IASTInternalEnumerationSpecifier) etor.getParent(); if (enumSpec.isValueComputationInProgress()) { - // During value computation enumerators can be referenced only by initializer + // During value computation enumerators can be referenced only by initializer // expressions of other enumerators of the same enumeration. Return the internal type // of the enumerator ([dcl.enum] 7.2-5). if (internalType != null) @@ -99,7 +98,7 @@ public class CPPEnumerator extends PlatformObject @Override public IType getInternalType() { if (internalType == null) { - getValue(); // Trigger value and internal type computation. + getValue(); // Trigger value and internal type computation. } return internalType; } @@ -114,26 +113,26 @@ public class CPPEnumerator extends PlatformObject internalType = type; } - @Override + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() throws DOMException { - IScope scope = getScope(); - while (scope != null) { - if (scope instanceof ICPPBlockScope) - return false; - scope = scope.getParent(); - } - return true; - } + IScope scope = getScope(); + while (scope != null) { + if (scope instanceof ICPPBlockScope) + return false; + scope = scope.getParent(); + } + return true; + } @Override public void addDefinition(IASTNode node) { @@ -155,7 +154,7 @@ public class CPPEnumerator extends PlatformObject @Override public IValue getValue() { - final IASTNode parent= enumName.getParent(); + final IASTNode parent = enumName.getParent(); if (parent instanceof ASTEnumerator) return ((ASTEnumerator) parent).getIntegralValue(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeratorSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeratorSpecialization.java index af68d27a75f..954fc197f1c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeratorSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeratorSpecialization.java @@ -43,7 +43,7 @@ public class CPPEnumeratorSpecialization extends CPPSpecialization implements IC public IType getType() { ICPPEnumerationSpecialization owner = getOwner(); if (((CPPEnumerationSpecialization) owner).isInitializing()) { - // During enumeration instantiation enumerators can be referenced only by initializer + // During enumeration instantiation enumerators can be referenced only by initializer // expressions of other enumerators of the same enumeration. Return the internal type // of the enumerator ([dcl.enum] 7.2-5). return fInternalType; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java index d4849deac1a..8853a85b815 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java @@ -30,23 +30,23 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; * Binding for a field. */ public class CPPField extends CPPVariable implements ICPPField { - public static class CPPFieldProblem extends ProblemBinding implements ICPPField { - private ICPPClassType fOwner; + public static class CPPFieldProblem extends ProblemBinding implements ICPPField { + private ICPPClassType fOwner; public CPPFieldProblem(ICPPClassType owner, IASTNode node, int id, char[] arg) { - super(node, id, arg); - fOwner= owner; - } + super(node, id, arg); + fOwner = owner; + } - @Override + @Override public int getVisibility() { - return v_private; - } + return v_private; + } - @Override + @Override public ICPPClassType getClassOwner() { - return fOwner; - } + return fOwner; + } @Override public ICompositeType getCompositeTypeOwner() { @@ -57,7 +57,7 @@ public class CPPField extends CPPVariable implements ICPPField { public int getFieldPosition() { return -1; } - } + } public CPPField(IASTName name) { super(name); @@ -74,11 +74,11 @@ public class CPPField extends CPPVariable implements ICPPField { return scope.getClassType(); } - @Override + @Override public boolean isStatic() { - // Definition of a static field doesn't necessarily say static. + // Definition of a static field doesn't necessarily say static. if (getDeclarations() == null) { - IASTNode def= getDefinition(); + IASTNode def = getDefinition(); if (def instanceof ICPPASTQualifiedName) { return true; } @@ -86,16 +86,16 @@ public class CPPField extends CPPVariable implements ICPPField { return super.isStatic(); } - @Override + @Override public boolean isMutable() { - return hasStorageClass(IASTDeclSpecifier.sc_mutable); - } + return hasStorageClass(IASTDeclSpecifier.sc_mutable); + } - @Override + @Override public boolean isExtern() { - // 7.1.1-5 The extern specifier can not be used in the declaration of class members. - return false; - } + // 7.1.1-5 The extern specifier can not be used in the declaration of class members. + return false; + } @Override public ICompositeType getCompositeTypeOwner() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java index 0f42d08ddb1..354a38cf88e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java @@ -27,8 +27,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; * Binding for a specialization of a field. */ public class CPPFieldSpecialization extends CPPVariableSpecialization implements ICPPField { - public CPPFieldSpecialization(IBinding orig, ICPPClassType owner, ICPPTemplateParameterMap tpmap, - IType type, IValue value) { + public CPPFieldSpecialization(IBinding orig, ICPPClassType owner, ICPPTemplateParameterMap tpmap, IType type, + IValue value) { super(orig, owner, tpmap, type, value); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplate.java index 9c38428fa96..dd3a54de6aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplate.java @@ -42,10 +42,10 @@ public class CPPFieldTemplate extends CPPVariableTemplate implements ICPPFieldTe @Override public ICPPClassType getClassOwner() { - IScope scope= getScope(); + IScope scope = getScope(); if (scope instanceof ICPPTemplateScope) { try { - scope= scope.getParent(); + scope = scope.getParent(); } catch (DOMException e) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplateSpecialization.java index 2c8cfa89862..df87423ef14 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldTemplateSpecialization.java @@ -66,14 +66,14 @@ public class CPPFieldTemplateSpecialization extends CPPFieldSpecialization public synchronized final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); instances.put(key, instance); } @Override public synchronized final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); return (ICPPTemplateInstance) instances.get(key); } return null; @@ -82,9 +82,9 @@ public class CPPFieldTemplateSpecialization extends CPPFieldSpecialization @Override public ICPPTemplateInstance[] getAllInstances() { if (instances != null) { - ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i= 0; i < instances.size(); i++) { - result[i]= (ICPPTemplateInstance) instances.getAt(i); + ICPPTemplateInstance[] result = new ICPPTemplateInstance[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + result[i] = (ICPPTemplateInstance) instances.getAt(i); } return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index d3546035213..b4fe2f7b25a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -75,12 +75,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt protected ICPPFunctionType declaredType; protected ICPPFunctionType type; - private static final int FULLY_RESOLVED = 1; + private static final int FULLY_RESOLVED = 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private int bits; public CPPFunction(IASTDeclarator declarator) { - if (declarator != null) { + if (declarator != null) { IASTNode parent = ASTQueries.findOutermostDeclarator(declarator).getParent(); if (parent instanceof IASTFunctionDefinition) { if (declarator instanceof ICPPASTFunctionDeclarator) { @@ -90,51 +90,51 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt declarations = new IASTDeclarator[] { declarator }; } - IASTName name= getASTName(); - name.setBinding(this); - } + IASTName name = getASTName(); + name.setBinding(this); + } } private void resolveAllDeclarations() { - if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { - bits |= RESOLUTION_IN_PROGRESS; - IASTTranslationUnit tu = null; - if (definition != null) { - tu = definition.getTranslationUnit(); - } else if (declarations != null) { - tu = declarations[0].getTranslationUnit(); - } else { - // Implicit binding - IScope scope = getScope(); - IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope); + if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { + bits |= RESOLUTION_IN_PROGRESS; + IASTTranslationUnit tu = null; + if (definition != null) { + tu = definition.getTranslationUnit(); + } else if (declarations != null) { + tu = declarations[0].getTranslationUnit(); + } else { + // Implicit binding + IScope scope = getScope(); + IASTNode node = ASTInternal.getPhysicalNodeOfScope(scope); if (node != null) { tu = node.getTranslationUnit(); } - } - if (tu != null) { - CPPVisitor.getDeclarations(tu, this); - } - declarations = ArrayUtil.trim(IASTDeclarator.class, declarations); - bits |= FULLY_RESOLVED; - bits &= ~RESOLUTION_IN_PROGRESS; - } + } + if (tu != null) { + CPPVisitor.getDeclarations(tu, this); + } + declarations = ArrayUtil.trim(IASTDeclarator.class, declarations); + bits |= FULLY_RESOLVED; + bits &= ~RESOLUTION_IN_PROGRESS; + } } - @Override + @Override public IASTDeclarator[] getDeclarations() { - return declarations; - } + return declarations; + } - @Override + @Override public ICPPASTFunctionDeclarator getDefinition() { - return definition; - } + return definition; + } @Override public final void addDefinition(IASTNode node) { IASTDeclarator dtor = extractRelevantDtor(node); if (dtor instanceof ICPPASTFunctionDeclarator) { - ICPPASTFunctionDeclarator fdtor= (ICPPASTFunctionDeclarator) dtor; + ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) dtor; updateFunctionParameterBindings(fdtor); definition = fdtor; } @@ -174,33 +174,33 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt @Override public ICPPParameter[] getParameters() { - ICPPASTFunctionDeclarator declarator = getDefinition(); - IASTDeclarator[] dtors = getDeclarations(); - if (dtors != null) { - // In case of multiple function declarations we select the one with the most - // default parameter values. + ICPPASTFunctionDeclarator declarator = getDefinition(); + IASTDeclarator[] dtors = getDeclarations(); + if (dtors != null) { + // In case of multiple function declarations we select the one with the most + // default parameter values. int defaultValuePosition = -1; - for (IASTDeclarator dtor : dtors) { - if (dtor instanceof ICPPASTFunctionDeclarator) { - if (declarator == null) { - declarator = (ICPPASTFunctionDeclarator) dtor; - } else { - ICPPASTFunctionDeclarator contender = (ICPPASTFunctionDeclarator) dtor; - if (defaultValuePosition < 0) - defaultValuePosition = findFirstDefaultValue(declarator.getParameters()); - int pos = findFirstDefaultValue(contender.getParameters()); - if (pos < defaultValuePosition) { - declarator = contender; - defaultValuePosition = pos; - } - } - } - } - } - - if (declarator == null) { + for (IASTDeclarator dtor : dtors) { + if (dtor instanceof ICPPASTFunctionDeclarator) { + if (declarator == null) { + declarator = (ICPPASTFunctionDeclarator) dtor; + } else { + ICPPASTFunctionDeclarator contender = (ICPPASTFunctionDeclarator) dtor; + if (defaultValuePosition < 0) + defaultValuePosition = findFirstDefaultValue(declarator.getParameters()); + int pos = findFirstDefaultValue(contender.getParameters()); + if (pos < defaultValuePosition) { + declarator = contender; + defaultValuePosition = pos; + } + } + } + } + } + + if (declarator == null) { return CPPBuiltinParameter.createParameterList(getType()); - } + } IASTParameterDeclaration[] params = declarator.getParameters(); int size = params.length; ICPPParameter[] result = new ICPPParameter[size]; @@ -208,12 +208,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt for (int i = 0; i < size; i++) { IASTParameterDeclaration param = params[i]; final IASTName name = getParamName(param); - final IBinding binding= name.resolveBinding(); + final IBinding binding = name.resolveBinding(); if (binding instanceof ICPPParameter) { - result[i]= (ICPPParameter) binding; + result[i] = (ICPPParameter) binding; } else { - result[i] = new CPPParameter.CPPParameterProblem( - param, IProblemBinding.SEMANTIC_INVALID_TYPE, name.toCharArray()); + result[i] = new CPPParameter.CPPParameterProblem(param, IProblemBinding.SEMANTIC_INVALID_TYPE, + name.toCharArray()); } } @@ -237,24 +237,24 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt @Override public IScope getFunctionScope() { - resolveAllDeclarations(); - if (definition != null) { + resolveAllDeclarations(); + if (definition != null) { return definition.getFunctionScope(); - } + } - for (IASTDeclarator dtor : declarations) { + for (IASTDeclarator dtor : declarations) { if (dtor instanceof ICPPASTFunctionDeclarator) { return ((ICPPASTFunctionDeclarator) dtor).getFunctionScope(); } } - // function declaration via typedef - return null; + // function declaration via typedef + return null; } @Override public String getName() { - return getASTName().toString(); + return getASTName().toString(); } @Override @@ -264,37 +264,37 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt protected IASTName getASTName() { IASTDeclarator dtor = (definition != null) ? definition : declarations[0]; - dtor= ASTQueries.findInnermostDeclarator(dtor); - return dtor.getName().getLastName(); + dtor = ASTQueries.findInnermostDeclarator(dtor); + return dtor.getName().getLastName(); } @Override public IScope getScope() { - IASTName n = getASTName(); - IScope scope = CPPVisitor.getContainingScope(n); - if (scope instanceof ICPPClassScope) { - ICPPASTDeclSpecifier declSpec = getDeclSpecifier(); - if (declSpec != null && declSpec.isFriend()) { - try { - while (scope instanceof ICPPClassScope) { - scope = scope.getParent(); - } - } catch (DOMException e) { - } - } - } + IASTName n = getASTName(); + IScope scope = CPPVisitor.getContainingScope(n); + if (scope instanceof ICPPClassScope) { + ICPPASTDeclSpecifier declSpec = getDeclSpecifier(); + if (declSpec != null && declSpec.isFriend()) { + try { + while (scope instanceof ICPPClassScope) { + scope = scope.getParent(); + } + } catch (DOMException e) { + } + } + } return scope; } private ICPPASTDeclSpecifier getDeclSpecifier() { if (definition != null) { IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent(); - IASTFunctionDefinition def = (IASTFunctionDefinition) node; - return (ICPPASTDeclSpecifier) def.getDeclSpecifier(); + IASTFunctionDefinition def = (IASTFunctionDefinition) node; + return (ICPPASTDeclSpecifier) def.getDeclSpecifier(); } else if (declarations != null && declarations.length != 0) { IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent(); - IASTSimpleDeclaration decl = (IASTSimpleDeclaration) node; - return (ICPPASTDeclSpecifier) decl.getDeclSpecifier(); + IASTSimpleDeclaration decl = (IASTSimpleDeclaration) node; + return (ICPPASTDeclSpecifier) decl.getDeclSpecifier(); } return null; } @@ -315,22 +315,22 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } } } - + @Override public ICPPFunctionType getDeclaredType() { - if (declaredType == null) { - IType t = CPPVisitor.createType((definition != null) ? definition : declarations[0], + if (declaredType == null) { + IType t = CPPVisitor.createType((definition != null) ? definition : declarations[0], CPPVisitor.DO_NOT_RESOLVE_PLACEHOLDERS); declaredType = toFunctionType(t); } - return declaredType; + return declaredType; } - + @Override public ICPPFunctionType getType() { - if (type == null) { - // TODO: As an optimization, check if declaredType contains placeholders, - // and if it doesn't, just return that. + if (type == null) { + // TODO: As an optimization, check if declaredType contains placeholders, + // and if it doesn't, just return that. IType t = CPPVisitor.createType((definition != null) ? definition : declarations[0]); // The declaration may not specify the return type, so look at the definition. if (t == ProblemType.NO_NAME) { @@ -341,176 +341,176 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } type = toFunctionType(t); } - return type; - } + return type; + } - @Override + @Override public IBinding resolveParameter(CPPParameter param) { - int pos= param.getParameterPosition(); - - int tdeclLen= declarations == null ? 0 : declarations.length; - for (int i= -1; i < tdeclLen; i++) { - ICPPASTFunctionDeclarator tdecl; - if (i == -1) { - tdecl= definition; - if (tdecl == null) - continue; - } else { - final IASTDeclarator dtor= declarations[i]; - if (!(dtor instanceof ICPPASTFunctionDeclarator)) { - if (dtor == null) { - break; - } - continue; - } - tdecl= (ICPPASTFunctionDeclarator) dtor; - } - - IASTParameterDeclaration[] params = tdecl.getParameters(); - if (pos < params.length) { + int pos = param.getParameterPosition(); + + int tdeclLen = declarations == null ? 0 : declarations.length; + for (int i = -1; i < tdeclLen; i++) { + ICPPASTFunctionDeclarator tdecl; + if (i == -1) { + tdecl = definition; + if (tdecl == null) + continue; + } else { + final IASTDeclarator dtor = declarations[i]; + if (!(dtor instanceof ICPPASTFunctionDeclarator)) { + if (dtor == null) { + break; + } + continue; + } + tdecl = (ICPPASTFunctionDeclarator) dtor; + } + + IASTParameterDeclaration[] params = tdecl.getParameters(); + if (pos < params.length) { final IASTName oName = getParamName(params[pos]); - return oName.resolvePreBinding(); - } - } - return param; - } + return oName.resolvePreBinding(); + } + } + return param; + } private IASTName getParamName(final IASTParameterDeclaration paramDecl) { return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName(); } - protected final void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { + protected final void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { IASTParameterDeclaration[] updateParams = fdtor.getParameters(); - int k= 0; - int tdeclLen= declarations == null ? 0 : declarations.length; - for (int i= -1; i < tdeclLen && k < updateParams.length; i++) { - ICPPASTFunctionDeclarator tdecl; - if (i == -1) { - tdecl= definition; - if (tdecl == null) - continue; - } else { - final IASTDeclarator dtor= declarations[i]; - if (!(dtor instanceof ICPPASTFunctionDeclarator)) { - if (dtor == null) { - break; - } - continue; - } - tdecl= (ICPPASTFunctionDeclarator) dtor; - } - - IASTParameterDeclaration[] params = tdecl.getParameters(); - int end= Math.min(params.length, updateParams.length); - for (; k < end; k++) { - final IASTName oName = getParamName(params[k]); - IBinding b= oName.resolvePreBinding(); - IASTName n = getParamName(updateParams[k]); - n.setBinding(b); - ASTInternal.addDeclaration(b, n); - } - } - } - - @Override + int k = 0; + int tdeclLen = declarations == null ? 0 : declarations.length; + for (int i = -1; i < tdeclLen && k < updateParams.length; i++) { + ICPPASTFunctionDeclarator tdecl; + if (i == -1) { + tdecl = definition; + if (tdecl == null) + continue; + } else { + final IASTDeclarator dtor = declarations[i]; + if (!(dtor instanceof ICPPASTFunctionDeclarator)) { + if (dtor == null) { + break; + } + continue; + } + tdecl = (ICPPASTFunctionDeclarator) dtor; + } + + IASTParameterDeclaration[] params = tdecl.getParameters(); + int end = Math.min(params.length, updateParams.length); + for (; k < end; k++) { + final IASTName oName = getParamName(params[k]); + IBinding b = oName.resolvePreBinding(); + IASTName n = getParamName(updateParams[k]); + n.setBinding(b); + ASTInternal.addDeclaration(b, n); + } + } + } + + @Override public final boolean isStatic() { - return isStatic(true); - } + return isStatic(true); + } - @Override + @Override public boolean isStatic(boolean resolveAll) { - if (resolveAll && (bits & FULLY_RESOLVED) == 0) { - resolveAllDeclarations(); - } + if (resolveAll && (bits & FULLY_RESOLVED) == 0) { + resolveAllDeclarations(); + } return hasStorageClass(this, IASTDeclSpecifier.sc_static); - } - -// static public boolean isStatic -// //2 state bits, most significant = whether or not we've figure this out yet -// //least significant = whether or not we are static -// int state = (bits & IS_STATIC) >> 2; -// if (state > 1) return (state % 2 != 0); -// -// IASTDeclSpecifier declSpec = null; -// IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition(); -// if (dtor != null) { -// declSpec = ((IASTFunctionDefinition) dtor.getParent()).getDeclSpecifier(); -// if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static) { -// bits |= 3 << 2; -// return true; -// } -// } -// -// IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations(); -// if (dtors != null) { -// for (int i = 0; i < dtors.length; i++) { -// IASTNode parent = dtors[i].getParent(); -// declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); -// if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static) { -// bits |= 3 << 2; -// return true; -// } -// } -// } -// bits |= 2 << 2; -// return false; -// } - - @Override + } + + // static public boolean isStatic + // //2 state bits, most significant = whether or not we've figure this out yet + // //least significant = whether or not we are static + // int state = (bits & IS_STATIC) >> 2; + // if (state > 1) return (state % 2 != 0); + // + // IASTDeclSpecifier declSpec = null; + // IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition(); + // if (dtor != null) { + // declSpec = ((IASTFunctionDefinition) dtor.getParent()).getDeclSpecifier(); + // if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static) { + // bits |= 3 << 2; + // return true; + // } + // } + // + // IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations(); + // if (dtors != null) { + // for (int i = 0; i < dtors.length; i++) { + // IASTNode parent = dtors[i].getParent(); + // declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + // if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static) { + // bits |= 3 << 2; + // return true; + // } + // } + // } + // bits |= 2 << 2; + // return false; + // } + + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() throws DOMException { - IScope scope = getScope(); - while (scope != null) { - if (scope instanceof ICPPBlockScope) - return false; - scope = scope.getParent(); - } - return true; - } + IScope scope = getScope(); + while (scope != null) { + if (scope instanceof ICPPBlockScope) + return false; + scope = scope.getParent(); + } + return true; + } static public boolean hasStorageClass(ICPPInternalFunction function, int storage) { - IASTDeclarator dtor = (IASTDeclarator) function.getDefinition(); - IASTNode[] ds = function.getDeclarations(); - - int i = -1; - do { - if (dtor != null) { - IASTNode parent = dtor.getParent(); - while (!(parent instanceof IASTDeclaration)) - parent = parent.getParent(); - - IASTDeclSpecifier declSpec = null; - if (parent instanceof IASTSimpleDeclaration) { - declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); - } else if (parent instanceof IASTFunctionDefinition) { - declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); - } - if (declSpec != null && declSpec.getStorageClass() == storage) { - return true; - } - } - if (ds != null && ++i < ds.length) { - dtor = (IASTDeclarator) ds[i]; - } else { - break; - } - } while (dtor != null); - return false; + IASTDeclarator dtor = (IASTDeclarator) function.getDefinition(); + IASTNode[] ds = function.getDeclarations(); + + int i = -1; + do { + if (dtor != null) { + IASTNode parent = dtor.getParent(); + while (!(parent instanceof IASTDeclaration)) + parent = parent.getParent(); + + IASTDeclSpecifier declSpec = null; + if (parent instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTFunctionDefinition) { + declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); + } + if (declSpec != null && declSpec.getStorageClass() == storage) { + return true; + } + } + if (ds != null && ++i < ds.length) { + dtor = (IASTDeclarator) ds[i]; + } else { + break; + } + } while (dtor != null); + return false; } public static ICPPASTFunctionDefinition getFunctionDefinition(IASTNode def) { while (def != null && !(def instanceof IASTDeclaration)) { - def= def.getParent(); + def = def.getParent(); } if (def instanceof ICPPASTFunctionDefinition) { return (ICPPASTFunctionDefinition) def; @@ -520,65 +520,65 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt @Override public boolean isMutable() { - return false; - } + return false; + } - @Override + @Override public boolean isInline() { - IASTDeclarator dtor = getDefinition(); - IASTDeclarator[] ds = getDeclarations(); - int i = -1; - do { - if (dtor != null) { - IASTNode parent = dtor.getParent(); - while (!(parent instanceof IASTDeclaration)) { - parent = parent.getParent(); - } - - IASTDeclSpecifier declSpec = null; - if (parent instanceof IASTSimpleDeclaration) { - declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); - } else if (parent instanceof IASTFunctionDefinition) { - declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); - } - - if (declSpec != null && declSpec.isInline()) - return true; - } - if (ds != null && ++i < ds.length) { - dtor = ds[i]; - } else { - break; - } - } while (dtor != null); - return false; - } - - @Override + IASTDeclarator dtor = getDefinition(); + IASTDeclarator[] ds = getDeclarations(); + int i = -1; + do { + if (dtor != null) { + IASTNode parent = dtor.getParent(); + while (!(parent instanceof IASTDeclaration)) { + parent = parent.getParent(); + } + + IASTDeclSpecifier declSpec = null; + if (parent instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTFunctionDefinition) { + declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); + } + + if (declSpec != null && declSpec.isInline()) + return true; + } + if (ds != null && ++i < ds.length) { + dtor = ds[i]; + } else { + break; + } + } while (dtor != null); + return false; + } + + @Override public boolean isExternC() { - if (CPPVisitor.isExternC(getDefinition())) { - return true; - } - IASTNode[] ds= getDeclarations(); - if (ds != null) { - for (IASTNode element : ds) { - if (CPPVisitor.isExternC(element)) { - return true; - } + if (CPPVisitor.isExternC(getDefinition())) { + return true; + } + IASTNode[] ds = getDeclarations(); + if (ds != null) { + for (IASTNode element : ds) { + if (CPPVisitor.isExternC(element)) { + return true; + } } - } - return false; - } + } + return false; + } - @Override + @Override public boolean isExtern() { - return hasStorageClass(this, IASTDeclSpecifier.sc_extern); - } + return hasStorageClass(this, IASTDeclSpecifier.sc_extern); + } - @Override + @Override public boolean isAuto() { - return hasStorageClass(this, IASTDeclSpecifier.sc_auto); - } + return hasStorageClass(this, IASTDeclSpecifier.sc_auto); + } @Override public boolean isConstexpr() { @@ -600,16 +600,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return false; } - @Override + @Override public boolean isRegister() { - return hasStorageClass(this, IASTDeclSpecifier.sc_register); - } + return hasStorageClass(this, IASTDeclSpecifier.sc_register); + } - @Override + @Override public boolean takesVarArgs() { - ICPPASTFunctionDeclarator dtor= getPreferredDtor(); - return dtor != null ? dtor.takesVarArgs() : false; - } + ICPPASTFunctionDeclarator dtor = getPreferredDtor(); + return dtor != null ? dtor.takesVarArgs() : false; + } @Override public ILinkage getLinkage() { @@ -634,7 +634,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt public IType[] getExceptionSpecification() { ICPPASTFunctionDeclarator declarator = getPreferredDtor(); if (declarator != null) { - IASTTypeId[] astTypeIds= declarator.getExceptionSpecification(); + IASTTypeId[] astTypeIds = declarator.getExceptionSpecification(); if (astTypeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION)) return null; @@ -642,7 +642,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return IType.EMPTY_TYPE_ARRAY; IType[] typeIds = new IType[astTypeIds.length]; - for (int i= 0; i < astTypeIds.length; ++i) { + for (int i = 0; i < astTypeIds.length; ++i) { typeIds[i] = CPPVisitor.createType(astTypeIds[i]); } return typeIds; @@ -651,18 +651,18 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } protected ICPPASTFunctionDeclarator getPreferredDtor() { - ICPPASTFunctionDeclarator dtor = getDefinition(); - if (dtor != null) - return dtor; - - IASTDeclarator[] dtors = getDeclarations(); - if (dtors != null) { - for (IASTDeclarator declarator : dtors) { - if (declarator instanceof ICPPASTFunctionDeclarator) - return (ICPPASTFunctionDeclarator) declarator; - } - } - return dtor; + ICPPASTFunctionDeclarator dtor = getDefinition(); + if (dtor != null) + return dtor; + + IASTDeclarator[] dtors = getDeclarations(); + if (dtors != null) { + for (IASTDeclarator declarator : dtors) { + if (declarator instanceof ICPPASTFunctionDeclarator) + return (ICPPASTFunctionDeclarator) declarator; + } + } + return dtor; } @Override @@ -701,7 +701,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } IASTNode parent = dtor.getParent(); if (parent instanceof IASTAttributeOwner) { - return AttributeUtil.hasNoreturnAttribute((IASTAttributeOwner) parent); + return AttributeUtil.hasNoreturnAttribute((IASTAttributeOwner) parent); } return false; } @@ -742,7 +742,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } return null; } - + private void findDefinition() { if (definition != null) return; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java index 2a65ce28bab..e6c2feb213b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java @@ -72,18 +72,18 @@ public class CPPFunctionInstance extends CPPFunctionSpecialization implements IC return getName() + " " + ASTTypeUtil.getArgumentListString(fArguments, true); //$NON-NLS-1$ } - @Override + @Override public boolean equals(Object obj) { - if ((obj instanceof ICPPTemplateInstance) && (obj instanceof ICPPFunction)) { - final ICPPTemplateInstance inst = (ICPPTemplateInstance) obj; - ICPPFunctionType ct1= ((ICPPFunction) getSpecializedBinding()).getType(); - ICPPFunctionType ct2= ((ICPPFunction) inst.getTemplateDefinition()).getType(); + if ((obj instanceof ICPPTemplateInstance) && (obj instanceof ICPPFunction)) { + final ICPPTemplateInstance inst = (ICPPTemplateInstance) obj; + ICPPFunctionType ct1 = ((ICPPFunction) getSpecializedBinding()).getType(); + ICPPFunctionType ct2 = ((ICPPFunction) inst.getTemplateDefinition()).getType(); if (!ct1.isSameType(ct2)) return false; return CPPTemplates.haveSameArguments(this, inst); - } + } - return false; - } + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java index a8849a212a5..9b0623aca38 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java @@ -39,7 +39,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * Scope of a function, containing labels. */ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { - private CharArrayObjectMap<ILabel> labels = CharArrayObjectMap.emptyMap(); + private CharArrayObjectMap<ILabel> labels = CharArrayObjectMap.emptyMap(); /** * @param physicalNode @@ -55,66 +55,66 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { @Override public void addBinding(IBinding binding) { - // 3.3.4 only labels have function scope. - if (!(binding instanceof ILabel)) - return; + // 3.3.4 only labels have function scope. + if (!(binding instanceof ILabel)) + return; - if (labels == CharArrayObjectMap.EMPTY_MAP) - labels = new CharArrayObjectMap<>(2); + if (labels == CharArrayObjectMap.EMPTY_MAP) + labels = new CharArrayObjectMap<>(2); - labels.put(binding.getNameCharArray(), (ILabel) binding); + labels.put(binding.getNameCharArray(), (ILabel) binding); } @Override public IBinding[] find(String name) { - char[] n = name.toCharArray(); - List<IBinding> bindings = new ArrayList<>(); - - for (int i = 0; i < labels.size(); i++) { - char[] key = labels.keyAt(i); - if (CharArrayUtils.equals(key, n)) { - bindings.add(labels.get(key)); - } - } - - IBinding[] additional = super.find(name); - for (IBinding element : additional) { - bindings.add(element); - } - - return bindings.toArray(new IBinding[bindings.size()]); + char[] n = name.toCharArray(); + List<IBinding> bindings = new ArrayList<>(); + + for (int i = 0; i < labels.size(); i++) { + char[] key = labels.keyAt(i); + if (CharArrayUtils.equals(key, n)) { + bindings.add(labels.get(key)); + } + } + + IBinding[] additional = super.find(name); + for (IBinding element : additional) { + bindings.add(element); + } + + return bindings.toArray(new IBinding[bindings.size()]); } @Override public IScope getParent() { - // We can't just resolve the function and get its parent scope, since there are cases where that - // could loop because resolving functions requires resolving their parameter types. - IASTFunctionDeclarator funcDeclarator = (IASTFunctionDeclarator) getPhysicalNode(); - IASTName name = funcDeclarator.getName(); - if (name != null) - return CPPVisitor.getContainingNonTemplateScope(name.getLastName()); - - return super.getParent(); + // We can't just resolve the function and get its parent scope, since there are cases where that + // could loop because resolving functions requires resolving their parameter types. + IASTFunctionDeclarator funcDeclarator = (IASTFunctionDeclarator) getPhysicalNode(); + IASTName name = funcDeclarator.getName(); + if (name != null) + return CPPVisitor.getContainingNonTemplateScope(name.getLastName()); + + return super.getParent(); } - @Override + @Override public IScope getBodyScope() { - IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) getPhysicalNode(); - IASTNode parent = fnDtor.getParent(); - if (parent instanceof IASTFunctionDefinition) { - IASTStatement body = ((IASTFunctionDefinition) parent).getBody(); - if (body instanceof IASTCompoundStatement) - return ((IASTCompoundStatement) body).getScope(); - } - return null; - } - - @Override + IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) getPhysicalNode(); + IASTNode parent = fnDtor.getParent(); + if (parent instanceof IASTFunctionDefinition) { + IASTStatement body = ((IASTFunctionDefinition) parent).getBody(); + if (body instanceof IASTCompoundStatement) + return ((IASTCompoundStatement) body).getScope(); + } + return null; + } + + @Override public IName getScopeName() { - IASTNode node = getPhysicalNode(); - if (node instanceof IASTDeclarator) { - return ((IASTDeclarator) node).getName(); - } - return null; - } + IASTNode node = getPhysicalNode(); + if (node instanceof IASTDeclarator) { + return ((IASTDeclarator) node).getName(); + } + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java index 5a34c61424a..bba88ff46df 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -46,8 +46,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * The specialization of a friend function in the context of a class specialization, * also used as base class for function instances. */ -public class CPPFunctionSpecialization extends CPPSpecialization implements ICPPFunctionSpecialization, - ICPPInternalFunction { +public class CPPFunctionSpecialization extends CPPSpecialization + implements ICPPFunctionSpecialization, ICPPInternalFunction { private final ICPPFunctionType fType; private ICPPParameter[] fParams; private final IType[] fExceptionSpecs; @@ -55,8 +55,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP public CPPFunctionSpecialization(ICPPFunction orig, IBinding owner, ICPPTemplateParameterMap argMap, ICPPFunctionType type, IType[] exceptionSpecs) { super(orig, owner, argMap); - fType= type; - fExceptionSpecs= exceptionSpecs; + fType = type; + fExceptionSpecs = exceptionSpecs; } private ICPPFunction getFunction() { @@ -92,7 +92,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP public ICPPFunctionType getDeclaredType() { return fType; } - + @Override public ICPPFunctionType getType() { return fType; @@ -197,14 +197,14 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP return f.takesVarArgs(); ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition(); - if (dtor != null) { - return dtor.takesVarArgs(); - } - ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); - if (ds != null && ds.length > 0) { - return ds[0].takesVarArgs(); - } - return false; + if (dtor != null) { + return dtor.takesVarArgs(); + } + ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); + if (ds != null && ds.length > 0) { + return ds[0].takesVarArgs(); + } + return false; } @Override @@ -212,69 +212,69 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP ICPPFunction f = (ICPPFunction) getSpecializedBinding(); if (f != null) return f.isNoReturn(); - return false; + return false; } - @Override + @Override public IBinding resolveParameter(CPPParameter param) { - int pos= param.getParameterPosition(); - - final IASTNode[] decls= getDeclarations(); - int tdeclLen= decls == null ? 0 : decls.length; - for (int i= -1; i < tdeclLen; i++) { - ICPPASTFunctionDeclarator tdecl; - if (i == -1) { - tdecl= (ICPPASTFunctionDeclarator) getDefinition(); - if (tdecl == null) - continue; - } else if (decls != null) { - tdecl= (ICPPASTFunctionDeclarator) decls[i]; - if (tdecl == null) - break; - } else { - break; - } - - IASTParameterDeclaration[] params = tdecl.getParameters(); - if (pos < params.length) { - final IASTName oName = getParamName(params[pos]); - return oName.resolvePreBinding(); - } - } - return param; - } - - protected void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { + int pos = param.getParameterPosition(); + + final IASTNode[] decls = getDeclarations(); + int tdeclLen = decls == null ? 0 : decls.length; + for (int i = -1; i < tdeclLen; i++) { + ICPPASTFunctionDeclarator tdecl; + if (i == -1) { + tdecl = (ICPPASTFunctionDeclarator) getDefinition(); + if (tdecl == null) + continue; + } else if (decls != null) { + tdecl = (ICPPASTFunctionDeclarator) decls[i]; + if (tdecl == null) + break; + } else { + break; + } + + IASTParameterDeclaration[] params = tdecl.getParameters(); + if (pos < params.length) { + final IASTName oName = getParamName(params[pos]); + return oName.resolvePreBinding(); + } + } + return param; + } + + protected void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { IASTParameterDeclaration[] updateParams = fdtor.getParameters(); - int k= 0; - final IASTNode[] decls= getDeclarations(); - int tdeclLen= decls == null ? 0 : decls.length; - for (int i= -1; i < tdeclLen && k < updateParams.length; i++) { - ICPPASTFunctionDeclarator tdecl; - if (i == -1) { - tdecl= (ICPPASTFunctionDeclarator) getDefinition(); - if (tdecl == null) - continue; - } else if (decls != null) { - tdecl= (ICPPASTFunctionDeclarator) decls[i]; - if (tdecl == null) - break; - } else { - break; - } - - IASTParameterDeclaration[] params = tdecl.getParameters(); - int end= Math.min(params.length, updateParams.length); - for (; k < end; k++) { - final IASTName oName = getParamName(params[k]); - IBinding b= oName.resolvePreBinding(); - IASTName n = getParamName(updateParams[k]); - n.setBinding(b); - ASTInternal.addDeclaration(b, n); - } - } - } + int k = 0; + final IASTNode[] decls = getDeclarations(); + int tdeclLen = decls == null ? 0 : decls.length; + for (int i = -1; i < tdeclLen && k < updateParams.length; i++) { + ICPPASTFunctionDeclarator tdecl; + if (i == -1) { + tdecl = (ICPPASTFunctionDeclarator) getDefinition(); + if (tdecl == null) + continue; + } else if (decls != null) { + tdecl = (ICPPASTFunctionDeclarator) decls[i]; + if (tdecl == null) + break; + } else { + break; + } + + IASTParameterDeclaration[] params = tdecl.getParameters(); + int end = Math.min(params.length, updateParams.length); + for (; k < end; k++) { + final IASTName oName = getParamName(params[k]); + IBinding b = oName.resolvePreBinding(); + IASTName n = getParamName(updateParams[k]); + n.setBinding(b); + ASTInternal.addDeclaration(b, n); + } + } + } private IASTName getParamName(final IASTParameterDeclaration paramDecl) { return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName(); @@ -285,19 +285,19 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP node = node.getParent(); if (!(node instanceof IASTDeclarator)) return null; - node= ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); + node = ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); if (!(node instanceof ICPPASTFunctionDeclarator)) return null; return (ICPPASTFunctionDeclarator) node; } - @Override + @Override public void addDefinition(IASTNode node) { ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node); if (dtor != null) { updateFunctionParameterBindings(dtor); - super.addDefinition(dtor); + super.addDefinition(dtor); } } @@ -306,7 +306,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node); if (dtor != null) { updateFunctionParameterBindings(dtor); - super.addDeclaration(dtor); + super.addDeclaration(dtor); } } @@ -316,7 +316,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP result.append(getName()); IFunctionType t = getType(); result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$ - ICPPTemplateParameterMap tpmap= getTemplateParameterMap(); + ICPPTemplateParameterMap tpmap = getTemplateParameterMap(); if (tpmap != null) { result.append(" "); //$NON-NLS-1$ result.append(tpmap.toString()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 0e1f84a0b72..9ed186ffce4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -45,8 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * Implementation of function templates. */ -public class CPPFunctionTemplate extends CPPTemplateDefinition - implements ICPPFunctionTemplate, ICPPInternalFunction { +public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFunctionTemplate, ICPPInternalFunction { protected ICPPFunctionType declaredType; protected ICPPFunctionType type; @@ -58,7 +57,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition public void addDefinition(IASTNode node) { if (!(node instanceof IASTName)) return; - IASTDeclarator fdecl= getDeclaratorByName(node); + IASTDeclarator fdecl = getDeclaratorByName(node); if (fdecl instanceof ICPPASTFunctionDeclarator) { updateFunctionParameterBindings((ICPPASTFunctionDeclarator) fdecl); super.addDefinition(node); @@ -69,7 +68,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition public void addDeclaration(IASTNode node) { if (!(node instanceof IASTName)) return; - IASTDeclarator fdecl= getDeclaratorByName(node); + IASTDeclarator fdecl = getDeclaratorByName(node); if (fdecl == null) return; @@ -80,53 +79,53 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition } private ICPPASTFunctionDeclarator getFirstFunctionDtor() { - IASTDeclarator dtor= getDeclaratorByName(getDefinition()); - if (dtor instanceof ICPPASTFunctionDeclarator) - return (ICPPASTFunctionDeclarator) dtor; - - IASTNode[] decls = getDeclarations(); - if (decls != null) { - for (IASTNode decl : decls) { - dtor= getDeclaratorByName(decl); - if (dtor instanceof ICPPASTFunctionDeclarator) - return (ICPPASTFunctionDeclarator) dtor; - } - } - return null; + IASTDeclarator dtor = getDeclaratorByName(getDefinition()); + if (dtor instanceof ICPPASTFunctionDeclarator) + return (ICPPASTFunctionDeclarator) dtor; + + IASTNode[] decls = getDeclarations(); + if (decls != null) { + for (IASTNode decl : decls) { + dtor = getDeclaratorByName(decl); + if (dtor instanceof ICPPASTFunctionDeclarator) + return (ICPPASTFunctionDeclarator) dtor; + } + } + return null; } @Override public ICPPParameter[] getParameters() { - ICPPASTFunctionDeclarator declarator= null; - IASTDeclarator dtor= getDeclaratorByName(getDefinition()); - if (dtor instanceof ICPPASTFunctionDeclarator) - declarator = (ICPPASTFunctionDeclarator) dtor; - - IASTNode[] decls = getDeclarations(); - if (decls != null) { - // In case of multiple function declarations we select the one with the most - // default parameter values. + ICPPASTFunctionDeclarator declarator = null; + IASTDeclarator dtor = getDeclaratorByName(getDefinition()); + if (dtor instanceof ICPPASTFunctionDeclarator) + declarator = (ICPPASTFunctionDeclarator) dtor; + + IASTNode[] decls = getDeclarations(); + if (decls != null) { + // In case of multiple function declarations we select the one with the most + // default parameter values. int defaultValuePosition = -1; - for (IASTNode decl : decls) { - dtor= getDeclaratorByName(decl); - if (dtor instanceof ICPPASTFunctionDeclarator) { - if (declarator == null) { - declarator = (ICPPASTFunctionDeclarator) dtor; - } else { - ICPPASTFunctionDeclarator contender = (ICPPASTFunctionDeclarator) dtor; - if (defaultValuePosition < 0) - defaultValuePosition = CPPFunction.findFirstDefaultValue(declarator.getParameters()); - int pos = CPPFunction.findFirstDefaultValue(contender.getParameters()); - if (pos < defaultValuePosition) { - declarator = contender; - defaultValuePosition = pos; - } - } - } - } - } - - if (declarator != null) { + for (IASTNode decl : decls) { + dtor = getDeclaratorByName(decl); + if (dtor instanceof ICPPASTFunctionDeclarator) { + if (declarator == null) { + declarator = (ICPPASTFunctionDeclarator) dtor; + } else { + ICPPASTFunctionDeclarator contender = (ICPPASTFunctionDeclarator) dtor; + if (defaultValuePosition < 0) + defaultValuePosition = CPPFunction.findFirstDefaultValue(declarator.getParameters()); + int pos = CPPFunction.findFirstDefaultValue(contender.getParameters()); + if (pos < defaultValuePosition) { + declarator = contender; + defaultValuePosition = pos; + } + } + } + } + } + + if (declarator != null) { IASTParameterDeclaration[] params = declarator.getParameters(); int size = params.length; if (size == 0) { @@ -136,12 +135,12 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition for (int i = 0; i < size; i++) { IASTParameterDeclaration param = params[i]; final IASTName pname = ASTQueries.findInnermostDeclarator(param.getDeclarator()).getName(); - final IBinding binding= pname.resolveBinding(); + final IBinding binding = pname.resolveBinding(); if (binding instanceof ICPPParameter) { - result[i]= (ICPPParameter) binding; + result[i] = (ICPPParameter) binding; } else { - result[i] = new CPPParameter.CPPParameterProblem( - param, IProblemBinding.SEMANTIC_INVALID_TYPE, pname.toCharArray()); + result[i] = new CPPParameter.CPPParameterProblem(param, IProblemBinding.SEMANTIC_INVALID_TYPE, + pname.toCharArray()); } } @@ -159,7 +158,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition @Override public boolean hasParameterPack() { - ICPPParameter[] pars= getParameters(); + ICPPParameter[] pars = getParameters(); return pars.length > 0 && pars[pars.length - 1].isParameterPack(); } @@ -175,13 +174,13 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition IASTNode parent = name.getParent(); while (parent.getParent() instanceof IASTDeclarator) parent = parent.getParent(); - + IType t = CPPVisitor.createType((IASTDeclarator) parent, CPPVisitor.DO_NOT_RESOLVE_PLACEHOLDERS); declaredType = CPPFunction.toFunctionType(t); } return declaredType; } - + @Override public ICPPFunctionType getType() { if (type == null) { @@ -189,9 +188,9 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition IASTNode parent = name.getParent(); while (parent.getParent() instanceof IASTDeclarator) parent = parent.getParent(); - + IType t = CPPVisitor.createType((IASTDeclarator) parent); - // TODO(nathanridge): Do we need to search for the definition here, if t is + // TODO(nathanridge): Do we need to search for the definition here, if t is // ProblemType.NO_NAME, as in CPPFunction? type = CPPFunction.toFunctionType(t); } @@ -199,103 +198,103 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition } public boolean hasStorageClass(int storage) { - IASTName name = (IASTName) getDefinition(); - IASTNode[] ns = getDeclarations(); - int i = -1; - do { - if (name != null) { - IASTNode parent = name.getParent(); - while (parent != null && !(parent instanceof IASTDeclaration)) - parent = parent.getParent(); - - IASTDeclSpecifier declSpec = getDeclSpecifier((IASTDeclaration) parent); - if (declSpec != null && declSpec.getStorageClass() == storage) { - return true; - } - } - if (ns != null && ++i < ns.length) { - name = (IASTName) ns[i]; - } else { - break; - } - } while (name != null); - return false; + IASTName name = (IASTName) getDefinition(); + IASTNode[] ns = getDeclarations(); + int i = -1; + do { + if (name != null) { + IASTNode parent = name.getParent(); + while (parent != null && !(parent instanceof IASTDeclaration)) + parent = parent.getParent(); + + IASTDeclSpecifier declSpec = getDeclSpecifier((IASTDeclaration) parent); + if (declSpec != null && declSpec.getStorageClass() == storage) { + return true; + } + } + if (ns != null && ++i < ns.length) { + name = (IASTName) ns[i]; + } else { + break; + } + } while (name != null); + return false; } protected ICPPASTDeclSpecifier getDeclSpecifier(IASTDeclaration decl) { if (decl instanceof IASTSimpleDeclaration) { - return (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); + return (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); } if (decl instanceof IASTFunctionDefinition) { - return (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier(); + return (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier(); } return null; } - @Override + @Override public IBinding resolveParameter(CPPParameter param) { - int pos= param.getParameterPosition(); - - final IASTNode[] decls= getDeclarations(); - int tdeclLen= decls == null ? 0 : decls.length; - for (int i= -1; i < tdeclLen; i++) { - IASTDeclarator tdecl; - if (i < 0) { - tdecl= getDeclaratorByName(getDefinition()); - if (tdecl == null) - continue; - } else if (decls != null) { - tdecl= getDeclaratorByName(decls[i]); - if (tdecl == null) - break; - } else { - break; - } - - if (tdecl instanceof ICPPASTFunctionDeclarator) { - IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) tdecl).getParameters(); - if (pos < params.length) { - final IASTName oName = getParamName(params[pos]); - return oName.resolvePreBinding(); - } - } - } - return param; - } - - protected void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { + int pos = param.getParameterPosition(); + + final IASTNode[] decls = getDeclarations(); + int tdeclLen = decls == null ? 0 : decls.length; + for (int i = -1; i < tdeclLen; i++) { + IASTDeclarator tdecl; + if (i < 0) { + tdecl = getDeclaratorByName(getDefinition()); + if (tdecl == null) + continue; + } else if (decls != null) { + tdecl = getDeclaratorByName(decls[i]); + if (tdecl == null) + break; + } else { + break; + } + + if (tdecl instanceof ICPPASTFunctionDeclarator) { + IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) tdecl).getParameters(); + if (pos < params.length) { + final IASTName oName = getParamName(params[pos]); + return oName.resolvePreBinding(); + } + } + } + return param; + } + + protected void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { IASTParameterDeclaration[] updateParams = fdtor.getParameters(); - int k= 0; - final IASTNode[] decls= getDeclarations(); - int tdeclLen= decls == null ? 0 : decls.length; - for (int i= -1; i < tdeclLen && k < updateParams.length; i++) { - IASTDeclarator tdecl; - if (i < 0) { - tdecl= getDeclaratorByName(getDefinition()); - if (tdecl == null) - continue; - } else if (decls != null) { - tdecl= getDeclaratorByName(decls[i]); - if (tdecl == null) - break; - } else { - break; - } - - if (tdecl instanceof ICPPASTFunctionDeclarator) { - IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) tdecl).getParameters(); - int end= Math.min(params.length, updateParams.length); - for (; k < end; k++) { - final IASTName oName = getParamName(params[k]); - IBinding b= oName.resolvePreBinding(); - IASTName n = getParamName(updateParams[k]); - n.setBinding(b); - ASTInternal.addDeclaration(b, n); - } - } - } - } + int k = 0; + final IASTNode[] decls = getDeclarations(); + int tdeclLen = decls == null ? 0 : decls.length; + for (int i = -1; i < tdeclLen && k < updateParams.length; i++) { + IASTDeclarator tdecl; + if (i < 0) { + tdecl = getDeclaratorByName(getDefinition()); + if (tdecl == null) + continue; + } else if (decls != null) { + tdecl = getDeclaratorByName(decls[i]); + if (tdecl == null) + break; + } else { + break; + } + + if (tdecl instanceof ICPPASTFunctionDeclarator) { + IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) tdecl).getParameters(); + int end = Math.min(params.length, updateParams.length); + for (; k < end; k++) { + final IASTName oName = getParamName(params[k]); + IBinding b = oName.resolvePreBinding(); + IASTName n = getParamName(updateParams[k]); + n.setBinding(b); + ASTInternal.addDeclaration(b, n); + } + } + } + } private IASTName getParamName(final IASTParameterDeclaration paramDecl) { return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName(); @@ -306,61 +305,61 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition return isStatic(true); } - @Override + @Override public boolean isMutable() { - return hasStorageClass(IASTDeclSpecifier.sc_mutable); - } + return hasStorageClass(IASTDeclSpecifier.sc_mutable); + } - @Override + @Override public boolean isInline() { - IASTName name = (IASTName) getDefinition(); - IASTNode[] ns = getDeclarations(); - int i = -1; - do { - if (name != null) { - IASTNode parent = name.getParent(); + IASTName name = (IASTName) getDefinition(); + IASTNode[] ns = getDeclarations(); + int i = -1; + do { + if (name != null) { + IASTNode parent = name.getParent(); while (parent != null && !(parent instanceof IASTDeclaration)) parent = parent.getParent(); - IASTDeclSpecifier declSpec = getDeclSpecifier((IASTDeclaration) parent); - - if (declSpec != null && declSpec.isInline()) - return true; - } - if (ns != null && ++i < ns.length) { - name = (IASTName) ns[i]; - } else { - break; - } - } while (name != null); - return false; - } - - @Override + IASTDeclSpecifier declSpec = getDeclSpecifier((IASTDeclaration) parent); + + if (declSpec != null && declSpec.isInline()) + return true; + } + if (ns != null && ++i < ns.length) { + name = (IASTName) ns[i]; + } else { + break; + } + } while (name != null); + return false; + } + + @Override public boolean isExternC() { - if (CPPVisitor.isExternC(getDefinition())) { - return true; - } - IASTNode[] ds= getDeclarations(); - if (ds != null) { - for (IASTNode element : ds) { - if (CPPVisitor.isExternC(element)) { - return true; - } + if (CPPVisitor.isExternC(getDefinition())) { + return true; + } + IASTNode[] ds = getDeclarations(); + if (ds != null) { + for (IASTNode element : ds) { + if (CPPVisitor.isExternC(element)) { + return true; + } } - } - return false; - } + } + return false; + } - @Override + @Override public boolean isExtern() { - return hasStorageClass(IASTDeclSpecifier.sc_extern); - } + return hasStorageClass(IASTDeclSpecifier.sc_extern); + } - @Override + @Override public boolean isAuto() { - return hasStorageClass(IASTDeclSpecifier.sc_auto); - } + return hasStorageClass(IASTDeclSpecifier.sc_auto); + } @Override public boolean isConstexpr() { @@ -375,44 +374,44 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition return CPPFunction.isDeletedDefinition(getDefinition()); } - @Override + @Override public boolean isRegister() { - return hasStorageClass(IASTDeclSpecifier.sc_register); - } + return hasStorageClass(IASTDeclSpecifier.sc_register); + } - @Override + @Override public boolean takesVarArgs() { - ICPPASTFunctionDeclarator fdecl= getFirstFunctionDtor(); - if (fdecl != null) { - return fdecl.takesVarArgs(); - } - return false; - } - - @Override + ICPPASTFunctionDeclarator fdecl = getFirstFunctionDtor(); + if (fdecl != null) { + return fdecl.takesVarArgs(); + } + return false; + } + + @Override public boolean isNoReturn() { - ICPPASTFunctionDeclarator fdecl= getFirstFunctionDtor(); - if (fdecl != null) { - return AttributeUtil.hasNoreturnAttribute(fdecl); - } - return false; - } + ICPPASTFunctionDeclarator fdecl = getFirstFunctionDtor(); + if (fdecl != null) { + return AttributeUtil.hasNoreturnAttribute(fdecl); + } + return false; + } private IASTDeclarator getDeclaratorByName(IASTNode node) { // Skip qualified names and nested declarators. - while (node != null) { - node= node.getParent(); - if (node instanceof IASTDeclarator) { - return ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); - } - } - return null; + while (node != null) { + node = node.getParent(); + if (node instanceof IASTDeclarator) { + return ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); + } + } + return null; } - @Override + @Override public boolean isStatic(boolean resolveAll) { - return hasStorageClass(IASTDeclSpecifier.sc_static); - } + return hasStorageClass(IASTDeclSpecifier.sc_static); + } @Override public String toString() { @@ -425,7 +424,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition @Override public IType[] getExceptionSpecification() { - ICPPASTFunctionDeclarator declarator = getFirstFunctionDtor(); + ICPPASTFunctionDeclarator declarator = getFirstFunctionDtor(); if (declarator != null) { IASTTypeId[] typeIds = declarator.getExceptionSpecification(); if (typeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java index 3ad71869d07..d4c23c5f520 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java @@ -51,14 +51,14 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization public synchronized final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); instances.put(key, instance); } @Override public synchronized final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); return (ICPPTemplateInstance) instances.get(key); } return null; @@ -67,9 +67,9 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization @Override public synchronized ICPPTemplateInstance[] getAllInstances() { if (instances != null) { - ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i= 0; i < instances.size(); i++) { - result[i]= (ICPPTemplateInstance) instances.getAt(i); + ICPPTemplateInstance[] result = new ICPPTemplateInstance[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + result[i] = (ICPPTemplateInstance) instances.getAt(i); } return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java index 2718c09eb98..9d2dae38b38 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java @@ -30,93 +30,91 @@ import org.eclipse.core.runtime.CoreException; * For safe usage in index bindings, all fields need to be final. */ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { - private final IType[] parameters; - private final IType returnType; - private final boolean isConst; - private final boolean isVolatile; + private final IType[] parameters; + private final IType returnType; + private final boolean isConst; + private final boolean isVolatile; private final boolean hasRefQualifier; private final boolean isRValueReference; - private final boolean takesVarargs; + private final boolean takesVarargs; - public CPPFunctionType(IType returnType, IType[] types) { - this(returnType, types, false, false, false, false, false); - } + public CPPFunctionType(IType returnType, IType[] types) { + this(returnType, types, false, false, false, false, false); + } public CPPFunctionType(IType returnType, IType[] types, boolean isConst, boolean isVolatile, boolean hasRefQualifier, boolean isRValueReference, boolean takesVarargs) { - this.returnType = returnType; - this.parameters = types; - this.isConst = isConst; - this.isVolatile= isVolatile; - this.hasRefQualifier = hasRefQualifier; - this.isRValueReference = isRValueReference; - this.takesVarargs= takesVarargs; - } - - @Override + this.returnType = returnType; + this.parameters = types; + this.isConst = isConst; + this.isVolatile = isVolatile; + this.hasRefQualifier = hasRefQualifier; + this.isRValueReference = isRValueReference; + this.takesVarargs = takesVarargs; + } + + @Override public boolean isSameType(IType o) { - if (o instanceof ITypedef) - return o.isSameType(this); - if (o instanceof ICPPFunctionType) { - ICPPFunctionType ft = (ICPPFunctionType) o; - if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile() - || hasRefQualifier() != ft.hasRefQualifier() - || isRValueReference() != ft.isRValueReference() - || takesVarArgs() != ft.takesVarArgs()) { - return false; - } - - IType[] fps; - fps = ft.getParameterTypes(); + if (o instanceof ITypedef) + return o.isSameType(this); + if (o instanceof ICPPFunctionType) { + ICPPFunctionType ft = (ICPPFunctionType) o; + if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile() + || hasRefQualifier() != ft.hasRefQualifier() || isRValueReference() != ft.isRValueReference() + || takesVarArgs() != ft.takesVarArgs()) { + return false; + } + + IType[] fps; + fps = ft.getParameterTypes(); // Constructors & destructors have null return type. if ((returnType == null) ^ (ft.getReturnType() == null)) - return false; + return false; if (returnType != null && !returnType.isSameType(ft.getReturnType())) - return false; + return false; if (parameters.length == fps.length) { for (int i = 0; i < parameters.length; i++) { - if (parameters[i] == null || !parameters[i].isSameType(fps[i])) - return false; - } + if (parameters[i] == null || !parameters[i].isSameType(fps[i])) + return false; + } } else { - if (!SemanticUtil.isEmptyParameterList(parameters) - || !SemanticUtil.isEmptyParameterList(fps)) { + if (!SemanticUtil.isEmptyParameterList(parameters) || !SemanticUtil.isEmptyParameterList(fps)) { return false; } } - return true; - } - return false; - } + return true; + } + return false; + } - @Override + @Override public IType getReturnType() { - return returnType; - } + return returnType; + } - @Override + @Override public IType[] getParameterTypes() { - return parameters; - } + return parameters; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } - - @Override + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } + + @Override @Deprecated - public IPointerType getThisType() { - return null; - } + public IPointerType getThisType() { + return null; + } @Override public final boolean isConst() { @@ -150,12 +148,17 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.FUNCTION_TYPE; - if (isConst) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (takesVarargs) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isVolatile) firstBytes |= ITypeMarshalBuffer.FLAG3; - if (hasRefQualifier) firstBytes |= ITypeMarshalBuffer.FLAG4; - if (isRValueReference) firstBytes |= ITypeMarshalBuffer.FLAG5; + short firstBytes = ITypeMarshalBuffer.FUNCTION_TYPE; + if (isConst) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (takesVarargs) + firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isVolatile) + firstBytes |= ITypeMarshalBuffer.FLAG3; + if (hasRefQualifier) + firstBytes |= ITypeMarshalBuffer.FLAG4; + if (isRValueReference) + firstBytes |= ITypeMarshalBuffer.FLAG5; buffer.putShort(firstBytes); buffer.putInt(parameters.length); @@ -167,18 +170,17 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - int len= buffer.getInt(); - IType rt= buffer.unmarshalType(); - IType[] pars= new IType[len]; + int len = buffer.getInt(); + IType rt = buffer.unmarshalType(); + IType[] pars = new IType[len]; for (int i = 0; i < pars.length; i++) { - pars[i]= buffer.unmarshalType(); + pars[i] = buffer.unmarshalType(); } boolean isConst = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; boolean takesVarargs = (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; boolean isVolatile = (firstBytes & ITypeMarshalBuffer.FLAG3) != 0; boolean hasRefQualifier = (firstBytes & ITypeMarshalBuffer.FLAG4) != 0; boolean isRValueReference = (firstBytes & ITypeMarshalBuffer.FLAG5) != 0; - return new CPPFunctionType(rt, pars, isConst, isVolatile, hasRefQualifier, isRValueReference, - takesVarargs); + return new CPPFunctionType(rt, pars, isConst, isVolatile, hasRefQualifier, isRValueReference, takesVarargs); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java index 04a900afd25..0c74fc52f4f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java @@ -33,14 +33,13 @@ public class CPPImplicitConstructor extends CPPImplicitMethod implements ICPPCon public CPPImplicitConstructor(ICPPClassScope scope, char[] name, ICPPParameter[] params, IASTNode point) { // Note: the value passed for the 'isConstexpr' parameter of the CPPImplicitMethod constructor // is irrelevant, as CPPImplicitConstructor overrides isConstexpr(). - super(scope, name, createFunctionType(params), params, false); - } + super(scope, name, createFunctionType(params), params, false); + } private static ICPPFunctionType createFunctionType(IParameter[] params) { return CPPVisitor.createImplicitFunctionType(UNSPECIFIED_TYPE, params, false, false); } - /* * From $12.1 / 5: * The implicitly-defined default constructor performs the set of initializations of the class that would diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java index adffbe27de1..2a693b9c48b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java @@ -29,79 +29,79 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; public class CPPImplicitFunction extends CPPFunction { private ICPPParameter[] params; private IScope scope; - private ICPPFunctionType functionType; + private ICPPFunctionType functionType; private final boolean isConstexpr; private final boolean takesVarArgs; private boolean isDeleted; private final char[] name; - public CPPImplicitFunction(char[] name, IScope scope, ICPPFunctionType type, - ICPPParameter[] params, boolean isConstexpr, boolean takesVarArgs) { - super(null); - this.name= name; - this.scope= scope; - this.functionType= type; - this.params= params; - this.takesVarArgs= takesVarArgs; - this.isConstexpr = isConstexpr; + public CPPImplicitFunction(char[] name, IScope scope, ICPPFunctionType type, ICPPParameter[] params, + boolean isConstexpr, boolean takesVarArgs) { + super(null); + this.name = name; + this.scope = scope; + this.functionType = type; + this.params = params; + this.takesVarArgs = takesVarArgs; + this.isConstexpr = isConstexpr; } - @Override + @Override public ICPPParameter[] getParameters() { - return params; - } + return params; + } - @Override + @Override public ICPPFunctionType getType() { - return functionType; - } - - @Override - public ICPPFunctionType getDeclaredType() { - return functionType; - } + return functionType; + } - @Override + @Override + public ICPPFunctionType getDeclaredType() { + return functionType; + } + + @Override public String getName() { - return String.valueOf(name); - } + return String.valueOf(name); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() { - return scope; - } + return scope; + } - @Override + @Override public IScope getFunctionScope() { - return null; - } + return null; + } @Override public boolean isConstexpr() { return isConstexpr; } - @Override + @Override public boolean takesVarArgs() { - return takesVarArgs; - } + return takesVarArgs; + } - @Override + @Override public boolean isDeleted() { - return isDeleted; - } + return isDeleted; + } - @Override + @Override public IBinding getOwner() { - return null; - } + return null; + } - public void setDeleted(boolean val) { - isDeleted= val; - } + public void setDeleted(boolean val) { + isDeleted = val; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index d70ea89a834..ab8c2a3665c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -46,23 +46,23 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; */ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod { - public CPPImplicitMethod(ICPPClassScope scope, char[] name, ICPPFunctionType type, ICPPParameter[] params, - boolean isConstexpr) { + public CPPImplicitMethod(ICPPClassScope scope, char[] name, ICPPFunctionType type, ICPPParameter[] params, + boolean isConstexpr) { super(name, scope, type, params, isConstexpr, false); } @Override public int getVisibility() { - IASTDeclaration decl= getPrimaryDeclaration(); + IASTDeclaration decl = getPrimaryDeclaration(); if (decl == null) { // 12.1-5, 12.8-10 Implicit constructors and assignment operators are public. return ICPPASTVisibilityLabel.v_public; } - IASTNode parent= decl.getParent(); + IASTNode parent = decl.getParent(); while (parent instanceof ICPPASTTemplateDeclaration) { - decl= (ICPPASTTemplateDeclaration) parent; - parent= parent.getParent(); + decl = (ICPPASTTemplateDeclaration) parent; + parent = parent.getParent(); } if (parent instanceof IASTCompositeTypeSpecifier) { IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); @@ -81,8 +81,8 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod return ICPPASTVisibilityLabel.v_private; } } - return ICPPASTVisibilityLabel.v_public; - } + return ICPPASTVisibilityLabel.v_public; + } @Override public ICPPClassType getClassOwner() { @@ -98,9 +98,9 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod break; IASTDeclaration decl = (IASTDeclaration) ASTQueries.findOutermostDeclarator(dtor).getParent(); - IASTNode parent= decl.getParent(); + IASTNode parent = decl.getParent(); while (parent instanceof ICPPASTTemplateDeclaration) - parent= parent.getParent(); + parent = parent.getParent(); if (parent instanceof ICPPASTCompositeTypeSpecifier) return decl; } @@ -109,8 +109,8 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod IFunctionType ftype = getType(); IType[] params = ftype.getParameterTypes(); - ICPPASTCompositeTypeSpecifier compSpec = - (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(getScope()); + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal + .getPhysicalNodeOfScope(getScope()); if (compSpec == null) { return null; } @@ -123,7 +123,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod if (member instanceof IASTSimpleDeclaration) { ds = ((IASTSimpleDeclaration) member).getDeclarators(); } else if (member instanceof IASTFunctionDefinition) { - ds = new IASTDeclarator[] {((IASTFunctionDefinition) member).getDeclarator()}; + ds = new IASTDeclarator[] { ((IASTFunctionDefinition) member).getDeclarator() }; } else { continue; } @@ -167,10 +167,10 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod return null; } - @Override + @Override public boolean isVirtual() { - return false; - } + return false; + } @Override public boolean isDestructor() { @@ -185,10 +185,10 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod return getPrimaryDeclaration() == null; } - @Override + @Override public boolean isExplicit() { - return false; - } + return false; + } @Override public boolean isPureVirtual() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethodTemplate.java index cf510dd5d6d..1787f6333db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethodTemplate.java @@ -18,15 +18,15 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; /** * Binding for implicit method templates. - * + * * Used for the function call operator and pointer-to-function conversion operator * of a generic lambda. */ public class CPPImplicitMethodTemplate extends CPPImplicitMethod implements ICPPFunctionTemplate { private ICPPTemplateParameter[] fTemplateParameters; - - public CPPImplicitMethodTemplate(ICPPTemplateParameter[] templateParameters, ICPPClassScope scope, - char[] name, ICPPFunctionType type, ICPPParameter[] params, boolean isConstexpr) { + + public CPPImplicitMethodTemplate(ICPPTemplateParameter[] templateParameters, ICPPClassScope scope, char[] name, + ICPPFunctionType type, ICPPParameter[] params, boolean isConstexpr) { super(scope, name, type, params, isConstexpr); fTemplateParameters = templateParameters; for (ICPPTemplateParameter parameter : templateParameters) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTemplateTypeParameter.java index b05dab95121..8152eff014a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTemplateTypeParameter.java @@ -32,25 +32,25 @@ import org.eclipse.core.runtime.PlatformObject; * * Used for the template type parameters of implicit method templates. */ -public class CPPImplicitTemplateTypeParameter extends PlatformObject implements ICPPTemplateTypeParameter, - ICPPUnknownType, ICPPUnknownBinding { +public class CPPImplicitTemplateTypeParameter extends PlatformObject + implements ICPPTemplateTypeParameter, ICPPUnknownType, ICPPUnknownBinding { private int fParameterID; private boolean fIsParameterPack; private ICPPScope fUnknownScope; - + // The containing (implicit) template definition. private ICPPTemplateDefinition fContainingTemplate; - + // The AST node that triggered the creation of the implicit template. // For methods of generic lambdas, this is the lambda expression. private IASTNode fNode; - + public CPPImplicitTemplateTypeParameter(IASTNode node, int position, boolean isParameterPack) { fParameterID = computeParameterID(position); fIsParameterPack = isParameterPack; fNode = node; } - + private int computeParameterID(int position) { int nesting = 0; for (IASTNode node = fNode; node != null; node = node.getParent()) { @@ -61,11 +61,11 @@ public class CPPImplicitTemplateTypeParameter extends PlatformObject implements } return (nesting << 16) + (position & 0xffff); } - + public void setContainingTemplate(ICPPTemplateDefinition containingTemplate) { fContainingTemplate = containingTemplate; } - + @Override public String[] getQualifiedName() throws DOMException { return new String[] { getName() }; @@ -142,20 +142,20 @@ public class CPPImplicitTemplateTypeParameter extends PlatformObject implements @Override public boolean isSameType(IType type) { - if (type == this) - return true; - if (type instanceof ITypedef) - return type.isSameType(this); - if (!(type instanceof ICPPTemplateTypeParameter)) - return false; + if (type == this) + return true; + if (type instanceof ITypedef) + return type.isSameType(this); + if (!(type instanceof ICPPTemplateTypeParameter)) + return false; - return getParameterID() == ((ICPPTemplateParameter) type).getParameterID(); + return getParameterID() == ((ICPPTemplateParameter) type).getParameterID(); } @Override public Object clone() { - return new CPPImplicitTemplateTypeParameter(fNode, getParameterPosition(), fIsParameterPack); - } + return new CPPImplicitTemplateTypeParameter(fNode, getParameterPosition(), fIsParameterPack); + } @Override public ICPPScope asScope() throws DOMException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java index a348b4858f1..f87cc8efdcd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitTypedef.java @@ -26,38 +26,38 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; * An example is the GCC built-in typedef: typedef char * __builtin_va_list; */ public class CPPImplicitTypedef extends CPPTypedef { - private IType type; - private char[] name; - private IScope scope; - - public CPPImplicitTypedef(IType type, char[] name, IScope scope) { - super(null); - this.type = type; - this.name = name; - this.scope = scope; - } - - @Override + private IType type; + private char[] name; + private IScope scope; + + public CPPImplicitTypedef(IType type, char[] name, IScope scope) { + super(null); + this.type = type; + this.name = name; + this.scope = scope; + } + + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public String getName() { - return String.valueOf(name); - } + return String.valueOf(name); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() { - return scope; - } + return scope; + } - @Override + @Override public boolean isSameType(IType t) { if (t == this) return true; @@ -75,67 +75,66 @@ public class CPPImplicitTypedef extends CPPTypedef { return false; } - @Override + @Override public Object clone() { - IType t = null; - t = (IType) super.clone(); - return t; - } - - /** - * returns null - */ - @Override + IType t = null; + t = (IType) super.clone(); + return t; + } + + /** + * returns null + */ + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - /** - * returns null - */ - @Override + /** + * returns null + */ + @Override public IASTNode getDefinition() { - return null; - } + return null; + } - /** - * does nothing - */ - @Override + /** + * does nothing + */ + @Override public void addDefinition(IASTNode node) { - // do nothing - } + // do nothing + } - /** - * does nothing - */ - @Override + /** + * does nothing + */ + @Override public void addDeclaration(IASTNode node) { - // do nothing - } + // do nothing + } - @Override + @Override public String[] getQualifiedName() { - String[] temp = new String[1]; - temp[0] = String.valueOf(name); - - return temp; - } + String[] temp = new String[1]; + temp[0] = String.valueOf(name); + return temp; + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - char[][] temp = new char[1][]; - temp[0] = name; + char[][] temp = new char[1][]; + temp[0] = name; - return temp; - } + return temp; + } - /** - * returns true - */ - @Override + /** + * returns true + */ + @Override public boolean isGloballyQualified() { - return true; - } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java index 70782c1a098..420a55bb565 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java @@ -26,70 +26,70 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; public class CPPLabel extends PlatformObject implements ILabel, ICPPInternalBinding { - private IASTName name; + private IASTName name; - public CPPLabel(IASTName name) { - this.name = name; - name.setBinding(this); - } + public CPPLabel(IASTName name) { + this.name = name; + name.setBinding(this); + } - @Override + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - @Override + @Override public IASTNode getDefinition() { - return name; - } + return name; + } - @Override + @Override public IASTLabelStatement getLabelStatement() { - IASTNode statement = name.getParent(); - if (statement instanceof IASTLabelStatement) - return (IASTLabelStatement) statement; + IASTNode statement = name.getParent(); + if (statement instanceof IASTLabelStatement) + return (IASTLabelStatement) statement; - // TODO find label statement - return null; - } + // TODO find label statement + return null; + } - @Override + @Override public String getName() { - return new String(getNameCharArray()); - } + return new String(getNameCharArray()); + } - @Override + @Override public char[] getNameCharArray() { - return name.getSimpleID(); - } + return name.getSimpleID(); + } - @Override + @Override public IScope getScope() { - return CPPVisitor.getContainingScope(name); - } + return CPPVisitor.getContainingScope(name); + } - public IASTNode getPhysicalNode() { - return name; - } + public IASTNode getPhysicalNode() { + return name; + } - public void setLabelStatement(IASTName labelStatement) { - name = labelStatement; - } + public void setLabelStatement(IASTName labelStatement) { + name = labelStatement; + } - @Override + @Override public String[] getQualifiedName() { - return new String[] { getName() }; - } + return new String[] { getName() }; + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return new char[][] { getNameCharArray() }; - } + return new char[][] { getNameCharArray() }; + } - @Override + @Override public boolean isGloballyQualified() { - return false; - } + return false; + } @Override public void addDefinition(IASTNode node) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index 815c8f0c61a..a78bc30c62c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -67,9 +67,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { final char[] myName = getASTName().getLookupKey(); ICPPClassScope scope = (ICPPClassScope) getScope(); - ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope); + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal + .getPhysicalNodeOfScope(scope); if (compSpec != null) { - IASTDeclaration [] members = compSpec.getMembers(); + IASTDeclaration[] members = compSpec.getMembers(); for (IASTDeclaration member : members) { if (member instanceof IASTSimpleDeclaration) { IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators(); @@ -99,13 +100,14 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { if (scope instanceof ICPPClassScope) { ICPPClassType cls = ((ICPPClassScope) scope).getClassType(); if (cls != null) - return (cls.getKey() == ICPPClassType.k_class) ? ICPPASTVisibilityLabel.v_private : ICPPASTVisibilityLabel.v_public; + return (cls.getKey() == ICPPClassType.k_class) ? ICPPASTVisibilityLabel.v_private + : ICPPASTVisibilityLabel.v_public; } return ICPPASTVisibilityLabel.v_private; } IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); - IASTDeclaration [] members = cls.getMembers(); + IASTDeclaration[] members = cls.getMembers(); ICPPASTVisibilityLabel vis = null; for (IASTDeclaration member : members) { if (member instanceof ICPPASTVisibilityLabel) { @@ -130,13 +132,13 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { @Override protected IASTName getASTName() { - IASTDeclarator dtor= (declarations != null && declarations.length > 0) ? declarations[0] : definition; - dtor= ASTQueries.findInnermostDeclarator(dtor); - IASTName name= dtor.getName(); - if (name instanceof ICPPASTQualifiedName) { - name = name.getLastName(); - } - return name; + IASTDeclarator dtor = (declarations != null && declarations.length > 0) ? declarations[0] : definition; + dtor = ASTQueries.findInnermostDeclarator(dtor); + IASTName name = dtor.getName(); + if (name instanceof ICPPASTQualifiedName) { + name = name.getLastName(); + } + return name; } @Override @@ -144,17 +146,17 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { return CPPVisitor.getContainingScope(getASTName()); } - @Override + @Override public boolean isVirtual() { - IASTDeclaration decl = getPrimaryDeclaration(); + IASTDeclaration decl = getPrimaryDeclaration(); if (decl != null) { ICPPASTDeclSpecifier declSpec = getDeclSpec(decl); if (declSpec != null) { return declSpec.isVirtual(); } } - return false; - } + return false; + } protected ICPPASTDeclSpecifier getDeclSpec(IASTDeclaration decl) { ICPPASTDeclSpecifier declSpec = null; @@ -166,22 +168,22 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { return declSpec; } - @Override + @Override public boolean isInline() { - IASTDeclaration decl = getPrimaryDeclaration(); - if (decl instanceof IASTFunctionDefinition) - return true; + IASTDeclaration decl = getPrimaryDeclaration(); + if (decl instanceof IASTFunctionDefinition) + return true; if (decl == null) return false; - IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); - return declSpec.isInline(); - } + IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); + return declSpec.isInline(); + } - @Override + @Override public boolean isMutable() { - return hasStorageClass(this, IASTDeclSpecifier.sc_mutable); - } + return hasStorageClass(this, IASTDeclSpecifier.sc_mutable); + } @Override public boolean isStatic(boolean resolveAll) { @@ -209,35 +211,35 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { return false; } - @Override + @Override public boolean isPureVirtual() { ICPPASTFunctionDeclarator declarator = findFunctionDeclarator(); - if (declarator != null) { - return declarator.isPureVirtual(); - } - return false; - } + if (declarator != null) { + return declarator.isPureVirtual(); + } + return false; + } - @Override - public boolean isFinal() { - ICPPASTFunctionDeclarator declarator = findFunctionDeclarator(); - if (declarator != null) { - return declarator.isFinal(); - } - return false; - } + @Override + public boolean isFinal() { + ICPPASTFunctionDeclarator declarator = findFunctionDeclarator(); + if (declarator != null) { + return declarator.isFinal(); + } + return false; + } - @Override - public boolean isOverride() { - ICPPASTFunctionDeclarator declarator = findFunctionDeclarator(); - if (declarator != null) { - return declarator.isOverride(); - } - return false; - } + @Override + public boolean isOverride() { + ICPPASTFunctionDeclarator declarator = findFunctionDeclarator(); + if (declarator != null) { + return declarator.isOverride(); + } + return false; + } - private ICPPASTFunctionDeclarator findFunctionDeclarator() { - if (declarations != null) { + private ICPPASTFunctionDeclarator findFunctionDeclarator() { + if (declarations != null) { for (IASTDeclarator dtor : declarations) { if (dtor == null) break; @@ -245,25 +247,25 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { dtor = ASTQueries.findOutermostDeclarator(dtor); IASTDeclaration decl = (IASTDeclaration) dtor.getParent(); if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { - dtor= ASTQueries.findTypeRelevantDeclarator(dtor); + dtor = ASTQueries.findTypeRelevantDeclarator(dtor); if (dtor instanceof ICPPASTFunctionDeclarator) { return (ICPPASTFunctionDeclarator) dtor; } } } } - return definition; - } + return definition; + } - @Override + @Override public boolean isExplicit() { - IASTDeclaration decl= getPrimaryDeclaration(); - if (decl != null) { - ICPPASTDeclSpecifier declspec= getDeclSpec(decl); - if (declspec != null) { - return declspec.isExplicit(); - } - } - return false; - } + IASTDeclaration decl = getPrimaryDeclaration(); + if (decl != null) { + ICPPASTDeclSpecifier declspec = getDeclSpec(decl); + if (declspec != null) { + return declspec.isExplicit(); + } + } + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java index a94d6bdf3b8..b8be935b95d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java @@ -42,14 +42,14 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod return (ICPPClassType) getOwner(); } - @Override + @Override public boolean isVirtual() { - return ((ICPPMethod) getTemplateDefinition()).isVirtual(); - } + return ((ICPPMethod) getTemplateDefinition()).isVirtual(); + } @Override public boolean isPureVirtual() { - return ((ICPPMethod) getTemplateDefinition()).isPureVirtual(); + return ((ICPPMethod) getTemplateDefinition()).isPureVirtual(); } @Override @@ -73,11 +73,11 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod @Override public boolean isOverride() { - return ((ICPPMethod) getTemplateDefinition()).isOverride(); + return ((ICPPMethod) getTemplateDefinition()).isOverride(); } @Override public boolean isFinal() { - return ((ICPPMethod) getTemplateDefinition()).isFinal(); + return ((ICPPMethod) getTemplateDefinition()).isFinal(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java index f9a045ee62e..1804a5e479f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java @@ -126,7 +126,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement } return super.getExceptionSpecification(); } - + @Override public IType[] getExceptionSpecification(IASTNode point) { return getExceptionSpecification(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java index 8542b21afeb..43fbac1bcda 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java @@ -80,7 +80,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod } } ICPPClassScope clsScope = (ICPPClassScope) scope; - ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope); + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal + .getPhysicalNodeOfScope(clsScope); IASTDeclaration[] members = compSpec.getMembers(); for (IASTDeclaration member : members) { if (member instanceof ICPPASTTemplateDeclaration) { @@ -94,7 +95,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod } } } else if (decl instanceof IASTFunctionDefinition) { - IASTName name = ASTQueries.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()).getName(); + IASTName name = ASTQueries.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()) + .getName(); if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) { return member; } @@ -110,13 +112,13 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod if (decl == null) { ICPPClassType cls = getClassOwner(); if (cls != null) { - return cls.getKey() == ICPPClassType.k_class ? - ICPPASTVisibilityLabel.v_private : ICPPASTVisibilityLabel.v_public; + return cls.getKey() == ICPPClassType.k_class ? ICPPASTVisibilityLabel.v_private + : ICPPASTVisibilityLabel.v_public; } return ICPPASTVisibilityLabel.v_private; } IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); - IASTDeclaration [] members = cls.getMembers(); + IASTDeclaration[] members = cls.getMembers(); ICPPASTVisibilityLabel vis = null; for (IASTDeclaration member : members) { if (member instanceof ICPPASTVisibilityLabel) { @@ -135,10 +137,10 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod @Override public ICPPClassType getClassOwner() { - IScope scope= getScope(); + IScope scope = getScope(); if (scope instanceof ICPPTemplateScope) { try { - scope= scope.getParent(); + scope = scope.getParent(); } catch (DOMException e) { return null; } @@ -149,11 +151,11 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod return null; } - @Override + @Override public boolean isVirtual() { IASTDeclaration decl = getPrimaryDeclaration(); if (decl instanceof ICPPASTTemplateDeclaration) { - ICPPASTDeclSpecifier declSpec= getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); + ICPPASTDeclSpecifier declSpec = getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); if (declSpec != null) { return declSpec.isVirtual(); } @@ -165,7 +167,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod public boolean isStatic(boolean resolveAll) { IASTDeclaration decl = getPrimaryDeclaration(); if (decl instanceof ICPPASTTemplateDeclaration) { - ICPPASTDeclSpecifier declSpec= getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); + ICPPASTDeclSpecifier declSpec = getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); if (declSpec != null) { return declSpec.getStorageClass() == IASTDeclSpecifier.sc_static; } @@ -173,7 +175,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod return false; } - @Override + @Override public boolean isInline() { IASTDeclaration decl = getPrimaryDeclaration(); if (decl instanceof ICPPASTTemplateDeclaration @@ -201,8 +203,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod public boolean isExplicit() { IASTDeclaration decl = getPrimaryDeclaration(); if (decl instanceof ICPPASTTemplateDeclaration) { - ICPPASTDeclSpecifier declSpec= - getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); + ICPPASTDeclSpecifier declSpec = getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration()); if (declSpec != null) { return declSpec.isExplicit(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java index 5137ee88770..ec0e633229d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java @@ -29,8 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; /** * The specialization of a method template in the context of a class specialization. */ -public class CPPMethodTemplateSpecialization extends CPPFunctionTemplateSpecialization - implements ICPPMethod { +public class CPPMethodTemplateSpecialization extends CPPFunctionTemplateSpecialization implements ICPPMethod { private ICPPTemplateParameter[] fTemplateParameters; public CPPMethodTemplateSpecialization(ICPPMethod specialized, ICPPClassSpecialization owner, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index 8d1e1fe1242..8b12c6387af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -48,9 +48,9 @@ import org.eclipse.core.runtime.PlatformObject; public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPInternalBinding { public static class CPPNamespaceProblem extends ProblemBinding implements ICPPNamespace, ICPPNamespaceScope { - public CPPNamespaceProblem(IASTNode node, int id, char[] arg) { - super(node, id, arg); - } + public CPPNamespaceProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); + } @Override public ICPPNamespaceScope getNamespaceScope() { @@ -75,71 +75,71 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI public ICPPNamespaceScope[] getInlineNamespaces() { return ICPPNamespaceScope.EMPTY_NAMESPACE_SCOPE_ARRAY; } - } + } IASTName[] namespaceDefinitions; ICPPNamespaceScope scope; ICPPASTTranslationUnit tu; public CPPNamespace(ICPPASTNamespaceDefinition nsDef) { - findAllDefinitions(nsDef); - if (namespaceDefinitions.length == 0) { - namespaceDefinitions = new IASTName[] { nsDef.getName() }; - } + findAllDefinitions(nsDef); + if (namespaceDefinitions.length == 0) { + namespaceDefinitions = new IASTName[] { nsDef.getName() }; + } } - @Override + @Override public IASTNode[] getDeclarations() { - return namespaceDefinitions; - } + return namespaceDefinitions; + } - @Override + @Override public IASTNode getDefinition() { - return tu != null ? tu : (IASTNode) namespaceDefinitions[0]; - } + return tu != null ? tu : (IASTNode) namespaceDefinitions[0]; + } static private class NamespaceCollector extends ASTVisitor { - private ICPPASTNamespaceDefinition namespaceDef; - private IASTName[] namespaces; + private ICPPASTNamespaceDefinition namespaceDef; + private IASTName[] namespaces; - public NamespaceCollector(ICPPASTNamespaceDefinition ns) { - shouldVisitNamespaces = true; - shouldVisitDeclarations = true; - this.namespaceDef = ns; - } + public NamespaceCollector(ICPPASTNamespaceDefinition ns) { + shouldVisitNamespaces = true; + shouldVisitDeclarations = true; + this.namespaceDef = ns; + } - @Override + @Override public int visit(ICPPASTNamespaceDefinition namespace) { - ICPPASTNamespaceDefinition orig = namespaceDef, candidate = namespace; - while (candidate != null) { - if (!CharArrayUtils.equals(orig.getName().getLookupKey(), candidate.getName().getLookupKey())) - return PROCESS_CONTINUE; - if (orig.getParent() instanceof ICPPASTNamespaceDefinition) { - if (!(candidate.getParent() instanceof ICPPASTNamespaceDefinition)) - return PROCESS_CONTINUE; - orig = (ICPPASTNamespaceDefinition) orig.getParent(); - candidate = (ICPPASTNamespaceDefinition) candidate.getParent(); - } else if (candidate.getParent() instanceof ICPPASTNamespaceDefinition) { - return PROCESS_CONTINUE; - } else { - break; - } - } - - namespaces = ArrayUtil.append(IASTName.class, namespaces, namespace.getName()); - return PROCESS_SKIP; - } - - @Override + ICPPASTNamespaceDefinition orig = namespaceDef, candidate = namespace; + while (candidate != null) { + if (!CharArrayUtils.equals(orig.getName().getLookupKey(), candidate.getName().getLookupKey())) + return PROCESS_CONTINUE; + if (orig.getParent() instanceof ICPPASTNamespaceDefinition) { + if (!(candidate.getParent() instanceof ICPPASTNamespaceDefinition)) + return PROCESS_CONTINUE; + orig = (ICPPASTNamespaceDefinition) orig.getParent(); + candidate = (ICPPASTNamespaceDefinition) candidate.getParent(); + } else if (candidate.getParent() instanceof ICPPASTNamespaceDefinition) { + return PROCESS_CONTINUE; + } else { + break; + } + } + + namespaces = ArrayUtil.append(IASTName.class, namespaces, namespace.getName()); + return PROCESS_SKIP; + } + + @Override public int visit(IASTDeclaration declaration) { - if (declaration instanceof ICPPASTLinkageSpecification) - return PROCESS_CONTINUE; - return PROCESS_SKIP; - } - - public IASTName[] getNamespaces() { - return ArrayUtil.trim(IASTName.class, namespaces); - } + if (declaration instanceof ICPPASTLinkageSpecification) + return PROCESS_CONTINUE; + return PROCESS_SKIP; + } + + public IASTName[] getNamespaces() { + return ArrayUtil.trim(IASTName.class, namespaces); + } } static private class NamespaceMemberCollector extends ASTVisitor { @@ -197,7 +197,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI @Override public int visit(IASTDeclaration declaration) { if (declaration instanceof ICPPASTUsingDeclaration) { - IBinding binding =((ICPPASTUsingDeclaration) declaration).getName().resolveBinding(); + IBinding binding = ((ICPPASTUsingDeclaration) declaration).getName().resolveBinding(); if (binding != null && !(binding instanceof IProblemBinding)) members.put(binding); return PROCESS_SKIP; @@ -209,17 +209,17 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI } private void findAllDefinitions(ICPPASTNamespaceDefinition namespaceDef) { - NamespaceCollector collector = new NamespaceCollector(namespaceDef); - namespaceDef.getTranslationUnit().accept(collector); + NamespaceCollector collector = new NamespaceCollector(namespaceDef); + namespaceDef.getTranslationUnit().accept(collector); - namespaceDefinitions = collector.getNamespaces(); - for (IASTName namespaceDefinition : namespaceDefinitions) { - namespaceDefinition.setBinding(this); - } + namespaceDefinitions = collector.getNamespaces(); + for (IASTName namespaceDefinition : namespaceDefinitions) { + namespaceDefinition.setBinding(this); + } } public IASTName[] getNamespaceDefinitions() { - return namespaceDefinitions; + return namespaceDefinitions; } public CPPNamespace(CPPASTTranslationUnit unit) { @@ -229,18 +229,18 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI @Override public ICPPNamespaceScope getNamespaceScope() { if (scope == null) { - if (tu != null) { - scope = (ICPPNamespaceScope) tu.getScope(); - } else { - scope = new CPPNamespaceScope(namespaceDefinitions[0].getParent()); - } + if (tu != null) { + scope = (ICPPNamespaceScope) tu.getScope(); + } else { + scope = new CPPNamespaceScope(namespaceDefinitions[0].getParent()); + } } return scope; } @Override public String getName() { - return new String(getNameCharArray()); + return new String(getNameCharArray()); } @Override @@ -253,33 +253,34 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI return tu != null ? null : CPPVisitor.getContainingScope(namespaceDefinitions[0]); } - @Override + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() { - return true; - } + return true; + } @Override public void addDefinition(IASTNode node) { if (!(node instanceof IASTName)) - return; + return; IASTName name = (IASTName) node; if (namespaceDefinitions == null) { - namespaceDefinitions = new IASTName[] { name }; - return; + namespaceDefinitions = new IASTName[] { name }; + return; } - if (namespaceDefinitions.length > 0 && ((ASTNode) name).getOffset() < ((ASTNode) namespaceDefinitions[0]).getOffset()) { + if (namespaceDefinitions.length > 0 + && ((ASTNode) name).getOffset() < ((ASTNode) namespaceDefinitions[0]).getOffset()) { namespaceDefinitions = ArrayUtil.prepend(IASTName.class, namespaceDefinitions, name); } else { namespaceDefinitions = ArrayUtil.append(IASTName.class, namespaceDefinitions, name); @@ -323,19 +324,19 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI return Linkage.CPP_LINKAGE; } - @Override + @Override public String toString() { - String[] names = getQualifiedName(); - if (names.length == 0) { - return "<global namespace>"; //$NON-NLS-1$ - } - StringBuilder buf = new StringBuilder(); - for (String name : names) { - if (buf.length() != 0) - buf.append(Keywords.cpCOLONCOLON); - buf.append(name.isEmpty() ? "<anonymous>" : name); //$NON-NLS-1$ - } - return buf.toString(); + String[] names = getQualifiedName(); + if (names.length == 0) { + return "<global namespace>"; //$NON-NLS-1$ + } + StringBuilder buf = new StringBuilder(); + for (String name : names) { + if (buf.length() != 0) + buf.append(Keywords.cpCOLONCOLON); + buf.append(name.isEmpty() ? "<anonymous>" : name); //$NON-NLS-1$ + } + return buf.toString(); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java index 9f9c9ad3a59..5122b553548 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java @@ -29,70 +29,70 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; public class CPPNamespaceAlias extends PlatformObject implements ICPPNamespaceAlias, ICPPInternalBinding { - private ICPPNamespace namespace; - private IASTName alias; + private ICPPNamespace namespace; + private IASTName alias; public CPPNamespaceAlias(IASTName aliasName, ICPPNamespace namespace) { - super(); - this.namespace = namespace; - this.alias = aliasName; - } + super(); + this.namespace = namespace; + this.alias = aliasName; + } - @Override + @Override public ICPPNamespaceScope getNamespaceScope() { - return namespace.getNamespaceScope(); - } + return namespace.getNamespaceScope(); + } - @Override + @Override public IBinding getBinding() { - return namespace; - } + return namespace; + } - @Override + @Override public String getName() { - return new String(getNameCharArray()); - } + return new String(getNameCharArray()); + } - @Override + @Override public char[] getNameCharArray() { - return alias.getSimpleID(); - } + return alias.getSimpleID(); + } - @Override + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public IScope getScope() { - return CPPVisitor.getContainingScope(alias); - } + return CPPVisitor.getContainingScope(alias); + } - @Override + @Override public boolean isGloballyQualified() throws DOMException { - IScope scope = getScope(); - while (scope != null) { - if (scope instanceof ICPPBlockScope) - return false; - scope = scope.getParent(); - } - return true; - } - - @Override + IScope scope = getScope(); + while (scope != null) { + if (scope instanceof ICPPBlockScope) + return false; + scope = scope.getParent(); + } + return true; + } + + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - @Override + @Override public IASTNode getDefinition() { - return alias; - } + return alias; + } @Override public void addDefinition(IASTNode node) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceScope.java index 0840df7ef1a..73ba1b3488b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceScope.java @@ -63,7 +63,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace private ICPPNamespaceScope[] fEnclosingNamespaceSet; private List<ICPPASTNamespaceDefinition> fInlineNamespaceDefinitions; private ICPPInternalNamespaceScope[] fInlineNamespaces; - + // The set of names declared in this scope that are currently only visible to argument-dependent lookup. private CharArraySet fVisibleToAdlOnly = new CharArraySet(0); @@ -88,7 +88,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace private void initUsingDirectives() { if (fUsingDirectives == null) { - fUsingDirectives= new ArrayList<>(1); + fUsingDirectives = new ArrayList<>(1); // Insert a using directive for every inline namespace found in the index. for (ICPPInternalNamespaceScope inline : getIndexInlineNamespaces()) { if (!(inline instanceof CPPNamespaceScope)) { @@ -104,87 +104,87 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace fUsingDirectives.add(directive); } - @Override + @Override public IName getScopeName() { - IASTNode node = getPhysicalNode(); - if (node instanceof ICPPASTNamespaceDefinition) { - return ((ICPPASTNamespaceDefinition) node).getName(); - } - return null; - } - - public IScope findNamespaceScope(IIndexScope scope) { - final ArrayList<IBinding> parentChain = new ArrayList<>(); - for (IBinding binding= scope.getScopeBinding(); binding != null; binding= binding.getOwner()) { - parentChain.add(binding); - } - - final IScope[] result= { null }; - final ASTVisitor visitor= new ASTVisitor() { - private int position = parentChain.size(); - - { - shouldVisitNamespaces= shouldVisitDeclarations= true; - } - - @Override - public int visit(IASTDeclaration declaration) { - if (declaration instanceof ICPPASTLinkageSpecification) - return PROCESS_CONTINUE; - return PROCESS_SKIP; - } - - @Override - public int visit(ICPPASTNamespaceDefinition namespace) { - final char[] name = namespace.getName().toCharArray(); - IBinding binding = parentChain.get(--position); - if (!CharArrayUtils.equals(name, binding.getNameCharArray())) { - ++position; - return PROCESS_SKIP; - } + IASTNode node = getPhysicalNode(); + if (node instanceof ICPPASTNamespaceDefinition) { + return ((ICPPASTNamespaceDefinition) node).getName(); + } + return null; + } + + public IScope findNamespaceScope(IIndexScope scope) { + final ArrayList<IBinding> parentChain = new ArrayList<>(); + for (IBinding binding = scope.getScopeBinding(); binding != null; binding = binding.getOwner()) { + parentChain.add(binding); + } + + final IScope[] result = { null }; + final ASTVisitor visitor = new ASTVisitor() { + private int position = parentChain.size(); + + { + shouldVisitNamespaces = shouldVisitDeclarations = true; + } + + @Override + public int visit(IASTDeclaration declaration) { + if (declaration instanceof ICPPASTLinkageSpecification) + return PROCESS_CONTINUE; + return PROCESS_SKIP; + } + + @Override + public int visit(ICPPASTNamespaceDefinition namespace) { + final char[] name = namespace.getName().toCharArray(); + IBinding binding = parentChain.get(--position); + if (!CharArrayUtils.equals(name, binding.getNameCharArray())) { + ++position; + return PROCESS_SKIP; + } if (position == 0) { - result[0]= namespace.getScope(); + result[0] = namespace.getScope(); return PROCESS_ABORT; } return PROCESS_CONTINUE; - } + } - @Override - public int leave(ICPPASTNamespaceDefinition namespace) { - ++position; - return PROCESS_CONTINUE; - } - }; + @Override + public int leave(ICPPASTNamespaceDefinition namespace) { + ++position; + return PROCESS_CONTINUE; + } + }; - getPhysicalNode().accept(visitor); - return result[0]; - } + getPhysicalNode().accept(visitor); + return result[0]; + } - @Override + @Override public void addName(IASTName name, boolean adlOnly) { - if (name instanceof ICPPASTQualifiedName && !canDenoteNamespaceMember((ICPPASTQualifiedName) name)) - return; - super.addName(name, adlOnly); - if (adlOnly) { - fVisibleToAdlOnly.put(name.getLookupKey()); - } else { - fVisibleToAdlOnly.remove(name.getLookupKey()); - } - } - - @Override - protected boolean nameIsVisibleToLookup(ScopeLookupData lookup) { - if (lookup.isArgumentDependent()) { - return true; - } - return !fVisibleToAdlOnly.containsKey(lookup.getLookupKey()); - } + if (name instanceof ICPPASTQualifiedName && !canDenoteNamespaceMember((ICPPASTQualifiedName) name)) + return; + super.addName(name, adlOnly); + if (adlOnly) { + fVisibleToAdlOnly.put(name.getLookupKey()); + } else { + fVisibleToAdlOnly.remove(name.getLookupKey()); + } + } + + @Override + protected boolean nameIsVisibleToLookup(ScopeLookupData lookup) { + if (lookup.isArgumentDependent()) { + return true; + } + return !fVisibleToAdlOnly.containsKey(lookup.getLookupKey()); + } public boolean canDenoteNamespaceMember(ICPPASTQualifiedName name) { - IScope scope= this; - ICPPASTNameSpecifier[] segments= name.getQualifier(); + IScope scope = this; + ICPPASTNameSpecifier[] segments = name.getQualifier(); try { - for (int i= segments.length; --i >= 0;) { + for (int i = segments.length; --i >= 0;) { if (scope == null) return false; IName scopeName = scope.getScopeName(); @@ -193,18 +193,18 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace if (segments[i] instanceof IASTName) { IASTName segmentName = (IASTName) segments[i]; - if (segmentName instanceof ICPPASTTemplateId || - !CharArrayUtils.equals(scopeName.getSimpleID(), segmentName.getSimpleID())) { + if (segmentName instanceof ICPPASTTemplateId + || !CharArrayUtils.equals(scopeName.getSimpleID(), segmentName.getSimpleID())) { return false; } } else { IBinding segmentBinding = segments[i].resolveBinding(); - if (segmentBinding instanceof ICPPTemplateInstance || - !CharArrayUtils.equals(scopeName.getSimpleID(), segmentBinding.getNameCharArray())) { + if (segmentBinding instanceof ICPPTemplateInstance + || !CharArrayUtils.equals(scopeName.getSimpleID(), segmentBinding.getNameCharArray())) { return false; } } - scope= scope.getParent(); + scope = scope.getParent(); } if (!name.isFullyQualified() || scope == null) { return true; @@ -218,14 +218,14 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace @Override public boolean isInlineNamepace() { if (!fIsInlineInitialized) { - fIsInline= computeIsInline(); - fIsInlineInitialized= true; + fIsInline = computeIsInline(); + fIsInlineInitialized = true; } return fIsInline; } public boolean computeIsInline() { - final IASTNode node= getPhysicalNode(); + final IASTNode node = getPhysicalNode(); if (!(node instanceof ICPPASTNamespaceDefinition)) { return false; } @@ -233,12 +233,12 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace if (((ICPPASTNamespaceDefinition) node).isInline()) return true; - IASTTranslationUnit tu= node.getTranslationUnit(); + IASTTranslationUnit tu = node.getTranslationUnit(); if (tu != null) { - final IIndex index= tu.getIndex(); - IIndexFileSet fileSet= tu.getASTFileSet(); + final IIndex index = tu.getIndex(); + IIndexFileSet fileSet = tu.getASTFileSet(); if (index != null && fileSet != null) { - fileSet= fileSet.invert(); + fileSet = fileSet.invert(); ICPPNamespace nsBinding = getNamespaceIndexBinding(index); if (nsBinding != null && nsBinding.isInline()) { try { @@ -260,7 +260,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace @Override public ICPPNamespaceScope[] getEnclosingNamespaceSet() { if (fEnclosingNamespaceSet == null) { - return fEnclosingNamespaceSet= computeEnclosingNamespaceSet(this); + return fEnclosingNamespaceSet = computeEnclosingNamespaceSet(this); } return fEnclosingNamespaceSet; } @@ -271,16 +271,16 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace return NO_NAMESPACE_SCOPES; if (fInlineNamespaces == null) { - fInlineNamespaces= computeInlineNamespaces(); + fInlineNamespaces = computeInlineNamespaces(); } return fInlineNamespaces; } ICPPInternalNamespaceScope[] computeInlineNamespaces() { populateCache(); - Set<ICPPInternalNamespaceScope> result= null; + Set<ICPPInternalNamespaceScope> result = null; if (fInlineNamespaceDefinitions != null) { - result= new HashSet<>(fInlineNamespaceDefinitions.size()); + result = new HashSet<>(fInlineNamespaceDefinitions.size()); for (ICPPASTNamespaceDefinition nsdef : fInlineNamespaceDefinitions) { final IScope scope = nsdef.getScope(); if (scope instanceof ICPPInternalNamespaceScope) { @@ -302,29 +302,29 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace } private ICPPInternalNamespaceScope[] getIndexInlineNamespaces() { - IASTTranslationUnit tu= getPhysicalNode().getTranslationUnit(); + IASTTranslationUnit tu = getPhysicalNode().getTranslationUnit(); if (tu instanceof CPPASTTranslationUnit) { - CPPASTTranslationUnit ast= (CPPASTTranslationUnit) tu; - IIndex index= tu.getIndex(); + CPPASTTranslationUnit ast = (CPPASTTranslationUnit) tu; + IIndex index = tu.getIndex(); if (index != null) { - IScope[] inlineScopes= null; - ICPPNamespace namespace= getNamespaceIndexBinding(index); + IScope[] inlineScopes = null; + ICPPNamespace namespace = getNamespaceIndexBinding(index); try { if (namespace != null) { ICPPNamespaceScope scope = namespace.getNamespaceScope(); - inlineScopes= scope.getInlineNamespaces(); + inlineScopes = scope.getInlineNamespaces(); } else if (getKind() == EScopeKind.eGlobal) { - inlineScopes= index.getInlineNamespaces(); + inlineScopes = index.getInlineNamespaces(); } } catch (CoreException e) { } if (inlineScopes != null) { - List<ICPPInternalNamespaceScope> result= null; + List<ICPPInternalNamespaceScope> result = null; for (IScope scope : inlineScopes) { - scope= ast.mapToASTScope(scope); + scope = ast.mapToASTScope(scope); if (scope instanceof ICPPInternalNamespaceScope) { if (result == null) { - result= new ArrayList<>(); + result = new ArrayList<>(); } result.add((ICPPInternalNamespaceScope) scope); } @@ -343,7 +343,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace */ public void addInlineNamespace(ICPPASTNamespaceDefinition nsDef) { if (fInlineNamespaceDefinitions == null) { - fInlineNamespaceDefinitions= new ArrayList<>(); + fInlineNamespaceDefinitions = new ArrayList<>(); } fInlineNamespaceDefinitions.add(nsDef); } @@ -351,7 +351,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace public static ICPPNamespaceScope[] computeEnclosingNamespaceSet(ICPPInternalNamespaceScope nsScope) { if (nsScope.isInlineNamepace()) { try { - IScope parent= nsScope.getParent(); + IScope parent = nsScope.getParent(); if (parent instanceof ICPPInternalNamespaceScope) { return ((ICPPInternalNamespaceScope) parent).getEnclosingNamespaceSet(); } @@ -360,13 +360,14 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace } } - Set<ICPPInternalNamespaceScope> result= new HashSet<>(); + Set<ICPPInternalNamespaceScope> result = new HashSet<>(); result.add(nsScope); addInlineNamespaces(nsScope, result); return result.toArray(new ICPPNamespaceScope[result.size()]); } - private static void addInlineNamespaces(ICPPInternalNamespaceScope nsScope, Set<ICPPInternalNamespaceScope> result) { + private static void addInlineNamespaces(ICPPInternalNamespaceScope nsScope, + Set<ICPPInternalNamespaceScope> result) { ICPPInternalNamespaceScope[] inlineNss = nsScope.getInlineNamespaces(); for (ICPPInternalNamespaceScope inlineNs : inlineNss) { if (result.add(inlineNs)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java index e76028c22cd..a929c58f638 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java @@ -195,7 +195,8 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) { + public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, + IASTExpression subscript) { return new CPPASTArraySubscriptExpression(arrayExpr, subscript); } @@ -238,7 +239,8 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTBaseSpecifier newBaseSpecifier(ICPPASTNameSpecifier nameSpecifier, int visibility, boolean isVirtual) { + public ICPPASTBaseSpecifier newBaseSpecifier(ICPPASTNameSpecifier nameSpecifier, int visibility, + boolean isVirtual) { return new CPPASTBaseSpecifier(nameSpecifier, visibility, isVirtual); } @@ -253,7 +255,8 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public IASTExpression newBinaryTypeIdExpression(IASTBinaryTypeIdExpression.Operator op, IASTTypeId type1, IASTTypeId type2) { + public IASTExpression newBinaryTypeIdExpression(IASTBinaryTypeIdExpression.Operator op, IASTTypeId type1, + IASTTypeId type2) { return new CPPASTBinaryTypeIdExpression(op, type1, type2); } @@ -305,14 +308,15 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public IASTConditionalExpression newConditionalExpession(IASTExpression condition, IASTExpression positive, IASTExpression negative) { + public IASTConditionalExpression newConditionalExpession(IASTExpression condition, IASTExpression positive, + IASTExpression negative) { return new CPPASTConditionalExpression(condition, positive, negative); } @Override @Deprecated public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName id, IASTExpression expression) { - ICPPASTConstructorChainInitializer result= new CPPASTConstructorChainInitializer(id, null); + ICPPASTConstructorChainInitializer result = new CPPASTConstructorChainInitializer(id, null); result.setInitializerValue(expression); return result; } @@ -325,7 +329,7 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { @Override @Deprecated public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp) { - ICPPASTConstructorInitializer result= new CPPASTConstructorInitializer(null); + ICPPASTConstructorInitializer result = new CPPASTConstructorInitializer(null); result.setExpression(exp); return result; } @@ -464,18 +468,19 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { @Deprecated public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) { CPPASTFunctionCallExpression result = new CPPASTFunctionCallExpression(idExpr, null); - if (argList == null) { - result.setArguments(null); - } else if (argList instanceof ICPPASTExpressionList) { - result.setArguments(((ICPPASTExpressionList) argList).getExpressions()); - } else { - result.setArguments(new IASTExpression[] {argList}); - } + if (argList == null) { + result.setArguments(null); + } else if (argList instanceof ICPPASTExpressionList) { + result.setArguments(((ICPPASTExpressionList) argList).getExpressions()); + } else { + result.setArguments(new IASTExpression[] { argList }); + } return result; } @Override - public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments) { + public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, + IASTInitializerClause[] arguments) { return new CPPASTFunctionCallExpression(idExpr, arguments); } @@ -485,19 +490,20 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, - IASTStatement bodyStatement) { + public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, + IASTFunctionDeclarator declarator, IASTStatement bodyStatement) { return new CPPASTFunctionDefinition(declSpecifier, declarator, bodyStatement); } @Override - public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, - IASTStatement bodyStatement) { + public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, + IASTFunctionDeclarator declarator, IASTStatement bodyStatement) { return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement); } @Override - public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) { + public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression( + IASTCompoundStatement compoundStatement) { return new CPPASTCompoundStatementExpression(compoundStatement); } @@ -583,7 +589,7 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTName newName(String name) { + public ICPPASTName newName(String name) { return newName(name.toCharArray()); } @@ -614,7 +620,8 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { @Override @Deprecated - public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId) { + public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, + IASTTypeId typeId) { final ICPPASTNewExpression result = new CPPASTNewExpression(null, null, typeId); result.setNewPlacement(placement); result.setNewInitializer(initializer); @@ -622,7 +629,8 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTNewExpression newNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId) { + public ICPPASTNewExpression newNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, + IASTTypeId typeId) { return new CPPASTNewExpression(placement, initializer, typeId); } @@ -737,13 +745,14 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression( - ICPPASTDeclSpecifier declSpec, IASTInitializer initializer) { + public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec, + IASTInitializer initializer) { return new CPPASTSimpleTypeConstructorExpression(declSpec, initializer); } @Override - public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) { + public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, + IASTTypeId typeId) { return new CPPASTSimpleTypeTemplateParameter(type, name, typeId); } @@ -779,12 +788,14 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue) { + public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, + IASTExpression defaultValue) { return new CPPASTTemplatedTypeTemplateParameter(name, defaultValue); } @Override - public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(int type, IASTName name, IASTExpression defaultValue) { + public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(int type, IASTName name, + IASTExpression defaultValue) { return new CPPASTTemplatedTypeTemplateParameter(type, name, defaultValue); } @@ -846,18 +857,21 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) { + public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, + IASTInitializer initializer) { return new CPPASTTypeIdInitializerExpression(typeId, initializer); } @Override @Deprecated - public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate) { + public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, + IASTExpression expr, boolean isTemplate) { return new CPPASTTypenameExpression(qualifiedName, expr); } @Override - public ICPPASTTypeTransformationSpecifier newTypeTransformationSpecifier(ICPPUnaryTypeTransformation.Operator operator, ICPPASTTypeId operand) { + public ICPPASTTypeTransformationSpecifier newTypeTransformationSpecifier( + ICPPUnaryTypeTransformation.Operator operator, ICPPASTTypeId operand) { return new CPPASTTypeTransformationSpecifier(operator, operand); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 503bed6cd37..3458fe1e5fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -48,11 +48,11 @@ import org.eclipse.core.runtime.PlatformObject; */ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPInternalBinding, ICPPTwoPhaseBinding { - public static class CPPParameterProblem extends ProblemBinding implements ICPPParameter { - public CPPParameterProblem(IASTNode node, int id, char[] arg) { - super(node, id, arg); - } - } + public static class CPPParameterProblem extends ProblemBinding implements ICPPParameter { + public CPPParameterProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); + } + } private IType fType; private IASTName[] fDeclarations; @@ -60,28 +60,28 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI public CPPParameter(IASTName name, int pos) { this.fDeclarations = new IASTName[] { name }; - fPosition= pos; + fPosition = pos; } public CPPParameter(IType type, int pos) { - this.fType = type; - fPosition= pos; + this.fType = type; + fPosition = pos; } - @Override + @Override public boolean isParameterPack() { return getType() instanceof ICPPParameterPackType; } - @Override + @Override public IASTNode[] getDeclarations() { - return fDeclarations; - } + return fDeclarations; + } - @Override + @Override public IASTNode getDefinition() { - return null; - } + return null; + } @Override public void addDeclaration(IASTNode node) { @@ -89,14 +89,14 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI return; IASTName name = (IASTName) node; if (fDeclarations == null || fDeclarations.length == 0) { - fDeclarations = new IASTName[] { name }; + fDeclarations = new IASTName[] { name }; } else { - if (isDeclaredBefore((ASTNode) node, (ASTNode) fDeclarations[0])) { + if (isDeclaredBefore((ASTNode) node, (ASTNode) fDeclarations[0])) { fDeclarations = ArrayUtil.prepend(IASTName.class, fDeclarations, name); } else { fDeclarations = ArrayUtil.append(IASTName.class, fDeclarations, name); } - } + } } private boolean isDeclaredBefore(ASTNode n1, ASTNode n2) { @@ -108,18 +108,18 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI } private IASTName getPrimaryDeclaration() { - if (fDeclarations != null) { - for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) { - IASTNode node = fDeclarations[i].getParent(); - while (!(node instanceof IASTDeclaration)) - node = node.getParent(); - - if (node instanceof IASTFunctionDefinition) - return fDeclarations[i]; - } - return fDeclarations[0]; - } - return null; + if (fDeclarations != null) { + for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) { + IASTNode node = fDeclarations[i].getParent(); + while (!(node instanceof IASTDeclaration)) + node = node.getParent(); + + if (node instanceof IASTFunctionDefinition) + return fDeclarations[i]; + } + return fDeclarations[0]; + } + return null; } @Override @@ -129,10 +129,10 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI @Override public char[] getNameCharArray() { - IASTName name = getPrimaryDeclaration(); - if (name != null) - return name.getSimpleID(); - return CharArrayUtils.EMPTY; + IASTName name = getPrimaryDeclaration(); + if (name != null) + return name.getSimpleID(); + return CharArrayUtils.EMPTY; } @Override @@ -141,62 +141,62 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI } public IASTNode getPhysicalNode() { - if (fDeclarations != null) - return fDeclarations[0]; + if (fDeclarations != null) + return fDeclarations[0]; return null; } @Override public IType getType() { if (fType == null && fDeclarations != null) { - IASTNode parent= fDeclarations[0].getParent(); + IASTNode parent = fDeclarations[0].getParent(); while (parent != null) { if (parent instanceof ICPPASTParameterDeclaration) { - fType= CPPVisitor.createType((ICPPASTParameterDeclaration) parent, false); + fType = CPPVisitor.createType((ICPPASTParameterDeclaration) parent, false); break; } - parent= parent.getParent(); + parent = parent.getParent(); } } return fType; } - @Override + @Override public boolean isStatic() { - return false; - } + return false; + } - @Override + @Override public String[] getQualifiedName() { - return new String[] { getName() }; - } + return new String[] { getName() }; + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return new char[][] { getNameCharArray() }; - } + return new char[][] { getNameCharArray() }; + } - @Override + @Override public boolean isGloballyQualified() { - return false; - } + return false; + } @Override public void addDefinition(IASTNode node) { addDeclaration(node); } - @Override + @Override public boolean isExtern() { - // 7.1.1-5 extern can not be used in the declaration of a parameter - return false; - } + // 7.1.1-5 extern can not be used in the declaration of a parameter + return false; + } - @Override + @Override public boolean isMutable() { - // 7.1.1-8 mutable can only apply to class members - return false; - } + // 7.1.1-8 mutable can only apply to class members + return false; + } @Override public boolean isConstexpr() { @@ -205,15 +205,15 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI @Override public boolean isAuto() { - return hasStorageClass(IASTDeclSpecifier.sc_auto); - } + return hasStorageClass(IASTDeclSpecifier.sc_auto); + } - @Override + @Override public boolean isRegister() { - return hasStorageClass(IASTDeclSpecifier.sc_register); - } + return hasStorageClass(IASTDeclSpecifier.sc_register); + } - public boolean hasStorageClass(int storage) { + public boolean hasStorageClass(int storage) { IASTNode[] ns = getDeclarations(); if (ns == null) return false; @@ -277,15 +277,14 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI @Override public IBinding getOwner() { - IASTFunctionDeclarator decl = - ASTQueries.findAncestorWithType(fDeclarations[0], IASTFunctionDeclarator.class); + IASTFunctionDeclarator decl = ASTQueries.findAncestorWithType(fDeclarations[0], IASTFunctionDeclarator.class); if (decl == null) return null; if (decl.getParent() instanceof ICPPASTLambdaExpression) { CPPClosureType closure = (CPPClosureType) ((ICPPASTLambdaExpression) decl.getParent()).getExpressionType(); return closure.getFunctionCallOperator(); } - IASTName name= decl.getName(); + IASTName name = decl.getName(); return name != null ? name.resolveBinding() : null; } @@ -297,18 +296,18 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI @Override public IBinding resolveFinalBinding(CPPASTNameBase name) { // Check if the binding has been updated. - IBinding current= name.getPreBinding(); + IBinding current = name.getPreBinding(); if (current != this) return current; - IASTNode node= getPrimaryDeclaration(); + IASTNode node = getPrimaryDeclaration(); while (node != null && !(node instanceof IASTFunctionDeclarator)) { - node= node.getParent(); + node = node.getParent(); } if (node instanceof IASTFunctionDeclarator) { - IASTName funcName= ASTQueries.findInnermostDeclarator((IASTFunctionDeclarator) node).getName(); - if (funcName != null) { // will be null for lambda declarator - IBinding b= funcName.resolvePreBinding(); + IASTName funcName = ASTQueries.findInnermostDeclarator((IASTFunctionDeclarator) node).getName(); + if (funcName != null) { // will be null for lambda declarator + IBinding b = funcName.resolvePreBinding(); if (b instanceof ICPPInternalFunction) { return ((ICPPInternalFunction) b).resolveParameter(this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java index 9afe0a7ce63..893795334ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java @@ -25,48 +25,48 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.CoreException; public class CPPParameterPackType implements ICPPParameterPackType, ITypeContainer, ISerializableType { - private IType fType; + private IType fType; - public CPPParameterPackType(IType type) { - setType(type); - } + public CPPParameterPackType(IType type) { + setType(type); + } - @Override + @Override public IType getType() { - return fType; - } + return fType; + } - @Override + @Override public void setType(IType t) { - assert t != null; - fType= t; - } + assert t != null; + fType = t; + } - @Override + @Override public boolean isSameType(IType obj) { - if (obj == this) - return true; - if (obj instanceof ITypedef) - return ((ITypedef) obj).isSameType(this); + if (obj == this) + return true; + if (obj instanceof ITypedef) + return ((ITypedef) obj).isSameType(this); - if (obj instanceof ICPPParameterPackType) { - final ICPPParameterPackType rhs = (ICPPParameterPackType) obj; - IType t1= getType(); - IType t2= rhs.getType(); - return t1 != null && t1.isSameType(t2); - } - return false; - } + if (obj instanceof ICPPParameterPackType) { + final ICPPParameterPackType rhs = (ICPPParameterPackType) obj; + IType t1 = getType(); + IType t2 = rhs.getType(); + return t1 != null && t1.isSameType(t2); + } + return false; + } - @Override + @Override public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen. - return null; - } - } + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen. + return null; + } + } @Override public String toString() { @@ -75,13 +75,13 @@ public class CPPParameterPackType implements ICPPParameterPackType, ITypeContain @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.PACK_EXPANSION_TYPE; + short firstBytes = ITypeMarshalBuffer.PACK_EXPANSION_TYPE; buffer.putShort(firstBytes); buffer.marshalType(getType()); } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); if (nested == null) return new ProblemBinding(null, IProblemBinding.SEMANTIC_INVALID_TYPE); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java index 9b6561e7cee..44d50390f71 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java @@ -32,7 +32,7 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP public CPPParameterSpecialization(ICPPParameter orig, IBinding owner, IType type, IValue defaultValue, ICPPTemplateParameterMap tpmap) { super(orig, owner, tpmap); - fType= type; + fType = type; fDefaultValue = defaultValue; } @@ -55,25 +55,25 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP return false; } - @Override + @Override public boolean isExtern() { - return false; - } + return false; + } - @Override + @Override public boolean isAuto() { - return getParameter().isAuto(); - } + return getParameter().isAuto(); + } - @Override + @Override public boolean isRegister() { - return getParameter().isRegister(); - } + return getParameter().isRegister(); + } - @Override + @Override public boolean isMutable() { - return false; - } + return false; + } @Override public boolean isConstexpr() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPlaceholderType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPlaceholderType.java index 086402a6500..2753996d305 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPlaceholderType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPlaceholderType.java @@ -18,24 +18,23 @@ import org.eclipse.core.runtime.CoreException; /** * Represents an occurrence of 'auto' or 'decltype(auto)' that has * not been resolved (replaced with a real type) because the information - * necessary to resolve it (the function's body) is not available yet. + * necessary to resolve it (the function's body) is not available yet. */ public class CPPPlaceholderType implements ISerializableType, IType { public enum PlaceholderKind { - Auto, - DecltypeAuto + Auto, DecltypeAuto } - + private final PlaceholderKind fPlaceholderKind; - + public CPPPlaceholderType(PlaceholderKind placeholderKind) { fPlaceholderKind = placeholderKind; } - + public PlaceholderKind getPlaceholderKind() { return fPlaceholderKind; } - + @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { short firstBytes = ITypeMarshalBuffer.PLACEHOLDER_TYPE; @@ -52,22 +51,21 @@ public class CPPPlaceholderType implements ISerializableType, IType { } return false; } - - @Override + + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // not going to happen + } + return t; + } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) { - PlaceholderKind kind = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0 - ? PlaceholderKind.DecltypeAuto - : PlaceholderKind.Auto; + PlaceholderKind kind = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0 ? PlaceholderKind.DecltypeAuto + : PlaceholderKind.Auto; return new CPPPlaceholderType(kind); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java index 4b5ff2c8b90..5d56d1e3194 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java @@ -32,7 +32,7 @@ import org.eclipse.core.runtime.CoreException; */ public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointerToMemberType { private ICPPASTPointerToMember operator; - private IType classType; // Can be either ICPPClassType or ICPPTemplateTypeParameter + private IType classType; // Can be either ICPPClassType or ICPPTemplateTypeParameter /** * @param type @@ -51,29 +51,29 @@ public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointe @Override public boolean isSameType(IType o) { - if (o == this) - return true; - if (o instanceof ITypedef) - return o.isSameType(this); + if (o == this) + return true; + if (o instanceof ITypedef) + return o.isSameType(this); - if (!(o instanceof ICPPPointerToMemberType)) - return false; + if (!(o instanceof ICPPPointerToMemberType)) + return false; - if (!super.isSameType(o)) - return false; + if (!super.isSameType(o)) + return false; - ICPPPointerToMemberType pt = (ICPPPointerToMemberType) o; - IType cls = pt.getMemberOfClass(); - if (cls != null) - return cls.isSameType(getMemberOfClass()); - return false; + ICPPPointerToMemberType pt = (ICPPPointerToMemberType) o; + IType cls = pt.getMemberOfClass(); + if (cls != null) + return cls.isSameType(getMemberOfClass()); + return false; } @Override public IType getMemberOfClass() { if (classType == null) { ICPPASTNameSpecifier nameSpec; - IBinding binding= null; + IBinding binding = null; ICPPASTPointerToMember pm = operator; if (pm == null) { nameSpec = new CPPASTName(); @@ -102,20 +102,22 @@ public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointe @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.POINTER_TO_MEMBER_TYPE; - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + short firstBytes = ITypeMarshalBuffer.POINTER_TO_MEMBER_TYPE; + if (isConst()) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) + firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) + firstBytes |= ITypeMarshalBuffer.FLAG3; buffer.putShort(firstBytes); buffer.marshalType(getType()); buffer.marshalType(getMemberOfClass()); } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); - IType memberOf= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); + IType memberOf = buffer.unmarshalType(); return new CPPPointerToMemberType(nested, memberOf, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, - (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, - (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java index 4058ba2dea1..f1021f28efa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java @@ -46,30 +46,30 @@ public class CPPPointerType implements IPointerType, ITypeContainer, ISerializab } public CPPPointerType(IType type) { - this(type, false, false, false); + this(type, false, false, false); } @Override public boolean isSameType(IType o) { - if (o == this) - return true; - if (o instanceof ITypedef) - return o.isSameType(this); + if (o == this) + return true; + if (o instanceof ITypedef) + return o.isSameType(this); - if (!(o instanceof IPointerType)) - return false; + if (!(o instanceof IPointerType)) + return false; - if (this instanceof ICPPPointerToMemberType != o instanceof ICPPPointerToMemberType) - return false; + if (this instanceof ICPPPointerToMemberType != o instanceof ICPPPointerToMemberType) + return false; - if (type == null) - return false; + if (type == null) + return false; - IPointerType pt = (IPointerType) o; - if (isConst == pt.isConst() && isVolatile == pt.isVolatile() && isRestrict == pt.isRestrict()) { + IPointerType pt = (IPointerType) o; + if (isConst == pt.isConst() && isVolatile == pt.isVolatile() && isRestrict == pt.isRestrict()) { return type.isSameType(pt.getType()); - } - return false; + } + return false; } @Override @@ -80,7 +80,7 @@ public class CPPPointerType implements IPointerType, ITypeContainer, ISerializab @Override public void setType(IType t) { assert t != null; - type = t; + type = t; } @Override @@ -98,33 +98,35 @@ public class CPPPointerType implements IPointerType, ITypeContainer, ISerializab return isRestrict; } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.POINTER_TYPE; - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + short firstBytes = ITypeMarshalBuffer.POINTER_TYPE; + if (isConst()) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) + firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) + firstBytes |= ITypeMarshalBuffer.FLAG3; buffer.putShort(firstBytes); final IType nestedType = getType(); buffer.marshalType(nestedType); } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); return new CPPPointerType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, - (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, - (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java index 36e4ecb29e6..6a2eb7e0e7a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java @@ -24,17 +24,17 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.core.runtime.CoreException; public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerializableType { - private final boolean isConst; - private final boolean isVolatile; - private IType type; + private final boolean isConst; + private final boolean isVolatile; + private IType type; - public CPPQualifierType(IType type, boolean isConst, boolean isVolatile) { - this.isConst = isConst; - this.isVolatile = isVolatile; - setType(type); - } + public CPPQualifierType(IType type, boolean isConst, boolean isVolatile) { + this.isConst = isConst; + this.isVolatile = isVolatile; + setType(type); + } - @Override + @Override public boolean isSameType(IType o) { if (o instanceof ITypedef) return o.isSameType(this); @@ -47,37 +47,37 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerial return false; } - @Override + @Override public boolean isConst() { - return isConst; - } + return isConst; + } - @Override + @Override public boolean isVolatile() { - return isVolatile; - } + return isVolatile; + } - @Override + @Override public IType getType() { - return type; - } + return type; + } - @Override + @Override public void setType(IType t) { - assert t != null; - type = t; - } + assert t != null; + type = t; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return t; + } @Override public String toString() { @@ -86,15 +86,17 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerial @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.CVQUALIFIER_TYPE; - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + short firstBytes = ITypeMarshalBuffer.CVQUALIFIER_TYPE; + if (isConst()) + firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) + firstBytes |= ITypeMarshalBuffer.FLAG2; buffer.putShort(firstBytes); buffer.marshalType(getType()); } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); return new CPPQualifierType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, (firstBytes & ITypeMarshalBuffer.FLAG2) != 0); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java index b76a9b6c27e..a5b469d3f03 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java @@ -24,86 +24,86 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.core.runtime.CoreException; public class CPPReferenceType implements ICPPReferenceType, ITypeContainer, ISerializableType { - private IType fType = null; - private boolean fIsRValue; + private IType fType = null; + private boolean fIsRValue; - public CPPReferenceType(IType type, boolean isRValue) { - fIsRValue= isRValue; - setType(type); - } + public CPPReferenceType(IType type, boolean isRValue) { + fIsRValue = isRValue; + setType(type); + } - @Override + @Override public IType getType() { - return fType; - } + return fType; + } @Override public boolean isRValueReference() { return fIsRValue; } - @Override + @Override public void setType(IType t) { - if (t instanceof ICPPReferenceType) { - final ICPPReferenceType rt = (ICPPReferenceType) t; + if (t instanceof ICPPReferenceType) { + final ICPPReferenceType rt = (ICPPReferenceType) t; fIsRValue = fIsRValue && rt.isRValueReference(); - t= rt.getType(); - } - assert t != null; - fType= t; - } + t = rt.getType(); + } + assert t != null; + fType = t; + } - @Override + @Override public boolean isSameType(IType obj) { - if (obj == this) - return true; - if (obj instanceof ITypedef) - return ((ITypedef) obj).isSameType(this); + if (obj == this) + return true; + if (obj instanceof ITypedef) + return ((ITypedef) obj).isSameType(this); - if (obj instanceof ICPPReferenceType) { - final ICPPReferenceType rhs = (ICPPReferenceType) obj; - IType t1= getType(); - IType t2= rhs.getType(); - boolean rv1= isRValueReference(); - boolean rv2= rhs.isRValueReference(); - for (;;) { - if (t1 instanceof ITypedef) { - t1= ((ITypedef) t1).getType(); - } else if (t1 instanceof ICPPReferenceType) { - rv1= rv1 && ((ICPPReferenceType) t1).isRValueReference(); - t1= ((ICPPReferenceType) t1).getType(); - } else { - break; - } - } - for (;;) { - if (t2 instanceof ITypedef) { - t2= ((ITypedef) t2).getType(); - } else if (t2 instanceof ICPPReferenceType) { - rv2= rv2 && ((ICPPReferenceType) t2).isRValueReference(); - t2= ((ICPPReferenceType) t2).getType(); - } else { - break; - } - } - if (t1 == null) - return false; + if (obj instanceof ICPPReferenceType) { + final ICPPReferenceType rhs = (ICPPReferenceType) obj; + IType t1 = getType(); + IType t2 = rhs.getType(); + boolean rv1 = isRValueReference(); + boolean rv2 = rhs.isRValueReference(); + for (;;) { + if (t1 instanceof ITypedef) { + t1 = ((ITypedef) t1).getType(); + } else if (t1 instanceof ICPPReferenceType) { + rv1 = rv1 && ((ICPPReferenceType) t1).isRValueReference(); + t1 = ((ICPPReferenceType) t1).getType(); + } else { + break; + } + } + for (;;) { + if (t2 instanceof ITypedef) { + t2 = ((ITypedef) t2).getType(); + } else if (t2 instanceof ICPPReferenceType) { + rv2 = rv2 && ((ICPPReferenceType) t2).isRValueReference(); + t2 = ((ICPPReferenceType) t2).getType(); + } else { + break; + } + } + if (t1 == null) + return false; return rv1 == rv2 && t1.isSameType(t2); - } - return false; - } + } + return false; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // not going to happen - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // not going to happen + } + return t; + } @Override public String toString() { @@ -112,7 +112,7 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer, ISer @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.REFERENCE_TYPE; + short firstBytes = ITypeMarshalBuffer.REFERENCE_TYPE; if (isRValueReference()) { firstBytes |= ITypeMarshalBuffer.FLAG1; } @@ -121,7 +121,7 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer, ISer } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType nested= buffer.unmarshalType(); + IType nested = buffer.unmarshalType(); return new CPPReferenceType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index 80fe63fd0b0..6c101654a53 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -62,20 +62,20 @@ abstract public class CPPScope implements ICPPASTInternalScope { private static final IProgressMonitor NPM = new NullProgressMonitor(); private static final ICPPNamespace UNINITIALIZED = new CPPNamespace.CPPNamespaceProblem(null, 0, null); - private final IASTNode physicalNode; + private final IASTNode physicalNode; private boolean isCached = false; protected CharArrayObjectMap<Object> bindings; - private ICPPNamespace fIndexNamespace= UNINITIALIZED; + private ICPPNamespace fIndexNamespace = UNINITIALIZED; public static class CPPScopeProblem extends ProblemBinding implements ICPPScope { - public CPPScopeProblem(IASTNode node, int id, char[] arg) { - super(node, id, arg); - } + public CPPScopeProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); + } - public CPPScopeProblem(IASTName name, int id) { - super(name, id); - } - } + public CPPScopeProblem(IASTName name, int id) { + super(name, id); + } + } public CPPScope(IASTNode physicalNode) { this.physicalNode = physicalNode; @@ -98,30 +98,29 @@ abstract public class CPPScope implements ICPPASTInternalScope { if (!name.isActive()) return; - if (name instanceof ICPPASTQualifiedName && - !(physicalNode instanceof ICPPASTCompositeTypeSpecifier) && - !(physicalNode instanceof ICPPASTNamespaceDefinition)) { + if (name instanceof ICPPASTQualifiedName && !(physicalNode instanceof ICPPASTCompositeTypeSpecifier) + && !(physicalNode instanceof ICPPASTNamespaceDefinition)) { return; } if (bindings == null) bindings = new CharArrayObjectMap<>(1); - final char[] c= name.getLookupKey(); + final char[] c = name.getLookupKey(); if (c.length == 0) return; Object o = bindings.get(c); if (o != null) { - if (o instanceof ObjectSet) { - ((ObjectSet<Object>) o).put(name); - } else { - ObjectSet<Object> temp = new ObjectSet<>(2); - temp.put(o); - temp.put(name); - bindings.put(c, temp); - } + if (o instanceof ObjectSet) { + ((ObjectSet<Object>) o).put(name); + } else { + ObjectSet<Object> temp = new ObjectSet<>(2); + temp.put(o); + temp.put(name); + bindings.put(c, temp); + } } else { - bindings.put(c, name); + bindings.put(c, name); } } @@ -129,8 +128,8 @@ abstract public class CPPScope implements ICPPASTInternalScope { public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) { final ScopeLookupData lookup = new ScopeLookupData(name, forceResolve, false); lookup.setIgnorePointOfDeclaration(true); - IBinding[] bs= getBindingsInAST(lookup); - IBinding binding= CPPSemantics.resolveAmbiguities(name, bs); + IBinding[] bs = getBindingsInAST(lookup); + IBinding binding = CPPSemantics.resolveAmbiguities(name, bs); if (binding == null && forceResolve) { final IASTTranslationUnit tu = name.getTranslationUnit(); IIndex index = tu == null ? null : tu.getIndex(); @@ -139,21 +138,21 @@ abstract public class CPPScope implements ICPPASTInternalScope { // Try looking this up in the index. if (physicalNode instanceof IASTTranslationUnit) { try { - IBinding[] bindings= index.findBindings(nchars, + IBinding[] bindings = index.findBindings(nchars, IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, NPM); if (fileSet != null) { - bindings= fileSet.filterFileLocalBindings(bindings); + bindings = fileSet.filterFileLocalBindings(bindings); + } + binding = CPPSemantics.resolveAmbiguities(name, bindings); + if (binding instanceof ICPPUsingDeclaration) { + binding = CPPSemantics.resolveAmbiguities(name, + ((ICPPUsingDeclaration) binding).getDelegates()); } - binding= CPPSemantics.resolveAmbiguities(name, bindings); - if (binding instanceof ICPPUsingDeclaration) { - binding= CPPSemantics.resolveAmbiguities(name, - ((ICPPUsingDeclaration) binding).getDelegates()); - } } catch (CoreException e) { - CCorePlugin.log(e); + CCorePlugin.log(e); } } else { - ICPPNamespace nsbinding= getNamespaceIndexBinding(index); + ICPPNamespace nsbinding = getNamespaceIndexBinding(index); if (nsbinding != null) { return nsbinding.getNamespaceScope().getBinding(name, forceResolve, fileSet); } @@ -165,13 +164,13 @@ abstract public class CPPScope implements ICPPASTInternalScope { protected ICPPNamespace getNamespaceIndexBinding(IIndex index) { if (fIndexNamespace == UNINITIALIZED) { - fIndexNamespace= null; - IASTNode node= getPhysicalNode(); + fIndexNamespace = null; + IASTNode node = getPhysicalNode(); if (node instanceof ICPPASTNamespaceDefinition) { IASTName nsname = ((ICPPASTNamespaceDefinition) node).getName(); - IBinding nsbinding= nsname.resolveBinding(); + IBinding nsbinding = nsname.resolveBinding(); if (nsbinding != null) { - fIndexNamespace= (ICPPNamespace) index.adaptBinding(nsbinding); + fIndexNamespace = (ICPPNamespace) index.adaptBinding(nsbinding); } } } @@ -194,16 +193,16 @@ abstract public class CPPScope implements ICPPASTInternalScope { if (tu != null) { IIndex index = tu.getIndex(); if (index != null) { - IIndexFileSet fileSet= lookup.getIncludedFiles(); + IIndexFileSet fileSet = lookup.getIncludedFiles(); if (physicalNode instanceof IASTTranslationUnit) { try { IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE; final char[] nchars = lookup.getLookupKey(); - IBinding[] bindings = lookup.isPrefixLookup() ? - index.findBindingsForContentAssist(nchars, true, filter, null) : - index.findBindings(nchars, filter, null); + IBinding[] bindings = lookup.isPrefixLookup() + ? index.findBindingsForContentAssist(nchars, true, filter, null) + : index.findBindings(nchars, filter, null); if (fileSet != null) { - bindings= fileSet.filterFileLocalBindings(bindings); + bindings = fileSet.filterFileLocalBindings(bindings); } result = ArrayUtil.addAll(IBinding.class, result, bindings); } catch (CoreException e) { @@ -217,8 +216,8 @@ abstract public class CPPScope implements ICPPASTInternalScope { ICPPNamespaceScope indexNs = ((ICPPNamespace) binding).getNamespaceScope(); IBinding[] bindings = indexNs.getBindings(lookup); for (IBinding candidate : bindings) { - if (lookup.isPrefixLookup() || - CPPSemantics.declaredBefore(candidate, lookup.getLookupPoint(), true)) { + if (lookup.isPrefixLookup() + || CPPSemantics.declaredBefore(candidate, lookup.getLookupPoint(), true)) { result = ArrayUtil.append(result, candidate); } } @@ -232,56 +231,56 @@ abstract public class CPPScope implements ICPPASTInternalScope { return ArrayUtil.trim(IBinding.class, result); } - + protected boolean nameIsVisibleToLookup(ScopeLookupData lookup) { return true; } public IBinding[] getBindingsInAST(ScopeLookupData lookup) { populateCache(); - final char[] c = lookup.getLookupKey(); - IBinding[] result = IBinding.EMPTY_BINDING_ARRAY; - if (!nameIsVisibleToLookup(lookup)) { - return result; - } - - Object obj = null; - if (lookup.isPrefixLookup()) { - char[][] keys = bindings != null ? bindings.keys() : CharArrayUtils.EMPTY_ARRAY_OF_CHAR_ARRAYS; - ObjectSet<Object> all= new ObjectSet<>(16); - IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(c); - for (char[] key : keys) { + final char[] c = lookup.getLookupKey(); + IBinding[] result = IBinding.EMPTY_BINDING_ARRAY; + if (!nameIsVisibleToLookup(lookup)) { + return result; + } + + Object obj = null; + if (lookup.isPrefixLookup()) { + char[][] keys = bindings != null ? bindings.keys() : CharArrayUtils.EMPTY_ARRAY_OF_CHAR_ARRAYS; + ObjectSet<Object> all = new ObjectSet<>(16); + IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(c); + for (char[] key : keys) { if (key != CONSTRUCTOR_KEY && matcher.match(key)) { - obj= bindings.get(key); - if (obj instanceof ObjectSet<?>) { - all.addAll((ObjectSet<?>) obj); - } else if (obj != null) { - all.put(obj); - } - } - } - obj= all; - } else { - obj = bindings != null ? bindings.get(c) : null; - } - - if (obj != null) { - if (obj instanceof ObjectSet<?>) { - ObjectSet<?> os= (ObjectSet<?>) obj; - for (int j = 0; j < os.size(); j++) { - result= addCandidate(os.keyAt(j), lookup, result); - } - } else { - result = addCandidate(obj, lookup, result); - } - } - return ArrayUtil.trim(result); + obj = bindings.get(key); + if (obj instanceof ObjectSet<?>) { + all.addAll((ObjectSet<?>) obj); + } else if (obj != null) { + all.put(obj); + } + } + } + obj = all; + } else { + obj = bindings != null ? bindings.get(c) : null; + } + + if (obj != null) { + if (obj instanceof ObjectSet<?>) { + ObjectSet<?> os = (ObjectSet<?>) obj; + for (int j = 0; j < os.size(); j++) { + result = addCandidate(os.keyAt(j), lookup, result); + } + } else { + result = addCandidate(obj, lookup, result); + } + } + return ArrayUtil.trim(result); } private boolean isInsideClassScope(IScope scope) { try { return scope instanceof ICPPClassScope - || (scope instanceof ICPPEnumScope && scope.getParent() instanceof ICPPClassScope); + || (scope instanceof ICPPEnumScope && scope.getParent() instanceof ICPPClassScope); } catch (DOMException e) { return false; } @@ -290,7 +289,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { private IBinding[] addCandidate(Object candidate, ScopeLookupData lookup, IBinding[] result) { final IASTNode point = lookup.getLookupPoint(); if (!lookup.isIgnorePointOfDeclaration()) { - IASTTranslationUnit tu= point.getTranslationUnit(); + IASTTranslationUnit tu = point.getTranslationUnit(); if (!CPPSemantics.declaredBefore(candidate, point, tu != null && tu.getIndex() != null)) { if (!isInsideClassScope(this) || !LookupData.checkWholeClassScope(lookup.getLookupName())) return result; @@ -299,19 +298,19 @@ abstract public class CPPScope implements ICPPASTInternalScope { IBinding binding; if (candidate instanceof IASTName) { - final IASTName candName= (IASTName) candidate; - IASTName simpleName= candName.getLastName(); + final IASTName candName = (IASTName) candidate; + IASTName simpleName = candName.getLastName(); if (simpleName instanceof ICPPASTTemplateId) { - simpleName= ((ICPPASTTemplateId) simpleName).getTemplateName(); + simpleName = ((ICPPASTTemplateId) simpleName).getTemplateName(); } if (lookup.isResolve() && candName != point && simpleName != point) { - candName.resolvePreBinding(); // Make sure to resolve the template-id + candName.resolvePreBinding(); // Make sure to resolve the template-id binding = simpleName.resolvePreBinding(); } else { binding = simpleName.getPreBinding(); } } else { - binding= (IBinding) candidate; + binding = (IBinding) candidate; } if (binding != null) @@ -322,7 +321,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { @Override public final void populateCache() { if (!isCached) { - isCached= true; // set to true before doing the work, to avoid recursion + isCached = true; // set to true before doing the work, to avoid recursion CPPSemantics.populateCache(this); } } @@ -336,7 +335,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { private void removeFromMap(CharArrayObjectMap<Object> map, IASTNode container) { for (int i = 0; i < map.size(); i++) { - Object o= map.getAt(i); + Object o = map.getAt(i); if (o instanceof IASTName) { if (container.contains((IASTNode) o)) { final char[] key = map.keyAt(i); @@ -353,7 +352,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { private void removeFromSet(ObjectSet<Object> set, IASTNode container) { for (int i = 0; i < set.size(); i++) { - Object o= set.keyAt(i); + Object o = set.keyAt(i); if (o instanceof IASTName) { if (container.contains((IASTNode) o)) { set.remove(o); @@ -365,37 +364,37 @@ abstract public class CPPScope implements ICPPASTInternalScope { @Override public IBinding[] find(String name, IASTTranslationUnit tu) { - return find(name); + return find(name); } @Override public IBinding[] find(String name) { - return CPPSemantics.findBindings(this, name, false); + return CPPSemantics.findBindings(this, name, false); } @Override @SuppressWarnings({ "unchecked" }) - public void addBinding(IBinding binding) { - if (bindings == null) - bindings = new CharArrayObjectMap<>(1); - char[] c = binding.getNameCharArray(); - if (c.length == 0) { - return; - } - Object o = bindings.get(c); - if (o != null) { - if (o instanceof ObjectSet) { - ((ObjectSet<Object>) o).put(binding); - } else { - ObjectSet<Object> set = new ObjectSet<>(2); - set.put(o); - set.put(binding); - bindings.put(c, set); - } - } else { - bindings.put(c, binding); - } - } + public void addBinding(IBinding binding) { + if (bindings == null) + bindings = new CharArrayObjectMap<>(1); + char[] c = binding.getNameCharArray(); + if (c.length == 0) { + return; + } + Object o = bindings.get(c); + if (o != null) { + if (o instanceof ObjectSet) { + ((ObjectSet<Object>) o).put(binding); + } else { + ObjectSet<Object> set = new ObjectSet<>(2); + set.put(o); + set.put(binding); + bindings.put(c, set); + } + } else { + bindings.put(c, binding); + } + } @Override public final IBinding getBinding(IASTName name, boolean resolve) { @@ -415,7 +414,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { @Override public String toString() { IName name = getScopeName(); - final String n= name != null ? name.toString() : "<unnamed scope>"; //$NON-NLS-1$ + final String n = name != null ? name.toString() : "<unnamed scope>"; //$NON-NLS-1$ return getKind().toString() + ' ' + n + ' ' + '(' + super.toString() + ')'; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java index 9c078dd1b61..947cb7c687b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java @@ -62,8 +62,8 @@ public class CPPScopeMapper { private final ICPPInternalNamespaceScope fNominated; public InlineNamespaceDirective(ICPPInternalNamespaceScope container, ICPPInternalNamespaceScope inline) { - fContainer= container; - fNominated= inline; + fContainer = container; + fNominated = inline; } @Override @@ -91,7 +91,7 @@ public class CPPScopeMapper { private ICPPNamespaceScope[] fEnclosingNamespaceSet; public NamespaceScopeWrapper(ICPPNamespaceScope scope) { - fScope= scope; + fScope = scope; assert fScope instanceof IIndexScope; } @@ -105,7 +105,8 @@ public class CPPScopeMapper { return fScope.find(name, tu); } - @Override @Deprecated + @Override + @Deprecated public IBinding[] find(String name) { return fScope.find(name); } @@ -120,13 +121,16 @@ public class CPPScopeMapper { return fScope.getBinding(name, resolve, acceptLocalBindings); } - @Override @Deprecated + @Override + @Deprecated public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) { return fScope.getBindings(name, resolve, prefixLookup); } - @Override @Deprecated - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) { + @Override + @Deprecated + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, + IIndexFileSet acceptLocalBindings) { return getBindings(name, resolve, prefixLookup, acceptLocalBindings); } @@ -137,7 +141,7 @@ public class CPPScopeMapper { @Override public IScope getParent() throws DOMException { - IScope parent= fScope.getParent(); + IScope parent = fScope.getParent(); if (parent instanceof IIndexScope) { return mapToASTScope((IIndexScope) parent); } @@ -157,9 +161,9 @@ public class CPPScopeMapper { private void initUsingDirectives() { if (fUsingDirectives == null) { - fUsingDirectives= new ArrayList<>(1); + fUsingDirectives = new ArrayList<>(1); // Insert a using directive for every inline namespace - for (ICPPInternalNamespaceScope inline: getInlineNamespaces()) { + for (ICPPInternalNamespaceScope inline : getInlineNamespaces()) { fUsingDirectives.add(new InlineNamespaceDirective(this, inline)); } } @@ -174,7 +178,7 @@ public class CPPScopeMapper { @Override public ICPPNamespaceScope[] getEnclosingNamespaceSet() { if (fEnclosingNamespaceSet == null) - return fEnclosingNamespaceSet= CPPNamespaceScope.computeEnclosingNamespaceSet(this); + return fEnclosingNamespaceSet = CPPNamespaceScope.computeEnclosingNamespaceSet(this); return fEnclosingNamespaceSet; } @@ -194,9 +198,9 @@ public class CPPScopeMapper { ICPPNamespaceScope[] pre = fScope.getInlineNamespaces(); if (pre.length == 0) return ICPPInternalNamespaceScope.EMPTY_NAMESPACE_SCOPE_ARRAY; - ICPPInternalNamespaceScope[] result= new ICPPInternalNamespaceScope[pre.length]; + ICPPInternalNamespaceScope[] result = new ICPPInternalNamespaceScope[pre.length]; for (int i = 0; i < result.length; i++) { - result[i]= (ICPPInternalNamespaceScope) mapToASTScope((IIndexScope) pre[i]); + result[i] = (ICPPInternalNamespaceScope) mapToASTScope((IIndexScope) pre[i]); } return result; } @@ -215,13 +219,13 @@ public class CPPScopeMapper { private final ICPPUsingDirective fDirective; public UsingDirectiveWrapper(int offset, ICPPUsingDirective ud) { - fOffset= offset; - fDirective= ud; + fOffset = offset; + fDirective = ud; } @Override public IScope getContainingScope() { - final IScope scope= fDirective.getContainingScope(); + final IScope scope = fDirective.getContainingScope(); if (scope == null) { return fTu.getScope(); } @@ -261,32 +265,30 @@ public class CPPScopeMapper { final IASTName name = cts.getName(); final char[] nameChars = name.getLookupKey(); if (nameChars.length > 0) { - IASTName[] names= fClasses.get(nameChars); - names= ArrayUtil.append(IASTName.class, names, name); + IASTName[] names = fClasses.get(nameChars); + names = ArrayUtil.append(IASTName.class, names, name); fClasses.put(nameChars, names); } return PROCESS_CONTINUE; } return PROCESS_SKIP; - } else if (declaration instanceof IASTASMDeclaration - || declaration instanceof IASTFunctionDefinition) { + } else if (declaration instanceof IASTASMDeclaration || declaration instanceof IASTFunctionDefinition) { return PROCESS_SKIP; } return PROCESS_CONTINUE; } } - private final HashMap<IIndexScope, IScope> fMappedScopes= new HashMap<>(); - private final HashMap<String, NamespaceScopeWrapper> fNamespaceWrappers= new HashMap<>(); - private final Map<String, List<UsingDirectiveWrapper>> fPerName= new HashMap<>(); + private final HashMap<IIndexScope, IScope> fMappedScopes = new HashMap<>(); + private final HashMap<String, NamespaceScopeWrapper> fNamespaceWrappers = new HashMap<>(); + private final Map<String, List<UsingDirectiveWrapper>> fPerName = new HashMap<>(); private final CPPASTTranslationUnit fTu; protected CharArrayMap<IASTName[]> fClasses; - - private final Map<ICPPClassTemplatePartialSpecialization, ICPPClassTemplatePartialSpecialization> - fPartialSpecs = new HashMap<>(); + + private final Map<ICPPClassTemplatePartialSpecialization, ICPPClassTemplatePartialSpecialization> fPartialSpecs = new HashMap<>(); public CPPScopeMapper(CPPASTTranslationUnit tu) { - fTu= tu; + fTu = tu; } /** @@ -297,12 +299,12 @@ public class CPPScopeMapper { public void registerAdditionalDirectives(int offset, List<ICPPUsingDirective> usingDirectives) { if (!usingDirectives.isEmpty()) { for (ICPPUsingDirective ud : usingDirectives) { - IScope container= ud.getContainingScope(); + IScope container = ud.getContainingScope(); try { - final String name= getReverseQualifiedName(container); - List<UsingDirectiveWrapper> list= fPerName.get(name); + final String name = getReverseQualifiedName(container); + List<UsingDirectiveWrapper> list = fPerName.get(name); if (list == null) { - list= new LinkedList<UsingDirectiveWrapper>(); + list = new LinkedList<UsingDirectiveWrapper>(); fPerName.put(name, list); } list.add(new UsingDirectiveWrapper(offset, ud)); @@ -322,7 +324,7 @@ public class CPPScopeMapper { } try { String qname = getReverseQualifiedName(scope); - List<UsingDirectiveWrapper> candidates= fPerName.remove(qname); + List<UsingDirectiveWrapper> candidates = fPerName.remove(qname); if (candidates != null) { for (UsingDirectiveWrapper ud : candidates) { scope.addUsingDirective(ud); @@ -335,21 +337,21 @@ public class CPPScopeMapper { private String getReverseQualifiedName(IScope scope) throws DOMException { final CPPNamespaceScope tuscope = fTu.getScope(); if (scope == tuscope || scope == null || scope.getKind() == EScopeKind.eGlobal) { - return ""; //$NON-NLS-1$ + return ""; //$NON-NLS-1$ } - StringBuilder buf= new StringBuilder(); + StringBuilder buf = new StringBuilder(); IName scopeName = scope.getScopeName(); if (scopeName != null) { buf.append(scopeName.getSimpleID()); } - scope= scope.getParent(); + scope = scope.getParent(); while (scope.getKind() != EScopeKind.eGlobal && scope != tuscope) { buf.append(':'); - scopeName= scope.getScopeName(); + scopeName = scope.getScopeName(); if (scopeName != null) { buf.append(scope.getScopeName().getSimpleID()); } - scope= scope.getParent(); + scope = scope.getParent(); } return buf.toString(); } @@ -362,11 +364,11 @@ public class CPPScopeMapper { return fTu.getScope(); } if (scope instanceof ICPPNamespaceScope) { - IScope result= fMappedScopes.get(scope); + IScope result = fMappedScopes.get(scope); if (result == null) { - result= fTu.getScope().findNamespaceScope(scope); + result = fTu.getScope().findNamespaceScope(scope); if (result == null) { - result= wrapNamespaceScope((ICPPNamespaceScope) scope); + result = wrapNamespaceScope((ICPPNamespaceScope) scope); } fMappedScopes.put(scope, result); } @@ -377,24 +379,24 @@ public class CPPScopeMapper { private IScope wrapNamespaceScope(ICPPNamespaceScope scope) { try { - String rqname= getReverseQualifiedName(scope); - NamespaceScopeWrapper result= fNamespaceWrappers.get(rqname); + String rqname = getReverseQualifiedName(scope); + NamespaceScopeWrapper result = fNamespaceWrappers.get(rqname); if (result == null) { - result= new NamespaceScopeWrapper(getCompositeNamespaceScope(scope)); + result = new NamespaceScopeWrapper(getCompositeNamespaceScope(scope)); fNamespaceWrappers.put(rqname, result); } return result; } catch (DOMException e) { - assert false; // index scopes don't throw dom-exceptions + assert false; // index scopes don't throw dom-exceptions return null; } } private ICPPNamespaceScope getCompositeNamespaceScope(ICPPNamespaceScope scope) throws DOMException { if (scope instanceof IIndexScope) { - IIndexBinding binding= fTu.getIndex().adaptBinding(((IIndexScope) scope).getScopeBinding()); + IIndexBinding binding = fTu.getIndex().adaptBinding(((IIndexScope) scope).getScopeBinding()); if (binding instanceof ICPPNamespace) { - scope= ((ICPPNamespace) binding).getNamespaceScope(); + scope = ((ICPPNamespace) binding).getNamespaceScope(); } } return scope; @@ -402,12 +404,12 @@ public class CPPScopeMapper { public ICPPClassType mapToAST(ICPPClassType type) { if (type instanceof ICPPTemplateInstance) { - ICPPTemplateInstance inst= (ICPPTemplateInstance) type; - ICPPTemplateDefinition template= inst.getTemplateDefinition(); + ICPPTemplateInstance inst = (ICPPTemplateInstance) type; + ICPPTemplateDefinition template = inst.getTemplateDefinition(); if (template instanceof IIndexBinding && template instanceof ICPPClassType) { - IBinding mapped= mapToAST((ICPPClassType) template); + IBinding mapped = mapToAST((ICPPClassType) template); if (mapped != template && mapped instanceof ICPPClassType) { - mapped= CPPTemplates.instantiate((ICPPClassTemplate) mapped, inst.getTemplateArguments()); + mapped = CPPTemplates.instantiate((ICPPClassTemplate) mapped, inst.getTemplateArguments()); if (mapped instanceof ICPPClassType) return (ICPPClassType) mapped; } @@ -416,15 +418,15 @@ public class CPPScopeMapper { } if (fClasses == null) { - fClasses= new CharArrayMap<>(); + fClasses = new CharArrayMap<>(); fTu.accept(new Visitor()); } - IASTName[] names= fClasses.get(type.getNameCharArray()); + IASTName[] names = fClasses.get(type.getNameCharArray()); if (names != null) { for (IASTName name : names) { if (name == null) break; - IBinding b= name.resolveBinding(); + IBinding b = name.resolveBinding(); if (b instanceof ICPPClassType) { final ICPPClassType mapped = (ICPPClassType) b; if (mapped.isSameType(type)) { @@ -440,7 +442,7 @@ public class CPPScopeMapper { ICPPClassTemplatePartialSpecialization astSpec) { fPartialSpecs.put(indexSpec, astSpec); } - + public ICPPClassTemplatePartialSpecialization mapToAST(ICPPClassTemplatePartialSpecialization indexSpec) { ICPPClassTemplatePartialSpecialization astSpec = fPartialSpecs.get(indexSpec); if (astSpec != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java index 35f6b389fbe..2365031d242 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java @@ -72,16 +72,15 @@ public abstract class CPPSpecialization extends PlatformObject implements ICPPSp @Override public void addDeclaration(IASTNode node) { if (declarations == null) { - declarations = new IASTNode[] { node }; + declarations = new IASTNode[] { node }; } else { - // Keep the lowest offset declaration in [0] - if (declarations.length > 0 && - ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { + // Keep the lowest offset declaration in [0] + if (declarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { declarations = ArrayUtil.prepend(IASTNode.class, declarations, node); } else { declarations = ArrayUtil.append(IASTNode.class, declarations, node); } - } + } } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index 8feeb1bb506..0b8cae1ea2c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -48,7 +48,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; -public abstract class CPPTemplateDefinition extends PlatformObject implements ICPPTemplateDefinition, ICPPInternalTemplate { +public abstract class CPPTemplateDefinition extends PlatformObject + implements ICPPTemplateDefinition, ICPPInternalTemplate { public static final class CPPTemplateProblem extends ProblemBinding implements ICPPTemplateDefinition { public CPPTemplateProblem(IASTNode node, int id, char[] arg) { super(node, id, arg); @@ -69,7 +70,6 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC private ICPPClassTemplate indexBinding; private boolean checkedIndex; - public CPPTemplateDefinition(IASTName name) { if (name != null) { ASTNodeProperty prop = name.getPropertyInParent(); @@ -97,14 +97,14 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); instances.put(key, instance); } @Override public final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); ICPPTemplateInstance cand = (ICPPTemplateInstance) instances.get(key); if (cand != null) return cand; @@ -112,9 +112,10 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC final ICPPClassTemplate ib = getIndexBinding(); if (ib instanceof ICPPInstanceCache) { - ICPPTemplateInstance cand= ((ICPPInstanceCache) ib).getInstance(arguments); + ICPPTemplateInstance cand = ((ICPPInstanceCache) ib).getInstance(arguments); if (cand instanceof IIndexBinding) { - if (getTemplateName().getTranslationUnit().getIndexFileSet().containsDeclaration((IIndexBinding) cand)) { + if (getTemplateName().getTranslationUnit().getIndexFileSet() + .containsDeclaration((IIndexBinding) cand)) { return cand; } } else { @@ -126,16 +127,16 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC protected ICPPClassTemplate getIndexBinding() { if (!checkedIndex) { - checkedIndex= true; - IASTName name= getTemplateName(); + checkedIndex = true; + IASTName name = getTemplateName(); if (name != null) { IASTTranslationUnit tu = name.getTranslationUnit(); if (tu != null) { - IIndex index= tu.getIndex(); + IIndex index = tu.getIndex(); if (index != null) { IIndexBinding ib = index.adaptBinding(this); if (ib instanceof ICPPClassTemplate) - indexBinding= (ICPPClassTemplate) ib; + indexBinding = (ICPPClassTemplate) ib; } } } @@ -146,9 +147,9 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC @Override public ICPPTemplateInstance[] getAllInstances() { if (instances != null) { - ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i= 0; i < instances.size(); i++) { - result[i]= (ICPPTemplateInstance) instances.getAt(i); + ICPPTemplateInstance[] result = new ICPPTemplateInstance[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + result[i] = (ICPPTemplateInstance) instances.getAt(i); } return result; } @@ -201,7 +202,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC if (template != null) { ICPPASTTemplateParameter[] params = template.getTemplateParameters(); for (ICPPASTTemplateParameter param : params) { - IBinding p= CPPTemplates.getTemplateParameterName(param).resolveBinding(); + IBinding p = CPPTemplates.getTemplateParameterName(param).resolveBinding(); if (p instanceof ICPPTemplateParameter) { result = ArrayUtil.append(result, (ICPPTemplateParameter) p); } @@ -214,12 +215,12 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC @Override public void addDefinition(IASTNode node) { - if (node instanceof ICPPASTCompositeTypeSpecifier) { - node = ((ICPPASTCompositeTypeSpecifier) node).getName(); - if (node instanceof ICPPASTQualifiedName) { - node = ((ICPPASTQualifiedName) node).getLastName(); - } - } + if (node instanceof ICPPASTCompositeTypeSpecifier) { + node = ((ICPPASTCompositeTypeSpecifier) node).getName(); + if (node instanceof ICPPASTQualifiedName) { + node = ((ICPPASTQualifiedName) node).getLastName(); + } + } if (!(node instanceof IASTName)) return; updateTemplateParameterBindings((IASTName) node); @@ -228,85 +229,85 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC @Override public void addDeclaration(IASTNode node) { - if (node instanceof ICPPASTElaboratedTypeSpecifier) { - node = ((ICPPASTElaboratedTypeSpecifier) node).getName(); - if (node instanceof ICPPASTQualifiedName) { - node = ((ICPPASTQualifiedName) node).getLastName(); - } - } + if (node instanceof ICPPASTElaboratedTypeSpecifier) { + node = ((ICPPASTElaboratedTypeSpecifier) node).getName(); + if (node instanceof ICPPASTQualifiedName) { + node = ((ICPPASTQualifiedName) node).getLastName(); + } + } if (!(node instanceof IASTName)) return; IASTName declName = (IASTName) node; updateTemplateParameterBindings(declName); if (declarations == null) { - declarations = new IASTName[] { declName }; + declarations = new IASTName[] { declName }; } else { - // Keep the lowest offset declaration in [0]. + // Keep the lowest offset declaration in [0]. if (declarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { declarations = ArrayUtil.prepend(IASTName.class, declarations, declName); } else { declarations = ArrayUtil.append(IASTName.class, declarations, declName); } - } + } } @Override public IBinding resolveTemplateParameter(ICPPTemplateParameter templateParameter) { - int pos= templateParameter.getParameterPosition(); - - int tdeclLen= declarations == null ? 0 : declarations.length; - for (int i= -1; i < tdeclLen; i++) { - IASTName tdecl; - if (i == -1) { - tdecl= definition; - if (tdecl == null) - continue; - } else { - tdecl= declarations[i]; - if (tdecl == null) - break; - } - - ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(tdecl).getTemplateParameters(); - if (pos < params.length) { - final IASTName oName = CPPTemplates.getTemplateParameterName(params[pos]); - return oName.resolvePreBinding(); - } - } - return templateParameter; + int pos = templateParameter.getParameterPosition(); + + int tdeclLen = declarations == null ? 0 : declarations.length; + for (int i = -1; i < tdeclLen; i++) { + IASTName tdecl; + if (i == -1) { + tdecl = definition; + if (tdecl == null) + continue; + } else { + tdecl = declarations[i]; + if (tdecl == null) + break; + } + + ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(tdecl).getTemplateParameters(); + if (pos < params.length) { + final IASTName oName = CPPTemplates.getTemplateParameterName(params[pos]); + return oName.resolvePreBinding(); + } + } + return templateParameter; } final protected void updateTemplateParameterBindings(IASTName name) { - final ICPPASTTemplateDeclaration templateDeclaration = CPPTemplates.getTemplateDeclaration(name); - if (templateDeclaration == null) - return; + final ICPPASTTemplateDeclaration templateDeclaration = CPPTemplates.getTemplateDeclaration(name); + if (templateDeclaration == null) + return; ICPPASTTemplateParameter[] updateParams = templateDeclaration.getTemplateParameters(); - int k= 0; - int tdeclLen= declarations == null ? 0 : declarations.length; - for (int i= -1; i < tdeclLen && k < updateParams.length; i++) { - IASTName tdecl; - if (i == -1) { - tdecl= definition; - if (tdecl == null) - continue; - } else { - tdecl= declarations[i]; - if (tdecl == null) - break; - } - - ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(tdecl).getTemplateParameters(); - int end= Math.min(params.length, updateParams.length); - for (; k < end; k++) { - final IASTName oName = CPPTemplates.getTemplateParameterName(params[k]); - IBinding b= oName.resolvePreBinding(); - IASTName n = CPPTemplates.getTemplateParameterName(updateParams[k]); - n.setBinding(b); - ASTInternal.addDeclaration(b, n); - } - } - } + int k = 0; + int tdeclLen = declarations == null ? 0 : declarations.length; + for (int i = -1; i < tdeclLen && k < updateParams.length; i++) { + IASTName tdecl; + if (i == -1) { + tdecl = definition; + if (tdecl == null) + continue; + } else { + tdecl = declarations[i]; + if (tdecl == null) + break; + } + + ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(tdecl).getTemplateParameters(); + int end = Math.min(params.length, updateParams.length); + for (; k < end; k++) { + final IASTName oName = CPPTemplates.getTemplateParameterName(params[k]); + IBinding b = oName.resolvePreBinding(); + IASTName n = CPPTemplates.getTemplateParameterName(updateParams[k]); + n.setBinding(b); + ASTInternal.addDeclaration(b, n); + } + } + } @Override public IASTNode[] getDeclarations() { @@ -325,7 +326,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC @Override public final IBinding getOwner() { - IASTName templateName= getTemplateName(); + IASTName templateName = getTemplateName(); if (templateName == null) return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java index 9af4d0d45d8..39121d65ecf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java @@ -34,16 +34,14 @@ public final class CPPTemplateNonTypeArgument implements ICPPTemplateArgument { public CPPTemplateNonTypeArgument(ICPPEvaluation evaluation) { Assert.isNotNull(evaluation); - if (evaluation instanceof EvalFixed || - evaluation.isTypeDependent() || evaluation.isValueDependent()) { - fEvaluation= evaluation; + if (evaluation instanceof EvalFixed || evaluation.isTypeDependent() || evaluation.isValueDependent()) { + fEvaluation = evaluation; } else { IValue value = evaluation.getValue(); if (value == IntegralValue.ERROR) { fEvaluation = EvalFixed.INCOMPLETE; } else { - fEvaluation= new EvalFixed(evaluation.getType(), - evaluation.getValueCategory(), value); + fEvaluation = new EvalFixed(evaluation.getType(), evaluation.getValueCategory(), value); } } } @@ -96,7 +94,7 @@ public final class CPPTemplateNonTypeArgument implements ICPPTemplateArgument { public ICPPTemplateArgument getExpansionPattern() { IType type = fEvaluation.getType(); if (type instanceof ICPPParameterPackType) { - IType t= ((ICPPParameterPackType) type).getType(); + IType t = ((ICPPParameterPackType) type).getType(); if (t != null) { ICPPEvaluation evaluation; if (fEvaluation instanceof EvalPackExpansion) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java index 85d3576c24a..ae09caa88f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java @@ -39,8 +39,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeOfDependentExp /** * Binding for a non-type template parameter. */ -public class CPPTemplateNonTypeParameter extends CPPTemplateParameter - implements ICPPTemplateNonTypeParameter { +public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements ICPPTemplateNonTypeParameter { private IType type; public CPPTemplateNonTypeParameter(IASTName name) { @@ -49,7 +48,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter @Override public IASTExpression getDefault() { - IASTInitializerClause def= getDefaultClause(); + IASTInitializerClause def = getDefaultClause(); if (def instanceof IASTExpression) { return (IASTExpression) def; } @@ -60,7 +59,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter public IASTInitializerClause getDefaultClause() { IASTName[] nds = getDeclarations(); if (nds == null || nds.length == 0) - return null; + return null; for (IASTName name : nds) { if (name != null) { @@ -80,19 +79,19 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter @Override public ICPPTemplateArgument getDefaultValue() { - IASTInitializerClause dc= getDefault(); - IASTExpression d= null; + IASTInitializerClause dc = getDefault(); + IASTExpression d = null; if (dc instanceof IASTExpression) { - d= (IASTExpression) dc; + d = (IASTExpression) dc; } else if (dc instanceof ICPPASTInitializerList) { - ICPPASTInitializerList list= (ICPPASTInitializerList) dc; + ICPPASTInitializerList list = (ICPPASTInitializerList) dc; switch (list.getSize()) { case 0: return new CPPTemplateNonTypeArgument(IntegralValue.create(0), getType()); case 1: - dc= list.getClauses()[0]; + dc = list.getClauses()[0]; if (dc instanceof IASTExpression) { - d= (IASTExpression) dc; + d = (IASTExpression) dc; } } } @@ -100,21 +99,21 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter if (d == null) return null; - IValue val= ValueFactory.create(d); - IType t= getType(); + IValue val = ValueFactory.create(d); + IType t = getType(); return new CPPTemplateNonTypeArgument(val, t); } @Override public IType getType() { if (type == null) { - IASTNode parent= getPrimaryDeclaration().getParent(); + IASTNode parent = getPrimaryDeclaration().getParent(); while (parent != null) { if (parent instanceof ICPPASTParameterDeclaration) { - type= CPPVisitor.createType((ICPPASTParameterDeclaration) parent, true); + type = CPPVisitor.createType((ICPPASTParameterDeclaration) parent, true); break; } - parent= parent.getParent(); + parent = parent.getParent(); } // C++17 template<auto> diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java index 0918af8e97f..0a54e4dcee8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java @@ -43,36 +43,36 @@ public abstract class CPPTemplateParameter extends PlatformObject private final int fParameterID; public CPPTemplateParameter(IASTName name) { - declarations = new IASTName[] {name}; - fParameterID= computeParameterID(name); + declarations = new IASTName[] { name }; + fParameterID = computeParameterID(name); } private int computeParameterID(IASTName name) { - int nesting= 0; - ICPPASTTemplateParameter tp= null; - ICPPASTTemplateParameter[] tps= null; - for (IASTNode node= name.getParent(); node != null; node= node.getParent()) { + int nesting = 0; + ICPPASTTemplateParameter tp = null; + ICPPASTTemplateParameter[] tps = null; + for (IASTNode node = name.getParent(); node != null; node = node.getParent()) { if (tp == null && node instanceof ICPPASTTemplateParameter) { - tp= (ICPPASTTemplateParameter) node; + tp = (ICPPASTTemplateParameter) node; } else if (node instanceof ICPPASTInternalTemplateDeclaration) { - final ICPPASTInternalTemplateDeclaration tdecl= (ICPPASTInternalTemplateDeclaration) node; + final ICPPASTInternalTemplateDeclaration tdecl = (ICPPASTInternalTemplateDeclaration) node; nesting += tdecl.getNestingLevel(); if (tps == null) { - tps= tdecl.getTemplateParameters(); + tps = tdecl.getTemplateParameters(); } break; } else if (node instanceof ICPPASTTemplatedTypeTemplateParameter) { nesting++; if (tps == null) { - tps= ((ICPPASTTemplatedTypeTemplateParameter) node).getTemplateParameters(); + tps = ((ICPPASTTemplatedTypeTemplateParameter) node).getTemplateParameters(); } } } - int pos= 0; + int pos = 0; if (tps != null && tp != null) { for (int i = 0; i < tps.length; i++) { if (tps[i] == tp) { - pos= i; + pos = i; break; } } @@ -83,14 +83,14 @@ public abstract class CPPTemplateParameter extends PlatformObject @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen. - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen. + } + return t; + } @Override public final String getName() { @@ -104,7 +104,7 @@ public abstract class CPPTemplateParameter extends PlatformObject if (decl == null) break; - final char[] result= decl.getSimpleID(); + final char[] result = decl.getSimpleID(); if (result.length > 0) return result; } @@ -126,14 +126,14 @@ public abstract class CPPTemplateParameter extends PlatformObject return (short) (fParameterID >> 16); } - public IASTName getPrimaryDeclaration () { + public IASTName getPrimaryDeclaration() { return declarations[0]; } private ICPPASTTemplateParameter getASTTemplateParameter() { - IASTNode node= declarations[0]; + IASTNode node = declarations[0]; while (node != null && !(node instanceof ICPPASTTemplateParameter)) - node= node.getParent(); + node = node.getParent(); assert node != null; return (ICPPASTTemplateParameter) node; } @@ -181,17 +181,17 @@ public abstract class CPPTemplateParameter extends PlatformObject return; IASTName name = (IASTName) node; if (declarations == null) { - declarations = new IASTName[] { name }; + declarations = new IASTName[] { name }; } else { - if (declarations.length > 0 && declarations[0] == node) - return; + if (declarations.length > 0 && declarations[0] == node) + return; // Keep the lowest offset declaration in [0]. if (declarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { declarations = ArrayUtil.prepend(IASTName.class, declarations, name); } else { declarations = ArrayUtil.append(IASTName.class, declarations, name); } - } + } } @Override @@ -209,12 +209,12 @@ public abstract class CPPTemplateParameter extends PlatformObject if (declarations == null || declarations.length == 0) return null; - IASTNode node= declarations[0]; + IASTNode node = declarations[0]; while (!(node instanceof ICPPASTTemplateParameter)) { if (node == null) return null; - node= node.getParent(); + node = node.getParent(); } return CPPTemplates.getContainingTemplate((ICPPASTTemplateParameter) node); @@ -223,11 +223,11 @@ public abstract class CPPTemplateParameter extends PlatformObject @Override public IBinding resolveFinalBinding(CPPASTNameBase name) { // Check if the binding has been updated. - IBinding current= name.getPreBinding(); + IBinding current = name.getPreBinding(); if (current != this) return current; - ICPPTemplateDefinition template= CPPTemplates.getContainingTemplate(getASTTemplateParameter()); + ICPPTemplateDefinition template = CPPTemplates.getContainingTemplate(getASTTemplateParameter()); if (template instanceof ICPPTemplateParameterOwner) { return ((ICPPTemplateParameterOwner) template).resolveTemplateParameter(this); } @@ -238,7 +238,7 @@ public abstract class CPPTemplateParameter extends PlatformObject } ICPPTemplateParameter[] params = template.getTemplateParameters(); - final int pos= getParameterPosition(); + final int pos = getParameterPosition(); if (pos < params.length) return params[pos]; return new ProblemBinding(getPrimaryDeclaration(), IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java index 5cc2bb43f20..abf62760574 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java @@ -31,11 +31,11 @@ public class CPPTemplateParameterMap implements ICPPTemplateParameterMap { * Constructs an empty parameter map. */ public CPPTemplateParameterMap(int initialSize) { - fMap= new ObjectMap(initialSize); + fMap = new ObjectMap(initialSize); } public CPPTemplateParameterMap(CPPTemplateParameterMap other) { - fMap= (ObjectMap) other.fMap.clone(); + fMap = (ObjectMap) other.fMap.clone(); } /** @@ -148,12 +148,12 @@ public class CPPTemplateParameterMap implements ICPPTemplateParameterMap { if (packSize != args.length) return false; } else if (object == null) { - args= new ICPPTemplateArgument[packSize]; + args = new ICPPTemplateArgument[packSize]; fMap.put(paramID, args); } else { return false; } - args[packOffset]= arg; + args[packOffset] = arg; return true; } @@ -162,7 +162,7 @@ public class CPPTemplateParameterMap implements ICPPTemplateParameterMap { */ public void putAll(ICPPTemplateParameterMap map) { if (map instanceof CPPTemplateParameterMap) { - final ObjectMap omap= ((CPPTemplateParameterMap) map).fMap; + final ObjectMap omap = ((CPPTemplateParameterMap) map).fMap; for (int i = 0; i < omap.size(); i++) { fMap.put(omap.keyAt(i), omap.getAt(i)); } @@ -172,10 +172,10 @@ public class CPPTemplateParameterMap implements ICPPTemplateParameterMap { } public boolean addDeducedArgs(CPPTemplateParameterMap deducedMap) { - Integer[] keys= deducedMap.getAllParameterPositions(); + Integer[] keys = deducedMap.getAllParameterPositions(); for (Integer key : keys) { - Object explicit= fMap.get(key); - Object deduced= deducedMap.fMap.get(key); + Object explicit = fMap.get(key); + Object deduced = deducedMap.fMap.get(key); if (explicit == null) { if (deduced instanceof ICPPTemplateArgument[]) { for (ICPPTemplateArgument arg : (ICPPTemplateArgument[]) deduced) { @@ -185,8 +185,8 @@ public class CPPTemplateParameterMap implements ICPPTemplateParameterMap { } fMap.put(key, deduced); } else if (explicit instanceof ICPPTemplateArgument[] && deduced instanceof ICPPTemplateArgument[]) { - ICPPTemplateArgument[] explicitPack= (ICPPTemplateArgument[]) explicit; - ICPPTemplateArgument[] deducedPack= (ICPPTemplateArgument[]) deduced; + ICPPTemplateArgument[] explicitPack = (ICPPTemplateArgument[]) explicit; + ICPPTemplateArgument[] deducedPack = (ICPPTemplateArgument[]) deduced; if (deducedPack.length < explicitPack.length) return false; System.arraycopy(explicitPack, 0, deducedPack, 0, explicitPack.length); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterSpecialization.java index edf0b78911e..62df4d44d47 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterSpecialization.java @@ -37,8 +37,8 @@ public abstract class CPPTemplateParameterSpecialization extends PlatformObject private final ICPPTemplateParameterMap fTemplateParameterMap; private final ICPPTemplateArgument fDefaultValue; - public CPPTemplateParameterSpecialization(ICPPSpecialization owner, ICPPScope scope, ICPPTemplateParameter specialized, - ICPPTemplateArgument defaultValue) { + public CPPTemplateParameterSpecialization(ICPPSpecialization owner, ICPPScope scope, + ICPPTemplateParameter specialized, ICPPTemplateArgument defaultValue) { fOwner = owner; fScope = scope; fSpecialized = specialized; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index 39d07cc1306..1b56a4b52a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -48,8 +48,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; * A template template parameter. */ public class CPPTemplateTemplateParameter extends CPPTemplateParameter - implements ICPPTemplateTemplateParameter, ICPPInternalTemplate, ICPPUnknownBinding, - ICPPUnknownType { + implements ICPPTemplateTemplateParameter, ICPPInternalTemplate, ICPPUnknownBinding, ICPPUnknownType { private ICPPTemplateParameter[] templateParameters; private ObjectMap instances; private ICPPScope unknownScope; @@ -57,7 +56,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter public CPPTemplateTemplateParameter(IASTName name, boolean isPack) { super(name); - fIsParameterPack= isPack; + fIsParameterPack = isPack; } @Override @@ -67,20 +66,21 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter @Override public ICPPScope asScope() { - if (unknownScope == null) { - IASTName n = null; - IASTNode[] nodes = getDeclarations(); - if (nodes != null && nodes.length > 0) - n = (IASTName) nodes[0]; - unknownScope = new CPPUnknownTypeScope(this, n); - } - return unknownScope; + if (unknownScope == null) { + IASTName n = null; + IASTNode[] nodes = getDeclarations(); + if (nodes != null && nodes.length > 0) + n = (IASTName) nodes[0]; + unknownScope = new CPPUnknownTypeScope(this, n); + } + return unknownScope; } @Override public ICPPTemplateParameter[] getTemplateParameters() { if (templateParameters == null) { - ICPPASTTemplatedTypeTemplateParameter template = (ICPPASTTemplatedTypeTemplateParameter) getPrimaryDeclaration().getParent(); + ICPPASTTemplatedTypeTemplateParameter template = (ICPPASTTemplatedTypeTemplateParameter) getPrimaryDeclaration() + .getParent(); ICPPASTTemplateParameter[] params = template.getTemplateParameters(); ICPPTemplateParameter[] result = ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY; for (ICPPASTTemplateParameter param : params) { @@ -103,7 +103,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter public IType getDefault() { IASTName[] nds = getDeclarations(); if (nds == null || nds.length == 0) - return null; + return null; for (IASTName nd : nds) { if (nd != null) { IASTNode parent = nd.getParent(); @@ -112,8 +112,8 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) parent; IASTExpression value = param.getDefaultValue(); if (value instanceof IASTIdExpression) { - IASTName name= ((IASTIdExpression) value).getName(); - IBinding b= name.resolveBinding(); + IASTName name = ((IASTIdExpression) value).getName(); + IBinding b = name.resolveBinding(); if (b instanceof IType) { return (IType) b; } @@ -126,7 +126,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter @Override public ICPPTemplateArgument getDefaultValue() { - IType d= getDefault(); + IType d = getDefault(); if (d == null) return null; @@ -172,6 +172,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter public ICPPConstructor[] getConstructors() { return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; } + @Override public IBinding[] getFriends() { return IBinding.EMPTY_BINDING_ARRAY; @@ -181,7 +182,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ICPPUsingDeclaration.EMPTY_USING_DECL_ARRAY; @@ -197,7 +198,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter return null; } - @Override + @Override public boolean isSameType(IType type) { if (type == this) return true; @@ -218,14 +219,14 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); instances.put(key, instance); } @Override public final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - String key= ASTTypeUtil.getArgumentListString(arguments, true); + String key = ASTTypeUtil.getArgumentListString(arguments, true); return (ICPPTemplateInstance) instances.get(key); } return null; @@ -234,9 +235,9 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter @Override public ICPPTemplateInstance[] getAllInstances() { if (instances != null) { - ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i=0; i < instances.size(); i++) { - result[i]= (ICPPTemplateInstance) instances.getAt(i); + ICPPTemplateInstance[] result = new ICPPTemplateInstance[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + result[i] = (ICPPTemplateInstance) instances.getAt(i); } return result; } @@ -260,6 +261,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter @Override public int getVisibility(IBinding member) { - throw new IllegalArgumentException(member.getName() + " is not a member of " + getName()); //$NON-NLS-1$ + throw new IllegalArgumentException(member.getName() + " is not a member of " + getName()); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterSpecialization.java index 0df30a492ec..cf63e8e4000 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterSpecialization.java @@ -112,7 +112,7 @@ public class CPPTemplateTemplateParameterSpecialization extends CPPTemplateParam public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ICPPUsingDeclaration.EMPTY_USING_DECL_ARRAY; @@ -167,12 +167,12 @@ public class CPPTemplateTemplateParameterSpecialization extends CPPTemplateParam @Override public Object clone() { - Object o = null; - try { - o = super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return o; - } + Object o = null; + try { + o = super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return o; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java index 2c23f6acfea..9c14bed2e8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java @@ -35,8 +35,8 @@ public final class CPPTemplateTypeArgument implements ICPPTemplateArgument { public CPPTemplateTypeArgument(IType simplifiedType, IType originalType) { Assert.isNotNull(simplifiedType); Assert.isNotNull(originalType); - fType= simplifiedType; - fOriginalType= originalType; + fType = simplifiedType; + fOriginalType = originalType; } @Override @@ -82,7 +82,7 @@ public final class CPPTemplateTypeArgument implements ICPPTemplateArgument { @Override public ICPPTemplateArgument getExpansionPattern() { if (fType instanceof ICPPParameterPackType) { - IType t= ((ICPPParameterPackType) fType).getType(); + IType t = ((ICPPParameterPackType) fType).getType(); if (t != null) { return new CPPTemplateTypeArgument(t); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java index 169d7185ec7..efc719545aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java @@ -29,14 +29,14 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * The standard template parameter (template<typename T> or template<class T>). */ -public class CPPTemplateTypeParameter extends CPPTemplateParameter implements - ICPPTemplateTypeParameter, ICPPUnknownType, ICPPUnknownBinding { +public class CPPTemplateTypeParameter extends CPPTemplateParameter + implements ICPPTemplateTypeParameter, ICPPUnknownType, ICPPUnknownBinding { private ICPPScope unknownScope; private final boolean fIsParameterPack; public CPPTemplateTypeParameter(IASTName name, boolean isPack) { super(name); - fIsParameterPack= isPack; + fIsParameterPack = isPack; } @Override @@ -46,21 +46,21 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements @Override public ICPPScope asScope() { - if (unknownScope == null) { - IASTName n = null; - IASTNode[] nodes = getDeclarations(); - if (nodes != null && nodes.length > 0) - n = (IASTName) nodes[0]; - unknownScope = new CPPUnknownTypeScope(this, n); - } - return unknownScope; + if (unknownScope == null) { + IASTName n = null; + IASTNode[] nodes = getDeclarations(); + if (nodes != null && nodes.length > 0) + n = (IASTName) nodes[0]; + unknownScope = new CPPUnknownTypeScope(this, n); + } + return unknownScope; } @Override public IType getDefault() { IASTName[] nds = getDeclarations(); if (nds == null || nds.length == 0) - return null; + return null; for (IASTName nd : nds) { if (nd != null) { IASTNode parent = nd.getParent(); @@ -77,22 +77,22 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements @Override public ICPPTemplateArgument getDefaultValue() { - IType t= getDefault(); + IType t = getDefault(); if (t == null) return null; return new CPPTemplateTypeArgument(t); } - @Override + @Override public boolean isSameType(IType type) { - if (type == this) - return true; - if (type instanceof ITypedef) - return type.isSameType(this); - if (!(type instanceof ICPPTemplateTypeParameter)) - return false; + if (type == this) + return true; + if (type instanceof ITypedef) + return type.isSameType(this); + if (!(type instanceof ICPPTemplateTypeParameter)) + return false; - return getParameterID() == ((ICPPTemplateParameter) type).getParameterID(); - } + return getParameterID() == ((ICPPTemplateParameter) type).getParameterID(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameterSpecialization.java index 26cb38a54e5..6672fb0a6f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameterSpecialization.java @@ -61,12 +61,12 @@ public class CPPTemplateTypeParameterSpecialization extends CPPTemplateParameter @Override public Object clone() { - Object o = null; - try { - o = super.clone(); - } catch (CloneNotSupportedException e) { - //not going to happen - } - return o; - } + Object o = null; + try { + o = super.clone(); + } catch (CloneNotSupportedException e) { + //not going to happen + } + return o; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index 85a2a1e404c..ee563259870 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -40,51 +40,51 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain public CPPTypedef(IASTName name) { // Bug 223020 even though qualified names are not legal, we need to deal with them. if (name != null && name.getParent() instanceof ICPPASTQualifiedName) { - name= (IASTName) name.getParent(); + name = (IASTName) name.getParent(); } this.declarations = new IASTName[] { name }; - if (name != null) - name.setBinding(this); + if (name != null) + name.setBinding(this); } - @Override + @Override public IASTNode[] getDeclarations() { - return declarations; - } + return declarations; + } - @Override + @Override public IASTNode getDefinition() { - return declarations[0]; - } + return declarations[0]; + } - @Override + @Override public boolean isSameType(IType o) { - if (o == this) - return true; - if (o instanceof ITypedef) { - IType t = getType(); + if (o == this) + return true; + if (o instanceof ITypedef) { + IType t = getType(); if (t != null) - return t.isSameType(((ITypedef) o).getType()); + return t.isSameType(((ITypedef) o).getType()); return false; - } + } - IType t = getType(); - if (t != null) - return t.isSameType(o); - return false; + IType t = getType(); + if (t != null) + return t.isSameType(o); + return false; } @Override public IType getType() { - if (type == null) { - type = CPPVisitor.createType((IASTDeclarator) declarations[0].getParent()); - } + if (type == null) { + type = CPPVisitor.createType((IASTDeclarator) declarations[0].getParent()); + } return type; } @Override public void setType(IType t) { - type = t; + type = t; } @Override @@ -102,66 +102,65 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain return CPPVisitor.getContainingScope(declarations[0].getParent()); } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen - } - return t; - } - - @Override + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen + } + return t; + } + + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() throws DOMException { - IScope scope = getScope(); - while (scope != null) { - if (scope instanceof ICPPBlockScope) - return false; - scope = scope.getParent(); - } - return true; - } + IScope scope = getScope(); + while (scope != null) { + if (scope instanceof ICPPBlockScope) + return false; + scope = scope.getParent(); + } + return true; + } @Override public void addDefinition(IASTNode node) { - addDeclaration(node); + addDeclaration(node); } @Override public void addDeclaration(IASTNode node) { - IASTName name; + IASTName name; if (!(node instanceof IASTName)) { return; } - if (node.getParent() instanceof ICPPASTQualifiedName) { - name= (IASTName) node.getParent(); - } else { - name= (IASTName) node; - } + if (node.getParent() instanceof ICPPASTQualifiedName) { + name = (IASTName) node.getParent(); + } else { + name = (IASTName) node; + } if (declarations == null) { - declarations = new IASTName[] { name }; + declarations = new IASTName[] { name }; } else { - // Keep the lowest offset declaration in [0] - if (declarations.length > 0 && - ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { + // Keep the lowest offset declaration in [0] + if (declarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { declarations = ArrayUtil.prepend(IASTName.class, declarations, name); } else { declarations = ArrayUtil.append(IASTName.class, declarations, name); } - } + } } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java index 9a99c9e3711..ad1c752c4fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java @@ -30,44 +30,43 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType private IType fType; - public CPPTypedefSpecialization(IBinding specialized, IBinding owner, - ICPPTemplateParameterMap tpmap, IType type) { - super(specialized, owner, tpmap); - fType= type; - } + public CPPTypedefSpecialization(IBinding specialized, IBinding owner, ICPPTemplateParameterMap tpmap, IType type) { + super(specialized, owner, tpmap); + fType = type; + } - @Override + @Override public IType getType() { - return fType; - } + return fType; + } - @Override + @Override public Object clone() { - IType t = null; - try { - t = (IType) super.clone(); - } catch (CloneNotSupportedException e) { - // Not going to happen. - } - return t; - } + IType t = null; + try { + t = (IType) super.clone(); + } catch (CloneNotSupportedException e) { + // Not going to happen. + } + return t; + } - @Override + @Override public boolean isSameType(IType o) { - if (o == this) - return true; - if (o instanceof ITypedef) { - IType t = getType(); + if (o == this) + return true; + if (o instanceof ITypedef) { + IType t = getType(); if (t != null) - return t.isSameType(((ITypedef) o).getType()); + return t.isSameType(((ITypedef) o).getType()); return false; - } + } - IType t = getType(); + IType t = getType(); if (t != null) - return t.isSameType(o); - return false; - } + return t.isSameType(o); + return false; + } @Override public void setType(IType type) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnaryTypeTransformation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnaryTypeTransformation.java index bacea22f979..f88adaeac09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnaryTypeTransformation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnaryTypeTransformation.java @@ -39,8 +39,7 @@ public class CPPUnaryTypeTransformation implements ICPPUnaryTypeTransformation, if (!(other instanceof ICPPUnaryTypeTransformation)) return false; ICPPUnaryTypeTransformation otherType = (ICPPUnaryTypeTransformation) other; - return getOperator() == otherType.getOperator() - && getOperand().isSameType(otherType.getOperand()); + return getOperator() == otherType.getOperator() && getOperand().isSameType(otherType.getOperand()); } @Override @@ -53,10 +52,10 @@ public class CPPUnaryTypeTransformation implements ICPPUnaryTypeTransformation, return fOperand; } - @Override + @Override public CPPUnaryTypeTransformation clone() { - return new CPPUnaryTypeTransformation(fOperator, (IType) fOperand.clone()); - } + return new CPPUnaryTypeTransformation(fOperator, (IType) fOperand.clone()); + } @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { @@ -69,7 +68,7 @@ public class CPPUnaryTypeTransformation implements ICPPUnaryTypeTransformation, int operator = buffer.getByte(); if (operator >= Operator.values().length) { throw new CoreException(CCorePlugin.createStatus( - "Cannot unmarshal CPPUnaryTypeTransformation - unrecognized type transformation operator")); //$NON-NLS-1$ + "Cannot unmarshal CPPUnaryTypeTransformation - unrecognized type transformation operator")); //$NON-NLS-1$ } return new CPPUnaryTypeTransformation(Operator.values()[operator], buffer.unmarshalType()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java index cdff4fd28d8..defdb9ca60d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java @@ -33,80 +33,80 @@ import org.eclipse.core.runtime.PlatformObject; */ public abstract class CPPUnknownBinding extends PlatformObject implements ICPPUnknownBinding, ICPPInternalBinding, Cloneable { - private ICPPScope unknownScope; - protected char[] name; + private ICPPScope unknownScope; + protected char[] name; - public CPPUnknownBinding(char[] name) { - super(); - this.name = name; - } + public CPPUnknownBinding(char[] name) { + super(); + this.name = name; + } - @Override + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - @Override + @Override public IASTNode getDefinition() { - return null; - } + return null; + } - @Override + @Override public void addDefinition(IASTNode node) { - } + } - @Override + @Override public void addDeclaration(IASTNode node) { - } + } - @Override + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() { - return false; - } + return false; + } - @Override + @Override public final String getName() { - return new String(getNameCharArray()); - } + return new String(getNameCharArray()); + } - @Override + @Override public char[] getNameCharArray() { - return name; - } + return name; + } - @Override + @Override public IScope getScope() throws DOMException { - // Use getOwner(), it is overridden by derived classes. - final IBinding owner = getOwner(); + // Use getOwner(), it is overridden by derived classes. + final IBinding owner = getOwner(); if (owner instanceof ICPPUnknownBinding) { - return ((ICPPUnknownBinding) owner).asScope(); - } else if (owner instanceof ICPPClassType) { - return ((ICPPClassType) owner).getCompositeScope(); - } else if (owner instanceof ICPPNamespace) { - return ((ICPPNamespace) owner).getNamespaceScope(); - } else if (owner instanceof ICPPFunction) { - return ((ICPPFunction) owner).getFunctionScope(); - } - return null; - } - - @Override + return ((ICPPUnknownBinding) owner).asScope(); + } else if (owner instanceof ICPPClassType) { + return ((ICPPClassType) owner).getCompositeScope(); + } else if (owner instanceof ICPPNamespace) { + return ((ICPPNamespace) owner).getNamespaceScope(); + } else if (owner instanceof ICPPFunction) { + return ((ICPPFunction) owner).getFunctionScope(); + } + return null; + } + + @Override public ICPPScope asScope() { - if (unknownScope == null && this instanceof ICPPUnknownType) { - unknownScope = createScope(); - } - return unknownScope; - } + if (unknownScope == null && this instanceof ICPPUnknownType) { + unknownScope = createScope(); + } + return unknownScope; + } protected CPPUnknownTypeScope createScope() { return new CPPUnknownTypeScope((ICPPUnknownType) this, new CPPASTName(name)); @@ -122,7 +122,7 @@ public abstract class CPPUnknownBinding extends PlatformObject try { return (CPPUnknownBinding) super.clone(); } catch (CloneNotSupportedException e) { - return null; // Never happens + return null; // Never happens } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java index c4f76d3bb86..891f7f6c27e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java @@ -57,10 +57,10 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC } if (type instanceof ICPPUnknownMemberClassInstance) { - ICPPUnknownMemberClassInstance rhs= (ICPPUnknownMemberClassInstance) type; + ICPPUnknownMemberClassInstance rhs = (ICPPUnknownMemberClassInstance) type; if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) { - ICPPTemplateArgument[] lhsArgs= getArguments(); - ICPPTemplateArgument[] rhsArgs= rhs.getArguments(); + ICPPTemplateArgument[] lhsArgs = getArguments(); + ICPPTemplateArgument[] rhsArgs = rhs.getArguments(); if (lhsArgs != rhsArgs) { if (lhsArgs == null || rhsArgs == null) return false; @@ -68,7 +68,7 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC if (lhsArgs.length != rhsArgs.length) return false; - for (int i= 0; i < lhsArgs.length; i++) { + for (int i = 0; i < lhsArgs.length; i++) { if (!lhsArgs[i].isSameValue(rhsArgs[i])) return false; } @@ -76,7 +76,7 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC final IType lhsContainer = getOwnerType(); final IType rhsContainer = rhs.getOwnerType(); if (lhsContainer != null && rhsContainer != null) { - return (lhsContainer.isSameType(rhsContainer)); + return (lhsContainer.isSameType(rhsContainer)); } } } @@ -85,7 +85,7 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.UNKNOWN_MEMBER_CLASS_INSTANCE; + short firstBytes = ITypeMarshalBuffer.UNKNOWN_MEMBER_CLASS_INSTANCE; buffer.putShort(firstBytes); buffer.marshalType(getOwnerType()); buffer.putCharArray(getNameCharArray()); @@ -95,13 +95,14 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC } } - public static ICPPUnknownMemberClassInstance unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType owner= buffer.unmarshalType(); + public static ICPPUnknownMemberClassInstance unmarshal(IIndexFragment fragment, short firstBytes, + ITypeMarshalBuffer buffer) throws CoreException { + IType owner = buffer.unmarshalType(); char[] name = buffer.getCharArray(); - int argcount= buffer.getInt(); + int argcount = buffer.getInt(); ICPPTemplateArgument[] args = new ICPPTemplateArgument[argcount]; for (int i = 0; i < argcount; i++) { - args[i]= buffer.unmarshalTemplateArgument(); + args[i] = buffer.unmarshalTemplateArgument(); } return new PDOMCPPUnknownMemberClassInstance(fragment, owner, name, args); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownField.java index fe8e6de7d51..17e7e499530 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownField.java @@ -69,6 +69,7 @@ public class CPPUnknownField extends CPPUnknownMember implements ICPPField { public int getVisibility() { return v_public; } + @Override public ICPPClassType getClassOwner() { IType owner = getOwnerType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java index ec0075f0fdb..f50cca86c26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java @@ -32,16 +32,16 @@ import org.eclipse.core.runtime.CoreException; /** * Represents a binding that is unknown because it depends on template arguments. */ -public class CPPUnknownMember extends CPPUnknownBinding implements ICPPUnknownMember, ISerializableType { - protected final IType fOwner; +public class CPPUnknownMember extends CPPUnknownBinding implements ICPPUnknownMember, ISerializableType { + protected final IType fOwner; - protected CPPUnknownMember(IType owner, char[] name) { - super(name); - if (owner instanceof ICPPClassTemplate) { - owner= CPPTemplates.createDeferredInstance((ICPPClassTemplate) owner); - } - fOwner= owner; - } + protected CPPUnknownMember(IType owner, char[] name) { + super(name); + if (owner instanceof ICPPClassTemplate) { + owner = CPPTemplates.createDeferredInstance((ICPPClassTemplate) owner); + } + fOwner = owner; + } @Override public IBinding getOwner() { @@ -57,7 +57,7 @@ public class CPPUnknownMember extends CPPUnknownBinding implements ICPPUnknownMe @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - short firstBytes= ITypeMarshalBuffer.UNKNOWN_MEMBER; + short firstBytes = ITypeMarshalBuffer.UNKNOWN_MEMBER; if (this instanceof ICPPField) { firstBytes |= ITypeMarshalBuffer.FLAG1; } else if (this instanceof ICPPMethod) { @@ -69,8 +69,9 @@ public class CPPUnknownMember extends CPPUnknownBinding implements ICPPUnknownMe buffer.putCharArray(getNameCharArray()); } - public static IBinding unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - IType owner= buffer.unmarshalType(); + public static IBinding unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) + throws CoreException { + IType owner = buffer.unmarshalType(); char[] name = buffer.getCharArray(); if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) { return new PDOMCPPUnknownField(fragment, owner, name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMemberClass.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMemberClass.java index f58beff6c30..c347d7cf817 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMemberClass.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMemberClass.java @@ -34,75 +34,75 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; * Represents a C++ class, declaration of which is not yet available. */ public class CPPUnknownMemberClass extends CPPUnknownMember implements ICPPUnknownMemberClass { - public CPPUnknownMemberClass(IType owner, char[] name) { - super(owner, name); - } + public CPPUnknownMemberClass(IType owner, char[] name) { + super(owner, name); + } - @Override + @Override public ICPPBase[] getBases() { - return ICPPBase.EMPTY_BASE_ARRAY; - } + return ICPPBase.EMPTY_BASE_ARRAY; + } - @Override + @Override public IField[] getFields() { - return IField.EMPTY_FIELD_ARRAY; - } + return IField.EMPTY_FIELD_ARRAY; + } - @Override + @Override public IField findField(String name) { - return null; - } + return null; + } - @Override + @Override public ICPPField[] getDeclaredFields() { - return ICPPField.EMPTY_CPPFIELD_ARRAY; - } + return ICPPField.EMPTY_CPPFIELD_ARRAY; + } - @Override + @Override public ICPPMethod[] getMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } - @Override + @Override public ICPPMethod[] getAllDeclaredMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } - @Override + @Override public ICPPMethod[] getDeclaredMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } - @Override + @Override public ICPPConstructor[] getConstructors() { - return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; - } + return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + } - @Override + @Override public IBinding[] getFriends() { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } - @Override + @Override public int getKey() { - return 0; - } + return 0; + } - @Override + @Override public final IScope getCompositeScope() { - return asScope(); - } + return asScope(); + } - @Override + @Override public boolean isSameType(IType type) { - if (this == type) - return true; + if (this == type) + return true; if (type instanceof ITypedef) return type.isSameType(this); if (type instanceof ICPPUnknownMemberClass && !(type instanceof ICPPUnknownMemberClassInstance)) { - ICPPUnknownMemberClass rhs= (ICPPUnknownMemberClass) type; + ICPPUnknownMemberClass rhs = (ICPPUnknownMemberClass) type; if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) { final IType lhsContainer = getOwnerType(); final IType rhsContainer = rhs.getOwnerType(); @@ -112,13 +112,13 @@ public class CPPUnknownMemberClass extends CPPUnknownMember implements ICPPUnkno } } return false; - } + } @Override public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations() { return ICPPUsingDeclaration.EMPTY_USING_DECL_ARRAY; @@ -141,6 +141,6 @@ public class CPPUnknownMemberClass extends CPPUnknownMember implements ICPPUnkno @Override public int getVisibility(IBinding member) { - throw new IllegalArgumentException(member.getName() + " is not a member of " + getName()); //$NON-NLS-1$ + throw new IllegalArgumentException(member.getName() + " is not a member of " + getName()); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMethod.java index 840ee1d91ee..1c0f21daf5e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMethod.java @@ -26,8 +26,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; * unknown. A compiler would resolve it during instantiation. */ public class CPPUnknownMethod extends CPPUnknownMember implements ICPPMethod { - private static final ICPPFunctionType FUNCTION_TYPE= - new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY); + private static final ICPPFunctionType FUNCTION_TYPE = new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, + IType.EMPTY_TYPE_ARRAY); public CPPUnknownMethod(IType owner, char[] name) { super(owner, name); @@ -72,7 +72,7 @@ public class CPPUnknownMethod extends CPPUnknownMember implements ICPPMethod { public ICPPFunctionType getDeclaredType() { return FUNCTION_TYPE; } - + @Override public ICPPFunctionType getType() { // TODO(nathanridge): We'd like to return a TypeOfUnknownMember here, @@ -126,6 +126,7 @@ public class CPPUnknownMethod extends CPPUnknownMember implements ICPPMethod { public int getVisibility() { return v_public; } + @Override public ICPPClassType getClassOwner() { IType owner = getOwnerType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java index c556e13511e..1b201544ad7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java @@ -42,18 +42,18 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.HeuristicResolver; * to be final or used in a thread-safe manner otherwise. */ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope { - private final IASTName fName; + private final IASTName fName; private final IType fScopeType; - /** - * This field needs to be protected when used in PDOMCPPUnknownScope, - * don't use it outside of {@link #getOrCreateBinding(IASTName, int)} - */ - private CharArrayObjectMap<IBinding[]> map; + /** + * This field needs to be protected when used in PDOMCPPUnknownScope, + * don't use it outside of {@link #getOrCreateBinding(IASTName, int)} + */ + private CharArrayObjectMap<IBinding[]> map; public CPPUnknownTypeScope(IType scopeType, IASTName name) { - fName= name; - fScopeType= scopeType; - } + fName = name; + fScopeType = scopeType; + } @Override public EScopeKind getKind() { @@ -62,101 +62,102 @@ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope { @Override public IASTNode getPhysicalNode() { - return fName; - } + return fName; + } - @Override + @Override public IName getScopeName() { - return fName; - } + return fName; + } - @Override + @Override public IType getScopeType() { - return fScopeType; - } + return fScopeType; + } - @Override + @Override public IScope getParent() throws DOMException { - if (fScopeType instanceof IBinding) - return ((IBinding) fScopeType).getScope(); - return null; - } + if (fScopeType instanceof IBinding) + return ((IBinding) fScopeType).getScope(); + return null; + } - @Override + @Override public IBinding[] find(String name, IASTTranslationUnit tu) { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } - @Override + @Override public IBinding[] find(String name) { - return IBinding.EMPTY_BINDING_ARRAY; - } + return IBinding.EMPTY_BINDING_ARRAY; + } @Override public final IBinding getBinding(IASTName name, boolean resolve) { return getBinding(name, resolve, IIndexFileSet.EMPTY); } - @Override + @Override public IBinding getBinding(final IASTName name, boolean resolve, IIndexFileSet fileSet) { - boolean type= false; - boolean function= false; - - if (name.getPropertyInParent() == null) { - type= true; - } else { - IASTName n= name; - IASTNode parent= name.getParent(); - if (parent instanceof ICPPASTTemplateId) { - n= (IASTName) parent; - parent= n.getParent(); - } - if (parent instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent; - if (qname.getLastName() != n) { - type= true; - } else { - parent= qname.getParent(); - } - } - if (!type) { - if (parent instanceof ICPPASTBaseSpecifier || - parent instanceof ICPPASTConstructorChainInitializer) { - type= true; - } else if (parent instanceof ICPPASTNamedTypeSpecifier) { - ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) parent; - type= nts.isTypename(); - } else if (parent instanceof ICPPASTUsingDeclaration) { - ICPPASTUsingDeclaration ud= (ICPPASTUsingDeclaration) parent; - type= ud.isTypename(); - function= true; - } - - if (!type && parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { - function= true; - } - } - } - - int idx= type ? 0 : function ? 1 : 2; - - IBinding result = getOrCreateBinding(name.getSimpleID(), idx); - return result; - } - - @Override @Deprecated + boolean type = false; + boolean function = false; + + if (name.getPropertyInParent() == null) { + type = true; + } else { + IASTName n = name; + IASTNode parent = name.getParent(); + if (parent instanceof ICPPASTTemplateId) { + n = (IASTName) parent; + parent = n.getParent(); + } + if (parent instanceof ICPPASTQualifiedName) { + ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; + if (qname.getLastName() != n) { + type = true; + } else { + parent = qname.getParent(); + } + } + if (!type) { + if (parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTConstructorChainInitializer) { + type = true; + } else if (parent instanceof ICPPASTNamedTypeSpecifier) { + ICPPASTNamedTypeSpecifier nts = (ICPPASTNamedTypeSpecifier) parent; + type = nts.isTypename(); + } else if (parent instanceof ICPPASTUsingDeclaration) { + ICPPASTUsingDeclaration ud = (ICPPASTUsingDeclaration) parent; + type = ud.isTypename(); + function = true; + } + + if (!type && parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { + function = true; + } + } + } + + int idx = type ? 0 : function ? 1 : 2; + + IBinding result = getOrCreateBinding(name.getSimpleID(), idx); + return result; + } + + @Override + @Deprecated public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) { return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY); } - @Override @Deprecated + @Override + @Deprecated public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) { return getBindings(new ScopeLookupData(name, resolve, prefixLookup)); } @Override public final IBinding[] getBindings(ScopeLookupData lookup) { - if (lookup.isPrefixLookup()) { + if (lookup.isPrefixLookup()) { // If name lookup is performed for the purpose of code completion in a dependent context, // try to give some useful results heuristically. IScope scope = HeuristicResolver.findConcreteScopeForType(fScopeType); @@ -164,14 +165,14 @@ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope { return scope.getBindings(lookup); } return IBinding.EMPTY_BINDING_ARRAY; - } - IASTName lookupName= lookup.getLookupName(); - if (lookupName != null) - return new IBinding[] { getBinding(lookupName, lookup.isResolve(), lookup.getIncludedFiles()) }; + } + IASTName lookupName = lookup.getLookupName(); + if (lookupName != null) + return new IBinding[] { getBinding(lookupName, lookup.isResolve(), lookup.getIncludedFiles()) }; - // When dealing with dependent expressions we always create an unknown class. That is because - // unknown objects are not used within the expressions, they are attached to names only. - return new IBinding[] { getOrCreateBinding(lookup.getLookupKey(), 0) }; + // When dealing with dependent expressions we always create an unknown class. That is because + // unknown objects are not used within the expressions, they are attached to names only. + return new IBinding[] { getOrCreateBinding(lookup.getLookupKey(), 0) }; } @Override @@ -179,35 +180,35 @@ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope { return fName.toString(); } - @Override + @Override public void addName(IASTName name, boolean adlOnly) { - } + } protected IBinding getOrCreateBinding(final char[] name, int idx) { if (map == null) - map = new CharArrayObjectMap<>(2); + map = new CharArrayObjectMap<>(2); - IBinding[] o = map.get(name); + IBinding[] o = map.get(name); if (o == null) { o = new IBinding[3]; map.put(name, o); } - IBinding result= o[idx]; - if (result == null) { - switch (idx) { - case 0: - result= new CPPUnknownMemberClass(fScopeType, name); - break; - case 1: - result= new CPPUnknownMethod(fScopeType, name); - break; - case 2: - result= new CPPUnknownField(fScopeType, name); - break; - } - o[idx]= result; - } + IBinding result = o[idx]; + if (result == null) { + switch (idx) { + case 0: + result = new CPPUnknownMemberClass(fScopeType, name); + break; + case 1: + result = new CPPUnknownMethod(fScopeType, name); + break; + case 2: + result = new CPPUnknownField(fScopeType, name); + break; + } + o[idx] = result; + } return result; } @@ -217,8 +218,10 @@ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope { } @Override - public void populateCache() {} + public void populateCache() { + } @Override - public void removeNestedFromCache(IASTNode container) {} + public void removeNestedFromCache(IASTNode container) { + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java index 83773e494cd..4283c8a4481 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java @@ -29,79 +29,79 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; public class CPPUsingDeclaration extends PlatformObject implements ICPPUsingDeclaration, ICPPInternalBinding { - private IASTName name; - private IBinding[] delegates; - - public CPPUsingDeclaration(IASTName name, IBinding[] bindings) { - if (name instanceof ICPPASTQualifiedName) { - name = name.getLastName(); - } - this.name = name; - this.delegates= bindings; - } - - @Override + private IASTName name; + private IBinding[] delegates; + + public CPPUsingDeclaration(IASTName name, IBinding[] bindings) { + if (name instanceof ICPPASTQualifiedName) { + name = name.getLastName(); + } + this.name = name; + this.delegates = bindings; + } + + @Override public IBinding[] getDelegates() { - return delegates; - } + return delegates; + } - @Override + @Override public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName(this); - } + return CPPVisitor.getQualifiedName(this); + } - @Override + @Override public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray(this); - } + return CPPVisitor.getQualifiedNameCharArray(this); + } - @Override + @Override public boolean isGloballyQualified() throws DOMException { - IScope scope = getScope(); - while (scope != null) { - if (scope instanceof ICPPBlockScope) - return false; - scope = scope.getParent(); - } - return true; - } - - @Override + IScope scope = getScope(); + while (scope != null) { + if (scope instanceof ICPPBlockScope) + return false; + scope = scope.getParent(); + } + return true; + } + + @Override public String getName() { - return new String(getNameCharArray()); - } + return new String(getNameCharArray()); + } - @Override + @Override public char[] getNameCharArray() { - return name.getSimpleID(); - } + return name.getSimpleID(); + } - @Override + @Override public IScope getScope() { - return CPPVisitor.getContainingScope(name.getParent()); - } + return CPPVisitor.getContainingScope(name.getParent()); + } - @Override + @Override public IASTNode[] getDeclarations() { - return null; - } + return null; + } - @Override + @Override public IASTNode getDefinition() { - IASTNode n = name.getParent(); - if (n instanceof ICPPASTTemplateId) - n = n.getParent(); + IASTNode n = name.getParent(); + if (n instanceof ICPPASTTemplateId) + n = n.getParent(); - return n; - } + return n; + } - @Override + @Override public void addDefinition(IASTNode node) { - } + } - @Override + @Override public void addDeclaration(IASTNode node) { - } + } @Override public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclarationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclarationSpecialization.java index 5db39c63569..74962774719 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclarationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclarationSpecialization.java @@ -23,11 +23,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; public class CPPUsingDeclarationSpecialization extends CPPSpecialization implements ICPPUsingDeclaration { private final IBinding[] fDelegates; - public CPPUsingDeclarationSpecialization(ICPPUsingDeclaration specialized, IBinding owner, - ICPPTemplateParameterMap tpmap, IBinding[] delegates) { - super(specialized, owner, tpmap); - fDelegates= delegates; - } + public CPPUsingDeclarationSpecialization(ICPPUsingDeclaration specialized, IBinding owner, + ICPPTemplateParameterMap tpmap, IBinding[] delegates) { + super(specialized, owner, tpmap); + fDelegates = delegates; + } @Override public IBinding[] getDelegates() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java index c43a680b2c2..11af0733072 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java @@ -36,19 +36,19 @@ public class CPPUsingDirective implements ICPPUsingDirective { * Constructor for explicit using directives */ public CPPUsingDirective(ICPPASTUsingDirective node) { - fNamespaceName= node.getQualifiedName(); + fNamespaceName = node.getQualifiedName(); } /** * Constructor for unnamed namespaces introducing an implicit using directive. */ public CPPUsingDirective(ICPPASTNamespaceDefinition nsdef) { - fNamespaceName= nsdef.getName(); + fNamespaceName = nsdef.getName(); } @Override public ICPPNamespaceScope getNominatedScope() throws DOMException { - IBinding binding= fNamespaceName.resolveBinding(); + IBinding binding = fNamespaceName.resolveBinding(); if (binding instanceof ICPPNamespace) { return ((ICPPNamespace) binding).getNamespaceScope(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index a212908ba58..4999c631b5f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -59,7 +59,7 @@ import org.eclipse.core.runtime.PlatformObject; public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredVariable { private IASTName fDefinition; - private IASTName fDeclarations[]; // Allowed to have trailing nulls. Users must check or trim! + private IASTName fDeclarations[]; // Allowed to have trailing nulls. Users must check or trim! private IType fType; private IValue fInitialValue = IntegralValue.NOT_INITIALIZED; private boolean fAllResolved; @@ -74,7 +74,7 @@ public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredV return new HashSet<>(); } }; - + public CPPVariable(IASTName name) { boolean isDef = name != null && name.isDefinition(); if (name instanceof ICPPASTQualifiedName) { @@ -106,8 +106,7 @@ public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredV fDeclarations = new IASTName[] { name }; } else { // Keep the lowest offset declaration at the first position. - if (fDeclarations.length > 0 - && ((ASTNode) node).getOffset() < ((ASTNode) fDeclarations[0]).getOffset()) { + if (fDeclarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) fDeclarations[0]).getOffset()) { fDeclarations = ArrayUtil.prepend(IASTName.class, fDeclarations, name); } else { fDeclarations = ArrayUtil.append(IASTName.class, fDeclarations, name); @@ -258,12 +257,13 @@ public class CPPVariable extends PlatformObject implements ICPPInternalDeclaredV try { IValue initialValue = null; final IType nestedType = SemanticUtil.getNestedType(getType(), TDEF | REF | CVTYPE); - if (nestedType instanceof ICPPClassType || (initialValue = VariableHelpers.getInitialValue(fDefinition, fDeclarations, getType())) == IntegralValue.UNKNOWN) { + if (nestedType instanceof ICPPClassType || (initialValue = VariableHelpers.getInitialValue(fDefinition, + fDeclarations, getType())) == IntegralValue.UNKNOWN) { ICPPEvaluation initEval = getInitializerEvaluation(); if (initEval == null) { return null; } - if (!initEval.isValueDependent() ) { + if (!initEval.isValueDependent()) { IASTNode point = fDefinition != null ? fDefinition : fDeclarations[0]; CPPSemantics.pushLookupPoint(point); try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariableInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariableInstance.java index f084cb50ecc..a1fde0b37f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariableInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariableInstance.java @@ -29,8 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariableInstance; /** * An instance of a variable template. */ -public class CPPVariableInstance extends CPPSpecialization - implements ICPPVariableInstance, ICPPInternalVariable { +public class CPPVariableInstance extends CPPSpecialization implements ICPPVariableInstance, ICPPInternalVariable { private ICPPTemplateArgument[] templateArguments; private IType type; private IValue initialValue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index 5ba825b50a5..a03884ceac6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -100,12 +100,13 @@ public class ClassTypeHelper { if (host.getDefinition() == null) { host.checkForDefinition(); if (host.getDefinition() == null) { - ICPPClassType backup= getBackupDefinition(host); + ICPPClassType backup = getBackupDefinition(host); if (backup != null) return backup.getFriends(); - IASTNode[] declarations= host.getDeclarations(); + IASTNode[] declarations = host.getDeclarations(); IASTNode node = (declarations != null && declarations.length != 0) ? declarations[0] : null; - return new IBinding[] { new ProblemBinding(node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray()) }; + return new IBinding[] { new ProblemBinding(node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, + host.getNameCharArray()) }; } } ObjectSet<IBinding> resultSet = new ObjectSet<>(2); @@ -116,7 +117,8 @@ public class ClassTypeHelper { } if (decl instanceof IASTSimpleDeclaration) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl) + .getDeclSpecifier(); if (declSpec.isFriend()) { IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); if (dtors.length == 0) { @@ -127,17 +129,19 @@ public class ClassTypeHelper { } } else { for (IASTDeclarator dtor : dtors) { - if (dtor == null) break; - dtor= ASTQueries.findInnermostDeclarator(dtor); + if (dtor == null) + break; + dtor = ASTQueries.findInnermostDeclarator(dtor); resultSet.put(dtor.getName().resolveBinding()); } } } } else if (decl instanceof IASTFunctionDefinition) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl) + .getDeclSpecifier(); if (declSpec.isFriend()) { IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator(); - dtor= ASTQueries.findInnermostDeclarator(dtor); + dtor = ASTQueries.findInnermostDeclarator(dtor); resultSet.put(dtor.getName().resolveBinding()); } } @@ -170,10 +174,9 @@ public class ClassTypeHelper { type = ((ICPPFunction) binding).getType(); char[] name = binding.getNameCharArray(); for (IBinding friend : classType.getFriends()) { - if (friend instanceof ICPPFunction && - CharArrayUtils.equals(name, friend.getNameCharArray()) && - SemanticUtil.haveSameOwner(binding, friend) && - type.isSameType(((ICPPFunction) friend).getType())) { + if (friend instanceof ICPPFunction && CharArrayUtils.equals(name, friend.getNameCharArray()) + && SemanticUtil.haveSameOwner(binding, friend) + && type.isSameType(((ICPPFunction) friend).getType())) { return true; } } @@ -198,7 +201,7 @@ public class ClassTypeHelper { if (host.getDefinition() == null) { host.checkForDefinition(); if (host.getDefinition() == null) { - ICPPClassType backup= getBackupDefinition(host); + ICPPClassType backup = getBackupDefinition(host); if (backup != null) return backup.getBases(); @@ -210,7 +213,7 @@ public class ClassTypeHelper { if (baseSpecifiers.length == 0) return ICPPBase.EMPTY_BASE_ARRAY; - ICPPBase[] bases = new ICPPBase[baseSpecifiers.length]; + ICPPBase[] bases = new ICPPBase[baseSpecifiers.length]; for (int i = 0; i < baseSpecifiers.length; i++) { bases[i] = new CPPBaseClause(baseSpecifiers[i]); } @@ -222,7 +225,7 @@ public class ClassTypeHelper { if (host.getDefinition() == null) { host.checkForDefinition(); if (host.getDefinition() == null) { - ICPPClassType backup= getBackupDefinition(host); + ICPPClassType backup = getBackupDefinition(host); if (backup != null) return backup.getDeclaredFields(); @@ -266,7 +269,7 @@ public class ClassTypeHelper { * @return An array of base classes in arbitrary order. */ public static ICPPClassType[] getAllBases(ICPPClassType classType) { - Set<ICPPClassType> result= new HashSet<>(); + Set<ICPPClassType> result = new HashSet<>(); result.add(classType); getAllBases(classType, result); result.remove(classType); @@ -274,9 +277,9 @@ public class ClassTypeHelper { } private static void getAllBases(ICPPClassType classType, Set<ICPPClassType> result) { - ICPPBase[] bases= classType.getBases(); + ICPPBase[] bases = classType.getBases(); for (ICPPBase base : bases) { - IBinding b= base.getBaseClass(); + IBinding b = base.getBaseClass(); if (b instanceof ICPPClassType) { final ICPPClassType baseClass = (ICPPClassType) b; if (result.add(baseClass)) { @@ -327,9 +330,9 @@ public class ClassTypeHelper { * @return {@code true} if {@code subclass} is a subclass of {@code superclass}. */ public static boolean isSubclass(ICPPClassType subclass, ICPPClassType superclass) { - ICPPBase[] bases= subclass.getBases(); + ICPPBase[] bases = subclass.getBases(); for (ICPPBase base : bases) { - IBinding b= base.getBaseClass(); + IBinding b = base.getBaseClass(); if (b instanceof ICPPClassType) { ICPPClassType baseClass = (ICPPClassType) b; if (baseClass.isSameType(superclass)) { @@ -344,8 +347,8 @@ public class ClassTypeHelper { } public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct) { - ICPPMethod[] methods= ct.getDeclaredMethods(); - ICPPClassType[] bases= getAllBases(ct); + ICPPMethod[] methods = ct.getDeclaredMethods(); + ICPPClassType[] bases = getAllBases(ct); for (ICPPClassType base : bases) { methods = ArrayUtil.addAll(ICPPMethod.class, methods, base.getDeclaredMethods()); } @@ -355,7 +358,7 @@ public class ClassTypeHelper { public static ICPPMethod[] getMethods(ICPPClassType ct) { ObjectSet<ICPPMethod> set = getOwnMethods(ct); - ICPPClassType[] bases= getAllBases(ct); + ICPPClassType[] bases = getAllBases(ct); for (ICPPClassType base : bases) { set.addAll(base.getDeclaredMethods()); set.addAll(getImplicitMethods(base)); @@ -368,7 +371,7 @@ public class ClassTypeHelper { * include methods declared in base classes. */ public static ObjectSet<ICPPMethod> getOwnMethods(ICPPClassType classType) { - ObjectSet<ICPPMethod> set= new ObjectSet<>(4); + ObjectSet<ICPPMethod> set = new ObjectSet<>(4); set.addAll(classType.getDeclaredMethods()); set.addAll(getImplicitMethods(classType)); return set; @@ -389,7 +392,7 @@ public class ClassTypeHelper { if (host.getDefinition() == null) { host.checkForDefinition(); if (host.getDefinition() == null) { - ICPPClassType backup= getBackupDefinition(host); + ICPPClassType backup = getBackupDefinition(host); if (backup != null) return backup.getDeclaredMethods(); @@ -470,7 +473,7 @@ public class ClassTypeHelper { } ICPPConstructor[] inheritedConstructors = getInheritedConstructors( (ICPPClassScope) classType.getCompositeScope(), classType.getBases(), paramTypes); - return ArrayUtil.addAll(declaredAndImplicitConstructors, inheritedConstructors); + return ArrayUtil.addAll(declaredAndImplicitConstructors, inheritedConstructors); } /** @@ -489,14 +492,14 @@ public class ClassTypeHelper { if (!base.isInheritedConstructorsSource()) continue; IBinding baseType = base.getBaseClass(); - if (!(baseType instanceof ICPPClassType)) - continue; - ICPPClassType baseClass = (ICPPClassType) baseType; + if (!(baseType instanceof ICPPClassType)) + continue; + ICPPClassType baseClass = (ICPPClassType) baseType; ICPPConstructor[] ctors = baseClass.getConstructors(); - for (ICPPConstructor ctor : ctors) { - if (canBeInherited(ctor, baseClass, existingConstructorParamTypes)) - inheritedConstructors = appendAt(inheritedConstructors, n++, ctor); - } + for (ICPPConstructor ctor : ctors) { + if (canBeInherited(ctor, baseClass, existingConstructorParamTypes)) + inheritedConstructors = appendAt(inheritedConstructors, n++, ctor); + } } return trim(inheritedConstructors, n); } @@ -512,7 +515,7 @@ public class ClassTypeHelper { // copy/move constructor or assignment operator of the derived class, as described below. for (int k = Math.max(ctor.getRequiredArgumentCount(), 1); k <= params.length; k++) { if (k == 1 && isReferenceToClass(params[0].getType(), baseClass)) { - continue; // Skip the copy constructor. + continue; // Skip the copy constructor. } if (findMatchingSignature(params, k, existingConstructorParamTypes) < 0) { return true; @@ -522,9 +525,9 @@ public class ClassTypeHelper { } private static boolean isReferenceToClass(IType type, IType classType) { - type= SemanticUtil.getNestedType(type, TDEF); + type = SemanticUtil.getNestedType(type, TDEF); if (type instanceof ICPPReferenceType && !((ICPPReferenceType) type).isRValueReference()) { - type= SemanticUtil.getNestedType(type, TDEF|REF|CVTYPE); + type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); return classType.isSameType(type); } return false; @@ -552,7 +555,7 @@ public class ClassTypeHelper { if (host.getDefinition() == null) { host.checkForDefinition(); if (host.getDefinition() == null) { - ICPPClassType backup= getBackupDefinition(host); + ICPPClassType backup = getBackupDefinition(host); if (backup != null) return backup.getNestedClasses(); @@ -572,8 +575,8 @@ public class ClassTypeHelper { IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); - } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && - ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) { + } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier + && ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) { binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding(); } if (binding instanceof ICPPClassType) @@ -582,12 +585,12 @@ public class ClassTypeHelper { } return ArrayUtil.trim(result, resultSize); } - + public static ICPPUsingDeclaration[] getUsingDeclarations(ICPPInternalClassTypeMixinHost host) { if (host.getDefinition() == null) { host.checkForDefinition(); if (host.getDefinition() == null) { - ICPPClassType backup= getBackupDefinition(host); + ICPPClassType backup = getBackupDefinition(host); if (backup != null) return backup.getUsingDeclarations(); @@ -627,9 +630,10 @@ public class ClassTypeHelper { if (field == null) { field = (IField) binding; } else { - IASTNode[] decls= ASTInternal.getDeclarationsOfBinding(ct); - IASTNode node= (decls != null && decls.length > 0) ? decls[0] : null; - return new CPPField.CPPFieldProblem(ct, node, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, name.toCharArray()); + IASTNode[] decls = ASTInternal.getDeclarationsOfBinding(ct); + IASTNode node = (decls != null && decls.length > 0) ? decls[0] : null; + return new CPPField.CPPFieldProblem(ct, node, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + name.toCharArray()); } } } @@ -646,13 +650,14 @@ public class ClassTypeHelper { if (m.isVirtual()) return true; - final char[] mname= m.getNameCharArray(); - final ICPPClassType mcl= m.getClassOwner(); + final char[] mname = m.getNameCharArray(); + final ICPPClassType mcl = m.getClassOwner(); if (mcl != null) { - final ICPPFunctionType mft= m.getType(); - ICPPMethod[] allMethods= ClassTypeHelper.getMethods(mcl); + final ICPPFunctionType mft = m.getType(); + ICPPMethod[] allMethods = ClassTypeHelper.getMethods(mcl); for (ICPPMethod method : allMethods) { - if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft, method.getType())) { + if (CharArrayUtils.equals(mname, method.getNameCharArray()) + && functionTypesAllowOverride(mft, method.getType())) { if (method.isVirtual()) { return true; } @@ -666,26 +671,26 @@ public class ClassTypeHelper { * Checks if the function types are consistent enough to be considered overrides. */ private static boolean functionTypesAllowOverride(ICPPFunctionType a, ICPPFunctionType b) { - if (a.isConst() != b.isConst() || a.isVolatile() != b.isVolatile() || a.takesVarArgs() != b.takesVarArgs()) { - return false; - } + if (a.isConst() != b.isConst() || a.isVolatile() != b.isVolatile() || a.takesVarArgs() != b.takesVarArgs()) { + return false; + } - IType[] paramsA = a.getParameterTypes(); - IType[] paramsB = b.getParameterTypes(); + IType[] paramsA = a.getParameterTypes(); + IType[] paramsB = b.getParameterTypes(); - if (paramsA.length == 1 && paramsB.length == 0) { + if (paramsA.length == 1 && paramsB.length == 0) { if (!SemanticUtil.isVoidType(paramsA[0])) return false; } else if (paramsB.length == 1 && paramsA.length == 0) { if (!SemanticUtil.isVoidType(paramsB[0])) return false; } else if (paramsA.length != paramsB.length) { - return false; + return false; } else { for (int i = 0; i < paramsA.length; i++) { - if (paramsA[i] == null || ! paramsA[i].isSameType(paramsB[i])) - return false; - } + if (paramsA[i] == null || !paramsA[i].isSameType(paramsB[i])) + return false; + } } return true; } @@ -701,12 +706,12 @@ public class ClassTypeHelper { if (!functionTypesAllowOverride(source.getType(), target.getType())) return false; - final ICPPClassType sourceClass= source.getClassOwner(); - final ICPPClassType targetClass= target.getClassOwner(); + final ICPPClassType sourceClass = source.getClassOwner(); + final ICPPClassType targetClass = target.getClassOwner(); if (sourceClass == null || targetClass == null) return false; - ICPPClassType[] bases= getAllBases(sourceClass); + ICPPClassType[] bases = getAllBases(sourceClass); for (ICPPClassType base : bases) { if (base.isSameType(targetClass)) return true; @@ -722,22 +727,22 @@ public class ClassTypeHelper { if (method instanceof ICPPConstructor) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - final char[] mname= method.getNameCharArray(); - final ICPPClassType mcl= method.getClassOwner(); + final char[] mname = method.getNameCharArray(); + final ICPPClassType mcl = method.getClassOwner(); if (mcl == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - final ArrayList<ICPPMethod> result= new ArrayList<>(); - final HashMap<ICPPClassType, Boolean> virtualInClass= new HashMap<>(); - final ICPPFunctionType methodType= method.getType(); + final ArrayList<ICPPMethod> result = new ArrayList<>(); + final HashMap<ICPPClassType, Boolean> virtualInClass = new HashMap<>(); + final ICPPFunctionType methodType = method.getType(); virtualInClass.put(mcl, method.isVirtual()); - ICPPBase[] bases= mcl.getBases(); + ICPPBase[] bases = mcl.getBases(); for (ICPPBase base : bases) { - IBinding b= base.getBaseClass(); + IBinding b = base.getBaseClass(); if (b instanceof ICPPClassType) { - findOverridden((ICPPClassType) b, mname, methodType, virtualInClass, - result, CPPSemantics.MAX_INHERITANCE_DEPTH); + findOverridden((ICPPClassType) b, mname, methodType, virtualInClass, result, + CPPSemantics.MAX_INHERITANCE_DEPTH); } } @@ -753,39 +758,37 @@ public class ClassTypeHelper { * * @return whether {@code classType} contains an overridden method. */ - private static boolean findOverridden(ICPPClassType classType, char[] methodName, - ICPPFunctionType methodType, Map<ICPPClassType, Boolean> virtualInClass, - List<ICPPMethod> result, int maxdepth) { + private static boolean findOverridden(ICPPClassType classType, char[] methodName, ICPPFunctionType methodType, + Map<ICPPClassType, Boolean> virtualInClass, List<ICPPMethod> result, int maxdepth) { // Prevent recursion due to a hierarchy of unbounded depth, e.g. A<I> deriving from A<I - 1>. if (maxdepth <= 0) return false; - Boolean visitedBefore= virtualInClass.get(classType); + Boolean visitedBefore = virtualInClass.get(classType); if (visitedBefore != null) return visitedBefore; - ICPPMethod[] methods= classType.getDeclaredMethods(); - ICPPMethod candidate= null; - boolean hasOverridden= false; + ICPPMethod[] methods = classType.getDeclaredMethods(); + ICPPMethod candidate = null; + boolean hasOverridden = false; for (ICPPMethod method : methods) { if (methodName[0] == '~' && method.isDestructor() - || (CharArrayUtils.equals(methodName, method.getNameCharArray()) - && functionTypesAllowOverride(methodType, method.getType()))) { - candidate= method; - hasOverridden= method.isVirtual(); + || (CharArrayUtils.equals(methodName, method.getNameCharArray()) + && functionTypesAllowOverride(methodType, method.getType()))) { + candidate = method; + hasOverridden = method.isVirtual(); break; } } // Prevent recursion due to a class inheriting (directly or indirectly) from itself. virtualInClass.put(classType, hasOverridden); - ICPPBase[] bases= classType.getBases(); + ICPPBase[] bases = classType.getBases(); for (ICPPBase base : bases) { - IBinding b= base.getBaseClass(); + IBinding b = base.getBaseClass(); if (b instanceof ICPPClassType) { - if (findOverridden((ICPPClassType) b, methodName, methodType, virtualInClass, - result, maxdepth - 1)) { - hasOverridden= true; + if (findOverridden((ICPPClassType) b, methodName, methodType, virtualInClass, result, maxdepth - 1)) { + hasOverridden = true; } } } @@ -801,16 +804,15 @@ public class ClassTypeHelper { /** * Returns all methods found in the index, that override the given {@code method}. */ - public static ICPPMethod[] findOverriders(IIndex index, ICPPMethod method) - throws CoreException { + public static ICPPMethod[] findOverriders(IIndex index, ICPPMethod method) throws CoreException { if (!isVirtual(method)) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - final ICPPClassType mcl= method.getClassOwner(); + final ICPPClassType mcl = method.getClassOwner(); if (mcl == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - ICPPClassType[] subclasses= getSubClasses(index, mcl); + ICPPClassType[] subclasses = getSubClasses(index, mcl); return findOverriders(subclasses, method); } @@ -818,14 +820,14 @@ public class ClassTypeHelper { * Returns all methods belonging to the given set of classes that override the given {@code method}. */ public static ICPPMethod[] findOverriders(ICPPClassType[] subclasses, ICPPMethod method) { - final char[] mname= method.getNameCharArray(); - final ICPPFunctionType mft= method.getType(); - final ArrayList<ICPPMethod> result= new ArrayList<>(); + final char[] mname = method.getNameCharArray(); + final ICPPFunctionType mft = method.getType(); + final ArrayList<ICPPMethod> result = new ArrayList<>(); for (ICPPClassType subClass : subclasses) { - ICPPMethod[] methods= subClass.getDeclaredMethods(); + ICPPMethod[] methods = subClass.getDeclaredMethods(); for (ICPPMethod candidate : methods) { - if (CharArrayUtils.equals(mname, candidate.getNameCharArray()) && - functionTypesAllowOverride(mft, candidate.getType())) { + if (CharArrayUtils.equals(mname, candidate.getNameCharArray()) + && functionTypesAllowOverride(mft, candidate.getType())) { result.add(candidate); } } @@ -834,15 +836,15 @@ public class ClassTypeHelper { } private static ICPPClassType[] getSubClasses(IIndex index, ICPPClassType mcl) throws CoreException { - Deque<ICPPBinding> result= new ArrayDeque<>(); - HashSet<String> handled= new HashSet<>(); + Deque<ICPPBinding> result = new ArrayDeque<>(); + HashSet<String> handled = new HashSet<>(); getSubClasses(index, mcl, result, handled); result.removeFirst(); return result.toArray(new ICPPClassType[result.size()]); } - private static void getSubClasses(IIndex index, ICPPBinding classOrTypedef, - Collection<ICPPBinding> result, HashSet<String> handled) throws CoreException { + private static void getSubClasses(IIndex index, ICPPBinding classOrTypedef, Collection<ICPPBinding> result, + HashSet<String> handled) throws CoreException { if (!(classOrTypedef instanceof IType)) return; @@ -856,12 +858,12 @@ public class ClassTypeHelper { } // TODO(nathanridge): Also find subclasses referenced via decltype-specifiers rather than names. - IIndexName[] names= index.findNames(classOrTypedef, IIndex.FIND_REFERENCES | IIndex.FIND_DEFINITIONS); + IIndexName[] names = index.findNames(classOrTypedef, IIndex.FIND_REFERENCES | IIndex.FIND_DEFINITIONS); for (IIndexName indexName : names) { if (indexName.isBaseSpecifier()) { - IIndexName subClassDef= indexName.getEnclosingDefinition(); + IIndexName subClassDef = indexName.getEnclosingDefinition(); if (subClassDef != null) { - IBinding subClass= index.findBinding(subClassDef); + IBinding subClass = index.findBinding(subClassDef); if (subClass instanceof ICPPBinding) { getSubClasses(index, (ICPPBinding) subClass, result, handled); } @@ -871,22 +873,16 @@ public class ClassTypeHelper { } public enum MethodKind { - DEFAULT_CTOR, - COPY_CTOR, - MOVE_CTOR, - COPY_ASSIGNMENT_OP, - MOVE_ASSIGNMENT_OP, - DTOR, - OTHER + DEFAULT_CTOR, COPY_CTOR, MOVE_CTOR, COPY_ASSIGNMENT_OP, MOVE_ASSIGNMENT_OP, DTOR, OTHER } public static MethodKind getMethodKind(ICPPClassType classType, ICPPMethod method) { if (method instanceof ICPPConstructor) { - final List<IType> params= getTypesOfRequiredParameters(method); + final List<IType> params = getTypesOfRequiredParameters(method); if (params.isEmpty()) return MethodKind.DEFAULT_CTOR; if (params.size() == 1) { - IType t= SemanticUtil.getNestedType(params.get(0), SemanticUtil.TDEF); + IType t = SemanticUtil.getNestedType(params.get(0), SemanticUtil.TDEF); if (SemanticUtil.isVoidType(t)) return MethodKind.DEFAULT_CTOR; @@ -901,12 +897,13 @@ public class ClassTypeHelper { return MethodKind.DTOR; if (CharArrayUtils.equals(method.getNameCharArray(), OverloadableOperator.ASSIGN.toCharArray())) { - final List<IType> params= getTypesOfRequiredParameters(method); + final List<IType> params = getTypesOfRequiredParameters(method); if (params.size() == 1) { - IType t= params.get(0); + IType t = params.get(0); ICPPReferenceType refToClass = getRefToClass(classType, t); if (refToClass != null) - return refToClass.isRValueReference() ? MethodKind.MOVE_ASSIGNMENT_OP : MethodKind.COPY_ASSIGNMENT_OP; + return refToClass.isRValueReference() ? MethodKind.MOVE_ASSIGNMENT_OP + : MethodKind.COPY_ASSIGNMENT_OP; } return MethodKind.OTHER; } @@ -933,22 +930,22 @@ public class ClassTypeHelper { */ public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod) { // See 15.4.13 - ICPPClassType owner= implicitMethod.getClassOwner(); + ICPPClassType owner = implicitMethod.getClassOwner(); if (owner == null || owner.getBases().length == 0) return null; // We use a list as types aren't comparable, and can have duplicates (15.4.6) - MethodKind kind= getMethodKind(owner, implicitMethod); + MethodKind kind = getMethodKind(owner, implicitMethod); if (kind == MethodKind.OTHER) return null; List<IType> inheritedTypeids = new ArrayList<>(); - ICPPClassType[] bases= getAllBases(owner); + ICPPClassType[] bases = getAllBases(owner); for (ICPPClassType base : bases) { if (!(base instanceof ICPPDeferredClassInstance)) { - ICPPMethod baseMethod= getMethodInClass(base, kind); + ICPPMethod baseMethod = getMethodInClass(base, kind); if (baseMethod != null) { - IType[] baseExceptionSpec= baseMethod.getExceptionSpecification(); + IType[] baseExceptionSpec = baseMethod.getExceptionSpecification(); if (baseExceptionSpec == null) return null; for (IType baseTypeId : baseMethod.getExceptionSpecification()) { @@ -966,17 +963,17 @@ public class ClassTypeHelper { */ private static ICPPReferenceType getRefToClass(ICPPClassType classType, IType type) { while (type instanceof ITypedef) { - type= ((ITypedef) type).getType(); + type = ((ITypedef) type).getType(); } if (type instanceof ICPPReferenceType) { ICPPReferenceType refType = (ICPPReferenceType) type; - type= refType.getType(); + type = refType.getType(); while (type instanceof ITypedef) { - type= ((ITypedef) type).getType(); + type = ((ITypedef) type).getType(); } if (type instanceof IQualifierType) { - type= ((IQualifierType) type).getType(); + type = ((IQualifierType) type).getType(); if (classType.isSameType(type)) return refType; } @@ -1071,8 +1068,8 @@ public class ClassTypeHelper { IASTNode node = ((ICPPInternalBinding) member).getDefinition(); if (node != null) { IASTName ownerName = CPPVisitor.findDeclarationOwnerDefinition(node, false); - if (ownerName != null && !ownerName.equals(classDeclSpec.getName()) && - ownerName.getPropertyInParent() == ICPPASTCompositeTypeSpecifier.TYPE_NAME) { + if (ownerName != null && !ownerName.equals(classDeclSpec.getName()) + && ownerName.getPropertyInParent() == ICPPASTCompositeTypeSpecifier.TYPE_NAME) { classDeclSpec = (ICPPASTCompositeTypeSpecifier) ownerName.getParent(); visibility = getVisibility(classDeclSpec, member); if (visibility >= 0) @@ -1085,8 +1082,8 @@ public class ClassTypeHelper { } private static int getVisibility(ICPPASTCompositeTypeSpecifier classDeclSpec, IBinding member) { - int visibility = classDeclSpec.getKey() == ICPPASTCompositeTypeSpecifier.k_class ? - ICPPClassType.v_private : ICPPClassType.v_public; + int visibility = classDeclSpec.getKey() == ICPPASTCompositeTypeSpecifier.k_class ? ICPPClassType.v_private + : ICPPClassType.v_public; IASTDeclaration[] hostMembers = classDeclSpec.getMembers(); for (IASTDeclaration hostMember : hostMembers) { if (hostMember instanceof ICPPASTVisibilityLabel) { @@ -1099,8 +1096,8 @@ public class ClassTypeHelper { if (hostMember instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration memberDeclaration = (IASTSimpleDeclaration) hostMember; for (IASTDeclarator memberDeclarator : memberDeclaration.getDeclarators()) { - IBinding memberBinding = - ASTQueries.findInnermostDeclarator(memberDeclarator).getName().resolveBinding(); + IBinding memberBinding = ASTQueries.findInnermostDeclarator(memberDeclarator).getName() + .resolveBinding(); if (member.equals(memberBinding)) { return visibility; } @@ -1108,15 +1105,13 @@ public class ClassTypeHelper { IASTDeclSpecifier declSpec = memberDeclaration.getDeclSpecifier(); if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { - IBinding memberBinding = - ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); + IBinding memberBinding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); if (member.equals(memberBinding)) { return visibility; } } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && memberDeclaration.getDeclarators().length == 0) { - IBinding memberBinding = - ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding(); + IBinding memberBinding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding(); if (member.equals(memberBinding)) { return visibility; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPASTGotoStatement.java index e01ff005b5a..b9047f288b0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPASTGotoStatement.java @@ -46,8 +46,7 @@ public class GNUCPPASTGotoStatement extends CPPASTAttributeOwner implements IGNU @Override public GNUCPPASTGotoStatement copy(CopyStyle style) { - GNUCPPASTGotoStatement copy = new GNUCPPASTGotoStatement(expression == null ? null - : expression.copy(style)); + GNUCPPASTGotoStatement copy = new GNUCPPASTGotoStatement(expression == null ? null : expression.copy(style)); return copy(copy, style); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index db091bdbc64..2e1520d2772 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -191,12 +191,14 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; */ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private static final int DEFAULT_PARM_LIST_SIZE = 4; - private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE= 4; + private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE = 4; private static final int TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT = 256; // This is a parameter to the protected function {@link #declarator(DtorStrategy, DeclarationOptions)} // so it needs to be protected too. - protected static enum DtorStrategy {PREFER_FUNCTION, PREFER_NESTED} + protected static enum DtorStrategy { + PREFER_FUNCTION, PREFER_NESTED + } private final boolean allowCPPRestrict; private final boolean supportExtendedTemplateSyntax; @@ -216,31 +218,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private Map<String, ContextSensitiveTokenType> fContextSensitiveTokens; - public GNUCPPSourceParser(IScanner scanner, ParserMode mode, - IParserLogService log, ICPPParserExtensionConfiguration config) { + public GNUCPPSourceParser(IScanner scanner, ParserMode mode, IParserLogService log, + ICPPParserExtensionConfiguration config) { this(scanner, mode, log, config, null); } public GNUCPPSourceParser(IScanner scanner, ParserMode mode, IParserLogService log, ICPPParserExtensionConfiguration config, IIndex index) { - super(scanner, log, mode, CPPNodeFactory.getDefault(), - config.supportStatementsInExpressions(), - config.supportTypeofUnaryExpressions(), - config.supportAlignOfUnaryExpression(), - config.supportKnRC(), - config.supportAttributeSpecifiers(), - config.supportDeclspecSpecifiers(), + super(scanner, log, mode, CPPNodeFactory.getDefault(), config.supportStatementsInExpressions(), + config.supportTypeofUnaryExpressions(), config.supportAlignOfUnaryExpression(), config.supportKnRC(), + config.supportAttributeSpecifiers(), config.supportDeclspecSpecifiers(), config.getBuiltinBindingsProvider()); allowCPPRestrict = config.allowRestrictPointerOperators(); supportExtendedTemplateSyntax = config.supportExtendedTemplateSyntax(); - supportParameterInfoBlock= config.supportParameterInfoBlock(); - supportExtendedSizeofOperator= config.supportExtendedSizeofOperator(); - supportFunctionStyleAsm= config.supportFunctionStyleAssembler(); + supportParameterInfoBlock = config.supportParameterInfoBlock(); + supportExtendedSizeofOperator = config.supportExtendedSizeofOperator(); + supportFunctionStyleAsm = config.supportFunctionStyleAssembler(); supportGCCStyleDesignators = config.supportGCCStyleDesignators(); - functionCallCanBeLValue= true; - supportAutoTypeSpecifier= true; - supportUserDefinedLiterals= config.supportUserDefinedLiterals(); - this.index= index; + functionCallCanBeLValue = true; + supportAutoTypeSpecifier = true; + supportUserDefinedLiterals = config.supportUserDefinedLiterals(); + this.index = index; scanner.setSplitShiftROperator(true); fContextSensitiveTokens = createContextSensitiveTokenMap(config); additionalNumericalSuffixes = scanner.getAdditionalNumericLiteralSuffixes(); @@ -284,8 +282,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private ICPPASTNameSpecifier ambiguousNameSpecifier(CastExprCtx ctx) throws BacktrackException, EndOfFileException { - TemplateIdStrategy strat= new TemplateIdStrategy(); - IToken m= mark(); + TemplateIdStrategy strat = new TemplateIdStrategy(); + IToken m = mark(); while (true) { try { return nameSpecifier(ctx, strat); @@ -305,45 +303,46 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parses a name specifier. */ - private ICPPASTNameSpecifier nameSpecifier(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { + private ICPPASTNameSpecifier nameSpecifier(CastExprCtx ctx, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException { if (strat == null) return ambiguousNameSpecifier(ctx); - ICPPASTQualifiedName qname= null; - ICPPASTNameSpecifier nameSpec= null; - final int offset= LA(1).getOffset(); - int endOffset= offset; + ICPPASTQualifiedName qname = null; + ICPPASTNameSpecifier nameSpec = null; + final int offset = LA(1).getOffset(); + int endOffset = offset; if (LT(1) == IToken.tCOLONCOLON) { - endOffset= consume().getEndOffset(); - qname= getNodeFactory().newQualifiedName(null); + endOffset = consume().getEndOffset(); + qname = getNodeFactory().newQualifiedName(null); qname.setFullyQualified(true); } - boolean mustBeLast= false; - boolean haveName= false; + boolean mustBeLast = false; + boolean haveName = false; loop: while (true) { - boolean keywordTemplate= false; + boolean keywordTemplate = false; if (qname != null && LT(1) == IToken.t_template) { consume(); - keywordTemplate= true; + keywordTemplate = true; } - int destructorOffset= -1; + int destructorOffset = -1; if (LT(1) == IToken.tBITCOMPLEMENT) { - destructorOffset= consume().getOffset(); - mustBeLast= true; + destructorOffset = consume().getOffset(); + mustBeLast = true; } switch (LT(1)) { case IToken.tIDENTIFIER: case IToken.tCOMPLETION: case IToken.tEOC: - IToken nt= consume(); + IToken nt = consume(); nameSpec = (ICPPASTName) buildName(destructorOffset, nt, keywordTemplate); break; case IToken.t_operator: - nameSpec= (ICPPASTName) operatorId(); + nameSpec = (ICPPASTName) operatorId(); break; case IToken.t_decltype: @@ -358,37 +357,37 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (!haveName || destructorOffset >= 0 || keywordTemplate) { throwBacktrack(LA(1)); } - nameSpec= getNodeFactory().newName(CharArrayUtils.EMPTY); + nameSpec = getNodeFactory().newName(CharArrayUtils.EMPTY); if (qname != null) { addNameSpecifier(qname, nameSpec); } break loop; } - haveName= true; + haveName = true; // Check for template-id if (nameSpec instanceof IASTName && LTcatchEOF(1) == IToken.tLT) { IASTName name = (IASTName) nameSpec; final boolean inBinaryExpression = ctx != CastExprCtx.eNotInBExpr; final int haveArgs = haveTemplateArguments(inBinaryExpression); - boolean templateID= true; + boolean templateID = true; if (!keywordTemplate) { if (haveArgs == NO_TEMPLATE_ID) { - templateID= false; + templateID = false; } else if (haveArgs == AMBIGUOUS_TEMPLATE_ID) { - templateID= strat.shallParseAsTemplateID(name); + templateID = strat.shallParseAsTemplateID(name); } } if (templateID) { if (haveArgs == NO_TEMPLATE_ID) throwBacktrack(LA(1)); - nameSpec= (ICPPASTName) addTemplateArguments(name, strat); + nameSpec = (ICPPASTName) addTemplateArguments(name, strat); } } - endOffset= calculateEndOffset(nameSpec); + endOffset = calculateEndOffset(nameSpec); if (qname != null) { addNameSpecifier(qname, nameSpec); } @@ -399,15 +398,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (mustBeLast) throwBacktrack(LA(1)); - endOffset= consume().getEndOffset(); // :: + endOffset = consume().getEndOffset(); // :: if (qname == null) { - qname= getNodeFactory().newQualifiedName(null); + qname = getNodeFactory().newQualifiedName(null); addNameSpecifier(qname, nameSpec); } } if (qname != null) { setRange(qname, offset, endOffset); - nameSpec= qname; + nameSpec = qname; } return nameSpec; } @@ -424,7 +423,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parses a qualified name. */ - private ICPPASTName qualifiedName(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { + private ICPPASTName qualifiedName(CastExprCtx ctx, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException { ICPPASTNameSpecifier nameSpec = nameSpecifier(ctx, strat); if (!(nameSpec instanceof ICPPASTName)) { // decltype-specifier without following :: @@ -444,18 +444,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTName name; if (destructorOffset < 0) { if (keywordTemplate) { - name= getNodeFactory().newTemplateName(nt.getCharImage()); + name = getNodeFactory().newTemplateName(nt.getCharImage()); } else { - name= getNodeFactory().newName(nt.getCharImage()); + name = getNodeFactory().newName(nt.getCharImage()); } setRange(name, nt.getOffset(), nt.getEndOffset()); } else { - char[] nchars= nt.getCharImage(); - final int len= nchars.length; + char[] nchars = nt.getCharImage(); + final int len = nchars.length; char[] image = new char[len + 1]; - image[0]= '~'; + image[0] = '~'; System.arraycopy(nchars, 0, image, 1, len); - name= getNodeFactory().newName(image); + name = getNodeFactory().newName(image); setRange(name, destructorOffset, nt.getEndOffset()); } switch (nt.getType()) { @@ -467,11 +467,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return name; } - private IASTName addTemplateArguments(IASTName templateName, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + private IASTName addTemplateArguments(IASTName templateName, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { // Parse for template arguments consume(IToken.tLT); List<IASTNode> list = templateArgumentList(strat); - IToken end= LA(1); + IToken end = LA(1); switch (end.getType()) { case IToken.tGT_in_SHIFTR: case IToken.tGT: @@ -517,17 +518,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * Makes a fast check whether there could be template arguments. * -1: no, 0: ambiguous, 1: yes */ - private static final int NO_TEMPLATE_ID= -1; - private static final int AMBIGUOUS_TEMPLATE_ID= 0; - private static final int TEMPLATE_ID= 1; + private static final int NO_TEMPLATE_ID = -1; + private static final int AMBIGUOUS_TEMPLATE_ID = 0; + private static final int TEMPLATE_ID = 1; + private int haveTemplateArguments(boolean inBinaryExpression) throws EndOfFileException, BacktrackException { - final IToken mark= mark(); + final IToken mark = mark(); try { consume(); - int nk= 0; - int depth= 0; - int angleDepth= 1; - int limit= 10000; + int nk = 0; + int depth = 0; + int angleDepth = 1; + int limit = 10000; while (--limit > 0) { switch (consume().getType()) { @@ -547,7 +549,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (!inBinaryExpression) return angleDepth == 0 ? TEMPLATE_ID : AMBIGUOUS_TEMPLATE_ID; - int end= endsTemplateIDInBinaryExpression(); + int end = endsTemplateIDInBinaryExpression(); if (end == NO_TEMPLATE_ID) { if (angleDepth == 0) return NO_TEMPLATE_ID; @@ -558,8 +560,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; case IToken.tLBRACKET: if (nk == 0) { - nk= IToken.tLBRACKET; - depth= 0; + nk = IToken.tLBRACKET; + depth = 0; } else if (nk == IToken.tLBRACKET) { depth++; } @@ -567,14 +569,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tRBRACKET: if (nk == IToken.tLBRACKET) { if (--depth < 0) { - nk= 0; + nk = 0; } } break; case IToken.tLPAREN: if (nk == 0) { - nk= IToken.tLPAREN; - depth= 0; + nk = IToken.tLPAREN; + depth = 0; } else if (nk == IToken.tLPAREN) { depth++; } @@ -583,11 +585,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tRPAREN: if (nk == IToken.tLPAREN) { if (--depth < 0) { - nk= 0; + nk = 0; } } break; - + // In C++11, braces can occur at the top level in a template-argument, // if an object of class type is being created via uniform initialization, // and that class type has a constexpr conversion operator to a type @@ -600,18 +602,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { depth++; } break; - + case IToken.tRBRACE: if (nk == 0) { return NO_TEMPLATE_ID; - } - else if (nk == IToken.tLBRACE) { + } else if (nk == IToken.tLBRACE) { if (--depth < 0) { nk = 0; } } break; - + case IToken.tSEMI: if (nk == 0) { return NO_TEMPLATE_ID; @@ -630,14 +631,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * else it is the end of a template-id, or special-cast. */ private int endsTemplateIDInBinaryExpression() { - int lt1= LTcatchEOF(1); + int lt1 = LTcatchEOF(1); switch (lt1) { // Can be start of expression, or the scope operator applied to the template-id case IToken.tCOLONCOLON: // 'CT<int>::member' or 'c<1 && 2 > ::g' return AMBIGUOUS_TEMPLATE_ID; // Can be start of expression or the function-call operator applied to a template-id - case IToken.tLPAREN: // 'ft<int>(args)' or 'c<1 && 2 > (x+y)' + case IToken.tLPAREN: // 'ft<int>(args)' or 'c<1 && 2 > (x+y)' return AMBIGUOUS_TEMPLATE_ID; // Start of unary expression @@ -720,19 +721,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - private List<IASTNode> templateArgumentList(ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + private List<IASTNode> templateArgumentList(ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { if (templateArgumentNestingDepth >= TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT) { - throwBacktrack(createProblem(IProblem.TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT_EXCEEDED, - LA(1).getOffset(), 1)); + throwBacktrack( + createProblem(IProblem.TEMPLATE_ARGUMENT_NESTING_DEPTH_LIMIT_EXCEEDED, LA(1).getOffset(), 1)); } ++templateArgumentNestingDepth; try { int startingOffset = LA(1).getOffset(); int endOffset = 0; - List<IASTNode> list= null; - - boolean needComma= false; - int lt1= LT(1); + List<IASTNode> list = null; + + boolean needComma = false; + int lt1 = LT(1); while (lt1 != IToken.tGT && lt1 != IToken.tGT_in_SHIFTR && lt1 != IToken.tEOC) { if (needComma) { if (lt1 != IToken.tCOMMA) { @@ -740,15 +742,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } consume(); } else { - needComma= true; + needComma = true; } - - IASTNode node= templateArgument(strat); + + IASTNode node = templateArgument(strat); if (list == null) { - list= new ArrayList<>(); + list = new ArrayList<>(); } list.add(node); - lt1= LT(1); + lt1 = LT(1); } if (list == null) { return Collections.emptyList(); @@ -762,10 +764,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTNode templateArgument(ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { IToken argStart = mark(); int markBranchPoint = ((TemplateIdStrategy) strat).getCurrentBranchPoint(); - ICPPASTTypeId typeId= null; - int lt1= 0; + ICPPASTTypeId typeId = null; + int lt1 = 0; try { - typeId= typeId(DeclarationOptions.TYPEID, strat); + typeId = typeId(DeclarationOptions.TYPEID, strat); lt1 = LT(1); } catch (BacktrackException e) { if (e.isFatal()) { @@ -773,11 +775,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - if (typeId != null - && (lt1 == IToken.tCOMMA || lt1 == IToken.tGT || lt1 == IToken.tGT_in_SHIFTR - || lt1 == IToken.tEOC || lt1 == IToken.tELLIPSIS)) { + if (typeId != null && (lt1 == IToken.tCOMMA || lt1 == IToken.tGT || lt1 == IToken.tGT_in_SHIFTR + || lt1 == IToken.tEOC || lt1 == IToken.tELLIPSIS)) { // This is potentially a type-id, now check ambiguity with expression. - IToken typeIdEnd= mark(); + IToken typeIdEnd = mark(); IASTNamedTypeSpecifier namedTypeSpec = null; IASTName name = null; try { @@ -797,9 +798,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { name = namedTypeSpec.getName(); if (name.contains(typeId)) { idExpression = setRange(getNodeFactory().newIdExpression(name), name); - + // If the name was one of the completion names, add it to the completion - // node again now that it has a new parent. This ensures that completion + // node again now that it has a new parent. This ensures that completion // proposals are offered for both contexts that the name appears in. ASTCompletionNode completionNode = (ASTCompletionNode) getCompletionNode(); if (completionNode != null && completionNode.containsName(name)) { @@ -813,7 +814,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // the argument. if (idExpression == null) backup(argStart); - IASTExpression expression = expression(ExprKind.eAssignment, BinaryExprCtx.eInTemplateID, idExpression, strat); + IASTExpression expression = expression(ExprKind.eAssignment, BinaryExprCtx.eInTemplateID, idExpression, + strat); // At this point we have a valid type-id and a valid expression. // We prefer the longer one. @@ -861,33 +863,33 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Not a type-id, parse as expression. backup(argStart); ((TemplateIdStrategy) strat).backupToBranchPoint(markBranchPoint); - IASTExpression expr= expression(ExprKind.eAssignment, BinaryExprCtx.eInTemplateID, null, strat); + IASTExpression expr = expression(ExprKind.eAssignment, BinaryExprCtx.eInTemplateID, null, strat); if (LT(1) == IToken.tELLIPSIS) { - expr= addPackExpansion(expr, consume()); + expr = addPackExpansion(expr, consume()); } return expr; } private void addPackExpansion(ICPPASTTypeId typeId, IToken consume) { - final int endOffset= consume.getEndOffset(); + final int endOffset = consume.getEndOffset(); adjustEndOffset(typeId, endOffset); typeId.setIsPackExpansion(true); } private IASTExpression addPackExpansion(IASTExpression expr, IToken ellipsis) { - IASTExpression result= getNodeFactory().newPackExpansionExpression(expr); + IASTExpression result = getNodeFactory().newPackExpansionExpression(expr); return setRange(result, expr, ellipsis.getEndOffset()); } private IASTName operatorId() throws BacktrackException, EndOfFileException { final IToken firstToken = consume(IToken.t_operator); - int endOffset= firstToken.getEndOffset(); + int endOffset = firstToken.getEndOffset(); IASTTypeId typeId = null; OverloadableOperator op = null; - final int lt1= LT(1); + final int lt1 = LT(1); switch (lt1) { case IToken.tLPAREN: - op = OverloadableOperator.PAREN; // operator () + op = OverloadableOperator.PAREN; // operator () consume(); endOffset = consume(IToken.tRPAREN).getEndOffset(); break; @@ -899,20 +901,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_new: case IToken.t_delete: if (LT(2) == IToken.tLBRACKET) { - op= lt1 == IToken.t_new ? OverloadableOperator.NEW_ARRAY : OverloadableOperator.DELETE_ARRAY; + op = lt1 == IToken.t_new ? OverloadableOperator.NEW_ARRAY : OverloadableOperator.DELETE_ARRAY; consume(); consume(); - endOffset= consume(IToken.tRBRACKET).getEndOffset(); + endOffset = consume(IToken.tRBRACKET).getEndOffset(); } else { - IToken t= consume(); - endOffset= t.getEndOffset(); - op= OverloadableOperator.valueOf(t); + IToken t = consume(); + endOffset = t.getEndOffset(); + op = OverloadableOperator.valueOf(t); } break; case IToken.tGT_in_SHIFTR: consume(); - endOffset= consume(IToken.tGT_in_SHIFTR).getEndOffset(); - op= OverloadableOperator.SHIFTR; + endOffset = consume(IToken.tGT_in_SHIFTR).getEndOffset(); + op = OverloadableOperator.SHIFTR; break; case IToken.tSTRING: // User defined literal T operator "" SUFFIX { @@ -950,21 +952,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; } default: - op= OverloadableOperator.valueOf(LA(1)); + op = OverloadableOperator.valueOf(LA(1)); if (op != null) { - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } break; } if (op != null) { - IASTName name= getNodeFactory().newOperatorName(op.toCharArray()); + IASTName name = getNodeFactory().newOperatorName(op.toCharArray()); setRange(name, firstToken.getOffset(), endOffset); return name; } // must be a conversion function - typeId= typeId(DeclarationOptions.TYPEID_CONVERSION); + typeId = typeId(DeclarationOptions.TYPEID_CONVERSION); IASTName name = getNodeFactory().newConversionName(typeId); setRange(name, firstToken.getOffset(), calculateEndOffset(typeId)); @@ -976,7 +978,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * template-id an ambiguous template-id (one where the '<' could be a greater sign) or * else where. */ - private enum BinaryExprCtx {eInTemplateID, eNotInTemplateID} + private enum BinaryExprCtx { + eInTemplateID, eNotInTemplateID + } @Override protected ICPPASTExpression expression() throws BacktrackException, EndOfFileException { @@ -988,74 +992,75 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return expression(ExprKind.eConstant, BinaryExprCtx.eNotInTemplateID, null, null); } - private ICPPASTExpression expression(final ExprKind kind, final BinaryExprCtx ctx, IASTInitializerClause expr, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { - final boolean allowComma= kind == ExprKind.eExpression; - boolean allowAssignment= kind != ExprKind.eConstant; + private ICPPASTExpression expression(final ExprKind kind, final BinaryExprCtx ctx, IASTInitializerClause expr, + ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + final boolean allowComma = kind == ExprKind.eExpression; + boolean allowAssignment = kind != ExprKind.eConstant; if (allowAssignment && LT(1) == IToken.t_throw) { return throwExpression(); } - final int startOffset= expr != null ? ((ASTNode) expr).getOffset() : LA(1).getOffset(); + final int startOffset = expr != null ? ((ASTNode) expr).getOffset() : LA(1).getOffset(); int lt1; - int conditionCount= 0; - BinaryOperator lastOperator= null; - NameOrTemplateIDVariants variants= null; + int conditionCount = 0; + BinaryOperator lastOperator = null; + NameOrTemplateIDVariants variants = null; - IToken variantMark= mark(); + IToken variantMark = mark(); if (expr == null) { Object e = castExpressionForBinaryExpression(strat); if (e instanceof IASTExpression) { - expr= (IASTExpression) e; + expr = (IASTExpression) e; } else { - variants= new NameOrTemplateIDVariants(); + variants = new NameOrTemplateIDVariants(); final Variant variant = (Variant) e; - expr= variant.getExpression(); + expr = variant.getExpression(); variants.addBranchPoint(variant.getNext(), null, allowAssignment, conditionCount); } } - boolean stopWithNextOperator= false; + boolean stopWithNextOperator = false; castExprLoop: for (;;) { // Typically after a binary operator there cannot be a throw expression - boolean allowThrow= false; + boolean allowThrow = false; // Brace initializers are allowed on the right hand side of an expression - boolean allowBraceInitializer= false; + boolean allowBraceInitializer = false; - boolean doneExpression= false; - BacktrackException failure= null; - final int opOffset= LA().getOffset(); - lt1= stopWithNextOperator ? IToken.tSEMI : LT(1); + boolean doneExpression = false; + BacktrackException failure = null; + final int opOffset = LA().getOffset(); + lt1 = stopWithNextOperator ? IToken.tSEMI : LT(1); switch (lt1) { case IToken.tQUESTION: conditionCount++; // <logical-or> ? <expression> : <assignment-expression> // Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 25, 0); - allowAssignment= true; // assignment expressions will be subsumed by the conditional expression - allowThrow= true; + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 25, 0); + allowAssignment = true; // assignment expressions will be subsumed by the conditional expression + allowThrow = true; break; case IToken.tCOLON: if (--conditionCount < 0) { - doneExpression= true; + doneExpression = true; } else { // <logical-or> ? <expression> : <assignment-expression> // Precedence: 0 is lower than precedence of expression; 15 is lower than precedence of assignment; - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 0, 15); - allowAssignment= true; // assignment expressions will be subsumed by the conditional expression - allowThrow= true; + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 0, 15); + allowAssignment = true; // assignment expressions will be subsumed by the conditional expression + allowThrow = true; } break; case IToken.tCOMMA: - allowThrow= true; + allowThrow = true; if (!allowComma && conditionCount == 0) { - doneExpression= true; + doneExpression = true; } else { // Lowest precedence except inside the conditional expression - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 10, 11); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 10, 11); } break; @@ -1071,36 +1076,36 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tXORASSIGN: case IToken.tBITORASSIGN: if (!allowAssignment && conditionCount == 0) { - doneExpression= true; + doneExpression = true; } else { // Assignments group right to left - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 21, 20); - allowBraceInitializer= true; + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 21, 20); + allowBraceInitializer = true; } break; case IToken.tOR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 30, 31); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 30, 31); break; case IToken.tAND: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 40, 41); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 40, 41); break; case IToken.tBITOR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 50, 51); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 50, 51); break; case IToken.tXOR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 60, 61); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 60, 61); break; case IToken.tAMPER: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 70, 71); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 70, 71); break; case IToken.tEQUAL: case IToken.tNOTEQUAL: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 80, 81); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 80, 81); break; case IToken.tGT: if (ctx == BinaryExprCtx.eInTemplateID) { - doneExpression= true; + doneExpression = true; break; } //$FALL-THROUGH$ @@ -1109,42 +1114,42 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tGTEQUAL: case IGCCToken.tMAX: case IGCCToken.tMIN: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 90, 91); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 90, 91); break; case IToken.tGT_in_SHIFTR: if (ctx == BinaryExprCtx.eInTemplateID) { - doneExpression= true; + doneExpression = true; break; } if (LT(2) != IToken.tGT_in_SHIFTR) { IToken token = LA(1); backtrack.initialize(token.getOffset(), token.getLength()); - failure= backtrack; + failure = backtrack; break; } - lt1= IToken.tSHIFTR; // convert back + lt1 = IToken.tSHIFTR; // convert back consume(); // consume the extra token //$FALL-THROUGH$ case IToken.tSHIFTL: case IToken.tSHIFTR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 100, 101); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 100, 101); break; case IToken.tPLUS: case IToken.tMINUS: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 110, 111); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 110, 111); break; case IToken.tSTAR: case IToken.tDIV: case IToken.tMOD: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 120, 121); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 120, 121); break; case IToken.tDOTSTAR: case IToken.tARROWSTAR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 130, 131); + lastOperator = new BinaryOperator(lastOperator, expr, lt1, 130, 131); break; default: - doneExpression= true; + doneExpression = true; break; } @@ -1154,7 +1159,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (variants != null && !variants.hasRightBound(opOffset)) { // We have a longer variant, ignore this one. backtrack.initialize(opOffset, 1); - failure= backtrack; + failure = backtrack; } else { break castExprLoop; } @@ -1168,62 +1173,62 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (failure == null && !doneExpression) { // Determine next cast-expression consume(); // consumes the operator - stopWithNextOperator= false; + stopWithNextOperator = false; try { if (lt1 == IToken.tQUESTION && LT(1) == IToken.tCOLON) { // Missing sub-expression after '?' (gnu-extension) - expr= null; + expr = null; } else if (allowThrow && LT(1) == IToken.t_throw) { // Throw expression - expr= throwExpression(); - lt1= LT(1); + expr = throwExpression(); + lt1 = LT(1); if (lt1 != IToken.tCOLON && lt1 != IToken.tCOMMA) - stopWithNextOperator= true; + stopWithNextOperator = true; } else if (allowBraceInitializer && LT(1) == IToken.tLBRACE) { // Brace initializer - expr= bracedInitList(true, false); - lt1= LT(1); + expr = bracedInitList(true, false); + lt1 = LT(1); if (lt1 != IToken.tCOLON && lt1 != IToken.tCOMMA) - stopWithNextOperator= true; + stopWithNextOperator = true; } else { Object e = castExpressionForBinaryExpression(strat); if (e instanceof IASTExpression) { - expr= (IASTExpression) e; + expr = (IASTExpression) e; } else { final Variant ae = (Variant) e; - expr= ae.getExpression(); + expr = ae.getExpression(); if (variants == null) - variants= new NameOrTemplateIDVariants(); + variants = new NameOrTemplateIDVariants(); variants.addBranchPoint(ae.getNext(), lastOperator, allowAssignment, conditionCount); } } continue castExprLoop; } catch (BacktrackException e) { - failure= e; + failure = e; } } // We need a new variant - Variant variant= variants == null ? null : variants.selectFallback(); + Variant variant = variants == null ? null : variants.selectFallback(); if (variant == null) { if (failure != null) throw failure; throwBacktrack(LA(1)); } else { // Restore variant and continue - BranchPoint varPoint= variant.getOwner(); - allowAssignment= varPoint.isAllowAssignment(); - conditionCount= varPoint.getConditionCount(); - lastOperator= varPoint.getLeftOperator(); - expr= variant.getExpression(); + BranchPoint varPoint = variant.getOwner(); + allowAssignment = varPoint.isAllowAssignment(); + conditionCount = varPoint.getConditionCount(); + lastOperator = varPoint.getLeftOperator(); + expr = variant.getExpression(); backup(variantMark); - int offset= variant.getRightOffset(); + int offset = variant.getRightOffset(); while (LA().getOffset() < offset) { consume(); } - variantMark= mark(); + variantMark = mark(); } } @@ -1236,7 +1241,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { variants.closeVariants(LA(1).getOffset(), end); variants.removeInvalid(end); if (!variants.isEmpty()) { - CPPASTTemplateIDAmbiguity result = new CPPASTTemplateIDAmbiguity(this, end, variants.getOrderedBranchPoints()); + CPPASTTemplateIDAmbiguity result = new CPPASTTemplateIDAmbiguity(this, end, + variants.getOrderedBranchPoints()); setRange(result, startOffset, calculateEndOffset(expr)); return result; } @@ -1251,27 +1257,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return castExpression(CastExprCtx.eDirectlyInBExpr, s); } - TemplateIdStrategy strat= new TemplateIdStrategy(); - Variant variants= null; - IASTExpression singleResult= null; - IASTName[] firstNames= null; + TemplateIdStrategy strat = new TemplateIdStrategy(); + Variant variants = null; + IASTExpression singleResult = null; + IASTName[] firstNames = null; - final IToken mark= mark(); - IToken lastToken= null; + final IToken mark = mark(); + IToken lastToken = null; while (true) { try { IASTExpression e = castExpression(CastExprCtx.eDirectlyInBExpr, strat); if (variants == null) { if (singleResult == null || lastToken == null) { - singleResult= e; - firstNames= strat.getTemplateNames(); + singleResult = e; + firstNames = strat.getTemplateNames(); } else { - variants= new Variant(null, singleResult, firstNames, lastToken.getOffset()); - singleResult= null; - firstNames= null; + variants = new Variant(null, singleResult, firstNames, lastToken.getOffset()); + singleResult = null; + firstNames = null; } } - lastToken= LA(); + lastToken = LA(); if (variants != null) { variants = new Variant(variants, e, strat.getTemplateNames(), lastToken.getOffset()); } @@ -1293,7 +1299,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } @Override - protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset) { + protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, + int lastOffset) { IASTBinaryExpression result = getNodeFactory().newBinaryExpression(operator, expr1, expr2); int o = ((ASTNode) expr1).getOffset(); ((ASTNode) result).setOffsetAndLength(o, lastOffset - o); @@ -1309,10 +1316,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(throwToken); consume(); } - int o = throwExpression != null ? - calculateEndOffset(throwExpression) : throwToken.getEndOffset(); - return (ICPPASTExpression) buildUnaryExpression(ICPPASTUnaryExpression.op_throw, - throwExpression, throwToken.getOffset(), o); // fix for 95225 + int o = throwExpression != null ? calculateEndOffset(throwExpression) : throwToken.getEndOffset(); + return (ICPPASTExpression) buildUnaryExpression(ICPPASTUnaryExpression.op_throw, throwExpression, + throwToken.getOffset(), o); // fix for 95225 } protected IASTExpression deleteExpression() throws EndOfFileException, BacktrackException { @@ -1335,7 +1341,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } IASTExpression castExpression = castExpression(CastExprCtx.eNotInBExpr, null); ICPPASTDeleteExpression deleteExpression = getNodeFactory().newDeleteExpression(castExpression); - ((ASTNode) deleteExpression).setOffsetAndLength(startingOffset, calculateEndOffset(castExpression) - startingOffset); + ((ASTNode) deleteExpression).setOffsetAndLength(startingOffset, + calculateEndOffset(castExpression) - startingOffset); deleteExpression.setIsGlobal(global); deleteExpression.setIsVectored(vectored); return deleteExpression; @@ -1350,7 +1357,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ protected IASTExpression newExpression() throws BacktrackException, EndOfFileException { IToken la = LA(1); - int offset= la.getOffset(); + int offset = la.getOffset(); final boolean isGlobal = la.getType() == IToken.tCOLONCOLON; if (isGlobal) { @@ -1361,78 +1368,78 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(); // consider placement first (P) ... - List<ICPPASTInitializerClause> plcmt= null; - IASTTypeId typeid= null; - boolean isNewTypeId= true; - IASTInitializer init= null; - int endOffset= 0; - IToken mark= mark(); - IToken end= null; + List<ICPPASTInitializerClause> plcmt = null; + IASTTypeId typeid = null; + boolean isNewTypeId = true; + IASTInitializer init = null; + int endOffset = 0; + IToken mark = mark(); + IToken end = null; try { - plcmt= expressionList(); - endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + plcmt = expressionList(); + endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); - final int lt1= LT(1); + final int lt1 = LT(1); if (lt1 == IToken.tEOC) { return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); } if (lt1 == IToken.tLPAREN) { // (P)(T) ... - isNewTypeId= false; + isNewTypeId = false; consume(IToken.tLPAREN); - typeid= typeId(DeclarationOptions.TYPEID); - endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + typeid = typeId(DeclarationOptions.TYPEID); + endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); } else { // (P) T ... - typeid= typeId(DeclarationOptions.TYPEID_NEW); - endOffset= calculateEndOffset(typeid); + typeid = typeId(DeclarationOptions.TYPEID_NEW); + endOffset = calculateEndOffset(typeid); } - end= LA(1); + end = LA(1); } catch (BacktrackException e) { - plcmt= null; - typeid= null; + plcmt = null; + typeid = null; } if (typeid != null && plcmt != null) { // (P)(T)(I) or (P) T (I) - int lt1= LT(1); + int lt1 = LT(1); if (lt1 == IToken.tEOC) return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { - init= bracedOrCtorStyleInitializer(); - endOffset= calculateEndOffset(init); + init = bracedOrCtorStyleInitializer(); + endOffset = calculateEndOffset(init); return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); } } // (T) ... backup(mark); - IASTTypeId typeid2= null; - IASTInitializer init2= null; + IASTTypeId typeid2 = null; + IASTInitializer init2 = null; int endOffset2; try { - typeid2= typeId(DeclarationOptions.TYPEID); - endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + typeid2 = typeId(DeclarationOptions.TYPEID); + endOffset2 = consumeOrEOC(IToken.tRPAREN).getEndOffset(); - final int lt1= LT(1); + final int lt1 = LT(1); if (lt1 == IToken.tEOC) return newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { - if (plcmt != null && - ASTQueries.findTypeRelevantDeclarator(typeid2.getAbstractDeclarator()) instanceof IASTArrayDeclarator) { + if (plcmt != null && ASTQueries.findTypeRelevantDeclarator( + typeid2.getAbstractDeclarator()) instanceof IASTArrayDeclarator) { throwBacktrack(LA(1)); } // (T)(I) - init2= bracedOrCtorStyleInitializer(); - endOffset2= calculateEndOffset(init2); + init2 = bracedOrCtorStyleInitializer(); + endOffset2 = calculateEndOffset(init2); } } catch (BacktrackException e) { if (plcmt == null) throw e; - endOffset2= -1; + endOffset2 = -1; } if (plcmt == null || endOffset2 > endOffset) @@ -1444,9 +1451,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // ambiguity: - IASTExpression ex1= newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); - IASTExpression ex2= newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); - IASTAmbiguousExpression ambiguity= createAmbiguousExpression(); + IASTExpression ex1 = newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); + IASTExpression ex2 = newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); + IASTAmbiguousExpression ambiguity = createAmbiguousExpression(); ambiguity.addExpression(ex1); ambiguity.addExpression(ex2); ((ASTNode) ambiguity).setOffsetAndLength((ASTNode) ex1); @@ -1456,21 +1463,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // T ... final IASTTypeId typeid = typeId(DeclarationOptions.TYPEID_NEW); int endOffset = calculateEndOffset(typeid); - IASTInitializer init= null; - final int lt1= LT(1); + IASTInitializer init = null; + final int lt1 = LT(1); if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { // T(I) - init= bracedOrCtorStyleInitializer(); - endOffset= calculateEndOffset(init); + init = bracedOrCtorStyleInitializer(); + endOffset = calculateEndOffset(init); } return newExpression(isGlobal, null, typeid, true, init, offset, endOffset); } - private IASTExpression newExpression(boolean isGlobal, List<? extends IASTInitializerClause> plcmt, IASTTypeId typeid, - boolean isNewTypeId, IASTInitializer init, int offset, int endOffset) { - IASTInitializerClause[] plcmtArray= null; + private IASTExpression newExpression(boolean isGlobal, List<? extends IASTInitializerClause> plcmt, + IASTTypeId typeid, boolean isNewTypeId, IASTInitializer init, int offset, int endOffset) { + IASTInitializerClause[] plcmtArray = null; if (plcmt != null && !plcmt.isEmpty()) { - plcmtArray= plcmt.toArray(new IASTInitializerClause[plcmt.size()]); + plcmtArray = plcmt.toArray(new IASTInitializerClause[plcmt.size()]); } ICPPASTNewExpression result = getNodeFactory().newNewExpression(plcmtArray, init, typeid); result.setIsGlobal(isGlobal); @@ -1480,7 +1487,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } @Override - protected IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + protected IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { switch (LT(1)) { case IToken.tSTAR: return unaryExpression(IASTUnaryExpression.op_star, ctx, strat); @@ -1515,11 +1523,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } case IToken.t_sizeof: if (LTcatchEOF(2) == IToken.tELLIPSIS) { - int offset= consume().getOffset(); // sizeof - consume(); // ... + int offset = consume().getOffset(); // sizeof + consume(); // ... return parseTypeidInParenthesisOrUnaryExpression(true, offset, - IASTTypeIdExpression.op_sizeofParameterPack, - IASTUnaryExpression.op_sizeofParameterPack, ctx, strat); + IASTTypeIdExpression.op_sizeofParameterPack, IASTUnaryExpression.op_sizeofParameterPack, ctx, + strat); } return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat); @@ -1560,8 +1568,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private IASTExpression parseTypeTrait() throws EndOfFileException, BacktrackException { - IToken first= consume(); - final boolean isBinary= isBinaryTrait(first); + IToken first = consume(); + final boolean isBinary = isBinaryTrait(first); final boolean isNary = isNaryTrait(first); consume(IToken.tLPAREN); @@ -1586,15 +1594,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } operands = ArrayUtil.removeNulls(operands); } - int endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); IASTExpression result; if (isNary) { - result= getNodeFactory().newNaryTypeIdExpression(getNaryTypeTraitOperator(first), operands); + result = getNodeFactory().newNaryTypeIdExpression(getNaryTypeTraitOperator(first), operands); } else if (isBinary) { - result= getNodeFactory().newBinaryTypeIdExpression(getBinaryTypeTraitOperator(first), operands[0], + result = getNodeFactory().newBinaryTypeIdExpression(getBinaryTypeTraitOperator(first), operands[0], operands[1]); } else { - result= getNodeFactory().newTypeIdExpression(getUnaryTypeTraitOperator(first), operands[0]); + result = getNodeFactory().newTypeIdExpression(getUnaryTypeTraitOperator(first), operands[0]); } return setRange(result, first.getOffset(), endOffset); } @@ -1715,7 +1723,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * typeid (expression) * typeid (type-id) */ - private IASTExpression postfixExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + private IASTExpression postfixExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { IASTExpression firstExpression = null; boolean isTemplate = false; int offset; @@ -1743,11 +1752,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_noexcept: // 'noexcept' (expression) - offset= consume().getOffset(); // noexcept - consume(IToken.tLPAREN); // ( - firstExpression= expression(); - firstExpression= getNodeFactory().newUnaryExpression(IASTUnaryExpression.op_noexcept, firstExpression); - final int endOffset = consume(IToken.tRPAREN).getEndOffset(); //) + offset = consume().getOffset(); // noexcept + consume(IToken.tLPAREN); // ( + firstExpression = expression(); + firstExpression = getNodeFactory().newUnaryExpression(IASTUnaryExpression.op_noexcept, firstExpression); + final int endOffset = consume(IToken.tRPAREN).getEndOffset(); //) setRange(firstExpression, offset, endOffset); break; @@ -1759,11 +1768,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { if (canBeCompoundLiteral()) { offset = consume().getOffset(); - IASTTypeId t= typeId(DeclarationOptions.TYPEID); + IASTTypeId t = typeId(DeclarationOptions.TYPEID); consume(IToken.tRPAREN); if (LT(1) == IToken.tLBRACE) { IASTInitializer i = bracedInitList(false, false); - firstExpression= getNodeFactory().newTypeIdInitializerExpression(t, i); + firstExpression = getNodeFactory().newTypeIdInitializerExpression(t, i); setRange(firstExpression, offset, calculateEndOffset(i)); break; } @@ -1771,7 +1780,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } catch (BacktrackException bt) { } backup(m); - firstExpression= primaryExpression(ctx, strat); + firstExpression = primaryExpression(ctx, strat); break; // typename-specifier (expression-list_opt) @@ -1811,7 +1820,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { firstExpression = primaryExpression(ctx, strat); if (firstExpression instanceof IASTIdExpression && LT(1) == IToken.tLBRACE) { IASTName name = ((IASTIdExpression) firstExpression).getName(); - ICPPASTDeclSpecifier declSpec= getNodeFactory().newTypedefNameSpecifier(name); + ICPPASTDeclSpecifier declSpec = getNodeFactory().newTypedefNameSpecifier(name); firstExpression = simpleTypeConstructorExpression(setRange(declSpec, name)); } break; @@ -1825,13 +1834,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tLBRACKET); IASTInitializerClause expression; if (LT(1) == IToken.tLBRACE) { - expression= bracedInitList(false, false); + expression = bracedInitList(false, false); } else { - expression= expression(); + expression = expression(); } - int endOffset= consumeOrEOC(IToken.tRBRACKET).getEndOffset(); - IASTArraySubscriptExpression s = getNodeFactory().newArraySubscriptExpression(firstExpression, expression); - firstExpression= setRange(s, firstExpression, endOffset); + int endOffset = consumeOrEOC(IToken.tRBRACKET).getEndOffset(); + IASTArraySubscriptExpression s = getNodeFactory().newArraySubscriptExpression(firstExpression, + expression); + firstExpression = setRange(s, firstExpression, endOffset); break; case IToken.tLPAREN: // postfix-expression (expression-list_opt) @@ -1839,7 +1849,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tLPAREN); IASTInitializerClause[] initArray; if (LT(1) == IToken.tRPAREN) { - initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY; + initArray = IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { final List<ICPPASTInitializerClause> exprList = expressionList(); initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]); @@ -1847,7 +1857,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); IASTFunctionCallExpression fce = getNodeFactory().newFunctionCallExpression(firstExpression, initArray); - firstExpression= setRange(fce, firstExpression, endOffset); + firstExpression = setRange(fce, firstExpression, endOffset); break; case IToken.tINCR: @@ -1878,8 +1888,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTFieldReference fieldReference = getNodeFactory().newFieldReference(name, firstExpression); fieldReference.setIsPointerDereference(false); fieldReference.setIsTemplate(isTemplate); - ((ASTNode) fieldReference).setOffsetAndLength( - ((ASTNode) firstExpression).getOffset(), + ((ASTNode) fieldReference).setOffsetAndLength(((ASTNode) firstExpression).getOffset(), calculateEndOffset(name) - ((ASTNode) firstExpression).getOffset()); firstExpression = fieldReference; break; @@ -1901,8 +1910,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { fieldReference = getNodeFactory().newFieldReference(name, firstExpression); fieldReference.setIsPointerDereference(true); fieldReference.setIsTemplate(isTemplate); - ((ASTNode) fieldReference).setOffsetAndLength( - ((ASTNode) firstExpression).getOffset(), + ((ASTNode) fieldReference).setOffsetAndLength(((ASTNode) firstExpression).getOffset(), calculateEndOffset(name) - ((ASTNode) firstExpression).getOffset()); firstExpression = fieldReference; break; @@ -1918,12 +1926,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } @Override - protected IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, IASTCastExpression castExpr) { + protected IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, + IASTCastExpression castExpr) { return new CPPASTAmbiguousBinaryVsCastExpression(binary, castExpr); } @Override - protected IASTAmbiguousExpression createAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, IASTFunctionCallExpression funcCall) { + protected IASTAmbiguousExpression createAmbiguousCastVsFunctionCallExpression(IASTCastExpression castExpr, + IASTFunctionCallExpression funcCall) { return new CPPASTAmbiguousCastVsFunctionCallExpression(castExpr, funcCall); } @@ -1931,15 +1941,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return new CPPASTAmbiguousTemplateArgument(); } - private IASTExpression simpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec) throws EndOfFileException, BacktrackException { + private IASTExpression simpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec) + throws EndOfFileException, BacktrackException { IASTInitializer initializer = bracedOrCtorStyleInitializer(); - ICPPASTSimpleTypeConstructorExpression result = getNodeFactory().newSimpleTypeConstructorExpression( - declSpec, initializer); + ICPPASTSimpleTypeConstructorExpression result = getNodeFactory().newSimpleTypeConstructorExpression(declSpec, + initializer); return setRange(result, declSpec, calculateEndOffset(initializer)); } @Override - protected IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { + protected IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) + throws EndOfFileException, BacktrackException { IToken t = null; IASTLiteralExpression literalExpr = null; IASTLiteralExpression literalExprWithRange = null; @@ -1947,12 +1959,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { switch (LT(1)) { case IToken.tINTEGER: t = consume(); - literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage(), additionalNumericalSuffixes); + literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage(), + additionalNumericalSuffixes); literalExprWithRange = setRange(literalExpr, t.getOffset(), t.getEndOffset()); break; case IToken.tFLOATINGPT: t = consume(); - literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage(), additionalNumericalSuffixes); + literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage(), + additionalNumericalSuffixes); literalExprWithRange = setRange(literalExpr, t.getOffset(), t.getEndOffset()); break; case IToken.tSTRING: @@ -1968,8 +1982,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tUTF32CHAR: case IToken.tUSER_DEFINED_CHAR_LITERAL: t = consume(); - literalExpr = getNodeFactory().newLiteralExpression( - IASTLiteralExpression.lk_char_constant, t.getImage()); + literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_char_constant, t.getImage()); literalExprWithRange = setRange(literalExpr, t.getOffset(), t.getEndOffset()); break; case IToken.t_false: @@ -1981,7 +1994,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_true, t.getImage()); return setRange(literalExpr, t.getOffset(), t.getEndOffset()); case IToken.t_nullptr: - t= consume(); + t = consume(); literalExpr = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_nullptr, t.getImage()); return setRange(literalExpr, t.getOffset(), t.getEndOffset()); @@ -1994,8 +2007,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return compoundStatementExpression(); } t = consume(); - int finalOffset= 0; - IASTExpression lhs= expression(ExprKind.eExpression, BinaryExprCtx.eNotInTemplateID, null, null); // instead of expression(), to keep the stack smaller + int finalOffset = 0; + IASTExpression lhs = expression(ExprKind.eExpression, BinaryExprCtx.eNotInTemplateID, null, null); // instead of expression(), to keep the stack smaller switch (LT(1)) { case IToken.tRPAREN: case IToken.tEOC: @@ -2058,31 +2071,32 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: throwBacktrack(LA(1)); } - IToken t= consume(); - ICPPASTLiteralExpression r= getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_string_literal, t.getImage()); + IToken t = consume(); + ICPPASTLiteralExpression r = getNodeFactory().newLiteralExpression(IASTLiteralExpression.lk_string_literal, + t.getImage()); return setRange(r, t.getOffset(), t.getEndOffset()); } private IASTExpression lambdaExpression() throws EndOfFileException, BacktrackException { - final int offset= LA().getOffset(); + final int offset = LA().getOffset(); - ICPPASTLambdaExpression lambdaExpr= getNodeFactory().newLambdaExpression(); + ICPPASTLambdaExpression lambdaExpr = getNodeFactory().newLambdaExpression(); // Lambda introducer consume(IToken.tLBRACKET); - boolean needComma= false; + boolean needComma = false; switch (LT(1)) { case IToken.tASSIGN: lambdaExpr.setCaptureDefault(CaptureDefault.BY_COPY); consume(); - needComma= true; + needComma = true; break; case IToken.tAMPER: final int lt2 = LT(2); if (lt2 == IToken.tCOMMA || lt2 == IToken.tRBRACKET) { lambdaExpr.setCaptureDefault(CaptureDefault.BY_REFERENCE); consume(); - needComma= true; + needComma = true; } break; } @@ -2099,9 +2113,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tCOMMA); } - ICPPASTCapture cap= capture(); + ICPPASTCapture cap = capture(); lambdaExpr.addCapture(cap); - needComma= true; + needComma = true; } if (LT(1) == IToken.tLPAREN) { @@ -2116,8 +2130,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return setRange(lambdaExpr, offset, calculateEndOffset(body)); } - private ICPPASTInitCapture createInitCapture(IASTName identifier, IASTInitializer initializer, boolean isReference, int offset) - throws EndOfFileException, BacktrackException { + private ICPPASTInitCapture createInitCapture(IASTName identifier, IASTInitializer initializer, boolean isReference, + int offset) throws EndOfFileException, BacktrackException { ICPPASTDeclarator declarator = getNodeFactory().newDeclarator(identifier); declarator.setInitializer(initializer); if (isReference) { @@ -2154,7 +2168,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { result.setIsByReference(referenceCapture); setRange(result, offset, calculateEndOffset(identifier)); - switch(LT(1)) { + switch (LT(1)) { case IToken.tASSIGN: result = createInitCapture(identifier, equalsInitalizerClause(false), referenceCapture, offset); break; @@ -2165,7 +2179,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (LT(1) == IToken.tELLIPSIS) { - // Note this will probably change with C++20 such that the + // Note this will probably change with C++20 such that the // pack expansion of a CPPASTInitCapture will be part of the IASTDeclarator // and not the capture. [See: P0780R2] result.setIsPackExpansion(true); @@ -2177,7 +2191,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected IASTExpression specialCastExpression(int kind) throws EndOfFileException, BacktrackException { final int offset = LA(1).getOffset(); - final int optype= consume().getType(); + final int optype = consume().getType(); consume(IToken.tLT); final IASTTypeId typeID = typeId(DeclarationOptions.TYPEID); final IToken gt = LA(1); @@ -2187,28 +2201,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(gt); } consumeOrEOC(IToken.tLPAREN); - IASTExpression operand= null; + IASTExpression operand = null; if (LT(1) != IToken.tEOC) { - operand= expression(); + operand = expression(); } - final int endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + final int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); int operator; switch (optype) { - case IToken.t_dynamic_cast: - operator = ICPPASTCastExpression.op_dynamic_cast; - break; - case IToken.t_static_cast: - operator = ICPPASTCastExpression.op_static_cast; - break; - case IToken.t_reinterpret_cast: - operator = ICPPASTCastExpression.op_reinterpret_cast; - break; - case IToken.t_const_cast: - operator = ICPPASTCastExpression.op_const_cast; - break; - default: - operator = IASTCastExpression.op_cast; - break; + case IToken.t_dynamic_cast: + operator = ICPPASTCastExpression.op_dynamic_cast; + break; + case IToken.t_static_cast: + operator = ICPPASTCastExpression.op_static_cast; + break; + case IToken.t_reinterpret_cast: + operator = ICPPASTCastExpression.op_reinterpret_cast; + break; + case IToken.t_const_cast: + operator = ICPPASTCastExpression.op_const_cast; + break; + default: + operator = IASTCastExpression.op_cast; + break; } return buildCastExpression(operator, typeID, operand, offset, endOffset); } @@ -2224,7 +2238,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ protected IASTDeclaration usingClause(List<IASTAttributeSpecifier> attributes) throws EndOfFileException, BacktrackException { - final int offset= consume().getOffset(); + final int offset = consume().getOffset(); if (LT(1) == IToken.t_namespace) { // using-directive @@ -2271,8 +2285,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * * @throws EndOfFileException */ - private IASTDeclaration aliasDeclaration(final int offset) throws EndOfFileException, - BacktrackException { + private IASTDeclaration aliasDeclaration(final int offset) throws EndOfFileException, BacktrackException { IToken identifierToken = consume(); IASTName aliasName = buildName(-1, identifierToken, false); @@ -2325,10 +2338,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * static_assert (constant-expression , string-literal); */ private ICPPASTStaticAssertDeclaration staticAssertDeclaration() throws EndOfFileException, BacktrackException { - int offset= consume(IToken.t_static_assert).getOffset(); + int offset = consume(IToken.t_static_assert).getOffset(); consume(IToken.tLPAREN); - IASTExpression e= constantExpression(); - int endOffset= calculateEndOffset(e); + IASTExpression e = constantExpression(); + int endOffset = calculateEndOffset(e); ICPPASTLiteralExpression message = null; if (LT(1) == IToken.tCOMMA) { consume(IToken.tCOMMA); @@ -2351,7 +2364,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * request for a backtrack */ protected ICPPASTLinkageSpecification linkageSpecification() throws EndOfFileException, BacktrackException { - int offset= consume().getOffset(); // t_extern + int offset = consume().getOffset(); // t_extern String spec = consume().getImage(); // tString ICPPASTLinkageSpecification linkage = getNodeFactory().newLinkageSpecification(spec); @@ -2378,10 +2391,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * request for a backtrack */ - protected IASTDeclaration templateDeclaration(DeclarationOptions option) throws EndOfFileException, BacktrackException { - final int offset= LA(1).getOffset(); + protected IASTDeclaration templateDeclaration(DeclarationOptions option) + throws EndOfFileException, BacktrackException { + final int offset = LA(1).getOffset(); boolean exported = false; - int explicitInstMod= 0; + int explicitInstMod = 0; switch (LT(1)) { case IToken.t_export: exported = true; @@ -2389,15 +2403,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; case IToken.t_extern: consume(); - explicitInstMod= ICPPASTExplicitTemplateInstantiation.EXTERN; + explicitInstMod = ICPPASTExplicitTemplateInstantiation.EXTERN; break; case IToken.t_static: consume(); - explicitInstMod= ICPPASTExplicitTemplateInstantiation.STATIC; + explicitInstMod = ICPPASTExplicitTemplateInstantiation.STATIC; break; case IToken.t_inline: consume(); - explicitInstMod= ICPPASTExplicitTemplateInstantiation.INLINE; + explicitInstMod = ICPPASTExplicitTemplateInstantiation.INLINE; break; } @@ -2406,7 +2420,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) != IToken.tLT) { // explicit-instantiation IASTDeclaration d = declaration(option); - ICPPASTExplicitTemplateInstantiation ti= getNodeFactory().newExplicitTemplateInstantiation(d); + ICPPASTExplicitTemplateInstantiation ti = getNodeFactory().newExplicitTemplateInstantiation(d); ti.setModifier(explicitInstMod); setRange(ti, offset, calculateEndOffset(d)); return ti; @@ -2426,7 +2440,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return templateSpecialization; } - List<ICPPASTTemplateParameter> parms= outerTemplateParameterList(); + List<ICPPASTTemplateParameter> parms = outerTemplateParameterList(); if (LT(1) != IToken.tEOC) { consume(IToken.tGT, IToken.tGT_in_SHIFTR); } @@ -2456,17 +2470,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * request for a backtrack */ - protected List<ICPPASTTemplateParameter> outerTemplateParameterList() throws BacktrackException, EndOfFileException { - fTemplateParameterListStrategy= new TemplateIdStrategy(); + protected List<ICPPASTTemplateParameter> outerTemplateParameterList() + throws BacktrackException, EndOfFileException { + fTemplateParameterListStrategy = new TemplateIdStrategy(); try { List<ICPPASTTemplateParameter> result = new ArrayList<>(DEFAULT_PARM_LIST_SIZE); - IToken m= mark(); + IToken m = mark(); while (true) { try { return templateParameterList(result); } catch (BacktrackException e) { - if (!fTemplateParameterListStrategy.setNextAlternative(true /* previous alternative failed to parse */)) { - fTemplateParameterListStrategy= null; + if (!fTemplateParameterListStrategy + .setNextAlternative(true /* previous alternative failed to parse */)) { + fTemplateParameterListStrategy = null; throw e; } result.clear(); @@ -2474,15 +2490,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } } finally { - fTemplateParameterListStrategy= null; + fTemplateParameterListStrategy = null; } } private List<ICPPASTTemplateParameter> templateParameterList(List<ICPPASTTemplateParameter> result) throws EndOfFileException, BacktrackException { - boolean needComma= false; + boolean needComma = false; for (;;) { - final int lt1= LT(1); + final int lt1 = LT(1); if (lt1 == IToken.tGT || lt1 == IToken.tEOC || lt1 == IToken.tGT_in_SHIFTR) { return result; } @@ -2490,7 +2506,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (needComma) { consume(IToken.tCOMMA); } else { - needComma= true; + needComma = true; } result.add(templateParameter()); @@ -2498,20 +2514,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private ICPPASTTemplateParameter templateParameter() throws EndOfFileException, BacktrackException { - final int lt1= LT(1); - final IToken start= mark(); + final int lt1 = LT(1); + final IToken start = mark(); if (lt1 == IToken.t_class || lt1 == IToken.t_typename) { try { int type = (lt1 == IToken.t_class ? ICPPASTSimpleTypeTemplateParameter.st_class : ICPPASTSimpleTypeTemplateParameter.st_typename); - boolean parameterPack= false; + boolean parameterPack = false; IASTName identifierName = null; IASTTypeId defaultValue = null; int endOffset = consume().getEndOffset(); if (LT(1) == IToken.tELLIPSIS) { - parameterPack= true; - endOffset= consume().getOffset(); + parameterPack = true; + endOffset = consume().getOffset(); } if (LT(1) == IToken.tIDENTIFIER) { // optional identifier identifierName = identifier(); @@ -2534,7 +2550,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tEOC: case IToken.tGT_in_SHIFTR: case IToken.tCOMMA: - ICPPASTSimpleTypeTemplateParameter tpar = getNodeFactory().newSimpleTypeTemplateParameter(type, identifierName, defaultValue); + ICPPASTSimpleTypeTemplateParameter tpar = getNodeFactory().newSimpleTypeTemplateParameter(type, + identifierName, defaultValue); tpar.setIsParameterPack(parameterPack); setRange(tpar, start.getOffset(), endOffset); return tpar; @@ -2544,7 +2561,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Can be a non-type template parameter, see bug 333285 backup(start); } else if (lt1 == IToken.t_template) { - boolean parameterPack= false; + boolean parameterPack = false; IASTName identifierName = null; IASTExpression defaultValue = null; @@ -2554,15 +2571,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tGT, IToken.tGT_in_SHIFTR); int kind = LT(1); - if(kind != IToken.t_class && kind != IToken.t_typename) { + if (kind != IToken.t_class && kind != IToken.t_typename) { throw backtrack; } int endOffset = consume(kind).getEndOffset(); if (LT(1) == IToken.tELLIPSIS) { - parameterPack= true; - endOffset= consume().getOffset(); + parameterPack = true; + endOffset = consume().getOffset(); } if (LT(1) == IToken.tIDENTIFIER) { // optional identifier @@ -2580,9 +2597,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { identifierName = getNodeFactory().newName(); } - ICPPASTTemplatedTypeTemplateParameter tpar = getNodeFactory().newTemplatedTypeTemplateParameter(identifierName, defaultValue); + ICPPASTTemplatedTypeTemplateParameter tpar = getNodeFactory() + .newTemplatedTypeTemplateParameter(identifierName, defaultValue); tpar.setIsParameterPack(parameterPack); - tpar.setParameterType(kind == IToken.t_class ? ICPPASTTemplatedTypeTemplateParameter.tt_class : ICPPASTTemplatedTypeTemplateParameter.tt_typename); + tpar.setParameterType(kind == IToken.t_class ? ICPPASTTemplatedTypeTemplateParameter.tt_class + : ICPPASTTemplatedTypeTemplateParameter.tt_typename); setRange(tpar, start.getOffset(), endOffset); for (int i = 0; i < tparList.size(); ++i) { @@ -2613,9 +2632,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTDeclaration declaration(DeclarationOptions option) throws EndOfFileException, BacktrackException { // Allow GNU-style attributes both before standard attribute / alignment specifiers, and after. - List<IASTAttributeSpecifier> attributes = __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + List<IASTAttributeSpecifier> attributes = __attribute_decl_seq(supportAttributeSpecifiers, + supportDeclspecSpecifiers); attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); - attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); + attributes = CollectionUtils.merge(attributes, + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); switch (LT(1)) { case IToken.t_asm: @@ -2644,9 +2665,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } break; case IToken.tSEMI: - IToken t= consume(); - IASTSimpleDeclSpecifier declspec= getNodeFactory().newSimpleDeclSpecifier(); - IASTSimpleDeclaration decl= getNodeFactory().newSimpleDeclaration(declspec); + IToken t = consume(); + IASTSimpleDeclSpecifier declspec = getNodeFactory().newSimpleDeclSpecifier(); + IASTSimpleDeclaration decl = getNodeFactory().newSimpleDeclaration(declspec); ((ASTNode) declspec).setOffsetAndLength(t.getOffset(), 0); ((ASTNode) decl).setOffsetAndLength(t.getOffset(), t.getLength()); return decl; @@ -2654,9 +2675,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_protected: case IToken.t_private: if (option == DeclarationOptions.CPP_MEMBER) { - t= consume(); - int key= t.getType(); - int endOffset= consume(IToken.tCOLON).getEndOffset(); + t = consume(); + int key = t.getType(); + int endOffset = consume(IToken.tCOLON).getEndOffset(); ICPPASTVisibilityLabel label = getNodeFactory().newVisibilityLabel(token2Visibility(key)); setRange(label, t.getOffset(), endOffset); return label; @@ -2669,8 +2690,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } catch (BacktrackException e) { if (option != DeclarationOptions.CPP_MEMBER || declarationMark == null) throw e; - BacktrackException orig= new BacktrackException(e); // copy the exception - IToken mark= mark(); + BacktrackException orig = new BacktrackException(e); // copy the exception + IToken mark = mark(); backup(declarationMark); try { return usingDeclaration(declarationMark.getOffset()); @@ -2690,13 +2711,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * request a backtrack */ protected IASTDeclaration namespaceDefinitionOrAlias() throws BacktrackException, EndOfFileException { - final int offset= LA().getOffset(); + final int offset = LA().getOffset(); int endOffset; - boolean isInline= false; + boolean isInline = false; if (LT(1) == IToken.t_inline) { consume(); - isInline= true; + isInline = true; } consume(IToken.t_namespace); @@ -2706,7 +2727,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTName name = null; if (LT(1) == IToken.tIDENTIFIER) { name = qualifiedName(); - endOffset= calculateEndOffset(name); + endOffset = calculateEndOffset(name); } else { name = getNodeFactory().newName(); } @@ -2728,7 +2749,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } ICPPASTName segment = (ICPPASTName) specifier; ICPPASTNamespaceDefinition ns = getNodeFactory().newNamespaceDefinition(segment); - if (outer == null || inner == null) { // second half of condition is just to avoid warning + if (outer == null || inner == null) { // second half of condition is just to avoid warning outer = ns; } else { inner.addDeclaration(ns); @@ -2738,7 +2759,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } IASTName lastName = name.getLastName(); ICPPASTNamespaceDefinition ns = getNodeFactory().newNamespaceDefinition(lastName); - if (outer == null || inner == null) { // second half of condition is just to avoid warning + if (outer == null || inner == null) { // second half of condition is just to avoid warning outer = ns; } else { inner.addDeclaration(ns); @@ -2762,13 +2783,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (LT(1) == IToken.tASSIGN) { - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); if (name.toString() == null || name instanceof ICPPASTQualifiedName) { throwBacktrack(offset, endOffset - offset); return null; } - IASTName qualifiedName= qualifiedName(); + IASTName qualifiedName = qualifiedName(); endOffset = consume(IToken.tSEMI).getEndOffset(); ICPPASTNamespaceAlias alias = getNodeFactory().newNamespaceAlias(name, qualifiedName); @@ -2787,12 +2808,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return attributes; } - protected List<IASTAttributeSpecifier> attributeSpecifierSeq() throws EndOfFileException, - BacktrackException { + protected List<IASTAttributeSpecifier> attributeSpecifierSeq() throws EndOfFileException, BacktrackException { List<IASTAttributeSpecifier> specifiers = null; - while ((LTcatchEOF(1) == IToken.tLBRACKET && LTcatchEOF(2) == IToken.tLBRACKET) || - LTcatchEOF(1) == IToken.t_alignas) { + while ((LTcatchEOF(1) == IToken.tLBRACKET && LTcatchEOF(2) == IToken.tLBRACKET) + || LTcatchEOF(1) == IToken.t_alignas) { if (specifiers == null) specifiers = new ArrayList<>(); if (LTcatchEOF(1) == IToken.t_alignas) { @@ -2848,8 +2868,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } char[] attributeName = nameToken.getCharImage(); char[] scopeName = scopeToken != null ? scopeToken.getCharImage() : null; - ICPPASTAttribute result = getNodeFactory().newAttribute(attributeName, scopeName, - argumentClause, packExpansion); + ICPPASTAttribute result = getNodeFactory().newAttribute(attributeName, scopeName, argumentClause, + packExpansion); setRange(result, nameToken.getOffset(), endOffset); return result; } @@ -2858,8 +2878,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected boolean isLegalWithoutDtor(IASTDeclSpecifier declSpec) { if (declSpec instanceof IASTElaboratedTypeSpecifier) { return ((IASTElaboratedTypeSpecifier) declSpec).getKind() != IASTElaboratedTypeSpecifier.k_enum; - } else if (declSpec instanceof ICPPASTNamedTypeSpecifier && - ((ICPPASTNamedTypeSpecifier) declSpec).isFriend()) { + } else if (declSpec instanceof ICPPASTNamedTypeSpecifier && ((ICPPASTNamedTypeSpecifier) declSpec).isFriend()) { return true; } return super.isLegalWithoutDtor(declSpec); @@ -2873,50 +2892,50 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tLBRACE) throwBacktrack(LA(1)); - final int firstOffset= attributesStartOffset(LA(1).getOffset(), attributes); - int endOffset= firstOffset; - boolean insertSemi= false; + final int firstOffset = attributesStartOffset(LA(1).getOffset(), attributes); + int endOffset = firstOffset; + boolean insertSemi = false; - IASTDeclSpecifier declSpec= null; - IASTDeclarator dtor= null; - IASTDeclSpecifier altDeclSpec= null; - IASTDeclarator altDtor= null; - IToken markBeforDtor= null; + IASTDeclSpecifier declSpec = null; + IASTDeclarator dtor = null; + IASTDeclSpecifier altDeclSpec = null; + IASTDeclarator altDtor = null; + IToken markBeforDtor = null; try { - Decl decl= declSpecifierSequence_initDeclarator(declOption, true); - markBeforDtor= decl.fDtorToken1; - declSpec= decl.fDeclSpec1; - dtor= decl.fDtor1; - altDeclSpec= decl.fDeclSpec2; - altDtor= decl.fDtor2; + Decl decl = declSpecifierSequence_initDeclarator(declOption, true); + markBeforDtor = decl.fDtorToken1; + declSpec = decl.fDeclSpec1; + dtor = decl.fDtor1; + altDeclSpec = decl.fDeclSpec2; + altDtor = decl.fDtor2; } catch (FoundAggregateInitializer lie) { - declSpec= lie.fDeclSpec; + declSpec = lie.fDeclSpec; // scalability: don't keep references to tokens, initializer may be large - declarationMark= null; - dtor= addInitializer(lie, declOption); + declarationMark = null; + dtor = addInitializer(lie, declOption); } catch (BacktrackException e) { - IASTNode node= e.getNodeBeforeProblem(); + IASTNode node = e.getNodeBeforeProblem(); if (node instanceof IASTDeclSpecifier && isLegalWithoutDtor((IASTDeclSpecifier) node)) { - IASTSimpleDeclaration d= getNodeFactory().newSimpleDeclaration((IASTDeclSpecifier) node); + IASTSimpleDeclaration d = getNodeFactory().newSimpleDeclaration((IASTDeclSpecifier) node); setRange(d, node); throwBacktrack(e.getProblem(), d); } throw e; } - IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + IASTDeclarator[] declarators = IASTDeclarator.EMPTY_DECLARATOR_ARRAY; if (dtor != null) { - declarators= new IASTDeclarator[] { dtor }; + declarators = new IASTDeclarator[] { dtor }; if (!declOption.fSingleDtor) { while (LTcatchEOF(1) == IToken.tCOMMA) { consume(); try { - dtor= initDeclarator(declSpec, declOption); + dtor = initDeclarator(declSpec, declOption); } catch (FoundAggregateInitializer e) { // scalability: don't keep references to tokens, initializer may be large - declarationMark= null; - markBeforDtor= null; - dtor= addInitializer(e, declOption); + declarationMark = null; + markBeforDtor = null; + dtor = addInitializer(e, declOption); } declarators = ArrayUtil.append(IASTDeclarator.class, declarators, dtor); } @@ -2924,17 +2943,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - final int lt1= LTcatchEOF(1); + final int lt1 = LTcatchEOF(1); switch (lt1) { case IToken.tEOC: - endOffset= figureEndOffset(declSpec, declarators); + endOffset = figureEndOffset(declSpec, declarators); break; case IToken.tSEMI: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.tCOLON: if (declOption == DeclarationOptions.RANGE_BASED_FOR) { - endOffset= figureEndOffset(declSpec, declarators); + endOffset = figureEndOffset(declSpec, declarators); break; } //$FALL-THROUGH$ @@ -2944,29 +2963,30 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (declarators.length != 1 || !declOption.fAllowFunctionDefinition) throwBacktrack(LA(1)); - dtor= declarators[0]; - if (altDeclSpec != null && altDtor != null && dtor != null && - !(ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator)) { - declSpec= altDeclSpec; - dtor= altDtor; + dtor = declarators[0]; + if (altDeclSpec != null && altDtor != null && dtor != null + && !(ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator)) { + declSpec = altDeclSpec; + dtor = altDtor; } ICPPASTFunctionDefinition functionDefinition = functionDefinition(firstOffset, declSpec, dtor); addAttributeSpecifiers(attributes, functionDefinition); return functionDefinition; default: - insertSemi= true; + insertSemi = true; if (declOption == DeclarationOptions.LOCAL) { - endOffset= figureEndOffset(declSpec, declarators); + endOffset = figureEndOffset(declSpec, declarators); break; } else { - if (isLegalWithoutDtor(declSpec) && markBeforDtor != null && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { + if (isLegalWithoutDtor(declSpec) && markBeforDtor != null + && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { backup(markBeforDtor); - declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - endOffset= calculateEndOffset(declSpec); + declarators = IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + endOffset = calculateEndOffset(declSpec); break; } - endOffset= figureEndOffset(declSpec, declarators); + endOffset = figureEndOffset(declSpec, declarators); if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { break; } @@ -2979,15 +2999,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // no function body - final boolean isAmbiguous= altDeclSpec != null && altDtor != null && declarators.length == 1; + final boolean isAmbiguous = altDeclSpec != null && altDtor != null && declarators.length == 1; IASTSimpleDeclaration simpleDeclaration; if (isAmbiguous) { // class C { C(T); }; // if T is a type this is a constructor, so // prefer the empty declspec, it shall be used if both variants show no problems - simpleDeclaration= getNodeFactory().newSimpleDeclaration(altDeclSpec); + simpleDeclaration = getNodeFactory().newSimpleDeclaration(altDeclSpec); simpleDeclaration.addDeclarator(altDtor); } else { - simpleDeclaration= getNodeFactory().newSimpleDeclaration(declSpec); + simpleDeclaration = getNodeFactory().newSimpleDeclaration(declSpec); for (IASTDeclarator declarator : declarators) { simpleDeclaration.addDeclarator(declarator); } @@ -3000,7 +3020,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (insertSemi) { - IASTProblem problem= createProblem(IProblem.MISSING_SEMICOLON, endOffset-1, 1); + IASTProblem problem = createProblem(IProblem.MISSING_SEMICOLON, endOffset - 1, 1); throwBacktrack(problem, simpleDeclaration); } addAttributeSpecifiers(attributes, simpleDeclaration); @@ -3009,20 +3029,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private ICPPASTFunctionDefinition functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec, IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException { - final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); + final IASTDeclarator dtor = ASTQueries.findTypeRelevantDeclarator(outerDtor); if (!(dtor instanceof ICPPASTFunctionDeclarator)) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); ICPPASTFunctionDefinition fdef; if (LT(1) == IToken.t_try) { consume(); - fdef= getNodeFactory().newFunctionTryBlock(declSpec, (ICPPASTFunctionDeclarator) dtor, null); + fdef = getNodeFactory().newFunctionTryBlock(declSpec, (ICPPASTFunctionDeclarator) dtor, null); } else { - fdef= getNodeFactory().newFunctionDefinition(declSpec, (ICPPASTFunctionDeclarator) dtor, null); + fdef = getNodeFactory().newFunctionDefinition(declSpec, (ICPPASTFunctionDeclarator) dtor, null); } if (LT(1) == IToken.tASSIGN) { consume(); - IToken kind= consume(); + IToken kind = consume(); switch (kind.getType()) { case IToken.t_default: fdef.setIsDefaulted(true); @@ -3041,11 +3061,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } try { - IASTStatement body= handleFunctionBody(); + IASTStatement body = handleFunctionBody(); fdef.setBody(body); setRange(fdef, firstOffset, calculateEndOffset(body)); } catch (BacktrackException bt) { - final IASTNode n= bt.getNodeBeforeProblem(); + final IASTNode n = bt.getNodeBeforeProblem(); if (n instanceof IASTCompoundStatement && !(fdef instanceof ICPPASTFunctionWithTryBlock)) { fdef.setBody((IASTCompoundStatement) n); setRange(fdef, firstOffset, calculateEndOffset(n)); @@ -3055,13 +3075,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (fdef instanceof ICPPASTFunctionWithTryBlock) { - ICPPASTFunctionWithTryBlock tryblock= (ICPPASTFunctionWithTryBlock) fdef; + ICPPASTFunctionWithTryBlock tryblock = (ICPPASTFunctionWithTryBlock) fdef; List<ICPPASTCatchHandler> handlers = new ArrayList<>(DEFAULT_CATCH_HANDLER_LIST_SIZE); catchHandlerSequence(handlers); - ICPPASTCatchHandler last= null; + ICPPASTCatchHandler last = null; for (ICPPASTCatchHandler catchHandler : handlers) { tryblock.addCatchHandler(catchHandler); - last= catchHandler; + last = catchHandler; } if (last != null) { adjustLength(tryblock, last); @@ -3086,21 +3106,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected void ctorInitializer(ICPPASTFunctionDefinition fdef) throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); loop: while (true) { - final int offset= LA(1).getOffset(); + final int offset = LA(1).getOffset(); final IASTName name = qualifiedName(); final IASTInitializer init; int endOffset; if (LT(1) != IToken.tEOC) { init = bracedOrCtorStyleInitializer(); - endOffset= calculateEndOffset(init); + endOffset = calculateEndOffset(init); } else { - init= null; - endOffset= calculateEndOffset(name); + init = null; + endOffset = calculateEndOffset(name); } - ICPPASTConstructorChainInitializer ctorInitializer = getNodeFactory().newConstructorChainInitializer(name, init); + ICPPASTConstructorChainInitializer ctorInitializer = getNodeFactory().newConstructorChainInitializer(name, + init); if (LT(1) == IToken.tELLIPSIS) { ctorInitializer.setIsPackExpansion(true); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } fdef.addMemberInitializer(setRange(ctorInitializer, offset, endOffset)); @@ -3119,23 +3140,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * request a backtrack */ protected ICPPASTParameterDeclaration parameterDeclaration() throws BacktrackException, EndOfFileException { - final int startOffset= LA(1).getOffset(); + final int startOffset = LA(1).getOffset(); List<IASTAttributeSpecifier> attributes = attributeSpecifierSeq(); - + if (LT(1) == IToken.tLBRACKET && supportParameterInfoBlock) { skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET, 0); } - IASTDeclSpecifier declSpec= null; + IASTDeclSpecifier declSpec = null; IASTDeclarator declarator; try { - Decl decl= declSpecifierSequence_initDeclarator(DeclarationOptions.PARAMETER, false); - declSpec= decl.fDeclSpec1; - declarator= decl.fDtor1; + Decl decl = declSpecifierSequence_initDeclarator(DeclarationOptions.PARAMETER, false); + declSpec = decl.fDeclSpec1; + declarator = decl.fDtor1; } catch (FoundAggregateInitializer lie) { - declSpec= lie.fDeclSpec; - declarator= addInitializer(lie, DeclarationOptions.PARAMETER); + declSpec = lie.fDeclSpec; + declarator = addInitializer(lie, DeclarationOptions.PARAMETER); } final ICPPASTParameterDeclaration parm = getNodeFactory().newParameterDeclaration(declSpec, declarator); @@ -3145,11 +3166,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return parm; } - private final static int INLINE= 0x1, CONST= 0x2, CONSTEXPR= 0x4, RESTRICT= 0x8, VOLATILE= 0x10, - SHORT= 0x20, UNSIGNED= 0x40, SIGNED= 0x80, COMPLEX= 0x100, IMAGINARY= 0x200, - VIRTUAL= 0x400, EXPLICIT= 0x800, FRIEND= 0x1000, THREAD_LOCAL= 0x2000; - private static final int FORBID_IN_EMPTY_DECLSPEC = - CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | THREAD_LOCAL; + private final static int INLINE = 0x1, CONST = 0x2, CONSTEXPR = 0x4, RESTRICT = 0x8, VOLATILE = 0x10, SHORT = 0x20, + UNSIGNED = 0x40, SIGNED = 0x80, COMPLEX = 0x100, IMAGINARY = 0x200, VIRTUAL = 0x400, EXPLICIT = 0x800, + FRIEND = 0x1000, THREAD_LOCAL = 0x2000; + private static final int FORBID_IN_EMPTY_DECLSPEC = CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED + | COMPLEX | IMAGINARY | THREAD_LOCAL; /** * This function parses a declaration specifier sequence, as according to @@ -3167,267 +3188,267 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * {"enum"} enumSpecifier */ @Override - protected Decl declSpecifierSeq(final DeclarationOptions option, ITemplateIdStrategy strat) + protected Decl declSpecifierSeq(final DeclarationOptions option, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { return declSpecifierSeq(option, false, strat); } private ICPPASTDeclSpecifier simpleTypeSpecifier() throws BacktrackException, EndOfFileException { - Decl d= declSpecifierSeq(null, true, null); + Decl d = declSpecifierSeq(null, true, null); return (ICPPASTDeclSpecifier) d.fDeclSpec1; } private ICPPASTDeclSpecifier simpleTypeSpecifierSequence() throws BacktrackException, EndOfFileException { - Decl d= declSpecifierSeq(null, false, null); + Decl d = declSpecifierSeq(null, false, null); return (ICPPASTDeclSpecifier) d.fDeclSpec1; } - private Decl declSpecifierSeq(final DeclarationOptions option, final boolean single, - ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { + private Decl declSpecifierSeq(final DeclarationOptions option, final boolean single, ITemplateIdStrategy strat) + throws BacktrackException, EndOfFileException { int storageClass = IASTDeclSpecifier.sc_unspecified; int simpleType = IASTSimpleDeclSpecifier.t_unspecified; - int options= 0; - int isLong= 0; + int options = 0; + int isLong = 0; - IToken returnToken= null; - ICPPASTDeclSpecifier result= null; - ICPPASTDeclSpecifier altResult= null; + IToken returnToken = null; + ICPPASTDeclSpecifier result = null; + ICPPASTDeclSpecifier altResult = null; List<IASTAttributeSpecifier> attributes = null; try { - IASTName identifier= null; - IASTExpression typeofExpression= null; - IASTProblem problem= null; + IASTName identifier = null; + IASTExpression typeofExpression = null; + IASTProblem problem = null; boolean isTypename = false; - boolean encounteredRawType= false; - boolean encounteredTypename= false; + boolean encounteredRawType = false; + boolean encounteredTypename = false; final int offset = LA(1).getOffset(); - int endOffset= offset; + int endOffset = offset; declSpecifiers: for (;;) { - final int lt1= LTcatchEOF(1); + final int lt1 = LTcatchEOF(1); switch (lt1) { case 0: // encountered eof break declSpecifiers; - // storage class specifiers + // storage class specifiers case IToken.t_auto: if (supportAutoTypeSpecifier) { if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_auto; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; } else { storageClass = IASTDeclSpecifier.sc_auto; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } break; case IToken.t_register: storageClass = IASTDeclSpecifier.sc_register; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_static: storageClass = IASTDeclSpecifier.sc_static; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_extern: storageClass = IASTDeclSpecifier.sc_extern; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_thread_local: - options |= THREAD_LOCAL; // thread_local may appear with static or extern - endOffset= consume().getEndOffset(); + options |= THREAD_LOCAL; // thread_local may appear with static or extern + endOffset = consume().getEndOffset(); break; case IToken.t_mutable: storageClass = IASTDeclSpecifier.sc_mutable; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_typedef: storageClass = IASTDeclSpecifier.sc_typedef; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; - // function specifiers + // function specifiers case IToken.t_inline: options |= INLINE; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_virtual: options |= VIRTUAL; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_explicit: options |= EXPLICIT; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_friend: options |= FRIEND; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_constexpr: options |= CONSTEXPR; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; - // type specifier + // type specifier case IToken.t_const: options |= CONST; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_volatile: options |= VOLATILE; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_restrict: options |= RESTRICT; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_signed: if (encounteredTypename) break declSpecifiers; options |= SIGNED; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_unsigned: if (encounteredTypename) break declSpecifiers; options |= UNSIGNED; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_short: if (encounteredTypename) break declSpecifiers; options |= SHORT; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_long: if (encounteredTypename) break declSpecifiers; isLong++; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t__Complex: if (encounteredTypename) break declSpecifiers; options |= COMPLEX; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t__Imaginary: if (encounteredTypename) break declSpecifiers; options |= IMAGINARY; - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_char: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_char; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_wchar_t: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_wchar_t; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_char16_t: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_char16_t; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_char32_t: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_char32_t; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_bool: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_bool; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_int: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_int; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IGCCToken.t__int128: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_int128; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_float: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_float; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_double: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_double; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IGCCToken.t__float128: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_float128; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IGCCToken.t_decimal32: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_decimal32; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IGCCToken.t_decimal64: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_decimal64; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IGCCToken.t_decimal128: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_decimal128; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_void: if (encounteredTypename) break declSpecifiers; simpleType = IASTSimpleDeclSpecifier.t_void; - encounteredRawType= true; - endOffset= consume().getEndOffset(); + encounteredRawType = true; + endOffset = consume().getEndOffset(); break; case IToken.t_typename: if (encounteredTypename || encounteredRawType) break declSpecifiers; consume(); - identifier= qualifiedName(); - endOffset= calculateEndOffset(identifier); + identifier = qualifiedName(); + endOffset = calculateEndOffset(identifier); isTypename = true; - encounteredTypename= true; + encounteredTypename = true; break; case IToken.tBITCOMPLEMENT: case IToken.tCOLONCOLON: @@ -3437,13 +3458,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break declSpecifiers; if (option != null && option.fAllowEmptySpecifier && LT(1) != IToken.tCOMPLETION) { - if ((options & FORBID_IN_EMPTY_DECLSPEC) == 0 && storageClass == IASTDeclSpecifier.sc_unspecified) { - altResult= buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); - returnToken= mark(); + if ((options & FORBID_IN_EMPTY_DECLSPEC) == 0 + && storageClass == IASTDeclSpecifier.sc_unspecified) { + altResult = buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, + offset, endOffset); + returnToken = mark(); } } - identifier= qualifiedName(CastExprCtx.eNotInBExpr, strat); + identifier = qualifiedName(CastExprCtx.eNotInBExpr, strat); if (identifier.getLookupKey().length == 0 && LT(1) != IToken.tEOC) throwBacktrack(LA(1)); @@ -3451,8 +3474,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { isTypename = true; } - endOffset= calculateEndOffset(identifier); - encounteredTypename= true; + endOffset = calculateEndOffset(identifier); + encounteredTypename = true; break; case IToken.t_class: case IToken.t_struct: @@ -3461,32 +3484,32 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break declSpecifiers; if (option != null && option.fAllowCompositeSpecifier) { try { - result= classSpecifier(); + result = classSpecifier(); } catch (BacktrackException bt) { - result= elaboratedTypeSpecifier(); + result = elaboratedTypeSpecifier(); } } else { result = elaboratedTypeSpecifier(); } - endOffset= calculateEndOffset(result); - encounteredTypename= true; + endOffset = calculateEndOffset(result); + encounteredTypename = true; break; case IToken.t_enum: if (encounteredTypename || encounteredRawType) break declSpecifiers; try { - result= enumDeclaration(option != null && option.fAllowOpaqueEnum); + result = enumDeclaration(option != null && option.fAllowOpaqueEnum); } catch (BacktrackException bt) { if (bt.getNodeBeforeProblem() instanceof ICPPASTDeclSpecifier) { - result= (ICPPASTDeclSpecifier) bt.getNodeBeforeProblem(); - problem= bt.getProblem(); + result = (ICPPASTDeclSpecifier) bt.getNodeBeforeProblem(); + problem = bt.getProblem(); break declSpecifiers; } throw bt; } - endOffset= calculateEndOffset(result); - encounteredTypename= true; + endOffset = calculateEndOffset(result); + encounteredTypename = true; break; case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec @@ -3504,13 +3527,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (encounteredRawType || encounteredTypename) throwBacktrack(LA(1)); - simpleType= IASTSimpleDeclSpecifier.t_typeof; + simpleType = IASTSimpleDeclSpecifier.t_typeof; consume(IGCCToken.t_typeof); - typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), + typeofExpression = parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), IASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotInBExpr, null); - encounteredTypename= true; - endOffset= calculateEndOffset(typeofExpression); + encounteredTypename = true; + endOffset = calculateEndOffset(typeofExpression); break; case IToken.t_decltype: @@ -3534,30 +3557,31 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.t_decltype); consume(IToken.tLPAREN); if (LT(1) == IToken.t_auto) { - simpleType= IASTSimpleDeclSpecifier.t_decltype_auto; + simpleType = IASTSimpleDeclSpecifier.t_decltype_auto; consume(IToken.t_auto); } else { - simpleType= IASTSimpleDeclSpecifier.t_decltype; - typeofExpression= expression(); + simpleType = IASTSimpleDeclSpecifier.t_decltype; + typeofExpression = expression(); } - endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); - encounteredTypename= true; + encounteredTypename = true; break; case IGCCToken.tTT_underlying_type: if (encounteredRawType || encounteredTypename) throwBacktrack(LA(1)); - result= typeTransformationSpecifier(DeclarationOptions.TYPEID); - endOffset= calculateEndOffset(result); - encounteredTypename= true; + result = typeTransformationSpecifier(DeclarationOptions.TYPEID); + endOffset = calculateEndOffset(result); + encounteredTypename = true; break; default: - if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) { + if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst + && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) { handleOtherDeclSpecModifier(); - endOffset= LA(1).getOffset(); + endOffset = LA(1).getOffset(); break; } break declSpecifiers; @@ -3588,9 +3612,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(problem, result); } } else if (identifier != null) { - result= buildNamedTypeSpecifier(identifier, isTypename, storageClass, options, offset, endOffset); + result = buildNamedTypeSpecifier(identifier, isTypename, storageClass, options, offset, endOffset); } else { - result= buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); + result = buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, + endOffset); } addAttributeSpecifiers(attributes, result); endOffset = attributesEndOffset(endOffset, attributes); @@ -3598,23 +3623,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } catch (BacktrackException e) { if (returnToken != null) { backup(returnToken); - result= altResult; - altResult= null; - returnToken= null; + result = altResult; + altResult = null; + returnToken = null; } else { throw e; } } - Decl target= new Decl(); - target.fDeclSpec1= result; - target.fDeclSpec2= altResult; - target.fDtorToken1= returnToken; + Decl target = new Decl(); + target.fDeclSpec1 = result; + target.fDeclSpec2 = altResult; + target.fDtorToken1 = returnToken; return target; } - private ICPPASTNamedTypeSpecifier buildNamedTypeSpecifier(IASTName name, boolean isTypename, - int storageClass, int options, int offset, int endOffset) { + private ICPPASTNamedTypeSpecifier buildNamedTypeSpecifier(IASTName name, boolean isTypename, int storageClass, + int options, int offset, int endOffset) { ICPPASTNamedTypeSpecifier declSpec = getNodeFactory().newTypedefNameSpecifier(name); declSpec.setIsTypename(isTypename); configureDeclSpec(declSpec, storageClass, options); @@ -3622,9 +3647,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return declSpec; } - private ICPPASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType, - int options, int isLong, IASTExpression typeofExpression, int offset, int endOffset) { - ICPPASTSimpleDeclSpecifier declSpec= getNodeFactory().newSimpleDeclSpecifier(); + private ICPPASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType, int options, int isLong, + IASTExpression typeofExpression, int offset, int endOffset) { + ICPPASTSimpleDeclSpecifier declSpec = getNodeFactory().newSimpleDeclSpecifier(); configureDeclSpec(declSpec, storageClass, options); @@ -3638,7 +3663,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { declSpec.setImaginary((options & IMAGINARY) != 0); declSpec.setDeclTypeExpression(typeofExpression); - ((ASTNode) declSpec).setOffsetAndLength(offset, endOffset-offset); + ((ASTNode) declSpec).setOffsetAndLength(offset, endOffset - offset); return declSpec; } @@ -3656,17 +3681,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private ICPPASTDeclSpecifier enumDeclaration(boolean allowOpaque) throws BacktrackException, EndOfFileException { - IToken mark= mark(); - final int offset= consume(IToken.t_enum).getOffset(); - int endOffset= 0; - boolean isScoped= false; + IToken mark = mark(); + final int offset = consume(IToken.t_enum).getOffset(); + int endOffset = 0; + boolean isScoped = false; ScopeStyle scopeStyle = ScopeStyle.NONE; - IASTName name= null; - ICPPASTDeclSpecifier baseType= null; + IASTName name = null; + ICPPASTDeclSpecifier baseType = null; List<IASTAttributeSpecifier> attributes = null; try { - int lt1= LT(1); + int lt1 = LT(1); if (lt1 == IToken.t_class || lt1 == IToken.t_struct) { scopeStyle = (lt1 == IToken.t_class) ? ScopeStyle.CLASS : ScopeStyle.STRUCT; isScoped = true; @@ -3678,28 +3703,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (isScoped || LT(1) == IToken.tIDENTIFIER) { // A qualified-name can appear here if an enumeration declared at class scope is // being defined out of line. - name= qualifiedName(); - endOffset= calculateEndOffset(name); + name = qualifiedName(); + endOffset = calculateEndOffset(name); } if (LT(1) == IToken.tCOLON) { consume(); - baseType= simpleTypeSpecifierSequence(); - endOffset= calculateEndOffset(baseType); + baseType = simpleTypeSpecifierSequence(); + endOffset = calculateEndOffset(baseType); } } catch (BacktrackException e) { backup(mark); return elaboratedTypeSpecifier(); } - final int lt1= LT(1); - final boolean isDef= lt1 == IToken.tLBRACE || (lt1 == IToken.tEOC && baseType != null); - final boolean isOpaque= !isDef && allowOpaque && lt1 == IToken.tSEMI; + final int lt1 = LT(1); + final boolean isDef = lt1 == IToken.tLBRACE || (lt1 == IToken.tEOC && baseType != null); + final boolean isOpaque = !isDef && allowOpaque && lt1 == IToken.tSEMI; if (!isDef && !isOpaque) { backup(mark); return elaboratedTypeSpecifier(); } - mark= null; + mark = null; if (isOpaque && !isScoped && baseType == null) throwBacktrack(LA(1)); @@ -3707,13 +3732,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (name == null) { if (isOpaque) throwBacktrack(LA(1)); - name= getNodeFactory().newName(); + name = getNodeFactory().newName(); } - final ICPPASTEnumerationSpecifier result= getNodeFactory().newEnumerationSpecifier(scopeStyle, name, baseType); + final ICPPASTEnumerationSpecifier result = getNodeFactory().newEnumerationSpecifier(scopeStyle, name, baseType); result.setIsOpaque(isOpaque); if (lt1 == IToken.tLBRACE) { - endOffset= enumBody(result); + endOffset = enumBody(result); } assert endOffset != 0; addAttributeSpecifiers(attributes, result); @@ -3728,7 +3753,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ protected ICPPASTElaboratedTypeSpecifier elaboratedTypeSpecifier() throws BacktrackException, EndOfFileException { // this is an elaborated class specifier - final int lt1= LT(1); + final int lt1 = LT(1); int eck = 0; switch (lt1) { @@ -3748,7 +3773,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(LA(1)); } - final int offset= consume().getOffset(); + final int offset = consume().getOffset(); // if __attribute__ or __declspec occurs after struct/union/class and before the identifier List<IASTAttributeSpecifier> attributes = anyAttributes(supportAttributeSpecifiers, supportDeclspecSpecifiers); @@ -3768,22 +3793,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tLPAREN); ICPPASTTypeId operand = typeId(options); final int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); - return setRange(getNodeFactory().newTypeTransformationSpecifier(ICPPUnaryTypeTransformation.Operator.underlying_type, operand), offset, endOffset); + return setRange(getNodeFactory().newTypeTransformationSpecifier( + ICPPUnaryTypeTransformation.Operator.underlying_type, operand), offset, endOffset); } @Override protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer { - final IToken mark= mark(); - IASTDeclarator dtor1= null; - IToken end1= null; - IASTDeclarator dtor2= null; - BacktrackException bt= null; + final IToken mark = mark(); + IASTDeclarator dtor1 = null; + IToken end1 = null; + IASTDeclarator dtor2 = null; + BacktrackException bt = null; try { - dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, declspec, option); + dtor1 = initDeclarator(DtorStrategy.PREFER_FUNCTION, declspec, option); verifyDtor(declspec, dtor1, option); - int lt1= LTcatchEOF(1); + int lt1 = LTcatchEOF(1); switch (lt1) { case 0: return dtor1; @@ -3793,7 +3819,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { || ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator) return dtor1; - dtor1= null; + dtor1 = null; throwBacktrack(LA(1)); break; @@ -3802,14 +3828,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (option != DeclarationOptions.CPP_MEMBER && option != DeclarationOptions.GLOBAL) break; //$FALL-THROUGH$ - case IToken.t_throw: case IToken.t_try: - case IToken.t_const: case IToken.t_volatile: + case IToken.t_throw: + case IToken.t_try: + case IToken.t_const: + case IToken.t_volatile: case IToken.tASSIGN: // defaulted or deleted function definition - if (option == DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE || - ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator) { + if (option == DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE + || ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator) { return dtor1; } else { - dtor1= null; + dtor1 = null; throwBacktrack(LA(1)); } } @@ -3817,9 +3845,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (!(dtor1 instanceof IASTFunctionDeclarator)) return dtor1; - end1= LA(1); + end1 = LA(1); } catch (BacktrackException e) { - bt= e; + bt = e; } if (!option.fAllowCtorStyleInitializer || !canHaveConstructorInitializer(declspec, dtor1)) { @@ -3830,7 +3858,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); try { - dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, declspec, option); + dtor2 = initDeclarator(DtorStrategy.PREFER_NESTED, declspec, option); if (dtor1 == null) { return dtor2; } @@ -3850,9 +3878,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (functionBodyCount != 0) { // prefer the variable prototype: - IASTDeclarator h= dtor1; dtor1= dtor2; dtor2= h; + IASTDeclarator h = dtor1; + dtor1 = dtor2; + dtor2 = h; } - CPPASTAmbiguousDeclarator dtor= new CPPASTAmbiguousDeclarator(dtor1, dtor2); + CPPASTAmbiguousDeclarator dtor = new CPPASTAmbiguousDeclarator(dtor1, dtor2); dtor.setOffsetAndLength((ASTNode) dtor1); return dtor; } @@ -3860,17 +3890,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Tries to detect illegal versions of declarations */ - private void verifyDtor(IASTDeclSpecifier declspec, IASTDeclarator dtor, DeclarationOptions opt) throws BacktrackException { + private void verifyDtor(IASTDeclSpecifier declspec, IASTDeclarator dtor, DeclarationOptions opt) + throws BacktrackException { if (CPPVisitor.doesNotSpecifyType(declspec)) { if (ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator) { - boolean isQualified= false; - IASTName name= ASTQueries.findInnermostDeclarator(dtor).getName(); + boolean isQualified = false; + IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName(); if (name instanceof ICPPASTQualifiedName) { - isQualified= true; - name= name.getLastName(); + isQualified = true; + name = name.getLastName(); } if (name instanceof ICPPASTTemplateId) - name= ((ICPPASTTemplateId) name).getTemplateName(); + name = ((ICPPASTTemplateId) name).getTemplateName(); // accept conversion operator if (name instanceof ICPPASTConversionName) @@ -3878,10 +3909,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (opt == DeclarationOptions.CPP_MEMBER) { // Accept constructor and destructor within class body - final char[] nchars= name.getLookupKey(); + final char[] nchars = name.getLookupKey(); if (nchars.length > 0 && currentClassName != null) { - final int start= nchars[0] == '~' ? 1 : 0; - if (CharArrayUtils.equals(nchars, start, nchars.length-start, currentClassName)) + final int start = nchars[0] == '~' ? 1 : 0; + if (CharArrayUtils.equals(nchars, start, nchars.length - start, currentClassName)) return; } @@ -3894,14 +3925,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - ASTNode node= (ASTNode) dtor; + ASTNode node = (ASTNode) dtor; throwBacktrack(node.getOffset(), node.getLength()); } } private boolean canHaveConstructorInitializer(IASTDeclSpecifier declspec, IASTDeclarator dtor) { if (declspec instanceof ICPPASTDeclSpecifier) { - ICPPASTDeclSpecifier cppspec= (ICPPASTDeclSpecifier) declspec; + ICPPASTDeclSpecifier cppspec = (ICPPASTDeclSpecifier) declspec; if (cppspec.isFriend()) { return false; } @@ -3911,12 +3942,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (declspec instanceof ICPPASTSimpleDeclSpecifier) { - ICPPASTSimpleDeclSpecifier sspec= (ICPPASTSimpleDeclSpecifier) declspec; + ICPPASTSimpleDeclSpecifier sspec = (ICPPASTSimpleDeclSpecifier) declspec; if (CPPVisitor.doesNotSpecifyType(declspec)) { return false; } - if (sspec.getType() == IASTSimpleDeclSpecifier.t_void && dtor != null && - dtor.getPointerOperators().length == 0 && dtor.getNestedDeclarator() == null) { + if (sspec.getType() == IASTSimpleDeclSpecifier.t_void && dtor != null + && dtor.getPointerOperators().length == 0 && dtor.getNestedDeclarator() == null) { return false; } } @@ -3924,7 +3955,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (dtor != null) { IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName().getLastName(); if (name instanceof ICPPASTTemplateId) { - name= ((ICPPASTTemplateId) name).getTemplateName(); + name = ((ICPPASTTemplateId) name).getTemplateName(); } if (name instanceof ICPPASTOperatorName || name instanceof ICPPASTConversionName) return false; @@ -3943,7 +3974,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ private IASTDeclarator initDeclarator(DtorStrategy strategy, IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer { - final IASTDeclarator dtor= declarator(strategy, option); + final IASTDeclarator dtor = declarator(strategy, option); if (option.fAllowInitializer) { final IASTDeclarator typeRelevantDtor = ASTQueries.findTypeRelevantDeclarator(dtor); if (option != DeclarationOptions.PARAMETER && typeRelevantDtor instanceof IASTFunctionDeclarator) { @@ -3951,7 +3982,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // For member functions we need to consider virtual specifiers and pure-virtual syntax. if (option == DeclarationOptions.CPP_MEMBER) { optionalVirtSpecifierSeq((ICPPASTFunctionDeclarator) typeRelevantDtor); - List<IASTAttributeSpecifier> attributeSpecifiers = __attribute_decl_seq(supportAttributeSpecifiers, false); + List<IASTAttributeSpecifier> attributeSpecifiers = __attribute_decl_seq(supportAttributeSpecifiers, + false); addAttributeSpecifiers(attributeSpecifiers, dtor); int lt1 = LTcatchEOF(1); if (lt1 == IToken.tASSIGN && LTcatchEOF(2) == IToken.tINTEGER) { @@ -3969,7 +4001,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE) throw new FoundAggregateInitializer(declspec, dtor); - IASTInitializer initializer= optionalInitializer(dtor, option); + IASTInitializer initializer = optionalInitializer(dtor, option); if (initializer != null) { if (initializer instanceof IASTInitializerList && ((IASTInitializerList) initializer).getSize() == 0) { @@ -4055,7 +4087,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions option) throws EndOfFileException, BacktrackException { - final int lt1= LTcatchEOF(1); + final int lt1 = LTcatchEOF(1); // = initializer-clause if (lt1 == IToken.tASSIGN) { @@ -4080,7 +4112,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private IASTInitializer bracedOrCtorStyleInitializer() throws EndOfFileException, BacktrackException { - final int lt1= LT(1); + final int lt1 = LT(1); if (lt1 == IToken.tLPAREN) { return ctorStyleInitializer(true); } @@ -4093,11 +4125,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private ICPPASTConstructorInitializer ctorStyleInitializer(boolean optionalExpressionList) throws EndOfFileException, BacktrackException { IASTInitializerClause[] initArray; - int offset = consume(IToken.tLPAREN).getOffset(); + int offset = consume(IToken.tLPAREN).getOffset(); // () if (optionalExpressionList && LT(1) == IToken.tRPAREN) { - initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY; + initArray = IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { final List<ICPPASTInitializerClause> exprList = expressionList(); initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]); @@ -4115,16 +4147,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * assignment-expression * braced-init-list */ - private ICPPASTInitializerClause initClause(boolean allowSkipping) throws EndOfFileException, - BacktrackException { + private ICPPASTInitializerClause initClause(boolean allowSkipping) throws EndOfFileException, BacktrackException { // braced-init-list if (LT(1) == IToken.tLBRACE) { return bracedInitList(allowSkipping, true); } // assignment expression - TemplateIdStrategy strat= fTemplateParameterListStrategy; - final BinaryExprCtx ctx= strat != null ? BinaryExprCtx.eInTemplateID : BinaryExprCtx.eNotInTemplateID; + TemplateIdStrategy strat = fTemplateParameterListStrategy; + final BinaryExprCtx ctx = strat != null ? BinaryExprCtx.eInTemplateID : BinaryExprCtx.eNotInTemplateID; return expression(ExprKind.eAssignment, ctx, null, strat); } @@ -4143,11 +4174,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // { initializer-list ,opt } - List<ICPPASTInitializerClause> initList= initializerList(allowSkipping, allowDesignators); + List<ICPPASTInitializerClause> initList = initializerList(allowSkipping, allowDesignators); if (LT(1) == IToken.tCOMMA) consume(); - int endOffset= consumeOrEOC(IToken.tRBRACE).getEndOffset(); + int endOffset = consumeOrEOC(IToken.tRBRACE).getEndOffset(); ICPPASTInitializerList result = getNodeFactory().newInitializerList(); for (IASTInitializerClause init : initList) { result.addClause(init); @@ -4162,13 +4193,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ private List<ICPPASTInitializerClause> initializerList(boolean allowSkipping, boolean allowDesignators) throws EndOfFileException, BacktrackException { - List<ICPPASTInitializerClause> result= new ArrayList<>(); + List<ICPPASTInitializerClause> result = new ArrayList<>(); // List of initializer clauses loop: while (true) { List<ICPPASTDesignator> designators = null; IToken mark = mark(); if (allowDesignators) { - designators= designatorList(); + designators = designatorList(); } if (designators != null) { @@ -4184,7 +4215,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tASSIGN) consume(IToken.tASSIGN); - ICPPASTInitializerClause clause= initClause(false); + ICPPASTInitializerClause clause = initClause(false); desigInitializer.setOperand(clause); adjustLength(desigInitializer, clause); } @@ -4201,7 +4232,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (allowSkipping && result.size() >= maximumTrivialExpressionsInAggregateInitializers && !ASTQueries.canContainName(clause)) { translationUnit.setHasNodesOmitted(true); - clause= null; + clause = null; } if (LT(1) == IToken.tELLIPSIS) { final int endOffset = consume(IToken.tELLIPSIS).getEndOffset(); @@ -4211,8 +4242,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { adjustEndOffset(clause, endOffset); } else if (clause instanceof IASTExpression) { // Wrap pack expanded assignment expressions - ICPPASTExpression packExpansion= getNodeFactory().newPackExpansionExpression((IASTExpression) clause); - clause= setRange(packExpansion, clause, endOffset); + ICPPASTExpression packExpansion = getNodeFactory() + .newPackExpansionExpression((IASTExpression) clause); + clause = setRange(packExpansion, clause, endOffset); } } result.add(clause); @@ -4232,11 +4264,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private List<ICPPASTDesignator> designatorList() throws EndOfFileException, BacktrackException { - IToken mark= mark(); + IToken mark = mark(); try { - final int lt1= LT(1); + final int lt1 = LT(1); if (lt1 == IToken.tDOT || lt1 == IToken.tLBRACKET) { - List<ICPPASTDesignator> designatorList= null; + List<ICPPASTDesignator> designatorList = null; while (true) { switch (LT(1)) { case IToken.tDOT: @@ -4256,7 +4288,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tELLIPSIS); ICPPASTExpression constantExpression2 = expression(); int lastOffset = consume(IToken.tRBRACKET).getEndOffset(); - IGPPASTArrayRangeDesignator designator = getNodeFactory().newArrayRangeDesignatorGPP(constantExpression, constantExpression2); + IGPPASTArrayRangeDesignator designator = getNodeFactory() + .newArrayRangeDesignatorGPP(constantExpression, constantExpression2); setRange(designator, offset, lastOffset); if (designatorList == null) designatorList = new ArrayList<>(DEFAULT_DESIGNATOR_LIST_SIZE); @@ -4279,7 +4312,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // If reached identifier and it's not a designator then return empty designator list (bug 84176). if (supportGCCStyleDesignators && lt1 == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { - int offset= LA(1).getOffset(); + int offset = LA(1).getOffset(); IASTName n = identifier(); int lastOffset = consume(IToken.tCOLON).getEndOffset(); ICPPASTFieldDesignator designator = getNodeFactory().newFieldDesignator(n); @@ -4297,8 +4330,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected ICPPASTTypeId typeId(DeclarationOptions option) throws EndOfFileException, BacktrackException { return typeId(option, null); } - - protected ICPPASTTypeId typeId(DeclarationOptions option, ITemplateIdStrategy strat) + + protected ICPPASTTypeId typeId(DeclarationOptions option, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { if (!canBeTypeSpecifier()) { throwBacktrack(LA(1)); @@ -4308,9 +4341,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTDeclarator declarator = null; try { - Decl decl= declSpecifierSequence_initDeclarator(option, false, strat); - declSpecifier= decl.fDeclSpec1; - declarator= decl.fDtor1; + Decl decl = declSpecifierSequence_initDeclarator(option, false, strat); + declSpecifier = decl.fDeclSpec1; + declarator = decl.fDtor1; } catch (FoundAggregateInitializer lie) { // type-ids have no initializers throwBacktrack(lie.fDeclarator); @@ -4350,12 +4383,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { supportDeclspecSpecifiers); // Look for identifier or nested declarator - boolean hasEllipsis= false; + boolean hasEllipsis = false; if (option.fAllowParameterPacks && LT(1) == IToken.tELLIPSIS) { consume(); - hasEllipsis= true; + hasEllipsis = true; } - final int lt1= LT(1); + final int lt1 = LT(1); switch (lt1) { case IToken.tBITCOMPLEMENT: case IToken.t_operator: @@ -4365,8 +4398,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (option.fRequireAbstract) { // We might have a virt-specifier following a type-id in a trailing-return-type. ContextSensitiveTokenType contextSensitiveType = getContextSensitiveType(LA(1)); - if (contextSensitiveType == ContextSensitiveTokenType.OVERRIDE || - contextSensitiveType == ContextSensitiveTokenType.FINAL) { + if (contextSensitiveType == ContextSensitiveTokenType.OVERRIDE + || contextSensitiveType == ContextSensitiveTokenType.FINAL) { // In that case, we're done parsing the declarator of the type-id. break; } else { @@ -4375,25 +4408,25 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - final IASTName declaratorName= !option.fRequireSimpleName ? qualifiedName() : identifier(); - endOffset= calculateEndOffset(declaratorName); - return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, - endOffset, strategy, option, attributes); + final IASTName declaratorName = !option.fRequireSimpleName ? qualifiedName() : identifier(); + endOffset = calculateEndOffset(declaratorName); + return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, endOffset, strategy, + option, attributes); } if (lt1 == IToken.tLPAREN) { - IASTDeclarator cand1= null; - IToken cand1End= null; + IASTDeclarator cand1 = null; + IToken cand1End = null; // try an abstract function declarator if (option.fAllowAbstract && option.fAllowFunctions) { - final IToken mark= mark(); + final IToken mark = mark(); try { - cand1= declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), null, - startingOffset, endOffset, strategy, option, attributes); + cand1 = declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), null, startingOffset, + endOffset, strategy, option, attributes); if (option.fRequireAbstract || !option.fAllowNested || hasEllipsis) return cand1; - cand1End= LA(1); + cand1End = LA(1); } catch (BacktrackException e) { } backup(mark); @@ -4402,8 +4435,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // type-ids for new or operator-id: if (!option.fAllowNested || hasEllipsis) { if (option.fAllowAbstract) { - return declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), null, - startingOffset, endOffset, strategy, option, attributes); + return declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), null, startingOffset, + endOffset, strategy, option, attributes); } throwBacktrack(LA(1)); } @@ -4414,15 +4447,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tRPAREN) throwBacktrack(LA(1)); - final IASTDeclarator nested= declarator(DtorStrategy.PREFER_FUNCTION, option); - endOffset= consume(IToken.tRPAREN).getEndOffset(); - final IASTDeclarator cand2= declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), nested, + final IASTDeclarator nested = declarator(DtorStrategy.PREFER_FUNCTION, option); + endOffset = consume(IToken.tRPAREN).getEndOffset(); + final IASTDeclarator cand2 = declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), nested, startingOffset, endOffset, strategy, option, attributes); if (cand1 == null || cand1End == null) return cand2; - final IToken cand2End= LA(1); + final IToken cand2End = LA(1); if (cand1End == cand2End) { - CPPASTAmbiguousDeclarator result= new CPPASTAmbiguousDeclarator(cand1, cand2); + CPPASTAmbiguousDeclarator result = new CPPASTAmbiguousDeclarator(cand1, cand2); ((ASTNode) result).setOffsetAndLength((ASTNode) cand1); return result; } @@ -4444,8 +4477,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (!option.fAllowBitField || LT(1) != IToken.tCOLON) throwBacktrack(LA(1)); } - return declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), null, startingOffset, - endOffset, strategy, option, attributes); + return declarator(pointerOps, hasEllipsis, getNodeFactory().newName(), null, startingOffset, endOffset, + strategy, option, attributes); } /** @@ -4458,22 +4491,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * request a backtrack */ - private List<? extends IASTPointerOperator> consumePointerOperators() throws EndOfFileException, BacktrackException { - List<IASTPointerOperator> result= null; + private List<? extends IASTPointerOperator> consumePointerOperators() + throws EndOfFileException, BacktrackException { + List<IASTPointerOperator> result = null; for (;;) { IToken mark = mark(); final int startOffset = mark.getOffset(); // __attribute__ in-between pointers - List<IASTAttributeSpecifier> attributes = __attribute_decl_seq(supportAttributeSpecifiers, false); + List<IASTAttributeSpecifier> attributes = __attribute_decl_seq(supportAttributeSpecifiers, false); final int lt1 = LT(1); if (lt1 == IToken.tAMPER || lt1 == IToken.tAND) { - IToken endToken= consume(); - final int offset= endToken.getOffset(); + IToken endToken = consume(); + final int offset = endToken.getOffset(); if (allowCPPRestrict && LT(1) == IToken.t_restrict) { - endToken= consume(); + endToken = consume(); } ICPPASTReferenceOperator refOp = getNodeFactory().newReferenceOperator(lt1 == IToken.tAND); setRange(refOp, offset, endToken.getEndOffset()); @@ -4489,24 +4523,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } boolean isConst = false, isVolatile = false, isRestrict = false; - IASTName name= null; - int coloncolon= LT(1) == IToken.tCOLONCOLON ? 1 : 0; - loop: while (LTcatchEOF(coloncolon+1) == IToken.tIDENTIFIER) { - switch (LTcatchEOF(coloncolon+2)) { + IASTName name = null; + int coloncolon = LT(1) == IToken.tCOLONCOLON ? 1 : 0; + loop: while (LTcatchEOF(coloncolon + 1) == IToken.tIDENTIFIER) { + switch (LTcatchEOF(coloncolon + 2)) { case IToken.tCOLONCOLON: - coloncolon+= 2; + coloncolon += 2; break; case IToken.tLT: - coloncolon= 1; + coloncolon = 1; break loop; default: - coloncolon= 0; + coloncolon = 0; break loop; } } if (coloncolon != 0) { try { - name= qualifiedName(); + name = qualifiedName(); if (name.getLookupKey().length != 0) { backup(mark); return result; @@ -4521,21 +4555,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - int endOffset= consume().getEndOffset(); + int endOffset = consume().getEndOffset(); loop: for (;;) { switch (LTcatchEOF(1)) { case IToken.t_const: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); isConst = true; break; case IToken.t_volatile: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); isVolatile = true; break; case IToken.t_restrict: if (!allowCPPRestrict) throwBacktrack(LA(1)); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); isRestrict = true; break; default: @@ -4545,7 +4579,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTPointer pointer; if (name != null) { - pointer= getNodeFactory().newPointerToMember(name); + pointer = getNodeFactory().newPointerToMember(name); } else { pointer = getNodeFactory().newPointer(); } @@ -4553,7 +4587,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { pointer.setVolatile(isVolatile); pointer.setRestrict(isRestrict); if (result == null) { - result= new ArrayList<>(4); + result = new ArrayList<>(4); } attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); @@ -4569,13 +4603,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTName declaratorName, IASTDeclarator nestedDeclarator, int startingOffset, int endOffset, DtorStrategy strategy, DeclarationOptions option, List<IASTAttributeSpecifier> attributes) throws EndOfFileException, BacktrackException { - ICPPASTDeclarator result= null; + ICPPASTDeclarator result = null; loop: while (true) { - final int lt1= LTcatchEOF(1); + final int lt1 = LTcatchEOF(1); switch (lt1) { case IToken.tLPAREN: if (option.fAllowFunctions && strategy == DtorStrategy.PREFER_FUNCTION) { - result= functionDeclarator(false); + result = functionDeclarator(false); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); } break loop; @@ -4585,29 +4619,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); break; } - result= arrayDeclarator(option); + result = arrayDeclarator(option); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; case IToken.tCOLON: if (!option.fAllowBitField || nestedDeclarator != null) - break loop; // no backtrack because typeid can be followed by colon + break loop; // no backtrack because typeid can be followed by colon - result= bitFieldDeclarator(); + result = bitFieldDeclarator(); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; case IGCCToken.t__attribute__: // if __attribute__ is after a declarator if (!supportAttributeSpecifiers) throwBacktrack(LA(1)); - attributes = CollectionUtils.merge(attributes, - __attribute_decl_seq(true, supportDeclspecSpecifiers)); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, supportDeclspecSpecifiers)); break; case IGCCToken.t__declspec: if (!supportDeclspecSpecifiers) throwBacktrack(LA(1)); - attributes = CollectionUtils.merge(attributes, - __attribute_decl_seq(supportAttributeSpecifiers, true)); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, true)); break; default: break loop; @@ -4617,15 +4649,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); if (result == null) { - result= getNodeFactory().newDeclarator(null); + result = getNodeFactory().newDeclarator(null); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); } else { - endOffset= calculateEndOffset(result); + endOffset = calculateEndOffset(result); } if (LTcatchEOF(1) == IToken.t_asm) { // asm labels bug 226121 consume(); - endOffset= asmExpression(null).getEndOffset(); + endOffset = asmExpression(null).getEndOffset(); attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); @@ -4644,7 +4676,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - private void setDeclaratorID(ICPPASTDeclarator declarator, boolean hasEllipsis, IASTName declaratorName, IASTDeclarator nestedDeclarator) { + private void setDeclaratorID(ICPPASTDeclarator declarator, boolean hasEllipsis, IASTName declaratorName, + IASTDeclarator nestedDeclarator) { if (nestedDeclarator != null) { declarator.setNestedDeclarator(nestedDeclarator); declarator.setName(getNodeFactory().newName()); @@ -4657,29 +4690,30 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parse a function declarator starting with the left parenthesis. */ - private ICPPASTFunctionDeclarator functionDeclarator(boolean isLambdaDeclarator) throws EndOfFileException, BacktrackException { + private ICPPASTFunctionDeclarator functionDeclarator(boolean isLambdaDeclarator) + throws EndOfFileException, BacktrackException { IToken last = consume(IToken.tLPAREN); - final int startOffset= last.getOffset(); - int endOffset= last.getEndOffset(); + final int startOffset = last.getOffset(); + int endOffset = last.getEndOffset(); final ICPPASTFunctionDeclarator fc = getNodeFactory().newFunctionDeclarator(null); - ICPPASTParameterDeclaration pd= null; + ICPPASTParameterDeclaration pd = null; paramLoop: while (true) { switch (LT(1)) { case IToken.tRPAREN: case IToken.tEOC: - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break paramLoop; case IToken.tELLIPSIS: consume(); - endOffset= consume(IToken.tRPAREN).getEndOffset(); + endOffset = consume(IToken.tRPAREN).getEndOffset(); fc.setVarArgs(true); break paramLoop; case IToken.tCOMMA: if (pd == null) throwBacktrack(LA(1)); - endOffset= consume().getEndOffset(); - pd= null; + endOffset = consume().getEndOffset(); + pd = null; break; default: if (pd != null) @@ -4695,8 +4729,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (pd != null) { ICPPASTDeclarator dtor = pd.getDeclarator(); if (dtor != null && !(dtor instanceof IASTAmbiguousDeclarator)) { - if (dtor.declaresParameterPack() && dtor.getNestedDeclarator() == null - && dtor.getInitializer() == null && dtor.getName().getSimpleID().length == 0) { + if (dtor.declaresParameterPack() && dtor.getNestedDeclarator() == null && dtor.getInitializer() == null + && dtor.getName().getSimpleID().length == 0) { ((IASTAmbiguityParent) fc).replace(pd, new CPPASTAmbiguousParameterDeclaration(pd)); } } @@ -4709,18 +4743,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (isLambdaDeclarator) { if (LT(1) == IToken.t_mutable) { fc.setMutable(true); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); } } else { cvloop: while (true) { switch (LT(1)) { case IToken.t_const: fc.setConst(true); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.t_volatile: fc.setVolatile(true); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; default: break cvloop; @@ -4732,11 +4766,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { switch (LT(1)) { case IToken.tAMPER: fc.setRefQualifier(RefQualifier.LVALUE); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; case IToken.tAND: fc.setRefQualifier(RefQualifier.RVALUE); - endOffset= consume().getEndOffset(); + endOffset = consume().getEndOffset(); break; default: break; @@ -4781,19 +4815,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // more __attribute__ after throws - attributes = CollectionUtils.merge(attributes, - __attribute_decl_seq(supportAttributeSpecifiers, false)); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, false)); } // noexcept specification if (LT(1) == IToken.t_noexcept) { - consume(); // noexcept + consume(); // noexcept IASTExpression expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT; endOffset = getEndOffset(); if (LT(1) == IToken.tLPAREN) { - consume(); // ( + consume(); // ( expression = expression(); - consume(IToken.tRPAREN); //) + consume(IToken.tRPAREN); //) endOffset = getEndOffset(); } fc.setNoexceptExpression((ICPPASTExpression) expression); @@ -4805,9 +4838,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tARROW) { consume(); - IASTTypeId typeId= typeId(DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE); + IASTTypeId typeId = typeId(DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE); fc.setTrailingReturnType(typeId); - endOffset= calculateEndOffset(typeId); + endOffset = calculateEndOffset(typeId); } return setRange(fc, startOffset, endOffset); @@ -4816,9 +4849,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parse an array declarator starting at the square bracket. */ - private ICPPASTArrayDeclarator arrayDeclarator(DeclarationOptions option) throws EndOfFileException, BacktrackException { + private ICPPASTArrayDeclarator arrayDeclarator(DeclarationOptions option) + throws EndOfFileException, BacktrackException { ArrayList<IASTArrayModifier> arrayMods = new ArrayList<>(4); - int start= LA(1).getOffset(); + int start = LA(1).getOffset(); consumeArrayModifiers(option, arrayMods); if (arrayMods.isEmpty()) throwBacktrack(LA(1)); @@ -4829,7 +4863,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { d.addArrayModifier(m); } - ((ASTNode) d).setOffsetAndLength(start, endOffset-start); + ((ASTNode) d).setOffsetAndLength(start, endOffset - start); return d; } @@ -4837,13 +4871,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * Parses for a bit field declarator starting with the colon */ private ICPPASTFieldDeclarator bitFieldDeclarator() throws EndOfFileException, BacktrackException { - int start= consume(IToken.tCOLON).getOffset(); + int start = consume(IToken.tCOLON).getOffset(); final IASTExpression bitField = constantExpression(); final int endOffset = calculateEndOffset(bitField); ICPPASTFieldDeclarator d = getNodeFactory().newFieldDeclarator(null, bitField); - ((ASTNode) d).setOffsetAndLength(start, endOffset-start); + ((ASTNode) d).setOffsetAndLength(start, endOffset - start); return d; } @@ -4857,7 +4891,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected ICPPASTCompositeTypeSpecifier classSpecifier() throws BacktrackException, EndOfFileException { int classKind = 0; IToken mark = mark(); - final int offset= mark.getOffset(); + final int offset = mark.getOffset(); // class key switch (LT(1)) { @@ -4890,7 +4924,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ; - attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); + attributes = CollectionUtils.merge(attributes, + __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); ICPPASTCompositeTypeSpecifier astClassSpecifier = getNodeFactory().newCompositeTypeSpecifier(classKind, name); addAttributeSpecifiers(attributes, astClassSpecifier); @@ -4921,14 +4956,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); throwBacktrack(errorPoint); } - mark= null; // don't hold on to tokens while parsing the members. - final char[] outerName= currentClassName; - currentClassName= name.getLookupKey(); + mark = null; // don't hold on to tokens while parsing the members. + final char[] outerName = currentClassName; + currentClassName = name.getLookupKey(); try { declarationListInBraces(astClassSpecifier, offset, DeclarationOptions.CPP_MEMBER); } finally { - currentClassName= outerName; + currentClassName = outerName; } return astClassSpecifier; } @@ -4978,13 +5013,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * final * @param astClassSpecifier */ - private void classVirtSpecifier(ICPPASTCompositeTypeSpecifier astClassSpecifier) throws EndOfFileException, BacktrackException { + private void classVirtSpecifier(ICPPASTCompositeTypeSpecifier astClassSpecifier) + throws EndOfFileException, BacktrackException { IToken token = LA(); ContextSensitiveTokenType contextSensitiveType = getContextSensitiveType(token); if (contextSensitiveType == ContextSensitiveTokenType.FINAL) { consume(); - ICPPASTClassVirtSpecifier spec = getNodeFactory().newClassVirtSpecifier( - ICPPASTClassVirtSpecifier.SpecifierKind.Final); + ICPPASTClassVirtSpecifier spec = getNodeFactory() + .newClassVirtSpecifier(ICPPASTClassVirtSpecifier.SpecifierKind.Final); setRange(spec, token.getOffset(), token.getOffset() + token.getLength()); astClassSpecifier.setVirtSpecifier(spec); } @@ -5000,7 +5036,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ private ICPPASTBaseSpecifier baseSpecifier() throws EndOfFileException, BacktrackException { - int startOffset= LA(1).getOffset(); + int startOffset = LA(1).getOffset(); boolean isVirtual = false; int visibility = 0; ICPPASTNameSpecifier nameSpec = null; @@ -5027,12 +5063,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } nameSpec = nameSpecifier(); - ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier baseSpec = getNodeFactory().newBaseSpecifier(nameSpec, visibility, isVirtual); + ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier baseSpec = getNodeFactory().newBaseSpecifier(nameSpec, + visibility, isVirtual); setRange(baseSpec, startOffset, calculateEndOffset(nameSpec)); return baseSpec; } - protected void catchHandlerSequence(List<ICPPASTCatchHandler> collection) throws EndOfFileException, BacktrackException { + protected void catchHandlerSequence(List<ICPPASTCatchHandler> collection) + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tEOC) return; @@ -5050,7 +5088,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tELLIPSIS); isEllipsis = true; } else { - decl= simpleSingleDeclaration(DeclarationOptions.EXCEPTION); + decl = simpleSingleDeclaration(DeclarationOptions.EXCEPTION); } if (LT(1) != IToken.tEOC) consume(IToken.tRPAREN); @@ -5066,7 +5104,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) != IToken.tEOC) { IASTStatement compoundStatement = catchBlockCompoundStatement(); - ((ASTNode) handler).setOffsetAndLength(startOffset, calculateEndOffset(compoundStatement) - startOffset); + ((ASTNode) handler).setOffsetAndLength(startOffset, + calculateEndOffset(compoundStatement) - startOffset); handler.setIsCatchAll(isEllipsis); if (compoundStatement != null) { handler.setCatchBody(compoundStatement); @@ -5078,23 +5117,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - private IASTSimpleDeclaration simpleSingleDeclaration(DeclarationOptions options) throws BacktrackException, EndOfFileException { - final int startOffset= LA(1).getOffset(); + private IASTSimpleDeclaration simpleSingleDeclaration(DeclarationOptions options) + throws BacktrackException, EndOfFileException { + final int startOffset = LA(1).getOffset(); IASTDeclSpecifier declSpec; IASTDeclarator declarator; List<IASTAttributeSpecifier> attributes = attributeSpecifierSeq(); try { - Decl decl= declSpecifierSequence_initDeclarator(options, true); - declSpec= decl.fDeclSpec1; - declarator= decl.fDtor1; + Decl decl = declSpecifierSequence_initDeclarator(options, true); + declSpec = decl.fDeclSpec1; + declarator = decl.fDtor1; } catch (FoundAggregateInitializer lie) { - declSpec= lie.fDeclSpec; - declarator= addInitializer(lie, options); + declSpec = lie.fDeclSpec; + declarator = addInitializer(lie, options); } final int endOffset = figureEndOffset(declSpec, declarator); - final IASTSimpleDeclaration decl= getNodeFactory().newSimpleDeclaration(declSpec); + final IASTSimpleDeclaration decl = getNodeFactory().newSimpleDeclaration(declSpec); if (declarator != null) decl.addDeclarator(declarator); ((ASTNode) decl).setOffsetAndLength(startOffset, endOffset - startOffset); @@ -5136,14 +5176,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private void consumeArrayModifiers(DeclarationOptions option, List<IASTArrayModifier> collection) throws EndOfFileException, BacktrackException { - boolean allowExpression= option == DeclarationOptions.TYPEID_NEW; + boolean allowExpression = option == DeclarationOptions.TYPEID_NEW; while (LT(1) == IToken.tLBRACKET) { int startOffset = consume().getOffset(); // eat the '[' IASTExpression exp = null; if (LT(1) != IToken.tRBRACKET && LT(1) != IToken.tEOC) { exp = allowExpression ? expression() : constantExpression(); - allowExpression= false; + allowExpression = false; } int endOffset; switch (LT(1)) { @@ -5202,29 +5242,29 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { statement = parseWhileStatement(); break; case IToken.t_do: - statement = parseDoStatement(); + statement = parseDoStatement(); break; case IToken.t_for: - statement = parseForStatement(); + statement = parseForStatement(); break; // jump statement case IToken.t_break: statement = parseBreakStatement(); break; case IToken.t_continue: - statement = parseContinueStatement(); + statement = parseContinueStatement(); break; case IToken.t_return: - statement = parseReturnStatement(); + statement = parseReturnStatement(); break; case IToken.t_goto: - statement = parseGotoStatement(); + statement = parseGotoStatement(); break; case IToken.tSEMI: - statement = parseNullStatement(); + statement = parseNullStatement(); break; case IToken.t_try: - statement = parseTryStatement(); + statement = parseTryStatement(); break; default: // can be many things: @@ -5294,28 +5334,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } protected IASTNode cppStyleCondition(int expectToken) throws BacktrackException, EndOfFileException { - IASTExpression e= null; - IASTSimpleDeclaration decl= null; - IToken end= null; + IASTExpression e = null; + IASTSimpleDeclaration decl = null; + IToken end = null; IToken mark = mark(); try { - decl= simpleSingleDeclaration(DeclarationOptions.CONDITION); - end= LA(1); - final int la= end.getType(); + decl = simpleSingleDeclaration(DeclarationOptions.CONDITION); + end = LA(1); + final int la = end.getType(); if (la != expectToken && la != IToken.tEOC) { - end= null; - decl= null; + end = null; + decl = null; } } catch (BacktrackException b) { } backup(mark); try { - e= expression(); + e = expression(); - final IToken end2= LA(1); - final int la= end2.getType(); + final IToken end2 = LA(1); + final int la = end2.getType(); if (la != expectToken && la != IToken.tEOC) { throwBacktrack(end2); } @@ -5325,7 +5365,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int endOffset = end.getOffset(); final int endOffset2 = end2.getOffset(); if (endOffset == endOffset2) { - CPPASTAmbiguousCondition ambig= new CPPASTAmbiguousCondition(e, decl); + CPPASTAmbiguousCondition ambig = new CPPASTAmbiguousCondition(e, decl); setRange(ambig, e); return ambig; } @@ -5369,7 +5409,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } consume(IToken.tLPAREN); // init-statement - IToken mark= mark(); + IToken mark = mark(); try { IASTStatement statement = initStatement(); new_if_statement.setInitializerStatement(statement); @@ -5377,7 +5417,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); } // condition - IASTNode condition= cppStyleCondition(IToken.tRPAREN); + IASTNode condition = cppStyleCondition(IToken.tRPAREN); if (LT(1) == IToken.tEOC) { // Completing in the condition if (condition instanceof IASTExpression) @@ -5395,7 +5435,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTStatement thenClause = statement(); ((ASTNode) new_if_statement).setOffset(so); if (condition != null && (condition instanceof IASTExpression || condition instanceof IASTDeclaration)) - // shouldn't be possible but failure in condition() makes it so + // shouldn't be possible but failure in condition() makes it so { if (condition instanceof IASTExpression) new_if_statement.setConditionExpression((IASTExpression) condition); @@ -5404,7 +5444,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (thenClause != null) { new_if_statement.setThenClause(thenClause); - ((ASTNode) new_if_statement).setLength(calculateEndOffset(thenClause) - ((ASTNode) new_if_statement).getOffset()); + ((ASTNode) new_if_statement) + .setLength(calculateEndOffset(thenClause) - ((ASTNode) new_if_statement).getOffset()); } if (LT(1) == IToken.t_else) { consume(); @@ -5413,7 +5454,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (if_statement != null) { if_statement.setElseClause(new_if_statement); - ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset()); + ((ASTNode) if_statement) + .setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset()); } if (result == null && if_statement != null) result = if_statement; @@ -5427,7 +5469,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { new_if_statement.setElseClause(elseStatement); if (if_statement != null) { if_statement.setElseClause(new_if_statement); - ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset()); + ((ASTNode) if_statement) + .setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset()); } else { if (result == null) result = new_if_statement; @@ -5471,7 +5514,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTSwitchStatement switch_statement = getNodeFactory().newSwitchStatement(); // init-statement - IToken mark= mark(); + IToken mark = mark(); try { IASTStatement statement = initStatement(); switch_statement.setInitializerStatement(statement); @@ -5507,18 +5550,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } protected IASTStatement parseForStatement() throws EndOfFileException, BacktrackException { - final int offset= consume(IToken.t_for).getOffset(); + final int offset = consume(IToken.t_for).getOffset(); consume(IToken.tLPAREN); - IToken mark= mark(); + IToken mark = mark(); IASTStatement forStmt; try { - forStmt= startRangeBasedForLoop(); + forStmt = startRangeBasedForLoop(); } catch (BacktrackException e) { backup(mark); - forStmt= startTraditionalForLoop(); + forStmt = startTraditionalForLoop(); } - mark= null; - int endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); + mark = null; + int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); if (LT(1) != IToken.tEOC) { IASTStatement body = statement(); @@ -5527,7 +5570,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { ((IASTForStatement) forStmt).setBody(body); } - endOffset= calculateEndOffset(body); + endOffset = calculateEndOffset(body); } return setRange(forStmt, offset, endOffset); } @@ -5540,17 +5583,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // braced-init-list private ICPPASTRangeBasedForStatement startRangeBasedForLoop() throws EndOfFileException, BacktrackException { List<IASTAttributeSpecifier> attributes = attributeSpecifierSeq(); - IASTDeclaration decl= simpleDeclaration(DeclarationOptions.RANGE_BASED_FOR, attributes); + IASTDeclaration decl = simpleDeclaration(DeclarationOptions.RANGE_BASED_FOR, attributes); consume(IToken.tCOLON); - IASTInitializerClause init= null; + IASTInitializerClause init = null; switch (LT(1)) { case IToken.tEOC: break; case IToken.tLBRACE: - init= bracedInitList(false, false); + init = bracedInitList(false, false); break; default: - init= expression(); + init = expression(); } ICPPASTRangeBasedForStatement result = getNodeFactory().newRangeBasedForStatement(); @@ -5561,8 +5604,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTForStatement startTraditionalForLoop() throws BacktrackException, EndOfFileException { final IASTStatement initStmt = initStatement(); - IASTNode condition= null; - IASTExpression iterExpr= null; + IASTNode condition = null; + IASTExpression iterExpr = null; int lt1 = LT(1); if (lt1 != IToken.tSEMI && lt1 != IToken.tEOC) { @@ -5588,25 +5631,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException { - final int offset= consume(IToken.t_return).getOffset(); // t_return + final int offset = consume(IToken.t_return).getOffset(); // t_return // Optional expression IASTInitializerClause expr = null; final int lt1 = LT(1); if (lt1 == IToken.tLBRACE) { - expr= bracedInitList(true, false); + expr = bracedInitList(true, false); } else if (lt1 != IToken.tSEMI) { expr = expression(); } // Semicolon - final int endOffset= consumeOrEOC(IToken.tSEMI).getEndOffset(); + final int endOffset = consumeOrEOC(IToken.tSEMI).getEndOffset(); return setRange(getNodeFactory().newReturnStatement(expr), offset, endOffset); } @Override - protected IASTExpression expressionWithOptionalTrailingEllipsis() throws BacktrackException, - EndOfFileException { + protected IASTExpression expressionWithOptionalTrailingEllipsis() throws BacktrackException, EndOfFileException { IASTExpression result = expression(); if (LT(1) == IToken.tELLIPSIS) { result = addPackExpansion(result, consume()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTExplicitTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTExplicitTemplateInstantiation.java index 4946426f513..0b09c181d44 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTExplicitTemplateInstantiation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTExplicitTemplateInstantiation.java @@ -20,11 +20,10 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation * @deprecated Replaced by {@link CPPASTExplicitTemplateInstantiation}. */ @Deprecated -public class GPPASTExplicitTemplateInstantiation extends - CPPASTExplicitTemplateInstantiation implements - IGPPASTExplicitTemplateInstantiation { +public class GPPASTExplicitTemplateInstantiation extends CPPASTExplicitTemplateInstantiation + implements IGPPASTExplicitTemplateInstantiation { - public GPPASTExplicitTemplateInstantiation() { + public GPPASTExplicitTemplateInstantiation() { super(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointer.java index 4597e6a9c39..e557e226ebe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointer.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; @Deprecated public class GPPASTPointer extends CPPASTPointer implements IGPPASTPointer { - @Override + @Override public GPPASTPointer copy() { return copy(CopyStyle.withoutLocations); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointerToMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointerToMember.java index 51ede21f082..1015e9aec0c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointerToMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTPointerToMember.java @@ -20,10 +20,9 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; * @deprecated */ @Deprecated -public class GPPASTPointerToMember extends CPPASTPointerToMember implements - IGPPASTPointerToMember { +public class GPPASTPointerToMember extends CPPASTPointerToMember implements IGPPASTPointerToMember { - public GPPASTPointerToMember() { + public GPPASTPointerToMember() { super(); } @@ -39,8 +38,7 @@ public class GPPASTPointerToMember extends CPPASTPointerToMember implements @Override public GPPASTPointerToMember copy(CopyStyle style) { IASTName name = getName(); - GPPASTPointerToMember copy = new GPPASTPointerToMember(name == null ? null - : name.copy(style)); + GPPASTPointerToMember copy = new GPPASTPointerToMember(name == null ? null : name.copy(style)); copy.setConst(isConst()); copy.setVolatile(isVolatile()); copy.setRestrict(isRestrict()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java index 8ec1cdbe336..98831459c47 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java @@ -21,10 +21,9 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; * @deprecated Replaced by {@link CPPASTSimpleDeclSpecifier} */ @Deprecated -public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier - implements IGPPASTSimpleDeclSpecifier { +public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier implements IGPPASTSimpleDeclSpecifier { - public GPPASTSimpleDeclSpecifier() { + public GPPASTSimpleDeclSpecifier() { } public GPPASTSimpleDeclSpecifier(IASTExpression typeofExpression) { @@ -42,13 +41,13 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier return copy(new GPPASTSimpleDeclSpecifier(), style); } - @Override + @Override public void setTypeofExpression(IASTExpression typeofExpression) { - setDeclTypeExpression(typeofExpression); - } + setDeclTypeExpression(typeofExpression); + } - @Override + @Override public IASTExpression getTypeofExpression() { - return getDeclTypeExpression(); - } + return getDeclTypeExpression(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/IASTAmbiguousCondition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/IASTAmbiguousCondition.java index 66912083273..edec365fd0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/IASTAmbiguousCondition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/IASTAmbiguousCondition.java @@ -20,6 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; * Marks ambiguous condition nodes. */ public interface IASTAmbiguousCondition extends IASTExpression { - public static final ASTNodeProperty SUBCONDITION = new ASTNodeProperty("IASTAmbiguousCondition.SUBCONDITION"); //$NON-NLS-1$ + public static final ASTNodeProperty SUBCONDITION = new ASTNodeProperty("IASTAmbiguousCondition.SUBCONDITION"); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java index 427718177b5..d33ba32f77b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java @@ -22,7 +22,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; /** * Interface for deferred class template instances. */ -public interface ICPPDeferredClassInstance extends ICPPUnknownBinding, ICPPUnknownType, ICPPClassType, ICPPTemplateInstance { +public interface ICPPDeferredClassInstance + extends ICPPUnknownBinding, ICPPUnknownType, ICPPClassType, ICPPTemplateInstance { /** * Returns the class template for the deferred instantiation. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 73d9b775879..2624aa05e97 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -31,6 +31,7 @@ public interface ICPPEvaluation { public static final ICPPEvaluation[] EMPTY_ARRAY = {}; boolean isInitializerList(); + boolean isFunctionSet(); /** @@ -49,8 +50,7 @@ public interface ICPPEvaluation { * @param point the point of instantiation, determines the scope for name lookups */ boolean isConstantExpression(); - - + /** * Returns {@code true} if this expression is equivalent to 'other' for * declaration matching purposes. @@ -161,7 +161,7 @@ public interface ICPPEvaluation { * Otherwise returns {@code null}. */ IBinding getTemplateDefinition(); - + /** * Marshals an ICPPEvaluation object for storage in the index. * diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalDeclaredVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalDeclaredVariable.java index 360d1b60287..81db7b733e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalDeclaredVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalDeclaredVariable.java @@ -18,7 +18,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; */ public interface ICPPInternalDeclaredVariable extends ICPPInternalVariable { /** - * Informs the variable that all its declarations and definitions have already been added. + * Informs the variable that all its declarations and definitions have already been added. */ public void allDeclarationsDefinitionsAdded(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java index 7b8c6f3ce73..684246a26b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java @@ -26,9 +26,9 @@ public interface ICPPInternalFunction extends ICPPInternalBinding, ICPPComputabl */ public IBinding resolveParameter(CPPParameter parameter); - /** - * Returns whether there is a static declaration for this function. - * @param resolveAll checks for names that are not yet resolved to this binding. - */ - public boolean isStatic(boolean resolveAll); + /** + * Returns whether there is a static declaration for this function. + * @param resolveAll checks for names that are not yet resolved to this binding. + */ + public boolean isStatic(boolean resolveAll); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java index 5b30956d566..8b312634f2f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java @@ -16,6 +16,5 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; /** * Interface for templates from the AST. */ -public interface ICPPInternalTemplate - extends ICPPTemplateParameterOwner, ICPPInternalBinding, ICPPInstanceCache { +public interface ICPPInternalTemplate extends ICPPTemplateParameterOwner, ICPPInternalBinding, ICPPInstanceCache { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java index 9d28a5d7c5b..31e89c01677 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java @@ -27,5 +27,5 @@ public interface ICPPUnknownBinding extends ICPPBinding { * Returns the scope this binding represents. * @throws DOMException */ - public ICPPScope asScope() throws DOMException; + public ICPPScope asScope() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ImplicitsAnalysis.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ImplicitsAnalysis.java index d4171fc8ae2..809aca85ba6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ImplicitsAnalysis.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ImplicitsAnalysis.java @@ -78,56 +78,54 @@ final class ImplicitsAnalysis { * Returns the number of implicit methods to declare not counting the inherited constructors. */ public int getImplicitsToDeclareCount() { - return (!hasDestructor ? 1 : 0) - + (!hasConstructor ? 1 : 0) - + (!hasCopyConstructor ? 1 : 0) - + (!hasCopyAssignmentOperator ? 1 : 0); + return (!hasDestructor ? 1 : 0) + (!hasConstructor ? 1 : 0) + (!hasCopyConstructor ? 1 : 0) + + (!hasCopyAssignmentOperator ? 1 : 0); } private void analyzeMembers(ICPPASTCompositeTypeSpecifier compositeTypeSpecifier) { IASTDeclaration[] members = compositeTypeSpecifier.getMembers(); char[] name = compositeTypeSpecifier.getName().getLookupKey(); - for (IASTDeclaration member : members) { - IASTDeclarator dcltor = null; - IASTDeclSpecifier spec = null; + for (IASTDeclaration member : members) { + IASTDeclarator dcltor = null; + IASTDeclSpecifier spec = null; if (member instanceof IASTSimpleDeclaration) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators(); - if (dtors.length != 1) - continue; - dcltor = dtors[0]; - spec = ((IASTSimpleDeclaration) member).getDeclSpecifier(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators(); + if (dtors.length != 1) + continue; + dcltor = dtors[0]; + spec = ((IASTSimpleDeclaration) member).getDeclSpecifier(); } else if (member instanceof IASTFunctionDefinition) { - dcltor = ((IASTFunctionDefinition) member).getDeclarator(); - spec = ((IASTFunctionDefinition) member).getDeclSpecifier(); + dcltor = ((IASTFunctionDefinition) member).getDeclarator(); + spec = ((IASTFunctionDefinition) member).getDeclSpecifier(); } if (!(dcltor instanceof ICPPASTFunctionDeclarator)) continue; - char[] declName= ASTQueries.findInnermostDeclarator(dcltor).getName().getLookupKey(); + char[] declName = ASTQueries.findInnermostDeclarator(dcltor).getName().getLookupKey(); - if (spec instanceof IASTSimpleDeclSpecifier && - ((IASTSimpleDeclSpecifier) spec).getType() == IASTSimpleDeclSpecifier.t_unspecified) { + if (spec instanceof IASTSimpleDeclSpecifier + && ((IASTSimpleDeclSpecifier) spec).getType() == IASTSimpleDeclSpecifier.t_unspecified) { if (CharArrayUtils.equals(declName, name)) { hasConstructor = true; IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) dcltor).getParameters(); - if (params.length != 0 && hasTypeReferenceToClassType(params[0]) - && parametersHaveInitializers(params, 1)) { - hasCopyConstructor = true; - } - } else if (declName.length != 0 && declName[0] == '~' && - CharArrayUtils.equals(declName, 1, name.length, name)) { + if (params.length != 0 && hasTypeReferenceToClassType(params[0]) + && parametersHaveInitializers(params, 1)) { + hasCopyConstructor = true; + } + } else if (declName.length != 0 && declName[0] == '~' + && CharArrayUtils.equals(declName, 1, name.length, name)) { hasDestructor = true; } } else if (CharArrayUtils.equals(declName, OverloadableOperator.ASSIGN.toCharArray())) { IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) dcltor).getParameters(); - if (params.length == 1 && hasTypeReferenceToClassType(params[0])) - hasCopyAssignmentOperator = true; + if (params.length == 1 && hasTypeReferenceToClassType(params[0])) + hasCopyAssignmentOperator = true; } if (hasCopyConstructor && hasDestructor && hasCopyAssignmentOperator) break; - } + } } private boolean hasTypeReferenceToClassType(IASTParameterDeclaration decl) { @@ -136,7 +134,7 @@ final class ImplicitsAnalysis { if (t != null) { t = SemanticUtil.getNestedType(t, TDEF); if (t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference()) { - t = SemanticUtil.getNestedType(t, TDEF|REF|CVTYPE); + t = SemanticUtil.getNestedType(t, TDEF | REF | CVTYPE); return classType.isSameType(t); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/InstantiationContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/InstantiationContext.java index 3c23d3d8a7c..61b889c2838 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/InstantiationContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/InstantiationContext.java @@ -59,8 +59,7 @@ public final class InstantiationContext { * @param contextSpecialization the specialization if instantiation happens inside a specialized * type or function, otherwise {@code null}. */ - public InstantiationContext(ICPPTemplateParameterMap parameterMap, - ICPPSpecialization contextSpecialization) { + public InstantiationContext(ICPPTemplateParameterMap parameterMap, ICPPSpecialization contextSpecialization) { this(parameterMap, -1, contextSpecialization); } @@ -131,7 +130,8 @@ public final class InstantiationContext { * {@code null}. */ public final ICPPTypeSpecialization getContextTypeSpecialization() { - return contextSpecialization instanceof ICPPTypeSpecialization ? (ICPPTypeSpecialization) contextSpecialization : null; + return contextSpecialization instanceof ICPPTypeSpecialization ? (ICPPTypeSpecialization) contextSpecialization + : null; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/NameOrTemplateIDVariants.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/NameOrTemplateIDVariants.java index 850f0c148a3..28ac86455ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/NameOrTemplateIDVariants.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/NameOrTemplateIDVariants.java @@ -32,46 +32,50 @@ public class NameOrTemplateIDVariants { private final int fConditionCount; private final BinaryOperator fLeftOperator; - BranchPoint(BranchPoint next, Variant variant, - BinaryOperator left, boolean allowAssignment, int conditionCount) { - fNext= next; - fFirstVariant= variant; - fAllowAssignment= allowAssignment; - fConditionCount= conditionCount; - fLeftOperator= left; + BranchPoint(BranchPoint next, Variant variant, BinaryOperator left, boolean allowAssignment, + int conditionCount) { + fNext = next; + fFirstVariant = variant; + fAllowAssignment = allowAssignment; + fConditionCount = conditionCount; + fLeftOperator = left; // Set owner while (variant != null) { - variant.fOwner= this; - variant= variant.getNext(); + variant.fOwner = this; + variant = variant.getNext(); } } public boolean isAllowAssignment() { return fAllowAssignment; } + public int getConditionCount() { return fConditionCount; } + public BinaryOperator getLeftOperator() { return fLeftOperator; } + public Variant getFirstVariant() { return fFirstVariant; } + public BranchPoint getNext() { return fNext; } public void reverseVariants() { - Variant prev= null; - Variant curr= fFirstVariant; + Variant prev = null; + Variant curr = fFirstVariant; while (curr != null) { - Variant next= curr.getNext(); - curr.fNext= prev; - prev= curr; - curr= next; + Variant next = curr.getNext(); + curr.fNext = prev; + prev = curr; + curr = next; } - fFirstVariant= prev; + fFirstVariant = prev; } } @@ -87,50 +91,54 @@ public class NameOrTemplateIDVariants { private final IASTName[] fTemplateNames; public Variant(Variant next, IASTExpression expr, IASTName[] templateNames, int rightOffset) { - fNext= next; - fExpression= expr; - fRightOffset= rightOffset; - fTemplateNames= templateNames; + fNext = next; + fExpression = expr; + fRightOffset = rightOffset; + fTemplateNames = templateNames; } public BranchPoint getOwner() { return fOwner; } + public int getRightOffset() { return fRightOffset; } + public IASTName[] getTemplateNames() { return fTemplateNames; } + public Variant getNext() { return fNext; } + public IASTExpression getExpression() { return fExpression; } + public BinaryOperator getTargetOperator() { return fTargetOperator; } + public void setTargetOperator(BinaryOperator lastOperator) { - fTargetOperator= lastOperator; + fTargetOperator = lastOperator; } } - private BranchPoint fFirst; public boolean isEmpty() { return fFirst == null; } - public void addBranchPoint(Variant variants, BinaryOperator left, - boolean allowAssignment, int conditionCount) { - fFirst= new BranchPoint(fFirst, variants, left, allowAssignment, conditionCount); + public void addBranchPoint(Variant variants, BinaryOperator left, boolean allowAssignment, int conditionCount) { + fFirst = new BranchPoint(fFirst, variants, left, allowAssignment, conditionCount); } public void closeVariants(int offset, BinaryOperator lastOperator) { - for (BranchPoint p = fFirst; p != null; p= p.getNext()) { - for (Variant v= p.getFirstVariant(); v != null; v= v.getNext()) { + for (BranchPoint p = fFirst; p != null; p = p.getNext()) { + for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) { if (v.getTargetOperator() == null) { if (offset == v.getRightOffset()) { v.setTargetOperator(lastOperator); @@ -142,12 +150,12 @@ public class NameOrTemplateIDVariants { public Variant selectFallback() { // Search for an open variant, with a small right offset and a large left offset - for (BranchPoint p = fFirst; p != null; p= p.getNext()) { - Variant best= null; - for (Variant v= p.getFirstVariant(); v != null; v= v.getNext()) { + for (BranchPoint p = fFirst; p != null; p = p.getNext()) { + Variant best = null; + for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) { if (v.getTargetOperator() == null) { if (best == null || v.fRightOffset < best.fRightOffset) { - best= v; + best = v; } } } @@ -162,9 +170,9 @@ public class NameOrTemplateIDVariants { private void remove(Variant remove) { final BranchPoint owner = remove.fOwner; final Variant next = remove.getNext(); - Variant prev= owner.getFirstVariant(); + Variant prev = owner.getFirstVariant(); if (remove == prev) { - owner.fFirstVariant= next; + owner.fFirstVariant = next; if (next == null) { remove(owner); } @@ -172,10 +180,10 @@ public class NameOrTemplateIDVariants { while (prev != null) { Variant n = prev.getNext(); if (n == remove) { - prev.fNext= next; + prev.fNext = next; break; } - prev= n; + prev = n; } } } @@ -183,38 +191,38 @@ public class NameOrTemplateIDVariants { private void remove(BranchPoint remove) { final BranchPoint next = remove.getNext(); if (remove == fFirst) { - fFirst= next; + fFirst = next; } else { - BranchPoint prev= fFirst; + BranchPoint prev = fFirst; while (prev != null) { BranchPoint n = prev.getNext(); if (n == remove) { - prev.fNext= next; + prev.fNext = next; break; } - prev= n; + prev = n; } } } public BranchPoint getOrderedBranchPoints() { - BranchPoint prev= null; - BranchPoint curr= fFirst; + BranchPoint prev = null; + BranchPoint curr = fFirst; while (curr != null) { curr.reverseVariants(); - BranchPoint next= curr.getNext(); - curr.fNext= prev; - prev= curr; - curr= next; + BranchPoint next = curr.getNext(); + curr.fNext = prev; + prev = curr; + curr = next; } - fFirst= null; + fFirst = null; return prev; } public boolean hasRightBound(int opOffset) { // Search for an open variant, with a small right offset and a large left offset - for (BranchPoint p = fFirst; p != null; p= p.getNext()) { - for (Variant v= p.getFirstVariant(); v != null; v= v.getNext()) { + for (BranchPoint p = fFirst; p != null; p = p.getNext()) { + for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) { if (v.fRightOffset > opOffset) return false; } @@ -223,11 +231,11 @@ public class NameOrTemplateIDVariants { } public void removeInvalid(BinaryOperator lastOperator) { - for (BranchPoint p = fFirst; p != null; p= p.getNext()) { + for (BranchPoint p = fFirst; p != null; p = p.getNext()) { if (!isReachable(p, lastOperator)) { remove(p); } else { - for (Variant v= p.getFirstVariant(); v != null; v= v.getNext()) { + for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) { if (v.getTargetOperator() == null) { remove(v); } @@ -241,7 +249,7 @@ public class NameOrTemplateIDVariants { if (op == null) return true; - for (; endOperator != null; endOperator= endOperator.getNext()) { + for (; endOperator != null; endOperator = endOperator.getNext()) { if (endOperator == op) return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/OverloadableOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/OverloadableOperator.java index 0db81acd0d6..5303b2c5367 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/OverloadableOperator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/OverloadableOperator.java @@ -31,48 +31,12 @@ import org.eclipse.cdt.core.parser.IToken; */ @SuppressWarnings("nls") public enum OverloadableOperator { - GT(">"), - LT("<"), - NOT("!"), - BITCOMPLEMENT("~"), - BITOR("|"), - AMPER("&"), - XOR("^"), - MOD("%"), - DIV("/"), - STAR("*"), - PLUS("+"), - BRACKET("[]"), - PAREN("()"), - ARROW("->"), - ARROWSTAR("->*"), - COMMA(","), - MINUS("-"), - DECR("--"), - INCR("++"), - OR("||"), - AND("&&"), - ASSIGN("="), - GTEQUAL(">="), - LTEQUAL("<="), - NOTEQUAL("!="), - EQUAL("=="), - SHIFTR(">>"), - SHIFTL("<<"), - SHIFTLASSIGN("<<="), - SHIFTRASSIGN(">>="), - BITORASSIGN("|="), - AMPERASSIGN("&="), - XORASSIGN("^="), - MODASSIGN("%="), - DIVASSIGN("/="), - STARASSIGN("*="), - MINUSASSIGN("-="), - PLUSASSIGN("+="), - NEW("new"), - DELETE_ARRAY("delete[]"), - DELETE("delete"), - NEW_ARRAY("new[]"), + GT(">"), LT("<"), NOT("!"), BITCOMPLEMENT("~"), BITOR("|"), AMPER("&"), XOR("^"), MOD("%"), DIV("/"), STAR("*"), + PLUS("+"), BRACKET("[]"), PAREN("()"), ARROW("->"), ARROWSTAR("->*"), COMMA(","), MINUS("-"), DECR("--"), + INCR("++"), OR("||"), AND("&&"), ASSIGN("="), GTEQUAL(">="), LTEQUAL("<="), NOTEQUAL("!="), EQUAL("=="), + SHIFTR(">>"), SHIFTL("<<"), SHIFTLASSIGN("<<="), SHIFTRASSIGN(">>="), BITORASSIGN("|="), AMPERASSIGN("&="), + XORASSIGN("^="), MODASSIGN("%="), DIVASSIGN("/="), STARASSIGN("*="), MINUSASSIGN("-="), PLUSASSIGN("+="), + NEW("new"), DELETE_ARRAY("delete[]"), DELETE("delete"), NEW_ARRAY("new[]"), /** * Cannot be overloaded by the user, however overload resolution needs to be performed. @@ -113,57 +77,99 @@ public enum OverloadableOperator { */ public static OverloadableOperator valueOf(IToken token) { switch (token.getType()) { - case IToken.t_delete: return DELETE; - case IToken.t_new: return NEW; - case IToken.tAMPER: return AMPER; - case IToken.tAMPERASSIGN: return AMPERASSIGN; - case IToken.tARROW: return ARROW; - case IToken.tARROWSTAR: return ARROWSTAR; - case IToken.tBITOR: return BITOR; - case IToken.tBITORASSIGN: return BITORASSIGN; - case IToken.tBITCOMPLEMENT: return BITCOMPLEMENT; - case IToken.tSHIFTL: return SHIFTL; - case IToken.tSHIFTLASSIGN: return SHIFTLASSIGN; - case IToken.tSHIFTR: return SHIFTR; - case IToken.tSHIFTRASSIGN: return SHIFTRASSIGN; - case IToken.tXOR: return XOR; - case IToken.tXORASSIGN: return XORASSIGN; - - // logical operations - case IToken.tNOT: return NOT; - case IToken.tAND: return AND; - case IToken.tOR: return OR; + case IToken.t_delete: + return DELETE; + case IToken.t_new: + return NEW; + case IToken.tAMPER: + return AMPER; + case IToken.tAMPERASSIGN: + return AMPERASSIGN; + case IToken.tARROW: + return ARROW; + case IToken.tARROWSTAR: + return ARROWSTAR; + case IToken.tBITOR: + return BITOR; + case IToken.tBITORASSIGN: + return BITORASSIGN; + case IToken.tBITCOMPLEMENT: + return BITCOMPLEMENT; + case IToken.tSHIFTL: + return SHIFTL; + case IToken.tSHIFTLASSIGN: + return SHIFTLASSIGN; + case IToken.tSHIFTR: + return SHIFTR; + case IToken.tSHIFTRASSIGN: + return SHIFTRASSIGN; + case IToken.tXOR: + return XOR; + case IToken.tXORASSIGN: + return XORASSIGN; + + // logical operations + case IToken.tNOT: + return NOT; + case IToken.tAND: + return AND; + case IToken.tOR: + return OR; // arithmetic - case IToken.tDECR: return DECR; - case IToken.tINCR: return INCR; - case IToken.tDIV: return DIV; - case IToken.tDIVASSIGN: return DIVASSIGN; - case IToken.tMINUS: return MINUS; - case IToken.tMINUSASSIGN: return MINUSASSIGN; - case IToken.tMOD: return MOD; - case IToken.tMODASSIGN: return MODASSIGN; - case IToken.tPLUS: return PLUS; - case IToken.tPLUSASSIGN: return PLUSASSIGN; - case IToken.tSTAR: return STAR; - case IToken.tSTARASSIGN: return STARASSIGN; + case IToken.tDECR: + return DECR; + case IToken.tINCR: + return INCR; + case IToken.tDIV: + return DIV; + case IToken.tDIVASSIGN: + return DIVASSIGN; + case IToken.tMINUS: + return MINUS; + case IToken.tMINUSASSIGN: + return MINUSASSIGN; + case IToken.tMOD: + return MOD; + case IToken.tMODASSIGN: + return MODASSIGN; + case IToken.tPLUS: + return PLUS; + case IToken.tPLUSASSIGN: + return PLUSASSIGN; + case IToken.tSTAR: + return STAR; + case IToken.tSTARASSIGN: + return STARASSIGN; // comparison - case IToken.tEQUAL: return EQUAL; - case IToken.tNOTEQUAL: return NOTEQUAL; - case IToken.tGT: return GT; - case IToken.tGTEQUAL: return GTEQUAL; - case IToken.tLT: return LT; - case IToken.tLTEQUAL: return LTEQUAL; + case IToken.tEQUAL: + return EQUAL; + case IToken.tNOTEQUAL: + return NOTEQUAL; + case IToken.tGT: + return GT; + case IToken.tGTEQUAL: + return GTEQUAL; + case IToken.tLT: + return LT; + case IToken.tLTEQUAL: + return LTEQUAL; // other - case IToken.tASSIGN: return ASSIGN; - case IToken.tCOMMA: return COMMA; + case IToken.tASSIGN: + return ASSIGN; + case IToken.tCOMMA: + return COMMA; - case IToken.tLBRACKET: return BRACKET; - case IToken.tRBRACKET: return BRACKET; - case IToken.tLPAREN: return PAREN; - case IToken.tRPAREN: return PAREN; + case IToken.tLBRACKET: + return BRACKET; + case IToken.tRBRACKET: + return BRACKET; + case IToken.tLPAREN: + return PAREN; + case IToken.tRPAREN: + return PAREN; } return null; @@ -177,44 +183,74 @@ public enum OverloadableOperator { */ public static OverloadableOperator fromBinaryExpression(int binaryOp) { switch (binaryOp) { - case IASTBinaryExpression.op_binaryAnd: return AMPER; - case IASTBinaryExpression.op_binaryAndAssign: return AMPERASSIGN; - case IASTBinaryExpression.op_pmarrow: return ARROWSTAR; - case IASTBinaryExpression.op_binaryOr: return BITOR; - case IASTBinaryExpression.op_binaryOrAssign: return BITORASSIGN; - case IASTBinaryExpression.op_shiftLeft: return SHIFTL; - case IASTBinaryExpression.op_shiftLeftAssign: return SHIFTLASSIGN; - case IASTBinaryExpression.op_shiftRight: return SHIFTR; - case IASTBinaryExpression.op_shiftRightAssign: return SHIFTRASSIGN; - case IASTBinaryExpression.op_binaryXor: return XOR; - case IASTBinaryExpression.op_binaryXorAssign: return XORASSIGN; - - // logical operations - case IASTBinaryExpression.op_logicalAnd: return AND; - case IASTBinaryExpression.op_logicalOr: return OR; + case IASTBinaryExpression.op_binaryAnd: + return AMPER; + case IASTBinaryExpression.op_binaryAndAssign: + return AMPERASSIGN; + case IASTBinaryExpression.op_pmarrow: + return ARROWSTAR; + case IASTBinaryExpression.op_binaryOr: + return BITOR; + case IASTBinaryExpression.op_binaryOrAssign: + return BITORASSIGN; + case IASTBinaryExpression.op_shiftLeft: + return SHIFTL; + case IASTBinaryExpression.op_shiftLeftAssign: + return SHIFTLASSIGN; + case IASTBinaryExpression.op_shiftRight: + return SHIFTR; + case IASTBinaryExpression.op_shiftRightAssign: + return SHIFTRASSIGN; + case IASTBinaryExpression.op_binaryXor: + return XOR; + case IASTBinaryExpression.op_binaryXorAssign: + return XORASSIGN; + + // logical operations + case IASTBinaryExpression.op_logicalAnd: + return AND; + case IASTBinaryExpression.op_logicalOr: + return OR; // arithmetic - case IASTBinaryExpression.op_divide: return DIV; - case IASTBinaryExpression.op_divideAssign: return DIVASSIGN; - case IASTBinaryExpression.op_minus: return MINUS; - case IASTBinaryExpression.op_minusAssign: return MINUSASSIGN; - case IASTBinaryExpression.op_modulo: return MOD; - case IASTBinaryExpression.op_moduloAssign: return MODASSIGN; - case IASTBinaryExpression.op_plus: return PLUS; - case IASTBinaryExpression.op_plusAssign: return PLUSASSIGN; - case IASTBinaryExpression.op_multiply: return STAR; - case IASTBinaryExpression.op_multiplyAssign: return STARASSIGN; + case IASTBinaryExpression.op_divide: + return DIV; + case IASTBinaryExpression.op_divideAssign: + return DIVASSIGN; + case IASTBinaryExpression.op_minus: + return MINUS; + case IASTBinaryExpression.op_minusAssign: + return MINUSASSIGN; + case IASTBinaryExpression.op_modulo: + return MOD; + case IASTBinaryExpression.op_moduloAssign: + return MODASSIGN; + case IASTBinaryExpression.op_plus: + return PLUS; + case IASTBinaryExpression.op_plusAssign: + return PLUSASSIGN; + case IASTBinaryExpression.op_multiply: + return STAR; + case IASTBinaryExpression.op_multiplyAssign: + return STARASSIGN; // comparison - case IASTBinaryExpression.op_equals: return EQUAL; - case IASTBinaryExpression.op_notequals: return NOTEQUAL; - case IASTBinaryExpression.op_greaterThan: return GT; - case IASTBinaryExpression.op_greaterEqual: return GTEQUAL; - case IASTBinaryExpression.op_lessThan: return LT; - case IASTBinaryExpression.op_lessEqual: return LTEQUAL; + case IASTBinaryExpression.op_equals: + return EQUAL; + case IASTBinaryExpression.op_notequals: + return NOTEQUAL; + case IASTBinaryExpression.op_greaterThan: + return GT; + case IASTBinaryExpression.op_greaterEqual: + return GTEQUAL; + case IASTBinaryExpression.op_lessThan: + return LT; + case IASTBinaryExpression.op_lessEqual: + return LTEQUAL; // other - case IASTBinaryExpression.op_assign: return ASSIGN; + case IASTBinaryExpression.op_assign: + return ASSIGN; } return null; @@ -222,16 +258,26 @@ public enum OverloadableOperator { public static OverloadableOperator fromUnaryExpression(int unaryOp) { switch (unaryOp) { - case IASTUnaryExpression.op_prefixIncr: return INCR; - case IASTUnaryExpression.op_prefixDecr: return DECR; - case IASTUnaryExpression.op_plus: return PLUS; - case IASTUnaryExpression.op_minus: return MINUS; - case IASTUnaryExpression.op_star: return STAR; - case IASTUnaryExpression.op_amper: return AMPER; - case IASTUnaryExpression.op_tilde: return BITCOMPLEMENT; - case IASTUnaryExpression.op_not: return NOT; - case IASTUnaryExpression.op_postFixIncr: return INCR; - case IASTUnaryExpression.op_postFixDecr: return DECR; + case IASTUnaryExpression.op_prefixIncr: + return INCR; + case IASTUnaryExpression.op_prefixDecr: + return DECR; + case IASTUnaryExpression.op_plus: + return PLUS; + case IASTUnaryExpression.op_minus: + return MINUS; + case IASTUnaryExpression.op_star: + return STAR; + case IASTUnaryExpression.op_amper: + return AMPER; + case IASTUnaryExpression.op_tilde: + return BITCOMPLEMENT; + case IASTUnaryExpression.op_not: + return NOT; + case IASTUnaryExpression.op_postFixIncr: + return INCR; + case IASTUnaryExpression.op_postFixDecr: + return DECR; } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/TemplateIdStrategy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/TemplateIdStrategy.java index d202939ae86..6bcc2418726 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/TemplateIdStrategy.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/TemplateIdStrategy.java @@ -54,8 +54,8 @@ final class TemplateIdStrategy implements ITemplateIdStrategy { private IASTName[] fTemplateNames; public TemplateIdStrategy() { - fCurrentBranchPoint= -1; - fTemplateNames= IASTName.EMPTY_NAME_ARRAY; + fCurrentBranchPoint = -1; + fTemplateNames = IASTName.EMPTY_NAME_ARRAY; } /** @@ -71,9 +71,9 @@ final class TemplateIdStrategy implements ITemplateIdStrategy { // 'fSimpleIDs == null' means we're on the first alternative. // On the first alternative, everything is parsed as a template-id. - boolean templateID= fSimpleIDs == null || !fSimpleIDs.get(fCurrentBranchPoint); + boolean templateID = fSimpleIDs == null || !fSimpleIDs.get(fCurrentBranchPoint); if (templateID) { - fTemplateNames= ArrayUtil.append(fTemplateNames, name); + fTemplateNames = ArrayUtil.append(fTemplateNames, name); } return templateID; } @@ -94,18 +94,18 @@ final class TemplateIdStrategy implements ITemplateIdStrategy { // Reset the current position, saving the old one, which should point to the last name in the // bitset for which parsing was attempted during the previous alternative. int bp = fCurrentBranchPoint; - fCurrentBranchPoint= -1; + fCurrentBranchPoint = -1; // Reset the list of names that were parsed as template-ids, saving the list for the previous // alternative. IASTName[] names = getTemplateNames(); // Note that 'names' here contains the list of names for which there is a '0' in the bitset. - int nameLen= names.length; - fTemplateNames= IASTName.EMPTY_NAME_ARRAY; + int nameLen = names.length; + fTemplateNames = IASTName.EMPTY_NAME_ARRAY; // If the previous alternative was the first, the bitset is still null. Create it. if (fSimpleIDs == null) { - fSimpleIDs= new BitSet(); + fSimpleIDs = new BitSet(); } // Advance to the next alternative by finding the right-most '0' in the bitset, and setting it to '1', @@ -125,7 +125,7 @@ final class TemplateIdStrategy implements ITemplateIdStrategy { // successfully (bug 445177). // TODO: This optimization is invalid since it triggers bug 497931. if (previousAlternativeFailedToParse || nameLen == 0 || !hasMultipleArgs(names[--nameLen])) { - fSimpleIDs.clear(bp+1, Integer.MAX_VALUE); + fSimpleIDs.clear(bp + 1, Integer.MAX_VALUE); fSimpleIDs.set(bp); return true; } @@ -138,7 +138,7 @@ final class TemplateIdStrategy implements ITemplateIdStrategy { } private boolean hasMultipleArgs(IASTName templateName) { - IASTNode parent= templateName.getParent(); + IASTNode parent = templateName.getParent(); if (parent instanceof ICPPASTTemplateId) { return ((ICPPASTTemplateId) parent).getTemplateArguments().length > 1; } @@ -156,11 +156,12 @@ final class TemplateIdStrategy implements ITemplateIdStrategy { * backtracking we need to restore the branch point that was active at the point * we're backing up to (otherwise, the current branch point could get out of sync * with the parsing position). These methods facilitate marking and backing up to - * the current branch point for such situations. + * the current branch point for such situations. */ public int getCurrentBranchPoint() { return fCurrentBranchPoint; } + public void backupToBranchPoint(int branchPoint) { fCurrentBranchPoint = branchPoint; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/VariableHelpers.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/VariableHelpers.java index f80a64e3100..df7c37954fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/VariableHelpers.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/VariableHelpers.java @@ -78,8 +78,7 @@ public class VariableHelpers { } if (parent instanceof IASTSimpleDeclaration) { - ICPPASTDeclSpecifier declSpec = - (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier(); if (declSpec != null) return declSpec.isConstexpr(); } @@ -98,8 +97,7 @@ public class VariableHelpers { // the declarations. // See http://bugs.eclipse.org/434150 if (definition != null && !doneWithDefinition - && (i == length - || ((ASTNode) definition).getOffset() < ((ASTNode) declarations[i]).getOffset())) { + && (i == length || ((ASTNode) definition).getOffset() < ((ASTNode) declarations[i]).getOffset())) { n = definition; doneWithDefinition = true; --i; // We still have to come back to the declaration at position i. @@ -133,8 +131,7 @@ public class VariableHelpers { return firstCandidate; } - private static void resolveAllDeclarations(ICPPVariable variable, IASTName definition, - IASTName[] declarations) { + private static void resolveAllDeclarations(ICPPVariable variable, IASTName definition, IASTName[] declarations) { final int length = declarations == null ? 0 : declarations.length; for (int i = -1; i < length; i++) { @SuppressWarnings("null") @@ -219,15 +216,15 @@ public class VariableHelpers { private static IASTDeclaration getPrimaryDeclaration(ICPPInternalVariable field) { // First check if we already know it. - IASTDeclaration decl= findDeclaration(field.getDefinition()); + IASTDeclaration decl = findDeclaration(field.getDefinition()); if (decl != null) { return decl; } - IASTName[] declarations = (IASTName[]) field.getDeclarations(); + IASTName[] declarations = (IASTName[]) field.getDeclarations(); if (declarations != null) { for (IASTName name : declarations) { - decl= findDeclaration(name); + decl = findDeclaration(name); if (decl != null) { return decl; } @@ -237,8 +234,8 @@ public class VariableHelpers { char[] myName = field.getNameCharArray(); ICPPClassScope scope = findClassScope(field); - ICPPASTCompositeTypeSpecifier compSpec = - (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope); + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal + .getPhysicalNodeOfScope(scope); IASTDeclaration[] members = compSpec.getMembers(); for (IASTDeclaration member : members) { if (member instanceof IASTSimpleDeclaration) { @@ -280,7 +277,7 @@ public class VariableHelpers { } if (node != null && node.getParent() instanceof ICPPASTCompositeTypeSpecifier) { return (IASTDeclaration) node; - } + } return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java index aa0401ef36a..b0790a9071c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java @@ -97,7 +97,7 @@ public class AccessContext { */ private boolean isUnqualifiedLookup; private boolean isPrefixLookup; - private ICPPClassType namingClass; // Depends on the binding for which we check the access. + private ICPPClassType namingClass; // Depends on the binding for which we check the access. // The first candidate is independent of the binding for which we do the access-check. private ICPPClassType firstCandidateForNamingClass; private DOMException initializationException; @@ -125,14 +125,13 @@ public class AccessContext { if (binding instanceof ICPPMember) { bindingVisibility = ((ICPPMember) binding).getVisibility(); } else { - while (binding instanceof ICPPSpecialization) { - binding = ((ICPPSpecialization) binding).getSpecializedBinding(); - } + while (binding instanceof ICPPSpecialization) { + binding = ((ICPPSpecialization) binding).getSpecializedBinding(); + } if (binding instanceof ICPPClassTemplatePartialSpecialization) { // A class template partial specialization requires its primary // template to be visible - if (!isAccessible( - ((ICPPClassTemplatePartialSpecialization) binding).getPrimaryClassTemplate())) + if (!isAccessible(((ICPPClassTemplatePartialSpecialization) binding).getPrimaryClassTemplate())) return false; } if (binding instanceof ICPPAliasTemplateInstance) { @@ -160,8 +159,7 @@ public class AccessContext { */ public boolean isAccessible(IBinding binding, int bindingVisibility) { IBinding owner; - while ((owner = binding.getOwner()) instanceof ICompositeType && - ((ICompositeType) owner).isAnonymous()) { + while ((owner = binding.getOwner()) instanceof ICompositeType && ((ICompositeType) owner).isAnonymous()) { binding = owner; } if (!(owner instanceof ICPPClassType)) { @@ -170,13 +168,12 @@ public class AccessContext { if (!initialize()) { return true; // Assume visibility if anything goes wrong. } - ICPPClassType accessOwner= (ICPPClassType) owner; + ICPPClassType accessOwner = (ICPPClassType) owner; namingClass = getNamingClass(accessOwner); if (namingClass == null) { return true; } - return isAccessible(binding, bindingVisibility, accessOwner, namingClass, - v_public, 0); + return isAccessible(binding, bindingVisibility, accessOwner, namingClass, v_public, 0); } /** @@ -189,7 +186,7 @@ public class AccessContext { } try { context = getContext(name); - firstCandidateForNamingClass= getFirstCandidateForNamingClass(name); + firstCandidateForNamingClass = getFirstCandidateForNamingClass(name); } catch (DOMException e) { CCorePlugin.log(e); initializationException = e; @@ -232,14 +229,14 @@ public class AccessContext { } } } - + ICPPBase[] bases = derivedClass.getBases(); if (bases != null) { for (ICPPBase base : bases) { IBinding baseBinding = base.getBaseClass(); if (baseBinding instanceof ICPPDeferredClassInstance) { // Support content assist for members of deferred instances. - baseBinding= ((ICPPDeferredClassInstance) baseBinding).getTemplateDefinition(); + baseBinding = ((ICPPDeferredClassInstance) baseBinding).getTemplateDefinition(); } if (!(baseBinding instanceof ICPPClassType)) { continue; @@ -247,8 +244,8 @@ public class AccessContext { if (!isAccessible(base.getVisibility(), accessLevel)) { continue; } - if (isAccessible(binding, bindingVisibility, owner, - (ICPPClassType) baseBinding, accessLevel == v_private ? v_protected : accessLevel, depth + 1)) { + if (isAccessible(binding, bindingVisibility, owner, (ICPPClassType) baseBinding, + accessLevel == v_private ? v_protected : accessLevel, depth + 1)) { return true; } } @@ -309,7 +306,7 @@ public class AccessContext { private ICPPClassType getFirstCandidateForNamingClass(IASTName name) throws DOMException { LookupData data = new LookupData(name); - isUnqualifiedLookup= !data.qualified; + isUnqualifiedLookup = !data.qualified; ICPPScope scope = CPPSemantics.getLookupScope(name); while (scope != null && !(scope instanceof ICPPClassScope)) { @@ -338,17 +335,16 @@ public class AccessContext { ICPPClassType classType = firstCandidateForNamingClass; if (classType != null && isUnqualifiedLookup) { IBinding owner = classType.getOwner(); - while (owner instanceof ICPPClassType && - !derivesFrom(classType, accessOwner, name, CPPSemantics.MAX_INHERITANCE_DEPTH)) { - classType= (ICPPClassType) owner; - owner= classType.getOwner(); + while (owner instanceof ICPPClassType + && !derivesFrom(classType, accessOwner, name, CPPSemantics.MAX_INHERITANCE_DEPTH)) { + classType = (ICPPClassType) owner; + owner = classType.getOwner(); } } return classType; } - private static boolean derivesFrom(ICPPClassType derived, ICPPClassType target, IASTNode point, - int maxdepth) { + private static boolean derivesFrom(ICPPClassType derived, ICPPClassType target, IASTNode point, int maxdepth) { if (derived == target || derived.isSameType(target)) { return true; } @@ -375,12 +371,12 @@ public class AccessContext { private static IBinding[] getContext(IASTName name) { IBinding[] accessibilityContext = IBinding.EMPTY_BINDING_ARRAY; - for (IBinding binding = CPPVisitor.findEnclosingFunctionOrClass(name); - binding != null; binding = binding.getOwner()) { + for (IBinding binding = CPPVisitor.findEnclosingFunctionOrClass(name); binding != null; binding = binding + .getOwner()) { if (binding instanceof ICPPMethod || - // Definition of an undeclared method. - binding instanceof IProblemBinding && - ((IProblemBinding) binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) { + // Definition of an undeclared method. + binding instanceof IProblemBinding && ((IProblemBinding) binding) + .getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) { continue; } if (binding instanceof ICPPFunction || binding instanceof ICPPClassType) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java index 4e51d5dd1b7..4ca169e751c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java @@ -34,10 +34,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter; */ class AutoTypeResolver implements ICPPFunctionTemplate { // Template parameter of the function. This parameter is used in place of 'auto' keyword. - public static final ICPPTemplateTypeParameter AUTO_TYPE = - new CPPTemplateTypeParameter(new CPPASTName(), false); - private static final ICPPTemplateTypeParameter[] TEMPLATE_PARAMETERS = - new ICPPTemplateTypeParameter[] { AUTO_TYPE }; + public static final ICPPTemplateTypeParameter AUTO_TYPE = new CPPTemplateTypeParameter(new CPPASTName(), false); + private static final ICPPTemplateTypeParameter[] TEMPLATE_PARAMETERS = new ICPPTemplateTypeParameter[] { + AUTO_TYPE }; private static final String UNEXPECTED_CALL = "Unexpected call"; //$NON-NLS-1$ private final CPPFunctionType functionType; @@ -54,7 +53,7 @@ class AutoTypeResolver implements ICPPFunctionTemplate { public ICPPFunctionType getDeclaredType() { return functionType; } - + @Override public ICPPFunctionType getType() { return functionType; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java index f2458bbcf0e..13f1bef138b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java @@ -56,30 +56,29 @@ class BaseClassLookup { if (classScope == null) return; - final ICPPClassType classType= classScope.getClassType(); + final ICPPClassType classType = classScope.getClassType(); if (classType == null) return; final HashMap<IScope, BaseClassLookup> infoMap = new HashMap<>(); - BaseClassLookup rootInfo= lookupInBaseClass(data, null, false, classType, infoMap, 0); + BaseClassLookup rootInfo = lookupInBaseClass(data, null, false, classType, infoMap, 0); if (data.contentAssist) { rootInfo.collectResultForContentAssist(data); } else { hideVirtualBases(rootInfo, infoMap); - IBinding[] result= rootInfo.collectResult(data, true, IBinding.EMPTY_BINDING_ARRAY); + IBinding[] result = rootInfo.collectResult(data, true, IBinding.EMPTY_BINDING_ARRAY); if (data.problem == null) { data.foundItems = ArrayUtil.addAll((Object[]) data.foundItems, result); } else if (result.length > 0) { data.problem.setCandidateBindings(result); } -// verifyResult(data, result); + // verifyResult(data, result); } } - private final ICPPClassType fClassType; private IBinding[] fBindings; - private List<BaseClassLookup> fChildren= Collections.emptyList(); + private List<BaseClassLookup> fChildren = Collections.emptyList(); private BitSet fVirtual; private boolean fHiddenAsVirtualBase; private boolean fPropagationDone; @@ -88,8 +87,8 @@ class BaseClassLookup { private final IASTNode fLookupPoint; private BaseClassLookup(ICPPClassType type, IASTNode lookupPoint) { - fClassType= type; - fLookupPoint= lookupPoint; + fClassType = type; + fLookupPoint = lookupPoint; } ICPPClassType getClassType() { @@ -113,26 +112,26 @@ class BaseClassLookup { return; if (fChildren.isEmpty()) { - fChildren= new ArrayList<>(); - fVirtual= new BitSet(); + fChildren = new ArrayList<>(); + fVirtual = new BitSet(); } fVirtual.set(fChildren.size(), virtual); fChildren.add(baseInfo); } public void setResult(IBinding[] bindings) { - fBindings= bindings; + fBindings = bindings; } public void setHiddenAsVirtualBase() { - fHiddenAsVirtualBase= true; + fHiddenAsVirtualBase = true; } public void propagateHiddenAsVirtual() { if (fPropagationDone) return; - fPropagationDone= true; - for (int i= 0; i < fChildren.size(); i++) { + fPropagationDone = true; + for (int i = 0; i < fChildren.size(); i++) { BaseClassLookup child = fChildren.get(i); if (fVirtual.get(i)) { child.setHiddenAsVirtualBase(); @@ -153,19 +152,19 @@ class BaseClassLookup { return false; } - static BaseClassLookup lookupInBaseClass(LookupData data, ICPPClassScope baseClassScope, - boolean isVirtual, ICPPClassType root, HashMap<IScope, BaseClassLookup> infoMap, int depth) { + static BaseClassLookup lookupInBaseClass(LookupData data, ICPPClassScope baseClassScope, boolean isVirtual, + ICPPClassType root, HashMap<IScope, BaseClassLookup> infoMap, int depth) { if (depth++ > CPPSemantics.MAX_INHERITANCE_DEPTH) return null; if (baseClassScope != null) { - BaseClassLookup info= infoMap.get(baseClassScope); + BaseClassLookup info = infoMap.get(baseClassScope); if (info != null) { // Avoid loops. if (info.getResult() == null) { - data.problem = new ProblemBinding(null, IProblemBinding.SEMANTIC_CIRCULAR_INHERITANCE, - root.getNameCharArray()); - return null; + data.problem = new ProblemBinding(null, IProblemBinding.SEMANTIC_CIRCULAR_INHERITANCE, + root.getNameCharArray()); + return null; } return info; } @@ -173,23 +172,23 @@ class BaseClassLookup { // This is the first time to handle the class. BaseClassLookup result; - IBinding[] matches= IBinding.EMPTY_BINDING_ARRAY; + IBinding[] matches = IBinding.EMPTY_BINDING_ARRAY; if (baseClassScope == null) { - result= new BaseClassLookup(root, data.getLookupPoint()); + result = new BaseClassLookup(root, data.getLookupPoint()); infoMap.put(root.getCompositeScope(), result); } else { - result= new BaseClassLookup(baseClassScope.getClassType(), data.getLookupPoint()); + result = new BaseClassLookup(baseClassScope.getClassType(), data.getLookupPoint()); infoMap.put(baseClassScope, result); try { // Determine the name qualifier if the lookup name is a definition. - ICPPASTNameSpecifier nameQualifier = null; + ICPPASTNameSpecifier nameQualifier = null; if (data.qualified) { // Check if the name qualifier is in agreement with the base class name. IASTName lookupName = data.getLookupName(); - if (lookupName != null && lookupName.getPropertyInParent() == ICPPASTQualifiedName.SEGMENT_NAME && - lookupName.getRoleOfName(false) == IASTNameOwner.r_definition) { - ICPPASTQualifiedName qName = (ICPPASTQualifiedName) lookupName.getParent(); - ICPPASTNameSpecifier[] qualifiers = qName.getQualifier(); + if (lookupName != null && lookupName.getPropertyInParent() == ICPPASTQualifiedName.SEGMENT_NAME + && lookupName.getRoleOfName(false) == IASTNameOwner.r_definition) { + ICPPASTQualifiedName qName = (ICPPASTQualifiedName) lookupName.getParent(); + ICPPASTNameSpecifier[] qualifiers = qName.getQualifier(); for (int i = 0; i < qualifiers.length && lookupName != qualifiers[i]; i++) { nameQualifier = qualifiers[i]; } @@ -197,11 +196,12 @@ class BaseClassLookup { } IName baseClassScopeName = baseClassScope.getScopeName(); - if (nameQualifier == null || (baseClassScopeName != null && Arrays.equals(baseClassScopeName.getSimpleID(), nameQualifier.toCharArray()))) { - IBinding[] members= CPPSemantics.getBindingsFromScope(baseClassScope, data); + if (nameQualifier == null || (baseClassScopeName != null + && Arrays.equals(baseClassScopeName.getSimpleID(), nameQualifier.toCharArray()))) { + IBinding[] members = CPPSemantics.getBindingsFromScope(baseClassScope, data); if (members != null && members.length > 0 && members[0] != null) { if (data.isPrefixLookup()) { - matches= members; + matches = members; } else { result.setResult(members); return result; @@ -215,14 +215,14 @@ class BaseClassLookup { // There is no result in the baseClass itself or we do content assist, we have to examine // its base classes. - ICPPClassType baseClass= result.getClassType(); + ICPPClassType baseClass = result.getClassType(); if (baseClass != null) { - ICPPBase[] grandBases= baseClass.getBases(); + ICPPBase[] grandBases = baseClass.getBases(); if (grandBases != null && grandBases.length > 0) { - HashSet<IBinding> grandBaseBindings= null; - BitSet selectedBases= null; + HashSet<IBinding> grandBaseBindings = null; + BitSet selectedBases = null; if (grandBases.length > 1) { - grandBaseBindings= new HashSet<>(); + grandBaseBindings = new HashSet<>(); // If we have reachable bases, then ignore the others. selectedBases = selectPreferredBases(data, grandBases); @@ -237,7 +237,7 @@ class BaseClassLookup { // 14.6.2.3 scope is not examined. if (grandBaseBinding instanceof ICPPUnknownBinding) { if (data.skippedScope == null) - data.skippedScope= root; + data.skippedScope = root; } continue; } @@ -245,22 +245,22 @@ class BaseClassLookup { ICPPClassType grandBaseClass = (ICPPClassType) grandBaseBinding; if (data.fHeuristicBaseLookup && grandBaseClass instanceof ICPPDeferredClassInstance) { // Support content assist for members of deferred instances. - grandBaseClass= ((ICPPDeferredClassInstance) grandBaseClass).getClassTemplate(); + grandBaseClass = ((ICPPDeferredClassInstance) grandBaseClass).getClassTemplate(); } if (grandBaseBindings != null && !grandBaseBindings.add(grandBaseClass)) continue; - final IScope grandBaseScope= grandBaseClass.getCompositeScope(); + final IScope grandBaseScope = grandBaseClass.getCompositeScope(); if (grandBaseScope == null || grandBaseScope instanceof ICPPInternalUnknownScope) { // 14.6.2.3 scope is not examined. if (data.skippedScope == null) - data.skippedScope= root; + data.skippedScope = root; continue; } if (!(grandBaseScope instanceof ICPPClassScope)) continue; - BaseClassLookup baseInfo= lookupInBaseClass(data, (ICPPClassScope) grandBaseScope, + BaseClassLookup baseInfo = lookupInBaseClass(data, (ICPPClassScope) grandBaseScope, grandBase.isVirtual(), root, infoMap, depth); if (baseInfo != null) result.addBase(grandBase.isVirtual(), baseInfo); @@ -276,19 +276,19 @@ class BaseClassLookup { return null; BitSet selectedBases; - selectedBases= new BitSet(grandBases.length); - IName baseName= null; + selectedBases = new BitSet(grandBases.length); + IName baseName = null; for (int i = 0; i < grandBases.length; i++) { ICPPBase nbase = grandBases[i]; if (nbase instanceof IProblemBinding) continue; final IName nbaseName = nbase.getClassDefinitionName(); - int cmp= baseName == null ? 0 : CPPSemantics.compareByRelevance(data, baseName, nbaseName); + int cmp = baseName == null ? 0 : CPPSemantics.compareByRelevance(data, baseName, nbaseName); if (cmp <= 0) { if (cmp < 0) { selectedBases.clear(); - baseName= nbaseName; + baseName = nbaseName; } selectedBases.set(i); } @@ -297,11 +297,11 @@ class BaseClassLookup { } static void hideVirtualBases(BaseClassLookup rootInfo, HashMap<IScope, BaseClassLookup> infoMap) { - boolean containsVirtualBase= false; + boolean containsVirtualBase = false; final BaseClassLookup[] allInfos = infoMap.values().toArray(new BaseClassLookup[infoMap.size()]); for (BaseClassLookup info : allInfos) { if (info.containsVirtualBase()) { - containsVirtualBase= true; + containsVirtualBase = true; break; } } @@ -319,8 +319,8 @@ class BaseClassLookup { return; if (fClassType != null) { - ICPPBase[] bases= null; - bases= fClassType.getBases(); + ICPPBase[] bases = null; + bases = fClassType.getBases(); if (bases != null && bases.length > 0) { for (ICPPBase base : bases) { IBinding baseBinding = base.getBaseClass(); @@ -329,11 +329,11 @@ class BaseClassLookup { } final ICPPClassType baseClass = (ICPPClassType) baseBinding; - final IScope baseScope= baseClass.getCompositeScope(); + final IScope baseScope = baseClass.getCompositeScope(); if (!(baseScope instanceof ICPPClassScope)) continue; - BaseClassLookup baseInfo= infoMap.get(baseScope); + BaseClassLookup baseInfo = infoMap.get(baseScope); if (baseInfo != null) { if (base.isVirtual()) { baseInfo.setHiddenAsVirtualBase(); @@ -341,7 +341,7 @@ class BaseClassLookup { baseInfo.propagateHiddenAsVirtual(); } else { // Mark to catch recursions. - baseInfo= new BaseClassLookup(baseClass, fLookupPoint); + baseInfo = new BaseClassLookup(baseClass, fLookupPoint); infoMap.put(baseScope, baseInfo); baseInfo.hideVirtualBases(infoMap, depth); } @@ -353,12 +353,12 @@ class BaseClassLookup { public void collectResultForContentAssist(LookupData data) { if (fCollected) return; - fCollected= true; + fCollected = true; @SuppressWarnings("unchecked") final CharArrayObjectMap<Object> resultMap = (CharArrayObjectMap<Object>) data.foundItems; data.foundItems = CPPSemantics.mergePrefixResults(resultMap, fBindings, true); - for (int i= 0; i < fChildren.size(); i++) { + for (int i = 0; i < fChildren.size(); i++) { BaseClassLookup child = fChildren.get(i); child.collectResultForContentAssist(data); } @@ -370,14 +370,14 @@ class BaseClassLookup { return result; } else { if (fCollectedAsRegularBase && data.problem == null && containsNonStaticMember()) { - data.problem= new ProblemBinding(data.getLookupName(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); + data.problem = new ProblemBinding(data.getLookupName(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); } - fCollectedAsRegularBase= true; + fCollectedAsRegularBase = true; } if (fCollected) return result; - fCollected= true; + fCollected = true; int numBindingsToAdd = 0; for (int i = 0; i < fBindings.length; i++) { @@ -395,7 +395,7 @@ class BaseClassLookup { // an indication of ambiguity (but see below). possibleAmbiguity = true; } - result= ArrayUtil.addAll(result, fBindings); + result = ArrayUtil.addAll(result, fBindings); if (possibleAmbiguity) { // [temp.local] p4: // A lookup that finds an injected-class-name can result in an @@ -407,13 +407,13 @@ class BaseClassLookup { // specialization thereof, and is not ambiguous. result = collapseInjectedClassNames(data, result); if (result.length > 1) { - data.problem= new ProblemBinding(data.getLookupName(), - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, result); + data.problem = new ProblemBinding(data.getLookupName(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + result); } } - for (int i= 0; i < fChildren.size(); i++) { + for (int i = 0; i < fChildren.size(); i++) { BaseClassLookup child = fChildren.get(i); - result= child.collectResult(data, fVirtual.get(i), result); + result = child.collectResult(data, fVirtual.get(i), result); } return result; } @@ -430,8 +430,8 @@ class BaseClassLookup { ICPPTemplateDefinition template = null; for (IBinding binding : result) { if (binding instanceof ICPPClassType && binding instanceof ICPPTemplateInstance) { - ICPPTemplateDefinition specialized = - (ICPPTemplateDefinition) ((ICPPTemplateInstance) binding).getSpecializedBinding(); + ICPPTemplateDefinition specialized = (ICPPTemplateDefinition) ((ICPPTemplateInstance) binding) + .getSpecializedBinding(); if (template == null) { template = specialized; continue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java index 9327c4c02ae..6dcf8df35c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java @@ -65,8 +65,7 @@ class BuiltinOperators { private static final int SECOND = 1; private static final IType PTR_DIFF = new CPPBasicType(Kind.eInt, 0); - public static ICPPFunction[] create(OverloadableOperator operator, ICPPEvaluation[] args, - Object[] globCandidates) { + public static ICPPFunction[] create(OverloadableOperator operator, ICPPEvaluation[] args, Object[] globCandidates) { if (operator == null || args == null || args.length == 0) return EMPTY; @@ -77,31 +76,29 @@ class BuiltinOperators { private final boolean fUnary; private IType fType1; private IType fType2; - private IType[][] fClassConversionTypes= { null, null }; - private boolean[] fIsClass= { false, false }; + private IType[][] fClassConversionTypes = { null, null }; + private boolean[] fIsClass = { false, false }; private IScope fFileScope; private List<ICPPFunction> fResult; private Set<String> fSignatures; private Object[] fGlobalCandidates; - BuiltinOperators(OverloadableOperator operator, ICPPEvaluation[] args, - Object[] globCandidates) { + BuiltinOperators(OverloadableOperator operator, ICPPEvaluation[] args, Object[] globCandidates) { IASTNode point = CPPSemantics.getCurrentLookupPoint(); - fFileScope= point == null ? - new CPPScope.CPPScopeProblem(null, IProblemBinding.SEMANTIC_BAD_SCOPE) : - point.getTranslationUnit().getScope(); - fOperator= operator; - fUnary= args.length < 2; - fGlobalCandidates= globCandidates; + fFileScope = point == null ? new CPPScope.CPPScopeProblem(null, IProblemBinding.SEMANTIC_BAD_SCOPE) + : point.getTranslationUnit().getScope(); + fOperator = operator; + fUnary = args.length < 2; + fGlobalCandidates = globCandidates; if (args.length > 0) { - IType type= args[0].getType(); + IType type = args[0].getType(); if (!(type instanceof ISemanticProblem)) - fType1= type; + fType1 = type; } if (args.length > 1) { - IType type= args[1].getType(); + IType type = args[1].getType(); if (!(type instanceof ISemanticProblem)) - fType2= type; + fType2 = type; } } @@ -242,25 +239,25 @@ class BuiltinOperators { // 13.6-3, 13.6-4, 13.6-5 private void opIncOrDec() { - IType[] types= getClassConversionTypes(FIRST); + IType[] types = getClassConversionTypes(FIRST); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF); + type = SemanticUtil.getNestedType(type, TDEF); if (type instanceof ICPPReferenceType) { - IType nested= ((ICPPReferenceType) type).getType(); - CVQualifier cvq= SemanticUtil.getCVQualifier(nested); + IType nested = ((ICPPReferenceType) type).getType(); + CVQualifier cvq = SemanticUtil.getCVQualifier(nested); if (!cvq.isConst()) { - nested= SemanticUtil.getNestedType(nested, TDEF | CVTYPE); - boolean ok= false; + nested = SemanticUtil.getNestedType(nested, TDEF | CVTYPE); + boolean ok = false; if (isArithmetic(nested)) { // 13.6-3 and 1.3.6-4 if (fOperator == OverloadableOperator.INCR || !isBoolean(type)) { - ok= true; + ok = true; } } else if (isPointer(nested)) { // 13.6-5 - nested= ((IPointerType) nested).getType(); + nested = ((IPointerType) nested).getType(); if (!(SemanticUtil.getNestedType(nested, TDEF) instanceof IFunctionType)) { - ok= true; + ok = true; } } if (ok) { @@ -277,13 +274,13 @@ class BuiltinOperators { // 13.6-6, 13.6-7 private void opDeref() { - IType[] types= getClassConversionTypes(FIRST); + IType[] types = getClassConversionTypes(FIRST); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF); + type = SemanticUtil.getNestedType(type, TDEF | REF); if (isPointer(type)) { - IType nested= SemanticUtil.getNestedType(((IPointerType) type).getType(), TDEF); + IType nested = SemanticUtil.getNestedType(((IPointerType) type).getType(), TDEF); if (nested instanceof ICPPFunctionType) { - ICPPFunctionType ft= (ICPPFunctionType) nested; + ICPPFunctionType ft = (ICPPFunctionType) nested; if (ft.isConst() || ft.isVolatile()) return; } @@ -294,9 +291,9 @@ class BuiltinOperators { // 13.6-8 private void unaryPointer() { - IType[] types= getClassConversionTypes(FIRST); + IType[] types = getClassConversionTypes(FIRST); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF); + type = SemanticUtil.getNestedType(type, TDEF | REF); if (isPointer(type)) { addFunction(type, type); } @@ -305,15 +302,15 @@ class BuiltinOperators { // 13.6-9, 13.6-10 private void unaryPromotedArithmetic(boolean includeFloatingPoint) { - IType[] types= getClassConversionTypes(FIRST); + IType[] types = getClassConversionTypes(FIRST); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF|CVTYPE); + type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (isFloatingPoint(type)) { if (includeFloatingPoint) { addFunction(type, type); } } else { - type= CPPArithmeticConversion.promoteCppType(type); + type = CPPArithmeticConversion.promoteCppType(type); if (type != null) { addFunction(type, type); } @@ -323,16 +320,16 @@ class BuiltinOperators { // 13.6-11 private void opArrowStar() { - List<IPointerType> classPointers= null; - List<ICPPPointerToMemberType> memberPointers= null; - IType[] types= getClassConversionTypes(FIRST); + List<IPointerType> classPointers = null; + List<ICPPPointerToMemberType> memberPointers = null; + IType[] types = getClassConversionTypes(FIRST); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF | REF); + type = SemanticUtil.getNestedType(type, TDEF | REF); if (isPointer(type)) { final IPointerType ptrType = (IPointerType) type; if (SemanticUtil.getNestedType(ptrType.getType(), TDEF | CVTYPE) instanceof ICPPClassType) { if (classPointers == null) { - classPointers= new ArrayList<>(); + classPointers = new ArrayList<>(); } classPointers.add(ptrType); } @@ -341,12 +338,12 @@ class BuiltinOperators { if (classPointers == null) return; - types= getClassConversionTypes(SECOND); + types = getClassConversionTypes(SECOND); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF | REF); + type = SemanticUtil.getNestedType(type, TDEF | REF); if (type instanceof ICPPPointerToMemberType) { if (memberPointers == null) { - memberPointers= new ArrayList<>(); + memberPointers = new ArrayList<>(); } memberPointers.add((ICPPPointerToMemberType) type); } @@ -355,17 +352,18 @@ class BuiltinOperators { return; for (IPointerType clsPtr : classPointers) { - IType cvClass= SemanticUtil.getNestedType(clsPtr.getType(), TDEF); - CVQualifier cv1= SemanticUtil.getCVQualifier(cvClass); - ICPPClassType c1= (ICPPClassType) SemanticUtil.getNestedType(cvClass, TDEF | CVTYPE); + IType cvClass = SemanticUtil.getNestedType(clsPtr.getType(), TDEF); + CVQualifier cv1 = SemanticUtil.getCVQualifier(cvClass); + ICPPClassType c1 = (ICPPClassType) SemanticUtil.getNestedType(cvClass, TDEF | CVTYPE); for (ICPPPointerToMemberType memPtr : memberPointers) { - IType t2= SemanticUtil.getNestedType(memPtr.getMemberOfClass(), TDEF); + IType t2 = SemanticUtil.getNestedType(memPtr.getMemberOfClass(), TDEF); if (t2 instanceof ICPPClassType) { - ICPPClassType c2= (ICPPClassType) t2; + ICPPClassType c2 = (ICPPClassType) t2; if (SemanticUtil.calculateInheritanceDepth(c1, c2) >= 0) { - IType cvt= SemanticUtil.getNestedType(memPtr.getType(), TDEF); - IType rt= new CPPReferenceType( - SemanticUtil.addQualifiers(cvt, cv1.isConst(), cv1.isVolatile(), cv1.isRestrict()), false); + IType cvt = SemanticUtil.getNestedType(memPtr.getType(), TDEF); + IType rt = new CPPReferenceType( + SemanticUtil.addQualifiers(cvt, cv1.isConst(), cv1.isVolatile(), cv1.isRestrict()), + false); addFunction(rt, clsPtr, memPtr); } } @@ -374,12 +372,15 @@ class BuiltinOperators { } // 13.6-12, 13.6-17 - private static enum ReturnType {CONVERT, USE_FIRST, USE_BOOL} + private static enum ReturnType { + CONVERT, USE_FIRST, USE_BOOL + } + private void binaryPromotedArithmetic(boolean fltPt, ReturnType rstrat) { - List<IType> p1= null, p2= null; + List<IType> p1 = null, p2 = null; - IType[] types1= getClassConversionTypes(FIRST); - IType[] types2= getClassConversionTypes(SECOND); + IType[] types1 = getClassConversionTypes(FIRST); + IType[] types2 = getClassConversionTypes(SECOND); if (types1.length == 0 && types2.length == 0) return; @@ -389,23 +390,23 @@ class BuiltinOperators { for (IType t : types2) { p2 = addPromotedArithmetic(t, fltPt, p2); } - p1= addPromotedArithmetic(fType1, fltPt, p1); - p2= addPromotedArithmetic(fType2, fltPt, p2); + p1 = addPromotedArithmetic(fType1, fltPt, p1); + p2 = addPromotedArithmetic(fType2, fltPt, p2); if (p1 == null || p2 == null) return; for (IType t1 : p1) { for (IType t2 : p2) { - IType rt= null; + IType rt = null; switch (rstrat) { case USE_BOOL: - rt= CPPBasicType.BOOLEAN; + rt = CPPBasicType.BOOLEAN; break; case USE_FIRST: - rt= t1; + rt = t1; break; case CONVERT: - rt= CPPArithmeticConversion.convertCppOperandTypes(IASTBinaryExpression.op_plus, t1, t2); + rt = CPPArithmeticConversion.convertCppOperandTypes(IASTBinaryExpression.op_plus, t1, t2); break; } addFunction(rt, t1, t2); @@ -414,17 +415,17 @@ class BuiltinOperators { } private List<IType> addPromotedArithmetic(IType t, boolean fltPt, List<IType> p1) { - IType type= SemanticUtil.getNestedType(t, TDEF|REF|CVTYPE); + IType type = SemanticUtil.getNestedType(t, TDEF | REF | CVTYPE); if (isFloatingPoint(type)) { if (!fltPt) { - type= null; + type = null; } } else { - type= CPPArithmeticConversion.promoteCppType(type); + type = CPPArithmeticConversion.promoteCppType(type); } if (type != null) { if (p1 == null) { - p1= new ArrayList<>(); + p1 = new ArrayList<>(); } p1.add(type); } @@ -433,17 +434,17 @@ class BuiltinOperators { // 13.6-13, 13.6.14 private void pointerArithmetic(boolean useRef, boolean isDiff) { - IType[] types= getClassConversionTypes(FIRST); + IType[] types = getClassConversionTypes(FIRST); if (types.length == 0 && !fIsClass[FIRST]) { - types= new IType[] {fType1}; + types = new IType[] { fType1 }; } for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF); + type = SemanticUtil.getNestedType(type, TDEF | REF); if (isPointer(type)) { final IType ptrTarget = ((IPointerType) type).getType(); - final IType uqPtrTarget = SemanticUtil.getNestedType(ptrTarget, TDEF|CVTYPE); + final IType uqPtrTarget = SemanticUtil.getNestedType(ptrTarget, TDEF | CVTYPE); if (!(uqPtrTarget instanceof IFunctionType)) { - final IType retType= useRef ? new CPPReferenceType(ptrTarget, false) : type; + final IType retType = useRef ? new CPPReferenceType(ptrTarget, false) : type; addFunction(retType, type, PTR_DIFF); if (isDiff) { addFunction(PTR_DIFF, type, type); @@ -452,20 +453,20 @@ class BuiltinOperators { } } - types= getClassConversionTypes(SECOND); + types = getClassConversionTypes(SECOND); if (types.length == 0 && !fIsClass[SECOND]) { - types= new IType[] {fType2}; + types = new IType[] { fType2 }; } for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF); + type = SemanticUtil.getNestedType(type, TDEF | REF); if (isPointer(type)) { final IType ptrTarget = ((IPointerType) type).getType(); - final IType uqPtrTarget = SemanticUtil.getNestedType(ptrTarget, TDEF|CVTYPE); + final IType uqPtrTarget = SemanticUtil.getNestedType(ptrTarget, TDEF | CVTYPE); if (!(uqPtrTarget instanceof IFunctionType)) { if (isDiff) { addFunction(PTR_DIFF, type, type); } else { - final IType retType= useRef ? new CPPReferenceType(ptrTarget, false) : type; + final IType retType = useRef ? new CPPReferenceType(ptrTarget, false) : type; addFunction(retType, PTR_DIFF, type); } } @@ -476,9 +477,9 @@ class BuiltinOperators { // 13.6-15, 13.6.16 private void comparison(boolean ordered) { for (int i = FIRST; i <= SECOND; i++) { - IType[] types= getClassConversionTypes(i); + IType[] types = getClassConversionTypes(i); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF|CVTYPE); + type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (isPointer(type) || isEnumeration(type) || (!ordered && isPointerToMember(type))) { addFunction(CPPBasicType.BOOLEAN, type, type); } @@ -487,20 +488,23 @@ class BuiltinOperators { } // 13.6-18, 13.6-29, 13.6-20, 13.6-22 - private static enum Assignment {WITHOUT_OPERATION, WITH_POINTER_OPERATION, WITH_OPERATION} + private static enum Assignment { + WITHOUT_OPERATION, WITH_POINTER_OPERATION, WITH_OPERATION + } + private void arithmeticAssignement(boolean fltPt, Assignment assign) { - IType[] types2= getClassConversionTypes(SECOND); + IType[] types2 = getClassConversionTypes(SECOND); if (types2.length == 0) return; - IType refType= SemanticUtil.getNestedType(fType1, TDEF); + IType refType = SemanticUtil.getNestedType(fType1, TDEF); if (refType instanceof ICPPReferenceType) { - IType t= SemanticUtil.getNestedType(((ICPPReferenceType) refType).getType(), TDEF); + IType t = SemanticUtil.getNestedType(((ICPPReferenceType) refType).getType(), TDEF); if (!SemanticUtil.getCVQualifier(t).isConst()) { switch (assign) { case WITHOUT_OPERATION: if (isEnumeration(t) || isPointerToMember(t) || isPointer(t)) { - addFunction(refType, refType, SemanticUtil.getNestedType(t, TDEF|ALLCVQ)); + addFunction(refType, refType, SemanticUtil.getNestedType(t, TDEF | ALLCVQ)); return; } break; @@ -515,7 +519,7 @@ class BuiltinOperators { } } if (fltPt ? isArithmetic(t) : isIntegral(t)) { - List<IType> p2= null; + List<IType> p2 = null; for (IType t2 : types2) { p2 = addPromotedArithmetic(t2, fltPt, p2); } @@ -531,9 +535,9 @@ class BuiltinOperators { // 13.6-25 private void conditional() { for (int i = FIRST; i <= SECOND; i++) { - IType[] types= getClassConversionTypes(i); + IType[] types = getClassConversionTypes(i); for (IType type : types) { - type= SemanticUtil.getNestedType(type, TDEF|REF|CVTYPE); + type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (isPointer(type) || isScopedEnumeration(type) || isPointerToMember(type)) { addFunction(type, type, type); } @@ -542,19 +546,19 @@ class BuiltinOperators { } private void addFunction(IType returnType, IType p1) { - addFunction(returnType, new IType[] {p1}); + addFunction(returnType, new IType[] { p1 }); } private void addFunction(IType returnType, IType p1, IType p2) { - addFunction(returnType, new IType[] {p1, p2}); + addFunction(returnType, new IType[] { p1, p2 }); } private void addFunction(IType returnType, IType[] parameterTypes) { ICPPParameter[] parameter = new ICPPParameter[parameterTypes.length]; ICPPFunctionType functionType = new CPPFunctionType(returnType, parameterTypes); - String sig= ASTTypeUtil.getType(functionType, true); + String sig = ASTTypeUtil.getType(functionType, true); if (fSignatures == null) { - fSignatures= new HashSet<>(); + fSignatures = new HashSet<>(); if (fGlobalCandidates != null) { for (Object cand : fGlobalCandidates) { if (cand instanceof IFunction && !(cand instanceof ICPPMethod)) { @@ -566,12 +570,13 @@ class BuiltinOperators { if (fSignatures.add(sig)) { for (int i = 0; i < parameterTypes.length; i++) { IType t = parameterTypes[i]; - parameter[i]= new CPPBuiltinParameter(t); + parameter[i] = new CPPBuiltinParameter(t); } if (fResult == null) { - fResult= new ArrayList<>(); + fResult = new ArrayList<>(); } - fResult.add(new CPPImplicitFunction(fOperator.toCharArray(), fFileScope, functionType, parameter, true, false)); + fResult.add( + new CPPImplicitFunction(fOperator.toCharArray(), fFileScope, functionType, parameter, true, false)); } } @@ -597,7 +602,7 @@ class BuiltinOperators { public static boolean isFloatingPoint(IType type) { if (type instanceof IBasicType) { - IBasicType.Kind kind= ((IBasicType) type).getKind(); + IBasicType.Kind kind = ((IBasicType) type).getKind(); switch (kind) { case eDouble: case eFloat: @@ -624,7 +629,7 @@ class BuiltinOperators { private static boolean isArithmetic(IType type) { if (type instanceof IBasicType) { - IBasicType.Kind kind= ((IBasicType) type).getKind(); + IBasicType.Kind kind = ((IBasicType) type).getKind(); switch (kind) { case eBoolean: case eChar: @@ -651,7 +656,7 @@ class BuiltinOperators { public static boolean isIntegral(IType type) { if (type instanceof IBasicType) { - IBasicType.Kind kind= ((IBasicType) type).getKind(); + IBasicType.Kind kind = ((IBasicType) type).getKind(); switch (kind) { case eBoolean: case eChar: @@ -679,33 +684,33 @@ class BuiltinOperators { private IType[] getClassConversionTypes(int idx) { IType[] result = fClassConversionTypes[idx]; if (result == null) { - result= IType.EMPTY_TYPE_ARRAY; - IType type= idx == 0 ? fType1 : fType2; + result = IType.EMPTY_TYPE_ARRAY; + IType type = idx == 0 ? fType1 : fType2; if (type != null) { - type= SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); + type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (type instanceof ICPPClassType) { - fIsClass[idx]= true; + fIsClass[idx] = true; try { ICPPMethod[] ops = SemanticUtil.getConversionOperators((ICPPClassType) type); - result= new IType[ops.length]; - int j= -1; + result = new IType[ops.length]; + int j = -1; for (ICPPMethod op : ops) { if (op.isExplicit()) continue; final ICPPFunctionType functionType = op.getType(); if (functionType != null) { - IType retType= functionType.getReturnType(); + IType retType = functionType.getReturnType(); if (retType != null) { - result[++j]= retType; + result[++j] = retType; } } } - result= ArrayUtil.trimAt(IType.class, result, j); + result = ArrayUtil.trimAt(IType.class, result, j); } catch (DOMException e) { } } } - fClassConversionTypes[idx]= result; + fClassConversionTypes[idx] = result; } return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java index 11f093a88e7..7bf07930382 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java @@ -108,8 +108,8 @@ public abstract class CPPDependentEvaluation extends CPPEvaluation { * This code is similar to CPPTemplates.instantiateArguments(), but applies to evaluations * rather than template arguments. */ - protected static ICPPEvaluation[] instantiateCommaSeparatedSubexpressions( - ICPPEvaluation[] subexpressions, InstantiationContext context, int maxDepth) { + protected static ICPPEvaluation[] instantiateCommaSeparatedSubexpressions(ICPPEvaluation[] subexpressions, + InstantiationContext context, int maxDepth) { ICPPEvaluation[] result = subexpressions; int resultShift = 0; for (int i = 0; i < subexpressions.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 1068813c44f..7dd48579219 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -57,7 +57,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return buf.getSignature(); } - + public static IType getType(ICPPASTExpression expr) { CPPSemantics.pushLookupPoint(expr); try { @@ -66,7 +66,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { CPPSemantics.popLookupPoint(); } } - + public static ValueCategory getValueCategory(ICPPASTExpression expr) { CPPSemantics.pushLookupPoint(expr); try { @@ -124,7 +124,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { * Checks if all evaluations contained in the given array are constant expressions. * * @param evaluations the evaluations to check - */ + */ protected static boolean areAllConstantExpressions(ICPPEvaluation[] evaluations) { return areAllConstantExpressions(evaluations, 0, evaluations.length); } @@ -133,9 +133,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { * Checks if all evaluations contained in a range of the given array are constant expressions. * * @param evaluations the evaluations to check - * @param from the initial index of the range to be checked, inclusive - * @param to the final index of the range to be checked, exclusive - */ + * @param from the initial index of the range to be checked, inclusive + * @param to the final index of the range to be checked, exclusive + */ protected static boolean areAllConstantExpressions(ICPPEvaluation[] evaluations, int from, int to) { for (int i = from; i < to; i++) { if (!evaluations[i].isConstantExpression()) { @@ -178,17 +178,17 @@ public abstract class CPPEvaluation implements ICPPEvaluation { if (targetType == null) { return argument; } - + IType type = argument.getType(); - + // Types match - don't bother to check for conversions. if (targetType.isSameType(type)) { return argument; } - + try { // Source type is class type - check for conversion operator. - IType uqType= SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); + IType uqType = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); ValueCategory valueCategory = argument.getValueCategory(); if (uqType instanceof ICPPClassType) { Cost cost = Conversions.initializationByConversion(valueCategory, type, (ICPPClassType) uqType, @@ -198,15 +198,15 @@ public abstract class CPPEvaluation implements ICPPEvaluation { if (!conversion.isConstexpr()) { return EvalFixed.INCOMPLETE; } - ICPPEvaluation eval = new EvalMemberAccess(uqType, valueCategory, conversion, argument, - false, CPPSemantics.getCurrentLookupPoint()); + ICPPEvaluation eval = new EvalMemberAccess(uqType, valueCategory, conversion, argument, false, + CPPSemantics.getCurrentLookupPoint()); return new EvalFunctionCall(new ICPPEvaluation[] { eval }, null, (IBinding) null); } } - + // Source type is not a class type, or is but a conversion operator wasn't used. // Check for standard conversions. - if (!Conversions.checkImplicitConversionSequence(targetType, type, valueCategory, UDCMode.FORBIDDEN, + if (!Conversions.checkImplicitConversionSequence(targetType, type, valueCategory, UDCMode.FORBIDDEN, Context.ORDINARY).converts()) { return EvalFixed.INCOMPLETE; } @@ -215,14 +215,14 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return argument; } - + protected static boolean areEquivalentOrNull(ICPPEvaluation a, ICPPEvaluation b) { if (a == null) { return (b == null); } return a.isEquivalentTo(b); } - + protected static boolean areEquivalentEvaluations(ICPPEvaluation[] a, ICPPEvaluation[] b) { if (a == null) { return (b == null); @@ -237,7 +237,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return true; } - + protected static boolean areEquivalentArguments(ICPPTemplateArgument[] a, ICPPTemplateArgument[] b) { if (a == null) { return (b == null); @@ -252,7 +252,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return true; } - + protected static boolean areEquivalentTypes(IType[] a, IType[] b) { if (a == null) { return (b == null); @@ -267,7 +267,7 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return true; } - + protected static <T extends IBinding> boolean areEquivalentBindings(T[] a, T[] b) { if (a == null) { return (b == null); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java index 01f35684803..3f85830e879 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPFunctionSet.java @@ -38,8 +38,8 @@ public class CPPFunctionSet implements ICPPTwoPhaseBinding { public CPPFunctionSet(ICPPFunction[] bindingList, ICPPTemplateArgument[] args, IASTName name) { fBindings = ArrayUtil.removeNulls(bindingList); - fTemplateArguments= args; - fName= name; + fTemplateArguments = args; + fName = name; } @Override @@ -115,15 +115,14 @@ public class CPPFunctionSet implements ICPPTwoPhaseBinding { return super.toString(); } } - + @Override public boolean equals(Object other) { if (!(other instanceof CPPFunctionSet)) { return false; } CPPFunctionSet o = (CPPFunctionSet) other; - return CPPEvaluation.areEquivalentBindings(fBindings, o.fBindings) - && fName == o.fName - && CPPEvaluation.areEquivalentArguments(fTemplateArguments, o.fTemplateArguments); + return CPPEvaluation.areEquivalentBindings(fBindings, o.fBindings) && fName == o.fName + && CPPEvaluation.areEquivalentArguments(fTemplateArguments, o.fTemplateArguments); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPInheritance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPInheritance.java index 46503b0b033..179cfeebaa9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPInheritance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPInheritance.java @@ -171,8 +171,8 @@ public class CPPInheritance { * @return the computed final overrider map */ public static FinalOverriderMap computeFinalOverriderMap(ICPPClassType classType) { - return new FinalOverriderAnalysis().collectFinalOverriders(classType, false, - new HashSet<ICPPClassType>(), CPPSemantics.MAX_INHERITANCE_DEPTH); + return new FinalOverriderAnalysis().collectFinalOverriders(classType, false, new HashSet<ICPPClassType>(), + CPPSemantics.MAX_INHERITANCE_DEPTH); } // The last subobject number used for each type in the hierarchy. This is used to @@ -248,8 +248,8 @@ public class CPPInheritance { for (ICPPMethod method : ClassTypeHelper.getOwnMethods(classType)) { // Skip methods that don't actually belong to us, such as methods brought // into scope via a using-declaration. - if (!(method.getOwner() instanceof ICPPClassType && - ((ICPPClassType) method.getOwner()).isSameType(classType))) { + if (!(method.getOwner() instanceof ICPPClassType + && ((ICPPClassType) method.getOwner()).isSameType(classType))) { continue; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index f6a67777171..a2a87d03683 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -260,10 +260,10 @@ public class CPPSemantics { /** * The maximum depth to search ancestors before assuming infinite looping. */ - public static final int MAX_INHERITANCE_DEPTH= 40; + public static final int MAX_INHERITANCE_DEPTH = 40; public static final String EMPTY_NAME = ""; //$NON-NLS-1$ - public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '}; + public static final char[] OPERATOR_ = new char[] { 'o', 'p', 'e', 'r', 'a', 't', 'o', 'r', ' ' }; public static final IType VOID_TYPE = new CPPBasicType(Kind.eVoid, 0); public static final IType INT_TYPE = new CPPBasicType(Kind.eInt, 0); @@ -272,7 +272,7 @@ public class CPPSemantics { // Set to true for debugging. public static boolean traceBindingResolution = false; - public static int traceIndent= 0; + public static int traceIndent = 0; // special return value for costForFunctionCall private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0); @@ -292,7 +292,7 @@ public class CPPSemantics { // "a" => { null, "a", null } // ":: i" => { "::", "i", null } private static final Pattern QUALNAME_REGEX = Pattern.compile("^\\s*(::)?\\s*([^\\s:]+)\\s*(?:::(.*))?$"); //$NON-NLS-1$ - + // This flag controls whether name lookup is allowed to find bindings in headers // that are not reachable via includes from the file containing the name. // Generally this is not allowed, but certain consumers, such as IncludeOrganizer, @@ -303,22 +303,25 @@ public class CPPSemantics { return false; } }; - + private static final ThreadLocal<Deque<IASTNode>> fLookupPoints = new ThreadLocal<Deque<IASTNode>>() { @Override protected Deque<IASTNode> initialValue() { return new ArrayDeque<>(); } }; + public static void pushLookupPoint(IASTNode point) { fLookupPoints.get().push(point); } + public static void popLookupPoint() { fLookupPoints.get().pop(); } + /** * Get the current point of instantiation / point of lookup for name lookups. - * + * * NOTE: This is meant to be used primarily for "declaredBefore" purposes, that is, * for determining whether something was declared before or after the point * of lookup. It is NOT meant to be used as a general mechanism for accessing @@ -351,7 +354,7 @@ public class CPPSemantics { try { // 2: Lookup lookup(data, null); - + // Perform argument dependent lookup if (data.checkAssociatedScopes() && !data.hasTypeOrMemberFunctionOrVariableResult()) { doArgumentDependentLookup(data); @@ -361,7 +364,7 @@ public class CPPSemantics { } if (data.problem != null) return data.problem; - + // 3: Resolve ambiguities try { binding = resolveAmbiguities(data); @@ -378,7 +381,7 @@ public class CPPSemantics { for (int i = 0; i < traceIndent; i++) { System.out.print(" "); //$NON-NLS-1$ } - System.out.println("Resolved " + name + ':' + ((ASTNode) name).getOffset() + //$NON-NLS-1$ + System.out.println("Resolved " + name + ':' + ((ASTNode) name).getOffset() + //$NON-NLS-1$ " to " + DebugUtil.toStringWithClass(binding) + ':' + System.identityHashCode(binding)); //$NON-NLS-1$ } return binding; @@ -398,7 +401,8 @@ public class CPPSemantics { // of the function arguments are dependent, a matching function could be found via // argument-dependent lookup at the point of instantiation. if (binding == null || binding instanceof IProblemBinding) { - if (!data.qualified && data.isFunctionCall() && CPPTemplates.containsDependentType(data.getFunctionArgumentTypes())) { + if (!data.qualified && data.isFunctionCall() + && CPPTemplates.containsDependentType(data.getFunctionArgumentTypes())) { binding = CPPDeferredFunction.createForName(lookupName.getSimpleID()); } } @@ -429,8 +433,8 @@ public class CPPSemantics { // Explicit type conversion in functional notation. if (binding instanceof ICPPClassTemplate && lookupName instanceof ICPPASTTemplateId) { final IASTNode parent = lookupName.getParent(); - if (parent instanceof IASTIdExpression && - parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { + if (parent instanceof IASTIdExpression + && parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { return binding; } } @@ -440,57 +444,59 @@ public class CPPSemantics { * nor followed by <, it is equivalent to the name followed by the template arguments * enclosed in <>. */ - if (binding instanceof ICPPClassTemplate - && !(binding instanceof ICPPClassSpecialization) - && !(binding instanceof ICPPTemplateParameter) - && !(lookupName instanceof ICPPASTTemplateId)) { + if (binding instanceof ICPPClassTemplate && !(binding instanceof ICPPClassSpecialization) + && !(binding instanceof ICPPTemplateParameter) && !(lookupName instanceof ICPPASTTemplateId)) { ASTNodeProperty prop = lookupName.getPropertyInParent(); if (prop != ICPPASTTemplateId.TEMPLATE_NAME && !lookupName.isQualified()) { // You cannot use a class template name outside of the class template scope, // mark it as a problem. - IBinding user= CPPTemplates.isUsedInClassTemplateScope((ICPPClassTemplate) binding, lookupName); + IBinding user = CPPTemplates.isUsedInClassTemplateScope((ICPPClassTemplate) binding, lookupName); if (user instanceof ICPPClassTemplate) { - binding= ((ICPPClassTemplate) user).asDeferredInstance(); + binding = ((ICPPClassTemplate) user).asDeferredInstance(); } else if (user != null) { - binding= user; + binding = user; } else { - boolean ok= false; - IASTNode node= lookupName.getParent(); + boolean ok = false; + IASTNode node = lookupName.getParent(); while (node != null && !ok) { - if (node instanceof ICPPASTTemplateId || - node instanceof ICPPASTTemplatedTypeTemplateParameter) { - ok= true; // Can be argument or default-value for template template parameter + if (node instanceof ICPPASTTemplateId + || node instanceof ICPPASTTemplatedTypeTemplateParameter) { + ok = true; // Can be argument or default-value for template template parameter break; } else if (node instanceof IASTElaboratedTypeSpecifier) { - IASTNode parent= node.getParent(); + IASTNode parent = node.getParent(); if (parent instanceof IASTSimpleDeclaration) { IASTDeclSpecifier declspec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); if (declspec instanceof ICPPASTDeclSpecifier) { if (((ICPPASTDeclSpecifier) declspec).isFriend()) { - ok= true; // A friend class template declarations uses resolution. + ok = true; // A friend class template declarations uses resolution. break; } } } } - node= node.getParent(); + node = node.getParent(); } if (!ok) { - binding = new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_INVALID_TYPE, + data.getFoundBindings()); } } } } else if (binding instanceof ICPPDeferredClassInstance) { // Try to replace binding by the one pointing to the enclosing template declaration. - ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) binding; - IBinding usedHere= CPPTemplates.isUsedInClassTemplateScope(dcl.getClassTemplate(), lookupName); + ICPPDeferredClassInstance dcl = (ICPPDeferredClassInstance) binding; + IBinding usedHere = CPPTemplates.isUsedInClassTemplateScope(dcl.getClassTemplate(), lookupName); if (usedHere instanceof ICPPClassTemplatePartialSpecialization) { - if (CPPTemplates.areSameArguments(((ICPPClassTemplatePartialSpecialization) usedHere).getTemplateArguments(), dcl.getTemplateArguments())) - binding= ((ICPPClassTemplatePartialSpecialization) usedHere).asDeferredInstance(); + if (CPPTemplates.areSameArguments( + ((ICPPClassTemplatePartialSpecialization) usedHere).getTemplateArguments(), + dcl.getTemplateArguments())) + binding = ((ICPPClassTemplatePartialSpecialization) usedHere).asDeferredInstance(); } else if (usedHere instanceof ICPPClassTemplate) { - if (CPPTemplates.areSameArguments(CPPTemplates.templateParametersAsArguments((ICPPClassTemplate) usedHere), dcl.getTemplateArguments())) { - binding= ((ICPPClassTemplate) usedHere).asDeferredInstance(); + if (CPPTemplates.areSameArguments( + CPPTemplates.templateParametersAsArguments((ICPPClassTemplate) usedHere), + dcl.getTemplateArguments())) { + binding = ((ICPPClassTemplate) usedHere).asDeferredInstance(); } } } @@ -498,28 +504,28 @@ public class CPPSemantics { if (binding instanceof IType) { IType t = getNestedType((IType) binding, TDEF); if (t instanceof ICPPClassType && convertClassToConstructor(lookupName)) { - ICPPClassType cls= (ICPPClassType) t; + ICPPClassType cls = (ICPPClassType) t; if (cls instanceof IIndexBinding) { - cls= data.getTranslationUnit().mapToAST(cls); + cls = data.getTranslationUnit().mapToAST(cls); } try { if (lookupName instanceof ICPPASTTemplateId && cls instanceof ICPPClassTemplate) { if (data.getTranslationUnit() != null) { ICPPASTTemplateId id = (ICPPASTTemplateId) lookupName; ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id); - IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args); + IBinding inst = CPPTemplates.instantiate((ICPPClassTemplate) cls, args); if (inst instanceof ICPPClassType) { - cls= (ICPPClassType) inst; + cls = (ICPPClassType) inst; } } } if (cls instanceof ICPPUnknownBinding) { - binding= new CPPDeferredConstructor(cls); + binding = new CPPDeferredConstructor(cls); } else { // Do not interpret template arguments to a template class as being // explicit template arguments to its templated constructor. data.setTemplateArguments(null); - binding= resolveFunction(data, cls.getConstructors(), true, false); + binding = resolveFunction(data, cls.getConstructors(), true, false); } } catch (DOMException e) { return e.getProblem(); @@ -527,8 +533,8 @@ public class CPPSemantics { } } - IASTName name= lookupName; - IASTNode nameParent= name.getParent(); + IASTName name = lookupName; + IASTNode nameParent = name.getParent(); if (nameParent instanceof ICPPASTTemplateId) { if (binding instanceof ICPPTemplateInstance) { final ICPPTemplateInstance instance = (ICPPTemplateInstance) binding; @@ -536,14 +542,14 @@ public class CPPSemantics { name.setBinding(binding); ((ICPPASTTemplateId) nameParent).setBinding(instance); } - name= (ICPPASTTemplateId) nameParent; - nameParent= name.getParent(); + name = (ICPPASTTemplateId) nameParent; + nameParent = name.getParent(); } boolean isNestedNameSpecifier = false; if (nameParent instanceof ICPPASTQualifiedName) { if (name == ((ICPPASTQualifiedName) nameParent).getLastName()) { - name= (IASTName) nameParent; - nameParent= name.getParent(); + name = (IASTName) nameParent; + nameParent = name.getParent(); } else { isNestedNameSpecifier = true; } @@ -554,11 +560,11 @@ public class CPPSemantics { final ASTNodeProperty namePropertyInParent = name.getPropertyInParent(); if (binding == null && data.skippedScope != null) { if (isNestedNameSpecifier || namePropertyInParent == IASTNamedTypeSpecifier.NAME) { - binding= new CPPUnknownMemberClass(data.skippedScope, name.getSimpleID()); + binding = new CPPUnknownMemberClass(data.skippedScope, name.getSimpleID()); } else if (data.isFunctionCall()) { - binding= new CPPUnknownMethod(data.skippedScope, name.getSimpleID()); + binding = new CPPUnknownMethod(data.skippedScope, name.getSimpleID()); } else { - binding= new CPPUnknownField(data.skippedScope, name.getSimpleID()); + binding = new CPPUnknownField(data.skippedScope, name.getSimpleID()); } } @@ -566,16 +572,17 @@ public class CPPSemantics { if (namePropertyInParent == IASTNamedTypeSpecifier.NAME) { if (!(binding instanceof IType || binding instanceof ICPPConstructor)) { IASTNode parent = name.getParent().getParent(); - if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { + if (parent instanceof IASTTypeId + && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { if (!(binding instanceof IType)) { // A type id needs to hold a type. - binding = new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_INVALID_TYPE, + data.getFoundBindings()); } // Don't create a problem here. } else { - binding = new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_INVALID_TYPE, + data.getFoundBindings()); } } } else if (namePropertyInParent == IASTIdExpression.ID_NAME) { @@ -586,12 +593,12 @@ public class CPPSemantics { // Default for template template parameter is a type. } else if (pip == IASTFunctionCallExpression.FUNCTION_NAME) { // Explicit type conversion in functional notation. - } else if (pip == IASTUnaryExpression.OPERAND - && ((ICPPASTUnaryExpression) idExpr.getParent()).getOperator() == IASTUnaryExpression.op_sizeofParameterPack) { + } else if (pip == IASTUnaryExpression.OPERAND && ((ICPPASTUnaryExpression) idExpr.getParent()) + .getOperator() == IASTUnaryExpression.op_sizeofParameterPack) { // Argument of sizeof... can be a type } else { - binding= new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_INVALID_TYPE, + data.getFoundBindings()); } } } @@ -603,7 +610,7 @@ public class CPPSemantics { if (declaration != null) { // Functions if (binding instanceof IFunction) { - binding= checkDeclSpecifier(binding, lookupName, declaration); + binding = checkDeclSpecifier(binding, lookupName, declaration); if (!(binding instanceof IProblemBinding)) { if (declaration instanceof ICPPASTFunctionDefinition) { ASTInternal.addDefinition(binding, lookupName); @@ -621,8 +628,8 @@ public class CPPSemantics { // If the result is a virtual method called without explicit qualification, and we can determine a // unique final overrider for it in the hierarchy of the method call's implied object type, replace // the method with its final overrider. - if (!(lookupName.getParent() instanceof ICPPASTQualifiedName) && binding instanceof ICPPMethod && - ((ICPPMethod) binding).isVirtual()) { + if (!(lookupName.getParent() instanceof ICPPASTQualifiedName) && binding instanceof ICPPMethod + && ((ICPPMethod) binding).isVirtual()) { IType impliedObjectType = data.getImpliedObjectType(); if (impliedObjectType instanceof ICPPClassType) { ICPPMethod finalOverrider = CPPInheritance.getFinalOverrider((ICPPMethod) binding, @@ -639,8 +646,8 @@ public class CPPSemantics { binding = new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.getFoundBindings()); } else { - binding = new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, + data.getFoundBindings()); } } return binding; @@ -656,11 +663,11 @@ public class CPPSemantics { if (propertyInParent == ICPPASTTemplateId.TEMPLATE_NAME) return false; - IASTNode parent= name.getParent(); + IASTNode parent = name.getParent(); if (parent instanceof ICPPASTQualifiedName) { if (((ICPPASTQualifiedName) parent).getLastName() != name) return false; - parent= parent.getParent(); + parent = parent.getParent(); } if (parent instanceof ICPPASTConstructorChainInitializer) { return true; @@ -682,9 +689,8 @@ public class CPPSemantics { lookup(data, scope); } } - Object[] matchingFriendFns = CollectionUtils.filter( - friendFns, - new NameMatcherPredicate(data.getLookupKey())).toArray(); + Object[] matchingFriendFns = CollectionUtils.filter(friendFns, new NameMatcherPredicate(data.getLookupKey())) + .toArray(); mergeResults(data, matchingFriendFns, false); data.qualified = originalQualified; data.setArgumentDependent(false); @@ -706,14 +712,14 @@ public class CPPSemantics { static IBinding checkDeclSpecifier(IBinding binding, IASTName name, IASTNode decl) { // Check for empty declaration specifiers. if (!isCtorOrConversionOperator(binding)) { - IASTDeclSpecifier declspec= null; + IASTDeclSpecifier declspec = null; if (decl instanceof IASTSimpleDeclaration) { - declspec= ((IASTSimpleDeclaration) decl).getDeclSpecifier(); + declspec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); } else if (decl instanceof IASTFunctionDefinition) { - declspec= ((IASTFunctionDefinition) decl).getDeclSpecifier(); + declspec = ((IASTFunctionDefinition) decl).getDeclSpecifier(); } if (declspec != null && CPPVisitor.doesNotSpecifyType(declspec)) { - binding= new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_TYPE); + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_TYPE); } } return binding; @@ -724,7 +730,7 @@ public class CPPSemantics { return true; if (binding instanceof ICPPMethod) { - ICPPMethod m= (ICPPMethod) binding; + ICPPMethod m = (ICPPMethod) binding; if (m.isDestructor()) return true; return isConversionOperator(m); @@ -748,10 +754,10 @@ public class CPPSemantics { } if (parent instanceof IASTIdExpression) { - IASTNode grand= parent.getParent(); + IASTNode grand = parent.getParent(); while (grand instanceof IASTUnaryExpression && ((IASTUnaryExpression) grand).getOperator() == IASTUnaryExpression.op_bracketedPrimary) { - parent= grand; + parent = grand; grand = grand.getParent(); } if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { @@ -760,10 +766,10 @@ public class CPPSemantics { data.setFunctionArguments(false, args); } } else if (parent instanceof ICPPASTFieldReference) { - IASTNode grand= parent.getParent(); + IASTNode grand = parent.getParent(); while (grand instanceof IASTUnaryExpression && ((IASTUnaryExpression) grand).getOperator() == IASTUnaryExpression.op_bracketedPrimary) { - parent= grand; + parent = grand; grand = grand.getParent(); } if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { @@ -810,18 +816,18 @@ public class CPPSemantics { } } - IASTName lookupName= data.getLookupName(); + IASTName lookupName = data.getLookupName(); if (lookupName != null) { final char[] simpleID = lookupName.getSimpleID(); if (CharArrayUtils.equals(CPPVisitor.BEGIN, simpleID) || CharArrayUtils.equals(CPPVisitor.END, simpleID)) { - IASTNode parent = lookupName.getParent(); // id-expression + IASTNode parent = lookupName.getParent(); // id-expression if (parent != null) - parent= parent.getParent(); // function call + parent = parent.getParent(); // function call if (parent != null) - parent= parent.getParent(); // the loop + parent = parent.getParent(); // the loop if (parent instanceof ICPPASTRangeBasedForStatement) { IASTTranslationUnit tu = parent.getTranslationUnit(); - IBinding[] std= tu.getScope().find(CPPVisitor.STD, tu); + IBinding[] std = tu.getScope().find(CPPVisitor.STD, tu); for (IBinding binding : std) { if (binding instanceof ICPPNamespace) { namespaces.add(((ICPPNamespace) binding).getNamespaceScope()); @@ -834,9 +840,8 @@ public class CPPSemantics { } // 3.4.2-2 - private static void getAssociatedScopes(IType t, Set<ICPPNamespaceScope> namespaces, - Set<ICPPFunction> friendFns, ObjectSet<IType> handled, CPPASTTranslationUnit tu, - boolean lookInBaseClasses) throws DOMException { + private static void getAssociatedScopes(IType t, Set<ICPPNamespaceScope> namespaces, Set<ICPPFunction> friendFns, + ObjectSet<IType> handled, CPPASTTranslationUnit tu, boolean lookInBaseClasses) throws DOMException { t = getNestedType(t, TDEF | CVTYPE | PTR | ARRAY | REF); // No point getting namespaces associated with a dependent type - we don't know what they // are yet. @@ -852,7 +857,7 @@ public class CPPSemantics { // is the innermost enclosing namespace of its declaration. getAssociatedNamespaceScopes(getContainingNamespaceScope((IBinding) t, tu), namespaces); } else { - IBinding owner= ((IBinding) t).getOwner(); + IBinding owner = ((IBinding) t).getOwner(); if (owner instanceof ICPPClassType) { getAssociatedScopes((IType) owner, namespaces, friendFns, handled, tu, false /* do not look at base classes of the enclosing class */); @@ -862,7 +867,7 @@ public class CPPSemantics { } } if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { - ICPPClassType ct= (ICPPClassType) t; + ICPPClassType ct = (ICPPClassType) t; if (lookInBaseClasses) { ICPPBase[] bases = ct.getBases(); for (ICPPBase base : bases) { @@ -902,15 +907,15 @@ public class CPPSemantics { getAssociatedScopes(pmt.getMemberOfClass(), namespaces, friendFns, handled, tu, true); getAssociatedScopes(pmt.getType(), namespaces, friendFns, handled, tu, true); } else if (t instanceof FunctionSetType) { - FunctionSetType fst= (FunctionSetType) t; + FunctionSetType fst = (FunctionSetType) t; for (ICPPFunction fn : fst.getFunctionSet().getBindings()) { getAssociatedScopes(fn.getType(), namespaces, friendFns, handled, tu, true); } } } - private static ICPPNamespaceScope getContainingNamespaceScope(IBinding binding, - CPPASTTranslationUnit tu) throws DOMException { + private static ICPPNamespaceScope getContainingNamespaceScope(IBinding binding, CPPASTTranslationUnit tu) + throws DOMException { if (binding == null) return null; IScope scope = binding.getScope(); @@ -975,8 +980,10 @@ public class CPPSemantics { * @param scoped * @return */ - static CharArrayObjectMap<Object> mergePrefixResults(CharArrayObjectMap<Object> dest, Object source, boolean scoped) { - if (source == null) return dest; + static CharArrayObjectMap<Object> mergePrefixResults(CharArrayObjectMap<Object> dest, Object source, + boolean scoped) { + if (source == null) + return dest; CharArrayObjectMap<Object> resultMap = (dest != null) ? dest : new CharArrayObjectMap<>(2); CharArrayObjectMap<Object> map = null; @@ -986,25 +993,25 @@ public class CPPSemantics { @SuppressWarnings("unchecked") final CharArrayObjectMap<Object> sourceMap = (CharArrayObjectMap<Object>) source; map = sourceMap; - size= map.size(); + size = map.size(); } else { if (source instanceof Object[]) objs = ArrayUtil.trim(Object.class, (Object[]) source); else - objs = new Object[]{ source }; - size= objs.length; + objs = new Object[] { source }; + size = objs.length; } int resultInitialSize = resultMap.size(); - for (int i = 0; i < size; i ++) { + for (int i = 0; i < size; i++) { char[] key; Object so; if (map != null) { - key= map.keyAt(i); - so= map.get(key); + key = map.keyAt(i); + so = map.get(key); } else if (objs != null) { - so= objs[i]; - key= (so instanceof IBinding) ? ((IBinding) so).getNameCharArray() : ((IASTName) so).getSimpleID(); + so = objs[i]; + key = (so instanceof IBinding) ? ((IBinding) so).getNameCharArray() : ((IASTName) so).getSimpleID(); } else { return resultMap; } @@ -1045,25 +1052,25 @@ public class CPPSemantics { return; } - ICPPScope nextScope= null; - ICPPTemplateScope nextTmplScope= null; + ICPPScope nextScope = null; + ICPPTemplateScope nextTmplScope = null; if (start instanceof ICPPScope) { - nextScope= (ICPPScope) start; + nextScope = (ICPPScope) start; } else { - IASTName lookupName= data.getLookupName(); + IASTName lookupName = data.getLookupName(); if (lookupName == null) return; - nextScope= getLookupScope(lookupName); + nextScope = getLookupScope(lookupName); if (nextScope instanceof ICPPTemplateScope) { - nextTmplScope= (ICPPTemplateScope) nextScope; - nextScope= getParentScope(nextScope, data.getTranslationUnit()); + nextTmplScope = (ICPPTemplateScope) nextScope; + nextScope = getParentScope(nextScope, data.getTranslationUnit()); } else { - nextTmplScope= enclosingTemplateScope(lookupName); + nextTmplScope = enclosingTemplateScope(lookupName); } if (data.qualified && nextTmplScope != null) { - nextTmplScope= null; + nextTmplScope = null; if (dependsOnTemplateFieldReference(lookupName)) { data.setIgnorePointOfDeclaration(true); } @@ -1084,17 +1091,17 @@ public class CPPSemantics { while (nextScope != null || nextTmplScope != null) { // When the non-template scope is no longer contained within the first template scope, // we use the template scope for the next iteration. - boolean useTemplScope= false; + boolean useTemplScope = false; if (nextTmplScope != null) { - useTemplScope= true; + useTemplScope = true; if (nextScope instanceof IASTInternalScope) { - final IASTNode node= ((IASTInternalScope) nextScope).getPhysicalNode(); + final IASTNode node = ((IASTInternalScope) nextScope).getPhysicalNode(); if (node != null && nextTmplScope.getTemplateDeclaration().contains(node)) { - useTemplScope= false; + useTemplScope = false; } } } - ICPPScope scope= useTemplScope ? nextTmplScope : nextScope; + ICPPScope scope = useTemplScope ? nextTmplScope : nextScope; scope = (ICPPScope) SemanticUtil.mapToAST(scope, data.getTranslationUnit()); if (!data.usingDirectivesOnly && !(data.ignoreMembers && scope instanceof ICPPClassScope)) { @@ -1102,7 +1109,7 @@ public class CPPSemantics { // Nominate using-directives found in this block or namespace. if (scope instanceof ICPPNamespaceScope) { - final ICPPNamespaceScope namespaceScope= (ICPPNamespaceScope) scope; + final ICPPNamespaceScope namespaceScope = (ICPPNamespaceScope) scope; if (data.qualified && namespaceScope.getKind() != EScopeKind.eLocal) { lookupInlineNamespaces(data, namespaceScope); @@ -1115,7 +1122,8 @@ public class CPPSemantics { } // Lookup in nominated namespaces - if (!data.ignoreUsingDirectives && scope instanceof ICPPNamespaceScope && !(scope instanceof ICPPBlockScope)) { + if (!data.ignoreUsingDirectives && scope instanceof ICPPNamespaceScope + && !(scope instanceof ICPPBlockScope)) { if (!data.hasResults() || !data.qualified || data.contentAssist) { lookupInNominated(data, (ICPPNamespaceScope) scope); } @@ -1141,9 +1149,9 @@ public class CPPSemantics { // Compute next scopes if (useTemplScope && nextTmplScope != null) { - nextTmplScope= enclosingTemplateScope(nextTmplScope.getTemplateDeclaration()); + nextTmplScope = enclosingTemplateScope(nextTmplScope.getTemplateDeclaration()); } else { - nextScope= getParentScope(scope, data.getTranslationUnit()); + nextScope = getParentScope(scope, data.getTranslationUnit()); } } } @@ -1171,20 +1179,18 @@ public class CPPSemantics { return false; } - private static void lookupInlineNamespaces(LookupData data, ICPPNamespaceScope namespace) - throws DOMException { + private static void lookupInlineNamespaces(LookupData data, ICPPNamespaceScope namespace) throws DOMException { lookupInlineNamespaces(data, namespace, new HashSet<ICPPInternalNamespaceScope>()); } private static void lookupInlineNamespaces(LookupData data, ICPPNamespaceScope namespace, Set<ICPPInternalNamespaceScope> visited) throws DOMException { if (namespace instanceof ICPPInternalNamespaceScope) { - ICPPInternalNamespaceScope ns= (ICPPInternalNamespaceScope) namespace; + ICPPInternalNamespaceScope ns = (ICPPInternalNamespaceScope) namespace; visited.add(ns); for (ICPPInternalNamespaceScope inline : ns.getInlineNamespaces()) { if (visited.contains(inline)) { - CCorePlugin.log(IStatus.WARNING, - "Detected circular reference between inline namespaces"); //$NON-NLS-1$ + CCorePlugin.log(IStatus.WARNING, "Detected circular reference between inline namespaces"); //$NON-NLS-1$ continue; } mergeResults(data, getBindingsFromScope(inline, data), true); @@ -1194,19 +1200,18 @@ public class CPPSemantics { } } - private static void nominateNamespaces(LookupData data, final ICPPNamespaceScope blockScope) - throws DOMException { + private static void nominateNamespaces(LookupData data, final ICPPNamespaceScope blockScope) throws DOMException { final boolean isBlockScope = blockScope.getKind() == EScopeKind.eLocal; if (!isBlockScope) { - data.visited.put(blockScope); // Mark as searched. - CPPASTTranslationUnit tu= data.getTranslationUnit(); + data.visited.put(blockScope); // Mark as searched. + CPPASTTranslationUnit tu = data.getTranslationUnit(); if (tu != null) { tu.handleAdditionalDirectives(blockScope); } } - ICPPUsingDirective[] uds= blockScope.getUsingDirectives(); + ICPPUsingDirective[] uds = blockScope.getUsingDirectives(); if (uds != null && uds.length > 0) { - HashSet<ICPPNamespaceScope> handled= new HashSet<>(); + HashSet<ICPPNamespaceScope> handled = new HashSet<>(); for (final ICPPUsingDirective ud : uds) { if (data.isIgnorePointOfDeclaration() || declaredBefore(ud, data.getLookupPoint(), false)) { storeUsingDirective(data, blockScope, ud, handled); @@ -1216,33 +1221,33 @@ public class CPPSemantics { } private static boolean lookupDestructor(LookupData data) throws DOMException { - IASTName typeDtorName= data.getLookupName(); + IASTName typeDtorName = data.getLookupName(); if (typeDtorName == null) return false; - final char[] typeDtorChars= typeDtorName.getSimpleID(); + final char[] typeDtorChars = typeDtorName.getSimpleID(); if (typeDtorChars.length == 0 || typeDtorChars[0] != '~') return false; // Assume class C; typedef C T; // When looking up ~T the strategy is to lookup T::~C in two steps: // * First resolve 'T', then compute '~C' and resolve it. - IASTNode parent= typeDtorName.getParent(); + IASTNode parent = typeDtorName.getParent(); if (parent instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName dqname= (ICPPASTQualifiedName) parent; + ICPPASTQualifiedName dqname = (ICPPASTQualifiedName) parent; if (dqname.getLastName() != typeDtorName) return false; } - char[] tchars= new char[typeDtorChars.length - 1]; + char[] tchars = new char[typeDtorChars.length - 1]; System.arraycopy(typeDtorChars, 1, tchars, 0, tchars.length); ICPPTemplateArgument[] templateArgs = data.getTemplateArguments(); - LookupData ld2= new LookupData(tchars, templateArgs, data.getLookupPoint()); + LookupData ld2 = new LookupData(tchars, templateArgs, data.getLookupPoint()); ld2.setIgnorePointOfDeclaration(data.isIgnorePointOfDeclaration()); - ld2.contentAssist= data.contentAssist; - ld2.fNoNarrowing= data.fNoNarrowing; - ld2.fHeuristicBaseLookup= data.fHeuristicBaseLookup; - ld2.qualified= parent instanceof ICPPASTQualifiedName; - ld2.typesOnly= true; + ld2.contentAssist = data.contentAssist; + ld2.fNoNarrowing = data.fNoNarrowing; + ld2.fHeuristicBaseLookup = data.fHeuristicBaseLookup; + ld2.qualified = parent instanceof ICPPASTQualifiedName; + ld2.typesOnly = true; lookup(ld2, getLookupScope(typeDtorName)); IBinding[] typedefs = ld2.getFoundBindings(); ITypedef typedef = null; @@ -1252,8 +1257,7 @@ public class CPPSemantics { } IType type = (IType) candidate; if (templateArgs != null && type instanceof ICPPAliasTemplate) { - IBinding instantiated = CPPTemplates.instantiateAliasTemplate((ICPPAliasTemplate) type, - templateArgs); + IBinding instantiated = CPPTemplates.instantiateAliasTemplate((ICPPAliasTemplate) type, templateArgs); if (instantiated instanceof IType) { type = (IType) instantiated; } @@ -1267,21 +1271,20 @@ public class CPPSemantics { return false; } - IType t= SemanticUtil.getNestedType(typedef, TDEF); - if (t instanceof ICPPUnknownBinding || t instanceof ISemanticProblem || - !(t instanceof ICPPClassType)) { + IType t = SemanticUtil.getNestedType(typedef, TDEF); + if (t instanceof ICPPUnknownBinding || t instanceof ISemanticProblem || !(t instanceof ICPPClassType)) { return false; } - ICPPClassType classType= (ICPPClassType) t; + ICPPClassType classType = (ICPPClassType) t; final IScope scope = ((ICPPClassType) t).getCompositeScope(); if (scope == null) { return false; } - char[] classChars= classType.getNameCharArray(); - char[] classDtorChars= new char[classChars.length + 1]; - classDtorChars[0]= '~'; + char[] classChars = classType.getNameCharArray(); + char[] classDtorChars = new char[classChars.length + 1]; + classDtorChars[0] = '~'; System.arraycopy(classChars, 0, classDtorChars, 1, classChars.length); data.setLookupKey(classDtorChars); lookup(data, scope); @@ -1295,35 +1298,35 @@ public class CPPSemantics { if (astName.getPropertyInParent() != IASTFieldReference.FIELD_NAME) return false; - final boolean[] result= {false}; + final boolean[] result = { false }; final IASTExpression fieldOwner = ((IASTFieldReference) astName.getParent()).getFieldOwner(); fieldOwner.accept(new ASTVisitor() { { - shouldVisitNames= true; - shouldVisitExpressions= true; + shouldVisitNames = true; + shouldVisitExpressions = true; } @Override public int visit(IASTName name) { - IBinding b= name.resolvePreBinding(); + IBinding b = name.resolvePreBinding(); if (b instanceof ICPPUnknownBinding || b instanceof ICPPTemplateDefinition) { - result[0]= true; + result[0] = true; return PROCESS_ABORT; } if (b instanceof ICPPMember) { - ICPPMember mem= (ICPPMember) b; + ICPPMember mem = (ICPPMember) b; if (!mem.isStatic()) { - ICPPClassType owner= mem.getClassOwner(); + ICPPClassType owner = mem.getClassOwner(); if (owner instanceof ICPPUnknownBinding || owner instanceof ICPPTemplateDefinition) { - result[0]= true; + result[0] = true; return PROCESS_ABORT; } } } if (b instanceof IVariable) { - IType t= SemanticUtil.getUltimateType(((IVariable) b).getType(), true); + IType t = SemanticUtil.getUltimateType(((IVariable) b).getType(), true); if (t instanceof ICPPUnknownBinding || t instanceof ICPPTemplateDefinition) { - result[0]= true; + result[0] = true; return PROCESS_ABORT; } } @@ -1337,9 +1340,10 @@ public class CPPSemantics { if (expression instanceof ICPPASTLiteralExpression) { final ICPPASTLiteralExpression litExpr = (ICPPASTLiteralExpression) expression; if (litExpr.getKind() == IASTLiteralExpression.lk_this) { - final IType thisType = SemanticUtil.getNestedType(litExpr.getEvaluation().getType(), TDEF | ALLCVQ | PTR | ARRAY | MPTR | REF); + final IType thisType = SemanticUtil.getNestedType(litExpr.getEvaluation().getType(), + TDEF | ALLCVQ | PTR | ARRAY | MPTR | REF); if (thisType instanceof ICPPUnknownBinding || thisType instanceof ICPPTemplateDefinition) { - result[0]= true; + result[0] = true; return PROCESS_ABORT; } } @@ -1383,7 +1387,7 @@ public class CPPSemantics { } static IBinding[] getBindingsFromScope(ICPPScope scope, LookupData data) throws DOMException { - IBinding[] bindings= scope.getBindings(data); + IBinding[] bindings = scope.getBindings(data); if (scope instanceof ICPPASTInternalScope && scope instanceof ICPPClassScope) { final IASTName lookupName = data.getLookupName(); @@ -1395,10 +1399,10 @@ public class CPPSemantics { IIndex index = tu.getIndex(); IASTNode node = ((IASTInternalScope) scope).getPhysicalNode(); if (index != null && node != null && node.contains(lookupName)) { - IBinding indexBinding= index.adaptBinding(((ICPPClassScope) scope).getClassType()); + IBinding indexBinding = index.adaptBinding(((ICPPClassScope) scope).getClassType()); if (indexBinding instanceof ICPPClassType) { - IScope scopeInIndex= ((ICPPClassType) indexBinding).getCompositeScope(); - bindings= ArrayUtil.addAll(bindings, scopeInIndex.getBindings(data)); + IScope scopeInIndex = ((ICPPClassType) indexBinding).getCompositeScope(); + bindings = ArrayUtil.addAll(bindings, scopeInIndex.getBindings(data)); } } } @@ -1425,8 +1429,7 @@ public class CPPSemantics { } } - private static IBinding[] expandUsingDeclarationsAndRemoveObjects(final IBinding[] bindings, - LookupData data) { + private static IBinding[] expandUsingDeclarationsAndRemoveObjects(final IBinding[] bindings, LookupData data) { if (bindings == null || bindings.length == 0) return IBinding.EMPTY_BINDING_ARRAY; @@ -1435,7 +1438,7 @@ public class CPPSemantics { break; if (b instanceof ICPPUsingDeclaration || (data.typesOnly && isObject(b))) { - List<IBinding> result= new ArrayList<>(bindings.length); + List<IBinding> result = new ArrayList<>(bindings.length); expandUsingDeclarations(bindings, data, result); return result.toArray(new IBinding[result.size()]); } @@ -1465,8 +1468,7 @@ public class CPPSemantics { // name lookup wants to ultimately resolve to a constructor, it can do so // after the name lookup phase, e.g. in the convertClassToConstructor() // call in postResolution(). - if (d != null && !(data.typesOnly && isObject(d)) && - !(d instanceof ICPPConstructor)) { + if (d != null && !(data.typesOnly && isObject(d)) && !(d instanceof ICPPConstructor)) { result.add(d); } } @@ -1479,14 +1481,14 @@ public class CPPSemantics { } private static ICPPTemplateScope enclosingTemplateScope(IASTNode node) { - IASTNode parent= node.getParent(); + IASTNode parent = node.getParent(); if (parent instanceof IASTName) { if (parent instanceof ICPPASTTemplateId) { - node= parent; - parent= node.getParent(); + node = parent; + parent = node.getParent(); } if (parent instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent; + ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; if (qname.isFullyQualified() || qname.getQualifier()[0] != node) return null; } @@ -1494,13 +1496,13 @@ public class CPPSemantics { while (!(parent instanceof ICPPASTTemplateDeclaration)) { if (parent == null) return null; - parent= parent.getParent(); + parent = parent.getParent(); } return ((ICPPASTTemplateDeclaration) parent).getScope(); } static ICPPScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException { - IScope parentScope= scope.getParent(); + IScope parentScope = scope.getParent(); // The index cannot return the translation unit as parent scope. if (parentScope == null && scope instanceof ICPPClassSpecializationScope && unit instanceof CPPASTTranslationUnit) { @@ -1517,25 +1519,25 @@ public class CPPSemantics { * This is important because the members nominated by a transitive directive can appear before * those of the original directive. */ - private static void storeUsingDirective(LookupData data, ICPPNamespaceScope container, - ICPPUsingDirective directive, Set<ICPPNamespaceScope> handled) throws DOMException { - ICPPNamespaceScope nominated= directive.getNominatedScope(); - CPPASTTranslationUnit tu= data.getTranslationUnit(); + private static void storeUsingDirective(LookupData data, ICPPNamespaceScope container, ICPPUsingDirective directive, + Set<ICPPNamespaceScope> handled) throws DOMException { + ICPPNamespaceScope nominated = directive.getNominatedScope(); + CPPASTTranslationUnit tu = data.getTranslationUnit(); if (tu != null) { - nominated= (ICPPNamespaceScope) tu.mapToASTScope(nominated); + nominated = (ICPPNamespaceScope) tu.mapToASTScope(nominated); } if (nominated == null || data.visited.containsKey(nominated) || (handled != null && !handled.add(nominated))) { return; } // 7.3.4.1 names appear at end of common enclosing scope of container and nominated scope. - final IScope appearsIn= getCommonEnclosingScope(nominated, container, tu); + final IScope appearsIn = getCommonEnclosingScope(nominated, container, tu); if (appearsIn instanceof ICPPNamespaceScope) { // store the directive with the scope where it has to be considered - List<ICPPNamespaceScope> listOfNominated= data.usingDirectives.get(appearsIn); + List<ICPPNamespaceScope> listOfNominated = data.usingDirectives.get(appearsIn); if (listOfNominated == null) { - listOfNominated= new ArrayList<>(1); + listOfNominated = new ArrayList<>(1); if (data.usingDirectives.isEmpty()) { - data.usingDirectives= new HashMap<ICPPNamespaceScope, List<ICPPNamespaceScope>>(); + data.usingDirectives = new HashMap<ICPPNamespaceScope, List<ICPPNamespaceScope>>(); } data.usingDirectives.put((ICPPNamespaceScope) appearsIn, listOfNominated); } @@ -1549,7 +1551,7 @@ public class CPPSemantics { if (tu != null) { tu.handleAdditionalDirectives(nominated); } - ICPPUsingDirective[] transitive= nominated.getUsingDirectives(); + ICPPUsingDirective[] transitive = nominated.getUsingDirectives(); for (ICPPUsingDirective element : transitive) { storeUsingDirective(data, container, element, handled); } @@ -1562,12 +1564,12 @@ public class CPPSemantics { private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, ICPPASTTranslationUnit tu) throws DOMException { ObjectSet<IScope> set = new ObjectSet<>(2); - IScope parent= s1; + IScope parent = s1; while (parent != null) { set.put(parent); - parent= getParentScope(parent, tu); + parent = getParentScope(parent, tu); } - parent= s2; + parent = s2; while (parent != null && !set.containsKey(parent)) { parent = getParentScope(parent, tu); } @@ -1576,7 +1578,7 @@ public class CPPSemantics { public static void populateCache(ICPPASTInternalScope scope) { IASTNode[] nodes = null; - IASTNode parent= ASTInternal.getPhysicalNodeOfScope(scope); + IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope); IASTName[] namespaceDefs = null; int namespaceIdx = -1; @@ -1584,7 +1586,8 @@ public class CPPSemantics { if (parent instanceof IASTCompoundStatement) { IASTNode p = parent.getParent(); if (p instanceof IASTFunctionDefinition) { - ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition) p).getDeclarator(); + ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition) p) + .getDeclarator(); nodes = dtor.getParameters(); } else if (p instanceof ICPPASTLambdaExpression) { ICPPASTLambdaExpression lambdaExpression = (ICPPASTLambdaExpression) p; @@ -1619,7 +1622,7 @@ public class CPPSemantics { namespaceDefs = namespace.getNamespaceDefinitions(); nodes = ((ICPPASTNamespaceDefinition) namespaceDefs[++namespaceIdx].getParent()).getDeclarations(); while (nodes.length == 0 && ++namespaceIdx < namespaceDefs.length) { - nodes= ((ICPPASTNamespaceDefinition) namespaceDefs[namespaceIdx].getParent()).getDeclarations(); + nodes = ((ICPPASTNamespaceDefinition) namespaceDefs[namespaceIdx].getParent()).getDeclarations(); } } else if (parent instanceof ICPPASTFunctionDeclarator) { ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent; @@ -1630,36 +1633,36 @@ public class CPPSemantics { } else if (parent instanceof ICPPASTForStatement) { ICPPASTForStatement forStatement = (ICPPASTForStatement) parent; final IASTDeclaration conditionDeclaration = forStatement.getConditionDeclaration(); - IASTStatement initDeclaration= forStatement.getInitializerStatement(); + IASTStatement initDeclaration = forStatement.getInitializerStatement(); if (conditionDeclaration != null) { - nodes= new IASTNode[] {initDeclaration, conditionDeclaration}; + nodes = new IASTNode[] { initDeclaration, conditionDeclaration }; } else { - nodes= new IASTNode[] {initDeclaration}; + nodes = new IASTNode[] { initDeclaration }; } } else if (parent instanceof ICPPASTSwitchStatement) { ICPPASTSwitchStatement ifStatement = (ICPPASTSwitchStatement) parent; final IASTStatement initStatement = ifStatement.getInitializerStatement(); final IASTDeclaration controllerDeclaration = ifStatement.getControllerDeclaration(); if (initStatement != null) { - nodes = new IASTNode[] {initStatement, controllerDeclaration}; + nodes = new IASTNode[] { initStatement, controllerDeclaration }; } else { - nodes = new IASTNode[] {controllerDeclaration}; + nodes = new IASTNode[] { controllerDeclaration }; } } else if (parent instanceof ICPPASTIfStatement) { ICPPASTIfStatement ifStatement = (ICPPASTIfStatement) parent; final IASTStatement initStatement = ifStatement.getInitializerStatement(); final IASTDeclaration conditionDeclaration = ifStatement.getConditionDeclaration(); if (initStatement != null) { - nodes = new IASTNode[] {initStatement, conditionDeclaration}; + nodes = new IASTNode[] { initStatement, conditionDeclaration }; } else { - nodes = new IASTNode[] {conditionDeclaration}; + nodes = new IASTNode[] { conditionDeclaration }; } } else if (parent instanceof ICPPASTWhileStatement) { nodes = new IASTNode[] { ((ICPPASTWhileStatement) parent).getConditionDeclaration() }; } else if (parent instanceof ICPPASTRangeBasedForStatement) { ICPPASTRangeBasedForStatement forStatement = (ICPPASTRangeBasedForStatement) parent; final IASTDeclaration decl = forStatement.getDeclaration(); - nodes= new IASTNode[] {decl}; + nodes = new IASTNode[] { decl }; } else if (parent instanceof ICPPASTEnumerationSpecifier) { // The enumeration scope contains the enumeration items for (IASTEnumerator enumerator : ((ICPPASTEnumerationSpecifier) parent).getEnumerators()) { @@ -1668,8 +1671,9 @@ public class CPPSemantics { return; } else if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) { // The template-template parameter scope contains the parameters - for (ICPPASTTemplateParameter par : ((ICPPASTTemplatedTypeTemplateParameter) parent).getTemplateParameters()) { - IASTName name= CPPTemplates.getTemplateParameterName(par); + for (ICPPASTTemplateParameter par : ((ICPPASTTemplatedTypeTemplateParameter) parent) + .getTemplateParameters()) { + IASTName name = CPPTemplates.getTemplateParameterName(par); if (name != null) { ASTInternal.addName(scope, name); } @@ -1695,7 +1699,7 @@ public class CPPSemantics { } } while (item instanceof IASTLabelStatement) { - item= ((IASTLabelStatement) item).getNestedStatement(); + item = ((IASTLabelStatement) item).getNestedStatement(); } if (item instanceof IASTDeclarationStatement) item = ((IASTDeclarationStatement) item).getDeclaration(); @@ -1710,7 +1714,7 @@ public class CPPSemantics { final boolean isUnnamed = nsDef.getName().getLookupKey().length == 0; boolean isInline = nsDef.isInline(); // An inline namespace can be re-opened without repeating the inline keyword, - // so we need to consult the binding to check inlineness. + // so we need to consult the binding to check inlineness. if (!isUnnamed && !isInline) { IBinding nsBinding = nsDef.getName().resolveBinding(); if (nsBinding instanceof ICPPNamespace) { @@ -1741,7 +1745,8 @@ public class CPPSemantics { if (namespaceDefs != null) { // Check all definitions of this namespace. while (++namespaceIdx < namespaceDefs.length) { - nodes = ((ICPPASTNamespaceDefinition) namespaceDefs[namespaceIdx].getParent()).getDeclarations(); + nodes = ((ICPPASTNamespaceDefinition) namespaceDefs[namespaceIdx].getParent()) + .getDeclarations(); if (nodes.length > 0) { idx = 0; item = nodes[0]; @@ -1796,12 +1801,12 @@ public class CPPSemantics { } else if (node instanceof IASTParameterDeclaration) { IASTParameterDeclaration parameterDeclaration = (IASTParameterDeclaration) node; IASTDeclarator dtor = parameterDeclaration.getDeclarator(); - IASTDeclarator innermost= dtor; + IASTDeclarator innermost = dtor; while (dtor != null) { if (dtor instanceof IASTAmbiguousDeclarator) return; - innermost= dtor; - dtor= dtor.getNestedDeclarator(); + innermost = dtor; + dtor = dtor.getNestedDeclarator(); } if (innermost != null) { // Could be null when content assist in the declSpec IASTName declName = innermost.getName(); @@ -1823,14 +1828,14 @@ public class CPPSemantics { IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); if (!declSpec.isFriend()) { for (IASTDeclarator declarator : declarators) { - IASTDeclarator innermost= null; + IASTDeclarator innermost = null; while (declarator != null) { if (declarator instanceof IASTAmbiguousDeclarator) { - innermost= null; + innermost = null; break; } - innermost= declarator; - declarator= declarator.getNestedDeclarator(); + innermost = declarator; + declarator = declarator.getNestedDeclarator(); } if (innermost != null) { IASTName declaratorName = innermost.getName(); @@ -1913,7 +1918,7 @@ public class CPPSemantics { handleEnumeration((ICPPASTEnumerationSpecifier) declSpec, scope); } } else if (declaration instanceof IASTFunctionDefinition) { - IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; + IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; final IASTDeclSpecifier declSpec = functionDef.getDeclSpecifier(); IASTFunctionDeclarator declarator = functionDef.getDeclarator(); @@ -1939,8 +1944,7 @@ public class CPPSemantics { } } - private static void handleEnumeration(ICPPASTEnumerationSpecifier enumSpec, - IScope enclosingScope) { + private static void handleEnumeration(ICPPASTEnumerationSpecifier enumSpec, IScope enclosingScope) { // Add unscoped enumerators to the enclosing scope if (!enumSpec.isScoped()) { for (IASTEnumerator enumerator : enumSpec.getEnumerators()) { @@ -1956,7 +1960,7 @@ public class CPPSemantics { * directive returns empty. */ private static void lookupInNominated(LookupData data, ICPPNamespaceScope scope) throws DOMException { - List<ICPPNamespaceScope> allNominated= data.usingDirectives.remove(scope); + List<ICPPNamespaceScope> allNominated = data.usingDirectives.remove(scope); while (allNominated != null) { for (ICPPNamespaceScope nominated : allNominated) { if (data.visited.containsKey(nominated)) { @@ -1965,7 +1969,7 @@ public class CPPSemantics { data.visited.put(nominated); boolean found = false; - IBinding[] bindings= getBindingsFromScope(nominated, data); + IBinding[] bindings = getBindingsFromScope(nominated, data); if (bindings != null && bindings.length > 0) { mergeResults(data, bindings, true); found = true; @@ -1979,14 +1983,14 @@ public class CPPSemantics { if (tu != null) { tu.handleAdditionalDirectives(nominated); } - ICPPUsingDirective[] usings= nominated.getUsingDirectives(); + ICPPUsingDirective[] usings = nominated.getUsingDirectives(); for (ICPPUsingDirective using : usings) { storeUsingDirective(data, scope, using, null); } } } // Retry with transitive directives that may have been nominated in a qualified lookup - allNominated= data.usingDirectives.remove(scope); + allNominated = data.usingDirectives.remove(scope); } } @@ -1995,18 +1999,17 @@ public class CPPSemantics { if (bindings == null || bindings.length == 0) { return null; } else if (bindings.length == 1) { - IBinding candidate= null; + IBinding candidate = null; if (bindings[0] instanceof IBinding) { - candidate= (IBinding) bindings[0]; + candidate = (IBinding) bindings[0]; } else if (bindings[0] instanceof IASTName) { - candidate= ((IASTName) bindings[0]).getPreBinding(); + candidate = ((IASTName) bindings[0]).getPreBinding(); } else { return null; } if (candidate != null) { - if (!(candidate instanceof IType) && !(candidate instanceof ICPPNamespace) && - !(candidate instanceof ICPPUsingDeclaration) && - LookupData.typesOnly(name)) { + if (!(candidate instanceof IType) && !(candidate instanceof ICPPNamespace) + && !(candidate instanceof ICPPUsingDeclaration) && LookupData.typesOnly(name)) { return null; } @@ -2016,7 +2019,7 @@ public class CPPSemantics { // Specialization is selected during instantiation if (candidate instanceof ICPPTemplateInstance) - candidate= ((ICPPTemplateInstance) candidate).getSpecializedBinding(); + candidate = ((ICPPTemplateInstance) candidate).getSpecializedBinding(); if (!(candidate instanceof ICPPFunctionTemplate)) return candidate; @@ -2030,16 +2033,16 @@ public class CPPSemantics { } catch (DOMException e) { return e.getProblem(); } -// -// IBinding[] result = null; -// for (Object binding : bindings) { -// if (binding instanceof IASTName) { -// result = ArrayUtil.append(IBinding.class, result, ((IASTName) binding).resolveBinding()); -// } else if (binding instanceof IBinding) { -// result = ArrayUtil.append(IBinding.class, result, (IBinding) binding); -// } -// } -// return new CPPCompositeBinding(result); + // + // IBinding[] result = null; + // for (Object binding : bindings) { + // if (binding instanceof IASTName) { + // result = ArrayUtil.append(IBinding.class, result, ((IASTName) binding).resolveBinding()); + // } else if (binding instanceof IBinding) { + // result = ArrayUtil.append(IBinding.class, result, (IBinding) binding); + // } + // } + // return new CPPCompositeBinding(result); } public static boolean declaredBefore(Object obj, IASTNode node, boolean indexBased) { @@ -2052,13 +2055,13 @@ public class CPPSemantics { // The pointOfRef and pointOfDecl variables contain node offsets scaled by a factor of two. // This is done to distinguish between left and right points for the same offset. - final int pointOfRef= ((ASTNode) node).getOffset() * 2; + final int pointOfRef = ((ASTNode) node).getOffset() * 2; ASTNode nd = null; while (obj instanceof ICPPSpecialization) { obj = ((ICPPSpecialization) obj).getSpecializedBinding(); } - int pointOfDecl= -1; + int pointOfDecl = -1; if (obj instanceof ICPPInternalBinding) { ICPPInternalBinding cpp = (ICPPInternalBinding) obj; IASTNode[] n = cpp.getDeclarations(); @@ -2073,7 +2076,7 @@ public class CPPSemantics { return true; } else { if (indexBased && obj instanceof IASTName) { - IBinding b= ((IASTName) obj).getPreBinding(); + IBinding b = ((IASTName) obj).getPreBinding(); if (b instanceof ICPPInternalBinding) { if (acceptDeclaredAfter((ICPPInternalBinding) b)) return true; @@ -2082,7 +2085,7 @@ public class CPPSemantics { if (obj instanceof ASTNode) { nd = (ASTNode) obj; } else if (obj instanceof ICPPUsingDirective) { - pointOfDecl= ((ICPPUsingDirective) obj).getPointOfDeclaration() * 2; + pointOfDecl = ((ICPPUsingDirective) obj).getPointOfDeclaration() * 2; } } @@ -2101,7 +2104,7 @@ public class CPPSemantics { } return pointOfDecl < pointOfRef; } - + /** * Returns the point of declaration for the given AST node. The point of declaration is a node offset * scaled by a factor of two. This is done to distinguish between left and right points for the offset. @@ -2111,7 +2114,7 @@ public class CPPSemantics { if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) { // Point of declaration for a name is immediately after its complete declarator // and before its initializer. - IASTDeclarator dtor = (IASTDeclarator)((nd instanceof IASTDeclarator) ? nd : nd.getParent()); + IASTDeclarator dtor = (IASTDeclarator) ((nd instanceof IASTDeclarator) ? nd : nd.getParent()); while (dtor.getParent() instanceof IASTDeclarator) { dtor = (IASTDeclarator) dtor.getParent(); } @@ -2165,12 +2168,12 @@ public class CPPSemantics { private static boolean acceptDeclaredAfter(ICPPInternalBinding cpp) { try { if (cpp instanceof ICPPNamespace || cpp instanceof ICPPFunction || cpp instanceof ICPPVariable) { - IScope scope= cpp.getScope(); + IScope scope = cpp.getScope(); if (!(scope instanceof ICPPBlockScope) && scope instanceof ICPPNamespaceScope) { return true; } } else if (cpp instanceof ICompositeType || cpp instanceof IEnumeration) { - IScope scope= cpp.getScope(); + IScope scope = cpp.getScope(); if (!(scope instanceof ICPPBlockScope) && scope instanceof ICPPNamespaceScope) { // If this is not the definition, it may be found in a header. (bug 229571) if (cpp.getDefinition() == null) { @@ -2189,9 +2192,9 @@ public class CPPSemantics { final IASTName lookupName = data.getLookupName(); IASTNode lookupPoint = data.getLookupPoint(); - final boolean indexBased= data.getIndex() != null; - final boolean checkWholeClass= lookupName == null || LookupData.checkWholeClassScope(lookupName); - ObjectSet<ICPPFunction> fns= ObjectSet.emptySet(); + final boolean indexBased = data.getIndex() != null; + final boolean checkWholeClass = lookupName == null || LookupData.checkWholeClassScope(lookupName); + ObjectSet<ICPPFunction> fns = ObjectSet.emptySet(); IBinding type = null; IBinding obj = null; boolean ambiguous = false; @@ -2202,21 +2205,21 @@ public class CPPSemantics { for (int i = 0; i < items.length && items[i] != null; i++) { Object o = items[i]; boolean declaredBefore = data.isIgnorePointOfDeclaration() || declaredBefore(o, lookupPoint, indexBased); - boolean checkResolvedNamesOnly= false; + boolean checkResolvedNamesOnly = false; if (!checkWholeClass && !declaredBefore) { if (lookupName != null && lookupName.getRoleOfName(false) != IASTNameOwner.r_reference) { - checkResolvedNamesOnly= true; - declaredBefore= true; + checkResolvedNamesOnly = true; + declaredBefore = true; } else { continue; } } if (o instanceof IASTName) { - IASTName on= (IASTName) o; + IASTName on = (IASTName) o; if (checkResolvedNamesOnly) { temp = on.getPreBinding(); } else { - temp= on.resolvePreBinding(); + temp = on.resolvePreBinding(); } if (temp == null) continue; @@ -2237,8 +2240,8 @@ public class CPPSemantics { continue; } - if (!declaredBefore && !(temp instanceof ICPPMember) && !(temp instanceof IType) && - !(temp instanceof IEnumerator)) { + if (!declaredBefore && !(temp instanceof ICPPMember) && !(temp instanceof IType) + && !(temp instanceof IEnumerator)) { continue; } @@ -2246,7 +2249,7 @@ public class CPPSemantics { if (temp instanceof ICPPPartialSpecialization) continue; if (temp instanceof ICPPTemplateInstance && lookupName instanceof ICPPASTTemplateId) { - temp= ((ICPPTemplateInstance) temp).getSpecializedBinding(); + temp = ((ICPPTemplateInstance) temp).getSpecializedBinding(); if (!(temp instanceof IType)) continue; } @@ -2263,7 +2266,7 @@ public class CPPSemantics { continue; } else if (temp instanceof ICPPFunction) { if (temp instanceof ICPPTemplateInstance) { - temp= ((ICPPTemplateInstance) temp).getSpecializedBinding(); + temp = ((ICPPTemplateInstance) temp).getSpecializedBinding(); if (!(temp instanceof IFunction)) continue; } @@ -2277,13 +2280,13 @@ public class CPPSemantics { } else if (!type.equals(temp)) { int c = compareByRelevance(tu, type, temp); if (c < 0) { - type= temp; + type = temp; ambiguous = false; } else if (c == 0) { if (((IType) type).isSameType((IType) temp)) { if (type instanceof ITypedef && !(temp instanceof ITypedef)) { // Between same types prefer non-typedef. - type= temp; + type = temp; ambiguous = false; } } else { @@ -2296,13 +2299,13 @@ public class CPPSemantics { obj = temp; ambiguous = false; } else if (!obj.equals(temp)) { - if (obj instanceof ICPPNamespace && temp instanceof ICPPNamespace && - SemanticUtil.isSameNamespace((ICPPNamespace) obj, (ICPPNamespace) temp)) { + if (obj instanceof ICPPNamespace && temp instanceof ICPPNamespace + && SemanticUtil.isSameNamespace((ICPPNamespace) obj, (ICPPNamespace) temp)) { continue; } int c = compareByRelevance(tu, obj, temp); if (c < 0) { - obj= temp; + obj = temp; ambiguous = false; } else if (c == 0) { ambiguous = true; @@ -2311,20 +2314,20 @@ public class CPPSemantics { } } if (ambiguous) { - return new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + data.getFoundBindings()); } if (data.forUsingDeclaration) { - int cmp= -1; + int cmp = -1; if (obj != null) { - cmp= 1; + cmp = 1; if (fns.size() > 0) { - IFunction[] fnArray= fns.keyArray(IFunction.class); - cmp= compareByRelevance(data, obj, fnArray); + IFunction[] fnArray = fns.keyArray(IFunction.class); + cmp = compareByRelevance(data, obj, fnArray); if (cmp == 0) { - return new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + data.getFoundBindings()); } } } @@ -2345,10 +2348,10 @@ public class CPPSemantics { if (obj != null && type != null) { if (obj instanceof ICPPNamespace) { if (compareByRelevance(tu, type, obj) >= 0) { - obj= null; + obj = null; } } else if (!data.typesOnly && overrulesByRelevance(data, type, obj)) { - obj= null; + obj = null; } } @@ -2366,10 +2369,10 @@ public class CPPSemantics { } if (obj != null) { - int cmp= compareByRelevance(data, obj, fnArray); + int cmp = compareByRelevance(data, obj, fnArray); if (cmp == 0) { - return new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + data.getFoundBindings()); } if (cmp > 0) { return obj; @@ -2397,15 +2400,15 @@ public class CPPSemantics { * <code>b2</code>. */ static int compareByRelevance(IASTTranslationUnit tu, IBinding b1, IBinding b2) { - boolean b1FromIndex= isFromIndex(b1); - boolean b2FromIndex= isFromIndex(b2); + boolean b1FromIndex = isFromIndex(b1); + boolean b2FromIndex = isFromIndex(b2); if (b1FromIndex != b2FromIndex) { return !b1FromIndex ? 1 : -1; } else if (b1FromIndex) { // Both are from index. if (tu != null) { - boolean b1Reachable= isReachableFromAst(tu, b1); - boolean b2Reachable= isReachableFromAst(tu, b2); + boolean b1Reachable = isReachableFromAst(tu, b1); + boolean b2Reachable = isReachableFromAst(tu, b2); if (b1Reachable != b2Reachable) { return b1Reachable ? 1 : -1; } @@ -2441,7 +2444,7 @@ public class CPPSemantics { for (int i = 0; i < fns.length; i++) { if (!isFromIndex(fns[i])) { - return false; // function from ast + return false; // function from ast } } @@ -2451,13 +2454,12 @@ public class CPPSemantics { for (IFunction fn : fns) { if (isReachableFromAst(tu, fn)) { - return false; // function from ast + return false; // function from ast } } return true; } - /** * Compares two bindings for relevance in the context of an AST. AST bindings are * considered more relevant than index ones since the index may be out of date, @@ -2471,16 +2473,16 @@ public class CPPSemantics { * <code>b2</code>. */ static int compareByRelevance(LookupData data, IName b1, IName b2) { - boolean b1FromIndex= (b1 instanceof IIndexName); - boolean b2FromIndex= (b2 instanceof IIndexName); + boolean b1FromIndex = (b1 instanceof IIndexName); + boolean b2FromIndex = (b2 instanceof IIndexName); if (b1FromIndex != b2FromIndex) { return !b1FromIndex ? 1 : -1; } else if (b1FromIndex) { // Both are from index. final CPPASTTranslationUnit tu = data.getTranslationUnit(); if (tu != null) { - boolean b1Reachable= isReachableFromAst(tu, b1); - boolean b2Reachable= isReachableFromAst(tu, b2); + boolean b1Reachable = isReachableFromAst(tu, b1); + boolean b2Reachable = isReachableFromAst(tu, b2); if (b1Reachable != b2Reachable) { return b1Reachable ? 1 : -1; } @@ -2502,7 +2504,7 @@ public class CPPSemantics { if (isFromIndex(obj)) { for (int i = 0; i < fns.length; i++) { if (!isFromIndex(fns[i])) { - return -1; // function from ast + return -1; // function from ast } } // Everything is from the index @@ -2516,7 +2518,7 @@ public class CPPSemantics { return 0; // obj reachable, 1 function reachable } } - return 1; // no function is reachable + return 1; // no function is reachable } // obj is not from the index @@ -2565,9 +2567,8 @@ public class CPPSemantics { } IIndexFileSet indexFileSet = ast.getIndexFileSet(); IIndexFileSet astFileSet = ast.getASTFileSet(); - return indexFileSet != null && - (indexFileSet.containsDeclaration(indexBinding) || - astFileSet.containsDeclaration(indexBinding)); + return indexFileSet != null + && (indexFileSet.containsDeclaration(indexBinding) || astFileSet.containsDeclaration(indexBinding)); } /** @@ -2584,7 +2585,7 @@ public class CPPSemantics { } IIndexName indexName = (IIndexName) name; try { - IIndexFile file= indexName.getFile(); + IIndexFile file = indexName.getFile(); IIndexFileSet indexFileSet = ast.getIndexFileSet(); return indexFileSet != null && indexFileSet.contains(file); } catch (CoreException e) { @@ -2596,15 +2597,15 @@ public class CPPSemantics { assert data.forDeclaration() == null; final int argumentCount = data.getFunctionArgumentCount(); - final int packExpansionCount= data.getFunctionArgumentPackExpansionCount(); + final int packExpansionCount = data.getFunctionArgumentPackExpansionCount(); // Trim the list down to the set of viable functions - ICPPFunction[] result= new ICPPFunction[functions.length]; - int idx= 0; + ICPPFunction[] result = new ICPPFunction[functions.length]; + int idx = 0; for (ICPPFunction fn : functions) { if (fn != null && !(fn instanceof IProblemBinding)) { if (fn instanceof ICPPUnknownBinding) { - return new ICPPFunction[] {fn}; + return new ICPPFunction[] { fn }; } // The index is optimized to provide the function type, try not to use the parameters @@ -2613,7 +2614,7 @@ public class CPPSemantics { final IType[] parameterTypes = ft.getParameterTypes(); int numPars = parameterTypes.length; if (numPars == 1 && SemanticUtil.isVoidType(parameterTypes[0])) - numPars= 0; + numPars = 0; int numArgs = argumentCount; if (fn instanceof ICPPMethod && data.argsContainImpliedObject) @@ -2622,7 +2623,7 @@ public class CPPSemantics { boolean ok; if (numArgs - packExpansionCount > numPars) { // More arguments than parameters --> need ellipsis or parameter pack - ok= fn.takesVarArgs() || fn.hasParameterPack(); + ok = fn.takesVarArgs() || fn.hasParameterPack(); } else { ok = numArgs >= fn.getRequiredArgumentCount() || packExpansionCount > 0; } @@ -2632,13 +2633,13 @@ public class CPPSemantics { if (other == null || other instanceof IIndexBinding) break; if (other.getType().isSameType(ft)) { - ok= false; + ok = false; break; } } } if (ok) { - result[idx++]= fn; + result[idx++] = fn; } } } @@ -2651,7 +2652,7 @@ public class CPPSemantics { final IASTName lookupName = data.getLookupName(); if (fns == null || fns.length == 0 || fns[0] == null) return null; - fns= ArrayUtil.trim(fns); + fns = ArrayUtil.trim(fns); sortAstBeforeIndex(fns); @@ -2674,17 +2675,15 @@ public class CPPSemantics { // Reduce our set of candidate functions to only those who have the right number of parameters. final IType[] argTypes = data.getFunctionArgumentTypes(); - ICPPFunction[] tmp= selectByArgumentCount(data, fns); + ICPPFunction[] tmp = selectByArgumentCount(data, fns); if (tmp.length == 0 || tmp[0] == null) return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); - tmp= CPPTemplates.instantiateForFunctionCall(tmp, data.getTemplateArguments(), - Arrays.asList(argTypes), - Arrays.asList(data.getFunctionArgumentValueCategories()), - data.argsContainImpliedObject); + tmp = CPPTemplates.instantiateForFunctionCall(tmp, data.getTemplateArguments(), Arrays.asList(argTypes), + Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject); if (tmp.length == 0 || tmp[0] == null) return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); - int viableCount= 0; + int viableCount = 0; for (IFunction f : tmp) { if (f instanceof ICPPUnknownBinding) { setTargetedFunctionsToUnknown(argTypes); @@ -2698,25 +2697,25 @@ public class CPPSemantics { return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); // Check for dependent arguments - fns= tmp; + fns = tmp; if (CPPTemplates.containsDependentType(argTypes)) { setTargetedFunctionsToUnknown(argTypes); return CPPDeferredFunction.createForCandidates(fns); } - IFunction[] ambiguousFunctions= null; // Ambiguity, two or more functions are equally good. - FunctionCost bestFnCost = null; // The cost of the best function. + IFunction[] ambiguousFunctions = null; // Ambiguity, two or more functions are equally good. + FunctionCost bestFnCost = null; // The cost of the best function. // Loop over all functions - List<FunctionCost> potentialCosts= null; - ICPPFunction unknownFunction= null; + List<FunctionCost> potentialCosts = null; + ICPPFunction unknownFunction = null; final CPPASTTranslationUnit tu = data.getTranslationUnit(); for (ICPPFunction fn : fns) { if (fn == null) continue; UDCMode udc = allowUDC ? UDCMode.DEFER : UDCMode.FORBIDDEN; - FunctionCost fnCost= costForFunctionCall(fn, udc, data, resolveTargetedArgumentTypes); + FunctionCost fnCost = costForFunctionCall(fn, udc, data, resolveTargetedArgumentTypes); if (fnCost == null) continue; @@ -2729,29 +2728,30 @@ public class CPPSemantics { if (fnCost.hasDeferredUDC()) { if (potentialCosts == null) { - potentialCosts= new ArrayList<>(); + potentialCosts = new ArrayList<>(); } potentialCosts.add(fnCost); continue; } - int cmp= fnCost.compareTo(tu, bestFnCost); + int cmp = fnCost.compareTo(tu, bestFnCost); if (cmp < 0) { - bestFnCost= fnCost; - ambiguousFunctions= null; + bestFnCost = fnCost; + ambiguousFunctions = null; } else if (cmp == 0) { - ambiguousFunctions= ArrayUtil.append(IFunction.class, ambiguousFunctions, fn); + ambiguousFunctions = ArrayUtil.append(IFunction.class, ambiguousFunctions, fn); } } if (potentialCosts != null) { for (FunctionCost fnCost : potentialCosts) { if (!fnCost.mustBeWorse(bestFnCost) && fnCost.performUDC()) { - int cmp= fnCost.compareTo(tu, bestFnCost); + int cmp = fnCost.compareTo(tu, bestFnCost); if (cmp < 0) { - bestFnCost= fnCost; - ambiguousFunctions= null; + bestFnCost = fnCost; + ambiguousFunctions = null; } else if (cmp == 0) { - ambiguousFunctions= ArrayUtil.append(IFunction.class, ambiguousFunctions, fnCost.getFunction()); + ambiguousFunctions = ArrayUtil.append(IFunction.class, ambiguousFunctions, + fnCost.getFunction()); } } } @@ -2766,13 +2766,13 @@ public class CPPSemantics { } if (ambiguousFunctions != null) { - ambiguousFunctions= ArrayUtil.append(IFunction.class, ambiguousFunctions, bestFnCost.getFunction()); - return new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, ambiguousFunctions); + ambiguousFunctions = ArrayUtil.append(IFunction.class, ambiguousFunctions, bestFnCost.getFunction()); + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + ambiguousFunctions); } if (bestFnCost.hasAmbiguousUserDefinedConversion()) { - return new ProblemBinding(lookupName, lookupPoint, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + data.getFoundBindings()); } for (int i = 0; i < argTypes.length; i++) { @@ -2781,10 +2781,10 @@ public class CPPSemantics { ((FunctionSetType) iType).applySelectedFunction(bestFnCost.getCost(i).getSelectedFunction()); } } - IFunction result= bestFnCost.getFunction(); + IFunction result = bestFnCost.getFunction(); if (bestFnCost.isDirectInitWithCopyCtor()) { - Cost c0= bestFnCost.getCost(0); - IFunction firstConversion= c0.getUserDefinedConversion(); + Cost c0 = bestFnCost.getCost(0); + IFunction firstConversion = c0.getUserDefinedConversion(); if (firstConversion instanceof ICPPConstructor) return firstConversion; } @@ -2808,8 +2808,7 @@ public class CPPSemantics { } if (t instanceof FunctionSetType) { - ICPPFunction function = - resolveTargetedFunction(targetType, ((FunctionSetType) t).getFunctionSet()); + ICPPFunction function = resolveTargetedFunction(targetType, ((FunctionSetType) t).getFunctionSet()); if (function != null && !(function instanceof IProblemBinding)) { type = function.getType(); if (targetType instanceof ITypeContainer) { @@ -2825,16 +2824,16 @@ public class CPPSemantics { private static IBinding createFunctionSet(ICPPFunction[] fns, ICPPTemplateArgument[] args, IASTName name) { // First try to find a unique function if (name != null && name.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { - name= (IASTName) name.getParent(); + name = (IASTName) name.getParent(); } - ICPPFunction f= getUniqueFunctionForSet(fns, args); + ICPPFunction f = getUniqueFunctionForSet(fns, args); return f == null ? new CPPFunctionSet(fns, args, name) : f; } private static ICPPFunction getUniqueFunctionForSet(ICPPFunction[] fns, ICPPTemplateArgument[] args) { // First try to find a unique function - ICPPFunction result= null; - boolean haveASTResult= false; + ICPPFunction result = null; + boolean haveASTResult = false; for (ICPPFunction f : fns) { // Use the ast binding final boolean fromIndex = isFromIndex(f); @@ -2844,27 +2843,27 @@ public class CPPSemantics { boolean isCandidate; if (f instanceof ICPPFunctionTemplate) { if (args == null) { - isCandidate= true; + isCandidate = true; } else { // See 14.3-7 ICPPFunctionTemplate funcTemp = (ICPPFunctionTemplate) f; final ICPPTemplateParameter[] tpars = funcTemp.getTemplateParameters(); final CPPTemplateParameterMap map = new CPPTemplateParameterMap(tpars.length); if (!TemplateArgumentDeduction.addExplicitArguments(funcTemp, tpars, args, map)) { - isCandidate= false; + isCandidate = false; } else { f = CPPTemplates.instantiateForAddressOfFunction(funcTemp, null, args); - isCandidate= f != null; + isCandidate = f != null; } } } else { - isCandidate= args == null; + isCandidate = args == null; } if (isCandidate) { if (result != null) return null; - result= f; - haveASTResult= !fromIndex; + result = f; + haveASTResult = !fromIndex; } } @@ -2887,22 +2886,21 @@ public class CPPSemantics { * specializations or instantiations. */ private static IBinding resolveFunctionDeclaration(LookupData data, ICPPFunction[] fns) throws DOMException { - final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(data.getDeclarator()); + final IASTDeclarator dtor = ASTQueries.findTypeRelevantDeclarator(data.getDeclarator()); final IType t = CPPVisitor.createType(dtor); if (!(t instanceof ICPPFunctionType)) return null; - final ICPPFunctionType ft= (ICPPFunctionType) t; + final ICPPFunctionType ft = (ICPPFunctionType) t; - IASTName templateID= data.getLookupName(); + IASTName templateID = data.getLookupName(); if (templateID.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { - templateID= (ICPPASTTemplateId) templateID.getParent(); + templateID = (ICPPASTTemplateId) templateID.getParent(); } // 14.5.4 Friends with template ids require instantiation - boolean isFriend= CPPVisitor.isFriendDeclaration(data.forDeclaration()); - if (!data.forExplicitFunctionSpecialization() - && !(isFriend && templateID instanceof ICPPASTTemplateId)) { + boolean isFriend = CPPVisitor.isFriendDeclaration(data.forDeclaration()); + if (!data.forExplicitFunctionSpecialization() && !(isFriend && templateID instanceof ICPPASTTemplateId)) { // Search for a matching function for (ICPPFunction fn : fns) { if (fn != null && !(fn instanceof IProblemBinding) && !(fn instanceof ICPPUnknownBinding)) { @@ -2919,38 +2917,39 @@ public class CPPSemantics { } // Try to instantiate a template - IASTTranslationUnit tu= data.getTranslationUnit(); - ICPPTemplateArgument[] tmplArgs= ICPPTemplateArgument.EMPTY_ARGUMENTS; + IASTTranslationUnit tu = data.getTranslationUnit(); + ICPPTemplateArgument[] tmplArgs = ICPPTemplateArgument.EMPTY_ARGUMENTS; if (templateID instanceof ICPPASTTemplateId) { tmplArgs = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) templateID); } - ICPPFunctionTemplate bestTemplate= null; - ICPPFunction bestInst= null; - boolean isAmbiguous= false; + ICPPFunctionTemplate bestTemplate = null; + ICPPFunction bestInst = null; + boolean isAmbiguous = false; for (ICPPFunction fn : fns) { - if (fn instanceof ICPPFunctionTemplate - && !(fn instanceof IProblemBinding) && !(fn instanceof ICPPUnknownBinding)) { + if (fn instanceof ICPPFunctionTemplate && !(fn instanceof IProblemBinding) + && !(fn instanceof ICPPUnknownBinding)) { // If the declared function type is dependent, there is no point trying to use it // to instantiate the template, so return a deferred function instead. // Note that CPPTemplates.instantiateForFunctionCall() behaves similarly. if (CPPTemplates.isDependentType(ft)) { return CPPDeferredFunction.createForCandidates(fns); } - ICPPFunctionTemplate template= (ICPPFunctionTemplate) fn; - ICPPFunction inst= CPPTemplates.instantiateForFunctionDeclaration(template, tmplArgs, ft); + ICPPFunctionTemplate template = (ICPPFunctionTemplate) fn; + ICPPFunction inst = CPPTemplates.instantiateForFunctionDeclaration(template, tmplArgs, ft); if (inst != null) { - int cmp= CPPTemplates.orderFunctionTemplates(bestTemplate, template, TypeSelection.PARAMETERS_AND_RETURN_TYPE); + int cmp = CPPTemplates.orderFunctionTemplates(bestTemplate, template, + TypeSelection.PARAMETERS_AND_RETURN_TYPE); if (cmp == 0) - cmp= compareByRelevance(tu, bestTemplate, template); + cmp = compareByRelevance(tu, bestTemplate, template); if (cmp == 0) - isAmbiguous= true; + isAmbiguous = true; if (cmp < 0) { - isAmbiguous= false; - bestTemplate= template; - bestInst= inst; + isAmbiguous = false; + bestTemplate = template; + bestInst = inst; } } } @@ -2963,13 +2962,13 @@ public class CPPSemantics { } public static void sortAstBeforeIndex(IFunction[] fns) { - int iast= 0; + int iast = 0; for (int i = 0; i < fns.length; i++) { - IFunction fn= fns[i]; + IFunction fn = fns[i]; if (!(fn instanceof IIndexBinding)) { if (iast != i) { - fns[i]= fns[iast]; - fns[iast]= fn; + fns[i] = fns[iast]; + fns[iast] = fn; } iast++; } @@ -2978,12 +2977,12 @@ public class CPPSemantics { private static FunctionCost costForFunctionCall(ICPPFunction fn, UDCMode udc, LookupData data, boolean resolveTargetedArgumentTypes) throws DOMException { - final ICPPFunctionType ftype= fn.getType(); + final ICPPFunctionType ftype = fn.getType(); if (ftype == null) return null; - IType[] argTypes= data.getFunctionArgumentTypes(); - ValueCategory[] argValueCategories= data.getFunctionArgumentValueCategories(); + IType[] argTypes = data.getFunctionArgumentTypes(); + ValueCategory[] argValueCategories = data.getFunctionArgumentValueCategories(); if (resolveTargetedArgumentTypes) { IType[] newArgTypes = null; IType[] paramTypes = fn.getType().getParameterTypes(); @@ -3004,40 +3003,39 @@ public class CPPSemantics { } } - int skipArg= 0; - IType implicitParameterType= null; - IType impliedObjectType= null; - ValueCategory impliedObjectValueCategory= null; - final IType[] paramTypes= ftype.getParameterTypes(); + int skipArg = 0; + IType implicitParameterType = null; + IType impliedObjectType = null; + ValueCategory impliedObjectValueCategory = null; + final IType[] paramTypes = ftype.getParameterTypes(); if (fn instanceof ICPPMethod && !(fn instanceof ICPPConstructor)) { implicitParameterType = getImplicitParameterType((ICPPMethod) fn); if (data.argsContainImpliedObject) { - impliedObjectType= argTypes[0]; - impliedObjectValueCategory= argValueCategories[0]; - skipArg= 1; + impliedObjectType = argTypes[0]; + impliedObjectValueCategory = argValueCategories[0]; + skipArg = 1; } } - int k= 0; + int k = 0; Cost cost; - final int sourceLen= argTypes.length - skipArg; + final int sourceLen = argTypes.length - skipArg; final FunctionCost result; if (implicitParameterType == null) { - result= new FunctionCost(fn, sourceLen); + result = new FunctionCost(fn, sourceLen); } else { - result= new FunctionCost(fn, sourceLen + 1); + result = new FunctionCost(fn, sourceLen + 1); if (impliedObjectType == null) { - impliedObjectType= data.getImpliedObjectType(); + impliedObjectType = data.getImpliedObjectType(); } if (impliedObjectValueCategory == null) { - impliedObjectValueCategory= data.getImpliedObjectValueCategory(); + impliedObjectValueCategory = data.getImpliedObjectValueCategory(); if (impliedObjectValueCategory == null) - impliedObjectValueCategory= ValueCategory.LVALUE; + impliedObjectValueCategory = ValueCategory.LVALUE; } - if (fn instanceof ICPPMethod && - (((ICPPMethod) fn).isDestructor() || ASTInternal.isStatic(fn, false))) { + if (fn instanceof ICPPMethod && (((ICPPMethod) fn).isDestructor() || ASTInternal.isStatic(fn, false))) { // 13.3.1-4 for static member functions, the implicit object parameter always matches, no cost cost = new Cost(impliedObjectType, implicitParameterType, Rank.IDENTITY); cost.setImpliedObject(); @@ -3047,17 +3045,17 @@ public class CPPSemantics { cost = new Cost(impliedObjectType, implicitParameterType, Rank.IDENTITY); cost.setImpliedObject(); } else { - Context context = ftype.hasRefQualifier() ? - Context.IMPLICIT_OBJECT_FOR_METHOD_WITH_REF_QUALIFIER : - Context.IMPLICIT_OBJECT_FOR_METHOD_WITHOUT_REF_QUALIFIER; + Context context = ftype.hasRefQualifier() ? Context.IMPLICIT_OBJECT_FOR_METHOD_WITH_REF_QUALIFIER + : Context.IMPLICIT_OBJECT_FOR_METHOD_WITHOUT_REF_QUALIFIER; cost = Conversions.checkImplicitConversionSequence(implicitParameterType, impliedObjectType, impliedObjectValueCategory, UDCMode.FORBIDDEN, context); if (cost.converts()) { cost.setImpliedObject(); } else { - if (CPPTemplates.isDependentType(implicitParameterType) || CPPTemplates.isDependentType(impliedObjectType)) { - IType s= getNestedType(impliedObjectType, TDEF|REF|CVTYPE); - IType t= getNestedType(implicitParameterType, TDEF|REF|CVTYPE); + if (CPPTemplates.isDependentType(implicitParameterType) + || CPPTemplates.isDependentType(impliedObjectType)) { + IType s = getNestedType(impliedObjectType, TDEF | REF | CVTYPE); + IType t = getNestedType(implicitParameterType, TDEF | REF | CVTYPE); if (SemanticUtil.calculateInheritanceDepth(s, t) >= 0) return null; @@ -3072,7 +3070,7 @@ public class CPPSemantics { } for (int j = 0; j < sourceLen; j++) { - final IType argType= SemanticUtil.getNestedType(argTypes[j + skipArg], TDEF | REF); + final IType argType = SemanticUtil.getNestedType(argTypes[j + skipArg], TDEF | REF); if (argType == null) return null; @@ -3080,9 +3078,9 @@ public class CPPSemantics { IType paramType; if (j < paramTypes.length) { - paramType= getNestedType(paramTypes[j], TDEF); + paramType = getNestedType(paramTypes[j], TDEF); } else if (!fn.takesVarArgs()) { - paramType= VOID_TYPE; + paramType = VOID_TYPE; } else { cost = new Cost(argType, null, Rank.ELLIPSIS_CONVERSION); result.setCost(k++, cost, argValueCategory); @@ -3090,26 +3088,26 @@ public class CPPSemantics { } if (argType instanceof FunctionSetType) { - cost= ((FunctionSetType) argType).costForTarget(paramType); + cost = ((FunctionSetType) argType).costForTarget(paramType); } else if (argType.isSameType(paramType)) { cost = new Cost(argType, paramType, Rank.IDENTITY); } else { if (CPPTemplates.isDependentType(paramType)) return CONTAINS_DEPENDENT_TYPES; - Context ctx= Context.ORDINARY; + Context ctx = Context.ORDINARY; if (j == 0 && sourceLen == 1 && fn instanceof ICPPConstructor) { if (paramType instanceof ICPPReferenceType) { - if (((ICPPConstructor) fn).getClassOwner().isSameType(getNestedType(paramType, TDEF|REF|CVTYPE))) { - ctx= Context.FIRST_PARAM_OF_DIRECT_COPY_CTOR; + if (((ICPPConstructor) fn).getClassOwner() + .isSameType(getNestedType(paramType, TDEF | REF | CVTYPE))) { + ctx = Context.FIRST_PARAM_OF_DIRECT_COPY_CTOR; result.setIsDirectInitWithCopyCtor(true); } } } - cost = Conversions.checkImplicitConversionSequence(paramType, argType, argValueCategory, - udc, ctx); + cost = Conversions.checkImplicitConversionSequence(paramType, argType, argValueCategory, udc, ctx); if (data.fNoNarrowing && cost.isNarrowingConversion()) { - cost= Cost.NO_CONVERSION; + cost = Cost.NO_CONVERSION; } } if (!cost.converts()) @@ -3120,44 +3118,44 @@ public class CPPSemantics { return result; } - static IType getImplicitParameterType(ICPPMethod m) { + static IType getImplicitParameterType(ICPPMethod m) { IType implicitType; - ICPPClassType owner= m.getClassOwner(); + ICPPClassType owner = m.getClassOwner(); if (owner instanceof ICPPClassTemplate) { - owner= (ICPPClassType) ((ICPPClassTemplate) owner).asDeferredInstance(); + owner = (ICPPClassType) ((ICPPClassTemplate) owner).asDeferredInstance(); } - ICPPFunctionType ft= m.getType(); - implicitType= SemanticUtil.addQualifiers(owner, ft.isConst(), ft.isVolatile(), false); + ICPPFunctionType ft = m.getType(); + implicitType = SemanticUtil.addQualifiers(owner, ft.isConst(), ft.isVolatile(), false); return new CPPReferenceType(implicitType, ft.isRValueReference()); } private static IBinding resolveUserDefinedConversion(LookupData data, ICPPFunction[] fns) { - ICPPASTConversionName astName= (ICPPASTConversionName) data.getLookupName(); - IType t= CPPVisitor.createType(astName.getTypeId()); + ICPPASTConversionName astName = (ICPPASTConversionName) data.getLookupName(); + IType t = CPPVisitor.createType(astName.getTypeId()); if (t instanceof ISemanticProblem) { - return new ProblemBinding(astName, data.getLookupPoint(), - IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); + return new ProblemBinding(astName, data.getLookupPoint(), IProblemBinding.SEMANTIC_INVALID_TYPE, + data.getFoundBindings()); } - if (data.forDeclaration() == null || - data.forExplicitFunctionSpecialization() || data.forExplicitFunctionInstantiation()) { - fns= CPPTemplates.instantiateConversionTemplates(fns, t); + if (data.forDeclaration() == null || data.forExplicitFunctionSpecialization() + || data.forExplicitFunctionInstantiation()) { + fns = CPPTemplates.instantiateConversionTemplates(fns, t); } - IFunction unknown= null; + IFunction unknown = null; for (IFunction function : fns) { if (function != null) { - IType t2= function.getType().getReturnType(); + IType t2 = function.getType().getReturnType(); if (t.isSameType(t2)) return function; if (unknown == null && function instanceof ICPPUnknownBinding) { - unknown= function; + unknown = function; } } } if (unknown != null) return unknown; - return new ProblemBinding(astName, data.getLookupPoint(), - IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getFoundBindings()); + return new ProblemBinding(astName, data.getLookupPoint(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, + data.getFoundBindings()); } /** @@ -3167,71 +3165,71 @@ public class CPPSemantics { static IBinding resolveTargetedFunction(IASTName name, CPPFunctionSet functionSet) { pushLookupPoint(name); try { - boolean addressOf= false; - IASTNode node= name.getParent(); + boolean addressOf = false; + IASTNode node = name.getParent(); while (node instanceof IASTName) { - node= node.getParent(); + node = node.getParent(); } - + if (!(node instanceof IASTIdExpression)) return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD); - - ASTNodeProperty prop= node.getPropertyInParent(); + + ASTNodeProperty prop = node.getPropertyInParent(); IASTNode parent = node.getParent(); while (parent instanceof IASTUnaryExpression) { - final int op= ((IASTUnaryExpression) parent).getOperator(); + final int op = ((IASTUnaryExpression) parent).getOperator(); if (op == IASTUnaryExpression.op_bracketedPrimary) { } else if (!addressOf && op == IASTUnaryExpression.op_amper) { - addressOf= true; + addressOf = true; } else { break; } - node= parent; - prop= node.getPropertyInParent(); - parent= node.getParent(); + node = parent; + prop = node.getPropertyInParent(); + parent = node.getParent(); } - - IType targetType= null; + + IType targetType = null; if (prop == IASTDeclarator.INITIALIZER) { // Target is an object or reference being initialized IASTDeclarator dtor = (IASTDeclarator) parent; - targetType= CPPVisitor.createType(dtor); + targetType = CPPVisitor.createType(dtor); } else if (prop == IASTEqualsInitializer.INITIALIZER) { final IASTNode grandpa = parent.getParent(); if (grandpa instanceof IASTDeclarator) { IASTDeclarator dtor = ASTQueries.findInnermostDeclarator((IASTDeclarator) grandpa); - IBinding var= dtor.getName().resolvePreBinding(); + IBinding var = dtor.getName().resolvePreBinding(); if (var instanceof IVariable) - targetType= ((IVariable) var).getType(); + targetType = ((IVariable) var).getType(); } } else if (prop == ICPPASTConstructorInitializer.ARGUMENT) { ICPPASTConstructorInitializer init = (ICPPASTConstructorInitializer) parent; final IASTNode parentOfInit = init.getParent(); if (parentOfInit instanceof IASTDeclarator) { IASTDeclarator dtor = (IASTDeclarator) parentOfInit; - targetType= CPPVisitor.createType(dtor); + targetType = CPPVisitor.createType(dtor); } else if (parentOfInit instanceof ICPPASTConstructorChainInitializer) { - ICPPASTConstructorChainInitializer memInit= (ICPPASTConstructorChainInitializer) parentOfInit; - IBinding var= memInit.getMemberInitializerId().resolveBinding(); + ICPPASTConstructorChainInitializer memInit = (ICPPASTConstructorChainInitializer) parentOfInit; + IBinding var = memInit.getMemberInitializerId().resolveBinding(); if (var instanceof IVariable) { - targetType= ((IVariable) var).getType(); + targetType = ((IVariable) var).getType(); } } - targetType= getNestedType(targetType, TDEF | REF | CVTYPE | PTR | MPTR); + targetType = getNestedType(targetType, TDEF | REF | CVTYPE | PTR | MPTR); if (init.getArguments().length != 1 || !(targetType instanceof ICPPFunctionType)) { if (targetType instanceof ICPPClassType) { - LookupData data= new LookupData(name); + LookupData data = new LookupData(name); data.setFunctionArguments(false, init.getArguments()); try { - IBinding ctor = resolveFunction(data, - ((ICPPClassType) targetType).getConstructors(), true, false); + IBinding ctor = resolveFunction(data, ((ICPPClassType) targetType).getConstructors(), true, + false); if (ctor instanceof ICPPConstructor) { - int i= 0; + int i = 0; for (IASTNode arg : init.getArguments()) { if (arg == node) { - IType[] params= ((ICPPConstructor) ctor).getType().getParameterTypes(); + IType[] params = ((ICPPConstructor) ctor).getType().getParameterTypes(); if (params.length > i) { - targetType= params[i]; + targetType = params[i]; } break; } @@ -3245,22 +3243,23 @@ public class CPPSemantics { } else if (prop == IASTBinaryExpression.OPERAND_TWO) { IASTBinaryExpression binaryExp = (IASTBinaryExpression) parent; if (binaryExp.getOperator() == IASTBinaryExpression.op_assign) { - targetType= binaryExp.getOperand1().getExpressionType(); + targetType = binaryExp.getOperand1().getExpressionType(); } } else if (prop == IASTFunctionCallExpression.ARGUMENT) { // Target is a parameter of a function, need to resolve the function call IASTFunctionCallExpression fnCall = (IASTFunctionCallExpression) parent; - IType t= SemanticUtil.getNestedType(fnCall.getFunctionNameExpression().getExpressionType(), TDEF | REF | CVTYPE); + IType t = SemanticUtil.getNestedType(fnCall.getFunctionNameExpression().getExpressionType(), + TDEF | REF | CVTYPE); if (t instanceof IPointerType) { - t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); + t = SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); } if (t instanceof IFunctionType) { - int i= 0; + int i = 0; for (IASTNode arg : fnCall.getArguments()) { if (arg == node) { - IType[] params= ((IFunctionType) t).getParameterTypes(); + IType[] params = ((IFunctionType) t).getParameterTypes(); if (params.length > i) { - targetType= params[i]; + targetType = params[i]; } break; } @@ -3270,7 +3269,7 @@ public class CPPSemantics { } else if (prop == IASTCastExpression.OPERAND) { // target is an explicit type conversion IASTCastExpression cast = (IASTCastExpression) parent; - targetType= CPPVisitor.createType(cast.getTypeId().getAbstractDeclarator()); + targetType = CPPVisitor.createType(cast.getTypeId().getAbstractDeclarator()); } else if (prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { // target is a template non-type parameter (14.3.2-5) ICPPASTTemplateId id = (ICPPASTTemplateId) parent; @@ -3285,7 +3284,7 @@ public class CPPSemantics { if (template instanceof ICPPTemplateDefinition) { ICPPTemplateParameter[] ps = ((ICPPTemplateDefinition) template).getTemplateParameters(); if (i < args.length && i < ps.length && ps[i] instanceof ICPPTemplateNonTypeParameter) { - targetType= ((ICPPTemplateNonTypeParameter) ps[i]).getType(); + targetType = ((ICPPTemplateNonTypeParameter) ps[i]).getType(); } } } else if (prop == IASTReturnStatement.RETURNVALUE) { @@ -3295,34 +3294,33 @@ public class CPPSemantics { } if (parent instanceof IASTFunctionDefinition) { IASTDeclarator dtor = ((IASTFunctionDefinition) parent).getDeclarator(); - dtor= ASTQueries.findInnermostDeclarator(dtor); + dtor = ASTQueries.findInnermostDeclarator(dtor); IBinding binding = dtor.getName().resolveBinding(); if (binding instanceof IFunction) { IFunctionType ft = ((IFunction) binding).getType(); - targetType= ft.getReturnType(); + targetType = ft.getReturnType(); } } } - if (targetType == null && parent instanceof ICPPASTExpression - && parent instanceof IASTImplicitNameOwner) { + if (targetType == null && parent instanceof ICPPASTExpression && parent instanceof IASTImplicitNameOwner) { // Trigger resolution of overloaded operator, which may resolve the // function set. ((IASTImplicitNameOwner) parent).getImplicitNames(); final IBinding newBinding = name.getPreBinding(); if (!(newBinding instanceof CPPFunctionSet)) return newBinding; - + // If we're in a dependent context, we don't have enough information // to resolve the function set. if (((ICPPASTExpression) parent).getEvaluation().isTypeDependent()) { return CPPDeferredFunction.createForCandidates(functionSet.getBindings()); } } - + ICPPFunction function = resolveTargetedFunction(targetType, functionSet); if (function == null) return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD); - + return function; } finally { popLookupPoint(); @@ -3380,7 +3378,7 @@ public class CPPSemantics { ICPPFunction[] funcs = new ICPPFunction[bindings.length]; ICPPFunctionTemplate[] tplFunctions = new ICPPFunctionTemplate[bindings.length]; LookupData data = new LookupData(((CPPASTLiteralExpression) exp).getOperatorName(), null, exp); - + int i = 0, j = 0; for (IBinding binding : bindings) { if (binding instanceof ICPPFunction || binding instanceof ICPPFunctionTemplate) { @@ -3390,15 +3388,15 @@ public class CPPSemantics { } } } - + funcs = ArrayUtil.trim(funcs, i); tplFunctions = ArrayUtil.trim(tplFunctions, j); - + if (funcs.length == 0) { // S shall not be empty return new ProblemBinding(data.getLookupName(), exp, IProblemBinding.SEMANTIC_NAME_NOT_FOUND); } - + if (kind == IASTLiteralExpression.lk_integer_constant || kind == IASTLiteralExpression.lk_float_constant) { if (kind == IASTLiteralExpression.lk_integer_constant) { /* @@ -3429,7 +3427,7 @@ public class CPPSemantics { return ret; } } - + /* * 2.14.8.3 (cont.), 2.14.8.4 (cont.) * Otherwise, S shall contain a raw literal operator or a literal @@ -3440,26 +3438,28 @@ public class CPPSemantics { data = new LookupData(((CPPASTLiteralExpression) exp).getOperatorName(), null, exp); data.setFunctionArguments(false, createArgForType(exp, charArray)); ret = resolveFunction(data, funcs, true, false); - + // char[] stringLiteral = exp.getValue(); // The string literal that was passed to the operator - + // The string literal is passed to the operator as chars: // "literal"_op -> operator "" _op<'l', 'i', 't', 'e', 'r', 'a', 'l'>(); ICPPTemplateArgument args[] = new ICPPTemplateArgument[stringLiteral.length]; for (int k = 0; k < stringLiteral.length; k++) { - args[k] = new CPPTemplateNonTypeArgument(new EvalFixed(CPPBasicType.CHAR, PRVALUE, IntegralValue.create(stringLiteral[k]))); + args[k] = new CPPTemplateNonTypeArgument( + new EvalFixed(CPPBasicType.CHAR, PRVALUE, IntegralValue.create(stringLiteral[k]))); } - + data = new LookupData(((CPPASTLiteralExpression) exp).getOperatorName(), args, exp); IBinding litTpl = resolveFunction(data, tplFunctions, true, false); - + // Do we have valid template and non-template bindings? if (ret != null && !(ret instanceof IProblemBinding)) { // Do we have valid template and non-template bindings? if (litTpl instanceof ICPPFunctionInstance) { // Ambiguity? It has two valid options, and the spec says it shouldn't - return new ProblemBinding(data.getLookupName(), exp, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, tplFunctions); + return new ProblemBinding(data.getLookupName(), exp, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, + tplFunctions); } } else { if (litTpl instanceof ICPPFunctionInstance) { @@ -3478,11 +3478,11 @@ public class CPPSemantics { * str (i.e., its length excluding the terminating null character). * L is treated as operator "" X(str, len) */ - CPPPointerType strType = new CPPPointerType(new CPPBasicType(((CPPASTLiteralExpression) exp).getBasicCharKind(), 0, null), true, false, false); - IASTInitializerClause[] initializer = new IASTInitializerClause[] { - createArgForType(exp, strType), - createArgForType(null, CPPBasicType.UNSIGNED_INT) - }; + CPPPointerType strType = new CPPPointerType( + new CPPBasicType(((CPPASTLiteralExpression) exp).getBasicCharKind(), 0, null), true, false, + false); + IASTInitializerClause[] initializer = new IASTInitializerClause[] { createArgForType(exp, strType), + createArgForType(null, CPPBasicType.UNSIGNED_INT) }; data.setFunctionArguments(false, initializer); ret = resolveFunction(data, funcs, true, false); } else if (kind == IASTLiteralExpression.lk_char_constant) { @@ -3509,12 +3509,12 @@ public class CPPSemantics { * a function. */ static ICPPFunction resolveTargetedFunction(IType targetType, CPPFunctionSet set) { - targetType= getNestedType(targetType, TDEF | REF | CVTYPE | PTR | MPTR); + targetType = getNestedType(targetType, TDEF | REF | CVTYPE | PTR | MPTR); if (!(targetType instanceof ICPPFunctionType)) return null; // First pass, consider functions - ICPPFunction[] fns= set.getBindings(); + ICPPFunction[] fns = set.getBindings(); for (ICPPFunction fn : fns) { if (!(fn instanceof ICPPFunctionTemplate)) { if (targetType.isSameType(fn.getType())) @@ -3523,29 +3523,29 @@ public class CPPSemantics { } // Second pass, consider templates - ICPPFunction result= null; - ICPPFunctionTemplate resultTemplate= null; - boolean isAmbiguous= false; - final IASTTranslationUnit tu= CPPSemantics.getCurrentLookupPoint().getTranslationUnit(); + ICPPFunction result = null; + ICPPFunctionTemplate resultTemplate = null; + boolean isAmbiguous = false; + final IASTTranslationUnit tu = CPPSemantics.getCurrentLookupPoint().getTranslationUnit(); for (IFunction fn : fns) { try { if (fn instanceof ICPPFunctionTemplate) { final ICPPFunctionTemplate template = (ICPPFunctionTemplate) fn; - ICPPFunction inst= CPPTemplates.instantiateForAddressOfFunction(template, + ICPPFunction inst = CPPTemplates.instantiateForAddressOfFunction(template, (ICPPFunctionType) targetType, set.getTemplateArguments()); if (inst != null) { - int cmp= CPPTemplates.orderFunctionTemplates(resultTemplate, template, + int cmp = CPPTemplates.orderFunctionTemplates(resultTemplate, template, TypeSelection.PARAMETERS_AND_RETURN_TYPE); if (cmp == 0) - cmp= compareByRelevance(tu, resultTemplate, template); + cmp = compareByRelevance(tu, resultTemplate, template); if (cmp == 0) - isAmbiguous= true; + isAmbiguous = true; if (cmp < 0) { - isAmbiguous= false; - resultTemplate= template; - result= inst; + isAmbiguous = false; + resultTemplate = template; + result = inst; } } } @@ -3558,23 +3558,22 @@ public class CPPSemantics { return result; } - public static ICPPFunction findOverloadedBinaryOperator(IScope pointOfDefinition, - OverloadableOperator op, ICPPEvaluation arg1, ICPPEvaluation arg2) { + public static ICPPFunction findOverloadedBinaryOperator(IScope pointOfDefinition, OverloadableOperator op, + ICPPEvaluation arg1, ICPPEvaluation arg2) { if (op == null || arg1 == null || arg2 == null) return null; IType op1type = getNestedType(arg1.getType(), TDEF | REF | CVTYPE); - if (!isUserDefined(op1type) && !isUserDefined( - getNestedType(arg2.getType(), TDEF | REF | CVTYPE))) + if (!isUserDefined(op1type) && !isUserDefined(getNestedType(arg2.getType(), TDEF | REF | CVTYPE))) return null; final LookupMode lookupNonMember; if (op == OverloadableOperator.ASSIGN || op == OverloadableOperator.BRACKET) { lookupNonMember = LookupMode.NO_GLOBALS; } else { - lookupNonMember= LookupMode.LIMITED_GLOBALS; + lookupNonMember = LookupMode.LIMITED_GLOBALS; } - return findOverloadedOperator(pointOfDefinition, new ICPPEvaluation[] {arg1, arg2}, op1type, op, + return findOverloadedOperator(pointOfDefinition, new ICPPEvaluation[] { arg1, arg2 }, op1type, op, lookupNonMember); } @@ -3585,27 +3584,27 @@ public class CPPSemantics { final ICPPEvaluation evaluation = expr.getEvaluation(); if (evaluation.isTypeDependent()) return null; - + final IASTInitializerClause[] placement = expr.getPlacementArguments(); - final ICPPEvaluation arg1= new EvalUnary(IASTUnaryExpression.op_star, evaluation, null, expr); - final ICPPEvaluation arg2= new EvalUnary(IASTUnaryExpression.op_sizeof, evaluation, null, expr); - + final ICPPEvaluation arg1 = new EvalUnary(IASTUnaryExpression.op_star, evaluation, null, expr); + final ICPPEvaluation arg2 = new EvalUnary(IASTUnaryExpression.op_sizeof, evaluation, null, expr); + ICPPEvaluation[] args; if (placement == null) { - args= new ICPPEvaluation[] { arg1, arg2 }; + args = new ICPPEvaluation[] { arg1, arg2 }; } else { - args= new ICPPEvaluation[2 + placement.length]; - args[0]= arg1; - args[1]= arg2; - int i= 2; + args = new ICPPEvaluation[2 + placement.length]; + args[0] = arg1; + args[1] = arg2; + int i = 2; for (IASTInitializerClause p : placement) { final ICPPEvaluation a = ((ICPPASTInitializerClause) p).getEvaluation(); if (a.isTypeDependent()) return null; - args[i++]= a; + args[i++] = a; } } - IType type= getNestedType(arg1.getType(), TDEF | REF | CVTYPE); + IType type = getNestedType(arg1.getType(), TDEF | REF | CVTYPE); return findOverloadedOperator(null, args, type, op, LookupMode.GLOBALS_IF_NO_MEMBERS); } finally { popLookupPoint(); @@ -3619,11 +3618,9 @@ public class CPPSemantics { IType type = getTypeOfPointer(expr.getOperand().getExpressionType()); if (type == null) return null; - - ICPPEvaluation[] args = { - new EvalFixed(type, LVALUE, IntegralValue.UNKNOWN), - ((ICPPASTExpression) expr.getOperand()).getEvaluation() - }; + + ICPPEvaluation[] args = { new EvalFixed(type, LVALUE, IntegralValue.UNKNOWN), + ((ICPPASTExpression) expr.getOperand()).getEvaluation() }; return findOverloadedOperator(null, args, type, op, LookupMode.GLOBALS_IF_NO_MEMBERS); } finally { popLookupPoint(); @@ -3646,15 +3643,15 @@ public class CPPSemantics { try { if (declarator.getNestedDeclarator() != null) return null; - IASTDeclarator dtor= ASTQueries.findOutermostDeclarator(declarator); + IASTDeclarator dtor = ASTQueries.findOutermostDeclarator(declarator); IASTNode parent = dtor.getParent(); if (parent instanceof IASTSimpleDeclaration) { final IASTInitializer initializer = dtor.getInitializer(); if (initializer == null) { IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); parent = parent.getParent(); - if (parent instanceof IASTCompositeTypeSpecifier || - declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern) { + if (parent instanceof IASTCompositeTypeSpecifier + || declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern) { // No initialization is performed for class members and extern declarations // without an initializer. return null; @@ -3692,10 +3689,10 @@ public class CPPSemantics { return null; if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem) return null; - + // The class type may be declared in a header but defined in the AST. // In such a case, we want the constructors as AST bindings (since as - // index bindings they would fail declaredBefore() filtering), so map + // index bindings they would fail declaredBefore() filtering), so map // the class type to its AST representation. type = SemanticUtil.mapToAST(type); @@ -3712,8 +3709,7 @@ public class CPPSemantics { return null; type = ((IPointerType) type).getType(); if (type instanceof ICPPClassType) { - return findImplicitlyCalledConstructor((ICPPClassType) type, - expr.getInitializer(), expr.getTypeId()); + return findImplicitlyCalledConstructor((ICPPClassType) type, expr.getInitializer(), expr.getTypeId()); } return null; } @@ -3724,18 +3720,18 @@ public class CPPSemantics { try { if (initializer instanceof IASTEqualsInitializer) { // Copy initialization. - IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer; + IASTEqualsInitializer eqInit = (IASTEqualsInitializer) initializer; ICPPASTInitializerClause evalOwner = (ICPPASTInitializerClause) eqInit.getInitializerClause(); final ICPPEvaluation evaluation = evalOwner.getEvaluation(); - IType sourceType= evaluation.getType(); - ValueCategory isLValue= evaluation.getValueCategory(); + IType sourceType = evaluation.getType(); + ValueCategory isLValue = evaluation.getValueCategory(); if (sourceType != null) { Cost c; if (calculateInheritanceDepth(sourceType, type) >= 0) { c = Conversions.copyInitializationOfClass(isLValue, sourceType, type, false); } else { - c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, - UDCMode.ALLOWED, Context.ORDINARY); + c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, + Context.ORDINARY); } if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion(); @@ -3746,9 +3742,9 @@ public class CPPSemantics { } } else if (initializer instanceof ICPPASTInitializerList) { // List initialization. - ICPPEvaluation eval= ((ICPPASTInitializerClause) initializer).getEvaluation(); + ICPPEvaluation eval = ((ICPPASTInitializerClause) initializer).getEvaluation(); if (eval instanceof EvalInitList) { - Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true); + Cost c = Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true); if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion(); if (f instanceof ICPPConstructor) @@ -3757,8 +3753,7 @@ public class CPPSemantics { } } else if (initializer instanceof ICPPASTConstructorInitializer) { // Direct initialization. - return findImplicitlyCalledConstructor(type, - (ICPPASTConstructorInitializer) initializer, typeId); + return findImplicitlyCalledConstructor(type, (ICPPASTConstructorInitializer) initializer, typeId); } else if (initializer == null) { // Default initialization. ICPPConstructor[] ctors = type.getConstructors(); @@ -3812,7 +3807,7 @@ public class CPPSemantics { data.setFunctionArguments(true, new EvalFixed(cls, LVALUE, IntegralValue.UNKNOWN)); try { lookup(data, scope); - IBinding[] found= data.getFoundBindings(); + IBinding[] found = data.getFoundBindings(); if (found.length > 0 && found[0] instanceof ICPPFunction) { return (ICPPFunction) found[0]; } @@ -3822,9 +3817,10 @@ public class CPPSemantics { } public static ICPPASTExpression createArgForType(IASTNode node, final IType type) { - CPPASTName x= new CPPASTName(); + CPPASTName x = new CPPASTName(); x.setBinding(new CPPVariable(x) { - @Override public IType getType() { + @Override + public IType getType() { return type; } }); @@ -3836,33 +3832,34 @@ public class CPPSemantics { /** * For simplicity returns an operator of form RT (T, T) rather than RT (boolean, T, T) */ - public static ICPPFunction findOverloadedConditionalOperator(IScope pointOfDefinition, - ICPPEvaluation positive, ICPPEvaluation negative) { - final ICPPEvaluation[] args = new ICPPEvaluation[] {positive, negative}; - return findOverloadedOperator(pointOfDefinition, args, null, - OverloadableOperator.CONDITIONAL_OPERATOR, LookupMode.NO_GLOBALS); + public static ICPPFunction findOverloadedConditionalOperator(IScope pointOfDefinition, ICPPEvaluation positive, + ICPPEvaluation negative) { + final ICPPEvaluation[] args = new ICPPEvaluation[] { positive, negative }; + return findOverloadedOperator(pointOfDefinition, args, null, OverloadableOperator.CONDITIONAL_OPERATOR, + LookupMode.NO_GLOBALS); } /** * Returns the operator,() function that would apply to the two given arguments. * The lookup type of the class where the operator,() might be found must also be provided. */ - public static ICPPFunction findOverloadedOperatorComma(IScope pointOfDefinition, - ICPPEvaluation arg1, ICPPEvaluation arg2) { + public static ICPPFunction findOverloadedOperatorComma(IScope pointOfDefinition, ICPPEvaluation arg1, + ICPPEvaluation arg2) { IType op1type = getNestedType(arg1.getType(), TDEF | REF | CVTYPE); IType op2type = getNestedType(arg2.getType(), TDEF | REF | CVTYPE); if (!isUserDefined(op1type) && !isUserDefined(op2type)) return null; - ICPPEvaluation[] args = { arg1 , arg2 }; - return findOverloadedOperator(pointOfDefinition, args, op1type, - OverloadableOperator.COMMA, LookupMode.LIMITED_GLOBALS); + ICPPEvaluation[] args = { arg1, arg2 }; + return findOverloadedOperator(pointOfDefinition, args, op1type, OverloadableOperator.COMMA, + LookupMode.LIMITED_GLOBALS); } + static enum LookupMode { + NO_GLOBALS, GLOBALS_IF_NO_MEMBERS, LIMITED_GLOBALS, ALL_GLOBALS + } - static enum LookupMode {NO_GLOBALS, GLOBALS_IF_NO_MEMBERS, LIMITED_GLOBALS, ALL_GLOBALS} - - static LookupData findOverloadedMemberOperator(IType methodLookupType, OverloadableOperator operator, + static LookupData findOverloadedMemberOperator(IType methodLookupType, OverloadableOperator operator, ICPPEvaluation[] args, IASTNode pointOfInstantiation) { LookupData methodData = null; if (methodLookupType instanceof ISemanticProblem) @@ -3885,24 +3882,26 @@ public class CPPSemantics { } return methodData; } - - static LookupData findOverloadedNonmemberOperator(IType methodLookupType, OverloadableOperator operator, - ICPPEvaluation[] args, IASTNode pointOfInstantiation, IScope pointOfDefinition, - LookupData methodData, LookupMode mode, IType type2, ICPPClassType callToObjectOfClassType) { + + static LookupData findOverloadedNonmemberOperator(IType methodLookupType, OverloadableOperator operator, + ICPPEvaluation[] args, IASTNode pointOfInstantiation, IScope pointOfDefinition, LookupData methodData, + LookupMode mode, IType type2, ICPPClassType callToObjectOfClassType) { LookupData funcData = new LookupData(operator.toCharArray(), null, pointOfInstantiation); // Global new and delete operators do not take an argument for the this pointer. switch (operator) { - case DELETE: case DELETE_ARRAY: - case NEW: case NEW_ARRAY: - args= ArrayUtil.removeFirst(args); + case DELETE: + case DELETE_ARRAY: + case NEW: + case NEW_ARRAY: + args = ArrayUtil.removeFirst(args); break; default: break; } funcData.setFunctionArguments(true, args); funcData.ignoreMembers = true; // (13.3.1.2.3) - boolean haveMembers= methodData != null && methodData.hasResults(); + boolean haveMembers = methodData != null && methodData.hasResults(); if (mode == LookupMode.ALL_GLOBALS || mode == LookupMode.LIMITED_GLOBALS || (mode == LookupMode.GLOBALS_IF_NO_MEMBERS && !haveMembers)) { try { @@ -3927,21 +3926,21 @@ public class CPPSemantics { } // Filter with file-set - IASTTranslationUnit tu= pointOfInstantiation.getTranslationUnit(); + IASTTranslationUnit tu = pointOfInstantiation.getTranslationUnit(); if (tu != null && funcData.foundItems instanceof Object[]) { final IIndexFileSet fileSet = tu.getIndexFileSet(); if (fileSet != null) { - int j= 0; - final Object[] items= (Object[]) funcData.foundItems; + int j = 0; + final Object[] items = (Object[]) funcData.foundItems; for (int i = 0; i < items.length; i++) { Object item = items[i]; - items[i]= null; + items[i] = null; if (item instanceof IIndexBinding) { if (!indexBindingIsReachable(fileSet, (IIndexBinding) item)) { continue; } } - items[j++]= item; + items[j++] = item; } } } @@ -3952,48 +3951,51 @@ public class CPPSemantics { if (operator == OverloadableOperator.NEW || operator == OverloadableOperator.DELETE || operator == OverloadableOperator.NEW_ARRAY || operator == OverloadableOperator.DELETE_ARRAY) { // Those operators replace the built-in operator - Object[] items= (Object[]) funcData.foundItems; - int j= 0; + Object[] items = (Object[]) funcData.foundItems; + int j = 0; for (Object object : items) { if (object instanceof ICPPFunction) { - ICPPFunction func= (ICPPFunction) object; + ICPPFunction func = (ICPPFunction) object; if (!(func instanceof CPPImplicitFunction)) - items[j++]= func; + items[j++] = func; } } if (j > 0) { while (j < items.length) { - items[j++]= null; + items[j++] = null; } } } // 13.3.1.2.3 // However, if no operand type has class type, only those non-member functions ... if (mode == LookupMode.LIMITED_GLOBALS) { - if (funcData.foundItems != null && !(methodLookupType instanceof ICPPClassType) && !(type2 instanceof ICPPClassType)) { - IEnumeration enum1= null; - IEnumeration enum2= null; + if (funcData.foundItems != null && !(methodLookupType instanceof ICPPClassType) + && !(type2 instanceof ICPPClassType)) { + IEnumeration enum1 = null; + IEnumeration enum2 = null; if (methodLookupType instanceof IEnumeration) { - enum1= (IEnumeration) methodLookupType; + enum1 = (IEnumeration) methodLookupType; } if (type2 instanceof IEnumeration) { - enum2= (IEnumeration) type2; + enum2 = (IEnumeration) type2; } - Object[] items= (Object[]) funcData.foundItems; - int j= 0; + Object[] items = (Object[]) funcData.foundItems; + int j = 0; for (Object object : items) { if (object instanceof ICPPFunction) { - ICPPFunction func= (ICPPFunction) object; + ICPPFunction func = (ICPPFunction) object; ICPPFunctionType ft = func.getType(); - IType[] pts= ft.getParameterTypes(); - if ((enum1 != null && pts.length > 0 && enum1.isSameType(getUltimateTypeUptoPointers(pts[0]))) || - (enum2 != null && pts.length > 1 && enum2.isSameType(getUltimateTypeUptoPointers(pts[1])))) { - items[j++]= object; + IType[] pts = ft.getParameterTypes(); + if ((enum1 != null && pts.length > 0 + && enum1.isSameType(getUltimateTypeUptoPointers(pts[0]))) + || (enum2 != null && pts.length > 1 + && enum2.isSameType(getUltimateTypeUptoPointers(pts[1])))) { + items[j++] = object; } } } while (j < items.length) { - items[j++]= null; + items[j++] = null; } } } @@ -4006,14 +4008,16 @@ public class CPPSemantics { for (ICPPMethod op : ops) { if (op.isExplicit()) continue; - IFunctionType ft= op.getType(); + IFunctionType ft = op.getType(); if (ft != null) { - IType rt= SemanticUtil.getNestedType(ft.getReturnType(), SemanticUtil.TDEF); + IType rt = SemanticUtil.getNestedType(ft.getReturnType(), SemanticUtil.TDEF); if (rt instanceof IPointerType) { - IType ptt= SemanticUtil.getNestedType(((IPointerType) rt).getType(), SemanticUtil.TDEF); + IType ptt = SemanticUtil.getNestedType(((IPointerType) rt).getType(), SemanticUtil.TDEF); if (ptt instanceof IFunctionType) { - IFunctionType ft2= (IFunctionType) ptt; - IBinding sf= createSurrogateCallFunction(pointOfInstantiation.getTranslationUnit().getScope(), ft2.getReturnType(), rt, ft2.getParameterTypes()); + IFunctionType ft2 = (IFunctionType) ptt; + IBinding sf = createSurrogateCallFunction( + pointOfInstantiation.getTranslationUnit().getScope(), ft2.getReturnType(), rt, + ft2.getParameterTypes()); mergeResults(funcData, sf, false); } } @@ -4025,37 +4029,36 @@ public class CPPSemantics { } if (methodLookupType instanceof ICPPClassType || type2 instanceof ICPPClassType) { - ICPPFunction[] builtins= BuiltinOperators.create(operator, args, (Object[]) funcData.foundItems); + ICPPFunction[] builtins = BuiltinOperators.create(operator, args, (Object[]) funcData.foundItems); mergeResults(funcData, builtins, false); } - + return funcData; } - - static ICPPFunction findOverloadedOperator(IScope pointOfDefinition, ICPPEvaluation[] args, - IType methodLookupType, OverloadableOperator operator, LookupMode mode) { + + static ICPPFunction findOverloadedOperator(IScope pointOfDefinition, ICPPEvaluation[] args, IType methodLookupType, + OverloadableOperator operator, LookupMode mode) { IASTNode pointOfInstantiation = CPPSemantics.getCurrentLookupPoint(); while (pointOfInstantiation instanceof IASTName) { - pointOfInstantiation= pointOfInstantiation.getParent(); + pointOfInstantiation = pointOfInstantiation.getParent(); } - ICPPClassType callToObjectOfClassType= null; - IType type2= null; + ICPPClassType callToObjectOfClassType = null; + IType type2 = null; if (args.length >= 2) { type2 = args[1].getType(); - type2= getNestedType(type2, TDEF | REF | CVTYPE); + type2 = getNestedType(type2, TDEF | REF | CVTYPE); } // Find a method - LookupData methodData = findOverloadedMemberOperator(methodLookupType, operator, args, - pointOfInstantiation); + LookupData methodData = findOverloadedMemberOperator(methodLookupType, operator, args, pointOfInstantiation); if (methodData != null && operator == OverloadableOperator.PAREN) { callToObjectOfClassType = (ICPPClassType) methodLookupType; } // Find a function - LookupData funcData = findOverloadedNonmemberOperator(methodLookupType, operator, args, - pointOfInstantiation, pointOfDefinition, methodData, mode, type2, callToObjectOfClassType); + LookupData funcData = findOverloadedNonmemberOperator(methodLookupType, operator, args, pointOfInstantiation, + pointOfDefinition, methodData, mode, type2, callToObjectOfClassType); try { IBinding binding = null; @@ -4084,30 +4087,30 @@ public class CPPSemantics { // Specializations of friend functions are sometimes created in the context // of the file for which the AST is created, and which is thus not in the index - // file set. In some cases, an AST binding cannot be created for such + // file set. In some cases, an AST binding cannot be created for such // specializations. To support these cases, consider the binding reachable if // the friend function being specialized is reachable. // This situation only arises in the presence of #includes that are not at // global scope. Once bug 315964 is fixed, this workaround can be removed. if (item instanceof ICPPFunctionSpecialization && !(item instanceof ICPPFunctionInstance)) { IBinding specialized = ((ICPPFunctionSpecialization) item).getSpecializedBinding(); - return !(specialized instanceof IIndexBinding) - || fileSet.containsDeclaration((IIndexBinding) specialized); + return !(specialized instanceof IIndexBinding) || fileSet.containsDeclaration((IIndexBinding) specialized); } - + return false; } - private static IBinding createSurrogateCallFunction(IScope scope, IType returnType, IType rt, IType[] parameterTypes) { + private static IBinding createSurrogateCallFunction(IScope scope, IType returnType, IType rt, + IType[] parameterTypes) { IType[] parms = new IType[parameterTypes.length + 1]; ICPPParameter[] theParms = new ICPPParameter[parms.length]; parms[0] = rt; - theParms[0]= new CPPBuiltinParameter(rt); + theParms[0] = new CPPBuiltinParameter(rt); for (int i = 1; i < parms.length; i++) { IType t = parameterTypes[i - 1]; - parms[i]= t; - theParms[i]= new CPPBuiltinParameter(t); + parms[i] = t; + theParms[i] = new CPPBuiltinParameter(t); } ICPPFunctionType functionType = new CPPFunctionType(returnType, parms); return new CPPImplicitFunction(CALL_FUNCTION, scope, functionType, theParms, false, false); @@ -4136,10 +4139,10 @@ public class CPPSemantics { public static IBinding[] findBindings(IScope scope, char[] name, boolean qualified, IASTNode beforeNode) { LookupData data; if (beforeNode == null) { - data= new LookupData(name, null, ASTInternal.getPhysicalNodeOfScope(scope)); + data = new LookupData(name, null, ASTInternal.getPhysicalNodeOfScope(scope)); data.setIgnorePointOfDeclaration(true); } else { - data= new LookupData(name, null, beforeNode); + data = new LookupData(name, null, beforeNode); data.setIgnorePointOfDeclaration(false); } data.qualified = qualified; @@ -4155,13 +4158,13 @@ public class CPPSemantics { data.foundItems = new CharArrayObjectMap<>(2); // Convert namespaces to scopes. - List<ICPPScope> nsScopes= new ArrayList<>(); + List<ICPPScope> nsScopes = new ArrayList<>(); IASTTranslationUnit tu = name.getTranslationUnit(); if (additionalNamespaces != null && tu instanceof CPPASTTranslationUnit) { for (String nsName : additionalNamespaces) { - nsName= nsName.trim(); + nsName = nsName.trim(); if (nsName.startsWith("::")) { //$NON-NLS-1$ - nsName= nsName.substring(2); + nsName = nsName.substring(2); } String[] namespaceParts = nsName.split("::"); //$NON-NLS-1$ try { @@ -4176,15 +4179,15 @@ public class CPPSemantics { } return contentAssistLookup(data, nsScopes); } - + /** * Similar to {@link CPPSemantics#findBindingsForContentAssist(IASTName, boolean, String[])}, * but in lieu of a name hooked up to the AST, accepts just a string, a position in the file * (represented as an IASTNode, and used to serve as the point of reference for the lookup), * and a starting scope (which is required). */ - public static IBinding[] findBindingsForContentAssist(char[] name, boolean prefixLookup, - IScope lookupScope, IASTNode point) { + public static IBinding[] findBindingsForContentAssist(char[] name, boolean prefixLookup, IScope lookupScope, + IASTNode point) { LookupData data = new LookupData(name, null, point); data.contentAssist = true; data.fHeuristicBaseLookup = true; @@ -4196,7 +4199,7 @@ public class CPPSemantics { } return collectContentAssistBindings(data); } - + private static IScope getLookupScope(IASTNode node) { if (node == null) return null; @@ -4280,7 +4283,8 @@ public class CPPSemantics { return bindings.size() == 0 ? IBinding.EMPTY_BINDING_ARRAY : bindings.toArray(new IBinding[bindings.size()]); } - private static void findBindingsForQualifiedName(IScope scope, String qualifiedName, Collection<IBinding> bindings) { + private static void findBindingsForQualifiedName(IScope scope, String qualifiedName, + Collection<IBinding> bindings) { // Split the qualified name into the first part (before the first :: qualifier) and the rest. All // bindings for the first part are found and their scope is used to find the rest of the name. When // the call tree gets to a leaf (non-qualified name) then a simple lookup happens and all matching @@ -4305,16 +4309,16 @@ public class CPPSemantics { } } - private static ICPPScope getNamespaceScope(CPPASTTranslationUnit tu, String[] namespaceParts, - IASTNode point) throws DOMException { - ICPPScope nsScope= tu.getScope(); + private static ICPPScope getNamespaceScope(CPPASTTranslationUnit tu, String[] namespaceParts, IASTNode point) + throws DOMException { + ICPPScope nsScope = tu.getScope(); outer: for (String nsPart : namespaceParts) { - nsPart= nsPart.trim(); + nsPart = nsPart.trim(); if (nsPart.length() != 0) { IBinding[] nsBindings = nsScope.getBindings(new ScopeLookupData(nsPart.toCharArray(), point)); for (IBinding nsBinding : nsBindings) { if (nsBinding instanceof ICPPNamespace) { - nsScope= ((ICPPNamespace) nsBinding).getNamespaceScope(); + nsScope = ((ICPPNamespace) nsBinding).getNamespaceScope(); continue outer; } } @@ -4347,7 +4351,7 @@ public class CPPSemantics { } return collectContentAssistBindings(data); } - + private static IBinding[] collectContentAssistBindings(LookupData data) { @SuppressWarnings("unchecked") CharArrayObjectMap<Object> map = (CharArrayObjectMap<Object>) data.foundItems; @@ -4365,8 +4369,8 @@ public class CPPSemantics { public static IBinding[] addContentAssistBinding(IBinding[] result, Object obj) { if (obj instanceof Object[]) { - for (Object o : (Object[]) obj) { - result= addContentAssistBinding(result, o); + for (Object o : (Object[]) obj) { + result = addContentAssistBinding(result, o); } return result; } @@ -4451,7 +4455,7 @@ public class CPPSemantics { return false; } - declarator= ASTQueries.findTypeRelevantDeclarator(declarator); + declarator = ASTQueries.findTypeRelevantDeclarator(declarator); if (declarator instanceof ICPPASTFunctionDeclarator) { // For declaration matching, compare the declared types (placeholders not resolved). IType type = function.getDeclaredType(); @@ -4460,8 +4464,7 @@ public class CPPSemantics { return false; } - private static boolean isSameTemplateParameterList(ICPPTemplateParameter[] tplist, - ICPPASTTemplateParameter[] tps) { + private static boolean isSameTemplateParameterList(ICPPTemplateParameter[] tplist, ICPPASTTemplateParameter[] tps) { if (tplist.length != tps.length) return false; @@ -4478,8 +4481,8 @@ public class CPPSemantics { if (tp1 instanceof ICPPTemplateNonTypeParameter) { if (tp2 instanceof ICPPASTParameterDeclaration) { - IType t1= ((ICPPTemplateNonTypeParameter) tp1).getType(); - IType t2= CPPVisitor.createType((ICPPASTParameterDeclaration) tp2, true); + IType t1 = ((ICPPTemplateNonTypeParameter) tp1).getType(); + IType t2 = CPPVisitor.createType((ICPPASTParameterDeclaration) tp2, true); return t1 != null && t1.isSameType(t2); } return false; @@ -4507,8 +4510,8 @@ public class CPPSemantics { IASTNode point = CPPSemantics.getCurrentLookupPoint(); LookupData data = new LookupData(unknownName, null, point); data.setIgnorePointOfDeclaration(true); - data.typesOnly= unknown instanceof IType; - data.qualified= true; + data.typesOnly = unknown instanceof IType; + data.qualified = true; try { // 2: Lookup @@ -4533,7 +4536,7 @@ public class CPPSemantics { return binding; } - + public static void enablePromiscuousBindingResolution() { fAllowPromiscuousBindingResolution.set(true); } @@ -4541,7 +4544,7 @@ public class CPPSemantics { public static void disablePromiscuousBindingResolution() { fAllowPromiscuousBindingResolution.set(false); } - + public static boolean isUsingPromiscuousBindingResolution() { return fAllowPromiscuousBindingResolution.get(); } @@ -4551,7 +4554,7 @@ public class CPPSemantics { * This is similar to CPPVisitor.getDeclType(IASTExpression), but used in cases where the * original expression was dependent, so we had to represent it as an evaluation and * instantiate it. - * + * * @param eval the (instantiated) evaluation representing the expression */ public static IType getDeclTypeForEvaluation(ICPPEvaluation eval) { @@ -4569,7 +4572,7 @@ public class CPPSemantics { } return expressionType; } - + /** * This method performs type deduction for auto, decltype or typeof * declarations. This is used by {@code CSourceHover} and @@ -4600,8 +4603,7 @@ public class CPPSemantics { // first declarator. if (declarators.length > 0) declarator = declarators[0]; - } else if (parent instanceof IASTParameterDeclaration - && builtin != ICPPASTSimpleDeclSpecifier.t_auto) { + } else if (parent instanceof IASTParameterDeclaration && builtin != ICPPASTSimpleDeclSpecifier.t_auto) { declarator = ((IASTParameterDeclaration) parent).getDeclarator(); } else if (parent instanceof ICPPASTTypeId && builtin != ICPPASTSimpleDeclSpecifier.t_auto) { declarator = ((ICPPASTTypeId) parent).getAbstractDeclarator(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 265ef3f0b0b..9df7a849964 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -228,11 +228,13 @@ public class CPPTemplates { // Used to indicate that two different packs with different sizes were found. static final int PACK_SIZE_FAIL = -2; - + // Used to indicate that no template parameter packs were found. static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; - static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE } + static enum TypeSelection { + PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE + } // Infrastructure to protect against rogue template metaprograms that don't terminate. private static final int TEMPLATE_INSTANTIATION_DEPTH_LIMIT = 128; @@ -242,8 +244,7 @@ public class CPPTemplates { return 0; } }; - private static final ThreadLocal<Set<TypeInstantiationRequest>> instantiationsInProgress = - new ThreadLocal<Set<TypeInstantiationRequest>>() { + private static final ThreadLocal<Set<TypeInstantiationRequest>> instantiationsInProgress = new ThreadLocal<Set<TypeInstantiationRequest>>() { @Override protected Set<TypeInstantiationRequest> initialValue() { return new HashSet<>(); @@ -263,9 +264,9 @@ public class CPPTemplates { private static IBinding instantiate(ICPPPartiallySpecializable template, ICPPTemplateArgument[] args, boolean isDefinition, boolean isExplicitSpecialization) { try { - ICPPTemplateArgument[] arguments= SemanticUtil.getSimplifiedArguments(args); + ICPPTemplateArgument[] arguments = SemanticUtil.getSimplifiedArguments(args); // Add default arguments, if necessary. - arguments= addDefaultArguments(template, arguments); + arguments = addDefaultArguments(template, arguments); if (arguments == null) return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); @@ -274,30 +275,29 @@ public class CPPTemplates { } if (template instanceof ICPPClassTemplatePartialSpecialization) { - return instantiatePartialSpecialization((ICPPClassTemplatePartialSpecialization) template, - arguments, isDefinition, null); + return instantiatePartialSpecialization((ICPPClassTemplatePartialSpecialization) template, arguments, + isDefinition, null); } if (arguments == args) { - arguments= args.clone(); // The createParameterMap call may modify the arguments array. + arguments = args.clone(); // The createParameterMap call may modify the arguments array. } CPPTemplateParameterMap map = createParameterMap(template, arguments); if (map == null) { return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); } - ICPPTemplateInstance prim= getInstance(template, arguments, isDefinition); + ICPPTemplateInstance prim = getInstance(template, arguments, isDefinition); if (prim != null && (isExplicitSpecialization || prim.isExplicitSpecialization())) return prim; if (!isExplicitSpecialization) { - IBinding result= selectSpecialization(template, arguments, isDefinition); + IBinding result = selectSpecialization(template, arguments, isDefinition); if (result != null) return result; } - return instantiatePrimaryTemplate(template, arguments, new InstantiationContext(map), - isDefinition); + return instantiatePrimaryTemplate(template, arguments, new InstantiationContext(map), isDefinition); } catch (DOMException e) { return e.getProblem(); } @@ -306,8 +306,7 @@ public class CPPTemplates { /** * Instantiates an alias template with the given arguments. */ - public static IBinding instantiateAliasTemplate(ICPPAliasTemplate aliasTemplate, - ICPPTemplateArgument[] args) { + public static IBinding instantiateAliasTemplate(ICPPAliasTemplate aliasTemplate, ICPPTemplateArgument[] args) { try { args = addDefaultArguments(aliasTemplate, args); if (args == null) { @@ -331,13 +330,15 @@ public class CPPTemplates { static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) { try { - IScope scope= null; - IASTNode node= name; + IScope scope = null; + IASTNode node = name; while (node != null) { if (node.getPropertyInParent() == IASTCompositeTypeSpecifier.TYPE_NAME) return null; if (node instanceof IASTFunctionDefinition) { - IASTName functionName= ASTQueries.findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()).getName().getLastName(); + IASTName functionName = ASTQueries + .findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()).getName() + .getLastName(); // 'name' may be inside the qualifier of a method name in a out-of-line method definition. // In such a case, calling getContainingScope() on the method name will attempt to // resolve the qualifier, which will attempt to resolve 'name', which will get into @@ -348,48 +349,50 @@ public class CPPTemplates { && ASTQueries.isAncestorOf(functionName.getParent(), name)) { return null; } - scope= CPPVisitor.getContainingScope(functionName); + scope = CPPVisitor.getContainingScope(functionName); break; } if (node instanceof ICPPASTCompositeTypeSpecifier) { - scope= ((ICPPASTCompositeTypeSpecifier) node).getScope(); + scope = ((ICPPASTCompositeTypeSpecifier) node).getScope(); break; } - node= node.getParent(); + node = node.getParent(); } while (scope != null) { if (scope instanceof ISemanticProblem) return null; if (scope instanceof ICPPClassScope) { - ICPPClassType b= ((ICPPClassScope) scope).getClassType(); + ICPPClassType b = ((ICPPClassScope) scope).getClassType(); if (b != null && ct.isSameType(b)) { return ct; } if (b instanceof ICPPClassTemplatePartialSpecialization) { - ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b; + ICPPClassTemplatePartialSpecialization pspec = (ICPPClassTemplatePartialSpecialization) b; if (ct.isSameType(pspec.getPrimaryClassTemplate())) { return pspec; } } else if (b instanceof ICPPClassSpecialization) { - ICPPClassSpecialization specialization= (ICPPClassSpecialization) b; + ICPPClassSpecialization specialization = (ICPPClassSpecialization) b; if (ct.isSameType(specialization.getSpecializedBinding())) { - return specialization; } + return specialization; + } } } if (scope instanceof IASTInternalScope) { - IASTInternalScope internalScope= (IASTInternalScope) scope; + IASTInternalScope internalScope = (IASTInternalScope) scope; IASTNode physicalNode = internalScope.getPhysicalNode(); - if (physicalNode instanceof ICPPASTCompositeTypeSpecifier && - ((ICPPASTCompositeTypeSpecifier) physicalNode).getName() instanceof ICPPASTQualifiedName) { - scope= scope.getParent(); + if (physicalNode instanceof ICPPASTCompositeTypeSpecifier + && ((ICPPASTCompositeTypeSpecifier) physicalNode) + .getName() instanceof ICPPASTQualifiedName) { + scope = scope.getParent(); } else { - scope= CPPVisitor.getContainingScope(physicalNode); + scope = CPPVisitor.getContainingScope(physicalNode); if (scope == internalScope) return null; } } else { - scope= scope.getParent(); + scope = scope.getParent(); } } } catch (DOMException e) { @@ -397,15 +400,14 @@ public class CPPTemplates { return null; } - private static IBinding instantiateFunctionTemplate(ICPPFunctionTemplate template, - ICPPTemplateArgument[] arguments, CPPTemplateParameterMap tpMap) - throws DOMException { - ICPPTemplateInstance instance= getInstance(template, arguments, false); + private static IBinding instantiateFunctionTemplate(ICPPFunctionTemplate template, ICPPTemplateArgument[] arguments, + CPPTemplateParameterMap tpMap) throws DOMException { + ICPPTemplateInstance instance = getInstance(template, arguments, false); if (instance != null) { return instance; } - IBinding owner= template.getOwner(); + IBinding owner = template.getOwner(); instance = createInstance(owner, template, tpMap, arguments); if (instance instanceof ICPPFunction && SemanticUtil.isValidType(((ICPPFunction) instance).getType())) { addInstance(template, arguments, instance); @@ -417,9 +419,8 @@ public class CPPTemplates { * Instantiates a partial class template specialization. */ private static IBinding instantiatePartialSpecialization(ICPPPartialSpecialization partialSpec, - ICPPTemplateArgument[] args, boolean isDef, CPPTemplateParameterMap tpMap) - throws DOMException { - ICPPTemplateInstance instance= getInstance(partialSpec, args, isDef); + ICPPTemplateArgument[] args, boolean isDef, CPPTemplateParameterMap tpMap) throws DOMException { + ICPPTemplateInstance instance = getInstance(partialSpec, args, isDef); if (instance != null) return instance; @@ -431,7 +432,7 @@ public class CPPTemplates { } } - instance= createInstance(partialSpec.getOwner(), partialSpec, tpMap, args); + instance = createInstance(partialSpec.getOwner(), partialSpec, tpMap, args); addInstance(partialSpec, args, instance); return instance; } @@ -441,14 +442,14 @@ public class CPPTemplates { * May return {@code null}. */ private static IBinding instantiatePrimaryTemplate(ICPPPartiallySpecializable template, - ICPPTemplateArgument[] arguments, InstantiationContext context, boolean isDef) throws DOMException { + ICPPTemplateArgument[] arguments, InstantiationContext context, boolean isDef) throws DOMException { assert !(template instanceof ICPPClassTemplatePartialSpecialization); - ICPPTemplateInstance instance= getInstance(template, arguments, isDef); + ICPPTemplateInstance instance = getInstance(template, arguments, isDef); if (instance != null) { return instance; } - IBinding owner= template.getOwner(); + IBinding owner = template.getOwner(); instance = createInstance(owner, template, context.getParameterMap(), arguments); addInstance(template, arguments, instance); return instance; @@ -457,8 +458,8 @@ public class CPPTemplates { /** * Obtains a cached instance from the template. */ - private static ICPPTemplateInstance getInstance(ICPPTemplateDefinition template, - ICPPTemplateArgument[] args, boolean forDefinition) { + private static ICPPTemplateInstance getInstance(ICPPTemplateDefinition template, ICPPTemplateArgument[] args, + boolean forDefinition) { if (template instanceof ICPPInstanceCache) { ICPPTemplateInstance result = ((ICPPInstanceCache) template).getInstance(args); if (forDefinition && result instanceof IIndexBinding) @@ -468,8 +469,8 @@ public class CPPTemplates { // argument is an AST type. Despite identical signatures the types may be different. ICPPTemplateArgument[] instanceArgs = result.getTemplateArguments(); for (int i = 0; i < args.length; i++) { - if (!(args[i].getTypeValue() instanceof IIndexType) && - (instanceArgs[i].getTypeValue() instanceof IIndexType)) { + if (!(args[i].getTypeValue() instanceof IIndexType) + && (instanceArgs[i].getTypeValue() instanceof IIndexType)) { return null; } } @@ -482,15 +483,16 @@ public class CPPTemplates { /** * Caches an instance with the template. */ - private static void addInstance(ICPPTemplateDefinition template, ICPPTemplateArgument[] args, ICPPTemplateInstance instance) { + private static void addInstance(ICPPTemplateDefinition template, ICPPTemplateArgument[] args, + ICPPTemplateInstance instance) { if (template instanceof ICPPInstanceCache) { ((ICPPInstanceCache) template).addInstance(args, instance); } } - private static IBinding deferredInstance(ICPPPartiallySpecializable template, - ICPPTemplateArgument[] arguments) throws DOMException { - ICPPTemplateInstance instance= getInstance(template, arguments, false); + private static IBinding deferredInstance(ICPPPartiallySpecializable template, ICPPTemplateArgument[] arguments) + throws DOMException { + ICPPTemplateInstance instance = getInstance(template, arguments, false); if (instance != null) return instance; @@ -510,14 +512,14 @@ public class CPPTemplates { if (template instanceof ICPPClassTemplatePartialSpecialization) return arguments; - boolean havePackExpansion= false; + boolean havePackExpansion = false; for (int i = 0; i < arguments.length; i++) { ICPPTemplateArgument arg = arguments[i]; if (arg.isPackExpansion()) { if (i != arguments.length - 1) { return arguments; } - havePackExpansion= true; + havePackExpansion = true; } } @@ -552,8 +554,8 @@ public class CPPTemplates { if (tparCount == argCount) return arguments; - ICPPTemplateArgument[] completeArgs= new ICPPTemplateArgument[tparCount]; - CPPTemplateParameterMap map= new CPPTemplateParameterMap(tparCount); + ICPPTemplateArgument[] completeArgs = new ICPPTemplateArgument[tparCount]; + CPPTemplateParameterMap map = new CPPTemplateParameterMap(tparCount); InstantiationContext context = new InstantiationContext(map); for (int i = 0; i < tparCount; i++) { final ICPPTemplateParameter tpar = tpars[i]; @@ -563,24 +565,24 @@ public class CPPTemplates { } ICPPTemplateArgument arg; if (i < argCount) { - arg= arguments[i]; + arg = arguments[i]; } else { - ICPPTemplateArgument defaultArg= tpar.getDefaultValue(); + ICPPTemplateArgument defaultArg = tpar.getDefaultValue(); if (defaultArg == null) { if (template instanceof ICPPInternalClassTemplate) { - defaultArg= ((ICPPInternalClassTemplate) template).getDefaultArgFromIndex(i); + defaultArg = ((ICPPInternalClassTemplate) template).getDefaultArgFromIndex(i); } } if (defaultArg == null) return null; - arg= instantiateArgument(defaultArg, context); - arg= SemanticUtil.getSimplifiedArgument(arg); + arg = instantiateArgument(defaultArg, context); + arg = SemanticUtil.getSimplifiedArgument(arg); if (!isValidArgument(arg)) { return null; } } context.addToParameterMap(tpar, arg); - completeArgs[i]= arg; + completeArgs[i] = arg; } return completeArgs; } @@ -588,7 +590,7 @@ public class CPPTemplates { public static ICPPDeferredClassInstance createDeferredInstance(ICPPClassTemplate ct) { ICPPTemplateArgument[] args; if (ct instanceof ICPPClassTemplatePartialSpecialization) { - args= ((ICPPClassTemplatePartialSpecialization) ct).getTemplateArguments(); + args = ((ICPPClassTemplatePartialSpecialization) ct).getTemplateArguments(); } else { args = templateParametersAsArguments(ct); } @@ -602,9 +604,9 @@ public class CPPTemplates { for (int i = 0; i < tpars.length; i++) { final ICPPTemplateParameter tp = tpars[i]; if (tp instanceof IType) { - IType t= (IType) tp; + IType t = (IType) tp; if (tp.isParameterPack()) { - t= new CPPParameterPackType(t); + t = new CPPParameterPackType(t); } args[i] = new CPPTemplateTypeArgument(t); } else if (tp instanceof ICPPTemplateNonTypeParameter) { @@ -635,11 +637,13 @@ public class CPPTemplates { IASTNode parent = param.getParent(); IBinding binding = null; if (parent instanceof ICPPASTTemplateDeclaration) { - ICPPASTTemplateDeclaration[] templates = new ICPPASTTemplateDeclaration[] { (ICPPASTTemplateDeclaration) parent }; + ICPPASTTemplateDeclaration[] templates = new ICPPASTTemplateDeclaration[] { + (ICPPASTTemplateDeclaration) parent }; while (parent.getParent() instanceof ICPPASTTemplateDeclaration) { parent = parent.getParent(); - templates = ArrayUtil.append(ICPPASTTemplateDeclaration.class, templates, (ICPPASTTemplateDeclaration) parent); + templates = ArrayUtil.append(ICPPASTTemplateDeclaration.class, templates, + (ICPPASTTemplateDeclaration) parent); } templates = ArrayUtil.trim(ICPPASTTemplateDeclaration.class, templates); @@ -662,12 +666,12 @@ public class CPPTemplates { } } else { IASTDeclarator dtor = dtors[0]; - dtor= ASTQueries.findInnermostDeclarator(dtor); + dtor = ASTQueries.findInnermostDeclarator(dtor); name = dtor.getName(); } } else if (decl instanceof IASTFunctionDefinition) { IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator(); - dtor= ASTQueries.findInnermostDeclarator(dtor); + dtor = ASTQueries.findInnermostDeclarator(dtor); name = dtor.getName(); } else if (decl instanceof ICPPASTAliasDeclaration) { name = ((ICPPASTAliasDeclaration) decl).getAlias(); @@ -702,10 +706,12 @@ public class CPPTemplates { public static IBinding createBinding(ICPPASTTemplateParameter tp) { if (tp instanceof ICPPASTSimpleTypeTemplateParameter) { - return new CPPTemplateTypeParameter(((ICPPASTSimpleTypeTemplateParameter) tp).getName(), tp.isParameterPack()); + return new CPPTemplateTypeParameter(((ICPPASTSimpleTypeTemplateParameter) tp).getName(), + tp.isParameterPack()); } if (tp instanceof ICPPASTTemplatedTypeTemplateParameter) { - return new CPPTemplateTemplateParameter(((ICPPASTTemplatedTypeTemplateParameter) tp).getName(), tp.isParameterPack()); + return new CPPTemplateTemplateParameter(((ICPPASTTemplatedTypeTemplateParameter) tp).getName(), + tp.isParameterPack()); } assert tp instanceof ICPPASTParameterDeclaration; final IASTDeclarator dtor = ((ICPPASTParameterDeclaration) tp).getDeclarator(); @@ -715,7 +721,7 @@ public class CPPTemplates { public static IBinding createBinding(ICPPASTTemplateId id) { if (!isClassTemplate(id)) { // Functions are instantiated as part of the resolution process. - IBinding result= CPPVisitor.createBinding(id); + IBinding result = CPPVisitor.createBinding(id); IASTName templateName = id.getTemplateName(); if (result instanceof ICPPClassTemplate || result instanceof ICPPAliasTemplate || result instanceof ICPPVariableTemplate) { @@ -732,38 +738,38 @@ public class CPPTemplates { } IASTNode parentOfName = id.getParent(); - boolean isLastName= true; + boolean isLastName = true; if (parentOfName instanceof ICPPASTQualifiedName) { - isLastName= ((ICPPASTQualifiedName) parentOfName).getLastName() == id; + isLastName = ((ICPPASTQualifiedName) parentOfName).getLastName() == id; parentOfName = parentOfName.getParent(); } - boolean isDeclaration= false; - boolean isDefinition= false; - boolean isExplicitSpecialization= false; + boolean isDeclaration = false; + boolean isDefinition = false; + boolean isExplicitSpecialization = false; if (isLastName && parentOfName != null) { - IASTNode declaration= parentOfName.getParent(); + IASTNode declaration = parentOfName.getParent(); if (declaration instanceof IASTSimpleDeclaration) { if (parentOfName instanceof ICPPASTElaboratedTypeSpecifier) { - isDeclaration= true; + isDeclaration = true; } else if (parentOfName instanceof ICPPASTCompositeTypeSpecifier) { - isDefinition= true; + isDefinition = true; } else if (parentOfName instanceof ICPPASTDeclarator) { - isDeclaration= true; + isDeclaration = true; } if (isDeclaration || isDefinition) { IASTNode parentOfDeclaration = declaration.getParent(); if (parentOfDeclaration instanceof ICPPASTExplicitTemplateInstantiation) { - isDeclaration= false; + isDeclaration = false; } else if (parentOfDeclaration instanceof ICPPASTTemplateSpecialization) { - isExplicitSpecialization= true; + isExplicitSpecialization = true; } } } } CPPSemantics.pushLookupPoint(id); try { - IBinding result= null; + IBinding result = null; IASTName templateName = id.getTemplateName(); IBinding template = templateName.resolvePreBinding(); @@ -780,35 +786,37 @@ public class CPPTemplates { // Class or variable template. if (template instanceof ICPPConstructor) { - template= template.getOwner(); + template = template.getOwner(); } if (template instanceof ICPPUnknownMemberClass) { - IType owner= ((ICPPUnknownMemberClass) template).getOwnerType(); - ICPPTemplateArgument[] args= createTemplateArgumentArray(id); - args= SemanticUtil.getSimplifiedArguments(args); + IType owner = ((ICPPUnknownMemberClass) template).getOwnerType(); + ICPPTemplateArgument[] args = createTemplateArgumentArray(id); + args = SemanticUtil.getSimplifiedArguments(args); return new CPPUnknownClassInstance(owner, id.getSimpleID(), args); } - if (!(template instanceof ICPPPartiallySpecializable) || template instanceof ICPPClassTemplatePartialSpecialization) + if (!(template instanceof ICPPPartiallySpecializable) + || template instanceof ICPPClassTemplatePartialSpecialization) return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, templateName.toCharArray()); final ICPPPartiallySpecializable classTemplate = (ICPPPartiallySpecializable) template; - ICPPTemplateArgument[] args= createTemplateArgumentArray(id); + ICPPTemplateArgument[] args = createTemplateArgumentArray(id); if (hasDependentArgument(args)) { - ICPPASTTemplateDeclaration tdecl= getTemplateDeclaration(id); + ICPPASTTemplateDeclaration tdecl = getTemplateDeclaration(id); if (tdecl != null) { if (argsAreTrivial(classTemplate.getTemplateParameters(), args)) { - result= classTemplate; + result = classTemplate; } else { - args= addDefaultArguments(classTemplate, args); + args = addDefaultArguments(classTemplate, args); if (args == null) { - return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, templateName.toCharArray()); + return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, + templateName.toCharArray()); } - ICPPPartialSpecialization partialSpec= findPartialSpecialization(classTemplate, args); + ICPPPartialSpecialization partialSpec = findPartialSpecialization(classTemplate, args); ICPPClassTemplatePartialSpecialization indexSpec = null; - if ((isDeclaration || isDefinition) && - (partialSpec instanceof ICPPClassTemplatePartialSpecialization)) { + if ((isDeclaration || isDefinition) + && (partialSpec instanceof ICPPClassTemplatePartialSpecialization)) { indexSpec = (ICPPClassTemplatePartialSpecialization) partialSpec; partialSpec = null; } @@ -834,14 +842,15 @@ public class CPPTemplates { } return partialSpec; } - return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, templateName.toCharArray()); + return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, + templateName.toCharArray()); } - result= partialSpec; + result = partialSpec; } } } if (result == null) { - result= instantiate(classTemplate, args, isDefinition, isExplicitSpecialization); + result = instantiate(classTemplate, args, isDefinition, isExplicitSpecialization); if (result instanceof ICPPInternalBinding) { if (isDeclaration) { ASTInternal.addDeclaration(result, id); @@ -858,9 +867,8 @@ public class CPPTemplates { } } - private static IBinding createAliasTemplaceInstance(ICPPAliasTemplate aliasTemplate, - ICPPTemplateArgument[] args, ICPPTemplateParameterMap parameterMap, IType aliasedType, - IBinding owner) { + private static IBinding createAliasTemplaceInstance(ICPPAliasTemplate aliasTemplate, ICPPTemplateArgument[] args, + ICPPTemplateParameterMap parameterMap, IType aliasedType, IBinding owner) { InstantiationContext context = createInstantiationContext(parameterMap, owner); IType instantiatedType = instantiateType(aliasedType, context); return new CPPAliasTemplateInstance(aliasTemplate, instantiatedType, owner, parameterMap, args); @@ -872,27 +880,26 @@ public class CPPTemplates { if (parentOfName instanceof ICPPASTQualifiedName) { if (((ICPPASTQualifiedName) parentOfName).getLastName() != id) return true; - parentOfName= parentOfName.getParent(); + parentOfName = parentOfName.getParent(); } - if (parentOfName instanceof ICPPASTElaboratedTypeSpecifier || - parentOfName instanceof ICPPASTCompositeTypeSpecifier || - parentOfName instanceof ICPPASTNamedTypeSpecifier || - parentOfName instanceof ICPPASTBaseSpecifier) { + if (parentOfName instanceof ICPPASTElaboratedTypeSpecifier + || parentOfName instanceof ICPPASTCompositeTypeSpecifier + || parentOfName instanceof ICPPASTNamedTypeSpecifier || parentOfName instanceof ICPPASTBaseSpecifier) { return true; } if (parentOfName instanceof IASTDeclarator) { - IASTDeclarator rel= ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) parentOfName); + IASTDeclarator rel = ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) parentOfName); return !(rel instanceof IASTFunctionDeclarator); } return false; } public static ICPPTemplateInstance createInstance(IBinding owner, ICPPTemplateDefinition template, - ICPPTemplateParameterMap tpMap, ICPPTemplateArgument[] args) { + ICPPTemplateParameterMap tpMap, ICPPTemplateArgument[] args) { if (owner instanceof ICPPSpecialization) { - ICPPTemplateParameterMap map= ((ICPPSpecialization) owner).getTemplateParameterMap(); + ICPPTemplateParameterMap map = ((ICPPSpecialization) owner).getTemplateParameterMap(); if (map != null) { ((CPPTemplateParameterMap) tpMap).putAll(map); } @@ -902,10 +909,10 @@ public class CPPTemplates { if (template instanceof ICPPClassType) { instance = new CPPClassInstance((ICPPClassType) template, owner, tpMap, args); } else if (template instanceof ICPPFunction) { - ICPPFunction func= (ICPPFunction) template; + ICPPFunction func = (ICPPFunction) template; InstantiationContext context = createInstantiationContext(tpMap, owner); - ICPPFunctionType type= (ICPPFunctionType) instantiateType(func.getType(), context); - IType[] exceptionSpecs= instantiateTypes(func.getExceptionSpecification(), context); + ICPPFunctionType type = (ICPPFunctionType) instantiateType(func.getType(), context); + IType[] exceptionSpecs = instantiateTypes(func.getExceptionSpecification(), context); CPPFunctionSpecialization spec; if (owner instanceof ICPPClassType && template instanceof ICPPMethod) { if (template instanceof ICPPConstructor) { @@ -916,9 +923,10 @@ public class CPPTemplates { context.getParameterMap(), args, type, exceptionSpecs); } } else { - spec = new CPPFunctionInstance((ICPPFunction) template, owner, tpMap, args, type, exceptionSpecs); + spec = new CPPFunctionInstance((ICPPFunction) template, owner, tpMap, args, type, exceptionSpecs); } - spec.setParameters(specializeParameters(func.getParameters(), spec, context, IntegralValue.MAX_RECURSION_DEPTH)); + spec.setParameters( + specializeParameters(func.getParameters(), spec, context, IntegralValue.MAX_RECURSION_DEPTH)); instance = (ICPPTemplateInstance) spec; } else if (template instanceof ICPPVariable) { ICPPVariable var = (ICPPVariable) template; @@ -987,17 +995,19 @@ public class CPPTemplates { /** * IMPORTANT: Do NOT call this method directly, at least when (owner instanceof ICPPClassSpecialization). * Use ICPPClassSpecialization.specializeMember(decl) instead. - * + * * This ensures that the caching mechanism for member specializations implemented by * ICPPClassSpecialization.specializeMember() is not bypassed. - * + * * TODO: Implement a caching mechanism for non-class owners, too, and make specializeMember() * a method of ICPPSpecialization itself. */ public static IBinding createSpecialization(ICPPSpecialization owner, IBinding decl) { IBinding spec = null; - final ICPPTemplateParameterMap tpMap= owner.getTemplateParameterMap(); - final ICPPClassSpecialization classOwner = (owner instanceof ICPPClassSpecialization) ? (ICPPClassSpecialization) owner : null; + final ICPPTemplateParameterMap tpMap = owner.getTemplateParameterMap(); + final ICPPClassSpecialization classOwner = (owner instanceof ICPPClassSpecialization) + ? (ICPPClassSpecialization) owner + : null; // Guard against infinite recursion during template instantiation with a depth limit. int instantiationDepth = fTemplateInstantiationDepth.get(); @@ -1010,19 +1020,20 @@ public class CPPTemplates { try { if (decl instanceof ICPPClassTemplatePartialSpecialization && classOwner != null) { try { - ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) decl; - ICPPClassTemplate template= pspec.getPrimaryClassTemplate(); + ICPPClassTemplatePartialSpecialization pspec = (ICPPClassTemplatePartialSpecialization) decl; + ICPPClassTemplate template = pspec.getPrimaryClassTemplate(); ICPPTemplateArgument[] args = pspec.getTemplateArguments(); - template= (ICPPClassTemplate) classOwner.specializeMember(template); + template = (ICPPClassTemplate) classOwner.specializeMember(template); InstantiationContext context = createInstantiationContext(tpMap, owner); - args= instantiateArguments(args, context, false); - spec= new CPPClassTemplatePartialSpecializationSpecialization(pspec, tpMap, template, args); + args = instantiateArguments(args, context, false); + spec = new CPPClassTemplatePartialSpecializationSpecialization(pspec, tpMap, template, args); } catch (DOMException e) { } } else if (decl instanceof ICPPClassTemplate && classOwner != null) { ICPPClassTemplate template = (ICPPClassTemplate) decl; - CPPClassTemplateSpecialization classTemplateSpec = new CPPClassTemplateSpecialization(template, classOwner, tpMap); + CPPClassTemplateSpecialization classTemplateSpec = new CPPClassTemplateSpecialization(template, + classOwner, tpMap); classTemplateSpec.setTemplateParameters(specializeTemplateParameters(classTemplateSpec, (ICPPScope) classTemplateSpec.getScope(), template.getTemplateParameters(), classOwner)); spec = classTemplateSpec; @@ -1035,51 +1046,53 @@ public class CPPTemplates { spec = new CPPClassSpecialization((ICPPClassType) decl, oldOwner, tpMap); } } else if (decl instanceof ICPPField && classOwner != null) { - ICPPField field= (ICPPField) decl; + ICPPField field = (ICPPField) decl; InstantiationContext context = createInstantiationContext(tpMap, owner); - IType type= instantiateType(field.getType(), context); - IValue value= instantiateValue(field.getInitialValue(), context, IntegralValue.MAX_RECURSION_DEPTH); + IType type = instantiateType(field.getType(), context); + IValue value = instantiateValue(field.getInitialValue(), context, IntegralValue.MAX_RECURSION_DEPTH); if (decl instanceof ICPPFieldTemplate) { - CPPFieldTemplateSpecialization fieldTempSpec = new CPPFieldTemplateSpecialization(decl, - classOwner, tpMap, type, value); + CPPFieldTemplateSpecialization fieldTempSpec = new CPPFieldTemplateSpecialization(decl, classOwner, + tpMap, type, value); ICPPTemplateParameter[] params = specializeTemplateParameters(fieldTempSpec, - (ICPPScope) fieldTempSpec.getScope(), - ((ICPPFieldTemplate) decl).getTemplateParameters(), classOwner); + (ICPPScope) fieldTempSpec.getScope(), ((ICPPFieldTemplate) decl).getTemplateParameters(), + classOwner); fieldTempSpec.setTemplateParameters(params); spec = fieldTempSpec; } else { spec = new CPPFieldSpecialization(decl, classOwner, tpMap, type, value); } } else if (decl instanceof ICPPFunction) { - ICPPFunction func= (ICPPFunction) decl; + ICPPFunction func = (ICPPFunction) decl; InstantiationContext context = createInstantiationContext(tpMap, owner); - ICPPFunctionType type= (ICPPFunctionType) instantiateType(func.getType(), context); - IType[] exceptionSpecs= instantiateTypes(func.getExceptionSpecification(), context); + ICPPFunctionType type = (ICPPFunctionType) instantiateType(func.getType(), context); + IType[] exceptionSpecs = instantiateTypes(func.getExceptionSpecification(), context); CPPFunctionSpecialization functionSpec = null; if (decl instanceof ICPPFunctionTemplate) { if (decl instanceof ICPPMethod && classOwner != null) { CPPMethodTemplateSpecialization methodSpec; if (decl instanceof ICPPConstructor) { - methodSpec = new CPPConstructorTemplateSpecialization((ICPPConstructor) decl, - classOwner, tpMap, type, exceptionSpecs); + methodSpec = new CPPConstructorTemplateSpecialization((ICPPConstructor) decl, classOwner, + tpMap, type, exceptionSpecs); } else { - methodSpec = new CPPMethodTemplateSpecialization((ICPPMethod) decl, classOwner, tpMap, - type, exceptionSpecs); + methodSpec = new CPPMethodTemplateSpecialization((ICPPMethod) decl, classOwner, tpMap, type, + exceptionSpecs); } - methodSpec.setTemplateParameters(specializeTemplateParameters(methodSpec, - (ICPPScope) methodSpec.getScope(), - ((ICPPFunctionTemplate) decl).getTemplateParameters(), classOwner)); + methodSpec.setTemplateParameters( + specializeTemplateParameters(methodSpec, (ICPPScope) methodSpec.getScope(), + ((ICPPFunctionTemplate) decl).getTemplateParameters(), classOwner)); functionSpec = methodSpec; } else { IBinding oldOwner = decl.getOwner(); - functionSpec = new CPPFunctionTemplateSpecialization((ICPPFunctionTemplate) decl, - oldOwner, tpMap, type, exceptionSpecs); + functionSpec = new CPPFunctionTemplateSpecialization((ICPPFunctionTemplate) decl, oldOwner, + tpMap, type, exceptionSpecs); } } else if (decl instanceof ICPPConstructor && classOwner != null) { - functionSpec = new CPPConstructorSpecialization((ICPPConstructor) decl, classOwner, tpMap, type, exceptionSpecs); + functionSpec = new CPPConstructorSpecialization((ICPPConstructor) decl, classOwner, tpMap, type, + exceptionSpecs); } else if (decl instanceof ICPPMethod && classOwner != null) { - functionSpec = new CPPMethodSpecialization((ICPPMethod) decl, classOwner, tpMap, type, exceptionSpecs); + functionSpec = new CPPMethodSpecialization((ICPPMethod) decl, classOwner, tpMap, type, + exceptionSpecs); } else if (decl instanceof ICPPFunction) { if (type.isSameType(func.getType())) { // There is no need to create a CPPFunctionSpecialization object since the function is @@ -1098,15 +1111,15 @@ public class CPPTemplates { } } else if (decl instanceof ITypedef) { InstantiationContext context = createInstantiationContext(tpMap, owner); - IType type= instantiateType(((ITypedef) decl).getType(), context); + IType type = instantiateType(((ITypedef) decl).getType(), context); spec = new CPPTypedefSpecialization(decl, owner, tpMap, type); } else if (decl instanceof ICPPAliasTemplate) { ICPPAliasTemplate aliasTemplate = (ICPPAliasTemplate) decl; InstantiationContext context = createInstantiationContext(tpMap, owner); - IType type= instantiateType(aliasTemplate.getType(), context); - CPPAliasTemplateSpecialization aliasSpec = - new CPPAliasTemplateSpecialization(aliasTemplate, owner, tpMap, type); - aliasSpec.setTemplateParameters(specializeTemplateParameters(aliasSpec, + IType type = instantiateType(aliasTemplate.getType(), context); + CPPAliasTemplateSpecialization aliasSpec = new CPPAliasTemplateSpecialization(aliasTemplate, owner, + tpMap, type); + aliasSpec.setTemplateParameters(specializeTemplateParameters(aliasSpec, (ICPPScope) aliasSpec.getScope(), aliasTemplate.getTemplateParameters(), classOwner)); spec = aliasSpec; } else if (decl instanceof ICPPEnumeration && classOwner != null) { @@ -1120,13 +1133,13 @@ public class CPPTemplates { spec = ((ICPPEnumerationSpecialization) enumSpec).specializeEnumerator(enumerator); } } else if (decl instanceof ICPPUsingDeclaration) { - IBinding[] delegates= ((ICPPUsingDeclaration) decl).getDelegates(); - List<IBinding> result= new ArrayList<>(); + IBinding[] delegates = ((ICPPUsingDeclaration) decl).getDelegates(); + List<IBinding> result = new ArrayList<>(); InstantiationContext context = createInstantiationContext(tpMap, owner); for (IBinding delegate : delegates) { try { if (delegate instanceof ICPPUnknownBinding) { - delegate= resolveUnknown((ICPPUnknownBinding) delegate, context); + delegate = resolveUnknown((ICPPUnknownBinding) delegate, context); } if (delegate instanceof CPPFunctionSet) { for (IBinding b : ((CPPFunctionSet) delegate).getBindings()) { @@ -1138,8 +1151,8 @@ public class CPPTemplates { } catch (DOMException e) { } } - delegates= result.toArray(new IBinding[result.size()]); - spec= new CPPUsingDeclarationSpecialization((ICPPUsingDeclaration) decl, owner, tpMap, delegates); + delegates = result.toArray(new IBinding[result.size()]); + spec = new CPPUsingDeclarationSpecialization((ICPPUsingDeclaration) decl, owner, tpMap, delegates); } } catch (DOMException e) { CCorePlugin.log(e); @@ -1150,8 +1163,7 @@ public class CPPTemplates { return spec; } - private static InstantiationContext createInstantiationContext(ICPPTemplateParameterMap tpMap, - IBinding owner) { + private static InstantiationContext createInstantiationContext(ICPPTemplateParameterMap tpMap, IBinding owner) { return new InstantiationContext(tpMap, getSpecializationContext(owner)); } @@ -1166,10 +1178,10 @@ public class CPPTemplates { if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType)) return within; ICPPClassSpecialization nextWithin = (ICPPClassSpecialization) o1; - orig= (ICPPClassType) o2; + orig = (ICPPClassType) o2; if (orig.isSameType(nextWithin)) return within; - within= nextWithin; + within = nextWithin; } } @@ -1198,7 +1210,7 @@ public class CPPTemplates { return r; IType[] ps = ft.getParameterTypes(); for (IType pt : ps) { - r= combinePackSize(r, determinePackSize(pt, tpMap)); + r = combinePackSize(r, determinePackSize(pt, tpMap)); if (r < 0) return r; } @@ -1220,25 +1232,25 @@ public class CPPTemplates { if (type instanceof ICPPParameterPackType) return PACK_SIZE_NOT_FOUND; - int r= PACK_SIZE_NOT_FOUND; + int r = PACK_SIZE_NOT_FOUND; if (type instanceof IArrayType) { - IArrayType at= (IArrayType) type; - IValue asize= at.getSize(); - r= determinePackSize(asize, tpMap); + IArrayType at = (IArrayType) type; + IValue asize = at.getSize(); + r = determinePackSize(asize, tpMap); if (r < 0) return r; } if (type instanceof ITypeContainer) { final ITypeContainer typeContainer = (ITypeContainer) type; - r= combinePackSize(r, determinePackSize(typeContainer.getType(), tpMap)); + r = combinePackSize(r, determinePackSize(typeContainer.getType(), tpMap)); } return r; } static int determinePackSize(ICPPTemplateParameter tpar, ICPPTemplateParameterMap tpMap) { if (tpar.isParameterPack()) { - ICPPTemplateArgument[] args= tpMap.getPackExpansion(tpar); + ICPPTemplateArgument[] args = tpMap.getPackExpansion(tpar); if (args != null) { return args.length; } @@ -1248,23 +1260,22 @@ public class CPPTemplates { } static int determinePackSize(ICPPUnknownBinding binding, ICPPTemplateParameterMap tpMap) { - int r= PACK_SIZE_NOT_FOUND; + int r = PACK_SIZE_NOT_FOUND; if (binding instanceof ICPPDeferredClassInstance) { - ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) binding; + ICPPDeferredClassInstance dcl = (ICPPDeferredClassInstance) binding; if (dcl.getClassTemplate() instanceof ICPPTemplateTemplateParameter) { - r = combinePackSize(r, determinePackSize((ICPPTemplateParameter) dcl.getClassTemplate(), - tpMap)); + r = combinePackSize(r, determinePackSize((ICPPTemplateParameter) dcl.getClassTemplate(), tpMap)); } ICPPTemplateArgument[] args = dcl.getTemplateArguments(); for (ICPPTemplateArgument arg : args) { - r= combinePackSize(r, determinePackSize(arg, tpMap)); + r = combinePackSize(r, determinePackSize(arg, tpMap)); if (r < 0) return r; } } - IBinding ownerBinding= binding.getOwner(); + IBinding ownerBinding = binding.getOwner(); if (ownerBinding instanceof IType) - r= combinePackSize(r, determinePackSize((IType) ownerBinding, tpMap)); + r = combinePackSize(r, determinePackSize((IType) ownerBinding, tpMap)); return r; } @@ -1306,26 +1317,26 @@ public class CPPTemplates { // Don't create a new array until it's really needed. IType[] result = types; - int j= 0; + int j = 0; for (int i = 0; i < types.length; i++) { IType origType = types[i]; IType newType; if (origType instanceof ICPPParameterPackType) { - IType innerType= ((ICPPParameterPackType) origType).getType(); - int packSize= determinePackSize(innerType, context.getParameterMap()); + IType innerType = ((ICPPParameterPackType) origType).getType(); + int packSize = determinePackSize(innerType, context.getParameterMap()); if (packSize == PACK_SIZE_FAIL || packSize == PACK_SIZE_NOT_FOUND) { - newType= new ProblemBinding(CPPSemantics.getCurrentLookupPoint(), - IProblemBinding.SEMANTIC_INVALID_TYPE, + newType = new ProblemBinding(CPPSemantics.getCurrentLookupPoint(), + IProblemBinding.SEMANTIC_INVALID_TYPE, types[i] instanceof IBinding ? ((IBinding) types[i]).getNameCharArray() : null); } else if (packSize == PACK_SIZE_DEFER) { - newType= origType; + newType = origType; } else { - IType[] newResult= new IType[result.length + packSize - 1]; + IType[] newResult = new IType[result.length + packSize - 1]; System.arraycopy(result, 0, newResult, 0, j); - result= newResult; + result = newResult; context.setExpandPack(true); int oldPackOffset = context.getPackOffset(); - for (int k= 0; k < packSize; k++) { + for (int k = 0; k < packSize; k++) { context.setPackOffset(k); IType instantiated = instantiateType(innerType, context); if (context.isPackExpanded()) { @@ -1333,8 +1344,8 @@ public class CPPTemplates { instantiated = new CPPParameterPackType(instantiated); } } - result[j++]= instantiated; - + result[j++] = instantiated; + } context.setPackOffset(oldPackOffset); context.setExpandPack(false); @@ -1344,12 +1355,12 @@ public class CPPTemplates { newType = instantiateType(origType, context); } if (result != types) { - result[j++]= newType; + result[j++] = newType; } else { if (newType != origType) { result = new IType[types.length]; System.arraycopy(types, 0, result, 0, i); - result[j]= newType; + result[j] = newType; } j++; } @@ -1364,29 +1375,29 @@ public class CPPTemplates { * {@code false}, any invalid instantiated arguments are replaced by the corresponding original * arguments. */ - public static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, - InstantiationContext context, boolean strict) throws DOMException { + public static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, InstantiationContext context, + boolean strict) throws DOMException { // Don't create a new array until it's really needed. ICPPTemplateArgument[] result = args; - int resultShift= 0; + int resultShift = 0; for (int i = 0; i < args.length; i++) { ICPPTemplateArgument origArg = args[i]; ICPPTemplateArgument newArg; if (origArg.isPackExpansion()) { - ICPPTemplateArgument pattern= origArg.getExpansionPattern(); - int packSize= determinePackSize(pattern, context.getParameterMap()); + ICPPTemplateArgument pattern = origArg.getExpansionPattern(); + int packSize = determinePackSize(pattern, context.getParameterMap()); if (packSize == PACK_SIZE_FAIL || packSize == PACK_SIZE_NOT_FOUND) { throw new DOMException(new ProblemBinding(CPPSemantics.getCurrentLookupPoint(), IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, null)); } else if (packSize == PACK_SIZE_DEFER) { - newArg= origArg; + newArg = origArg; } else { int shift = packSize - 1; - ICPPTemplateArgument[] newResult= new ICPPTemplateArgument[args.length + resultShift + shift]; + ICPPTemplateArgument[] newResult = new ICPPTemplateArgument[args.length + resultShift + shift]; System.arraycopy(result, 0, newResult, 0, i + resultShift); context.setExpandPack(true); int oldPackOffset = context.getPackOffset(); - for (int j= 0; j < packSize; j++) { + for (int j = 0; j < packSize; j++) { context.setPackOffset(j); newArg = instantiateArgument(pattern, context); if (!isValidArgument(newArg)) { @@ -1405,11 +1416,11 @@ public class CPPTemplates { } context.setPackExpanded(false); } - newResult[i + resultShift + j]= newArg; + newResult[i + resultShift + j] = newArg; } context.setPackOffset(oldPackOffset); context.setExpandPack(false); - result= newResult; + result = newResult; resultShift += shift; continue; } @@ -1423,14 +1434,14 @@ public class CPPTemplates { } if (result != args) { - result[i + resultShift]= newArg; + result[i + resultShift] = newArg; } else if (newArg != origArg) { assert resultShift == 0; result = new ICPPTemplateArgument[args.length]; if (i > 0) { System.arraycopy(args, 0, result, 0, i); } - result[i]= newArg; + result[i] = newArg; } } return result; @@ -1444,7 +1455,7 @@ public class CPPTemplates { return null; if (arg.isNonTypeValue()) { final ICPPEvaluation eval = arg.getNonTypeEvaluation(); - final ICPPEvaluation newEval= eval.instantiate(context, IntegralValue.MAX_RECURSION_DEPTH); + final ICPPEvaluation newEval = eval.instantiate(context, IntegralValue.MAX_RECURSION_DEPTH); if (eval == newEval) return arg; return new CPPTemplateNonTypeArgument(newEval); @@ -1453,10 +1464,10 @@ public class CPPTemplates { // Which to instantiate, getOriginalTypeValue() or getTypeValue()? // // Using getOriginalTypeValue() is better for typedef preservation, - // and in the case of alias template instances, also necessary for - // correctness (since an alias template instance could have dependent - // arguments that don't appear in the resulting type, and these - // arguments could SFINAE out during instantiation; the popular + // and in the case of alias template instances, also necessary for + // correctness (since an alias template instance could have dependent + // arguments that don't appear in the resulting type, and these + // arguments could SFINAE out during instantiation; the popular // "void_t" technique relies on this). // // However, caching of template instances is based on the normalized @@ -1478,8 +1489,8 @@ public class CPPTemplates { } else { type = arg.getTypeValue(); } - - final IType inst= instantiateType(type, context); + + final IType inst = instantiateType(type, context); if (type == inst) return arg; return new CPPTemplateTypeArgument(inst); @@ -1488,7 +1499,7 @@ public class CPPTemplates { private static CPPTemplateParameterMap instantiateArgumentMap(ICPPTemplateParameterMap orig, InstantiationContext context) { final Integer[] positions = orig.getAllParameterPositions(); - CPPTemplateParameterMap newMap= new CPPTemplateParameterMap(positions.length); + CPPTemplateParameterMap newMap = new CPPTemplateParameterMap(positions.length); for (Integer key : positions) { ICPPTemplateArgument arg = orig.getArgument(key); if (arg != null) { @@ -1517,11 +1528,11 @@ public class CPPTemplates { public static IType instantiateType(final IType type, InstantiationContext context) { if (context.getParameterMap() == null) return type; - + TypeInstantiationRequest instantiationRequest = new TypeInstantiationRequest(type, context); if (!instantiationsInProgress.get().add(instantiationRequest)) { - return type instanceof ICPPFunctionType ? - ProblemFunctionType.RECURSION_IN_LOOKUP : ProblemType.RECURSION_IN_LOOKUP; + return type instanceof ICPPFunctionType ? ProblemFunctionType.RECURSION_IN_LOOKUP + : ProblemType.RECURSION_IN_LOOKUP; } try { @@ -1535,14 +1546,14 @@ public class CPPTemplates { return type; } // The parameter types need to be adjusted. - for (int i= 0; i < params.length; i++) { - IType p= params[i]; + for (int i = 0; i < params.length; i++) { + IType p = params[i]; if (!isDependentType(p)) { - params[i]= CPPVisitor.adjustParameterType(p, true); + params[i] = CPPVisitor.adjustParameterType(p, true); } } - return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), - ft.hasRefQualifier(), ft.isRValueReference(), ft.takesVarArgs()); + return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), ft.hasRefQualifier(), + ft.isRValueReference(), ft.takesVarArgs()); } if (type instanceof ICPPTemplateParameter) { @@ -1572,16 +1583,16 @@ public class CPPTemplates { } return type; } else { - IBinding binding= resolveUnknown((ICPPUnknownBinding) type, context); + IBinding binding = resolveUnknown((ICPPUnknownBinding) type, context); if (binding instanceof IType) return (IType) binding; return type; } } - + if (context.getContextTypeSpecialization() != null && type instanceof IBinding) { - IType unwound= getNestedType(type, TDEF); + IType unwound = getNestedType(type, TDEF); ICPPClassSpecialization withinClass = context.getContextClassSpecialization(); if (unwound instanceof ICPPClassType && unwound.isSameType(withinClass.getSpecializedBinding())) { // Convert (partial) class-templates (specializations) to the more specialized @@ -1589,17 +1600,18 @@ public class CPPTemplates { if (withinClass instanceof ICPPClassTemplate || !(unwound instanceof ICPPClassTemplate)) return withinClass; } - IBinding typeAsBinding= (IBinding) type; - IBinding owner= typeAsBinding.getOwner(); + IBinding typeAsBinding = (IBinding) type; + IBinding owner = typeAsBinding.getOwner(); if (owner instanceof IType) { final IType ownerAsType = getNestedType((IType) owner, TDEF); - Object newOwner= owner; - if (ownerAsType instanceof ICPPClassType && ownerAsType.isSameType(withinClass.getSpecializedBinding())) { + Object newOwner = owner; + if (ownerAsType instanceof ICPPClassType + && ownerAsType.isSameType(withinClass.getSpecializedBinding())) { // Convert (partial) class-templates (specializations) that are used as // owner of another binding, to the more specialized version. - newOwner= withinClass; + newOwner = withinClass; } else { - newOwner= instantiateType(ownerAsType, context); + newOwner = instantiateType(ownerAsType, context); } if (newOwner != owner && newOwner instanceof ICPPClassSpecialization) { @@ -1608,7 +1620,7 @@ public class CPPTemplates { } } - // An alias template instance may have dependent arguments that don't contribute + // An alias template instance may have dependent arguments that don't contribute // to the target type but can SFINAE out during instantiation, so it's not // sufficient to handle it in the ITypeContainer case. if (type instanceof ICPPAliasTemplateInstance) { @@ -1618,7 +1630,7 @@ public class CPPTemplates { // instantiateArgumentMap(), and if the argument appears in the aliased type, then // a third time in instantiateType()), leading to exponential runtime in cases of // nested alias template instances (which can be common in metaprogramming code - // implemented using alias templates). + // implemented using alias templates). IType result = getCachedInstantiation(instantiationRequest); if (result != null) { return result; @@ -1628,14 +1640,12 @@ public class CPPTemplates { ICPPTemplateArgument[] args = instance.getTemplateArguments(); ICPPTemplateArgument[] newArgs = instantiateArguments(args, context, true); if (newArgs == null) { - result = (IType) createProblem(template, - IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); + result = (IType) createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); } else if (args != newArgs) { IType target = instantiateType(instance.getType(), context); CPPTemplateParameterMap map = createParameterMap(template, newArgs); if (map == null) { - result = (IType) createProblem(template, - IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); + result = (IType) createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); } else { result = new CPPAliasTemplateInstance(template, target, instance.getOwner(), map, newArgs); } @@ -1660,16 +1670,16 @@ public class CPPTemplates { return new ProblemType(ISemanticProblem.BINDING_INVALID_TYPE); } if (newNestedType != nestedType || newMemberOfClass != memberOfClass) { - return new CPPPointerToMemberType(newNestedType, newMemberOfClass, - ptm.isConst(), ptm.isVolatile(), ptm.isRestrict()); + return new CPPPointerToMemberType(newNestedType, newMemberOfClass, ptm.isConst(), + ptm.isVolatile(), ptm.isRestrict()); } return typeContainer; } if (typeContainer instanceof IArrayType) { - IArrayType at= (IArrayType) typeContainer; - IValue asize= at.getSize(); + IArrayType at = (IArrayType) typeContainer; + IValue asize = at.getSize(); if (asize != null) { - IValue newSize= instantiateValue(asize, context, IntegralValue.MAX_RECURSION_DEPTH); + IValue newSize = instantiateValue(asize, context, IntegralValue.MAX_RECURSION_DEPTH); if (newSize != asize) { return new CPPArrayType(newNestedType, newSize); } @@ -1685,11 +1695,13 @@ public class CPPTemplates { ICPPUnaryTypeTransformation typeTransformation = (ICPPUnaryTypeTransformation) type; IType operand = instantiateType(typeTransformation.getOperand(), context); switch (typeTransformation.getOperator()) { - case underlying_type: return TypeTraits.underlyingType(operand); - default: return null; // shouldn't happen + case underlying_type: + return TypeTraits.underlyingType(operand); + default: + return null; // shouldn't happen } } - + if (type instanceof CPPClosureType) { return ((CPPClosureType) type).instantiate(context); } @@ -1726,8 +1738,8 @@ public class CPPTemplates { IType type = instantiateType(spec.getType(), context); return new CPPTemplateNonTypeParameterSpecialization(owner, scope, spec, defaultValue, type); } else if (specialized instanceof ICPPTemplateTypeParameter) { - return new CPPTemplateTypeParameterSpecialization(owner, scope, - (ICPPTemplateTypeParameter) specialized, defaultValue); + return new CPPTemplateTypeParameterSpecialization(owner, scope, (ICPPTemplateTypeParameter) specialized, + defaultValue); } else if (specialized instanceof ICPPTemplateTemplateParameter) { return new CPPTemplateTemplateParameterSpecialization(owner, scope, (ICPPTemplateTemplateParameter) specialized, defaultValue); @@ -1755,9 +1767,7 @@ public class CPPTemplates { if (binding instanceof ICPPUnknownBinding) { return resolveUnknown((ICPPUnknownBinding) binding, context); - } else if (binding instanceof ICPPMethod - || binding instanceof ICPPField - || binding instanceof ICPPEnumeration + } else if (binding instanceof ICPPMethod || binding instanceof ICPPField || binding instanceof ICPPEnumeration || binding instanceof ICPPClassType) { IBinding owner = binding.getOwner(); if (!(owner instanceof ICPPSpecialization)) { @@ -1786,12 +1796,13 @@ public class CPPTemplates { ICPPTemplateArgument[] origArgs = origInstance.getTemplateArguments(); ICPPTemplateArgument[] newArgs = instantiateArguments(origArgs, context, false); if (origArgs != newArgs) { - CPPTemplateParameterMap newMap = - instantiateArgumentMap(origInstance.getTemplateParameterMap(), context); + CPPTemplateParameterMap newMap = instantiateArgumentMap(origInstance.getTemplateParameterMap(), + context); IType newType = instantiateType(origInstance.getType(), context); IType[] newExceptionSpecs = instantiateTypes(origInstance.getExceptionSpecification(), context); - CPPFunctionInstance result = new CPPFunctionInstance((ICPPFunction) origInstance.getTemplateDefinition(), - origInstance.getOwner(), newMap, newArgs, (ICPPFunctionType) newType, newExceptionSpecs); + CPPFunctionInstance result = new CPPFunctionInstance( + (ICPPFunction) origInstance.getTemplateDefinition(), origInstance.getOwner(), newMap, newArgs, + (ICPPFunctionType) newType, newExceptionSpecs); result.setParameters(specializeParameters(origInstance.getParameters(), result, context, maxDepth)); return result; } @@ -1803,30 +1814,29 @@ public class CPPTemplates { ICPPTemplateArgument[] origArgs = origInstance.getTemplateArguments(); ICPPTemplateArgument[] newArgs = instantiateArguments(origArgs, context, false); if (origArgs != newArgs) { - CPPTemplateParameterMap newMap = instantiateArgumentMap( - origInstance.getTemplateParameterMap(), context); + CPPTemplateParameterMap newMap = instantiateArgumentMap(origInstance.getTemplateParameterMap(), + context); IType newType = instantiateType(origInstance.getType(), context); IValue newValue = instantiateValue(origInstance.getInitialValue(), context, IntegralValue.MAX_RECURSION_DEPTH); - return new CPPVariableInstance(origInstance.getTemplateDefinition(), origInstance.getOwner(), - newMap, newArgs, newType, newValue); + return new CPPVariableInstance(origInstance.getTemplateDefinition(), origInstance.getOwner(), newMap, + newArgs, newType, newValue); } } return binding; } - public static IType resolveTemplateTypeParameter(final ICPPTemplateParameter tpar, - InstantiationContext context) { - ICPPTemplateArgument arg= null; + public static IType resolveTemplateTypeParameter(final ICPPTemplateParameter tpar, InstantiationContext context) { + ICPPTemplateArgument arg = null; if (tpar.isParameterPack()) { if (context.hasPackOffset()) { ICPPTemplateArgument[] args = context.getPackExpansion(tpar); if (args != null) { if (context.getPackOffset() >= args.length) { - return new ProblemBinding(CPPSemantics.getCurrentLookupPoint(), + return new ProblemBinding(CPPSemantics.getCurrentLookupPoint(), IProblemBinding.SEMANTIC_INVALID_TYPE, tpar.getNameCharArray()); } - arg= args[context.getPackOffset()]; + arg = args[context.getPackOffset()]; } if (context.shouldExpandPack()) { if (arg != null) { @@ -1839,11 +1849,11 @@ public class CPPTemplates { } } } else { - arg= context.getArgument(tpar); + arg = context.getArgument(tpar); } if (arg != null) { - IType t= arg.getOriginalTypeValue(); + IType t = arg.getOriginalTypeValue(); if (t != null) return t; } @@ -1866,12 +1876,12 @@ public class CPPTemplates { return null; // first look for a related sequence of template declarations - ICPPASTInternalTemplateDeclaration tdecl= getInnerTemplateDeclaration(name); + ICPPASTInternalTemplateDeclaration tdecl = getInnerTemplateDeclaration(name); if (tdecl == null) return null; - name= name.getLastName(); - IASTNode parent= name.getParent(); + name = name.getLastName(); + IASTNode parent = name.getParent(); if (!(parent instanceof ICPPASTQualifiedName)) { if (parent instanceof ICPPASTTemplateId) { return null; @@ -1881,9 +1891,9 @@ public class CPPTemplates { } // last name can be associated even if it is not a template-id - final ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent; + final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; final IASTName lastName = qname.getLastName(); - final boolean lastIsTemplate= tdecl.isAssociatedWithLastName(); + final boolean lastIsTemplate = tdecl.isAssociatedWithLastName(); if (name == lastName) { if (lastIsTemplate) { return tdecl; @@ -1897,16 +1907,16 @@ public class CPPTemplates { if (lastIsTemplate) { // skip one - tdecl= getDirectlyEnclosingTemplateDeclaration(tdecl); + tdecl = getDirectlyEnclosingTemplateDeclaration(tdecl); } - final ICPPASTNameSpecifier[] qualifier= qname.getQualifier(); + final ICPPASTNameSpecifier[] qualifier = qname.getQualifier(); for (int i = qualifier.length - 1; tdecl != null && i >= 0; i--) { final ICPPASTNameSpecifier n = qualifier[i]; if (n == name) { return tdecl; } if (n instanceof ICPPASTTemplateId) { - tdecl= getDirectlyEnclosingTemplateDeclaration(tdecl); + tdecl = getDirectlyEnclosingTemplateDeclaration(tdecl); } } // not enough template declarations @@ -1915,74 +1925,73 @@ public class CPPTemplates { public static void associateTemplateDeclarations(ICPPASTInternalTemplateDeclaration tdecl) { // Find innermost template declaration - IASTDeclaration decl= tdecl.getDeclaration(); + IASTDeclaration decl = tdecl.getDeclaration(); while (decl instanceof ICPPASTInternalTemplateDeclaration) { - tdecl= (ICPPASTInternalTemplateDeclaration) decl; - decl= tdecl.getDeclaration(); + tdecl = (ICPPASTInternalTemplateDeclaration) decl; + decl = tdecl.getDeclaration(); } - final ICPPASTInternalTemplateDeclaration innerMostTDecl= tdecl; + final ICPPASTInternalTemplateDeclaration innerMostTDecl = tdecl; // Find name declared within the template declaration - final IASTName declName= getNameForDeclarationInTemplateDeclaration(decl); + final IASTName declName = getNameForDeclarationInTemplateDeclaration(decl); // Count non-empty template declarations - int instDeclCount= 0; - int tdeclCount= 0; - IASTNode node= tdecl; + int instDeclCount = 0; + int tdeclCount = 0; + IASTNode node = tdecl; while (node instanceof ICPPASTInternalTemplateDeclaration) { tdecl = (ICPPASTInternalTemplateDeclaration) node; - node= node.getParent(); + node = node.getParent(); if (tdecl.getTemplateParameters().length == 0) { instDeclCount++; } else { - instDeclCount= 0; + instDeclCount = 0; } tdeclCount++; } - final ICPPASTInternalTemplateDeclaration outerMostTDecl= tdecl; - final int paramTDeclCount = tdeclCount-instDeclCount; + final ICPPASTInternalTemplateDeclaration outerMostTDecl = tdecl; + final int paramTDeclCount = tdeclCount - instDeclCount; // Determine association of names with template declarations - boolean lastIsTemplate= true; + boolean lastIsTemplate = true; int nestingLevel; if (declName instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qname= (ICPPASTQualifiedName) declName; + ICPPASTQualifiedName qname = (ICPPASTQualifiedName) declName; // Count dependent-ids - CharArraySet tparnames= collectTemplateParameterNames(outerMostTDecl); - int depIDCount= 0; - IBinding owner= null; - final ICPPASTNameSpecifier[] qualifier= qname.getQualifier(); + CharArraySet tparnames = collectTemplateParameterNames(outerMostTDecl); + int depIDCount = 0; + IBinding owner = null; + final ICPPASTNameSpecifier[] qualifier = qname.getQualifier(); for (int i = 0; i < qualifier.length; i++) { - ICPPASTNameSpecifier n= qualifier[i]; + ICPPASTNameSpecifier n = qualifier[i]; if (n instanceof ICPPASTTemplateId) { if (depIDCount > 0 || usesTemplateParameter((ICPPASTTemplateId) n, tparnames)) { depIDCount++; } } if (depIDCount == 0) { - owner= n.resolveBinding(); + owner = n.resolveBinding(); } } - if (qname.getLastName() instanceof ICPPASTTemplateId - || paramTDeclCount > depIDCount // not enough template ids - || qualifier.length < 1 // ::name - ) { - lastIsTemplate= true; + if (qname.getLastName() instanceof ICPPASTTemplateId || paramTDeclCount > depIDCount // not enough template ids + || qualifier.length < 1 // ::name + ) { + lastIsTemplate = true; depIDCount++; } else { - lastIsTemplate= false; + lastIsTemplate = false; } - nestingLevel= 0; + nestingLevel = 0; if (owner != null) { - int consumesTDecl= 0; - IBinding b= owner; + int consumesTDecl = 0; + IBinding b = owner; if (b instanceof IType) { - IType t= SemanticUtil.getNestedType((IType) b, TDEF); + IType t = SemanticUtil.getNestedType((IType) b, TDEF); if (t instanceof IBinding) - b= (IBinding) t; + b = (IBinding) t; } while (b != null) { if (b instanceof ICPPTemplateInstance) { @@ -1993,62 +2002,63 @@ public class CPPTemplates { nestingLevel++; consumesTDecl++; } - b= b.getOwner(); + b = b.getOwner(); } if (depIDCount > 0) { - nestingLevel+= depIDCount; + nestingLevel += depIDCount; } else if (consumesTDecl < tdeclCount && !lastIsTemplate) { nestingLevel++; - lastIsTemplate= true; + lastIsTemplate = true; } } else { - nestingLevel+= depIDCount; - node= outerMostTDecl.getParent(); + nestingLevel += depIDCount; + node = outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } - node= node.getParent(); + node = node.getParent(); } } } else { - nestingLevel= 1; - lastIsTemplate= true; + nestingLevel = 1; + lastIsTemplate = true; if (!isFriendFunctionDeclaration(innerMostTDecl.getDeclaration())) { - node= outerMostTDecl.getParent(); + node = outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } - node= node.getParent(); + node = node.getParent(); } } } - node= innerMostTDecl; + node = innerMostTDecl; while (node instanceof ICPPASTInternalTemplateDeclaration) { if (--nestingLevel < 0) - nestingLevel= 0; - tdecl= (ICPPASTInternalTemplateDeclaration) node; + nestingLevel = 0; + tdecl = (ICPPASTInternalTemplateDeclaration) node; tdecl.setNestingLevel((short) nestingLevel); tdecl.setAssociatedWithLastName(false); - node= tdecl.getParent(); + node = tdecl.getParent(); } innerMostTDecl.setAssociatedWithLastName(lastIsTemplate); } private static boolean isFriendFunctionDeclaration(IASTDeclaration declaration) { while (declaration instanceof ICPPASTTemplateDeclaration) { - declaration= ((ICPPASTTemplateDeclaration) declaration).getDeclaration(); + declaration = ((ICPPASTTemplateDeclaration) declaration).getDeclaration(); } if (declaration instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) declaration; - ICPPASTDeclSpecifier declspec= (ICPPASTDeclSpecifier) sdecl.getDeclSpecifier(); + ICPPASTDeclSpecifier declspec = (ICPPASTDeclSpecifier) sdecl.getDeclSpecifier(); if (declspec.isFriend()) { - IASTDeclarator[] dtors= sdecl.getDeclarators(); - if (dtors.length == 1 && ASTQueries.findTypeRelevantDeclarator(dtors[0]) instanceof IASTFunctionDeclarator) { + IASTDeclarator[] dtors = sdecl.getDeclarators(); + if (dtors.length == 1 + && ASTQueries.findTypeRelevantDeclarator(dtors[0]) instanceof IASTFunctionDeclarator) { return true; } } @@ -2057,17 +2067,17 @@ public class CPPTemplates { } private static CharArraySet collectTemplateParameterNames(ICPPASTTemplateDeclaration tdecl) { - CharArraySet set= new CharArraySet(4); + CharArraySet set = new CharArraySet(4); while (true) { ICPPASTTemplateParameter[] pars = tdecl.getTemplateParameters(); for (ICPPASTTemplateParameter par : pars) { - IASTName name= getTemplateParameterName(par); + IASTName name = getTemplateParameterName(par); if (name != null) set.put(name.getLookupKey()); } - final IASTNode next= tdecl.getDeclaration(); + final IASTNode next = tdecl.getDeclaration(); if (next instanceof ICPPASTTemplateDeclaration) { - tdecl= (ICPPASTTemplateDeclaration) next; + tdecl = (ICPPASTTemplateDeclaration) next; } else { break; } @@ -2076,40 +2086,44 @@ public class CPPTemplates { } private static boolean usesTemplateParameter(final ICPPASTTemplateId id, final CharArraySet names) { - final boolean[] result= {false}; - ASTVisitor v= new ASTVisitor(false) { - { shouldVisitNames= true; shouldVisitAmbiguousNodes=true;} + final boolean[] result = { false }; + ASTVisitor v = new ASTVisitor(false) { + { + shouldVisitNames = true; + shouldVisitAmbiguousNodes = true; + } + @Override public int visit(IASTName name) { if (name instanceof ICPPASTTemplateId) return PROCESS_CONTINUE; if (name instanceof ICPPASTQualifiedName) { - ICPPASTQualifiedName qname= (ICPPASTQualifiedName) name; + ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name; if (qname.isFullyQualified()) return PROCESS_SKIP; return PROCESS_CONTINUE; } if (names.containsKey(name.getLookupKey())) { - IASTNode parent= name.getParent(); + IASTNode parent = name.getParent(); if (parent instanceof ICPPASTQualifiedName) { ICPPASTNameSpecifier[] qualifier = ((ICPPASTQualifiedName) parent).getQualifier(); if (qualifier.length > 0 && qualifier[0] != name) { return PROCESS_CONTINUE; } - result[0]= true; + result[0] = true; return PROCESS_ABORT; - } else if (parent instanceof IASTIdExpression || - parent instanceof ICPPASTNamedTypeSpecifier) { - result[0]= true; + } else if (parent instanceof IASTIdExpression || parent instanceof ICPPASTNamedTypeSpecifier) { + result[0] = true; return PROCESS_ABORT; } } return PROCESS_CONTINUE; } + @Override public int visit(ASTAmbiguousNode node) { - IASTNode[] alternatives= node.getNodes(); + IASTNode[] alternatives = node.getNodes(); for (IASTNode alt : alternatives) { if (!alt.accept(this)) return PROCESS_ABORT; @@ -2122,36 +2136,34 @@ public class CPPTemplates { } private static IASTName getNameForDeclarationInTemplateDeclaration(IASTDeclaration decl) { - IASTName name= null; + IASTName name = null; if (decl instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration sdecl= (IASTSimpleDeclaration) decl; + IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl; IASTDeclarator[] dtors = sdecl.getDeclarators(); if (dtors != null && dtors.length > 0) { - name= ASTQueries.findInnermostDeclarator(dtors[0]).getName(); + name = ASTQueries.findInnermostDeclarator(dtors[0]).getName(); } else { IASTDeclSpecifier declspec = sdecl.getDeclSpecifier(); if (declspec instanceof IASTCompositeTypeSpecifier) { - name= ((IASTCompositeTypeSpecifier) declspec).getName(); + name = ((IASTCompositeTypeSpecifier) declspec).getName(); } else if (declspec instanceof IASTElaboratedTypeSpecifier) { - name= ((IASTElaboratedTypeSpecifier) declspec).getName(); + name = ((IASTElaboratedTypeSpecifier) declspec).getName(); } } } else if (decl instanceof IASTFunctionDefinition) { - IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl; - name= ASTQueries.findInnermostDeclarator(fdef.getDeclarator()).getName(); + IASTFunctionDefinition fdef = (IASTFunctionDefinition) decl; + name = ASTQueries.findInnermostDeclarator(fdef.getDeclarator()).getName(); } return name; } - private static ICPPASTInternalTemplateDeclaration getInnerTemplateDeclaration(final IASTName name) { IASTNode parent = name.getParent(); while (parent instanceof IASTName) { parent = parent.getParent(); } if (parent instanceof IASTDeclSpecifier) { - if (!(parent instanceof IASTCompositeTypeSpecifier) && - !(parent instanceof IASTElaboratedTypeSpecifier)) { + if (!(parent instanceof IASTCompositeTypeSpecifier) && !(parent instanceof IASTElaboratedTypeSpecifier)) { return null; } parent = parent.getParent(); @@ -2172,7 +2184,7 @@ public class CPPTemplates { private static ICPPASTInternalTemplateDeclaration getDirectlyEnclosingTemplateDeclaration( ICPPASTInternalTemplateDeclaration tdecl) { - final IASTNode parent= tdecl.getParent(); + final IASTNode parent = tdecl.getParent(); if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; @@ -2180,7 +2192,8 @@ public class CPPTemplates { } public static IASTName getTemplateName(ICPPASTTemplateDeclaration templateDecl) { - if (templateDecl == null) return null; + if (templateDecl == null) + return null; ICPPASTTemplateDeclaration decl = templateDecl; while (decl.getParent() instanceof ICPPASTTemplateDeclaration) @@ -2209,7 +2222,7 @@ public class CPPTemplates { } } else if (nestedDecl instanceof IASTFunctionDefinition) { IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator(); - declarator= ASTQueries.findInnermostDeclarator(declarator); + declarator = ASTQueries.findInnermostDeclarator(declarator); name = declarator.getName(); } else if (nestedDecl instanceof ICPPASTAliasDeclaration) { name = ((ICPPASTAliasDeclaration) nestedDecl).getAlias(); @@ -2237,14 +2250,14 @@ public class CPPTemplates { } } - return null; + return null; } public static boolean areSameArguments(ICPPTemplateArgument[] args, ICPPTemplateArgument[] specArgs) { if (args.length != specArgs.length) { return false; } - for (int i= 0; i < args.length; i++) { + for (int i = 0; i < args.length; i++) { if (!specArgs[i].isSameValue(args[i])) return false; } @@ -2257,24 +2270,25 @@ public class CPPTemplates { * The empty ICPPTemplateArgument array is returned if id is {@code null} */ public static ICPPTemplateArgument[] createTemplateArgumentArray(ICPPASTTemplateId id) throws DOMException { - ICPPTemplateArgument[] result= ICPPTemplateArgument.EMPTY_ARGUMENTS; + ICPPTemplateArgument[] result = ICPPTemplateArgument.EMPTY_ARGUMENTS; if (id != null) { - IASTNode[] args= id.getTemplateArguments(); + IASTNode[] args = id.getTemplateArguments(); result = new ICPPTemplateArgument[args.length]; for (int i = 0; i < args.length; i++) { - IASTNode arg= args[i]; + IASTNode arg = args[i]; if (arg instanceof IASTTypeId) { - result[i]= new CPPTemplateTypeArgument(CPPVisitor.createType((IASTTypeId) arg)); + result[i] = new CPPTemplateTypeArgument(CPPVisitor.createType((IASTTypeId) arg)); } else if (arg instanceof ICPPASTExpression) { - ICPPASTExpression expr= (ICPPASTExpression) arg; + ICPPASTExpression expr = (ICPPASTExpression) arg; CPPSemantics.pushLookupPoint(expr); try { - result[i]= new CPPTemplateNonTypeArgument(expr.getEvaluation()); + result[i] = new CPPTemplateNonTypeArgument(expr.getEvaluation()); } finally { CPPSemantics.popLookupPoint(); } } else if (arg instanceof ICPPASTAmbiguousTemplateArgument) { - IProblemBinding problem = new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); + IProblemBinding problem = new ProblemBinding(id, + IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); throw new DOMException(problem); } else { throw new IllegalArgumentException("Unexpected type: " + arg.getClass().getName()); //$NON-NLS-1$ @@ -2287,21 +2301,21 @@ public class CPPTemplates { static ICPPFunction[] instantiateForFunctionCall(ICPPFunction[] fns, ICPPTemplateArgument[] tmplArgs, List<IType> fnArgs, List<ValueCategory> argCats, boolean withImpliedObjectArg) { // Extract template arguments. - boolean requireTemplate= tmplArgs != null; - boolean haveTemplate= false; + boolean requireTemplate = tmplArgs != null; + boolean haveTemplate = false; for (final ICPPFunction func : fns) { if (func instanceof ICPPConstructor || (func instanceof ICPPMethod && ((ICPPMethod) func).isDestructor())) - requireTemplate= false; + requireTemplate = false; if (func instanceof ICPPFunctionTemplate) { if (containsDependentType(fnArgs)) - return new ICPPFunction[] {CPPDeferredFunction.createForCandidates(fns)}; + return new ICPPFunction[] { CPPDeferredFunction.createForCandidates(fns) }; if (requireTemplate && hasDependentArgument(tmplArgs)) - return new ICPPFunction[] {CPPDeferredFunction.createForCandidates(fns)}; + return new ICPPFunction[] { CPPDeferredFunction.createForCandidates(fns) }; - haveTemplate= true; + haveTemplate = true; break; } } @@ -2309,11 +2323,11 @@ public class CPPTemplates { if (!haveTemplate && !requireTemplate) return fns; - final List<ICPPFunction> result= new ArrayList<>(fns.length); + final List<ICPPFunction> result = new ArrayList<>(fns.length); for (ICPPFunction fn : fns) { if (fn != null) { if (fn instanceof ICPPFunctionTemplate) { - ICPPFunctionTemplate fnTmpl= (ICPPFunctionTemplate) fn; + ICPPFunctionTemplate fnTmpl = (ICPPFunctionTemplate) fn; ICPPFunction inst = instantiateForFunctionCall(fnTmpl, tmplArgs, fnArgs, argCats, withImpliedObjectArg); if (inst != null) @@ -2330,16 +2344,16 @@ public class CPPTemplates { ICPPTemplateArgument[] tmplArgs, List<IType> fnArgs, List<ValueCategory> argCats, boolean withImpliedObjectArg) { if (withImpliedObjectArg && template instanceof ICPPMethod) { - fnArgs= fnArgs.subList(1, fnArgs.size()); - argCats= argCats.subList(1, argCats.size()); + fnArgs = fnArgs.subList(1, fnArgs.size()); + argCats = argCats.subList(1, argCats.size()); } - CPPTemplateParameterMap map= new CPPTemplateParameterMap(fnArgs.size()); + CPPTemplateParameterMap map = new CPPTemplateParameterMap(fnArgs.size()); try { - ICPPTemplateArgument[] args= - TemplateArgumentDeduction.deduceForFunctionCall(template, tmplArgs, fnArgs, argCats, map); + ICPPTemplateArgument[] args = TemplateArgumentDeduction.deduceForFunctionCall(template, tmplArgs, fnArgs, + argCats, map); if (args != null) { - IBinding instance= instantiateFunctionTemplate(template, args, map); + IBinding instance = instantiateFunctionTemplate(template, args, map); if (instance instanceof ICPPFunction) { final ICPPFunction f = (ICPPFunction) instance; if (isValidFunctionType(f.getType())) { @@ -2381,32 +2395,32 @@ public class CPPTemplates { * @param point */ static ICPPFunction[] instantiateConversionTemplates(ICPPFunction[] functions, IType conversionType) { - boolean checkedForDependentType= false; - ICPPFunction[] result= functions; - int i= 0; - boolean done= false; + boolean checkedForDependentType = false; + ICPPFunction[] result = functions; + int i = 0; + boolean done = false; for (ICPPFunction f : functions) { ICPPFunction inst = f; if (f instanceof ICPPFunctionTemplate) { - ICPPFunctionTemplate template= (ICPPFunctionTemplate) f; - inst= null; + ICPPFunctionTemplate template = (ICPPFunctionTemplate) f; + inst = null; // Extract template arguments and parameter types. if (!checkedForDependentType) { if (isDependentType(conversionType)) { - inst= CPPDeferredFunction.createForCandidates(functions); - done= true; + inst = CPPDeferredFunction.createForCandidates(functions); + done = true; } - checkedForDependentType= true; + checkedForDependentType = true; } - CPPTemplateParameterMap map= new CPPTemplateParameterMap(1); + CPPTemplateParameterMap map = new CPPTemplateParameterMap(1); try { - ICPPTemplateArgument[] args= - TemplateArgumentDeduction.deduceForConversion(template, conversionType, map); + ICPPTemplateArgument[] args = TemplateArgumentDeduction.deduceForConversion(template, + conversionType, map); if (args != null) { - IBinding instance= instantiateFunctionTemplate(template, args, map); + IBinding instance = instantiateFunctionTemplate(template, args, map); if (instance instanceof ICPPFunction) { - inst= (ICPPFunction) instance; + inst = (ICPPFunction) instance; } } } catch (DOMException e) { @@ -2415,10 +2429,10 @@ public class CPPTemplates { } if (result != functions || f != inst) { if (result == functions) { - result= new ICPPFunction[functions.length]; + result = new ICPPFunction[functions.length]; System.arraycopy(functions, 0, result, 0, i); } - result[i++]= inst; + result[i++] = inst; } if (done) break; @@ -2431,13 +2445,13 @@ public class CPPTemplates { * @param point * @return */ - static ICPPFunction instantiateForFunctionDeclaration(ICPPFunctionTemplate template, - ICPPTemplateArgument[] args, ICPPFunctionType functionType) { - CPPTemplateParameterMap map= new CPPTemplateParameterMap(1); + static ICPPFunction instantiateForFunctionDeclaration(ICPPFunctionTemplate template, ICPPTemplateArgument[] args, + ICPPFunctionType functionType) { + CPPTemplateParameterMap map = new CPPTemplateParameterMap(1); try { - args= TemplateArgumentDeduction.deduceForDeclaration(template, args, functionType, map); + args = TemplateArgumentDeduction.deduceForDeclaration(template, args, functionType, map); if (args != null) { - IBinding instance= instantiateFunctionTemplate(template, args, map); + IBinding instance = instantiateFunctionTemplate(template, args, map); if (instance instanceof ICPPFunction) { return (ICPPFunction) instance; } @@ -2448,7 +2462,6 @@ public class CPPTemplates { return null; } - /** * 14.8.2.2 Deducing template arguments taking the address of a function template [temp.deduct.funcaddr] */ @@ -2460,12 +2473,12 @@ public class CPPTemplates { } if (template instanceof ICPPConstructor || args == null) - args= ICPPTemplateArgument.EMPTY_ARGUMENTS; + args = ICPPTemplateArgument.EMPTY_ARGUMENTS; - CPPTemplateParameterMap map= new CPPTemplateParameterMap(4); - args= TemplateArgumentDeduction.deduceForAddressOf(template, args, target, map); + CPPTemplateParameterMap map = new CPPTemplateParameterMap(4); + args = TemplateArgumentDeduction.deduceForAddressOf(template, args, target, map); if (args != null) { - IBinding instance= instantiateFunctionTemplate(template, args, map); + IBinding instance = instantiateFunctionTemplate(template, args, map); if (instance instanceof ICPPFunction) { return (ICPPFunction) instance; } @@ -2506,9 +2519,9 @@ public class CPPTemplates { for (int i = 0; i < argLen; i++) { final ICPPTemplateParameter tpar = tpars[i]; final ICPPTemplateArgument arg = uniqueArg(tpar); - args[i]= arg; + args[i] = arg; if (tpar.isParameterPack()) { - map.put(tpar, new ICPPTemplateArgument[] {arg}); + map.put(tpar, new ICPPTemplateArgument[] { arg }); } else { map.put(tpar, arg); } @@ -2524,7 +2537,8 @@ public class CPPTemplates { private static ICPPTemplateArgument uniqueArg(final ICPPTemplateParameter tpar) throws DOMException { final ICPPTemplateArgument arg; if (tpar instanceof ICPPTemplateNonTypeParameter) { - arg = new CPPTemplateNonTypeArgument(IntegralValue.unique(), ((ICPPTemplateNonTypeParameter) tpar).getType()); + arg = new CPPTemplateNonTypeArgument(IntegralValue.unique(), + ((ICPPTemplateNonTypeParameter) tpar).getType()); } else { arg = new CPPTemplateTypeArgument(new UniqueType(tpar.isParameterPack())); } @@ -2544,14 +2558,15 @@ public class CPPTemplates { } } ICPPFunctionType originalType = function.getType(); - if (i == parameters.length) // No parameters with default arguments. + if (i == parameters.length) // No parameters with default arguments. return originalType; - return new CPPFunctionType(originalType.getReturnType(), ArrayUtil.trim(parameterTypes), - originalType.isConst(), originalType.isVolatile(), originalType.hasRefQualifier(), - originalType.isRValueReference(), originalType.takesVarArgs()); + return new CPPFunctionType(originalType.getReturnType(), ArrayUtil.trim(parameterTypes), originalType.isConst(), + originalType.isVolatile(), originalType.hasRefQualifier(), originalType.isRValueReference(), + originalType.takesVarArgs()); } - private static int compareSpecialization(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2, TypeSelection mode) throws DOMException { + private static int compareSpecialization(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2, TypeSelection mode) + throws DOMException { ICPPFunction transF1 = transferFunctionTemplate(f1); if (transF1 == null) return -1; @@ -2564,24 +2579,24 @@ public class CPPTemplates { IType[] args; switch (mode) { case RETURN_TYPE: - pars= new IType[] {ft2.getReturnType()}; - args= new IType[] {transFt1.getReturnType()}; + pars = new IType[] { ft2.getReturnType() }; + args = new IType[] { transFt1.getReturnType() }; break; case PARAMETERS_AND_RETURN_TYPE: - pars= SemanticUtil.concatTypes(ft2.getReturnType(), ft2.getParameterTypes()); - args= SemanticUtil.concatTypes(transFt1.getReturnType(), transFt1.getParameterTypes()); + pars = SemanticUtil.concatTypes(ft2.getReturnType(), ft2.getParameterTypes()); + args = SemanticUtil.concatTypes(transFt1.getReturnType(), transFt1.getParameterTypes()); break; case PARAMETERS: default: - pars= ft2.getParameterTypes(); + pars = ft2.getParameterTypes(); args = transFt1.getParameterTypes(); - boolean nonStaticMember1= isNonStaticMember(f1); - boolean nonStaticMember2= isNonStaticMember(f2); + boolean nonStaticMember1 = isNonStaticMember(f1); + boolean nonStaticMember2 = isNonStaticMember(f2); if (nonStaticMember1 != nonStaticMember2) { if (nonStaticMember1) { - args= SemanticUtil.addImplicitParameterType(args, (ICPPMethod) f1); + args = SemanticUtil.addImplicitParameterType(args, (ICPPMethod) f1); } else { - pars= SemanticUtil.addImplicitParameterType(pars, (ICPPMethod) f2); + pars = SemanticUtil.addImplicitParameterType(pars, (ICPPMethod) f2); } } break; @@ -2597,7 +2612,7 @@ public class CPPTemplates { ICPPTemplateArgument[] args) throws DOMException { ICPPPartialSpecialization[] pspecs = template.getPartialSpecializations(); if (pspecs != null && pspecs.length > 0) { - final String argStr= ASTTypeUtil.getArgumentListString(args, true); + final String argStr = ASTTypeUtil.getArgumentListString(args, true); for (ICPPPartialSpecialization pspec : pspecs) { if (argStr.equals(ASTTypeUtil.getArgumentListString(pspec.getTemplateArguments(), true))) return pspec; @@ -2617,20 +2632,20 @@ public class CPPTemplates { } ICPPPartialSpecialization bestMatch = null; - CPPTemplateParameterMap bestMap= null; + CPPTemplateParameterMap bestMap = null; boolean bestMatchIsBest = true; for (ICPPPartialSpecialization specialization : specializations) { final CPPTemplateParameterMap map = new CPPTemplateParameterMap(args.length); ICPPTemplateArgument[] specializationArguments = specialization.getTemplateArguments(); - if (TemplateArgumentDeduction.fromTemplateArguments( - specialization.getTemplateParameters(), specializationArguments, args, map) && - checkInstantiationOfArguments(specializationArguments, map)) { + if (TemplateArgumentDeduction.fromTemplateArguments(specialization.getTemplateParameters(), + specializationArguments, args, map) + && checkInstantiationOfArguments(specializationArguments, map)) { int compare = orderSpecializations(bestMatch, specialization); if (compare == 0) { bestMatchIsBest = false; } else if (compare < 0) { bestMatch = specialization; - bestMap= map; + bestMap = map; bestMatchIsBest = true; } } @@ -2654,8 +2669,8 @@ public class CPPTemplates { return instantiatePartialSpecialization(bestMatch, args, isDef, bestMap); } - private static boolean checkInstantiationOfArguments(ICPPTemplateArgument[] args, - CPPTemplateParameterMap tpMap) throws DOMException { + private static boolean checkInstantiationOfArguments(ICPPTemplateArgument[] args, CPPTemplateParameterMap tpMap) + throws DOMException { return instantiateArguments(args, new InstantiationContext(tpMap), true) != null; } @@ -2692,7 +2707,7 @@ public class CPPTemplates { return -1; } - private static boolean isAtLeastAsSpecializedAs(ICPPPartialSpecialization f1, ICPPPartialSpecialization f2) + private static boolean isAtLeastAsSpecializedAs(ICPPPartialSpecialization f1, ICPPPartialSpecialization f2) throws DOMException { // 14.5.5.2 // Using the transformed parameter list, perform argument deduction against the other @@ -2707,27 +2722,28 @@ public class CPPTemplates { // Transfer arguments of specialization 1 final int tpars1Len = tpars1.length; ICPPTemplateArgument[] args = new ICPPTemplateArgument[tpars1Len]; - final CPPTemplateParameterMap transferMap= new CPPTemplateParameterMap(tpars1Len); + final CPPTemplateParameterMap transferMap = new CPPTemplateParameterMap(tpars1Len); for (int i = 0; i < tpars1Len; i++) { final ICPPTemplateParameter param = tpars1[i]; final ICPPTemplateArgument arg = uniqueArg(param); - args[i]= arg; + args[i] = arg; if (param.isParameterPack()) { transferMap.put(param, new ICPPTemplateArgument[] { arg }); } else { transferMap.put(param, arg); } } - final ICPPTemplateArgument[] transferredArgs1 = - instantiateArguments(targs1, new InstantiationContext(transferMap), false); + final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, + new InstantiationContext(transferMap), false); // Deduce arguments for specialization 2 - final CPPTemplateParameterMap deductionMap= new CPPTemplateParameterMap(2); + final CPPTemplateParameterMap deductionMap = new CPPTemplateParameterMap(2); return TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap); } static boolean isValidArgument(ICPPTemplateArgument arg) { - return arg != null && SemanticUtil.isValidType(arg.isTypeValue() ? arg.getTypeValue() : arg.getTypeOfNonTypeValue()); + return arg != null + && SemanticUtil.isValidType(arg.isTypeValue() ? arg.getTypeValue() : arg.getTypeOfNonTypeValue()); } static ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateDefinition template, @@ -2736,21 +2752,21 @@ public class CPPTemplates { return null; } if (param instanceof ICPPTemplateTypeParameter) { - IType t= arg.getTypeValue(); - if (t != null && ! (t instanceof ICPPTemplateDefinition)) + IType t = arg.getTypeValue(); + if (t != null && !(t instanceof ICPPTemplateDefinition)) return arg; return null; } if (param instanceof ICPPTemplateTemplateParameter) { - IType t= arg.getTypeValue(); + IType t = arg.getTypeValue(); if (t instanceof ICPPUnknownType) return arg; while (!(t instanceof ICPPTemplateDefinition)) { if (t instanceof ICPPClassSpecialization) { // Undo the effect of specializing a template when the unqualified name // is used within the template itself. - t= ((ICPPClassSpecialization) t).getSpecializedBinding(); + t = ((ICPPClassSpecialization) t).getSpecializedBinding(); } else { return null; } @@ -2773,14 +2789,14 @@ public class CPPTemplates { if (param instanceof ICPPTemplateNonTypeParameter) { if (!arg.isNonTypeValue()) return null; - IType argType= arg.getTypeOfNonTypeValue(); + IType argType = arg.getTypeOfNonTypeValue(); try { IType pType = ((ICPPTemplateNonTypeParameter) param).getType(); if (pType instanceof ICPPParameterPackType) { - pType= ((ICPPParameterPackType) pType).getType(); + pType = ((ICPPParameterPackType) pType).getType(); } if (map != null && pType != null) { - pType= instantiateType(pType, new InstantiationContext(map)); + pType = instantiateType(pType, new InstantiationContext(map)); } if (argType instanceof ICPPParameterPackType) { @@ -2800,8 +2816,8 @@ public class CPPTemplates { private static boolean matchTemplateTemplateParameters(ICPPTemplateParameter[] pParams, ICPPTemplateParameter[] aParams) throws DOMException { - int pi= 0; - int ai= 0; + int pi = 0; + int ai = 0; while (pi < pParams.length && ai < aParams.length) { final ICPPTemplateParameter pp = pParams[pi]; final ICPPTemplateParameter ap = aParams[ai]; @@ -2810,31 +2826,30 @@ public class CPPTemplates { if (ap.isParameterPack() && !pp.isParameterPack()) return false; - - boolean pb= pp instanceof ICPPTemplateTypeParameter; - boolean ab= ap instanceof ICPPTemplateTypeParameter; + boolean pb = pp instanceof ICPPTemplateTypeParameter; + boolean ab = ap instanceof ICPPTemplateTypeParameter; if (pb != ab) return false; if (pb) { // Both are template type parameters } else { - pb= pp instanceof ICPPTemplateNonTypeParameter; - ab= ap instanceof ICPPTemplateNonTypeParameter; + pb = pp instanceof ICPPTemplateNonTypeParameter; + ab = ap instanceof ICPPTemplateNonTypeParameter; if (pb != ab) return false; if (pb) { // Both are non-type parameters } else { - if (!(pp instanceof ICPPTemplateTemplateParameter) || - !(ap instanceof ICPPTemplateTemplateParameter)) { + if (!(pp instanceof ICPPTemplateTemplateParameter) + || !(ap instanceof ICPPTemplateTemplateParameter)) { assert false; return false; } if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(), - ((ICPPTemplateTemplateParameter) ap).getTemplateParameters())) + ((ICPPTemplateTemplateParameter) ap).getTemplateParameters())) return false; } } @@ -2860,7 +2875,7 @@ public class CPPTemplates { private static ICPPTemplateArgument convertNonTypeTemplateArgument(ICPPTemplateDefinition template, final IType paramType, ICPPTemplateArgument arg) throws DOMException { // 14.1s8 function to pointer and array to pointer conversions. - IType a= arg.getTypeOfNonTypeValue(); + IType a = arg.getTypeOfNonTypeValue(); if (a instanceof ICPPParameterPackType) { a = ((ICPPParameterPackType) a).getType(); } @@ -2870,14 +2885,14 @@ public class CPPTemplates { } else if (paramType instanceof IArrayType) { p = new CPPPointerType(((IArrayType) paramType).getType()); } else { - p= paramType; + p = paramType; if (p != null && p.isSameType(a)) return arg; } if (a instanceof FunctionSetType) { if (p instanceof IPointerType) { - p= ((IPointerType) p).getType(); + p = ((IPointerType) p).getType(); } if (p instanceof IFunctionType) { final CPPFunctionSet functionSet = ((FunctionSetType) a).getFunctionSet(); @@ -2899,8 +2914,7 @@ public class CPPTemplates { } } - Cost cost = Conversions.checkImplicitConversionSequence(p, a, LVALUE, UDCMode.FORBIDDEN, - Context.ORDINARY); + Cost cost = Conversions.checkImplicitConversionSequence(p, a, LVALUE, UDCMode.FORBIDDEN, Context.ORDINARY); if (cost == null || !cost.converts()) { ICPPEvaluation eval = arg.getNonTypeEvaluation(); ICPPEvaluation newEval = CPPEvaluation.maybeApplyConversion(eval, p, false); @@ -2917,18 +2931,18 @@ public class CPPTemplates { return false; } for (int i = 0; i < args.length; i++) { - ICPPTemplateParameter par= pars[i]; + ICPPTemplateParameter par = pars[i]; ICPPTemplateArgument arg = args[i]; if (par instanceof IType) { if (arg.isNonTypeValue()) return false; - IType argType= arg.getTypeValue(); + IType argType = arg.getTypeValue(); if (argType == null) return false; if (par.isParameterPack()) { if (!(argType instanceof ICPPParameterPackType)) return false; - argType= ((ICPPParameterPackType) argType).getType(); + argType = ((ICPPParameterPackType) argType).getType(); if (argType == null) return false; } @@ -2939,7 +2953,7 @@ public class CPPTemplates { return false; if (par.isParameterPack() != arg.isPackExpansion()) return false; - int parpos= IntegralValue.isTemplateParameter(arg.getNonTypeValue()); + int parpos = IntegralValue.isTemplateParameter(arg.getNonTypeValue()); if (parpos != par.getParameterID()) return false; } @@ -2988,21 +3002,21 @@ public class CPPTemplates { final ICPPFunctionType ft = (ICPPFunctionType) t; if (containsDependentType(ft.getParameterTypes())) return true; - t= ft.getReturnType(); + t = ft.getReturnType(); } else if (t instanceof ICPPPointerToMemberType) { - ICPPPointerToMemberType ptmt= (ICPPPointerToMemberType) t; + ICPPPointerToMemberType ptmt = (ICPPPointerToMemberType) t; if (isDependentType(ptmt.getMemberOfClass())) return true; - t= ptmt.getType(); + t = ptmt.getType(); } else if (t instanceof ICPPParameterPackType) { return true; } else if (t instanceof ITypeContainer) { if (t instanceof IArrayType) { - IValue asize= ((IArrayType) t).getSize(); + IValue asize = ((IArrayType) t).getSize(); if (asize != null && IntegralValue.isDependentValue(asize)) return true; } - t= ((ITypeContainer) t).getType(); + t = ((ITypeContainer) t).getType(); } else if (t instanceof InitializerListType) { return ((InitializerListType) t).getEvaluation().isTypeDependent(); } else if (t instanceof IBinding) { @@ -3045,12 +3059,12 @@ public class CPPTemplates { return resolveUnknownMember((ICPPUnknownMember) unknown, context); } if (unknown instanceof ICPPTemplateParameter && unknown instanceof IType) { - IType type= resolveTemplateTypeParameter((ICPPTemplateParameter) unknown, context); + IType type = resolveTemplateTypeParameter((ICPPTemplateParameter) unknown, context); if (type instanceof IBinding) return (IBinding) type; } if (unknown instanceof TypeOfDependentExpression) { - IType type= instantiateType((IType) unknown, context); + IType type = instantiateType((IType) unknown, context); if (type instanceof IBinding) return (IBinding) type; } @@ -3059,7 +3073,7 @@ public class CPPTemplates { private static IBinding resolveUnknownMember(ICPPUnknownMember unknown, InstantiationContext context) throws DOMException { - final IType ot0= unknown.getOwnerType(); + final IType ot0 = unknown.getOwnerType(); if (ot0 == null) return unknown; @@ -3069,27 +3083,26 @@ public class CPPTemplates { ot1 = SemanticUtil.getUltimateType(ot1, false); if (ot1 instanceof ICPPUnknownType) { if (unknown instanceof ICPPUnknownMemberClassInstance) { - ICPPUnknownMemberClassInstance ucli= (ICPPUnknownMemberClassInstance) unknown; + ICPPUnknownMemberClassInstance ucli = (ICPPUnknownMemberClassInstance) unknown; ICPPTemplateArgument[] args0 = ucli.getArguments(); ICPPTemplateArgument[] args1 = instantiateArguments(args0, context, false); if (args0 != args1 || !ot1.isSameType(ot0)) { - args1= SemanticUtil.getSimplifiedArguments(args1); - result= new CPPUnknownClassInstance(ot1, ucli.getNameCharArray(), args1); + args1 = SemanticUtil.getSimplifiedArguments(args1); + result = new CPPUnknownClassInstance(ot1, ucli.getNameCharArray(), args1); } } else if (!ot1.isSameType(ot0)) { if (unknown instanceof ICPPUnknownMemberClass) { - result= new CPPUnknownMemberClass(ot1, unknown.getNameCharArray()); + result = new CPPUnknownMemberClass(ot1, unknown.getNameCharArray()); } else { - result= new CPPUnknownMethod(ot1, unknown.getNameCharArray()); + result = new CPPUnknownMethod(ot1, unknown.getNameCharArray()); } } } else if (ot1 instanceof ICPPClassType) { IScope s = ((ICPPClassType) ot1).getCompositeScope(); if (s != null) { - result= CPPSemantics.resolveUnknownName(s, unknown); - if (unknown instanceof ICPPUnknownMemberClassInstance && - (result instanceof ICPPTemplateDefinition || - result instanceof ICPPAliasTemplateInstance)) { + result = CPPSemantics.resolveUnknownName(s, unknown); + if (unknown instanceof ICPPUnknownMemberClassInstance && (result instanceof ICPPTemplateDefinition + || result instanceof ICPPAliasTemplateInstance)) { ICPPTemplateArgument[] args1 = instantiateArguments( ((ICPPUnknownMemberClassInstance) unknown).getArguments(), context, false); if (result instanceof ICPPClassTemplate) { @@ -3100,7 +3113,7 @@ public class CPPTemplates { } } } else if (ot1 != ot0) { - return new ProblemBinding(new CPPASTName(unknown.getNameCharArray()), + return new ProblemBinding(new CPPASTName(unknown.getNameCharArray()), CPPSemantics.getCurrentLookupPoint(), IProblemBinding.SEMANTIC_BAD_SCOPE); } } @@ -3120,12 +3133,12 @@ public class CPPTemplates { if (newArgs == null) return createProblem(classTemplate, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); - boolean changed= arguments != newArgs; - IType classTemplateSpecialization= instantiateType(classTemplate, context); + boolean changed = arguments != newArgs; + IType classTemplateSpecialization = instantiateType(classTemplate, context); if (classTemplateSpecialization != classTemplate) { if (classTemplateSpecialization instanceof ICPPClassTemplate) { - classTemplate= (ICPPClassTemplate) classTemplateSpecialization; - changed= true; + classTemplate = (ICPPClassTemplate) classTemplateSpecialization; + changed = true; } else if (classTemplateSpecialization instanceof ICPPAliasTemplate) { IBinding inst = instantiateAliasTemplate((ICPPAliasTemplate) classTemplateSpecialization, newArgs); if (inst != null) @@ -3134,14 +3147,14 @@ public class CPPTemplates { } if (changed) { - IBinding inst= instantiate(classTemplate, newArgs); + IBinding inst = instantiate(classTemplate, newArgs); if (inst != null) return inst; } return dci; } - - private static IBinding resolveDeferredVariableInstance(ICPPDeferredVariableInstance dvi, + + private static IBinding resolveDeferredVariableInstance(ICPPDeferredVariableInstance dvi, InstantiationContext context) { ICPPVariableTemplate variableTemplate = dvi.getTemplateDefinition(); ICPPTemplateArgument[] arguments = dvi.getTemplateArguments(); @@ -3154,10 +3167,10 @@ public class CPPTemplates { if (newArgs == null) { return createProblem(variableTemplate, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); } - + // Unlike class templates, variable templates cannot be passed as template template arguments, // so there is no need to instantiate the template itself. - + if (arguments != newArgs) { IBinding inst = instantiate(variableTemplate, newArgs); if (inst != null) @@ -3167,8 +3180,8 @@ public class CPPTemplates { } public static boolean haveSameArguments(ICPPTemplateInstance i1, ICPPTemplateInstance i2) { - final ICPPTemplateArgument[] m1= i1.getTemplateArguments(); - final ICPPTemplateArgument[] m2= i2.getTemplateArguments(); + final ICPPTemplateArgument[] m1 = i1.getTemplateArguments(); + final ICPPTemplateArgument[] m2 = i2.getTemplateArguments(); if (m1 == null || m2 == null || m1.length != m2.length) return false; @@ -3190,30 +3203,29 @@ public class CPPTemplates { */ private static CPPTemplateParameterMap createParameterMap(ICPPTemplateDefinition template, ICPPTemplateArgument[] arguments) { - final ICPPTemplateParameter[] parameters= template.getTemplateParameters(); + final ICPPTemplateParameter[] parameters = template.getTemplateParameters(); final int numArgs = arguments.length; - final int numParams= parameters.length; - final int length= Math.max(numArgs, numParams); + final int numParams = parameters.length; + final int length = Math.max(numArgs, numParams); - CPPTemplateParameterMap map= new CPPTemplateParameterMap(numParams); + CPPTemplateParameterMap map = new CPPTemplateParameterMap(numParams); - boolean isPack= false; - ICPPTemplateParameter param= null; + boolean isPack = false; + ICPPTemplateParameter param = null; for (int i = 0; i < length; i++) { if (!isPack || param == null) { if (i >= numParams) return null; - param= parameters[i]; - isPack= param.isParameterPack(); + param = parameters[i]; + isPack = param.isParameterPack(); } if (i < numArgs) { - ICPPTemplateArgument arg= arguments[i]; - ICPPTemplateArgument newArg = - matchTemplateParameterAndArgument(template, param, arg, map); + ICPPTemplateArgument arg = arguments[i]; + ICPPTemplateArgument newArg = matchTemplateParameterAndArgument(template, param, arg, map); if (newArg == null) return null; if (newArg != arg) { - arguments[i]= newArg; + arguments[i] = newArg; } if (!isPack) { map.put(param, newArg); @@ -3225,9 +3237,9 @@ public class CPPTemplates { } if (isPack) { - int packOffset= numParams - 1; - int packSize= numArgs - packOffset; - ICPPTemplateArgument[] pack= new ICPPTemplateArgument[packSize]; + int packOffset = numParams - 1; + int packSize = numArgs - packOffset; + ICPPTemplateArgument[] pack = new ICPPTemplateArgument[packSize]; System.arraycopy(arguments, packOffset, pack, 0, packSize); map.put(param, pack); } @@ -3239,10 +3251,10 @@ public class CPPTemplates { if (ASTInternal.hasDeclaration(binding)) return binding; - IBinding original= ((ICPPSpecialization) binding).getSpecializedBinding(); + IBinding original = ((ICPPSpecialization) binding).getSpecializedBinding(); if (original == null) return binding; - binding= original; + binding = original; } return binding; } @@ -3263,8 +3275,8 @@ public class CPPTemplates { } return exec; } - private static void addInstantiatedParameters(InstantiationContext context, - ICPPFunctionSpecialization spec) { + + private static void addInstantiatedParameters(InstantiationContext context, ICPPFunctionSpecialization spec) { ICPPFunction specialized = (ICPPFunction) spec.getSpecializedBinding(); ICPPParameter paramSpecs[] = spec.getParameters(); ICPPParameter specializedParams[] = specialized.getParameters(); @@ -3304,12 +3316,12 @@ public class CPPTemplates { } return new String(name).substring(1).trim(); } - + /** * Instantiate a plain name (simple-id). * Only destructor names require instantiation, e.g. the name "~T", when instantiated * with a parameter map that maps T to C, needs to become "~C". - * + * * @param name the name to be instantiated * @param context the instantiation context * @param enclosingTemplate The enclosing template definition. This is required because the @@ -3318,11 +3330,11 @@ public class CPPTemplates { * template parameter names. * @return The instantiated name. If the provided name is not a destructor name, or if * the type named by the destructor name is not mapped to anything in the - * instantiation context's parameter map, the provided name is returned unchanged. + * instantiation context's parameter map, the provided name is returned unchanged. */ public static char[] instantiateName(char[] name, InstantiationContext context, IBinding enclosingTemplate) { String typename = unwrapDestructorName(name); - if (typename == null) { // not a destructor-name + if (typename == null) { // not a destructor-name return name; } ICPPTemplateParameterMap map = context.getParameterMap(); @@ -3358,7 +3370,7 @@ public class CPPTemplates { } return name; } - + /** * Checks whether a binding is fully instantiated, that is, it does not depend on template * parameters that do not yet have values. @@ -3386,12 +3398,12 @@ public class CPPTemplates { } return null; } - + private static IType getCachedInstantiation(TypeInstantiationRequest instantiationRequest) { Map<TypeInstantiationRequest, IType> cache = getInstantiationCache(); return cache != null ? cache.get(instantiationRequest) : null; } - + private static void putCachedInstantiation(TypeInstantiationRequest instantiationRequest, IType result) { Map<TypeInstantiationRequest, IType> cache = getInstantiationCache(); if (cache != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java index d5e2070b24f..6f8b4d518c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java @@ -47,7 +47,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; * with the variable. */ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { - private static CPPVariableReadWriteFlags INSTANCE= new CPPVariableReadWriteFlags(); + private static CPPVariableReadWriteFlags INSTANCE = new CPPVariableReadWriteFlags(); public static int getReadWriteFlags(IASTName variable) { CPPSemantics.pushLookupPoint(variable); @@ -65,7 +65,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { return rwInCtorInitializer(node, indirection, (ICPPASTConstructorInitializer) parent); } if (parent instanceof ICPPASTFieldDesignator) { - return WRITE; // Field is initialized via a designated initializer. + return WRITE; // Field is initialized via a designated initializer. } return super.rwAnyNode(node, indirection); } @@ -73,25 +73,24 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { @Override protected int rwInDeclarator(IASTDeclarator parent, int indirection) { IType type = CPPVisitor.createType(parent); - if (type instanceof ICPPUnknownType || - type instanceof ICPPClassType && - !TypeTraits.hasTrivialDefaultConstructor((ICPPClassType) type, CPPSemantics.MAX_INHERITANCE_DEPTH)) { + if (type instanceof ICPPUnknownType || type instanceof ICPPClassType + && !TypeTraits.hasTrivialDefaultConstructor((ICPPClassType) type, CPPSemantics.MAX_INHERITANCE_DEPTH)) { return WRITE; } return super.rwInDeclarator(parent, indirection); } private int rwInCtorInitializer(IASTNode node, int indirection, ICPPASTConstructorInitializer parent) { - IASTNode grand= parent.getParent(); + IASTNode grand = parent.getParent(); if (grand instanceof IASTDeclarator || grand instanceof ICPPASTNewExpression) { // Look for a constructor being called. if (grand instanceof IASTImplicitNameOwner) { IASTImplicitName[] names = ((IASTImplicitNameOwner) grand).getImplicitNames(); for (IASTImplicitName in : names) { - IBinding b= in.resolveBinding(); + IBinding b = in.resolveBinding(); if (b instanceof ICPPConstructor) { final ICPPConstructor ctor = (ICPPConstructor) b; - int idx= 0; + int idx = 0; for (IASTInitializerClause child : parent.getArguments()) { if (child == node) { return rwArgumentForFunctionCall(ctor.getType(), idx, child, indirection); @@ -103,14 +102,14 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { } // Allow for initialization of primitive types. if (grand instanceof IASTDeclarator && parent.getArguments().length == 1) { - IBinding binding= ((IASTDeclarator) grand).getName().getBinding(); + IBinding binding = ((IASTDeclarator) grand).getName().getBinding(); if (binding instanceof IVariable) { - IType type= ((IVariable) binding).getType(); + IType type = ((IVariable) binding).getType(); return rwAssignmentToType(type, indirection); } } } - return READ | WRITE; // fallback + return READ | WRITE; // fallback } @Override @@ -125,7 +124,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { @Override protected int rwInFunctionName(IASTExpression node) { if (!(node instanceof IASTIdExpression)) { - IType type= node.getExpressionType(); + IType type = node.getExpressionType(); if (type instanceof ICPPFunctionType && !((ICPPFunctionType) type).isConst()) return READ | WRITE; } @@ -138,13 +137,13 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { if (!(type instanceof ICPPReferenceType) || ((ICPPReferenceType) type).isRValueReference()) { return READ; } - type= ((ICPPReferenceType) type).getType(); + type = ((ICPPReferenceType) type).getType(); } while (indirection > 0 && (type instanceof ITypeContainer)) { if (type instanceof IPointerType) { indirection--; } - type= ((ITypeContainer) type).getType(); + type = ((ITypeContainer) type).getType(); } if (indirection == 0) { if (type instanceof IQualifierType) { @@ -153,6 +152,6 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { return ((IPointerType) type).isConst() ? READ : READ | WRITE; } } - return READ | WRITE; // fallback + return READ | WRITE; // fallback } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 494203cecad..d39a95274a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -242,7 +242,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; public class CPPVisitor extends ASTQueries { public static final String BEGIN_STR = "begin"; //$NON-NLS-1$ public static final char[] BEGIN = BEGIN_STR.toCharArray(); - public static final char[] END = "end".toCharArray(); //$NON-NLS-1$ + public static final char[] END = "end".toCharArray(); //$NON-NLS-1$ public static final String STD = "std"; //$NON-NLS-1$ private static final char[] SIZE_T = "size_t".toCharArray(); //$NON-NLS-1$ private static final char[] PTRDIFF_T = "ptrdiff_t".toCharArray(); //$NON-NLS-1$ @@ -252,22 +252,21 @@ public class CPPVisitor extends ASTQueries { public static final IASTInitializerClause[] NO_ARGS = {}; // Flags for createType(). - + // Attempt to resolve placeholders ('auto' and 'decltype(auto)'). public static final int RESOLVE_PLACEHOLDERS = 0x1; - + // Given a function declarator, compute only the return type rather than // the entire function type. public static final int ONLY_RETURN_TYPE = 0x2; - + // Common combinations of flags. public static final int DO_NOT_RESOLVE_PLACEHOLDERS = 0; - + // Thread-local set of declarators for which auto types are being created. // Used to prevent infinite recursion while processing invalid self-referencing // auto-type declarations. - private static final ThreadLocal<Set<IASTDeclarator>> autoTypeDeclarators = - new ThreadLocal<Set<IASTDeclarator>>() { + private static final ThreadLocal<Set<IASTDeclarator>> autoTypeDeclarators = new ThreadLocal<Set<IASTDeclarator>>() { @Override protected Set<IASTDeclarator> initialValue() { return new HashSet<>(); @@ -277,18 +276,17 @@ public class CPPVisitor extends ASTQueries { public static IBinding createBinding(IASTName name) { IASTNode parent = name.getParent(); IBinding binding = null; - if (parent instanceof IASTNamedTypeSpecifier || - parent instanceof ICPPASTBaseSpecifier || - parent instanceof ICPPASTConstructorChainInitializer || - (parent instanceof ICPPASTCapture && !(parent instanceof ICPPASTInitCapture)) || - name.getPropertyInParent() == ICPPASTNamespaceAlias.MAPPING_NAME) { - if (name.getLookupKey().length == 0) - return null; + if (parent instanceof IASTNamedTypeSpecifier || parent instanceof ICPPASTBaseSpecifier + || parent instanceof ICPPASTConstructorChainInitializer + || (parent instanceof ICPPASTCapture && !(parent instanceof ICPPASTInitCapture)) + || name.getPropertyInParent() == ICPPASTNamespaceAlias.MAPPING_NAME) { + if (name.getLookupKey().length == 0) + return null; return CPPSemantics.resolveBinding(name); } else if (parent instanceof ICPPASTQualifiedName) { - if (name.getLookupKey().length == 0) - return null; + if (name.getLookupKey().length == 0) + return null; final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; if (name != qname.getLastName()) @@ -331,13 +329,13 @@ public class CPPVisitor extends ASTQueries { } else if (parent instanceof IASTDeclaration) { return createBinding((IASTDeclaration) parent); } else if (parent instanceof ICPPASTEnumerationSpecifier) { - return createBinding((ICPPASTEnumerationSpecifier) parent); + return createBinding((ICPPASTEnumerationSpecifier) parent); } else if (parent instanceof IASTEnumerator) { - return createBinding((IASTEnumerator) parent); + return createBinding((IASTEnumerator) parent); } else if (parent instanceof IASTGotoStatement) { - return resolveBinding((IASTGotoStatement) parent); + return resolveBinding((IASTGotoStatement) parent); } else if (parent instanceof IASTLabelStatement) { - return createBinding((IASTLabelStatement) parent); + return createBinding((IASTLabelStatement) parent); } else if (parent instanceof ICPPASTTemplateParameter) { return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent); } else if (parent instanceof ICPPASTFieldDesignator) { @@ -350,18 +348,18 @@ public class CPPVisitor extends ASTQueries { } private static boolean declaresMemberInClassOrNamespace(ICPPASTQualifiedName qname) { - ICPPASTNameSpecifier[] qualifier= qname.getQualifier(); + ICPPASTNameSpecifier[] qualifier = qname.getQualifier(); if (qualifier.length == 0) return false; - IASTNode parent= qname.getParent(); - IASTNode decl= null; + IASTNode parent = qname.getParent(); + IASTNode decl = null; if (parent instanceof IASTCompositeTypeSpecifier) { - decl= parent.getParent(); + decl = parent.getParent(); } else if (parent instanceof IASTDeclarator) { - decl= ASTQueries.findOutermostDeclarator((IASTDeclarator) parent).getParent(); + decl = ASTQueries.findOutermostDeclarator((IASTDeclarator) parent).getParent(); } - IScope inScope= null; + IScope inScope = null; while (decl != null) { ASTNodeProperty prop = decl.getPropertyInParent(); if (prop == IASTCompositeTypeSpecifier.MEMBER_DECLARATION) { @@ -371,7 +369,7 @@ public class CPPVisitor extends ASTQueries { inScope = ((ICPPASTNamespaceDefinition) decl.getParent()).getScope(); break; } else if (prop == ICPPASTTemplateDeclaration.OWNED_DECLARATION) { - decl= decl.getParent(); + decl = decl.getParent(); } else { return false; } @@ -380,18 +378,18 @@ public class CPPVisitor extends ASTQueries { if (inScope == null) return false; - IBinding pb= qualifier[qualifier.length - 1].resolvePreBinding(); + IBinding pb = qualifier[qualifier.length - 1].resolvePreBinding(); if (pb instanceof IProblemBinding) return false; - IScope scope= null; + IScope scope = null; if (pb instanceof IType) { - IType t= SemanticUtil.getNestedType((IType) pb, TDEF); + IType t = SemanticUtil.getNestedType((IType) pb, TDEF); if (t instanceof ICPPClassType) { - scope= ((ICPPClassType) t).getCompositeScope(); + scope = ((ICPPClassType) t).getCompositeScope(); } } else if (pb instanceof ICPPNamespace) { - scope= ((ICPPNamespace) pb).getNamespaceScope(); + scope = ((ICPPNamespace) pb).getNamespaceScope(); } return scope == inScope; @@ -402,42 +400,42 @@ public class CPPVisitor extends ASTQueries { } private static IBinding createBinding(IASTLabelStatement labelStatement) { - IASTName name = labelStatement.getName(); - ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope(name); - IBinding binding = functionScope.getBinding(name, false); + IASTName name = labelStatement.getName(); + ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope(name); + IBinding binding = functionScope.getBinding(name, false); if (binding == null || !(binding instanceof ILabel)) { - binding = new CPPLabel(name); - ASTInternal.addName(functionScope, name); + binding = new CPPLabel(name); + ASTInternal.addName(functionScope, name); } else { - ((CPPLabel) binding).setLabelStatement(name); + ((CPPLabel) binding).setLabelStatement(name); } - return binding; + return binding; } - private static IBinding createBinding(IASTEnumerator enumerator) { - ICPPScope scope = (ICPPScope) getContainingScope(enumerator); - IBinding enumtor; - enumtor = scope.getBinding(enumerator.getName(), false); + private static IBinding createBinding(IASTEnumerator enumerator) { + ICPPScope scope = (ICPPScope) getContainingScope(enumerator); + IBinding enumtor; + enumtor = scope.getBinding(enumerator.getName(), false); if (enumtor == null || !(enumtor instanceof IEnumerator)) { - enumtor = new CPPEnumerator(enumerator.getName()); + enumtor = new CPPEnumerator(enumerator.getName()); } - return enumtor; - } + return enumtor; + } - private static IBinding createBinding(ICPPASTEnumerationSpecifier specifier) { - ICPPScope scope = (ICPPScope) getContainingScope(specifier); - final IASTName name = specifier.getName(); - IType fixedType= createEnumBaseType(specifier); + private static IBinding createBinding(ICPPASTEnumerationSpecifier specifier) { + ICPPScope scope = (ICPPScope) getContainingScope(specifier); + final IASTName name = specifier.getName(); + IType fixedType = createEnumBaseType(specifier); IBinding binding = scope.getBinding(name, false); if (binding instanceof CPPEnumeration) { - CPPEnumeration e= (CPPEnumeration) binding; + CPPEnumeration e = (CPPEnumeration) binding; if (name.equals(e.getDefinition())) { return e; } if (e.isScoped() == specifier.isScoped()) { - IType ft2= e.getFixedType(); + IType ft2 = e.getFixedType(); if (fixedType == ft2 || (fixedType != null && fixedType.isSameType(ft2))) { if (specifier.isOpaque()) { e.addDeclaration(name); @@ -459,12 +457,12 @@ public class CPPVisitor extends ASTQueries { fixedType = CPPBasicType.INT; } return new CPPEnumeration(specifier, fixedType); - } + } private static IType createEnumBaseType(ICPPASTEnumerationSpecifier specifier) { ICPPASTDeclSpecifier declspec = specifier.getBaseType(); if (declspec != null) { - IType type= createType(declspec); + IType type = createType(declspec); return SemanticUtil.getNestedType(type, ALLCVQ); } if (specifier.isScoped()) { @@ -474,116 +472,114 @@ public class CPPVisitor extends ASTQueries { } private static IBinding createBinding(final ICPPASTElaboratedTypeSpecifier elabType) { - final IASTNode parent = elabType.getParent(); - IBinding binding = null; - boolean mustBeSimple = true; - boolean isFriend = false; - boolean qualified = false; - IASTName name = elabType.getName(); - if (name instanceof ICPPASTQualifiedName) { - qualified = true; - name = name.getLastName(); - } - if (parent instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) parent; - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) simpleDeclaration.getDeclSpecifier(); + final IASTNode parent = elabType.getParent(); + IBinding binding = null; + boolean mustBeSimple = true; + boolean isFriend = false; + boolean qualified = false; + IASTName name = elabType.getName(); + if (name instanceof ICPPASTQualifiedName) { + qualified = true; + name = name.getLastName(); + } + if (parent instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) parent; + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) simpleDeclaration.getDeclSpecifier(); IASTDeclarator[] dtors = simpleDeclaration.getDeclarators(); - isFriend = declSpec.isFriend() && dtors.length == 0; - if (dtors.length != 0 || isFriend) { - binding = CPPSemantics.resolveBinding(name); - mustBeSimple = !isFriend; - } else { - mustBeSimple = false; - } - } else if (parent instanceof IASTParameterDeclaration || - parent instanceof IASTDeclaration || - parent instanceof IASTTypeId) { - binding = CPPSemantics.resolveBinding(elabType.getName()); - } - if (binding instanceof IIndexBinding && binding instanceof ICPPClassType) { - binding= (ICPPClassType) SemanticUtil.mapToAST((ICPPClassType) binding); - ASTInternal.addDeclaration(binding, elabType); - } - - if (binding != null && - (!(binding instanceof IProblemBinding) || - ((IProblemBinding) binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND)) { + isFriend = declSpec.isFriend() && dtors.length == 0; + if (dtors.length != 0 || isFriend) { + binding = CPPSemantics.resolveBinding(name); + mustBeSimple = !isFriend; + } else { + mustBeSimple = false; + } + } else if (parent instanceof IASTParameterDeclaration || parent instanceof IASTDeclaration + || parent instanceof IASTTypeId) { + binding = CPPSemantics.resolveBinding(elabType.getName()); + } + if (binding instanceof IIndexBinding && binding instanceof ICPPClassType) { + binding = (ICPPClassType) SemanticUtil.mapToAST((ICPPClassType) binding); + ASTInternal.addDeclaration(binding, elabType); + } + + if (binding != null && (!(binding instanceof IProblemBinding) + || ((IProblemBinding) binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND)) { return binding; - } + } // 7.1.5.3-2 ... If name lookup does not find a declaration for the name, the elaborated-type-specifier is ill-formed // unless it is of the simple form class-key identifier - if (mustBeSimple && - (elabType.getName() instanceof ICPPASTQualifiedName || elabType.getKind() == IASTElaboratedTypeSpecifier.k_enum)) { - return binding; - } - - try { - ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration(name); - ICPPScope scope = (ICPPScope) getContainingScope(name); - while (scope instanceof ICPPTemplateScope) { - scope= (ICPPScope) scope.getParent(); - } - - if (mustBeSimple) { - // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype - // scope that contains the declaration. - while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) { - scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit()); - } - } - if (scope instanceof ICPPClassScope && isFriend && !qualified) { - while (scope instanceof ICPPClassScope) { - scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit()); - } - } - if (scope != null) { - binding = scope.getBinding(elabType.getName(), false); - if (binding instanceof ICPPUsingDeclaration) { - IBinding[] expanded = ((ICPPUsingDeclaration) binding).getDelegates(); - if (expanded.length == 1 && expanded[0] instanceof IType) { - binding= expanded[0]; - } - } - } - if (binding instanceof ICPPInternalBinding) { - if (!name.isActive()) - return binding; - - if (binding instanceof ICPPClassType) { - ICPPInternalBinding internalBinding = (ICPPInternalBinding) binding; - if (templateParametersMatch((ICPPClassType) binding, templateDecl)) { - internalBinding.addDeclaration(elabType); - return binding; - } - - if (CPPSemantics.declaredBefore(internalBinding, name, false)) { - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } - markRedeclaration(internalBinding); - } - } - - // Create a binding. - if (elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum) { - if (templateDecl != null) { - binding = new CPPClassTemplate(name); - } else { - binding = new CPPClassType(name, binding); - } - // Name may live in a different scope, so make sure to add it to the owner scope as well. - // [namespace.memdef] p3: - // "If a friend declaration in a non-local class first declares a - // class, function, class template or function template the friend - // is a member of the innermost enclosing namespace. The friend - // declaration does not by itself make the name visible to - // unqualified lookup or qualified lookup." - boolean visibleToAdlOnly = isFriend; - ASTInternal.addName(scope, elabType.getName(), visibleToAdlOnly); - } - } catch (DOMException e) { - binding = e.getProblem(); - } + if (mustBeSimple && (elabType.getName() instanceof ICPPASTQualifiedName + || elabType.getKind() == IASTElaboratedTypeSpecifier.k_enum)) { + return binding; + } + + try { + ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration(name); + ICPPScope scope = (ICPPScope) getContainingScope(name); + while (scope instanceof ICPPTemplateScope) { + scope = (ICPPScope) scope.getParent(); + } + + if (mustBeSimple) { + // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype + // scope that contains the declaration. + while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) { + scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit()); + } + } + if (scope instanceof ICPPClassScope && isFriend && !qualified) { + while (scope instanceof ICPPClassScope) { + scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit()); + } + } + if (scope != null) { + binding = scope.getBinding(elabType.getName(), false); + if (binding instanceof ICPPUsingDeclaration) { + IBinding[] expanded = ((ICPPUsingDeclaration) binding).getDelegates(); + if (expanded.length == 1 && expanded[0] instanceof IType) { + binding = expanded[0]; + } + } + } + if (binding instanceof ICPPInternalBinding) { + if (!name.isActive()) + return binding; + + if (binding instanceof ICPPClassType) { + ICPPInternalBinding internalBinding = (ICPPInternalBinding) binding; + if (templateParametersMatch((ICPPClassType) binding, templateDecl)) { + internalBinding.addDeclaration(elabType); + return binding; + } + + if (CPPSemantics.declaredBefore(internalBinding, name, false)) { + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } + markRedeclaration(internalBinding); + } + } + + // Create a binding. + if (elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum) { + if (templateDecl != null) { + binding = new CPPClassTemplate(name); + } else { + binding = new CPPClassType(name, binding); + } + // Name may live in a different scope, so make sure to add it to the owner scope as well. + // [namespace.memdef] p3: + // "If a friend declaration in a non-local class first declares a + // class, function, class template or function template the friend + // is a member of the innermost enclosing namespace. The friend + // declaration does not by itself make the name visible to + // unqualified lookup or qualified lookup." + boolean visibleToAdlOnly = isFriend; + ASTInternal.addName(scope, elabType.getName(), visibleToAdlOnly); + } + } catch (DOMException e) { + binding = e.getProblem(); + } return binding; } @@ -608,9 +604,9 @@ public class CPPVisitor extends ASTQueries { return false; IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) typeSpec.getParent(); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) declaration.getDeclSpecifier(); - return declSpec.isFriend() && declaration.getDeclarators().length == 0; + return declSpec.isFriend() && declaration.getDeclarators().length == 0; } - + public static void markRedeclaration(final ICPPInternalBinding ib) { // Mark the other declarations as problem and create the binding final IASTNode[] decls = ib.getDeclarations(); @@ -622,7 +618,7 @@ public class CPPVisitor extends ASTQueries { } } } - IASTNode decl= ib.getDefinition(); + IASTNode decl = ib.getDefinition(); if (decl instanceof IASTName) { final IASTName n = (IASTName) decl; n.setBinding(new ProblemBinding(n, IProblemBinding.SEMANTIC_INVALID_REDEFINITION)); @@ -632,9 +628,8 @@ public class CPPVisitor extends ASTQueries { /** * Tests whether a class binding matches the template parameters of another declaration */ - private static boolean templateParametersMatch(ICPPClassType binding, - ICPPASTTemplateDeclaration templateDecl) { - final boolean isTemplate= binding instanceof ICPPClassTemplate; + private static boolean templateParametersMatch(ICPPClassType binding, ICPPASTTemplateDeclaration templateDecl) { + final boolean isTemplate = binding instanceof ICPPClassTemplate; if (templateDecl == null) return !isTemplate; if (!isTemplate) @@ -643,7 +638,7 @@ public class CPPVisitor extends ASTQueries { ICPPTemplateParameter[] pars1 = ((ICPPClassTemplate) binding).getTemplateParameters(); ICPPASTTemplateParameter[] pars2 = templateDecl.getTemplateParameters(); - int i=0; + int i = 0; for (ICPPASTTemplateParameter p2 : pars2) { if (i >= pars1.length) return true; @@ -659,23 +654,22 @@ public class CPPVisitor extends ASTQueries { if (name instanceof ICPPASTTemplateId) return CPPTemplates.createBinding((ICPPASTTemplateId) name); - ICPPScope scope = (ICPPScope) getContainingScope(name); + ICPPScope scope = (ICPPScope) getContainingScope(name); try { - while (scope instanceof ICPPTemplateScope) { - scope= (ICPPScope) scope.getParent(); - } - } catch (DOMException e) { - return e.getProblem(); - } - - // Can't lookup anonymous names. - IBinding binding= null; + while (scope instanceof ICPPTemplateScope) { + scope = (ICPPScope) scope.getParent(); + } + } catch (DOMException e) { + return e.getProblem(); + } + + // Can't lookup anonymous names. + IBinding binding = null; ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration(name); if (name.getLookupKey().length > 0 && scope != null) { binding = scope.getBinding(name, false); - if (binding instanceof ICPPInternalBinding - && binding instanceof ICPPClassType && name.isActive()) { + if (binding instanceof ICPPInternalBinding && binding instanceof ICPPClassType && name.isActive()) { ICPPInternalBinding internalBinding = (ICPPInternalBinding) binding; if (internalBinding.getDefinition() == null && templateParametersMatch((ICPPClassType) binding, templateDecl)) { @@ -691,7 +685,7 @@ public class CPPVisitor extends ASTQueries { if (templateDecl != null) return new CPPClassTemplate(name); - return new CPPClassType(name, binding); + return new CPPClassType(name, binding); } private static IBinding createBinding(IASTDeclaration declaration) { @@ -699,7 +693,7 @@ public class CPPVisitor extends ASTQueries { ICPPASTNamespaceDefinition namespaceDef = (ICPPASTNamespaceDefinition) declaration; ICPPScope scope = (ICPPScope) getContainingScope(namespaceDef); IBinding binding; - binding = scope.getBinding(namespaceDef.getName(), false); + binding = scope.getBinding(namespaceDef.getName(), false); if (!(binding instanceof ICPPInternalBinding) || binding instanceof IProblemBinding || !(binding instanceof ICPPNamespace)) { binding = new CPPNamespace(namespaceDef); @@ -708,22 +702,22 @@ public class CPPVisitor extends ASTQueries { } else if (declaration instanceof ICPPASTUsingDirective) { return CPPSemantics.resolveBinding(((ICPPASTUsingDirective) declaration).getQualifiedName()); } else if (declaration instanceof ICPPASTNamespaceAlias) { - ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration; - ICPPScope scope = (ICPPScope) getContainingScope(declaration); - IBinding binding; - binding = scope.getBinding(alias.getAlias(), false); + ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration; + ICPPScope scope = (ICPPScope) getContainingScope(declaration); + IBinding binding; + binding = scope.getBinding(alias.getAlias(), false); if (!(binding instanceof ICPPInternalBinding)) { - IBinding namespace = alias.getMappingName().resolveBinding(); - if (namespace instanceof IProblemBinding) { - IProblemBinding problem = (IProblemBinding) namespace; - namespace = new CPPNamespace.CPPNamespaceProblem(problem.getASTNode(), - problem.getID(), alias.getMappingName().toCharArray()); - } - if (namespace instanceof ICPPNamespace) { - binding = new CPPNamespaceAlias(alias.getAlias(), (ICPPNamespace) namespace); - } else { - binding = new ProblemBinding(alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); - } + IBinding namespace = alias.getMappingName().resolveBinding(); + if (namespace instanceof IProblemBinding) { + IProblemBinding problem = (IProblemBinding) namespace; + namespace = new CPPNamespace.CPPNamespaceProblem(problem.getASTNode(), problem.getID(), + alias.getMappingName().toCharArray()); + } + if (namespace instanceof ICPPNamespace) { + binding = new CPPNamespaceAlias(alias.getAlias(), (ICPPNamespace) namespace); + } else { + binding = new ProblemBinding(alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); + } } return binding; } else if (declaration instanceof ICPPASTAliasDeclaration) { @@ -733,21 +727,21 @@ public class CPPVisitor extends ASTQueries { if (!(binding instanceof ICPPInternalBinding)) { IType type = createType(alias.getMappingTypeId()); if (type instanceof IProblemBinding) { - IProblemBinding problem = (IProblemBinding) type; - type = new CPPClassType.CPPClassTypeProblem(problem.getASTNode(), problem.getID(), - alias.getMappingTypeId().getAbstractDeclarator().getName().toCharArray()); - } - if (type != null) { - if (alias.getParent() instanceof ICPPASTTemplateDeclaration) { - binding = new CPPAliasTemplate(alias.getAlias(), type); - } else { - CPPTypedef typedef = new CPPTypedef(alias.getAlias()); - typedef.setType(type); - binding = typedef; - } - } else { - binding = new ProblemBinding(alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); - } + IProblemBinding problem = (IProblemBinding) type; + type = new CPPClassType.CPPClassTypeProblem(problem.getASTNode(), problem.getID(), + alias.getMappingTypeId().getAbstractDeclarator().getName().toCharArray()); + } + if (type != null) { + if (alias.getParent() instanceof ICPPASTTemplateDeclaration) { + binding = new CPPAliasTemplate(alias.getAlias(), type); + } else { + CPPTypedef typedef = new CPPTypedef(alias.getAlias()); + typedef.setType(type); + binding = typedef; + } + } else { + binding = new ProblemBinding(alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); + } } return binding; } @@ -755,14 +749,14 @@ public class CPPVisitor extends ASTQueries { } private static int findParameterIndex(IASTParameterDeclaration param, IASTParameterDeclaration[] params) { - int i= 0; + int i = 0; for (; i < params.length; i++) { if (params[i] == param) return i; } return -1; } - + private static IBinding createBinding(IASTDeclarator declarator) { IASTNode parent = findOutermostDeclarator(declarator).getParent(); @@ -770,21 +764,21 @@ public class CPPVisitor extends ASTQueries { return new CPPVariable(declarator.getName()); } - declarator= findInnermostDeclarator(declarator); + declarator = findInnermostDeclarator(declarator); - final IASTDeclarator typeRelevantDtor= findTypeRelevantDeclarator(declarator); + final IASTDeclarator typeRelevantDtor = findTypeRelevantDeclarator(declarator); - IASTName name= declarator.getName().getLastName(); + IASTName name = declarator.getName().getLastName(); // In case the binding was created starting from another name within the declarator. - IBinding candidate= name.getBinding(); + IBinding candidate = name.getBinding(); if (candidate != null) { return candidate; } // Function type. if (parent instanceof IASTTypeId) - return CPPSemantics.resolveBinding(name); + return CPPSemantics.resolveBinding(name); // Function type for non-type template parameter. ASTNodeProperty prop = parent.getPropertyInParent(); @@ -797,9 +791,9 @@ public class CPPVisitor extends ASTQueries { return CPPSemantics.resolveBinding(name); // Explicit specializations. - ICPPASTTemplateDeclaration tmplDecl= CPPTemplates.getTemplateDeclaration(name); + ICPPASTTemplateDeclaration tmplDecl = CPPTemplates.getTemplateDeclaration(name); if (tmplDecl instanceof ICPPASTTemplateSpecialization) { - IBinding b= CPPSemantics.resolveBinding(name); + IBinding b = CPPSemantics.resolveBinding(name); if (parent instanceof ICPPASTFunctionDefinition) { ASTInternal.addDefinition(b, name); } else { @@ -809,7 +803,7 @@ public class CPPVisitor extends ASTQueries { } // Parameter declarations. - if (parent instanceof ICPPASTParameterDeclaration) { + if (parent instanceof ICPPASTParameterDeclaration) { ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent; parent = param.getParent(); if (parent instanceof IASTStandardFunctionDeclarator) { @@ -818,10 +812,10 @@ public class CPPVisitor extends ASTQueries { if (findTypeRelevantDeclarator(fdtor) != fdtor) return null; - final IASTNode dtorParent= findOutermostDeclarator(fdtor).getParent(); + final IASTNode dtorParent = findOutermostDeclarator(fdtor).getParent(); if (dtorParent instanceof ICPPASTLambdaExpression) { - CPPClosureType closure = (CPPClosureType) - ((ICPPASTLambdaExpression) dtorParent).getExpressionType(); + CPPClosureType closure = (CPPClosureType) ((ICPPASTLambdaExpression) dtorParent) + .getExpressionType(); ICPPParameter[] paramBindings = closure.getParameters(); int index = findParameterIndex(param, fdtor.getParameters()); if (index >= 0 && index < paramBindings.length) { @@ -838,12 +832,12 @@ public class CPPVisitor extends ASTQueries { return CPPTemplates.createBinding(param); } return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_TYPE); - } + } // Function declaration/definition. - IBinding binding= null; - final boolean template= tmplDecl != null; - boolean isFriendDecl= false; + IBinding binding = null; + final boolean template = tmplDecl != null; + boolean isFriendDecl = false; ICPPScope scope = (ICPPScope) getContainingNonTemplateScope(name); if (scope instanceof ICPPClassScope) { isFriendDecl = isFriendDeclaration(parent); @@ -856,77 +850,78 @@ public class CPPVisitor extends ASTQueries { } } } - boolean forceResolve= isFriendDecl && name instanceof ICPPASTTemplateId; + boolean forceResolve = isFriendDecl && name instanceof ICPPASTTemplateId; if (name.getLookupKey().length != 0 && scope != null) { binding = scope.getBinding(name, forceResolve); } - boolean isFunction= false; - if (parent instanceof ICPPASTFunctionDefinition) { - isFunction= true; - } else if (parent instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; - if (simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { - // Typedef declaration. - if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef && name.isActive()) { - IType t1 = ((ITypedef) binding).getType(); - IType t2 = createType(declarator); - if (t1 != null && t2 != null && t1.isSameType(t2)) { - ASTInternal.addDeclaration(binding, name); - return binding; - } - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } - // If we don't resolve the target type first, we get a problem binding in case - // the typedef redeclares the target type, otherwise it is safer to defer - // the resolution of the target type. - IType targetType= createType(declarator); - CPPTypedef td= new CPPTypedef(name); - td.setType(targetType); - binding = td; - } else if (typeRelevantDtor instanceof IASTFunctionDeclarator) { - // Function declaration via function declarator. - isFunction= true; - } else { - // Looks like a variable declaration. - IType t1 = createType(declarator); - if (SemanticUtil.getNestedType(t1, TDEF) instanceof IFunctionType) { - // Function declaration via a typedef for a function type - isFunction= true; - } else if (binding instanceof IParameter) { - // Variable declaration redeclaring a parameter. - binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } else { - // Variable declaration. - IType t2= null; - if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { - t2 = ((IVariable) binding).getType(); - } - if (t1 != null && t2 != null) { - if (areArraysOfTheSameElementType(t1, t2) || t1.isSameType(t2)) { - ASTInternal.addDeclaration(binding, name); - } else { - binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } - } else if (simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { - binding = new CPPField(name); - } else if (template) { - if (simpleDecl.getParent().getParent() instanceof ICPPASTCompositeTypeSpecifier) { - binding = new CPPFieldTemplate(name); - } else { - binding = new CPPVariableTemplate(name); - } - } else { - binding = new CPPVariable(name); - } - } - } - } - - if (isFunction) { + boolean isFunction = false; + if (parent instanceof ICPPASTFunctionDefinition) { + isFunction = true; + } else if (parent instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; + if (simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { + // Typedef declaration. + if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef && name.isActive()) { + IType t1 = ((ITypedef) binding).getType(); + IType t2 = createType(declarator); + if (t1 != null && t2 != null && t1.isSameType(t2)) { + ASTInternal.addDeclaration(binding, name); + return binding; + } + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } + // If we don't resolve the target type first, we get a problem binding in case + // the typedef redeclares the target type, otherwise it is safer to defer + // the resolution of the target type. + IType targetType = createType(declarator); + CPPTypedef td = new CPPTypedef(name); + td.setType(targetType); + binding = td; + } else if (typeRelevantDtor instanceof IASTFunctionDeclarator) { + // Function declaration via function declarator. + isFunction = true; + } else { + // Looks like a variable declaration. + IType t1 = createType(declarator); + if (SemanticUtil.getNestedType(t1, TDEF) instanceof IFunctionType) { + // Function declaration via a typedef for a function type + isFunction = true; + } else if (binding instanceof IParameter) { + // Variable declaration redeclaring a parameter. + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } else { + // Variable declaration. + IType t2 = null; + if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { + t2 = ((IVariable) binding).getType(); + } + if (t1 != null && t2 != null) { + if (areArraysOfTheSameElementType(t1, t2) || t1.isSameType(t2)) { + ASTInternal.addDeclaration(binding, name); + } else { + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } + } else if (simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { + binding = new CPPField(name); + } else if (template) { + if (simpleDecl.getParent().getParent() instanceof ICPPASTCompositeTypeSpecifier) { + binding = new CPPFieldTemplate(name); + } else { + binding = new CPPVariableTemplate(name); + } + } else { + binding = new CPPVariable(name); + } + } + } + } + + if (isFunction) { if (binding instanceof ICPPInternalBinding && binding instanceof ICPPFunction && name.isActive()) { ICPPFunction function = (ICPPFunction) binding; - boolean sameFunction = CPPSemantics.isSameFunction(function, typeRelevantDtor) || function instanceof ICPPDeferredFunction; + boolean sameFunction = CPPSemantics.isSameFunction(function, typeRelevantDtor) + || function instanceof ICPPDeferredFunction; if (function.getOwner() instanceof ICPPClassType) { // Don't consider a function brought into scope from a base class scope // to be the same as a function declared in a derived class scope. @@ -935,46 +930,44 @@ public class CPPVisitor extends ASTQueries { sameFunction = false; } } - if (sameFunction) { - binding= CPPSemantics.checkDeclSpecifier(binding, name, parent); - if (binding instanceof IProblemBinding) - return binding; - - ICPPInternalBinding internal = (ICPPInternalBinding) function; - if (parent instanceof IASTSimpleDeclaration) { - ASTInternal.addDeclaration(internal, name); - } else if (internal.getDefinition() == null) { - ASTInternal.addDefinition(internal, name); - } else { - IASTNode def = internal.getDefinition(); - if (def instanceof IASTDeclarator) - def = ((IASTDeclarator) def).getName(); - if (def != name) { - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION); - } - } - - return function; - } + if (sameFunction) { + binding = CPPSemantics.checkDeclSpecifier(binding, name, parent); + if (binding instanceof IProblemBinding) + return binding; + + ICPPInternalBinding internal = (ICPPInternalBinding) function; + if (parent instanceof IASTSimpleDeclaration) { + ASTInternal.addDeclaration(internal, name); + } else if (internal.getDefinition() == null) { + ASTInternal.addDefinition(internal, name); + } else { + IASTNode def = internal.getDefinition(); + if (def instanceof IASTDeclarator) + def = ((IASTDeclarator) def).getName(); + if (def != name) { + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION); + } + } + + return function; + } } if (scope instanceof ICPPClassScope) { if (isConstructor(scope, typeRelevantDtor)) { - binding = template ? (ICPPConstructor) new CPPConstructorTemplate(name) - : new CPPConstructor((ICPPASTFunctionDeclarator) typeRelevantDtor); + binding = template ? (ICPPConstructor) new CPPConstructorTemplate(name) + : new CPPConstructor((ICPPASTFunctionDeclarator) typeRelevantDtor); } else { - binding = template ? (ICPPMethod) new CPPMethodTemplate(name) - : new CPPMethod(typeRelevantDtor); + binding = template ? (ICPPMethod) new CPPMethodTemplate(name) : new CPPMethod(typeRelevantDtor); } } else { - binding = template ? (ICPPFunction) new CPPFunctionTemplate(name) - : new CPPFunction(typeRelevantDtor); + binding = template ? (ICPPFunction) new CPPFunctionTemplate(name) : new CPPFunction(typeRelevantDtor); } - binding= CPPSemantics.checkDeclSpecifier(binding, name, parent); + binding = CPPSemantics.checkDeclSpecifier(binding, name, parent); if (isFriendDecl && scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).addBinding(binding); } - } + } return binding; } @@ -993,8 +986,8 @@ public class CPPVisitor extends ASTQueries { public static boolean isConstructor(IScope containingScope, IASTDeclarator declarator) { if (containingScope instanceof ICPPClassScope && isConstructorDtor(declarator)) { - ICPPClassType classType= ((ICPPClassScope) containingScope).getClassType(); - final char[] dtorName = findInnermostDeclarator(declarator).getName().getLookupKey(); + ICPPClassType classType = ((ICPPClassScope) containingScope).getClassType(); + final char[] dtorName = findInnermostDeclarator(declarator).getName().getLookupKey(); return CharArrayUtils.equals(dtorName, classType.getNameCharArray()); } return false; @@ -1008,25 +1001,25 @@ public class CPPVisitor extends ASTQueries { return false; IASTNode parent = name.getParent(); if (parent instanceof ICPPASTTemplateId) { - name= (IASTName) parent; - parent= name.getParent(); + name = (IASTName) parent; + parent = name.getParent(); } if (parent instanceof ICPPASTQualifiedName) { if (((ICPPASTQualifiedName) parent).getLastName() != name) return false; - name= (IASTName) parent; - parent= name.getParent(); + name = (IASTName) parent; + parent = name.getParent(); } if (parent instanceof IASTDeclarator) { if (isConstructorDtor((IASTDeclarator) parent)) { if (name instanceof ICPPASTQualifiedName) { ICPPASTNameSpecifier[] qualifier = ((ICPPASTQualifiedName) name).getQualifier(); if (qualifier.length >= 1) { - IBinding b= qualifier[qualifier.length - 1].resolvePreBinding(); + IBinding b = qualifier[qualifier.length - 1].resolvePreBinding(); if (b instanceof IType) { - IType classType= getNestedType((IType) b, TDEF); + IType classType = getNestedType((IType) b, TDEF); if (classType instanceof ICPPClassType) { - final char[] dtorName = name.getLastName().getLookupKey(); + final char[] dtorName = name.getLastName().getLookupKey(); final char[] className = ((ICPPClassType) classType).getNameCharArray(); return CharArrayUtils.equals(dtorName, className); } @@ -1036,11 +1029,12 @@ public class CPPVisitor extends ASTQueries { } while (parent != null) { if (parent instanceof ICPPASTCompositeTypeSpecifier) { - final char[] className= ((ICPPASTCompositeTypeSpecifier) parent).getName().getLastName().getLookupKey(); - final char[] dtorName = name.getLookupKey(); + final char[] className = ((ICPPASTCompositeTypeSpecifier) parent).getName().getLastName() + .getLookupKey(); + final char[] dtorName = name.getLookupKey(); return CharArrayUtils.equals(dtorName, className); } - parent= parent.getParent(); + parent = parent.getParent(); } } } @@ -1051,31 +1045,30 @@ public class CPPVisitor extends ASTQueries { if (declarator == null || !(declarator instanceof IASTFunctionDeclarator)) return false; - IASTDeclSpecifier declSpec = null; - IASTNode parent = findOutermostDeclarator(declarator).getParent(); - if (parent instanceof IASTSimpleDeclaration) { - declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); - } else if (parent instanceof IASTFunctionDefinition) { - declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); - } - if (declSpec != null && declSpec instanceof IASTSimpleDeclSpecifier) { - return (((IASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified); - } + IASTDeclSpecifier declSpec = null; + IASTNode parent = findOutermostDeclarator(declarator).getParent(); + if (parent instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTFunctionDefinition) { + declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); + } + if (declSpec != null && declSpec instanceof IASTSimpleDeclSpecifier) { + return (((IASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified); + } - return false; + return false; } public static boolean isLastNameInUsingDeclaration(IASTName name) { IASTNode parent = name.getParent(); - return parent instanceof ICPPASTQualifiedName - && ((ICPPASTQualifiedName) parent).getLastName() == name - && parent.getParent() instanceof ICPPASTUsingDeclaration; + return parent instanceof ICPPASTQualifiedName && ((ICPPASTQualifiedName) parent).getLastName() == name + && parent.getParent() instanceof ICPPASTUsingDeclaration; } public static IScope getContainingNonTemplateScope(final IASTNode inputNode) { - IScope scope= getContainingScope(inputNode); + IScope scope = getContainingScope(inputNode); while (scope instanceof ICPPTemplateScope) { - scope= getContainingScope(((ICPPTemplateScope) scope).getTemplateDeclaration()); + scope = getContainingScope(((ICPPTemplateScope) scope).getTemplateDeclaration()); } return scope; } @@ -1083,23 +1076,23 @@ public class CPPVisitor extends ASTQueries { public static IScope getContainingScope(final IASTNode inputNode) { if (inputNode == null || inputNode instanceof IASTTranslationUnit) return null; - IASTNode node= inputNode; + IASTNode node = inputNode; while (node != null) { - if (node instanceof IASTName && !(node instanceof ICPPASTQualifiedName)) { + if (node instanceof IASTName && !(node instanceof ICPPASTQualifiedName)) { return getContainingScope((IASTName) node); } - if (node instanceof IASTDeclaration) { + if (node instanceof IASTDeclaration) { IASTNode parent = node.getParent(); if (parent instanceof IASTTranslationUnit) { return ((IASTTranslationUnit) parent).getScope(); } else if (parent instanceof IASTDeclarationStatement) { return getContainingScope((IASTStatement) parent); } else if (parent instanceof IASTForStatement) { - return ((IASTForStatement) parent).getScope(); + return ((IASTForStatement) parent).getScope(); } else if (parent instanceof ICPPASTRangeBasedForStatement) { - return ((ICPPASTRangeBasedForStatement) parent).getScope(); + return ((ICPPASTRangeBasedForStatement) parent).getScope(); } else if (parent instanceof IASTCompositeTypeSpecifier) { - return ((IASTCompositeTypeSpecifier) parent).getScope(); + return ((IASTCompositeTypeSpecifier) parent).getScope(); } else if (parent instanceof ICPPASTNamespaceDefinition) { return ((ICPPASTNamespaceDefinition) parent).getScope(); } else if (parent instanceof ICPPASTSwitchStatement) { @@ -1114,81 +1107,82 @@ public class CPPVisitor extends ASTQueries { return ((ICPPASTCatchHandler) parent).getScope(); } } else if (node instanceof IASTStatement) { - return getContainingScope((IASTStatement) node); + return getContainingScope((IASTStatement) node); } else if (node instanceof IASTTypeId) { ASTNodeProperty prop = node.getPropertyInParent(); if (prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT || prop == ICPPASTConversionName.TYPE_ID) { - node= node.getParent(); // template-id or conversion name + node = node.getParent(); // template-id or conversion name while (node instanceof IASTName) { - node= node.getParent(); + node = node.getParent(); } continue; - } else if (prop == ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE || - prop == ICPPASTFunctionDeclarator.EXCEPTION_TYPEID) { + } else if (prop == ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE + || prop == ICPPASTFunctionDeclarator.EXCEPTION_TYPEID) { IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) node.getParent()); if (result != null) return result; } - } else if (node instanceof IASTParameterDeclaration || - node.getPropertyInParent() == ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) { - IASTNode parent = node.getParent(); - if (parent instanceof ICPPASTFunctionDeclarator) { + } else if (node instanceof IASTParameterDeclaration + || node.getPropertyInParent() == ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) { + IASTNode parent = node.getParent(); + if (parent instanceof ICPPASTFunctionDeclarator) { IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent); if (result != null) return result; - } else if (parent instanceof ICPPASTTemplateDeclaration) { - return ((ICPPASTTemplateDeclaration) parent).getScope(); - } + } else if (parent instanceof ICPPASTTemplateDeclaration) { + return ((ICPPASTTemplateDeclaration) parent).getScope(); + } } else if (node instanceof IASTInitializer) { if (node instanceof ICPPASTConstructorChainInitializer) { // The name of the member initializer is resolved in the scope of // the owner of the ctor. ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) node; - IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent(); + IASTFunctionDefinition fdef = (IASTFunctionDefinition) initializer.getParent(); IBinding binding = fdef.getDeclarator().getName().resolveBinding(); try { return binding.getScope(); } catch (DOMException e) { } - } else { - IASTNode parent = node.getParent(); - if (parent instanceof IASTDeclarator) { - IASTDeclarator dtor = (IASTDeclarator) parent; - IASTName name = dtor.getName(); - if (name instanceof ICPPASTQualifiedName) { - return getContainingScope(name.getLastName()); - } - } else if (parent instanceof ICPPASTConstructorChainInitializer) { - // The initializer for the member initializer is resolved in - // the body of the ctor. - IASTNode temp = getContainingBlockItem(node); - if (temp instanceof IASTFunctionDefinition) { - IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition) temp).getBody(); - return body.getScope(); - } - node= parent; - } - } - } else if (node instanceof IASTExpression) { - IASTNode parent = node.getParent(); - if (parent instanceof IASTForStatement) { - return ((IASTForStatement) parent).getScope(); + } else { + IASTNode parent = node.getParent(); + if (parent instanceof IASTDeclarator) { + IASTDeclarator dtor = (IASTDeclarator) parent; + IASTName name = dtor.getName(); + if (name instanceof ICPPASTQualifiedName) { + return getContainingScope(name.getLastName()); + } + } else if (parent instanceof ICPPASTConstructorChainInitializer) { + // The initializer for the member initializer is resolved in + // the body of the ctor. + IASTNode temp = getContainingBlockItem(node); + if (temp instanceof IASTFunctionDefinition) { + IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition) temp) + .getBody(); + return body.getScope(); + } + node = parent; + } + } + } else if (node instanceof IASTExpression) { + IASTNode parent = node.getParent(); + if (parent instanceof IASTForStatement) { + return ((IASTForStatement) parent).getScope(); } else if (parent instanceof ICPPASTRangeBasedForStatement) { - return ((ICPPASTRangeBasedForStatement) parent).getScope(); - } else if (parent instanceof ICPPASTIfStatement) { - return ((ICPPASTIfStatement) parent).getScope(); - } else if (parent instanceof ICPPASTSwitchStatement) { - return ((ICPPASTSwitchStatement) parent).getScope(); - } else if (parent instanceof ICPPASTWhileStatement) { - return ((ICPPASTWhileStatement) parent).getScope(); - } else if (parent instanceof IASTCompoundStatement) { - return ((IASTCompoundStatement) parent).getScope(); - } else if (parent instanceof IASTArrayModifier) { - IASTNode d = parent.getParent(); + return ((ICPPASTRangeBasedForStatement) parent).getScope(); + } else if (parent instanceof ICPPASTIfStatement) { + return ((ICPPASTIfStatement) parent).getScope(); + } else if (parent instanceof ICPPASTSwitchStatement) { + return ((ICPPASTSwitchStatement) parent).getScope(); + } else if (parent instanceof ICPPASTWhileStatement) { + return ((ICPPASTWhileStatement) parent).getScope(); + } else if (parent instanceof IASTCompoundStatement) { + return ((IASTCompoundStatement) parent).getScope(); + } else if (parent instanceof IASTArrayModifier) { + IASTNode d = parent.getParent(); while (!(d instanceof IASTDeclarator || d instanceof IASTExpression)) { - d = d.getParent(); - } + d = d.getParent(); + } if (d instanceof IASTDeclarator) { IASTDeclarator dtor = (IASTDeclarator) d; while (dtor.getNestedDeclarator() != null) @@ -1198,43 +1192,43 @@ public class CPPVisitor extends ASTQueries { return getContainingScope(name.getLastName()); } } - } else if (parent instanceof ICPPASTTemplateId && - node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { - node= parent; // template-id + } else if (parent instanceof ICPPASTTemplateId + && node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { + node = parent; // template-id while (node instanceof IASTName) { - node= node.getParent(); + node = node.getParent(); } continue; - } - } else if (node instanceof ICPPASTTemplateParameter) { - if (node instanceof ICPPASTTemplatedTypeTemplateParameter && node != inputNode) { - return ((ICPPASTTemplatedTypeTemplateParameter) node).asScope(); - } - IASTNode parent = node.getParent(); - if (parent instanceof ICPPASTTemplateDeclaration) { - return ((ICPPASTTemplateDeclaration) parent).getScope(); - } - } else if (node instanceof ICPPASTBaseSpecifier) { - ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) node.getParent(); - IASTName n = compSpec.getName().getLastName(); - return getContainingScope(n); - } else if (node instanceof IASTEnumerator) { - node= node.getParent(); - if (node instanceof ICPPASTEnumerationSpecifier) { - ICPPASTEnumerationSpecifier enumSpec= (ICPPASTEnumerationSpecifier) node; - IBinding binding = enumSpec.getName().resolveBinding(); - if (binding instanceof ICPPEnumeration) { - ICPPEnumeration enumType = (ICPPEnumeration) binding; - if (enumType.isScoped()) { - return enumType.asScope(); - } - } - } - } - node = node.getParent(); - } - return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE, - inputNode.getRawSignature().toCharArray()); + } + } else if (node instanceof ICPPASTTemplateParameter) { + if (node instanceof ICPPASTTemplatedTypeTemplateParameter && node != inputNode) { + return ((ICPPASTTemplatedTypeTemplateParameter) node).asScope(); + } + IASTNode parent = node.getParent(); + if (parent instanceof ICPPASTTemplateDeclaration) { + return ((ICPPASTTemplateDeclaration) parent).getScope(); + } + } else if (node instanceof ICPPASTBaseSpecifier) { + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) node.getParent(); + IASTName n = compSpec.getName().getLastName(); + return getContainingScope(n); + } else if (node instanceof IASTEnumerator) { + node = node.getParent(); + if (node instanceof ICPPASTEnumerationSpecifier) { + ICPPASTEnumerationSpecifier enumSpec = (ICPPASTEnumerationSpecifier) node; + IBinding binding = enumSpec.getName().resolveBinding(); + if (binding instanceof ICPPEnumeration) { + ICPPEnumeration enumType = (ICPPEnumeration) binding; + if (enumType.isScoped()) { + return enumType.asScope(); + } + } + } + } + node = node.getParent(); + } + return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE, + inputNode.getRawSignature().toCharArray()); } private static IScope scopeViaFunctionDtor(ICPPASTFunctionDeclarator dtor) { @@ -1242,26 +1236,27 @@ public class CPPVisitor extends ASTQueries { IASTDeclarator outerDtor = ASTQueries.findOutermostDeclarator(dtor); ASTNodeProperty prop = outerDtor.getPropertyInParent(); if (prop == IASTSimpleDeclaration.DECLARATOR) { - return dtor.getFunctionScope(); + return dtor.getFunctionScope(); } if (prop == IASTFunctionDefinition.DECLARATOR) { - final IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition) outerDtor.getParent()).getBody(); - if (body != null) - return body.getScope(); - return dtor.getFunctionScope(); + final IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition) outerDtor + .getParent()).getBody(); + if (body != null) + return body.getScope(); + return dtor.getFunctionScope(); } if (prop == ICPPASTLambdaExpression.DECLARATOR) { - final IASTCompoundStatement body = ((ICPPASTLambdaExpression) outerDtor.getParent()).getBody(); - if (body != null) - return body.getScope(); - return dtor.getFunctionScope(); + final IASTCompoundStatement body = ((ICPPASTLambdaExpression) outerDtor.getParent()).getBody(); + if (body != null) + return body.getScope(); + return dtor.getFunctionScope(); } } return null; } public static IScope getContainingScope(IASTName name) { - IScope scope= getContainingScopeOrNull(name); + IScope scope = getContainingScopeOrNull(name); if (scope == null) { return new CPPScope.CPPScopeProblem(name, IProblemBinding.SEMANTIC_BAD_SCOPE); } @@ -1275,14 +1270,14 @@ public class CPPVisitor extends ASTQueries { } IASTNode parent = name.getParent(); try { - if (parent instanceof ICPPASTTemplateId) { - name = (IASTName) parent; - parent = name.getParent(); - } + if (parent instanceof ICPPASTTemplateId) { + name = (IASTName) parent; + parent = name.getParent(); + } if (parent instanceof ICPPASTQualifiedName) { - final ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent; - final ICPPASTNameSpecifier[] qualifiers= qname.getQualifier(); + final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) parent; + final ICPPASTNameSpecifier[] qualifiers = qname.getQualifier(); int i = 0; for (; i < qualifiers.length; i++) { if (qualifiers[i] == name) @@ -1296,41 +1291,42 @@ public class CPPVisitor extends ASTQueries { return tu.getScope(); } if (qname.getParent() instanceof ICPPASTFieldReference) { - name= qname; - parent= name.getParent(); + name = qname; + parent = name.getParent(); } - } else { // i > 0 + } else { // i > 0 // For template functions we may need to resolve a template parameter // as a parent of an unknown type used as parameter type. IBinding binding = qualifiers[i - 1].resolvePreBinding(); // 7.1.3-7 Unwrap typedefs, delete cv-qualifiers. if (binding instanceof ITypedef) { - IType type= getNestedType((ITypedef) binding, TDEF | CVTYPE); + IType type = getNestedType((ITypedef) binding, TDEF | CVTYPE); if (type instanceof IBinding) { - binding= (IBinding) type; + binding = (IBinding) type; } } - boolean done= true; - IScope scope= null; + boolean done = true; + IScope scope = null; if (binding instanceof ICPPClassType) { - binding= (ICPPClassType) SemanticUtil.mapToAST((ICPPClassType) binding); - scope= ((ICPPClassType) binding).getCompositeScope(); + binding = (ICPPClassType) SemanticUtil.mapToAST((ICPPClassType) binding); + scope = ((ICPPClassType) binding).getCompositeScope(); } else if (binding instanceof ICPPNamespace) { - scope= ((ICPPNamespace) binding).getNamespaceScope(); + scope = ((ICPPNamespace) binding).getNamespaceScope(); } else if (binding instanceof ICPPEnumeration) { - scope= ((ICPPEnumeration) binding).asScope(); + scope = ((ICPPEnumeration) binding).asScope(); } else if (binding instanceof ICPPUnknownBinding) { - scope= ((ICPPUnknownBinding) binding).asScope(); + scope = ((ICPPUnknownBinding) binding).asScope(); } else if (binding instanceof IProblemBinding) { if (binding instanceof ICPPScope) - scope= (IScope) binding; + scope = (IScope) binding; } else { - done= false; + done = false; } if (done) { if (scope == null) { - return new CPPScope.CPPScopeProblem(qualifiers[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE, null); + return new CPPScope.CPPScopeProblem(qualifiers[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE, + null); } return scope; } @@ -1343,9 +1339,9 @@ public class CPPVisitor extends ASTQueries { if (type instanceof ICPPParameterPackType) { type = ((ICPPParameterPackType) type).getType(); } - type= getUltimateTypeUptoPointers(type); + type = getUltimateTypeUptoPointers(type); if (type instanceof ICPPClassType) { - type= SemanticUtil.mapToAST(type); + type = SemanticUtil.mapToAST(type); return ((ICPPClassType) type).getCompositeScope(); } else if (type instanceof ICPPUnknownBinding) { return ((ICPPUnknownBinding) type).asScope(); @@ -1369,19 +1365,19 @@ public class CPPVisitor extends ASTQueries { } while ((node = node.getParent()) != null); if (type != null) { - type= getNestedType(type, TDEF | CVTYPE); + type = getNestedType(type, TDEF | CVTYPE); if (type instanceof ICPPClassType) { - type= SemanticUtil.mapToAST(type); + type = SemanticUtil.mapToAST(type); return ((ICPPClassType) type).getCompositeScope(); } } return new CPPScope.CPPScopeProblem(name, ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); } else if (parent instanceof IASTGotoStatement || parent instanceof IASTLabelStatement) { - while (!(parent instanceof IASTFunctionDefinition)) { - parent = parent.getParent(); - } - IASTFunctionDefinition fdef = (IASTFunctionDefinition) parent; - return ((ICPPASTFunctionDeclarator) fdef.getDeclarator()).getFunctionScope(); + while (!(parent instanceof IASTFunctionDefinition)) { + parent = parent.getParent(); + } + IASTFunctionDefinition fdef = (IASTFunctionDefinition) parent; + return ((ICPPASTFunctionDeclarator) fdef.getDeclarator()).getFunctionScope(); } } catch (DOMException e) { IProblemBinding problem = e.getProblem(); @@ -1396,12 +1392,12 @@ public class CPPVisitor extends ASTQueries { IASTNode parent = statement.getParent(); IScope scope = null; if (parent instanceof IASTCompoundStatement) { - IASTCompoundStatement compound = (IASTCompoundStatement) parent; - scope = compound.getScope(); + IASTCompoundStatement compound = (IASTCompoundStatement) parent; + scope = compound.getScope(); } else if (parent instanceof IASTForStatement) { - scope = ((IASTForStatement) parent).getScope(); + scope = ((IASTForStatement) parent).getScope(); } else if (parent instanceof ICPPASTRangeBasedForStatement) { - scope= ((ICPPASTRangeBasedForStatement) parent).getScope(); + scope = ((ICPPASTRangeBasedForStatement) parent).getScope(); } else if (parent instanceof ICPPASTSwitchStatement) { scope = ((ICPPASTSwitchStatement) parent).getScope(); } else if (parent instanceof ICPPASTIfStatement) { @@ -1416,8 +1412,8 @@ public class CPPVisitor extends ASTQueries { return fdef.getScope(); IASTFunctionDeclarator fnDeclarator = fdef.getDeclarator(); - IASTName name = findInnermostDeclarator(fnDeclarator).getName().getLastName(); - return getContainingScope(name); + IASTName name = findInnermostDeclarator(fnDeclarator).getName().getLastName(); + return getContainingScope(name); } if (scope == null) @@ -1426,8 +1422,10 @@ public class CPPVisitor extends ASTQueries { } public static IASTNode getContainingBlockItem(IASTNode node) { - if (node == null) return null; - if (node.getPropertyInParent() == null) return null; + if (node == null) + return null; + if (node.getPropertyInParent() == null) + return null; for (IASTNode parent = node.getParent(); parent != null; parent = parent.getParent()) { if (parent instanceof IASTDeclaration) { @@ -1438,17 +1436,18 @@ public class CPPVisitor extends ASTQueries { } else if (parent instanceof IASTExpression) { IASTNode p = parent.getParent(); if (p instanceof IASTForStatement) - return parent; + return parent; if (p instanceof ICPPASTRangeBasedForStatement) return parent; if (p instanceof IASTStatement) return p; } else if (parent instanceof IASTStatement || parent instanceof IASTTranslationUnit) { return parent; - } else if (parent instanceof IASTFunctionDeclarator && node.getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER) { - return node; + } else if (parent instanceof IASTFunctionDeclarator + && node.getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER) { + return node; } else if (parent instanceof IASTEnumerationSpecifier.IASTEnumerator) { - return parent; + return parent; } node = parent; } @@ -1481,13 +1480,14 @@ public class CPPVisitor extends ASTQueries { } } if (name != null) { - name= name.getLastName(); + name = name.getLastName(); IBinding binding = name.getPreBinding(); if (binding == null) { binding = CPPSemantics.resolveBinding(name); name.setBinding(binding); if (name instanceof ICPPASTTemplateId && binding instanceof ICPPSpecialization) { - ((ICPPASTTemplateId) name).getTemplateName().setBinding(((ICPPSpecialization) binding).getSpecializedBinding()); + ((ICPPASTTemplateId) name).getTemplateName() + .setBinding(((ICPPSpecialization) binding).getSpecializedBinding()); } } return binding; @@ -1504,7 +1504,7 @@ public class CPPVisitor extends ASTQueries { private void addProblem(IASTProblem problem) { if (fProblems == null) { - fProblems= new ArrayList<>(); + fProblems = new ArrayList<>(); } fProblems.add(problem); } @@ -1526,7 +1526,7 @@ public class CPPVisitor extends ASTQueries { } public static class CollectDeclarationsAction extends ASTVisitor { - private static final int DEFAULT_LIST_SIZE = 8; + private static final int DEFAULT_LIST_SIZE = 8; private IASTName[] decls; private IBinding[] bindings; private int idx = 0; @@ -1535,9 +1535,9 @@ public class CPPVisitor extends ASTQueries { private IIndex index; private boolean permissive; - private static final int KIND_LABEL = 1; + private static final int KIND_LABEL = 1; private static final int KIND_OBJ_FN = 2; - private static final int KIND_TYPE = 3; + private static final int KIND_TYPE = 3; private static final int KIND_NAMESPACE = 4; private static final int KIND_COMPOSITE = 5; private static final int KIND_TEMPLATE_PARAMETER = 6; @@ -1550,25 +1550,23 @@ public class CPPVisitor extends ASTQueries { final String bname = binding.getName(); if (bname.length() > 0 && !bname.startsWith("operator")) { //$NON-NLS-1$ - requiredName= bname.toCharArray(); + requiredName = bname.toCharArray(); } this.bindings = new IBinding[] { binding }; if (binding instanceof ICPPUsingDeclaration) { - this.bindings= ((ICPPUsingDeclaration) binding).getDelegates(); - kind= KIND_COMPOSITE; + this.bindings = ((ICPPUsingDeclaration) binding).getDelegates(); + kind = KIND_COMPOSITE; } else if (binding instanceof ILabel) { kind = KIND_LABEL; } else if (binding instanceof ICPPTemplateParameter) { kind = KIND_TEMPLATE_PARAMETER; - } else if (binding instanceof ICompositeType || - binding instanceof ICPPAliasTemplate || - binding instanceof ITypedef || - binding instanceof IEnumeration) { + } else if (binding instanceof ICompositeType || binding instanceof ICPPAliasTemplate + || binding instanceof ITypedef || binding instanceof IEnumeration) { kind = KIND_TYPE; } else if (binding instanceof ICPPNamespace) { kind = KIND_NAMESPACE; } else if (binding instanceof IParameter) { - requiredName= null; + requiredName = null; kind = KIND_OBJ_FN; } else { kind = KIND_OBJ_FN; @@ -1583,7 +1581,8 @@ public class CPPVisitor extends ASTQueries { @Override public int visit(IASTName name) { - if (name instanceof ICPPASTQualifiedName) return PROCESS_CONTINUE; + if (name instanceof ICPPASTQualifiedName) + return PROCESS_CONTINUE; if (requiredName != null && !CharArrayUtils.equals(name.getLookupKey(), requiredName)) { return PROCESS_CONTINUE; } @@ -1593,69 +1592,65 @@ public class CPPVisitor extends ASTQueries { prop = name.getParent().getPropertyInParent(); switch (kind) { - case KIND_TEMPLATE_PARAMETER: - if (prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME || - prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME) { + case KIND_TEMPLATE_PARAMETER: + if (prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME + || prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME) { + break; + } else if (prop == IASTDeclarator.DECLARATOR_NAME) { + IASTNode d = name.getParent(); + while (d.getParent() instanceof IASTDeclarator) + d = d.getParent(); + if (d.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR) { break; - } else if (prop == IASTDeclarator.DECLARATOR_NAME) { - IASTNode d = name.getParent(); - while (d.getParent() instanceof IASTDeclarator) - d = d.getParent(); - if (d.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR) { - break; - } } - return PROCESS_CONTINUE; + } + return PROCESS_CONTINUE; - case KIND_LABEL: - if (prop == IASTLabelStatement.NAME) - break; - return PROCESS_CONTINUE; + case KIND_LABEL: + if (prop == IASTLabelStatement.NAME) + break; + return PROCESS_CONTINUE; - case KIND_TYPE: - case KIND_COMPOSITE: - if (prop == IASTCompositeTypeSpecifier.TYPE_NAME || - prop == ICPPASTAliasDeclaration.ALIAS_NAME || - prop == IASTEnumerationSpecifier.ENUMERATION_NAME || - prop == ICPPASTUsingDeclaration.NAME) { - break; - } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { - IASTNode p = name.getParent().getParent(); - if (p instanceof IASTParameterDeclaration || - (p instanceof IASTSimpleDeclaration && - ((IASTSimpleDeclaration) p).getDeclarators().length == 0)) { + case KIND_TYPE: + case KIND_COMPOSITE: + if (prop == IASTCompositeTypeSpecifier.TYPE_NAME || prop == ICPPASTAliasDeclaration.ALIAS_NAME + || prop == IASTEnumerationSpecifier.ENUMERATION_NAME || prop == ICPPASTUsingDeclaration.NAME) { + break; + } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { + IASTNode p = name.getParent().getParent(); + if (p instanceof IASTParameterDeclaration || (p instanceof IASTSimpleDeclaration + && ((IASTSimpleDeclaration) p).getDeclarators().length == 0)) { + break; + } + } else if (prop == IASTDeclarator.DECLARATOR_NAME) { + IASTNode p = name.getParent(); + while (p instanceof IASTDeclarator) { + p = p.getParent(); + } + if (p instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) p).getDeclSpecifier(); + if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef) break; - } - } else if (prop == IASTDeclarator.DECLARATOR_NAME) { - IASTNode p = name.getParent(); - while (p instanceof IASTDeclarator) { - p= p.getParent(); - } - if (p instanceof IASTSimpleDeclaration) { - IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) p).getDeclSpecifier(); - if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef) - break; - } } + } - if (kind == KIND_TYPE) - return PROCESS_CONTINUE; - // $FALL-THROUGH$ - - case KIND_OBJ_FN: - if (prop == IASTDeclarator.DECLARATOR_NAME || - prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME || - prop == ICPPASTUsingDeclaration.NAME) { - break; - } + if (kind == KIND_TYPE) return PROCESS_CONTINUE; + // $FALL-THROUGH$ - case KIND_NAMESPACE: - if (prop == ICPPASTNamespaceDefinition.NAMESPACE_NAME || - prop == ICPPASTNamespaceAlias.ALIAS_NAME) { - break; - } - return PROCESS_CONTINUE; + case KIND_OBJ_FN: + if (prop == IASTDeclarator.DECLARATOR_NAME + || prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME + || prop == ICPPASTUsingDeclaration.NAME) { + break; + } + return PROCESS_CONTINUE; + + case KIND_NAMESPACE: + if (prop == ICPPASTNamespaceDefinition.NAMESPACE_NAME || prop == ICPPASTNamespaceAlias.ALIAS_NAME) { + break; + } + return PROCESS_CONTINUE; } if (bindings != null) { @@ -1664,7 +1659,7 @@ public class CPPVisitor extends ASTQueries { decls = Arrays.copyOf(decls, decls.length * 2); } decls[idx++] = name; - } + } } return PROCESS_CONTINUE; } @@ -1707,7 +1702,7 @@ public class CPPVisitor extends ASTQueries { } return areEquivalentBindings(candidate, target, index); } - + private static boolean areEquivalentBindings(IBinding binding1, IBinding binding2, IIndex index) { if (binding1.equals(binding2)) { return true; @@ -1732,7 +1727,7 @@ public class CPPVisitor extends ASTQueries { protected static IBinding unwindBinding(IBinding binding) { while (true) { if (binding instanceof ICPPSpecialization) { - binding= ((ICPPSpecialization) binding).getSpecializedBinding(); + binding = ((ICPPSpecialization) binding).getSpecializedBinding(); } else { break; } @@ -1748,10 +1743,10 @@ public class CPPVisitor extends ASTQueries { private int kind; private IIndex index; - private static final int KIND_LABEL = 1; + private static final int KIND_LABEL = 1; private static final int KIND_OBJ_FN = 2; - private static final int KIND_TYPE = 3; - private static final int KIND_NAMESPACE = 4; + private static final int KIND_TYPE = 3; + private static final int KIND_NAMESPACE = 4; private static final int KIND_COMPOSITE = 5; public CollectReferencesAction(IBinding binding) { @@ -1763,18 +1758,17 @@ public class CPPVisitor extends ASTQueries { this.bindings = new IBinding[] { binding }; if (binding instanceof ICPPUsingDeclaration) { - this.bindings= ((ICPPUsingDeclaration) binding).getDelegates(); - kind= KIND_COMPOSITE; + this.bindings = ((ICPPUsingDeclaration) binding).getDelegates(); + kind = KIND_COMPOSITE; } else if (binding instanceof ILabel) { kind = KIND_LABEL; - } else if (binding instanceof ICompositeType || - binding instanceof ITypedef || - binding instanceof IEnumeration) { + } else if (binding instanceof ICompositeType || binding instanceof ITypedef + || binding instanceof IEnumeration) { kind = KIND_TYPE; } else if (binding instanceof ICPPNamespace) { kind = KIND_NAMESPACE; } else if (binding instanceof ICPPTemplateParameter) { - kind = KIND_COMPOSITE; + kind = KIND_COMPOSITE; } else { kind = KIND_OBJ_FN; } @@ -1794,7 +1788,7 @@ public class CPPVisitor extends ASTQueries { ASTNodeProperty prop = name.getPropertyInParent(); ASTNodeProperty p2 = null; if (prop == ICPPASTQualifiedName.SEGMENT_NAME) { - p2 = prop; + p2 = prop; prop = name.getParent().getPropertyInParent(); } @@ -1806,62 +1800,53 @@ public class CPPVisitor extends ASTQueries { case KIND_TYPE: case KIND_COMPOSITE: - if (prop == IASTNamedTypeSpecifier.NAME || - prop == ICPPASTPointerToMember.NAME || - prop == ICPPASTUsingDeclaration.NAME || - prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME_SPECIFIER || - prop == ICPPASTTemplateId.TEMPLATE_NAME || - p2 == ICPPASTQualifiedName.SEGMENT_NAME) { + if (prop == IASTNamedTypeSpecifier.NAME || prop == ICPPASTPointerToMember.NAME + || prop == ICPPASTUsingDeclaration.NAME + || prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME_SPECIFIER + || prop == ICPPASTTemplateId.TEMPLATE_NAME || p2 == ICPPASTQualifiedName.SEGMENT_NAME) { break; - } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { + } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { IASTNode p = name.getParent().getParent(); - if (!(p instanceof IASTSimpleDeclaration) || - ((IASTSimpleDeclaration) p).getDeclarators().length > 0) { + if (!(p instanceof IASTSimpleDeclaration) + || ((IASTSimpleDeclaration) p).getDeclarators().length > 0) { break; } } if (kind == KIND_TYPE) - return PROCESS_CONTINUE; + return PROCESS_CONTINUE; //$FALL-THROUGH$ case KIND_OBJ_FN: - if (prop == IASTIdExpression.ID_NAME || - prop == IASTFieldReference.FIELD_NAME || - prop == ICPPASTUsingDirective.QUALIFIED_NAME || - prop == ICPPASTUsingDeclaration.NAME || - prop == IASTFunctionCallExpression.FUNCTION_NAME || - prop == ICPPASTUsingDeclaration.NAME || - prop == IASTNamedTypeSpecifier.NAME || - prop == ICPPASTConstructorChainInitializer.MEMBER_ID || - prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT || - prop == ICPPASTCapture.IDENTIFIER || - prop == IASTImplicitNameOwner.IMPLICIT_NAME) { + if (prop == IASTIdExpression.ID_NAME || prop == IASTFieldReference.FIELD_NAME + || prop == ICPPASTUsingDirective.QUALIFIED_NAME || prop == ICPPASTUsingDeclaration.NAME + || prop == IASTFunctionCallExpression.FUNCTION_NAME || prop == ICPPASTUsingDeclaration.NAME + || prop == IASTNamedTypeSpecifier.NAME || prop == ICPPASTConstructorChainInitializer.MEMBER_ID + || prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT || prop == ICPPASTCapture.IDENTIFIER + || prop == IASTImplicitNameOwner.IMPLICIT_NAME) { break; } return PROCESS_CONTINUE; case KIND_NAMESPACE: - if (prop == ICPPASTUsingDirective.QUALIFIED_NAME || - prop == ICPPASTNamespaceAlias.MAPPING_NAME || - prop == ICPPASTUsingDeclaration.NAME || - p2 == ICPPASTQualifiedName.SEGMENT_NAME) { + if (prop == ICPPASTUsingDirective.QUALIFIED_NAME || prop == ICPPASTNamespaceAlias.MAPPING_NAME + || prop == ICPPASTUsingDeclaration.NAME || p2 == ICPPASTQualifiedName.SEGMENT_NAME) { break; } return PROCESS_CONTINUE; } if (bindings != null) { - if (isReferenceBinding(name.resolveBinding())) { - if (refs.length == idx) { + if (isReferenceBinding(name.resolveBinding())) { + if (refs.length == idx) { refs = Arrays.copyOf(refs, refs.length * 2); - } - refs[idx++] = name; - } + } + refs[idx++] = name; + } } return PROCESS_CONTINUE; } private boolean isReferenceBinding(IBinding nameBinding) { - nameBinding= unwindBinding(nameBinding); + nameBinding = unwindBinding(nameBinding); if (nameBinding != null) { for (IBinding binding : bindings) { if (areEquivalentBindings(nameBinding, binding, index)) { @@ -1869,7 +1854,7 @@ public class CPPVisitor extends ASTQueries { } } if (nameBinding instanceof ICPPUsingDeclaration) { - IBinding[] delegates= ((ICPPUsingDeclaration) nameBinding).getDelegates(); + IBinding[] delegates = ((ICPPUsingDeclaration) nameBinding).getDelegates(); for (IBinding delegate : delegates) { if (isReferenceBinding(delegate)) { return true; @@ -1894,15 +1879,15 @@ public class CPPVisitor extends ASTQueries { */ public static ICPPFunctionType createImplicitFunctionType(IType returnType, IParameter[] parameters, boolean isConst, boolean isVolatile) { - IType[] pTypes = new IType[parameters.length]; - IType pt = null; + IType[] pTypes = new IType[parameters.length]; + IType pt = null; - for (int i = 0; i < parameters.length; i++) { - pt = parameters[i].getType(); + for (int i = 0; i < parameters.length; i++) { + pt = parameters[i].getType(); // remove qualifiers if (pt instanceof IQualifierType) { - pt= ((IQualifierType) pt).getType(); + pt = ((IQualifierType) pt).getType(); } if (pt instanceof IArrayType) { @@ -1911,10 +1896,10 @@ public class CPPVisitor extends ASTQueries { pt = new CPPPointerType(pt); } - pTypes[i] = pt; - } + pTypes[i] = pt; + } - return new CPPFunctionType(returnType, pTypes, isConst, isVolatile, false, false, false); + return new CPPFunctionType(returnType, pTypes, isConst, isVolatile, false, false, false); } /** @@ -1940,35 +1925,34 @@ public class CPPVisitor extends ASTQueries { pt = createType(pt, pDtor); } } - - pt= adjustParameterType(pt, forFuncType); + + pt = adjustParameterType(pt, forFuncType); if (pDtor != null && findInnermostDeclarator(pDtor).declaresParameterPack()) { - pt= new CPPParameterPackType(pt); + pt = new CPPParameterPackType(pt); } return pt; } private static IType createFunctionType(IType returnType, ICPPASTFunctionDeclarator fnDtor) { - IType[] pTypes = createParameterTypes(fnDtor); - - IASTName name = fnDtor.getName().getLastName(); - if (name instanceof ICPPASTConversionName) { - returnType = createType(((ICPPASTConversionName) name).getTypeId()); - } else { - returnType = applyAttributes(returnType, fnDtor); - returnType = getPointerTypes(returnType, fnDtor); - } - - RefQualifier refQualifier = fnDtor.getRefQualifier(); - CPPFunctionType type = new CPPFunctionType(returnType, pTypes, fnDtor.isConst(), - fnDtor.isVolatile(), refQualifier != null, refQualifier == RefQualifier.RVALUE, - fnDtor.takesVarArgs()); - final IASTDeclarator nested = fnDtor.getNestedDeclarator(); - if (nested != null) { - return createType(type, nested); - } - return type; + IType[] pTypes = createParameterTypes(fnDtor); + + IASTName name = fnDtor.getName().getLastName(); + if (name instanceof ICPPASTConversionName) { + returnType = createType(((ICPPASTConversionName) name).getTypeId()); + } else { + returnType = applyAttributes(returnType, fnDtor); + returnType = getPointerTypes(returnType, fnDtor); + } + + RefQualifier refQualifier = fnDtor.getRefQualifier(); + CPPFunctionType type = new CPPFunctionType(returnType, pTypes, fnDtor.isConst(), fnDtor.isVolatile(), + refQualifier != null, refQualifier == RefQualifier.RVALUE, fnDtor.takesVarArgs()); + final IASTDeclarator nested = fnDtor.getNestedDeclarator(); + if (nested != null) { + return createType(type, nested); + } + return type; } /** @@ -1976,14 +1960,14 @@ public class CPPVisitor extends ASTQueries { */ public static IType[] createParameterTypes(ICPPASTFunctionDeclarator fnDtor) { ICPPASTParameterDeclaration[] params = fnDtor.getParameters(); - IType[] pTypes = new IType[params.length]; - for (int i = 0; i < params.length; i++) { - pTypes[i]= createType(params[i], true); - } - - if (pTypes.length == 1 && SemanticUtil.isVoidType(pTypes[0])) { - return IType.EMPTY_TYPE_ARRAY; // f(void) is the same as f(). - } + IType[] pTypes = new IType[params.length]; + for (int i = 0; i < params.length; i++) { + pTypes[i] = createType(params[i], true); + } + + if (pTypes.length == 1 && SemanticUtil.isVoidType(pTypes[0])) { + return IType.EMPTY_TYPE_ARRAY; // f(void) is the same as f(). + } return pTypes; } @@ -1993,7 +1977,7 @@ public class CPPVisitor extends ASTQueries { */ static IType adjustParameterType(final IType pt, boolean forFunctionType) { // Bug 239975 - IType t= SemanticUtil.getNestedType(pt, TDEF); + IType t = SemanticUtil.getNestedType(pt, TDEF); if (t instanceof IArrayType) { IArrayType at = (IArrayType) t; return new CPPPointerType(at.getType()); @@ -2012,16 +1996,16 @@ public class CPPVisitor extends ASTQueries { } private static IType getPointerTypes(IType type, IASTDeclarator declarator) { - IASTPointerOperator[] ptrOps = declarator.getPointerOperators(); + IASTPointerOperator[] ptrOps = declarator.getPointerOperators(); for (IASTPointerOperator ptrOp : ptrOps) { - if (ptrOp instanceof ICPPASTPointerToMember) { + if (ptrOp instanceof ICPPASTPointerToMember) { type = new CPPPointerToMemberType(type, (ICPPASTPointerToMember) ptrOp); - } else if (ptrOp instanceof IASTPointer) { - type = new CPPPointerType(type, (IASTPointer) ptrOp); - } else if (ptrOp instanceof ICPPASTReferenceOperator) { - final ICPPASTReferenceOperator refOp = (ICPPASTReferenceOperator) ptrOp; + } else if (ptrOp instanceof IASTPointer) { + type = new CPPPointerType(type, (IASTPointer) ptrOp); + } else if (ptrOp instanceof ICPPASTReferenceOperator) { + final ICPPASTReferenceOperator refOp = (ICPPASTReferenceOperator) ptrOp; type = new CPPReferenceType(type, refOp.isRValueReference()); - } + } } return type; } @@ -2030,7 +2014,7 @@ public class CPPVisitor extends ASTQueries { if (type instanceof IBasicType) { IBasicType basicType = (IBasicType) type; if (basicType.getKind() == IBasicType.Kind.eInt) { - IASTAttribute[] attributes = declarator.getAttributes(); + IASTAttribute[] attributes = declarator.getAttributes(); for (IASTAttribute attribute : attributes) { char[] name = attribute.getName(); if (CharArrayUtils.equals(name, "__mode__") || CharArrayUtils.equals(name, "mode")) { //$NON-NLS-1$ //$NON-NLS-2$ @@ -2046,14 +2030,13 @@ public class CPPVisitor extends ASTQueries { } else if (CharArrayUtils.equals(mode, "__DI__") || CharArrayUtils.equals(mode, "DI")) { //$NON-NLS-1$ //$NON-NLS-2$ SizeofCalculator sizeofs = new SizeofCalculator(declarator.getTranslationUnit()); int modifier; - if (sizeofs.sizeof_long != null && sizeofs.sizeof_int != null && - sizeofs.sizeof_long.size == 2 * sizeofs.sizeof_int.size) { + if (sizeofs.sizeof_long != null && sizeofs.sizeof_int != null + && sizeofs.sizeof_long.size == 2 * sizeofs.sizeof_int.size) { modifier = IBasicType.IS_LONG; } else { modifier = IBasicType.IS_LONG_LONG; } - type = new CPPBasicType(IBasicType.Kind.eInt, - modifier | getSignModifiers(basicType)); + type = new CPPBasicType(IBasicType.Kind.eInt, modifier | getSignModifiers(basicType)); } else if (CharArrayUtils.equals(mode, "__word__") || CharArrayUtils.equals(mode, "word")) { //$NON-NLS-1$ //$NON-NLS-2$ type = new CPPBasicType(IBasicType.Kind.eInt, IBasicType.IS_LONG | getSignModifiers(basicType)); @@ -2070,32 +2053,32 @@ public class CPPVisitor extends ASTQueries { } private static IType getArrayType(IType type, IASTArrayDeclarator declarator) { - IASTArrayModifier[] mods = declarator.getArrayModifiers(); - for (int i = mods.length; --i >= 0;) { - IASTArrayModifier mod = mods[i]; - IASTExpression sizeExpression = mod.getConstantExpression(); - if (sizeExpression != null) { - type = new CPPArrayType(type, sizeExpression); - } else { - IValue sizeValue = null; - IASTInitializer initializer = declarator.getInitializer(); - if (initializer instanceof IASTEqualsInitializer) { - IASTInitializerClause clause = ((IASTEqualsInitializer) initializer).getInitializerClause(); - if (clause instanceof IASTInitializerList) { - IASTInitializerClause[] clauses = ((IASTInitializerList) clause).getClauses(); - sizeValue = IntegralValue.create(clauses.length); - } else if (clause instanceof ICPPASTLiteralExpression) { - ICPPEvaluation value = ((ICPPASTExpression) clause).getEvaluation(); - IType valueType = value.getType(); - if (valueType instanceof IArrayType) { - sizeValue = ((IArrayType) valueType).getSize(); - } - } - } - type = new CPPArrayType(type, sizeValue); - } - } - return type; + IASTArrayModifier[] mods = declarator.getArrayModifiers(); + for (int i = mods.length; --i >= 0;) { + IASTArrayModifier mod = mods[i]; + IASTExpression sizeExpression = mod.getConstantExpression(); + if (sizeExpression != null) { + type = new CPPArrayType(type, sizeExpression); + } else { + IValue sizeValue = null; + IASTInitializer initializer = declarator.getInitializer(); + if (initializer instanceof IASTEqualsInitializer) { + IASTInitializerClause clause = ((IASTEqualsInitializer) initializer).getInitializerClause(); + if (clause instanceof IASTInitializerList) { + IASTInitializerClause[] clauses = ((IASTInitializerList) clause).getClauses(); + sizeValue = IntegralValue.create(clauses.length); + } else if (clause instanceof ICPPASTLiteralExpression) { + ICPPEvaluation value = ((ICPPASTExpression) clause).getEvaluation(); + IType valueType = value.getType(); + if (valueType instanceof IArrayType) { + sizeValue = ((IArrayType) valueType).getSize(); + } + } + } + type = new CPPArrayType(type, sizeValue); + } + } + return type; } public static PlaceholderKind usesAuto(IASTDeclSpecifier declSpec) { @@ -2123,18 +2106,18 @@ public class CPPVisitor extends ASTQueries { // Resolve placeholders by default. return createType(declarator, RESOLVE_PLACEHOLDERS); } - + public static IType createType(IASTDeclarator declarator, int flags) { if (declarator == null) return ProblemType.NO_NAME; CPPSemantics.pushLookupPoint(declarator); try { - declarator= findOutermostDeclarator(declarator); + declarator = findOutermostDeclarator(declarator); IASTNode parent = declarator.getParent(); - + IASTDeclSpecifier declSpec = null; - boolean isPackExpansion= false; + boolean isPackExpansion = false; if (parent instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); } else if (parent instanceof IASTParameterDeclaration) { @@ -2144,39 +2127,40 @@ public class CPPVisitor extends ASTQueries { } else if (parent instanceof ICPPASTTypeId) { final ICPPASTTypeId typeId = (ICPPASTTypeId) parent; declSpec = typeId.getDeclSpecifier(); - isPackExpansion= typeId.isPackExpansion(); + isPackExpansion = typeId.isPackExpansion(); } else if (parent instanceof ICPPASTInitCapture) { return createType((ICPPASTInitCapture) parent); } else { throw new IllegalArgumentException(); } - + PlaceholderKind placeholder = usesAuto(declSpec); if (placeholder != null) { return createAutoType(declSpec, declarator, flags, placeholder); } - + IType type = createType(declSpec); type = makeConstIfConstexpr(type, declSpec, declarator); type = createType(type, declarator, flags); - + // C++ specification 8.3.4.3 and 8.5.1.4 - IASTNode initClause= declarator.getInitializer(); + IASTNode initClause = declarator.getInitializer(); if (initClause instanceof IASTEqualsInitializer) { - initClause= ((IASTEqualsInitializer) initClause).getInitializerClause(); + initClause = ((IASTEqualsInitializer) initClause).getInitializerClause(); } if (initClause instanceof IASTInitializerList) { - IType t= SemanticUtil.getNestedType(type, TDEF); + IType t = SemanticUtil.getNestedType(type, TDEF); if (t instanceof IArrayType) { - IArrayType at= (IArrayType) t; + IArrayType at = (IArrayType) t; if (at.getSize() == null) { - type= new CPPArrayType(at.getType(), IntegralValue.create(((IASTInitializerList) initClause).getSize())); + type = new CPPArrayType(at.getType(), + IntegralValue.create(((IASTInitializerList) initClause).getSize())); } } } - + if (isPackExpansion) { - type= new CPPParameterPackType(type); + type = new CPPParameterPackType(type); } return type; } finally { @@ -2190,7 +2174,7 @@ public class CPPVisitor extends ASTQueries { if (placeholder == PlaceholderKind.DecltypeAuto) { return ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE; } - + // In C++14, auto is only allowed in lambda parameters. // In the Concepts TS (not implemented yet), this restriction is removed. ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declaration.getParent(); @@ -2198,7 +2182,7 @@ public class CPPVisitor extends ASTQueries { ICPPASTLambdaExpression lambda = (ICPPASTLambdaExpression) functionDeclarator.getParent(); CPPClosureType closure = (CPPClosureType) lambda.getExpressionType(); ICPPTemplateParameter[] templateParameters = closure.getInventedTemplateParameterList(); - + // Find the invented template parameter corresponding to this 'auto'. int templateParameterIndex = -1; for (ICPPASTParameterDeclaration parameter : functionDeclarator.getParameters()) { @@ -2219,7 +2203,7 @@ public class CPPVisitor extends ASTQueries { } private static ICPPASTInitializerClause getAutoInitClauseForDeclarator(IASTDeclarator declarator) { - IASTInitializer initClause= declarator.getInitializer(); + IASTInitializer initClause = declarator.getInitializer(); if (initClause instanceof IASTEqualsInitializer) { return (ICPPASTInitializerClause) ((IASTEqualsInitializer) initClause).getInitializerClause(); } else if (initClause instanceof ICPPASTConstructorInitializer) { @@ -2239,11 +2223,10 @@ public class CPPVisitor extends ASTQueries { return null; } - private static IType createAutoType(final IASTDeclSpecifier declSpec, IASTDeclarator declarator, - int flags, PlaceholderKind placeholderKind) { - IType cannotDeduce = placeholderKind == PlaceholderKind.Auto ? - ProblemType.CANNOT_DEDUCE_AUTO_TYPE : - ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE; + private static IType createAutoType(final IASTDeclSpecifier declSpec, IASTDeclarator declarator, int flags, + PlaceholderKind placeholderKind) { + IType cannotDeduce = placeholderKind == PlaceholderKind.Auto ? ProblemType.CANNOT_DEDUCE_AUTO_TYPE + : ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE; Set<IASTDeclarator> recursionProtectionSet = autoTypeDeclarators.get(); if (!recursionProtectionSet.add(declarator)) { // Detected a self referring auto type, e.g.: auto x = x; @@ -2252,13 +2235,12 @@ public class CPPVisitor extends ASTQueries { try { if (declarator instanceof ICPPASTFunctionDeclarator) { - return createAutoFunctionType(declSpec, (ICPPASTFunctionDeclarator) declarator, flags, - placeholderKind); + return createAutoFunctionType(declSpec, (ICPPASTFunctionDeclarator) declarator, flags, placeholderKind); } if (declarator.getParent() instanceof ICPPASTParameterDeclaration) { if (declarator.getParent().getParent() instanceof ICPPASTFunctionDeclarator) { // 'auto' used as the type of a function parameter. - return createAutoParameterType(declSpec, declarator, + return createAutoParameterType(declSpec, declarator, (ICPPASTParameterDeclaration) declarator.getParent(), placeholderKind); } else { if (placeholderKind == PlaceholderKind.Auto) { @@ -2270,7 +2252,7 @@ public class CPPVisitor extends ASTQueries { } } } - ICPPASTInitializerClause autoInitClause= null; + ICPPASTInitializerClause autoInitClause = null; IASTNode parent = declarator.getParent().getParent(); if (parent instanceof ICPPASTNewExpression) { IASTInitializer initializer = ((ICPPASTNewExpression) parent).getInitializer(); @@ -2282,39 +2264,40 @@ public class CPPVisitor extends ASTQueries { } } else if (parent instanceof ICPPASTRangeBasedForStatement) { // See 6.5.4 The range-based for statement [stmt.ranged] - ICPPASTRangeBasedForStatement forStmt= (ICPPASTRangeBasedForStatement) parent; + ICPPASTRangeBasedForStatement forStmt = (ICPPASTRangeBasedForStatement) parent; IASTInitializerClause forInit = forStmt.getInitializerClause(); - IASTExpression beginExpr= null; + IASTExpression beginExpr = null; if (forInit instanceof IASTExpression) { final IASTExpression expr = (IASTExpression) forInit; - IType type= SemanticUtil.getNestedType(expr.getExpressionType(), TDEF | CVTYPE); + IType type = SemanticUtil.getNestedType(expr.getExpressionType(), TDEF | CVTYPE); if (type instanceof IArrayType) { - beginExpr= expr.copy(); + beginExpr = expr.copy(); } } if (beginExpr == null) { - IASTImplicitName[] implicits= forStmt.getImplicitNames(); + IASTImplicitName[] implicits = forStmt.getImplicitNames(); if (implicits.length > 0) { - IBinding b= implicits[0].getBinding(); - CPPASTName name= new CPPASTName(); + IBinding b = implicits[0].getBinding(); + CPPASTName name = new CPPASTName(); name.setBinding(b); IASTInitializerClause[] beginCallArguments = new IASTInitializerClause[] { forInit.copy() }; if (b instanceof ICPPMethod && forInit instanceof IASTExpression) { - beginExpr= new CPPASTFunctionCallExpression( + beginExpr = new CPPASTFunctionCallExpression( new CPPASTFieldReference(name, (IASTExpression) forInit.copy()), beginCallArguments); } else { - beginExpr= new CPPASTFunctionCallExpression(new CPPASTIdExpression(name), beginCallArguments); + beginExpr = new CPPASTFunctionCallExpression(new CPPASTIdExpression(name), + beginCallArguments); } } else { return cannotDeduce; } } - autoInitClause= new CPPASTUnaryExpression(IASTUnaryExpression.op_star, beginExpr); + autoInitClause = new CPPASTUnaryExpression(IASTUnaryExpression.op_star, beginExpr); autoInitClause.setParent(forStmt); autoInitClause.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER); - } else if (parent instanceof IASTCompositeTypeSpecifier && - declSpec.getStorageClass() != IASTDeclSpecifier.sc_static) { + } else if (parent instanceof IASTCompositeTypeSpecifier + && declSpec.getStorageClass() != IASTDeclSpecifier.sc_static) { // Non-static auto-typed class members are not allowed. return ProblemType.AUTO_FOR_NON_STATIC_FIELD; } else { @@ -2335,7 +2318,7 @@ public class CPPVisitor extends ASTQueries { return ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE; } if (autoInitClause instanceof IASTExpression) { - return getDeclType((IASTExpression) autoInitClause); + return getDeclType((IASTExpression) autoInitClause); } else { return ProblemType.CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE; } @@ -2350,7 +2333,7 @@ public class CPPVisitor extends ASTQueries { // C++0x: 7.1.6.4 IType type = AutoTypeResolver.AUTO_TYPE; IType initType = null; - ValueCategory valueCat= null; + ValueCategory valueCat = null; initType = evaluation.getType(); valueCat = evaluation.getValueCategory(); if (initType == null || initType instanceof ISemanticProblem) { @@ -2398,14 +2381,14 @@ public class CPPVisitor extends ASTQueries { } return type; } - + private static class ReturnTypeDeducer extends ReturnStatementVisitor { - private static final ICPPEvaluation voidEval = new EvalFixed( - CPPSemantics.VOID_TYPE, ValueCategory.PRVALUE, IntegralValue.UNKNOWN); - + private static final ICPPEvaluation voidEval = new EvalFixed(CPPSemantics.VOID_TYPE, ValueCategory.PRVALUE, + IntegralValue.UNKNOWN); + private ICPPEvaluation[] fReturnEvals = ICPPEvaluation.EMPTY_ARRAY; private boolean fEncounteredReturnStatement = false; - + protected ReturnTypeDeducer(IASTFunctionDefinition func) { super(func); } @@ -2423,17 +2406,17 @@ public class CPPVisitor extends ASTQueries { IType returnType = returnEval.getType(); if (returnType instanceof ISemanticProblem) { // If a function makes a recursive call in some of its return statements, - // the type those return expressions will be a problem type. We ignore - // these, because we can still successfully deduce from another return + // the type those return expressions will be a problem type. We ignore + // these, because we can still successfully deduce from another return // statement that is not recursive. // If all return statements are recursive, fReturnEvals will remain empty // and deduceReturnType() will error out as desired. return; } - + fReturnEvals = ArrayUtil.append(fReturnEvals, returnEval); } - + public ICPPEvaluation[] getReturnEvaluations() { if (fReturnEvals.length == 0 && !fEncounteredReturnStatement) { fReturnEvals = ArrayUtil.append(fReturnEvals, voidEval); @@ -2442,8 +2425,8 @@ public class CPPVisitor extends ASTQueries { } } - private static IType deduceTypeFromReturnEvaluation(ICPPEvaluation returnEval, - IASTDeclSpecifier autoDeclSpec, IASTDeclarator autoDeclarator, PlaceholderKind placeholder) { + private static IType deduceTypeFromReturnEvaluation(ICPPEvaluation returnEval, IASTDeclSpecifier autoDeclSpec, + IASTDeclarator autoDeclarator, PlaceholderKind placeholder) { // [dcl.type.auto.deduct] p3: // If the deduction is for a return statement and the initializer is a // braced-init-list, the proram is ill-formed. @@ -2465,8 +2448,8 @@ public class CPPVisitor extends ASTQueries { return createAutoType(returnEval, autoDeclSpec, autoDeclarator); } } - - public static IType deduceReturnType(IASTStatement functionBody, IASTDeclSpecifier autoDeclSpec, + + public static IType deduceReturnType(IASTStatement functionBody, IASTDeclSpecifier autoDeclSpec, IASTDeclarator autoDeclarator, PlaceholderKind placeholder) { ICPPEvaluation[] returnEvals = ICPPEvaluation.EMPTY_ARRAY; if (functionBody != null) { @@ -2477,28 +2460,26 @@ public class CPPVisitor extends ASTQueries { if (returnEvals.length == 0) { return ProblemType.CANNOT_DEDUCE_AUTO_TYPE; } - - // [dcl.spec.auto] p7: - // If a function with a declared return type that contains a placeholder type has multiple + + // [dcl.spec.auto] p7: + // If a function with a declared return type that contains a placeholder type has multiple // return statements, the return type is deduced for each such return statement. // If the type deduced is not the same in each deduction, the program is ill-formed. - IType returnType = deduceTypeFromReturnEvaluation(returnEvals[0], autoDeclSpec, autoDeclarator, - placeholder); + IType returnType = deduceTypeFromReturnEvaluation(returnEvals[0], autoDeclSpec, autoDeclarator, placeholder); for (int i = 1; i < returnEvals.length; ++i) { - IType otherType = deduceTypeFromReturnEvaluation(returnEvals[i], autoDeclSpec, autoDeclarator, - placeholder); + IType otherType = deduceTypeFromReturnEvaluation(returnEvals[i], autoDeclSpec, autoDeclarator, placeholder); if (!returnType.isSameType(otherType)) { return ProblemType.CANNOT_DEDUCE_AUTO_TYPE; } } return returnType; } - + /** * C++0x: [8.3.5-2] */ - private static IType createAutoFunctionType(IASTDeclSpecifier declSpec, - ICPPASTFunctionDeclarator declarator, int flags, PlaceholderKind placeholder) { + private static IType createAutoFunctionType(IASTDeclSpecifier declSpec, ICPPASTFunctionDeclarator declarator, + int flags, PlaceholderKind placeholder) { IType returnType = null; IASTDeclSpecifier declSpecForDeduction = null; IASTDeclarator declaratorForDeduction = null; @@ -2528,28 +2509,28 @@ public class CPPVisitor extends ASTQueries { returnType = qualifyType(returnType, declSpec); } } - + if (returnType == null) { // Try to deduce return type from return statement. - + // [dcl.spec.auto] p12: // A function declared with a return type that uses a placeholder type // shall not be virtual. if (((ICPPASTDeclSpecifier) declSpec).isVirtual()) return ProblemType.AUTO_FOR_VIRTUAL_METHOD; - - ICPPASTFunctionDefinition definition= CPPFunction.getFunctionDefinition(declarator); + + ICPPASTFunctionDefinition definition = CPPFunction.getFunctionDefinition(declarator); if (definition != null) { - returnType = deduceReturnType(definition.getBody(), declSpecForDeduction, - declaratorForDeduction, placeholder); + returnType = deduceReturnType(definition.getBody(), declSpecForDeduction, declaratorForDeduction, + placeholder); } } - + if (returnType != null) { if ((flags & ONLY_RETURN_TYPE) != 0) { return returnType; } - + // Do not use createFunctionType() because that would decorate the return type // with pointer operators from e.g. an 'auto &', but we have already done that // above. @@ -2564,20 +2545,20 @@ public class CPPVisitor extends ASTQueries { return result; } return ProblemType.NO_NAME; - + } public static IType createType(IASTDeclSpecifier declSpec) { - IType type = getBaseType(declSpec); + IType type = getBaseType(declSpec); return qualifyType(type, declSpec); } private static IType getBaseType(IASTDeclSpecifier declSpec) { - IASTName name; - if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { + IASTName name; + if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { name = ((ICPPASTCompositeTypeSpecifier) declSpec).getName(); - } else if (declSpec instanceof ICPPASTNamedTypeSpecifier) { - name = ((ICPPASTNamedTypeSpecifier) declSpec).getName(); + } else if (declSpec instanceof ICPPASTNamedTypeSpecifier) { + name = ((ICPPASTNamedTypeSpecifier) declSpec).getName(); } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) { name = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName(); } else if (declSpec instanceof IASTEnumerationSpecifier) { @@ -2595,18 +2576,18 @@ public class CPPVisitor extends ASTQueries { } else { throw new IllegalArgumentException(); } - if (name == null) + if (name == null) return ProblemType.NO_NAME; - IBinding binding = name.resolvePreBinding(); - if (!(binding instanceof IProblemBinding)) { - if (binding instanceof ICPPConstructor) - return ((ICPPConstructor) binding).getClassOwner(); + IBinding binding = name.resolvePreBinding(); + if (!(binding instanceof IProblemBinding)) { + if (binding instanceof ICPPConstructor) + return ((ICPPConstructor) binding).getClassOwner(); - if (binding instanceof IType) - return (IType) binding; - } - return ProblemType.UNRESOLVED_NAME; + if (binding instanceof IType) + return (IType) binding; + } + return ProblemType.UNRESOLVED_NAME; } // Helper function for createAutoType(). @@ -2636,22 +2617,22 @@ public class CPPVisitor extends ASTQueries { private static IType createType(IType baseType, IASTDeclarator declarator) { return createType(baseType, declarator, 0); } - + private static IType createType(IType baseType, IASTDeclarator declarator, int flags) { - if (((flags & ONLY_RETURN_TYPE) == 0) && declarator instanceof ICPPASTFunctionDeclarator) - return createFunctionType(baseType, (ICPPASTFunctionDeclarator) declarator); + if (((flags & ONLY_RETURN_TYPE) == 0) && declarator instanceof ICPPASTFunctionDeclarator) + return createFunctionType(baseType, (ICPPASTFunctionDeclarator) declarator); IType type = baseType; type = applyAttributes(type, declarator); type = getPointerTypes(type, declarator); if (declarator instanceof IASTArrayDeclarator) - type = getArrayType(type, (IASTArrayDeclarator) declarator); + type = getArrayType(type, (IASTArrayDeclarator) declarator); - IASTDeclarator nested = declarator.getNestedDeclarator(); - if (nested != null) { - return createType(type, nested); - } - return type; + IASTDeclarator nested = declarator.getNestedDeclarator(); + if (nested != null) { + return createType(type, nested); + } + return type; } /** @@ -2673,14 +2654,14 @@ public class CPPVisitor extends ASTQueries { * Computes the type for an expression in decltype(expr) context. */ private static IType getDeclType(IASTExpression expr) { - IASTName namedEntity= null; + IASTName namedEntity = null; if (expr instanceof IASTIdExpression) { - namedEntity= ((IASTIdExpression) expr).getName(); + namedEntity = ((IASTIdExpression) expr).getName(); } else if (expr instanceof IASTFieldReference) { - namedEntity= ((IASTFieldReference) expr).getFieldName(); + namedEntity = ((IASTFieldReference) expr).getFieldName(); } if (namedEntity != null) { - IBinding b= namedEntity.resolvePreBinding(); + IBinding b = namedEntity.resolvePreBinding(); if (b instanceof IType) { return (IType) b; } @@ -2694,10 +2675,10 @@ public class CPPVisitor extends ASTQueries { IType type = expr.getExpressionType(); switch (expr.getValueCategory()) { case XVALUE: - type= new CPPReferenceType(type, true); + type = new CPPReferenceType(type, true); break; case LVALUE: - type= new CPPReferenceType(type, false); + type = new CPPReferenceType(type, false); break; case PRVALUE: break; @@ -2706,7 +2687,7 @@ public class CPPVisitor extends ASTQueries { } public static IType getImpliedObjectType(IScope scope) { - try { + try { IASTNode node = null; while (scope != null) { if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope) { @@ -2720,7 +2701,7 @@ public class CPPVisitor extends ASTQueries { // Might be in the default member initializer on a field. IType type = ((ICPPClassScope) scope).getClassType(); if (type instanceof ICPPClassTemplate) { - type= (ICPPClassType) ((ICPPClassTemplate) type).asDeferredInstance(); + type = (ICPPClassType) ((ICPPClassTemplate) type).asDeferredInstance(); } return type; } @@ -2742,20 +2723,20 @@ public class CPPVisitor extends ASTQueries { ICPPClassScope cScope = (ICPPClassScope) s; IType type = cScope.getClassType(); if (type instanceof ICPPClassTemplate) { - type= (ICPPClassType) ((ICPPClassTemplate) type).asDeferredInstance(); + type = (ICPPClassType) ((ICPPClassTemplate) type).asDeferredInstance(); } return SemanticUtil.addQualifiers(type, dtor.isConst(), dtor.isVolatile(), false); } } } } catch (DOMException e) { - return e.getProblem(); + return e.getProblem(); } return null; } public static IType getPointerDiffType() { - IType t= getStdType(PTRDIFF_T); + IType t = getStdType(PTRDIFF_T); return t != null ? t : CPPBasicType.LONG; } @@ -2764,11 +2745,11 @@ public class CPPVisitor extends ASTQueries { if (node == null) return null; ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); - IBinding[] std= ast.getScope().find(STD, ast); + IBinding[] std = ast.getScope().find(STD, ast); for (IBinding binding : std) { if (binding instanceof ICPPNamespace) { final ICPPNamespaceScope scope = ((ICPPNamespace) binding).getNamespaceScope(); - IBinding[] bs= CPPSemantics.findBindings(scope, name, false, node); + IBinding[] bs = CPPSemantics.findBindings(scope, name, false, node); if (bs.length > 0) { for (IBinding b : bs) { if (b instanceof IType && CPPSemantics.declaredBefore(b, node, false)) { @@ -2782,17 +2763,17 @@ public class CPPVisitor extends ASTQueries { } public static IType get_type_info() { - IType t= getStdType(TYPE_INFO); + IType t = getStdType(TYPE_INFO); return t != null ? t : CPPBasicType.INT; } public static IType get_SIZE_T() { - IType t= getStdType(SIZE_T); + IType t = getStdType(SIZE_T); return t != null ? t : CPPBasicType.UNSIGNED_LONG; } public static ICPPClassTemplate get_initializer_list() { - IType t= getStdType(INITIALIZER_LIST); + IType t = getStdType(INITIALIZER_LIST); if (t instanceof ICPPClassTemplate) return (ICPPClassTemplate) t; return null; @@ -2825,10 +2806,10 @@ public class CPPVisitor extends ASTQueries { public static IASTName[] getDeclarations(IASTTranslationUnit tu, IBinding binding) { return getDeclarations(tu, binding, false); } - + public static IASTName[] getDeclarations(IASTTranslationUnit tu, IBinding binding, boolean permissive) { - CollectDeclarationsAction action = new CollectDeclarationsAction(binding, permissive); - tu.accept(action); + CollectDeclarationsAction action = new CollectDeclarationsAction(binding, permissive); + tu.accept(action); IASTName[] found = action.getDeclarations(); if (found.length == 0 && binding instanceof ICPPSpecialization && binding instanceof ICPPInternalBinding) { @@ -2855,52 +2836,52 @@ public class CPPVisitor extends ASTQueries { public static String[] getQualifiedName(IBinding binding) { String[] ns = null; - for (IBinding owner= binding.getOwner(); owner != null; owner= owner.getOwner()) { + for (IBinding owner = binding.getOwner(); owner != null; owner = owner.getOwner()) { if (owner instanceof ICPPEnumeration && !((ICPPEnumeration) owner).isScoped()) { continue; } - String name= owner.getName(); + String name = owner.getName(); if (name == null) break; - if (owner instanceof ICPPFunction) - break; - if (owner instanceof ICPPNamespace && name.length() == 0) { - continue; - } + if (owner instanceof ICPPFunction) + break; + if (owner instanceof ICPPNamespace && name.length() == 0) { + continue; + } - ns = ArrayUtil.append(String.class, ns, name); + ns = ArrayUtil.append(String.class, ns, name); } - ns = ArrayUtil.trim(String.class, ns); - String[] result = new String[ns.length + 1]; - for (int i = ns.length; --i >= 0;) { - result[ns.length - i - 1] = ns[i]; - } - result[ns.length]= binding.getName(); - return result; + ns = ArrayUtil.trim(String.class, ns); + String[] result = new String[ns.length + 1]; + for (int i = ns.length; --i >= 0;) { + result[ns.length - i - 1] = ns[i]; + } + result[ns.length] = binding.getName(); + return result; } public static char[][] getQualifiedNameCharArray(IBinding binding) { char[][] ns = EMPTY_CHAR_ARRAY_ARRAY; ns = ArrayUtil.append(ns, binding.getNameCharArray()); - for (IBinding owner= binding.getOwner(); owner != null; owner= owner.getOwner()) { - char[] name= owner.getNameCharArray(); + for (IBinding owner = binding.getOwner(); owner != null; owner = owner.getOwner()) { + char[] name = owner.getNameCharArray(); if (name == null) break; - if (owner instanceof ICPPFunction) - break; - if (owner instanceof ICPPNamespace && name.length == 0) - continue; + if (owner instanceof ICPPFunction) + break; + if (owner instanceof ICPPNamespace && name.length == 0) + continue; - ns = ArrayUtil.append(ns, name); + ns = ArrayUtil.append(ns, name); } - ns = ArrayUtil.trim(ns); - ArrayUtil.reverse(ns); - return ns; + ns = ArrayUtil.trim(ns); + ArrayUtil.reverse(ns); + return ns; } public static boolean isExternC(IASTNode node) { while (node != null) { - node= node.getParent(); + node = node.getParent(); if (node instanceof ICPPASTLinkageSpecification) { if ("\"C\"".equals(((ICPPASTLinkageSpecification) node).getLiteral())) { //$NON-NLS-1$ return true; @@ -2925,7 +2906,7 @@ public class CPPVisitor extends ASTQueries { @Deprecated public static boolean isLValueReference(IType t) { - t= SemanticUtil.getNestedType(t, TDEF); + t = SemanticUtil.getNestedType(t, TDEF); return t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference(); } @@ -2934,16 +2915,16 @@ public class CPPVisitor extends ASTQueries { */ public static IBinding findEnclosingFunctionOrClass(IASTNode node) { IASTName name = null; - for (; node != null; node= node.getParent()) { + for (; node != null; node = node.getParent()) { if (node instanceof IASTFunctionDefinition) { - IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + IASTDeclarator dtor = findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); if (dtor != null) { - name= dtor.getName(); + name = dtor.getName(); } break; } if (node instanceof IASTCompositeTypeSpecifier) { - name= ((IASTCompositeTypeSpecifier) node).getName(); + name = ((IASTCompositeTypeSpecifier) node).getName(); break; } } @@ -2954,7 +2935,7 @@ public class CPPVisitor extends ASTQueries { } public static IBinding findNameOwner(IASTName name, boolean allowFunction) { - IASTNode node= name.getLastName(); + IASTNode node = name.getLastName(); while (node instanceof IASTName) { if (node instanceof ICPPASTQualifiedName) { ICPPASTNameSpecifier[] segments = ((ICPPASTQualifiedName) node).getAllSegments(); @@ -2972,22 +2953,22 @@ public class CPPVisitor extends ASTQueries { } return bindingToOwner(binding); } - name= (IASTName) node; - node= node.getParent(); + name = (IASTName) node; + node = node.getParent(); } return findDeclarationOwner(node, allowFunction); } private static IBinding bindingToOwner(IBinding b) { if (b instanceof ITypedef) { - IType t= SemanticUtil.getNestedType((IType) b, TDEF); + IType t = SemanticUtil.getNestedType((IType) b, TDEF); if (t instanceof IBinding) return (IBinding) t; return b; } while (b instanceof ICPPNamespaceAlias) { - b= ((ICPPNamespaceAlias) b).getBinding(); + b = ((ICPPNamespaceAlias) b).getBinding(); } return b; } @@ -3008,32 +2989,32 @@ public class CPPVisitor extends ASTQueries { public static IASTName findDeclarationOwnerDefinition(IASTNode node, boolean allowFunction) { // Search for declaration - boolean isNonSimpleElabDecl= false; + boolean isNonSimpleElabDecl = false; while (!(node instanceof IASTDeclaration) && !(node instanceof ICPPASTLambdaExpression)) { if (node == null) return null; if (node instanceof IASTElaboratedTypeSpecifier) { - isNonSimpleElabDecl= true; - final IASTNode parent= node.getParent(); + isNonSimpleElabDecl = true; + final IASTNode parent = node.getParent(); if (parent instanceof IASTSimpleDeclaration) { final IASTSimpleDeclaration decl = (IASTSimpleDeclaration) parent; if (decl.getDeclarators().length == 0) { - isNonSimpleElabDecl= false; + isNonSimpleElabDecl = false; } } } else if (node instanceof IASTEnumerator) { break; } - node= node.getParent(); + node = node.getParent(); } - boolean isFriend= isFriendDeclaration(node); + boolean isFriend = isFriendDeclaration(node); // Search for enclosing binding. - for (node= node.getParent(); node != null; node= node.getParent()) { + for (node = node.getParent(); node != null; node = node.getParent()) { if (node instanceof IASTFunctionDefinition) { if (allowFunction) { - IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + IASTDeclarator dtor = findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); if (dtor != null) { return dtor.getName(); } @@ -3060,7 +3041,7 @@ public class CPPVisitor extends ASTQueries { public static boolean doesNotSpecifyType(IASTDeclSpecifier declspec) { if (declspec instanceof ICPPASTSimpleDeclSpecifier) { - ICPPASTSimpleDeclSpecifier ds= (ICPPASTSimpleDeclSpecifier) declspec; + ICPPASTSimpleDeclSpecifier ds = (ICPPASTSimpleDeclSpecifier) declspec; if (ds.getType() == IASTSimpleDeclSpecifier.t_unspecified) { if (ds.isShort() || ds.isLong() || ds.isLongLong() || ds.isSigned() || ds.isUnsigned()) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java index 8a94c16b773..f9491a81c8f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java @@ -27,7 +27,7 @@ public enum CVQualifier { final private int fQualifiers; private CVQualifier(int qualifiers) { - fQualifiers= qualifiers; + fQualifiers = qualifiers; } public boolean isConst() { @@ -60,14 +60,23 @@ public enum CVQualifier { private CVQualifier fromQualifier(final int q) { switch (q) { - case C|V|R: return CONST_VOLATILE_RESTRICT; - case V|R: return VOLATILE_RESTRICT; - case C|R: return CONST_RESTRICT; - case R: return RESTRICT; - case C|V: return CONST_VOLATILE; - case V: return VOLATILE; - case C: return CONST; - case 0: default: return NONE; + case C | V | R: + return CONST_VOLATILE_RESTRICT; + case V | R: + return VOLATILE_RESTRICT; + case C | R: + return CONST_RESTRICT; + case R: + return RESTRICT; + case C | V: + return CONST_VOLATILE; + case V: + return VOLATILE; + case C: + return CONST; + case 0: + default: + return NONE; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index f83bf1b2928..707ff7bd7e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -75,13 +75,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.ReferenceBind * Routines for calculating the cost of conversions. */ public class Conversions { - public enum UDCMode { ALLOWED, FORBIDDEN, DEFER } + public enum UDCMode { + ALLOWED, FORBIDDEN, DEFER + } + public enum Context { - ORDINARY, - IMPLICIT_OBJECT_FOR_METHOD_WITHOUT_REF_QUALIFIER, - IMPLICIT_OBJECT_FOR_METHOD_WITH_REF_QUALIFIER, - FIRST_PARAM_OF_DIRECT_COPY_CTOR, - REQUIRE_DIRECT_BINDING + ORDINARY, IMPLICIT_OBJECT_FOR_METHOD_WITHOUT_REF_QUALIFIER, IMPLICIT_OBJECT_FOR_METHOD_WITH_REF_QUALIFIER, + FIRST_PARAM_OF_DIRECT_COPY_CTOR, REQUIRE_DIRECT_BINDING } private static final char[] INITIALIZER_LIST_NAME = "initializer_list".toCharArray(); //$NON-NLS-1$ @@ -97,33 +97,33 @@ public class Conversions { * @return the cost of converting from source to target * @throws DOMException */ - public static Cost checkImplicitConversionSequence(IType target, IType exprType, - ValueCategory valueCat, UDCMode udc, Context ctx) throws DOMException { - final boolean isImpliedObject= - ctx == Context.IMPLICIT_OBJECT_FOR_METHOD_WITHOUT_REF_QUALIFIER || - ctx == Context.IMPLICIT_OBJECT_FOR_METHOD_WITH_REF_QUALIFIER; + public static Cost checkImplicitConversionSequence(IType target, IType exprType, ValueCategory valueCat, + UDCMode udc, Context ctx) throws DOMException { + final boolean isImpliedObject = ctx == Context.IMPLICIT_OBJECT_FOR_METHOD_WITHOUT_REF_QUALIFIER + || ctx == Context.IMPLICIT_OBJECT_FOR_METHOD_WITH_REF_QUALIFIER; if (isImpliedObject) - udc= UDCMode.FORBIDDEN; + udc = UDCMode.FORBIDDEN; - target= getNestedType(target, TDEF); - exprType= getNestedType(exprType, TDEF | REF); - final IType cv1T1= getNestedType(target, TDEF | REF); - final IType T1= getNestedType(cv1T1, TDEF | REF | ALLCVQ); + target = getNestedType(target, TDEF); + exprType = getNestedType(exprType, TDEF | REF); + final IType cv1T1 = getNestedType(target, TDEF | REF); + final IType T1 = getNestedType(cv1T1, TDEF | REF | ALLCVQ); if (target instanceof ICPPReferenceType) { - ReferenceBinding refBindingType= ReferenceBinding.OTHER_REF; + ReferenceBinding refBindingType = ReferenceBinding.OTHER_REF; // [8.5.3-5] initialization of a reference - final boolean isLValueRef= !((ICPPReferenceType) target).isRValueReference(); - final IType cv2T2= exprType; - final IType T2= getNestedType(cv2T2, TDEF | REF | ALLCVQ); + final boolean isLValueRef = !((ICPPReferenceType) target).isRValueReference(); + final IType cv2T2 = exprType; + final IType T2 = getNestedType(cv2T2, TDEF | REF | ALLCVQ); - refBindingType= isLValueRef ? ReferenceBinding.LVALUE_REF : ReferenceBinding.RVALUE_REF_BINDS_RVALUE; + refBindingType = isLValueRef ? ReferenceBinding.LVALUE_REF : ReferenceBinding.RVALUE_REF_BINDS_RVALUE; if (exprType instanceof InitializerListType) { if (isLValueRef && getCVQualifier(cv1T1) != CVQualifier.CONST) return Cost.NO_CONVERSION; - Cost cost= listInitializationSequence(((InitializerListType) exprType).getEvaluation(), T1, udc, false); + Cost cost = listInitializationSequence(((InitializerListType) exprType).getEvaluation(), T1, udc, + false); if (cost.converts()) { cost.setReferenceBinding(refBindingType); } @@ -143,9 +143,9 @@ public class Conversions { // [Note: The fact that such an argument is an rvalue does not affect the ranking of // implicit conversion sequences (13.3.3.2). — end note] if (valueCat != LVALUE) - refBindingType= ReferenceBinding.RVALUE_REF_BINDS_RVALUE; + refBindingType = ReferenceBinding.RVALUE_REF_BINDS_RVALUE; // ... and "cv1 T1" is reference-compatible with "cv2 T2" - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost = isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; @@ -156,7 +156,8 @@ public class Conversions { // 'cv3 T3' (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6) // and choosing the best one through overload resolution (13.3)), if (T2 instanceof ICPPClassType && udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2) < 0) { - Cost cost= initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, true, false, ctx); + Cost cost = initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, true, + false, ctx); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; @@ -174,8 +175,8 @@ public class Conversions { // and 'cv1 T1' is reference-compatible with 'cv2 T2', then the reference is bound to the value // of the initializer expression (or the appropriate base class subobject). if (valueCat == ValueCategory.XVALUE - || (valueCat == ValueCategory.PRVALUE && (T2 instanceof ICPPClassType || T2 instanceof IArrayType)) - || (valueCat == ValueCategory.LVALUE && T2 instanceof ICPPFunctionType)) { + || (valueCat == ValueCategory.PRVALUE && (T2 instanceof ICPPClassType || T2 instanceof IArrayType)) + || (valueCat == ValueCategory.LVALUE && T2 instanceof ICPPFunctionType)) { Cost cost = isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); if (cost != null) { cost.setReferenceBinding(refBindingType); @@ -192,7 +193,8 @@ public class Conversions { // conversion, the program is ill-formed [this is why we pass illFormedIfLValue = true]. if (T2 instanceof ICPPClassType) { if (udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2) < 0) { - Cost cost= initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, false, true, ctx); + Cost cost = initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, false, + true, ctx); if (cost != null) { if (cost != Cost.NO_CONVERSION) { cost.setReferenceBinding(refBindingType); @@ -208,7 +210,7 @@ public class Conversions { // 13.3.3.1.7 no temporary object when converting the implicit object parameter if (!isImpliedObject && ctx != Context.REQUIRE_DIRECT_BINDING) { - Cost cost= nonReferenceConversion(valueCat, cv2T2, T1, udc); + Cost cost = nonReferenceConversion(valueCat, cv2T2, T1, udc); if (cost.converts()) { cost.setReferenceBinding(refBindingType); } @@ -241,13 +243,12 @@ public class Conversions { * Note that there's a difference between returning null and returning Cost.NO_CONVERSION: * in the former case, the caller will continue trying other conversion methods. */ - private static Cost initializationByConversionForDirectReference(final IType cv1T1, final IType cv2T2, final ICPPClassType T2, - boolean needLValue, boolean illFormedIfLValue, Context ctx) - throws DOMException { - ICPPMethod[] fcns= SemanticUtil.getConversionOperators(T2); - Cost operatorCost= null; - FunctionCost bestUdcCost= null; - boolean ambiguousConversionOperator= false; + private static Cost initializationByConversionForDirectReference(final IType cv1T1, final IType cv2T2, + final ICPPClassType T2, boolean needLValue, boolean illFormedIfLValue, Context ctx) throws DOMException { + ICPPMethod[] fcns = SemanticUtil.getConversionOperators(T2); + Cost operatorCost = null; + FunctionCost bestUdcCost = null; + boolean ambiguousConversionOperator = false; if (fcns.length > 0 && !(fcns[0] instanceof IProblemBinding)) { for (final ICPPMethod op : fcns) { // Note: the special case of initializing a temporary to be bound to the first parameter @@ -256,24 +257,25 @@ public class Conversions { if (op.isExplicit() && ctx != Context.FIRST_PARAM_OF_DIRECT_COPY_CTOR) continue; final ICPPFunctionType ft = op.getType(); - IType t= getNestedType(ft.getReturnType(), TDEF); - final boolean isLValueRef= t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference(); + IType t = getNestedType(ft.getReturnType(), TDEF); + final boolean isLValueRef = t instanceof ICPPReferenceType + && !((ICPPReferenceType) t).isRValueReference(); if (needLValue && !isLValueRef) { continue; } - IType implicitParameterType= CPPSemantics.getImplicitParameterType(op); - Cost udcCost= isReferenceCompatible(getNestedType(implicitParameterType, TDEF | REF), cv2T2, true); // expression type to implicit object type + IType implicitParameterType = CPPSemantics.getImplicitParameterType(op); + Cost udcCost = isReferenceCompatible(getNestedType(implicitParameterType, TDEF | REF), cv2T2, true); // expression type to implicit object type if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost udcFuncCost= new FunctionCost(op, udcCost); - int cmp= udcFuncCost.compareTo(null, bestUdcCost); + FunctionCost udcFuncCost = new FunctionCost(op, udcCost); + int cmp = udcFuncCost.compareTo(null, bestUdcCost); if (cmp <= 0) { - Cost cost= isReferenceCompatible(cv1T1, getNestedType(t, TDEF | REF), false); // converted to target + Cost cost = isReferenceCompatible(cv1T1, getNestedType(t, TDEF | REF), false); // converted to target if (cost != null) { - bestUdcCost= udcFuncCost; - ambiguousConversionOperator= cmp == 0; - operatorCost= cost; + bestUdcCost = udcFuncCost; + ambiguousConversionOperator = cmp == 0; + operatorCost = cost; operatorCost.setUserDefinedConversion(op); if (illFormedIfLValue && isLValueRef) { @@ -294,22 +296,23 @@ public class Conversions { /** * 8.5-16 */ - private static Cost nonReferenceConversion(ValueCategory valueCat, IType source, IType target, UDCMode udc) throws DOMException { + private static Cost nonReferenceConversion(ValueCategory valueCat, IType source, IType target, UDCMode udc) + throws DOMException { if (source instanceof InitializerListType) { return listInitializationSequence(((InitializerListType) source).getEvaluation(), target, udc, false); } - IType uqTarget= SemanticUtil.getNestedType(target, TDEF | REF | CVTYPE); - IType uqSource= SemanticUtil.getNestedType(source, TDEF | REF | CVTYPE); + IType uqTarget = SemanticUtil.getNestedType(target, TDEF | REF | CVTYPE); + IType uqSource = SemanticUtil.getNestedType(source, TDEF | REF | CVTYPE); if (uqTarget instanceof ICPPClassType) { if (uqSource instanceof ICPPClassType) { // 13.3.3.1-6 Conceptual derived to base conversion - int depth= calculateInheritanceDepth(uqSource, uqTarget); + int depth = calculateInheritanceDepth(uqSource, uqTarget); if (depth >= 0) { if (depth == 0) { return new Cost(source, target, Rank.IDENTITY); } - Cost cost= new Cost(source, target, Rank.CONVERSION); + Cost cost = new Cost(source, target, Rank.CONVERSION); cost.setInheritanceDistance(depth); return cost; } @@ -324,7 +327,8 @@ public class Conversions { if (udc == UDCMode.FORBIDDEN) return Cost.NO_CONVERSION; - return initializationByConversion(valueCat, source, (ICPPClassType) uqSource, target, udc == UDCMode.DEFER, false); + return initializationByConversion(valueCat, source, (ICPPClassType) uqSource, target, udc == UDCMode.DEFER, + false); } return checkStandardConversionSequence(uqSource, target); @@ -354,43 +358,42 @@ public class Conversions { } return ArrayUtil.trim(result); } - + /** * Checks whether 'targetClass' can be initialized from 'list' according to the rules for * aggregate initialization ([dcl.init.aggr]). */ - static boolean checkAggregateInitialization(EvalInitList list, ICPPClassType targetClass) - throws DOMException { + static boolean checkAggregateInitialization(EvalInitList list, ICPPClassType targetClass) throws DOMException { ICPPField[] fields = getFieldsForAggregateInitialization(targetClass); ICPPEvaluation[] initializers = list.getClauses(); - + // p7: An initializer-list is ill-formed if the number of initializer-clauses exceeds // the number of members to initialize. if (initializers.length > fields.length) { return false; } - + // p3: The elements of the initializer list are taken as initializers for the elements // of the aggregate, in order. int i = 0; for (; i < initializers.length; ++i) { ICPPEvaluation initializer = initializers[i]; ICPPField field = fields[i]; - + // Each element is copy-initialized from the corresponding initializer-clause. - Cost cost = checkImplicitConversionSequence(field.getType(), initializer.getType(), + Cost cost = checkImplicitConversionSequence(field.getType(), initializer.getType(), initializer.getValueCategory(), UDCMode.ALLOWED, Context.ORDINARY); if (!cost.converts()) { return false; } - + // If the initializer-clause is an expression and a narrowing conversion is // required to convert the expression, the program is ill-formed. if (!(initializer instanceof EvalInitList) && cost.isNarrowingConversion()) { return false; } } - + // p8: If there are fewer initializer-clauses than there are elements in the // aggregate, then each element not explicitly initialized shall be // initialized from its default member initializer or, if there is no @@ -399,41 +402,42 @@ public class Conversions { ICPPField field = fields[i]; IValue initialValue = field.getInitialValue(); if (initialValue != null) { - continue; // has a default member initializer + continue; // has a default member initializer } - + // p11: If an incomplete or empty initializer-list leaves a member of // reference type uninitialized, the program is ill-formed. IType fieldType = SemanticUtil.getNestedType(field.getType(), TDEF); if (fieldType instanceof ICPPReferenceType) { return false; } - + // Empty initializer list - EvalInitList emptyInit = new EvalInitList(ICPPEvaluation.EMPTY_ARRAY, - CPPSemantics.getCurrentLookupPoint()); + EvalInitList emptyInit = new EvalInitList(ICPPEvaluation.EMPTY_ARRAY, CPPSemantics.getCurrentLookupPoint()); Cost cost = listInitializationSequence(emptyInit, fieldType, UDCMode.ALLOWED, false); if (!cost.converts()) { return false; } } - + // TODO: Implement brace elision rules. - + return true; } - + /** * 13.3.3.1.5 List-initialization sequence [over.ics.list] */ - static Cost listInitializationSequence(EvalInitList arg, IType target, UDCMode udc, boolean isDirect) throws DOMException { + static Cost listInitializationSequence(EvalInitList arg, IType target, UDCMode udc, boolean isDirect) + throws DOMException { Cost result = listInitializationSequenceHelper(arg, target, udc, isDirect); result.setListInitializationTarget(target); return result; } - static Cost listInitializationSequenceHelper(EvalInitList arg, IType target, UDCMode udc, boolean isDirect) throws DOMException { - IType listType= getInitListType(target); + static Cost listInitializationSequenceHelper(EvalInitList arg, IType target, UDCMode udc, boolean isDirect) + throws DOMException { + IType listType = getInitListType(target); if (listType == null && target instanceof IArrayType) { Number arraySize = ((IArrayType) target).getSize().numberValue(); if (arraySize != null) { @@ -448,10 +452,10 @@ public class Conversions { if (listType != null) { ICPPEvaluation[] clauses = arg.getClauses(); - Cost worstCost= new Cost(arg.getType(), target, Rank.IDENTITY); + Cost worstCost = new Cost(arg.getType(), target, Rank.IDENTITY); for (ICPPEvaluation clause : clauses) { - Cost cost= checkImplicitConversionSequence(listType, clause.getType(), - clause.getValueCategory(), UDCMode.ALLOWED, Context.ORDINARY); + Cost cost = checkImplicitConversionSequence(listType, clause.getType(), clause.getValueCategory(), + UDCMode.ALLOWED, Context.ORDINARY); if (!cost.converts()) return cost; if (cost.isNarrowingConversion()) { @@ -459,20 +463,20 @@ public class Conversions { return cost; } if (cost.compareTo(worstCost) > 0) { - worstCost= cost; + worstCost = cost; } } return worstCost; } - IType noCVTarget= getNestedType(target, CVTYPE | TDEF); + IType noCVTarget = getNestedType(target, CVTYPE | TDEF); if (noCVTarget instanceof ICPPClassType) { if (udc == UDCMode.FORBIDDEN) return Cost.NO_CONVERSION; - ICPPClassType classTarget= (ICPPClassType) noCVTarget; + ICPPClassType classTarget = (ICPPClassType) noCVTarget; if (TypeTraits.isAggregateClass(classTarget) && checkAggregateInitialization(arg, classTarget)) { - Cost cost= new Cost(arg.getType(), target, Rank.IDENTITY); + Cost cost = new Cost(arg.getType(), target, Rank.IDENTITY); cost.setUserDefinedConversion(null); return cost; } @@ -483,7 +487,8 @@ public class Conversions { if (args.length == 1) { final ICPPEvaluation firstArg = args[0]; if (!firstArg.isInitializerList()) { - Cost cost= checkImplicitConversionSequence(target, firstArg.getType(), firstArg.getValueCategory(), udc, Context.ORDINARY); + Cost cost = checkImplicitConversionSequence(target, firstArg.getType(), firstArg.getValueCategory(), + udc, Context.ORDINARY); if (cost.isNarrowingConversion()) { return Cost.NO_CONVERSION; } @@ -501,8 +506,7 @@ public class Conversions { ICPPTemplateInstance inst = (ICPPTemplateInstance) target; if (CharArrayUtils.equals(INITIALIZER_LIST_NAME, inst.getNameCharArray())) { IBinding owner = inst.getOwner(); - if (owner instanceof ICPPNamespace - && CharArrayUtils.equals(STD_NAME, owner.getNameCharArray()) + if (owner instanceof ICPPNamespace && CharArrayUtils.equals(STD_NAME, owner.getNameCharArray()) && owner.getOwner() == null) { ICPPTemplateArgument[] args = inst.getTemplateArguments(); if (args.length == 1) { @@ -540,15 +544,15 @@ public class Conversions { * @return inheritance distance, or -1, if <code>cv1t1</code> is not reference-related to <code>cv2t2</code> */ private static final int isReferenceRelated(IType cv1Target, IType cv2Source) { - IType t= SemanticUtil.getNestedType(cv1Target, TDEF | REF); - IType s= SemanticUtil.getNestedType(cv2Source, TDEF | REF); + IType t = SemanticUtil.getNestedType(cv1Target, TDEF | REF); + IType s = SemanticUtil.getNestedType(cv2Source, TDEF | REF); // The way cv-qualification is currently modeled means // we must cope with IPointerType objects separately. if (t instanceof IPointerType) { if (s instanceof IPointerType) { - t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF); - s= SemanticUtil.getNestedType(((IPointerType) s).getType(), TDEF | REF); + t = SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF); + s = SemanticUtil.getNestedType(((IPointerType) s).getType(), TDEF | REF); } else { return -1; } @@ -556,11 +560,11 @@ public class Conversions { if (s instanceof IArrayType) { final IArrayType at = (IArrayType) t; final IArrayType st = (IArrayType) s; - final IValue av= at.getSize(); - final IValue sv= st.getSize(); + final IValue av = at.getSize(); + final IValue sv = st.getSize(); if (av == sv || (av != null && av.equals(sv))) { - t= SemanticUtil.getNestedType(at.getType(), TDEF | REF | ALLCVQ); - s= SemanticUtil.getNestedType(st.getType(), TDEF | REF | ALLCVQ); + t = SemanticUtil.getNestedType(at.getType(), TDEF | REF | ALLCVQ); + s = SemanticUtil.getNestedType(st.getType(), TDEF | REF | ALLCVQ); } else { return -1; } @@ -569,9 +573,9 @@ public class Conversions { } } else { if (t instanceof IQualifierType) - t= SemanticUtil.getNestedType(((IQualifierType) t).getType(), TDEF | REF); + t = SemanticUtil.getNestedType(((IQualifierType) t).getType(), TDEF | REF); if (s instanceof IQualifierType) - s= SemanticUtil.getNestedType(((IQualifierType) s).getType(), TDEF | REF); + s = SemanticUtil.getNestedType(((IQualifierType) s).getType(), TDEF | REF); if (t instanceof ICPPClassType && s instanceof ICPPClassType) { return SemanticUtil.calculateInheritanceDepth(s, t); @@ -591,14 +595,14 @@ public class Conversions { * reference-compatible with <code>cv2t2</code> */ private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject) { - int inheritanceDist= isReferenceRelated(cv1Target, cv2Source); + int inheritanceDist = isReferenceRelated(cv1Target, cv2Source); if (inheritanceDist < 0) return null; - final int cmp= compareQualifications(cv1Target, cv2Source); + final int cmp = compareQualifications(cv1Target, cv2Source); if (cmp < 0) return null; - Cost cost= new Cost(cv2Source, cv1Target, Rank.IDENTITY); + Cost cost = new Cost(cv2Source, cv1Target, Rank.IDENTITY); cost.setQualificationAdjustment(cmp); if (inheritanceDist > 0) { cost.setInheritanceDistance(inheritanceDist); @@ -616,7 +620,7 @@ public class Conversions { * Computes the cost of using the standard conversion sequence from source to target. */ private static final Cost checkStandardConversionSequence(IType source, IType target) { - final Cost cost= new Cost(source, target, Rank.IDENTITY); + final Cost cost = new Cost(source, target, Rank.IDENTITY); if (lvalue_to_rvalue(cost)) return cost; @@ -635,44 +639,45 @@ public class Conversions { } // [over.match.list] Initialization by list-initialization - static Cost listInitializationOfClass(EvalInitList arg, ICPPClassType t, boolean isDirect, boolean deferUDC) throws DOMException { + static Cost listInitializationOfClass(EvalInitList arg, ICPPClassType t, boolean isDirect, boolean deferUDC) + throws DOMException { if (deferUDC) { - Cost c= new Cost(arg.getType(), t, Rank.USER_DEFINED_CONVERSION); + Cost c = new Cost(arg.getType(), t, Rank.USER_DEFINED_CONVERSION); c.setDeferredUDC(isDirect ? DeferredUDC.DIRECT_LIST_INIT_OF_CLASS : DeferredUDC.LIST_INIT_OF_CLASS); return c; } - + // p1: When objects of non-aggregate class type are list-initialized, // [...] overload resoution selects the constructor in two phases: // - Initially, the candidate functions are the initializer- - // list constructors of the class T and the argument list - // consists of the initializer list as a single argument. - - ICPPConstructor usedCtor= null; - Cost bestCost= null; + // list constructors of the class T and the argument list + // consists of the initializer list as a single argument. + + ICPPConstructor usedCtor = null; + Cost bestCost = null; final ICPPConstructor[] constructors = t.getConstructors(); - ICPPConstructor[] ctors= constructors; + ICPPConstructor[] ctors = constructors; for (ICPPConstructor ctor : ctors) { final int minArgCount = ctor.getRequiredArgumentCount(); if (minArgCount == 0) { if (arg.getClauses().length == 0) { - Cost c= new Cost(arg.getType(), t, Rank.IDENTITY); + Cost c = new Cost(arg.getType(), t, Rank.IDENTITY); c.setUserDefinedConversion(ctor); return c; } } else if (minArgCount <= 1) { - IType[] parTypes= ctor.getType().getParameterTypes(); + IType[] parTypes = ctor.getType().getParameterTypes(); if (parTypes.length > 0) { final IType target = parTypes[0]; if (getInitListType(target) != null) { - Cost cost= listInitializationSequence(arg, target, UDCMode.FORBIDDEN, isDirect); + Cost cost = listInitializationSequence(arg, target, UDCMode.FORBIDDEN, isDirect); if (cost.converts()) { - int cmp= cost.compareTo(bestCost); + int cmp = cost.compareTo(bestCost); if (bestCost == null || cmp < 0) { - usedCtor= ctor; + usedCtor = ctor; cost.setUserDefinedConversion(ctor); - bestCost= cost; + bestCost = cost; } else if (cmp == 0) { bestCost.setAmbiguousUDC(true); } @@ -696,44 +701,44 @@ public class Conversions { } // - If no viable initializer-list constructor is found, - // overload resolution is performed again, where the - // candidate functions are all the constructors of the - // class T and the argument list consists of the elements - // of the initializer list. + // overload resolution is performed again, where the + // candidate functions are all the constructors of the + // class T and the argument list consists of the elements + // of the initializer list. - LookupData data= new LookupData(t.getNameCharArray(), null, CPPSemantics.getCurrentLookupPoint()); - final ICPPEvaluation[] expandedArgs = arg.getClauses(); + LookupData data = new LookupData(t.getNameCharArray(), null, CPPSemantics.getCurrentLookupPoint()); + final ICPPEvaluation[] expandedArgs = arg.getClauses(); data.setFunctionArguments(false, expandedArgs); - data.fNoNarrowing= true; + data.fNoNarrowing = true; // 13.3.3.1.4 ICPPConstructor[] filteredConstructors = constructors; if (expandedArgs.length == 1) { - filteredConstructors= new ICPPConstructor[constructors.length]; - int j= 0; + filteredConstructors = new ICPPConstructor[constructors.length]; + int j = 0; for (ICPPConstructor ctor : constructors) { if (ctor.getRequiredArgumentCount() < 2) { - IType[] ptypes= ctor.getType().getParameterTypes(); + IType[] ptypes = ctor.getType().getParameterTypes(); if (ptypes.length > 0) { - IType ptype= getNestedType(ptypes[0], TDEF | REF | CVTYPE); + IType ptype = getNestedType(ptypes[0], TDEF | REF | CVTYPE); if (!t.isSameType(ptype)) { - filteredConstructors[j++]= ctor; + filteredConstructors[j++] = ctor; } } } } } - final IBinding result= CPPSemantics.resolveFunction(data, filteredConstructors, true, false); + final IBinding result = CPPSemantics.resolveFunction(data, filteredConstructors, true, false); final Cost c; if (result instanceof ICPPMethod) { - c= new Cost(arg.getType(), t, Rank.IDENTITY); + c = new Cost(arg.getType(), t, Rank.IDENTITY); c.setUserDefinedConversion((ICPPMethod) result); } else if (result instanceof IProblemBinding && ((IProblemBinding) result).getID() == IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP) { c = new Cost(arg.getType(), t, Rank.USER_DEFINED_CONVERSION); c.setAmbiguousUDC(true); } else { - c= Cost.NO_CONVERSION; + c = Cost.NO_CONVERSION; } // This cost came from listInitializationSequence() with an std::initializer_list // type as the list initialization target. From the point of view of the caller, @@ -746,25 +751,25 @@ public class Conversions { /** * 13.3.1.4 Copy-initialization of class by user-defined conversion [over.match.copy] */ - static final Cost copyInitializationOfClass(ValueCategory valueCat, IType source, ICPPClassType t, - boolean deferUDC) throws DOMException { + static final Cost copyInitializationOfClass(ValueCategory valueCat, IType source, ICPPClassType t, boolean deferUDC) + throws DOMException { if (deferUDC) { - Cost c= new Cost(source, t, Rank.USER_DEFINED_CONVERSION); + Cost c = new Cost(source, t, Rank.USER_DEFINED_CONVERSION); c.setDeferredUDC(DeferredUDC.COPY_INIT_OF_CLASS); return c; } - FunctionCost cost1= null; - Cost cost2= null; - ICPPFunction[] ctors= t.getConstructors(); - ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, - Collections.singletonList(source), Collections.singletonList(valueCat), false); + FunctionCost cost1 = null; + Cost cost2 = null; + ICPPFunction[] ctors = t.getConstructors(); + ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, Collections.singletonList(source), + Collections.singletonList(valueCat), false); for (ICPPFunction f : ctors) { if (!(f instanceof ICPPConstructor) || f instanceof IProblemBinding) continue; - ICPPConstructor ctor= (ICPPConstructor) f; + ICPPConstructor ctor = (ICPPConstructor) f; // Note: the special case of initializing a temporary to be bound to the first parameter // of a copy constructor called with a single argument in the context of direct-initialization // is (more naturally) handled in initializationByConversionForDirectReference. @@ -774,24 +779,25 @@ public class Conversions { FunctionCost c1; if (ptypes.length == 0) { if (ctor.takesVarArgs()) { - c1= new FunctionCost(ctor, new Cost(source, null, Rank.ELLIPSIS_CONVERSION)); + c1 = new FunctionCost(ctor, new Cost(source, null, Rank.ELLIPSIS_CONVERSION)); } else { continue; } } else { - IType ptype= SemanticUtil.getNestedType(ptypes[0], TDEF); + IType ptype = SemanticUtil.getNestedType(ptypes[0], TDEF); // We don't need to check the implicit conversion sequence if the type is void if (SemanticUtil.isVoidType(ptype)) continue; if (ctor.getRequiredArgumentCount() > 1) continue; - c1= new FunctionCost(ctor, checkImplicitConversionSequence(ptype, source, valueCat, UDCMode.FORBIDDEN, Context.ORDINARY)); + c1 = new FunctionCost(ctor, checkImplicitConversionSequence(ptype, source, valueCat, + UDCMode.FORBIDDEN, Context.ORDINARY)); } - int cmp= c1.compareTo(null, cost1); + int cmp = c1.compareTo(null, cost1); if (cmp <= 0) { - cost1= c1; - cost2= new Cost(t, t, Rank.IDENTITY); + cost1 = c1; + cost2 = new Cost(t, t, Rank.IDENTITY); cost2.setUserDefinedConversion(ctor); if (cmp == 0) { cost2.setAmbiguousUDC(true); @@ -800,29 +806,30 @@ public class Conversions { } } - final IType uqSource= getNestedType(source, TDEF | REF | CVTYPE); + final IType uqSource = getNestedType(source, TDEF | REF | CVTYPE); if (uqSource instanceof ICPPClassType) { ICPPFunction[] ops = SemanticUtil.getConversionOperators((ICPPClassType) uqSource); - ops= CPPTemplates.instantiateConversionTemplates(ops, t); + ops = CPPTemplates.instantiateConversionTemplates(ops, t); for (final ICPPFunction f : ops) { if (f instanceof ICPPMethod && !(f instanceof IProblemBinding)) { - ICPPMethod op= (ICPPMethod) f; + ICPPMethod op = (ICPPMethod) f; if (op.isExplicit()) continue; final IType returnType = op.getType().getReturnType(); - final IType uqReturnType= getNestedType(returnType, REF | TDEF | CVTYPE); + final IType uqReturnType = getNestedType(returnType, REF | TDEF | CVTYPE); final int dist = SemanticUtil.calculateInheritanceDepth(uqReturnType, t); if (dist >= 0) { - IType implicitType= CPPSemantics.getImplicitParameterType(op); - final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true); + IType implicitType = CPPSemantics.getImplicitParameterType(op); + final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, + true); if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost c1= new FunctionCost(op, udcCost); - int cmp= c1.compareTo(null, cost1); + FunctionCost c1 = new FunctionCost(op, udcCost); + int cmp = c1.compareTo(null, cost1); if (cmp <= 0) { - cost1= c1; - cost2= new Cost(t, t, Rank.IDENTITY); + cost1 = c1; + cost2 = new Cost(t, t, Rank.IDENTITY); if (dist > 0) { cost2.setInheritanceDistance(dist); cost2.setRank(Rank.CONVERSION); @@ -846,32 +853,34 @@ public class Conversions { /** * 13.3.1.5 Initialization by conversion function [over.match.conv] */ - static Cost initializationByConversion(ValueCategory valueCat, IType source, ICPPClassType uqSource, - IType target, boolean deferUDC, boolean allowExplicitConversion) throws DOMException { + static Cost initializationByConversion(ValueCategory valueCat, IType source, ICPPClassType uqSource, IType target, + boolean deferUDC, boolean allowExplicitConversion) throws DOMException { if (deferUDC) { - Cost c= new Cost(source, target, Rank.USER_DEFINED_CONVERSION); + Cost c = new Cost(source, target, Rank.USER_DEFINED_CONVERSION); c.setDeferredUDC(DeferredUDC.INIT_BY_CONVERSION); return c; } ICPPFunction[] ops = SemanticUtil.getConversionOperators(uqSource); - ops= CPPTemplates.instantiateConversionTemplates(ops, target); - FunctionCost cost1= null; - Cost cost2= null; + ops = CPPTemplates.instantiateConversionTemplates(ops, target); + FunctionCost cost1 = null; + Cost cost2 = null; for (final ICPPFunction f : ops) { if (f instanceof ICPPMethod && !(f instanceof IProblemBinding)) { - ICPPMethod op= (ICPPMethod) f; - final boolean isExplicitConversion= op.isExplicit() && !allowExplicitConversion; - if (isExplicitConversion /** && !direct **/) + ICPPMethod op = (ICPPMethod) f; + final boolean isExplicitConversion = op.isExplicit() && !allowExplicitConversion; + if (isExplicitConversion /** && !direct **/ + ) continue; ICPPFunctionType functionType = op.getType(); final IType returnType = functionType.getReturnType(); - IType uqReturnType= getNestedType(returnType, TDEF | ALLCVQ); - Cost c2= checkImplicitConversionSequence(target, uqReturnType, valueCategoryFromReturnType(uqReturnType), UDCMode.FORBIDDEN, Context.ORDINARY); + IType uqReturnType = getNestedType(returnType, TDEF | ALLCVQ); + Cost c2 = checkImplicitConversionSequence(target, uqReturnType, + valueCategoryFromReturnType(uqReturnType), UDCMode.FORBIDDEN, Context.ORDINARY); if (c2.converts()) { if (isExplicitConversion && c2.getRank() != Rank.IDENTITY) continue; - IType implicitType= CPPSemantics.getImplicitParameterType(op); + IType implicitType = CPPSemantics.getImplicitParameterType(op); final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true); if (udcCost != null) { // Make sure top-level cv-qualifiers are compared @@ -880,11 +889,11 @@ public class Conversions { } else { udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); } - FunctionCost c1= new FunctionCost(op, udcCost); - int cmp= c1.compareTo(null, cost1); + FunctionCost c1 = new FunctionCost(op, udcCost); + int cmp = c1.compareTo(null, cost1); if (cmp <= 0) { - cost1= c1; - cost2= c2; + cost1 = c1; + cost2 = c2; cost2.setUserDefinedConversion(op); if (cmp == 0) { cost2.setAmbiguousUDC(true); @@ -909,7 +918,7 @@ public class Conversions { */ private static final boolean lvalue_to_rvalue(final Cost cost) { IType target = getNestedType(cost.target, REF | TDEF | ALLCVQ); - IType source= getNestedType(cost.source, REF | TDEF); + IType source = getNestedType(cost.source, REF | TDEF); // 4.2 array to pointer conversion if (source instanceof IArrayType) { @@ -939,8 +948,8 @@ public class Conversions { cost.setRank(Rank.NO_MATCH); return true; } - cost.source= source; - cost.target= target; + cost.source = source; + cost.target = target; return source.isSameType(target); } @@ -948,20 +957,20 @@ public class Conversions { if (target instanceof ICPPPointerToMemberType) return source; - final IType targetPtrTgt= getNestedType((target).getType(), TDEF); + final IType targetPtrTgt = getNestedType((target).getType(), TDEF); if (targetPtrTgt instanceof IQualifierType && ((IQualifierType) targetPtrTgt).isConst()) return source; - IType srcTarget= ((ITypeContainer) source).getType(); + IType srcTarget = ((ITypeContainer) source).getType(); if (!(srcTarget instanceof IQualifierType)) return source; - final IQualifierType srcQTarget= (IQualifierType) srcTarget; + final IQualifierType srcQTarget = (IQualifierType) srcTarget; if (srcQTarget.isConst() && !srcQTarget.isVolatile()) { - srcTarget= srcQTarget.getType(); + srcTarget = srcQTarget.getType(); if (srcTarget instanceof CPPBasicType) { if (((CPPBasicType) srcTarget).isFromStringLiteral()) { - source= new CPPPointerType(srcTarget, false, false, false); + source = new CPPPointerType(srcTarget, false, false, false); CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST); cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3); } @@ -978,14 +987,14 @@ public class Conversions { IType s = cost.source; IType t = cost.target; boolean constInEveryCV2k = true; - boolean firstPointer= true; - int adjustments= 0; - int shift=0; + boolean firstPointer = true; + int adjustments = 0; + int shift = 0; while (true) { - s= getNestedType(s, TDEF | REF); - t= getNestedType(t, TDEF | REF); + s = getNestedType(s, TDEF | REF); + t = getNestedType(t, TDEF | REF); if (s instanceof IPointerType && t instanceof IPointerType) { - final int cmp= compareQualifications(t, s); // is t more qualified than s? + final int cmp = compareQualifications(t, s); // is t more qualified than s? if (cmp < 0 || (cmp > 0 && !constInEveryCV2k)) { return false; } @@ -995,24 +1004,24 @@ public class Conversions { return false; constInEveryCV2k &= (firstPointer || tPtr.isConst()); - s= sPtr.getType(); - t= tPtr.getType(); - firstPointer= false; + s = sPtr.getType(); + t = tPtr.getType(); + firstPointer = false; adjustments |= (cmp << shift); - shift+= 3; + shift += 3; } else { break; } } - int cmp= compareQualifications(t, s); // is t more qualified than s? + int cmp = compareQualifications(t, s); // is t more qualified than s? if (cmp < 0 || (cmp > 0 && !constInEveryCV2k)) { return false; } adjustments |= (cmp << shift); - s= getNestedType(s, ALLCVQ | TDEF | REF); - t= getNestedType(t, ALLCVQ | TDEF | REF); + s = getNestedType(s, ALLCVQ | TDEF | REF); + t = getNestedType(t, ALLCVQ | TDEF | REF); if (adjustments > 0) { cost.setQualificationAdjustment(adjustments); @@ -1053,7 +1062,7 @@ public class Conversions { IType src = cost.source; IType trg = cost.target; - boolean canPromote= false; + boolean canPromote = false; if (trg instanceof IBasicType) { IBasicType basicTgt = (IBasicType) trg; final Kind tKind = basicTgt.getKind(); @@ -1063,13 +1072,14 @@ public class Conversions { if (enumType.isScoped()) { return false; } - IType fixedType= enumType.getFixedType(); + IType fixedType = enumType.getFixedType(); if (fixedType == null) { if (tKind == Kind.eInt || tKind == Kind.eUnspecified) { if (trg instanceof ICPPBasicType) { int qualifiers = ArithmeticConversion.getEnumIntTypeModifiers((IEnumeration) src); int targetModifiers = ((ICPPBasicType) trg).getModifiers(); - if (qualifiers == (targetModifiers & (IBasicType.IS_LONG | IBasicType.IS_LONG_LONG | IBasicType.IS_SHORT | IBasicType.IS_UNSIGNED))) { + if (qualifiers == (targetModifiers & (IBasicType.IS_LONG | IBasicType.IS_LONG_LONG + | IBasicType.IS_SHORT | IBasicType.IS_UNSIGNED))) { canPromote = true; } } else { @@ -1078,9 +1088,9 @@ public class Conversions { } } else { if (fixedType.isSameType(trg)) - canPromote= true; + canPromote = true; // Allow to further promote the fixed type - src= fixedType; + src = fixedType; } } if (src instanceof IBasicType) { @@ -1091,7 +1101,7 @@ public class Conversions { switch (sKind) { case eInt: // short, and unsigned short if (basicSrc.isShort() && !basicTgt.isUnsigned()) { - canPromote= true; + canPromote = true; } break; case eChar: @@ -1100,13 +1110,13 @@ public class Conversions { case eChar16: case eUnspecified: // treat unspecified as int if (!basicTgt.isUnsigned()) { - canPromote= true; + canPromote = true; } break; case eChar32: if (basicTgt.isUnsigned()) { - canPromote= true; + canPromote = true; } break; default: @@ -1114,7 +1124,7 @@ public class Conversions { } } } else if (tKind == Kind.eDouble && sKind == Kind.eFloat) { - canPromote= true; + canPromote = true; } } } @@ -1173,7 +1183,7 @@ public class Conversions { } if (t instanceof IPointerType) { - IPointerType tgtPtr= (IPointerType) t; + IPointerType tgtPtr = (IPointerType) t; // 4.10-1 an integral constant expression of integer type that evaluates to 0 can // be converted to a pointer type // 4.11-1 same for pointer to member @@ -1185,15 +1195,16 @@ public class Conversions { return false; } if (s instanceof IPointerType) { - IPointerType srcPtr= (IPointerType) s; + IPointerType srcPtr = (IPointerType) s; // 4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be // converted to an rvalue of type "pointer to cv void" - IType tgtPtrTgt= getNestedType(tgtPtr.getType(), TDEF | CVTYPE | REF); + IType tgtPtrTgt = getNestedType(tgtPtr.getType(), TDEF | CVTYPE | REF); if (SemanticUtil.isVoidType(tgtPtrTgt)) { cost.setRank(Rank.CONVERSION); cost.setInheritanceDistance(Short.MAX_VALUE); - CVQualifier cv= getCVQualifier(srcPtr.getType()); - cost.source= new CPPPointerType(addQualifiers(CPPSemantics.VOID_TYPE, cv.isConst(), cv.isVolatile(), cv.isRestrict())); + CVQualifier cv = getCVQualifier(srcPtr.getType()); + cost.source = new CPPPointerType( + addQualifiers(CPPSemantics.VOID_TYPE, cv.isConst(), cv.isVolatile(), cv.isRestrict())); return false; } @@ -1202,9 +1213,9 @@ public class Conversions { if (!tIsPtrToMember && !sIsPtrToMember) { // 4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted // to an rvalue of type "pointer to cv B", where B is a base class of D. - IType srcPtrTgt= getNestedType(srcPtr.getType(), TDEF | CVTYPE | REF); + IType srcPtrTgt = getNestedType(srcPtr.getType(), TDEF | CVTYPE | REF); if (tgtPtrTgt instanceof ICPPClassType && srcPtrTgt instanceof ICPPClassType) { - int depth= SemanticUtil.calculateInheritanceDepth(srcPtrTgt, tgtPtrTgt); + int depth = SemanticUtil.calculateInheritanceDepth(srcPtrTgt, tgtPtrTgt); if (depth == -1) { cost.setRank(Rank.NO_MATCH); return true; @@ -1212,8 +1223,9 @@ public class Conversions { if (depth > 0) { cost.setRank(Rank.CONVERSION); cost.setInheritanceDistance(depth); - CVQualifier cv= getCVQualifier(srcPtr.getType()); - cost.source= new CPPPointerType(addQualifiers(tgtPtrTgt, cv.isConst(), cv.isVolatile(), cv.isRestrict())); + CVQualifier cv = getCVQualifier(srcPtr.getType()); + cost.source = new CPPPointerType( + addQualifiers(tgtPtrTgt, cv.isConst(), cv.isVolatile(), cv.isRestrict())); } return false; } @@ -1235,8 +1247,8 @@ public class Conversions { if (depth > 0) { cost.setRank(Rank.CONVERSION); cost.setInheritanceDistance(depth); - cost.source = new CPPPointerToMemberType(spm.getType(), - tpm.getMemberOfClass(), spm.isConst(), spm.isVolatile(), spm.isRestrict()); + cost.source = new CPPPointerToMemberType(spm.getType(), tpm.getMemberOfClass(), + spm.isConst(), spm.isVolatile(), spm.isRestrict()); } return false; } @@ -1264,14 +1276,14 @@ public class Conversions { * 4.1, 4.2, 4.3 */ public static IType lvalue_to_rvalue(IType type, boolean resolveTypedefs) { - IType t= SemanticUtil.getNestedType(type, TDEF | REF); + IType t = SemanticUtil.getNestedType(type, TDEF | REF); if (t instanceof IArrayType) { return new CPPPointerType(((IArrayType) t).getType()); } if (t instanceof IFunctionType) { return new CPPPointerType(t); } - IType uqType= SemanticUtil.getNestedType(t, TDEF | REF | ALLCVQ); + IType uqType = SemanticUtil.getNestedType(t, TDEF | REF | ALLCVQ); if (uqType instanceof ICPPClassType) { return resolveTypedefs ? t : SemanticUtil.getNestedType(type, COND_TDEF | REF); } @@ -1300,8 +1312,8 @@ public class Conversions { if (!isPtr1 || !isPtr2) return null; - final IPointerType p1= (IPointerType) t1; - final IPointerType p2= (IPointerType) t2; + final IPointerType p1 = (IPointerType) t1; + final IPointerType p2 = (IPointerType) t2; if (haveMemberPtrConflict(p1, p2)) return null; @@ -1314,7 +1326,7 @@ public class Conversions { return addQualifiers(p2, p1.isConst(), p1.isVolatile(), p1.isRestrict()); } - IType t= mergePointers(target1, target2, true, true); + IType t = mergePointers(target1, target2, true, true); if (t == null) return null; if (t == target1) @@ -1325,20 +1337,20 @@ public class Conversions { } private static IType mergePointers(IType t1, IType t2, boolean allcq, boolean allowInheritance) { - t1= getNestedType(t1, TDEF | REF); - t2= getNestedType(t2, TDEF | REF); + t1 = getNestedType(t1, TDEF | REF); + t2 = getNestedType(t2, TDEF | REF); if (t1 instanceof IPointerType && t2 instanceof IPointerType) { final IPointerType p1 = (IPointerType) t1; final IPointerType p2 = (IPointerType) t2; - final CVQualifier cv1= getCVQualifier(t1); - final CVQualifier cv2= getCVQualifier(t2); + final CVQualifier cv1 = getCVQualifier(t1); + final CVQualifier cv2 = getCVQualifier(t2); if (haveMemberPtrConflict(p1, p2)) return null; if (!allcq && cv1 != cv2) return null; final IType p1target = p1.getType(); - IType merged= mergePointers(p1target, p2.getType(), allcq && (cv1.isConst() || cv2.isConst()), false); + IType merged = mergePointers(p1target, p2.getType(), allcq && (cv1.isConst() || cv2.isConst()), false); if (merged == null) return null; if (p1target == merged && cv1.isAtLeastAsQualifiedAs(cv2)) @@ -1349,8 +1361,8 @@ public class Conversions { return copyPointer(p1, merged, cv1.isConst() || cv2.isConst(), cv1.isVolatile() || cv2.isVolatile()); } - final IType uq1= getNestedType(t1, TDEF|REF|CVTYPE); - final IType uq2= getNestedType(t2, TDEF|REF|CVTYPE); + final IType uq1 = getNestedType(t1, TDEF | REF | CVTYPE); + final IType uq2 = getNestedType(t2, TDEF | REF | CVTYPE); if (uq1 == null) { return null; } @@ -1359,8 +1371,8 @@ public class Conversions { if (uq1 == t1 && uq2 == t2) return t1; - CVQualifier cv1= getCVQualifier(t1); - CVQualifier cv2= getCVQualifier(t2); + CVQualifier cv1 = getCVQualifier(t1); + CVQualifier cv2 = getCVQualifier(t2); if (cv1 == cv2) return t1; @@ -1384,8 +1396,8 @@ public class Conversions { } else { return null; } - CVQualifier cv1= getCVQualifier(t1); - CVQualifier cv2= getCVQualifier(t2); + CVQualifier cv1 = getCVQualifier(t1); + CVQualifier cv2 = getCVQualifier(t2); if (cv1 == CVQualifier.NONE && cv2 == CVQualifier.NONE) { return base; } @@ -1397,7 +1409,7 @@ public class Conversions { public static IType copyPointer(final IPointerType p1, IType target, final boolean isConst, final boolean isVolatile) { if (p1 instanceof ICPPPointerToMemberType) { - ICPPPointerToMemberType ptm= (ICPPPointerToMemberType) p1; + ICPPPointerToMemberType ptm = (ICPPPointerToMemberType) p1; return new CPPPointerToMemberType(target, ptm.getMemberOfClass(), isConst, isVolatile, false); } return new CPPPointerType(target, isConst, isVolatile, false); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java index 95f8b675ea1..e3e312b05d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java @@ -37,10 +37,11 @@ public class Cost { public enum DeferredUDC { NONE, COPY_INIT_OF_CLASS, INIT_BY_CONVERSION, LIST_INIT_OF_CLASS, DIRECT_LIST_INIT_OF_CLASS } + public enum Rank { - IDENTITY, PROMOTION, CONVERSION, CONVERSION_PTR_BOOL, - USER_DEFINED_CONVERSION, ELLIPSIS_CONVERSION, NO_MATCH + IDENTITY, PROMOTION, CONVERSION, CONVERSION_PTR_BOOL, USER_DEFINED_CONVERSION, ELLIPSIS_CONVERSION, NO_MATCH } + enum ReferenceBinding { RVALUE_REF_BINDS_RVALUE, LVALUE_REF, OTHER_REF, NO_REF } @@ -50,34 +51,42 @@ public class Cost { public void setRank(Rank rank) { assert false; } + @Override public void setReferenceBinding(ReferenceBinding binding) { assert false; } + @Override public void setAmbiguousUDC(boolean val) { assert false; } + @Override public void setDeferredUDC(DeferredUDC val) { assert false; } + @Override public void setInheritanceDistance(int inheritanceDistance) { assert false; } + @Override public void setQualificationAdjustment(int adjustment) { assert false; } + @Override public void setUserDefinedConversion(ICPPMethod conv) { assert false; } + @Override public void setCouldNarrow() { assert false; } + @Override public void setSelectedFunction(ICPPFunction function) { assert false; @@ -90,7 +99,7 @@ public class Cost { private Rank fRank; private Rank fSecondStandardConversionRank; private boolean fAmbiguousUDC; - private DeferredUDC fDeferredUDC= DeferredUDC.NONE; + private DeferredUDC fDeferredUDC = DeferredUDC.NONE; private int fQualificationAdjustments; private int fInheritanceDistance; private boolean fImpliedObject; @@ -110,8 +119,8 @@ public class Cost { public Cost(IType s, IType t, Rank rank) { source = s; target = t; - fRank= rank; - fReferenceBinding= ReferenceBinding.NO_REF; + fRank = rank; + fReferenceBinding = ReferenceBinding.NO_REF; } public final Rank getRank() { @@ -123,7 +132,7 @@ public class Cost { } public void setRank(Rank rank) { - fRank= rank; + fRank = rank; } public ReferenceBinding getReferenceBinding() { @@ -131,7 +140,7 @@ public class Cost { } public void setReferenceBinding(ReferenceBinding binding) { - fReferenceBinding= binding; + fReferenceBinding = binding; } public boolean isAmbiguousUDC() { @@ -139,7 +148,7 @@ public class Cost { } public void setAmbiguousUDC(boolean val) { - fAmbiguousUDC= val; + fAmbiguousUDC = val; } public DeferredUDC isDeferredUDC() { @@ -147,7 +156,7 @@ public class Cost { } public void setDeferredUDC(DeferredUDC udc) { - fDeferredUDC= udc; + fDeferredUDC = udc; } public int getInheritanceDistance() { @@ -159,7 +168,7 @@ public class Cost { } public void setQualificationAdjustment(int adjustment) { - fQualificationAdjustments= adjustment; + fQualificationAdjustments = adjustment; } /** @@ -167,10 +176,10 @@ public class Cost { * implicit conversion sequence. */ public void setUserDefinedConversion(ICPPMethod conv) { - fUserDefinedConversion= conv; - fSecondStandardConversionRank= fRank; - fRank= Rank.USER_DEFINED_CONVERSION; - fCouldNarrow= false; + fUserDefinedConversion = conv; + fSecondStandardConversionRank = fRank; + fRank = Rank.USER_DEFINED_CONVERSION; + fCouldNarrow = false; } /** @@ -188,17 +197,17 @@ public class Cost { // 7.3.3.13 (using declarations in classes): // for overload resolution the implicit this pointer // is treated as if it were a pointer to the derived class - final boolean ignoreInheritanceDist= fImpliedObject && other.fImpliedObject; + final boolean ignoreInheritanceDist = fImpliedObject && other.fImpliedObject; Rank rank = fRank; Rank otherRank = other.fRank; if (ignoreInheritanceDist) { if (rank == Rank.CONVERSION) - rank= Rank.IDENTITY; + rank = Rank.IDENTITY; if (otherRank == Rank.CONVERSION) - otherRank= Rank.IDENTITY; + otherRank = Rank.IDENTITY; } - int cmp= rank.compareTo(otherRank); + int cmp = rank.compareTo(otherRank); if (cmp != 0) return cmp; @@ -218,7 +227,8 @@ public class Cost { // - L1 converts to type "array of N1 T", L2 converts to type "array of // N2 T", and N1 is smaller than N2 - if (fListInitializationTarget instanceof IArrayType && other.fListInitializationTarget instanceof IArrayType) { + if (fListInitializationTarget instanceof IArrayType + && other.fListInitializationTarget instanceof IArrayType) { IArrayType arrayType = (IArrayType) fListInitializationTarget; IArrayType otherArrayType = (IArrayType) other.fListInitializationTarget; if (arrayType.getType().isSameType(otherArrayType.getType())) { @@ -240,17 +250,16 @@ public class Cost { return 0; if (fUserDefinedConversion != other.fUserDefinedConversion) { - if (fUserDefinedConversion == null || - !fUserDefinedConversion.equals(other.fUserDefinedConversion)) + if (fUserDefinedConversion == null || !fUserDefinedConversion.equals(other.fUserDefinedConversion)) return 0; } - cmp= fSecondStandardConversionRank.compareTo(other.fSecondStandardConversionRank); + cmp = fSecondStandardConversionRank.compareTo(other.fSecondStandardConversionRank); if (cmp != 0) return cmp; } if (!ignoreInheritanceDist) { - cmp= fInheritanceDistance - other.fInheritanceDistance; + cmp = fInheritanceDistance - other.fInheritanceDistance; if (cmp != 0) return cmp; } @@ -264,7 +273,7 @@ public class Cost { } // Top level cv-qualifiers are compared only for reference bindings. - int qdiff= fQualificationAdjustments ^ other.fQualificationAdjustments; + int qdiff = fQualificationAdjustments ^ other.fQualificationAdjustments; if (fReferenceBinding == ReferenceBinding.NO_REF || other.fReferenceBinding == ReferenceBinding.NO_REF) qdiff &= ~7; @@ -281,24 +290,24 @@ public class Cost { @SuppressWarnings("nls") @Override public String toString() { - StringBuilder buf= new StringBuilder(); - String comma= ""; + StringBuilder buf = new StringBuilder(); + String comma = ""; buf.append(fRank).append('['); if (fQualificationAdjustments != 0) { buf.append(comma).append("qualification=").append(fQualificationAdjustments); - comma= ", "; + comma = ", "; } if (fInheritanceDistance != 0) { buf.append(comma).append("inheritance=").append(fInheritanceDistance); - comma= ", "; + comma = ", "; } if (fDeferredUDC != DeferredUDC.NONE) { buf.append(comma).append(fDeferredUDC); - comma= ", "; + comma = ", "; } if (fAmbiguousUDC) { buf.append(comma).append("ambiguous UDC"); - comma= ", "; + comma = ", "; } if (fSecondStandardConversionRank != null) { buf.append(comma).append("2ndConvRank=").append(fSecondStandardConversionRank); @@ -331,9 +340,9 @@ public class Cost { basicSource = (CPPBasicType) fixedType; } } - if (basicSource == null) { // C enumeration or no fixed type - return !ArithmeticConversion.fitsIntoType(basicTarget, enumSource.getMinValue()) || - !ArithmeticConversion.fitsIntoType(basicTarget, enumSource.getMaxValue()); + if (basicSource == null) { // C enumeration or no fixed type + return !ArithmeticConversion.fitsIntoType(basicTarget, enumSource.getMinValue()) + || !ArithmeticConversion.fitsIntoType(basicTarget, enumSource.getMaxValue()); } } @@ -348,17 +357,15 @@ public class Cost { if (BuiltinOperators.isFloatingPoint(basicSource) && BuiltinOperators.isIntegral(basicTarget)) { // From a floating-point type to an integer type return true; - } else if (basicSource.getKind() == Kind.eDouble - && (basicTarget.getKind() == Kind.eFloat - || (basicTarget.getKind() == Kind.eDouble && !basicTarget.isLong() && basicSource.isLong()))) { + } else if (basicSource.getKind() == Kind.eDouble && (basicTarget.getKind() == Kind.eFloat + || (basicTarget.getKind() == Kind.eDouble && !basicTarget.isLong() && basicSource.isLong()))) { // From long double to double or float, or from double to float constantExprExceptionApplies = true; } else if (BuiltinOperators.isIntegral(basicSource) && BuiltinOperators.isFloatingPoint(basicTarget)) { // From an integer type or unscoped enumeration type to a floating-point type constantExprExceptionApplies = true; - } else if (BuiltinOperators.isIntegral(basicSource) - && BuiltinOperators.isIntegral(basicTarget) - && !ArithmeticConversion.fitsIntoType(basicTarget, basicSource)) { + } else if (BuiltinOperators.isIntegral(basicSource) && BuiltinOperators.isIntegral(basicTarget) + && !ArithmeticConversion.fitsIntoType(basicTarget, basicSource)) { // From an integer type or unscoped enumeration type to an integer type that // cannot represent all the values of the original type constantExprExceptionApplies = true; @@ -373,7 +380,7 @@ public class Cost { } public void setCouldNarrow() { - fCouldNarrow= true; + fCouldNarrow = true; } public ICPPFunction getUserDefinedConversion() { @@ -384,7 +391,7 @@ public class Cost { * Stores a selected function. Used when resolving targeted functions. */ public void setSelectedFunction(ICPPFunction function) { - fSelectedFunction= function; + fSelectedFunction = function; } public ICPPFunction getSelectedFunction() { @@ -392,7 +399,7 @@ public class Cost { } public void setImpliedObject() { - fImpliedObject= true; + fImpliedObject = true; } public void setListInitializationTarget(IType target) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/DestructorCallCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/DestructorCallCollector.java index bf153c441cc..0e7f4442360 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/DestructorCallCollector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/DestructorCallCollector.java @@ -81,8 +81,8 @@ public class DestructorCallCollector { public static IASTImplicitDestructorName[] getLocalVariablesDestructorCalls(IASTStatement statement) { if (!(statement instanceof IASTImplicitDestructorNameOwner)) return IASTImplicitDestructorName.EMPTY_NAME_ARRAY; - LocalVariablesDestructorCollector collector = - new LocalVariablesDestructorCollector((IASTImplicitDestructorNameOwner) statement); + LocalVariablesDestructorCollector collector = new LocalVariablesDestructorCollector( + (IASTImplicitDestructorNameOwner) statement); statement.accept(collector); return collector.getDestructorCalls(); } @@ -109,13 +109,13 @@ public class DestructorCallCollector { } protected void addDestructorCall(IASTName name, ICPPMethod destructor) { - CPPASTImplicitDestructorName destructorName = - new CPPASTImplicitDestructorName(destructor.getNameCharArray(), owner, name); + CPPASTImplicitDestructorName destructorName = new CPPASTImplicitDestructorName( + destructor.getNameCharArray(), owner, name); destructorName.setBinding(destructor); ASTNode parentNode = (ASTNode) owner; int offset = parentNode.getOffset() + parentNode.getLength(); if (!(owner instanceof ICPPASTExpression)) - offset--; // Before the closing brace. + offset--; // Before the closing brace. destructorName.setOffsetAndLength(offset, 0); destructorNames = ArrayUtil.prepend(destructorNames, destructorName); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java index cf25674e5c5..3f8522e833c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java @@ -91,13 +91,13 @@ import org.eclipse.core.runtime.IStatus; * Performs evaluation of an expression. */ public class EvalBinary extends CPPDependentEvaluation { - public final static int op_arrayAccess= Byte.MAX_VALUE; + public final static int op_arrayAccess = Byte.MAX_VALUE; private final int fOperator; private final ICPPEvaluation fArg1; private final ICPPEvaluation fArg2; - private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION; + private ICPPFunction fOverload = CPPFunction.UNINITIALIZED_FUNCTION; private ICPPEvaluation fOverloadCall; private IType fType; private boolean fCheckedIsConstantExpression; @@ -109,9 +109,9 @@ public class EvalBinary extends CPPDependentEvaluation { public EvalBinary(int operator, ICPPEvaluation arg1, ICPPEvaluation arg2, IBinding templateDefinition) { super(templateDefinition); - fOperator= operator; - fArg1= arg1; - fArg2= arg2; + fOperator = operator; + fArg1 = arg1; + fArg2 = arg2; } public int getOperator() { @@ -140,30 +140,32 @@ public class EvalBinary extends CPPDependentEvaluation { public IType getType() { if (fType == null) { if (isTypeDependent()) { - fType= new TypeOfDependentExpression(this); + fType = new TypeOfDependentExpression(this); } else { ICPPFunction overload = getOverload(); if (overload != null) { - fType= ExpressionTypes.restoreTypedefs( - ExpressionTypes.typeFromFunctionCall(overload), fArg1.getType(), fArg2.getType()); + fType = ExpressionTypes.restoreTypedefs(ExpressionTypes.typeFromFunctionCall(overload), + fArg1.getType(), fArg2.getType()); } else { - fType= computeType(); + fType = computeType(); } } } return fType; } - private ICPPEvaluation createOperatorOverloadEvaluation(ICPPFunction overload, ICPPEvaluation arg1, ICPPEvaluation arg2) { + private ICPPEvaluation createOperatorOverloadEvaluation(ICPPFunction overload, ICPPEvaluation arg1, + ICPPEvaluation arg2) { EvalFunctionCall operatorCall; IASTNode point = CPPSemantics.getCurrentLookupPoint(); if (overload instanceof ICPPMethod) { - EvalMemberAccess opAccess = new EvalMemberAccess(arg1.getType(), ValueCategory.LVALUE, overload, arg1, false, point); - ICPPEvaluation[] args = new ICPPEvaluation[]{opAccess, arg2}; + EvalMemberAccess opAccess = new EvalMemberAccess(arg1.getType(), ValueCategory.LVALUE, overload, arg1, + false, point); + ICPPEvaluation[] args = new ICPPEvaluation[] { opAccess, arg2 }; operatorCall = new EvalFunctionCall(args, arg1, point); } else { EvalBinding op = new EvalBinding(overload, overload.getType(), point); - ICPPEvaluation[] args = new ICPPEvaluation[]{op, arg1, arg2}; + ICPPEvaluation[] args = new ICPPEvaluation[] { op, arg1, arg2 }; operatorCall = new EvalFunctionCall(args, null, point); } return operatorCall; @@ -186,7 +188,7 @@ public class EvalBinary extends CPPDependentEvaluation { arg2 = maybeApplyConversion(fArg2, parameterTypes[1], allowContextualConversion); } else { CCorePlugin.log(IStatus.ERROR, "Unexpected overload for binary operator " + fOperator //$NON-NLS-1$ - + ": '" + overload.getName() + "'"); //$NON-NLS-1$//$NON-NLS-2$ + + ": '" + overload.getName() + "'"); //$NON-NLS-1$//$NON-NLS-2$ } if (!(overload instanceof CPPImplicitFunction)) { @@ -259,22 +261,18 @@ public class EvalBinary extends CPPDependentEvaluation { } return fIsConstantExpression; } - + @Override public boolean isEquivalentTo(ICPPEvaluation other) { if (!(other instanceof EvalBinary)) { return false; } EvalBinary o = (EvalBinary) other; - return fOperator == o.fOperator - && fArg1.isEquivalentTo(o.fArg1) - && fArg2.isEquivalentTo(o.fArg2); + return fOperator == o.fOperator && fArg1.isEquivalentTo(o.fArg1) && fArg2.isEquivalentTo(o.fArg2); } private boolean computeIsConstantExpression() { - return fArg1.isConstantExpression() - && fArg2.isConstantExpression() - && isNullOrConstexprFunc(getOverload()); + return fArg1.isConstantExpression() && fArg2.isConstantExpression() && isNullOrConstexprFunc(getOverload()); } @Override @@ -317,7 +315,7 @@ public class EvalBinary extends CPPDependentEvaluation { public ICPPFunction getOverload() { if (fOverload == CPPFunction.UNINITIALIZED_FUNCTION) { - fOverload= computeOverload(); + fOverload = computeOverload(); } return fOverload; } @@ -328,24 +326,23 @@ public class EvalBinary extends CPPDependentEvaluation { if (fOperator == op_arrayAccess) { IType type = fArg1.getType(); - type= SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); - if (type instanceof ICPPClassType) { - return CPPSemantics.findOverloadedBinaryOperator(getTemplateDefinitionScope(), - OverloadableOperator.BRACKET, fArg1, fArg2); - } + type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); + if (type instanceof ICPPClassType) { + return CPPSemantics.findOverloadedBinaryOperator(getTemplateDefinitionScope(), + OverloadableOperator.BRACKET, fArg1, fArg2); + } } else { final OverloadableOperator op = OverloadableOperator.fromBinaryExpression(fOperator); if (op != null) { - return CPPSemantics.findOverloadedBinaryOperator(getTemplateDefinitionScope(), - op, fArg1, fArg2); + return CPPSemantics.findOverloadedBinaryOperator(getTemplateDefinitionScope(), op, fArg1, fArg2); } } - return null; + return null; } public IType computeType() { // Check for overloaded operator. - ICPPFunction o= getOverload(); + ICPPFunction o = getOverload(); if (o != null) return typeFromFunctionCall(o); @@ -355,69 +352,69 @@ public class EvalBinary extends CPPDependentEvaluation { return type1; } - final IType originalType2 = fArg2.getType(); + final IType originalType2 = fArg2.getType(); final IType type2 = prvalueTypeWithResolvedTypedefs(originalType2); if (type2 instanceof ISemanticProblem) { return type2; } - IType type= CPPArithmeticConversion.convertCppOperandTypes(fOperator, type1, type2); - if (type != null) { - return ExpressionTypes.restoreTypedefs(type, originalType1, originalType2); - } - - switch (fOperator) { - case op_arrayAccess: - if (type1 instanceof IPointerType) { - return glvalueType(((IPointerType) type1).getType()); - } - if (type2 instanceof IPointerType) { - return glvalueType(((IPointerType) type2).getType()); - } - return ProblemType.UNKNOWN_FOR_EXPRESSION; - - case op_lessEqual: - case op_lessThan: - case op_greaterEqual: - case op_greaterThan: - case op_logicalAnd: - case op_logicalOr: - case op_equals: - case op_notequals: - return CPPBasicType.BOOLEAN; - - case op_plus: - if (type1 instanceof IPointerType) { - return ExpressionTypes.restoreTypedefs(type1, originalType1); - } - if (type2 instanceof IPointerType) { - return ExpressionTypes.restoreTypedefs(type2, originalType2); - } - break; - - case op_minus: - if (type1 instanceof IPointerType) { - if (type2 instanceof IPointerType) { - return CPPVisitor.getPointerDiffType(); - } - return originalType1; - } - break; - - case op_pmarrow: - case op_pmdot: - if (type2 instanceof ICPPPointerToMemberType) { - IType t= ((ICPPPointerToMemberType) type2).getType(); - if (t instanceof ICPPFunctionType) - return t; - if (fOperator == op_pmdot && fArg1.getValueCategory() == PRVALUE) { - return prvalueType(t); - } - return glvalueType(t); - } - return ProblemType.UNKNOWN_FOR_EXPRESSION; - } - return type1; + IType type = CPPArithmeticConversion.convertCppOperandTypes(fOperator, type1, type2); + if (type != null) { + return ExpressionTypes.restoreTypedefs(type, originalType1, originalType2); + } + + switch (fOperator) { + case op_arrayAccess: + if (type1 instanceof IPointerType) { + return glvalueType(((IPointerType) type1).getType()); + } + if (type2 instanceof IPointerType) { + return glvalueType(((IPointerType) type2).getType()); + } + return ProblemType.UNKNOWN_FOR_EXPRESSION; + + case op_lessEqual: + case op_lessThan: + case op_greaterEqual: + case op_greaterThan: + case op_logicalAnd: + case op_logicalOr: + case op_equals: + case op_notequals: + return CPPBasicType.BOOLEAN; + + case op_plus: + if (type1 instanceof IPointerType) { + return ExpressionTypes.restoreTypedefs(type1, originalType1); + } + if (type2 instanceof IPointerType) { + return ExpressionTypes.restoreTypedefs(type2, originalType2); + } + break; + + case op_minus: + if (type1 instanceof IPointerType) { + if (type2 instanceof IPointerType) { + return CPPVisitor.getPointerDiffType(); + } + return originalType1; + } + break; + + case op_pmarrow: + case op_pmdot: + if (type2 instanceof ICPPPointerToMemberType) { + IType t = ((ICPPPointerToMemberType) type2).getType(); + if (t instanceof ICPPFunctionType) + return t; + if (fOperator == op_pmdot && fArg1.getValueCategory() == PRVALUE) { + return prvalueType(t); + } + return glvalueType(t); + } + return ProblemType.UNKNOWN_FOR_EXPRESSION; + } + return type1; } @Override @@ -430,10 +427,10 @@ public class EvalBinary extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - int op= buffer.getByte(); - ICPPEvaluation arg1= buffer.unmarshalEvaluation(); - ICPPEvaluation arg2= buffer.unmarshalEvaluation(); - IBinding templateDefinition= buffer.unmarshalBinding(); + int op = buffer.getByte(); + ICPPEvaluation arg1 = buffer.unmarshalEvaluation(); + ICPPEvaluation arg2 = buffer.unmarshalEvaluation(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalBinary(op, arg1, arg2, templateDefinition); } @@ -459,7 +456,8 @@ public class EvalBinary extends CPPDependentEvaluation { final ICPPEvaluation fixed1 = vp1.getSecond(); Pair<ICPPEvaluation, ICPPEvaluation> vp2 = EvalUtil.getValuePair(fArg2, record, context); final ICPPEvaluation fixed2 = vp2.getSecond(); - ICPPEvaluation eval = fixed1 == fArg1 && fixed2 == fArg2 ? this : new EvalBinary(fOperator, fixed1, fixed2, getTemplateDefinition()); + ICPPEvaluation eval = fixed1 == fArg1 && fixed2 == fArg2 ? this + : new EvalBinary(fOperator, fixed1, fixed2, getTemplateDefinition()); if (isBinaryOperationWithAssignment(fOperator)) { if (isPointerToArray(fixed1) && hasIntType(fixed2)) { @@ -479,7 +477,8 @@ public class EvalBinary extends CPPDependentEvaluation { return EvalFixed.INCOMPLETE; int binaryOperator = getBinaryOperatorWithoutAssignment(fOperator); EvalBinary binaryOpEval = new EvalBinary(binaryOperator, fixed1, fixed2, getTemplateDefinition()); - EvalBinary assignmentEval = new EvalBinary(op_assign, updateable1, binaryOpEval, getTemplateDefinition()); + EvalBinary assignmentEval = new EvalBinary(op_assign, updateable1, binaryOpEval, + getTemplateDefinition()); return assignmentEval.computeForFunctionCall(record, context); } } else if (fOperator == op_assign) { @@ -519,11 +518,15 @@ public class EvalBinary extends CPPDependentEvaluation { } return new EvalCompositeAccess(composite, arrayIndex); } else if ((isArray(fixed1) || isArray(fixed2)) && (hasIntType(fixed1) || hasIntType(fixed2))) { - int offset = hasIntType(fixed1) ? fixed1.getValue().numberValue().intValue() : fixed2.getValue().numberValue().intValue(); - EvalCompositeAccess evalCompositeAccess = new EvalCompositeAccess(isArray(fixed1) ? fixed1 : fixed2, offset); + int offset = hasIntType(fixed1) ? fixed1.getValue().numberValue().intValue() + : fixed2.getValue().numberValue().intValue(); + EvalCompositeAccess evalCompositeAccess = new EvalCompositeAccess(isArray(fixed1) ? fixed1 : fixed2, + offset); return new EvalPointer(record, evalCompositeAccess, evalCompositeAccess.getTemplateDefinition()); - } else if ((isPointerToArray(fixed1) || isPointerToArray(fixed2)) && (hasIntType(fixed1) || hasIntType(fixed2))) { - final EvalPointer pointer = isPointerToArray(fixed1) ? ((EvalPointer) fixed1).copy() : ((EvalPointer) fixed2).copy(); + } else if ((isPointerToArray(fixed1) || isPointerToArray(fixed2)) + && (hasIntType(fixed1) || hasIntType(fixed2))) { + final EvalPointer pointer = isPointerToArray(fixed1) ? ((EvalPointer) fixed1).copy() + : ((EvalPointer) fixed2).copy(); pointer.setPosition(eval.getValue().numberValue().intValue()); return pointer; } @@ -551,46 +554,46 @@ public class EvalBinary extends CPPDependentEvaluation { private static boolean isBinaryOperationWithAssignment(int operator) { switch (operator) { - case op_binaryAndAssign: - case op_binaryOrAssign: - case op_binaryXorAssign: - case op_divideAssign: - case op_plusAssign: - case op_minusAssign: - case op_multiplyAssign: - case op_moduloAssign: - case op_shiftLeftAssign: - case op_shiftRightAssign: - return true; - default: - return false; + case op_binaryAndAssign: + case op_binaryOrAssign: + case op_binaryXorAssign: + case op_divideAssign: + case op_plusAssign: + case op_minusAssign: + case op_multiplyAssign: + case op_moduloAssign: + case op_shiftLeftAssign: + case op_shiftRightAssign: + return true; + default: + return false; } } private static int getBinaryOperatorWithoutAssignment(int operator) { switch (operator) { - case op_binaryAndAssign: - return op_binaryAnd; - case op_binaryOrAssign: - return op_binaryOr; - case op_binaryXorAssign: - return op_binaryXor; - case op_divideAssign: - return op_divide; - case op_plusAssign: - return op_plus; - case op_minusAssign: - return op_minus; - case op_multiplyAssign: - return op_multiply; - case op_moduloAssign: - return op_modulo; - case op_shiftLeftAssign: - return op_shiftLeft; - case op_shiftRightAssign: - return op_shiftRight; - default: - throw new IllegalArgumentException("Operator must be binary operation with assignment"); //$NON-NLS-1$ + case op_binaryAndAssign: + return op_binaryAnd; + case op_binaryOrAssign: + return op_binaryOr; + case op_binaryXorAssign: + return op_binaryXor; + case op_divideAssign: + return op_divide; + case op_plusAssign: + return op_plus; + case op_minusAssign: + return op_minus; + case op_multiplyAssign: + return op_multiply; + case op_moduloAssign: + return op_modulo; + case op_shiftLeftAssign: + return op_shiftLeft; + case op_shiftRightAssign: + return op_shiftRight; + default: + throw new IllegalArgumentException("Operator must be binary operation with assignment"); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java index d433214c038..46202d4b114 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java @@ -48,9 +48,9 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation { public EvalBinaryTypeId(Operator kind, IType type1, IType type2, IBinding templateDefinition) { super(templateDefinition); - fOperator= kind; - fType1= type1; - fType2= type2; + fOperator = kind; + fType1 = type1; + fType2 = type2; } public Operator getOperator() { @@ -101,8 +101,8 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation { @Override public boolean isValueDependent() { if (!fCheckedValueDependent) { - fIsValueDependent= CPPTemplates.isDependentType(fType1) || CPPTemplates.isDependentType(fType2); - fCheckedValueDependent= true; + fIsValueDependent = CPPTemplates.isDependentType(fType1) || CPPTemplates.isDependentType(fType2); + fCheckedValueDependent = true; } return fIsValueDependent; } @@ -111,16 +111,14 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation { public boolean isConstantExpression() { return true; } - + @Override public boolean isEquivalentTo(ICPPEvaluation other) { if (!(other instanceof EvalBinaryTypeId)) { return false; } EvalBinaryTypeId o = (EvalBinaryTypeId) other; - return fOperator == o.fOperator - && fType1.isSameType(o.fType1) - && fType2.isSameType(o.fType2); + return fOperator == o.fOperator && fType1.isSameType(o.fType1) && fType2.isSameType(o.fType2); } @Override @@ -138,10 +136,10 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - int op= buffer.getByte(); - IType arg1= buffer.unmarshalType(); - IType arg2= buffer.unmarshalType(); - IBinding templateDefinition= buffer.unmarshalBinding(); + int op = buffer.getByte(); + IType arg1 = buffer.unmarshalType(); + IType arg2 = buffer.unmarshalType(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalBinaryTypeId(Operator.values()[op], arg1, arg2, templateDefinition); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index 2aca5f4dfcf..39f4eb38d6c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -68,8 +68,8 @@ public class EvalBinding extends CPPDependentEvaluation { private int fParameterPosition; /** * The binding represented by this evaluation. For a function parameter binding may be computed - * lazily to avoid infinite recursion during unmarshalling of the evaluation. If - * {@link #fBinding} is {@code null}, {@link #fParameterOwner} is guaranteed to be not {@code null} + * lazily to avoid infinite recursion during unmarshalling of the evaluation. If + * {@link #fBinding} is {@code null}, {@link #fParameterOwner} is guaranteed to be not {@code null} * and vice versa. */ private IBinding fBinding; @@ -90,9 +90,9 @@ public class EvalBinding extends CPPDependentEvaluation { public EvalBinding(IBinding binding, IType type, IBinding templateDefinition) { super(templateDefinition); fParameterPosition = -1; - fBinding= binding; - fType= type; - fFixedType= type != null; + fBinding = binding; + fType = type; + fFixedType = type != null; } public EvalBinding(ICPPFunction parameterOwner, int parameterPosition, IType type, IASTNode pointOfDefinition) { @@ -103,8 +103,8 @@ public class EvalBinding extends CPPDependentEvaluation { super(templateDefinition); fParameterOwner = parameterOwner; fParameterPosition = parameterPosition; - fType= type; - fFixedType= type != null; + fType = type; + fFixedType = type != null; } public IBinding getBinding() { @@ -169,8 +169,7 @@ public class EvalBinding extends CPPDependentEvaluation { public int getTemplateParameterID() { // No need to call getBinding method since fBinding cannot be null if the evaluation // represents a template parameter. - return fBinding instanceof ICPPTemplateParameter ? - ((ICPPTemplateParameter) fBinding).getParameterID() : -1; + return fBinding instanceof ICPPTemplateParameter ? ((ICPPTemplateParameter) fBinding).getParameterID() : -1; } public IType getFixedType() { @@ -187,31 +186,31 @@ public class EvalBinding extends CPPDependentEvaluation { return false; } - @Override - public boolean isTypeDependent() { + @Override + public boolean isTypeDependent() { if (!fCheckedIsTypeDependent) { - fCheckedIsTypeDependent= true; - fIsTypeDependent= computeIsTypeDependent(); + fCheckedIsTypeDependent = true; + fIsTypeDependent = computeIsTypeDependent(); } return fIsTypeDependent; - } + } private boolean computeIsTypeDependent() { - IType t= null; + IType t = null; if (fFixedType) { t = fType; - } else { + } else { IBinding binding = getBinding(); if (binding instanceof IEnumerator) { - t= ((IEnumerator) binding).getType(); + t = ((IEnumerator) binding).getType(); } else if (binding instanceof ICPPTemplateNonTypeParameter) { - t= ((ICPPTemplateNonTypeParameter) binding).getType(); + t = ((ICPPTemplateNonTypeParameter) binding).getType(); } else if (binding instanceof IVariable) { t = ((IVariable) binding).getType(); } else if (binding instanceof ICPPUnknownBinding) { return true; } else if (binding instanceof IFunction) { - t= ((IFunction) binding).getType(); + t = ((IFunction) binding).getType(); } else { return false; } @@ -219,17 +218,17 @@ public class EvalBinding extends CPPDependentEvaluation { return CPPTemplates.isDependentType(t); } - @Override - public boolean isValueDependent() { + @Override + public boolean isValueDependent() { if (!fCheckedIsValueDependent) { - fCheckedIsValueDependent= true; - fIsValueDependent= computeIsValueDependent(); + fCheckedIsValueDependent = true; + fIsValueDependent = computeIsValueDependent(); } return fIsValueDependent; - } + } - private boolean computeIsValueDependent() { - // No need to call getBinding() since a function parameter never has an initial value. + private boolean computeIsValueDependent() { + // No need to call getBinding() since a function parameter never has an initial value. if (fBinding instanceof IEnumerator) { return IntegralValue.isDependentValue(((IEnumerator) fBinding).getValue()); } @@ -258,9 +257,8 @@ public class EvalBinding extends CPPDependentEvaluation { } private boolean computeIsConstantExpression() { - return fBinding instanceof IEnumerator - || fBinding instanceof ICPPFunction - || (fBinding instanceof IVariable && isConstexprValue(((IVariable) fBinding).getInitialValue())); + return fBinding instanceof IEnumerator || fBinding instanceof ICPPFunction + || (fBinding instanceof IVariable && isConstexprValue(((IVariable) fBinding).getInitialValue())); } @Override @@ -272,14 +270,13 @@ public class EvalBinding extends CPPDependentEvaluation { if (fBinding != null) { return fBinding == o.fBinding; } - return fParameterOwner == o.fParameterOwner - && fParameterPosition == o.fParameterPosition; + return fParameterOwner == o.fParameterOwner && fParameterPosition == o.fParameterPosition; } - + @Override public IType getType() { if (fType == null) { - fType= computeType(); + fType = computeType(); } return fType; } @@ -290,7 +287,7 @@ public class EvalBinding extends CPPDependentEvaluation { return ((IEnumerator) binding).getType(); } if (binding instanceof ICPPTemplateNonTypeParameter) { - IType type= ((ICPPTemplateNonTypeParameter) binding).getType(); + IType type = ((ICPPTemplateNonTypeParameter) binding).getType(); // If the binding is a non-type parameter pack, it must have been // referenced from inside the expansion pattern of a pack expansion. // In such a context, the type of the binding is the type of each @@ -302,8 +299,8 @@ public class EvalBinding extends CPPDependentEvaluation { if (binding instanceof IVariable) { IType type = ((IVariable) binding).getType(); IASTNode point = CPPSemantics.getCurrentLookupPoint(); - if (type instanceof IArrayType && ((IArrayType) type).getSize() == null && - binding instanceof IIndexBinding && point != null) { + if (type instanceof IArrayType && ((IArrayType) type).getSize() == null && binding instanceof IIndexBinding + && point != null) { // Refine the type of the array variable by filling in missing size information. // This may be necessary if the variable is declared outside of the current // translation unit without providing array size information, but is defined in @@ -346,16 +343,15 @@ public class EvalBinding extends CPPDependentEvaluation { if (isValueDependent()) return DependentValue.create(this); - IValue value= null; + IValue value = null; if (fBinding instanceof ICPPVariable) { - ICPPEvaluation valueEval = EvalUtil.getVariableValue((ICPPVariable) fBinding, - new ActivationRecord()); + ICPPEvaluation valueEval = EvalUtil.getVariableValue((ICPPVariable) fBinding, new ActivationRecord()); if (valueEval != null) { value = valueEval.getValue(); } } else if (fBinding instanceof IEnumerator) { - value= ((IEnumerator) fBinding).getValue(); + value = ((IEnumerator) fBinding).getValue(); } if (value == null) value = IntegralValue.UNKNOWN; @@ -365,10 +361,10 @@ public class EvalBinding extends CPPDependentEvaluation { @Override public ValueCategory getValueCategory() { - if (fBinding instanceof ICPPTemplateNonTypeParameter) - return ValueCategory.PRVALUE; + if (fBinding instanceof ICPPTemplateNonTypeParameter) + return ValueCategory.PRVALUE; - // fBinding can be null only when the evaluation represents a function parameter. + // fBinding can be null only when the evaluation represents a function parameter. if (fBinding instanceof IFunction || fBinding instanceof IVariable || fBinding == null) { return ValueCategory.LVALUE; } @@ -401,18 +397,18 @@ public class EvalBinding extends CPPDependentEvaluation { // If this happens, it's almost certainly a bug, but the severity // is mitigated by returning a problem evaluation instead of just // trying to cast to ICPPFunction and throwing a ClassCastException. - CCorePlugin.log("An EvalBinding had a parameter owner that could not be stored in the index"); //$NON-NLS-1$ + CCorePlugin.log("An EvalBinding had a parameter owner that could not be stored in the index"); //$NON-NLS-1$ return EvalFixed.INCOMPLETE; } - ICPPFunction parameterOwner= (ICPPFunction) paramOwnerBinding; - int parameterPosition= buffer.getInt(); - IType type= buffer.unmarshalType(); - IBinding templateDefinition= buffer.unmarshalBinding(); + ICPPFunction parameterOwner = (ICPPFunction) paramOwnerBinding; + int parameterPosition = buffer.getInt(); + IType type = buffer.unmarshalType(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalBinding(parameterOwner, parameterPosition, type, templateDefinition); } else { - IBinding binding= buffer.unmarshalBinding(); - IType type= buffer.unmarshalType(); - IBinding templateDefinition= buffer.unmarshalBinding(); + IBinding binding = buffer.unmarshalBinding(); + IType type = buffer.unmarshalType(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalBinding(binding, type, templateDefinition); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java index c61d9ca649c..3878c76fa59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java @@ -48,7 +48,7 @@ public class EvalComma extends CPPDependentEvaluation { public EvalComma(ICPPEvaluation[] evals, IBinding templateDefinition) { super(templateDefinition); - fArguments= evals; + fArguments = evals; } public ICPPEvaluation[] getArguments() { @@ -107,10 +107,10 @@ public class EvalComma extends CPPDependentEvaluation { EvalComma o = (EvalComma) other; return areEquivalentEvaluations(fArguments, o.fArguments); } - + public ICPPFunction[] getOverloads() { if (fOverloads == null) { - fOverloads= computeOverloads(); + fOverloads = computeOverloads(); } return fOverloads; } @@ -123,17 +123,18 @@ public class EvalComma extends CPPDependentEvaluation { return NO_FUNCTIONS; ICPPFunction[] overloads = new ICPPFunction[fArguments.length - 1]; - ICPPEvaluation e1= fArguments[0]; + ICPPEvaluation e1 = fArguments[0]; for (int i = 1; i < fArguments.length; i++) { ICPPEvaluation e2 = fArguments[i]; ICPPFunction overload = CPPSemantics.findOverloadedOperatorComma(getTemplateDefinitionScope(), e1, e2); if (overload == null) { - e1= e2; + e1 = e2; } else { overloads[i - 1] = overload; - e1= new EvalFixed(typeFromFunctionCall(overload), valueCategoryFromFunctionCall(overload), IntegralValue.UNKNOWN); + e1 = new EvalFixed(typeFromFunctionCall(overload), valueCategoryFromFunctionCall(overload), + IntegralValue.UNKNOWN); if (e1.getType() instanceof ISemanticProblem) { - e1= e2; + e1 = e2; } } } @@ -143,7 +144,7 @@ public class EvalComma extends CPPDependentEvaluation { @Override public IType getType() { if (fType == null) { - fType= computeType(); + fType = computeType(); } return fType; } @@ -196,10 +197,10 @@ public class EvalComma extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - int len= buffer.getInt(); + int len = buffer.getInt(); ICPPEvaluation[] args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { - args[i]= buffer.unmarshalEvaluation(); + args[i] = buffer.unmarshalEvaluation(); } IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalComma(args, templateDefinition); @@ -211,7 +212,7 @@ public class EvalComma extends CPPDependentEvaluation { for (int i = 0; i < fArguments.length; i++) { ICPPEvaluation arg = fArguments[i].instantiate(context, maxDepth); if (arg != fArguments[i]) { - // Propagate instantiation errors for SFINAE purposes. + // Propagate instantiation errors for SFINAE purposes. if (arg == EvalFixed.INCOMPLETE) { return arg; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java index b726e7ec1d5..f379bdd3706 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompositeAccess.java @@ -39,8 +39,8 @@ import org.eclipse.core.runtime.CoreException; * Composite values can include arrays, structures, and parameter packs (see {@code CompositeValue}). */ public final class EvalCompositeAccess implements ICPPEvaluation { - private final ICPPEvaluation parent; // The composite value being accessed - private final int elementId; // The index of the sub-value being accessed + private final ICPPEvaluation parent; // The composite value being accessed + private final int elementId; // The index of the sub-value being accessed public EvalCompositeAccess(ICPPEvaluation parent, int elementId) { Assert.isNotNull(parent); @@ -87,10 +87,9 @@ public final class EvalCompositeAccess implements ICPPEvaluation { return false; } EvalCompositeAccess o = (EvalCompositeAccess) other; - return parent.isEquivalentTo(o.parent) - && elementId == o.elementId; + return parent.isEquivalentTo(o.parent) && elementId == o.elementId; } - + @Override public IType getType() { IType type = getParent().getType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java index 6b4ad279a10..4aaf284c02b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompoundStatementExpression.java @@ -44,7 +44,7 @@ public class EvalCompoundStatementExpression extends CPPDependentEvaluation { public EvalCompoundStatementExpression(ICPPEvaluation delegate, IBinding templateDefinition) { super(templateDefinition); - fDelegate= delegate; + fDelegate = delegate; } public ICPPEvaluation getLastEvaluation() { @@ -84,7 +84,7 @@ public class EvalCompoundStatementExpression extends CPPDependentEvaluation { EvalCompoundStatementExpression o = (EvalCompoundStatementExpression) other; return fDelegate.isEquivalentTo(o.fDelegate); } - + @Override public IType getType() { return fDelegate.getType(); @@ -108,8 +108,8 @@ public class EvalCompoundStatementExpression extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - ICPPEvaluation arg= buffer.unmarshalEvaluation(); - IBinding templateDefinition= buffer.unmarshalBinding(); + ICPPEvaluation arg = buffer.unmarshalEvaluation(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalCompoundStatementExpression(arg, templateDefinition); } @@ -127,7 +127,8 @@ public class EvalCompoundStatementExpression extends CPPDependentEvaluation { if (delegate == fDelegate) { return this; } else { - EvalCompoundStatementExpression evalCompound = new EvalCompoundStatementExpression(delegate, getTemplateDefinition()); + EvalCompoundStatementExpression evalCompound = new EvalCompoundStatementExpression(delegate, + getTemplateDefinition()); return evalCompound; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java index 022130407b7..348eb29da62 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java @@ -69,12 +69,12 @@ public class EvalConditional extends CPPDependentEvaluation { public EvalConditional(ICPPEvaluation condition, ICPPEvaluation positive, ICPPEvaluation negative, boolean positiveThrows, boolean negativeThrows, IBinding templateDefinition) { super(templateDefinition); - // Gnu-extension: Empty positive expression is replaced by condition. - fCondition= condition; - fPositive= positive; - fNegative= negative; - fPositiveThrows= positiveThrows; - fNegativeThrows= negativeThrows; + // Gnu-extension: Empty positive expression is replaced by condition. + fCondition = condition; + fPositive = positive; + fNegative = negative; + fPositiveThrows = positiveThrows; + fNegativeThrows = negativeThrows; } public ICPPEvaluation getCondition() { @@ -162,9 +162,8 @@ public class EvalConditional extends CPPDependentEvaluation { } private boolean computeIsConstantExpression() { - return fCondition.isConstantExpression() - && (fPositive == null || fPositive.isConstantExpression()) - && fNegative.isConstantExpression(); + return fCondition.isConstantExpression() && (fPositive == null || fPositive.isConstantExpression()) + && fNegative.isConstantExpression(); } @Override @@ -173,61 +172,60 @@ public class EvalConditional extends CPPDependentEvaluation { return false; } EvalConditional o = (EvalConditional) other; - return fCondition.isEquivalentTo(o.fCondition) - && areEquivalentOrNull(fPositive, o.fPositive) - && fNegative.isEquivalentTo(o.fNegative); + return fCondition.isEquivalentTo(o.fCondition) && areEquivalentOrNull(fPositive, o.fPositive) + && fNegative.isEquivalentTo(o.fNegative); } - + private void evaluate() { - if (fValueCategory != null) - return; + if (fValueCategory != null) + return; - fValueCategory= PRVALUE; + fValueCategory = PRVALUE; final ICPPEvaluation positive = fPositive == null ? fCondition : fPositive; IType t2 = positive.getType(); IType t3 = fNegative.getType(); - final IType uqt2= getNestedType(t2, TDEF | REF | CVTYPE); - final IType uqt3= getNestedType(t3, TDEF | REF | CVTYPE); + final IType uqt2 = getNestedType(t2, TDEF | REF | CVTYPE); + final IType uqt3 = getNestedType(t3, TDEF | REF | CVTYPE); if (uqt2 instanceof ISemanticProblem || uqt2 instanceof ICPPUnknownType) { - fType= uqt2; + fType = uqt2; return; } if (uqt3 instanceof ISemanticProblem || uqt3 instanceof ICPPUnknownType) { - fType= uqt3; + fType = uqt3; return; } - final boolean void2= isVoidType(uqt2); - final boolean void3= isVoidType(uqt3); + final boolean void2 = isVoidType(uqt2); + final boolean void3 = isVoidType(uqt3); // Void types: Either both are void or one is a throw expression. if (void2 || void3) { if (fPositiveThrows) { - fType= Conversions.lvalue_to_rvalue(t3, false); + fType = Conversions.lvalue_to_rvalue(t3, false); } else if (fNegativeThrows) { - fType= Conversions.lvalue_to_rvalue(t2, false); + fType = Conversions.lvalue_to_rvalue(t2, false); } else if (void2 && void3) { - fType= uqt2; + fType = uqt2; } else { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; } return; } - final ValueCategory vcat2= positive.getValueCategory(); - final ValueCategory vcat3= fNegative.getValueCategory(); + final ValueCategory vcat2 = positive.getValueCategory(); + final ValueCategory vcat3 = fNegative.getValueCategory(); // Same type if (t2.isSameType(t3)) { if (vcat2 == vcat3) { - fType= t2; - fValueCategory= vcat2; + fType = t2; + fValueCategory = vcat2; } else { - fType= prvalueType(t2); - fValueCategory= PRVALUE; + fType = prvalueType(t2); + fValueCategory = PRVALUE; } return; } @@ -237,15 +235,15 @@ public class EvalConditional extends CPPDependentEvaluation { // Different types with at least one class type if (isClassType2 || isClassType3) { - final Cost cost2= convertToMatch(t2, vcat2, uqt2, t3, vcat3, uqt3); // sets fType and fValueCategory - final Cost cost3= convertToMatch(t3, vcat3, uqt3, t2, vcat2, uqt2); // sets fType and fValueCategory + final Cost cost2 = convertToMatch(t2, vcat2, uqt2, t3, vcat3, uqt3); // sets fType and fValueCategory + final Cost cost3 = convertToMatch(t3, vcat3, uqt3, t2, vcat2, uqt2); // sets fType and fValueCategory if (cost2.converts() || cost3.converts()) { if (cost2.converts()) { if (cost3.converts() || cost2.isAmbiguousUDC()) { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; } } else if (cost3.isAmbiguousUDC()) { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; } return; } @@ -254,65 +252,67 @@ public class EvalConditional extends CPPDependentEvaluation { final CVQualifier cv2 = SemanticUtil.getCVQualifier(t2); final CVQualifier cv3 = SemanticUtil.getCVQualifier(t3); if (cv2.isAtLeastAsQualifiedAs(cv3)) { - fType= t2; - fValueCategory= vcat2; + fType = t2; + fValueCategory = vcat2; } else if (cv3.isAtLeastAsQualifiedAs(cv2)) { - fType= t3; - fValueCategory= vcat3; + fType = t3; + fValueCategory = vcat3; } else { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; } return; } // 5.16-5: At least one class type but no conversion if (isClassType2 || isClassType3) { - fOverload = CPPSemantics.findOverloadedConditionalOperator(getTemplateDefinitionScope(), positive, fNegative); + fOverload = CPPSemantics.findOverloadedConditionalOperator(getTemplateDefinitionScope(), positive, + fNegative); if (fOverload != null) { - fType= ExpressionTypes.typeFromFunctionCall(fOverload); + fType = ExpressionTypes.typeFromFunctionCall(fOverload); } else { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; } return; } // 5.16-6 - t2= Conversions.lvalue_to_rvalue(t2, false); - t3= Conversions.lvalue_to_rvalue(t3, false); + t2 = Conversions.lvalue_to_rvalue(t2, false); + t3 = Conversions.lvalue_to_rvalue(t3, false); if (t2.isSameType(t3)) { - fType= t2; + fType = t2; } else { - fType= CPPArithmeticConversion.convertCppOperandTypes(IASTBinaryExpression.op_plus, t2, t3); - if (fType == null) { - fType= Conversions.compositePointerType(t2, t3); - if (fType == null) { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; - } - } + fType = CPPArithmeticConversion.convertCppOperandTypes(IASTBinaryExpression.op_plus, t2, t3); + if (fType == null) { + fType = Conversions.compositePointerType(t2, t3); + if (fType == null) { + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; + } + } } - } + } - private Cost convertToMatch(IType t1, ValueCategory vcat1, IType uqt1, IType t2, ValueCategory vcat2, IType uqt2) { + private Cost convertToMatch(IType t1, ValueCategory vcat1, IType uqt1, IType t2, ValueCategory vcat2, IType uqt2) { // E2 is an lvalue or E2 is an xvalue try { if (vcat2.isGLValue()) { - IType target= new CPPReferenceType(t2, vcat2 == XVALUE); - Cost c= Conversions.checkImplicitConversionSequence(target, t1, vcat1, UDCMode.ALLOWED, Context.REQUIRE_DIRECT_BINDING); + IType target = new CPPReferenceType(t2, vcat2 == XVALUE); + Cost c = Conversions.checkImplicitConversionSequence(target, t1, vcat1, UDCMode.ALLOWED, + Context.REQUIRE_DIRECT_BINDING); if (c.converts()) { - fType= t2; - fValueCategory= vcat2; + fType = t2; + fValueCategory = vcat2; return c; } } // Both are class types and one derives from the other if (uqt1 instanceof ICPPClassType && uqt2 instanceof ICPPClassType) { - int dist= SemanticUtil.calculateInheritanceDepth(uqt1, uqt2); + int dist = SemanticUtil.calculateInheritanceDepth(uqt1, uqt2); if (dist >= 0) { CVQualifier cv1 = SemanticUtil.getCVQualifier(t1); CVQualifier cv2 = SemanticUtil.getCVQualifier(t2); if (cv2.isAtLeastAsQualifiedAs(cv1)) { - fType= t2; - fValueCategory= PRVALUE; + fType = t2; + fValueCategory = PRVALUE; return new Cost(t1, t2, Rank.IDENTITY); } return Cost.NO_CONVERSION; @@ -322,12 +322,12 @@ public class EvalConditional extends CPPDependentEvaluation { } // Unrelated class types or just one class: if (vcat2 != PRVALUE) { - t2= Conversions.lvalue_to_rvalue(t2, false); + t2 = Conversions.lvalue_to_rvalue(t2, false); } - Cost c= Conversions.checkImplicitConversionSequence(t2, t1, vcat1, UDCMode.ALLOWED, Context.ORDINARY); + Cost c = Conversions.checkImplicitConversionSequence(t2, t1, vcat1, UDCMode.ALLOWED, Context.ORDINARY); if (c.converts()) { - fType= t2; - fValueCategory= PRVALUE; + fType = t2; + fValueCategory = PRVALUE; return c; } } catch (DOMException e) { @@ -355,24 +355,24 @@ public class EvalConditional extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - boolean pth= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; - boolean nth= (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; - ICPPEvaluation cond= buffer.unmarshalEvaluation(); - ICPPEvaluation pos= buffer.unmarshalEvaluation(); - ICPPEvaluation neg= buffer.unmarshalEvaluation(); - IBinding templateDefinition= buffer.unmarshalBinding(); + boolean pth = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; + boolean nth = (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; + ICPPEvaluation cond = buffer.unmarshalEvaluation(); + ICPPEvaluation pos = buffer.unmarshalEvaluation(); + ICPPEvaluation neg = buffer.unmarshalEvaluation(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalConditional(cond, pos, neg, pth, nth, templateDefinition); } @Override public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) { ICPPEvaluation condition = fCondition.instantiate(context, maxDepth); - ICPPEvaluation positive = fPositive == null ? - null : fPositive.instantiate(context, maxDepth); + ICPPEvaluation positive = fPositive == null ? null : fPositive.instantiate(context, maxDepth); ICPPEvaluation negative = fNegative.instantiate(context, maxDepth); if (condition == fCondition && positive == fPositive && negative == fNegative) return this; - return new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows, getTemplateDefinition()); + return new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows, + getTemplateDefinition()); } @Override @@ -390,14 +390,15 @@ public class EvalConditional extends CPPDependentEvaluation { return fNegative.computeForFunctionCall(record, context.recordStep()); } } - ICPPEvaluation positive = fPositive == null ? - null : fPositive.computeForFunctionCall(record, context.recordStep()); + ICPPEvaluation positive = fPositive == null ? null + : fPositive.computeForFunctionCall(record, context.recordStep()); ICPPEvaluation negative = fNegative.computeForFunctionCall(record, context.recordStep()); if (condition == fCondition && positive == fPositive && negative == fNegative) { return this; } - EvalConditional evalConditional = new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows, getTemplateDefinition()); + EvalConditional evalConditional = new EvalConditional(condition, positive, negative, fPositiveThrows, + fNegativeThrows, getTemplateDefinition()); return evalConditional; } @@ -412,8 +413,8 @@ public class EvalConditional extends CPPDependentEvaluation { @Override public boolean referencesTemplateParameter() { - return fCondition.referencesTemplateParameter() || - (fPositive != null && fPositive.referencesTemplateParameter()) || - fNegative.referencesTemplateParameter(); + return fCondition.referencesTemplateParameter() + || (fPositive != null && fPositive.referencesTemplateParameter()) + || fNegative.referencesTemplateParameter(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java index 87f64a26197..4d6073838ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConstructor.java @@ -122,28 +122,26 @@ public final class EvalConstructor extends CPPDependentEvaluation { return false; } EvalConstructor o = (EvalConstructor) other; - return fType.isSameType(o.fType) - && fConstructor == o.fConstructor - && areEquivalentEvaluations(fArguments, o.fArguments); + return fType.isSameType(o.fType) && fConstructor == o.fConstructor + && areEquivalentEvaluations(fArguments, o.fArguments); } - + @Override public IType getType() { return fType; } - + public ICPPConstructor getConstructor() { return fConstructor; } - + public ICPPEvaluation[] getArguments() { return fArguments; } @Override public IValue getValue() { - ICPPEvaluation computed = - computeForFunctionCall(new ActivationRecord(), new ConstexprEvaluationContext()); + ICPPEvaluation computed = computeForFunctionCall(new ActivationRecord(), new ConstexprEvaluationContext()); if (computed == this) return IntegralValue.ERROR; @@ -156,20 +154,19 @@ public final class EvalConstructor extends CPPDependentEvaluation { } @Override - public ICPPEvaluation computeForFunctionCall(ActivationRecord callSiteRecord, - ConstexprEvaluationContext context) { + public ICPPEvaluation computeForFunctionCall(ActivationRecord callSiteRecord, ConstexprEvaluationContext context) { final IType unwrappedType = SemanticUtil.getNestedType(fType, TDEF | REF | CVTYPE); if (!(unwrappedType instanceof ICPPClassType)) { return this; } - final ICPPClassType classType = (ICPPClassType) unwrappedType; + final ICPPClassType classType = (ICPPClassType) unwrappedType; final CompositeValue compositeValue = CompositeValue.create(classType); ICPPEvaluation[] argList = evaluateArguments(fArguments, callSiteRecord, context); EvalFixed constructedObject = new EvalFixed(fType, ValueCategory.PRVALUE, compositeValue); CPPVariable binding = new CPPVariable(TEMP_NAME); - ActivationRecord localRecord = EvalFunctionCall.createActivationRecord(fConstructor.getParameters(), - argList, constructedObject); + ActivationRecord localRecord = EvalFunctionCall.createActivationRecord(fConstructor.getParameters(), argList, + constructedObject); localRecord.update(binding, constructedObject); ICPPExecution exec = fConstructor.getConstructorChainExecution(); @@ -180,8 +177,7 @@ public final class EvalConstructor extends CPPDependentEvaluation { if (ccInitializer.getKey() instanceof ICPPConstructor) { ICPPClassType baseClassType = (ICPPClassType) ccInitializer.getKey().getOwner(); final ICPPEvaluation memberEval = ccInitializer.getValue(); - ICPPEvaluation memberValue = - memberEval.computeForFunctionCall(localRecord, context.recordStep()); + ICPPEvaluation memberValue = memberEval.computeForFunctionCall(localRecord, context.recordStep()); ICPPEvaluation[] baseClassValues = memberValue.getValue().getAllSubValues(); ICPPField[] baseFields = ClassTypeHelper.getFields(baseClassType); @@ -195,14 +191,13 @@ public final class EvalConstructor extends CPPDependentEvaluation { } } - ICPPField[] fields = classType.getDeclaredFields(); for (ICPPField field : fields) { if (field.isStatic()) { continue; } - final Map.Entry<IBinding, ICPPEvaluation> initializer = - getInitializerFromMemberInitializerList(field, exec); + final Map.Entry<IBinding, ICPPEvaluation> initializer = getInitializerFromMemberInitializerList(field, + exec); ICPPEvaluation value = null; if (initializer != null) { @@ -283,8 +278,8 @@ public final class EvalConstructor extends CPPDependentEvaluation { IASTInitializerClause initClause = equalsInitalizer.getInitializerClause(); return evaluateArguments(initClause); } else { - throw new IllegalArgumentException(initializer.getClass().getSimpleName() - + " type of initializer is not supported"); //$NON-NLS-1$ + throw new IllegalArgumentException( + initializer.getClass().getSimpleName() + " type of initializer is not supported"); //$NON-NLS-1$ } } @@ -300,17 +295,15 @@ public final class EvalConstructor extends CPPDependentEvaluation { private ICPPEvaluation[] evaluateArguments(ICPPEvaluation[] arguments, ActivationRecord record, ConstexprEvaluationContext context) { ICPPEvaluation[] argList = new ICPPEvaluation[arguments.length + 1]; - EvalBinding constructorBinding = - new EvalBinding(fConstructor, fConstructor.getType(), getTemplateDefinition()); + EvalBinding constructorBinding = new EvalBinding(fConstructor, fConstructor.getType(), getTemplateDefinition()); argList[0] = constructorBinding; for (int i = 0; i < arguments.length; i++) { ICPPEvaluation evaluatedClause = arguments[i].computeForFunctionCall(record, context.recordStep()); - argList[i+1] = evaluatedClause; + argList[i + 1] = evaluatedClause; } return argList; } - @Override public int determinePackSize(ICPPTemplateParameterMap tpMap) { int r = CPPTemplates.determinePackSize(fType, tpMap); @@ -370,11 +363,9 @@ public final class EvalConstructor extends CPPDependentEvaluation { if (newConstructor instanceof CPPDeferredFunction) { ICPPFunction[] candidates = ((CPPDeferredFunction) newConstructor).getCandidates(); if (candidates != null) { - CPPFunctionSet functionSet = - new CPPFunctionSet(candidates, new ICPPTemplateArgument[]{}, null); - EvalFunctionSet evalFunctionSet = - new EvalFunctionSet(functionSet, false, false, newType, - CPPSemantics.getCurrentLookupPoint()); + CPPFunctionSet functionSet = new CPPFunctionSet(candidates, new ICPPTemplateArgument[] {}, null); + EvalFunctionSet evalFunctionSet = new EvalFunctionSet(functionSet, false, false, newType, + CPPSemantics.getCurrentLookupPoint()); ICPPEvaluation resolved = evalFunctionSet.resolveFunction(newArguments); if (resolved instanceof EvalBinding) { EvalBinding evalBinding = (EvalBinding) resolved; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java index f480b614b44..1eab6725954 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java @@ -37,8 +37,8 @@ import org.eclipse.core.runtime.CoreException; * Performs evaluation of an expression. */ public final class EvalFixed extends CPPEvaluation { - public static final ICPPEvaluation INCOMPLETE = - new EvalFixed(ProblemType.UNKNOWN_FOR_EXPRESSION, PRVALUE, IntegralValue.ERROR); + public static final ICPPEvaluation INCOMPLETE = new EvalFixed(ProblemType.UNKNOWN_FOR_EXPRESSION, PRVALUE, + IntegralValue.ERROR); private final IType fType; private final IValue fValue; @@ -67,9 +67,9 @@ public final class EvalFixed extends CPPEvaluation { type = t; } } - fType= type; - fValueCategory= cat; - fValue= value; + fType = type; + fValueCategory = cat; + fValue = value; } @Override @@ -85,8 +85,8 @@ public final class EvalFixed extends CPPEvaluation { @Override public boolean isTypeDependent() { if (!fCheckedIsTypeDependent) { - fCheckedIsTypeDependent= true; - fIsTypeDependent= CPPTemplates.isDependentType(fType); + fCheckedIsTypeDependent = true; + fIsTypeDependent = CPPTemplates.isDependentType(fType); } return fIsTypeDependent; } @@ -94,8 +94,8 @@ public final class EvalFixed extends CPPEvaluation { @Override public boolean isValueDependent() { if (!fCheckedIsValueDependent) { - fCheckedIsValueDependent= true; - fIsValueDependent= IntegralValue.isDependentValue(fValue); + fCheckedIsValueDependent = true; + fIsValueDependent = IntegralValue.isDependentValue(fValue); } return fIsValueDependent; } @@ -110,8 +110,7 @@ public final class EvalFixed extends CPPEvaluation { } private boolean computeIsConstantExpression() { - return (fType instanceof ICPPClassType && TypeTraits.isEmpty(fType)) - || isConstexprValue(fValue); + return (fType instanceof ICPPClassType && TypeTraits.isEmpty(fType)) || isConstexprValue(fValue); } @Override @@ -120,10 +119,9 @@ public final class EvalFixed extends CPPEvaluation { return false; } EvalFixed o = (EvalFixed) other; - return fType.isSameType(o.fType) - && fValue.isEquivalentTo(o.fValue); + return fType.isSameType(o.fType) && fValue.isEquivalentTo(o.fValue); } - + @Override public IType getType() { return fType; @@ -141,7 +139,7 @@ public final class EvalFixed extends CPPEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - includeValue= includeValue && fValue != IntegralValue.UNKNOWN; + includeValue = includeValue && fValue != IntegralValue.UNKNOWN; short firstBytes = ITypeMarshalBuffer.EVAL_FIXED; if (includeValue) firstBytes |= ITypeMarshalBuffer.FLAG1; @@ -164,23 +162,23 @@ public final class EvalFixed extends CPPEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - final boolean readValue= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; + final boolean readValue = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; IValue value; ValueCategory cat; switch (firstBytes & (ITypeMarshalBuffer.FLAG2 | ITypeMarshalBuffer.FLAG3)) { case ITypeMarshalBuffer.FLAG2: - cat= PRVALUE; + cat = PRVALUE; break; case ITypeMarshalBuffer.FLAG3: - cat= LVALUE; + cat = LVALUE; break; default: - cat= XVALUE; + cat = XVALUE; break; } - IType type= buffer.unmarshalType(); - value= readValue ? buffer.unmarshalValue() : IntegralValue.UNKNOWN; + IType type = buffer.unmarshalType(); + value = readValue ? buffer.unmarshalValue() : IntegralValue.UNKNOWN; return new EvalFixed(type, cat, value); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java index f5c6df142a5..96465604670 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java @@ -80,11 +80,11 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { public ICPPEvaluation[] getArguments() { return fArguments; } - + private ICPPEvaluation getImplicitThis() { if (fImplicitThis != null) return fImplicitThis; - + if (fArguments.length > 0) { if (fArguments[0] instanceof EvalMemberAccess) { return ((EvalMemberAccess) fArguments[0]).getOwnerEval(); @@ -92,7 +92,7 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { return ((EvalID) fArguments[0]).getFieldOwner(); } } - + return null; } @@ -113,10 +113,9 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { @Override public boolean isValueDependent() { - return containsDependentValue(fArguments) || - !CPPTemplates.isFullyInstantiated(resolveFunctionBinding()); + return containsDependentValue(fArguments) || !CPPTemplates.isFullyInstantiated(resolveFunctionBinding()); } - + @Override public boolean isConstantExpression() { if (!fCheckedIsConstantExpression) { @@ -129,7 +128,7 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { private boolean computeIsConstantExpression() { return areAllConstantExpressions(fArguments) && isNullOrConstexprFunc(getOverload()); } - + @Override public boolean isEquivalentTo(ICPPEvaluation other) { if (!(other instanceof EvalFunctionCall)) { @@ -150,10 +149,10 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { if (isTypeDependent()) return null; - IType t= SemanticUtil.getNestedType(fArguments[0].getType(), TDEF | REF | CVTYPE); + IType t = SemanticUtil.getNestedType(fArguments[0].getType(), TDEF | REF | CVTYPE); if (t instanceof ICPPClassType) { - return CPPSemantics.findOverloadedOperator(getTemplateDefinitionScope(), fArguments, t, - OverloadableOperator.PAREN, LookupMode.NO_GLOBALS); + return CPPSemantics.findOverloadedOperator(getTemplateDefinitionScope(), fArguments, t, + OverloadableOperator.PAREN, LookupMode.NO_GLOBALS); } return null; } @@ -196,7 +195,7 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { if (overload != null) return valueCategoryFromFunctionCall(overload); - IType t= fArguments[0].getType(); + IType t = fArguments[0].getType(); if (t instanceof IPointerType) { t = SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); } @@ -217,8 +216,7 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) - throws CoreException { + public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len = buffer.getInt(); ICPPEvaluation[] args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { @@ -236,7 +234,7 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { return this; ICPPEvaluation implicitThis = fImplicitThis; - + if (args[0] instanceof EvalFunctionSet && getOverload() == null) { // Resolve the function using the parameters of the function call. EvalFunctionSet functionSet = (EvalFunctionSet) args[0]; @@ -246,8 +244,8 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { if (args[0] == EvalFixed.INCOMPLETE) { return args[0]; } - - // For functions sets of member functions, EvalFunctionSet does not store + + // For functions sets of member functions, EvalFunctionSet does not store // the value of the object on which the member function is called. // If this value was previously elided (not stored explicitly in // fImplicitThis to avoid duplication with the copy stored in fArguments[0]), @@ -278,20 +276,21 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { ICPPParameter[] parameters = functionBinding.getParameters(); for (int i = 0; i < fArguments.length; i++) { ICPPEvaluation arg = fArguments[i].computeForFunctionCall(record, context.recordStep()); - if (0 < i && i <= parameters.length && isReference(parameters[i - 1]) && fArguments[i] instanceof EvalBinding) { - final EvalBinding evalBinding = (EvalBinding) fArguments[i]; - IBinding binding = evalBinding.getBinding(); - // If the binding being referenced isn't present in the activation record, - // we won't be able to evaluate the function call. - if (record.getVariable(binding) == null) - return EvalFixed.INCOMPLETE; - arg = new EvalReference(record, binding, evalBinding.getTemplateDefinition()); - } else if (0 < i && i <= parameters.length && !isReference(parameters[i - 1])) { - IValue copiedValue = arg.getValue().clone(); - arg = new EvalFixed(arg.getType(), arg.getValueCategory(), copiedValue); - } - if (arg == EvalFixed.INCOMPLETE) - return EvalFixed.INCOMPLETE; + if (0 < i && i <= parameters.length && isReference(parameters[i - 1]) + && fArguments[i] instanceof EvalBinding) { + final EvalBinding evalBinding = (EvalBinding) fArguments[i]; + IBinding binding = evalBinding.getBinding(); + // If the binding being referenced isn't present in the activation record, + // we won't be able to evaluate the function call. + if (record.getVariable(binding) == null) + return EvalFixed.INCOMPLETE; + arg = new EvalReference(record, binding, evalBinding.getTemplateDefinition()); + } else if (0 < i && i <= parameters.length && !isReference(parameters[i - 1])) { + IValue copiedValue = arg.getValue().clone(); + arg = new EvalFixed(arg.getType(), arg.getValueCategory(), copiedValue); + } + if (arg == EvalFixed.INCOMPLETE) + return EvalFixed.INCOMPLETE; args[i] = arg; } @@ -328,12 +327,11 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { ICPPFunction function = resolveFunctionBinding(); if (function == null) return this; - + if (!function.isConstexpr()) return EvalFixed.INCOMPLETE; - ActivationRecord record = createActivationRecord(function.getParameters(), fArguments, - getImplicitThis()); + ActivationRecord record = createActivationRecord(function.getParameters(), fArguments, getImplicitThis()); ICPPExecution bodyExec = CPPFunction.getFunctionBodyExecution(function); if (bodyExec == null) { if (!(function instanceof ICPPTemplateInstance) @@ -398,12 +396,12 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { } private boolean isReference(IBinding binding) { - return binding instanceof IVariable - && (((IVariable) binding).getType() instanceof ICPPReferenceType || ((IVariable) binding) - .getType() instanceof IPointerType); + return binding instanceof IVariable && (((IVariable) binding).getType() instanceof ICPPReferenceType + || ((IVariable) binding).getType() instanceof IPointerType); } - public static ActivationRecord createActivationRecord(ICPPParameter[] parameters, ICPPEvaluation[] arguments, ICPPEvaluation implicitThis) { + public static ActivationRecord createActivationRecord(ICPPParameter[] parameters, ICPPEvaluation[] arguments, + ICPPEvaluation implicitThis) { ActivationRecord record = new ActivationRecord(parameters, implicitThis); // We start at arguments[1] because arguments[0] is the function's evaluation. @@ -415,7 +413,7 @@ public final class EvalFunctionCall extends CPPDependentEvaluation { ICPPEvaluation[] values = new ICPPEvaluation[paramPackLen]; IType[] types = new IType[paramPackLen]; for (int i = 0; i < paramPackLen; i++) { - ICPPEvaluation arg = arguments[j+i]; + ICPPEvaluation arg = arguments[j + i]; values[i] = arg; types[i] = arg.getType(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java index 1fc341b1d9b..f8eb1a08ceb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java @@ -70,11 +70,11 @@ public class EvalFunctionSet extends CPPDependentEvaluation { public EvalFunctionSet(CPPFunctionSet set, boolean qualified, boolean addressOf, IType impliedObjectType, IBinding templateDefinition) { super(templateDefinition); - fFunctionSet= set; - fQualified= qualified; - fAddressOf= addressOf; - fImpliedObjectType= impliedObjectType; - fName= null; + fFunctionSet = set; + fQualified = qualified; + fAddressOf = addressOf; + fImpliedObjectType = impliedObjectType; + fName = null; } public EvalFunctionSet(char[] name, boolean qualified, boolean addressOf, IASTNode pointOfDefinition) { @@ -83,11 +83,11 @@ public class EvalFunctionSet extends CPPDependentEvaluation { public EvalFunctionSet(char[] name, boolean qualified, boolean addressOf, IBinding templateDefinition) { super(templateDefinition); - fFunctionSet= null; - fQualified= qualified; - fAddressOf= addressOf; - fImpliedObjectType= null; - fName= name; + fFunctionSet = null; + fQualified = qualified; + fAddressOf = addressOf; + fImpliedObjectType = null; + fName = name; } public CPPFunctionSet getFunctionSet() { @@ -169,7 +169,7 @@ public class EvalFunctionSet extends CPPDependentEvaluation { EvalFunctionSet o = (EvalFunctionSet) other; return fFunctionSet.equals(o.fFunctionSet); } - + @Override public IType getType() { return new FunctionSetType(fFunctionSet, fAddressOf); @@ -186,10 +186,10 @@ public class EvalFunctionSet extends CPPDependentEvaluation { } // Descriptive names for flags used during serialization. - private final static short FLAG_ADDRESS_OF = ITypeMarshalBuffer.FLAG1; - private final static short FLAG_HAS_FUNCTION_SET = ITypeMarshalBuffer.FLAG2; + private final static short FLAG_ADDRESS_OF = ITypeMarshalBuffer.FLAG1; + private final static short FLAG_HAS_FUNCTION_SET = ITypeMarshalBuffer.FLAG2; private final static short FLAG_HAS_TEMPLATE_ARGS = ITypeMarshalBuffer.FLAG3; - private final static short FLAG_QUALIFIED = ITypeMarshalBuffer.FLAG4; + private final static short FLAG_QUALIFIED = ITypeMarshalBuffer.FLAG4; @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { @@ -225,29 +225,29 @@ public class EvalFunctionSet extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - final boolean qualified= (firstBytes & FLAG_QUALIFIED) != 0; - final boolean addressOf= (firstBytes & FLAG_ADDRESS_OF) != 0; + final boolean qualified = (firstBytes & FLAG_QUALIFIED) != 0; + final boolean addressOf = (firstBytes & FLAG_ADDRESS_OF) != 0; if ((firstBytes & FLAG_HAS_FUNCTION_SET) != 0) { - int bindingCount= buffer.getInt(); - ICPPFunction[] bindings= new ICPPFunction[bindingCount]; + int bindingCount = buffer.getInt(); + ICPPFunction[] bindings = new ICPPFunction[bindingCount]; for (int i = 0; i < bindings.length; i++) { - bindings[i]= (ICPPFunction) buffer.unmarshalBinding(); + bindings[i] = (ICPPFunction) buffer.unmarshalBinding(); } - ICPPTemplateArgument[] args= null; + ICPPTemplateArgument[] args = null; if ((firstBytes & FLAG_HAS_TEMPLATE_ARGS) != 0) { - int len= buffer.getInt(); + int len = buffer.getInt(); args = new ICPPTemplateArgument[len]; for (int i = 0; i < args.length; i++) { - args[i]= buffer.unmarshalTemplateArgument(); + args[i] = buffer.unmarshalTemplateArgument(); } } - IType impliedObjectType= buffer.unmarshalType(); - IBinding templateDefinition= buffer.unmarshalBinding(); + IType impliedObjectType = buffer.unmarshalType(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalFunctionSet(new CPPFunctionSet(bindings, args, null), qualified, addressOf, impliedObjectType, templateDefinition); } else { char[] name = buffer.getCharArray(); - IBinding templateDefinition= buffer.unmarshalBinding(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalFunctionSet(name, qualified, addressOf, templateDefinition); } } @@ -279,7 +279,7 @@ public class EvalFunctionSet extends CPPDependentEvaluation { ICPPClassSpecialization ownerClass = (ICPPClassSpecialization) owner; functions = new ICPPFunction[originalFunctions.length]; for (int i = 0; i < originalFunctions.length; i++) { - functions[i] = (ICPPFunction) ownerClass.specializeMember(originalFunctions[i]); + functions[i] = (ICPPFunction) ownerClass.specializeMember(originalFunctions[i]); } } // No need to instantiate the implied object type. An EvalFunctioNSet should only be created @@ -311,8 +311,7 @@ public class EvalFunctionSet extends CPPDependentEvaluation { data = new LookupData(fName, null, point); } else { functions = fFunctionSet.getBindings(); - data = new LookupData(functions[0].getNameCharArray(), fFunctionSet.getTemplateArguments(), - point); + data = new LookupData(functions[0].getNameCharArray(), fFunctionSet.getTemplateArguments(), point); data.foundItems = functions; } data.setFunctionArguments(false, args); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 017ea516b12..06aceebca0a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -78,26 +78,24 @@ public class EvalID extends CPPDependentEvaluation { private final boolean fIsPointerDeref; private final ICPPTemplateArgument[] fTemplateArgs; - public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, - boolean qualified, boolean isPointerDeref, ICPPTemplateArgument[] templateArgs, - IASTNode pointOfDefinition) { + public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, boolean qualified, + boolean isPointerDeref, ICPPTemplateArgument[] templateArgs, IASTNode pointOfDefinition) { this(fieldOwner, nameOwner, simpleID, addressOf, qualified, isPointerDeref, templateArgs, findEnclosingTemplate(pointOfDefinition)); } - public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, - boolean qualified, boolean isPointerDeref, ICPPTemplateArgument[] templateArgs, - IBinding templateDefinition) { + public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, boolean qualified, + boolean isPointerDeref, ICPPTemplateArgument[] templateArgs, IBinding templateDefinition) { super(templateDefinition); if (simpleID == null) throw new NullPointerException("simpleID"); //$NON-NLS-1$ - fFieldOwner= fieldOwner; - fName= simpleID; - fNameOwner= nameOwner; - fAddressOf= addressOf; - fQualified= qualified; - fIsPointerDeref= isPointerDeref; - fTemplateArgs= templateArgs; + fFieldOwner = fieldOwner; + fName = simpleID; + fNameOwner = nameOwner; + fAddressOf = addressOf; + fQualified = qualified; + fIsPointerDeref = isPointerDeref; + fTemplateArgs = templateArgs; } /** @@ -165,15 +163,11 @@ public class EvalID extends CPPDependentEvaluation { return false; } EvalID o = (EvalID) other; - return areEquivalentOrNull(fFieldOwner, o.fFieldOwner) - && CharArrayUtils.equals(fName, o.fName) - && fNameOwner == o.fNameOwner - && fAddressOf == o.fAddressOf - && fQualified == o.fQualified - && fIsPointerDeref == o.fIsPointerDeref - && areEquivalentArguments(fTemplateArgs, o.fTemplateArgs); + return areEquivalentOrNull(fFieldOwner, o.fFieldOwner) && CharArrayUtils.equals(fName, o.fName) + && fNameOwner == o.fNameOwner && fAddressOf == o.fAddressOf && fQualified == o.fQualified + && fIsPointerDeref == o.fIsPointerDeref && areEquivalentArguments(fTemplateArgs, o.fTemplateArgs); } - + @Override public IType getType() { return new TypeOfDependentExpression(this); @@ -216,23 +210,22 @@ public class EvalID extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - final boolean addressOf= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; - final boolean qualified= (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; - final boolean isPointerDeref= (firstBytes & ITypeMarshalBuffer.FLAG4) != 0; - ICPPEvaluation fieldOwner= buffer.unmarshalEvaluation(); - char[] name= buffer.getCharArray(); - IBinding nameOwner= buffer.unmarshalBinding(); - ICPPTemplateArgument[] args= null; + final boolean addressOf = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; + final boolean qualified = (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; + final boolean isPointerDeref = (firstBytes & ITypeMarshalBuffer.FLAG4) != 0; + ICPPEvaluation fieldOwner = buffer.unmarshalEvaluation(); + char[] name = buffer.getCharArray(); + IBinding nameOwner = buffer.unmarshalBinding(); + ICPPTemplateArgument[] args = null; if ((firstBytes & ITypeMarshalBuffer.FLAG3) != 0) { - int len= buffer.getInt(); + int len = buffer.getInt(); args = new ICPPTemplateArgument[len]; for (int i = 0; i < args.length; i++) { - args[i]= buffer.unmarshalTemplateArgument(); + args[i] = buffer.unmarshalTemplateArgument(); } } - IBinding templateDefinition= buffer.unmarshalBinding(); - return new EvalID(fieldOwner, nameOwner, name, addressOf, qualified, isPointerDeref, args, - templateDefinition); + IBinding templateDefinition = buffer.unmarshalBinding(); + return new EvalID(fieldOwner, nameOwner, name, addressOf, qualified, isPointerDeref, args, templateDefinition); } public static ICPPEvaluation create(IASTIdExpression expr) { @@ -249,12 +242,12 @@ public class EvalID extends CPPDependentEvaluation { if (binding instanceof ICPPDeferredVariableInstance) { return new EvalBinding(binding, null, expr); } - + ICPPTemplateArgument[] templateArgs = null; final IASTName lastName = name.getLastName(); if (lastName instanceof ICPPASTTemplateId) { try { - templateArgs= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) lastName); + templateArgs = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) lastName); } catch (DOMException e) { return EvalFixed.INCOMPLETE; } @@ -275,10 +268,10 @@ public class EvalID extends CPPDependentEvaluation { if (owner instanceof IProblemBinding) return EvalFixed.INCOMPLETE; - ICPPEvaluation fieldOwner= null; - IType fieldOwnerType= withinNonStaticMethod(expr); + ICPPEvaluation fieldOwner = null; + IType fieldOwnerType = withinNonStaticMethod(expr); if (fieldOwnerType != null) { - fieldOwner= new EvalFixed(fieldOwnerType, ValueCategory.LVALUE, IntegralValue.UNKNOWN); + fieldOwner = new EvalFixed(fieldOwnerType, ValueCategory.LVALUE, IntegralValue.UNKNOWN); } return new EvalID(fieldOwner, owner, name.getSimpleID(), isAddressOf(expr), @@ -287,18 +280,18 @@ public class EvalID extends CPPDependentEvaluation { /** * 9.3.1-3 Transformation to class member access within a non-static member function. */ - if (binding instanceof ICPPMember && !(binding instanceof IType) - && !(binding instanceof ICPPConstructor) &&!((ICPPMember) binding).isStatic()) { - IType fieldOwnerType= withinNonStaticMethod(expr); + if (binding instanceof ICPPMember && !(binding instanceof IType) && !(binding instanceof ICPPConstructor) + && !((ICPPMember) binding).isStatic()) { + IType fieldOwnerType = withinNonStaticMethod(expr); if (fieldOwnerType != null) { return new EvalMemberAccess(fieldOwnerType, LVALUE, binding, true, expr); } } if (binding instanceof IEnumerator) { - IType type= ((IEnumerator) binding).getType(); + IType type = ((IEnumerator) binding).getType(); if (type instanceof ICPPEnumeration) { - ICPPEnumeration enumType= (ICPPEnumeration) type; + ICPPEnumeration enumType = (ICPPEnumeration) type; // [dcl.enum] 7.2-5 if (isInsideEnum(expr, enumType)) { if (binding instanceof ICPPInternalEnumerator) { @@ -331,12 +324,12 @@ public class EvalID extends CPPDependentEvaluation { } private static IType withinNonStaticMethod(IASTExpression expr) { - IASTNode parent= expr.getParent(); + IASTNode parent = expr.getParent(); while (parent != null && !(parent instanceof ICPPASTFunctionDefinition)) { - parent= parent.getParent(); + parent = parent.getParent(); } if (parent instanceof ICPPASTFunctionDefinition) { - ICPPASTFunctionDefinition fdef= (ICPPASTFunctionDefinition) parent; + ICPPASTFunctionDefinition fdef = (ICPPASTFunctionDefinition) parent; // Resolution of the method name triggers name resolution inside the // decl-specifier of the method definition. If we are currently // resolving something inside the decl-specifier, this can lead to @@ -357,9 +350,9 @@ public class EvalID extends CPPDependentEvaluation { IASTNode e = expr.getParent(); while (e instanceof IASTUnaryExpression) { final IASTUnaryExpression unary = (IASTUnaryExpression) e; - final int op= unary.getOperator(); + final int op = unary.getOperator(); if (op == IASTUnaryExpression.op_bracketedPrimary) { - e= unary.getOperand(); + e = unary.getOperand(); } else { return op == IASTUnaryExpression.op_amper; } @@ -373,7 +366,7 @@ public class EvalID extends CPPDependentEvaluation { if (templateArgs != null) { templateArgs = instantiateArguments(templateArgs, context, false); } - + char[] name = fName; name = CPPTemplates.instantiateName(name, context, getTemplateDefinition()); @@ -425,11 +418,11 @@ public class EvalID extends CPPDependentEvaluation { IType fieldOwnerTypeSimplifiedCV = SemanticUtil.getNestedType(fieldOwnerType, TDEF | REF); IType fieldOwnerTypeSimplified = SemanticUtil.getNestedType(fieldOwnerTypeSimplifiedCV, CVTYPE); if (fieldOwnerTypeSimplified instanceof ICPPClassType) { - ICPPEvaluation eval = resolveName(name, (ICPPClassType) fieldOwnerTypeSimplified, fieldOwner, + ICPPEvaluation eval = resolveName(name, (ICPPClassType) fieldOwnerTypeSimplified, fieldOwner, templateArgs, fieldOwnerTypeSimplifiedCV); if (eval != null) return eval; - if (!CPPTemplates.isDependentType(fieldOwnerTypeSimplified)) + if (!CPPTemplates.isDependentType(fieldOwnerTypeSimplified)) return EvalFixed.INCOMPLETE; } else if (fieldOwnerTypeSimplified instanceof ICPPBasicType) { // Handle pseudo-destructor of basic type, e.g. "T().~T" instantiated with [T = int]. @@ -454,11 +447,12 @@ public class EvalID extends CPPDependentEvaluation { if (fieldOwner == fFieldOwner) { return this; } - EvalID newEvalID = new EvalID(fieldOwner, fNameOwner, fName, fAddressOf, fQualified, fIsPointerDeref, fTemplateArgs, getTemplateDefinition()); + EvalID newEvalID = new EvalID(fieldOwner, fNameOwner, fName, fAddressOf, fQualified, fIsPointerDeref, + fTemplateArgs, getTemplateDefinition()); return newEvalID; } - private ICPPEvaluation resolveName(char[] name, ICPPClassType nameOwner, ICPPEvaluation ownerEval, + private ICPPEvaluation resolveName(char[] name, ICPPClassType nameOwner, ICPPEvaluation ownerEval, ICPPTemplateArgument[] templateArgs, IType impliedObjectType) { IASTNode point = CPPSemantics.getCurrentLookupPoint(); LookupData data = new LookupData(name, templateArgs, point); @@ -473,12 +467,12 @@ public class EvalID extends CPPDependentEvaluation { if (binding instanceof ICPPFunction) { ICPPFunction[] functions = new ICPPFunction[bindings.length]; System.arraycopy(bindings, 0, functions, 0, bindings.length); - return new EvalFunctionSet(new CPPFunctionSet(functions, templateArgs, null), fQualified, - fAddressOf, impliedObjectType, getTemplateDefinition()); + return new EvalFunctionSet(new CPPFunctionSet(functions, templateArgs, null), fQualified, fAddressOf, + impliedObjectType, getTemplateDefinition()); } if (binding instanceof CPPFunctionSet) { - return new EvalFunctionSet((CPPFunctionSet) binding, fQualified, fAddressOf, - impliedObjectType, getTemplateDefinition()); + return new EvalFunctionSet((CPPFunctionSet) binding, fQualified, fAddressOf, impliedObjectType, + getTemplateDefinition()); } if (binding instanceof IEnumerator) { return new EvalBinding(binding, null, getTemplateDefinition()); @@ -489,9 +483,11 @@ public class EvalID extends CPPDependentEvaluation { return new EvalBinding(binding, null, getTemplateDefinition()); } if (ownerEval != null) { - return new EvalMemberAccess(nameOwner, ownerEval.getValueCategory(), binding, ownerEval, false, point); + return new EvalMemberAccess(nameOwner, ownerEval.getValueCategory(), binding, ownerEval, false, + point); } else { - return new EvalMemberAccess(nameOwner, ValueCategory.PRVALUE, binding, false, getTemplateDefinition()); + return new EvalMemberAccess(nameOwner, ValueCategory.PRVALUE, binding, false, + getTemplateDefinition()); } } } @@ -502,9 +498,9 @@ public class EvalID extends CPPDependentEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { int r = fFieldOwner != null ? fFieldOwner.determinePackSize(tpMap) : CPPTemplates.PACK_SIZE_NOT_FOUND; if (fNameOwner instanceof ICPPTemplateParameter) { - r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPTemplateParameter) fNameOwner, tpMap)); - } - else if (fNameOwner instanceof ICPPUnknownBinding) { + r = CPPTemplates.combinePackSize(r, + CPPTemplates.determinePackSize((ICPPTemplateParameter) fNameOwner, tpMap)); + } else if (fNameOwner instanceof ICPPUnknownBinding) { r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPUnknownBinding) fNameOwner, tpMap)); } if (fTemplateArgs != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java index ba026ede4d4..d5b4203afb9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java @@ -45,7 +45,7 @@ public class EvalInitList extends CPPDependentEvaluation { public EvalInitList(ICPPEvaluation[] clauses, IBinding templateDefinition) { super(templateDefinition); - fClauses= clauses; + fClauses = clauses; } public ICPPEvaluation[] getClauses() { @@ -97,7 +97,7 @@ public class EvalInitList extends CPPDependentEvaluation { EvalInitList o = (EvalInitList) other; return areEquivalentEvaluations(fClauses, o.fClauses); } - + @Override public IType getType() { return new InitializerListType(this); @@ -127,12 +127,12 @@ public class EvalInitList extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - int len= buffer.getInt(); + int len = buffer.getInt(); ICPPEvaluation[] args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { - args[i]= buffer.unmarshalEvaluation(); + args[i] = buffer.unmarshalEvaluation(); } - IBinding templateDefinition= buffer.unmarshalBinding(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalInitList(args, templateDefinition); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java index b3514f85418..e32d8c97873 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java @@ -78,23 +78,23 @@ public class EvalMemberAccess extends CPPDependentEvaluation { private boolean fIsValueDependent; private boolean fCheckedIsValueDependent; - public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, - boolean isPointerDeref, IASTNode pointOfDefinition) { + public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, boolean isPointerDeref, + IASTNode pointOfDefinition) { this(ownerType, ownerValueCat, member, isPointerDeref, findEnclosingTemplate(pointOfDefinition)); } - public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, - boolean isPointerDeref, IBinding templateDefinition) { + public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, boolean isPointerDeref, + IBinding templateDefinition) { this(ownerType, ownerValueCat, member, null, isPointerDeref, templateDefinition); } - public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, - ICPPEvaluation ownerEval, boolean isDeref, IASTNode pointOfDefinition) { + public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, ICPPEvaluation ownerEval, + boolean isDeref, IASTNode pointOfDefinition) { this(ownerType, ownerValueCat, member, ownerEval, isDeref, findEnclosingTemplate(pointOfDefinition)); } - public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, - ICPPEvaluation ownerEval, boolean isDeref, IBinding templateDefinition) { + public EvalMemberAccess(IType ownerType, ValueCategory ownerValueCat, IBinding member, ICPPEvaluation ownerEval, + boolean isDeref, IBinding templateDefinition) { super(templateDefinition); fOwnerType = ownerType; fOwnerValueCategory = ownerValueCat; @@ -197,40 +197,38 @@ public class EvalMemberAccess extends CPPDependentEvaluation { return false; } EvalMemberAccess o = (EvalMemberAccess) other; - return fOwnerType.isSameType(o.fOwnerType) - && fMember == o.fMember - && fOwnerValueCategory == o.fOwnerValueCategory - && fIsPointerDeref == o.fIsPointerDeref; + return fOwnerType.isSameType(o.fOwnerType) && fMember == o.fMember + && fOwnerValueCategory == o.fOwnerValueCategory && fIsPointerDeref == o.fIsPointerDeref; } - + public static IType getFieldOwnerType(IType fieldOwnerExpressionType, boolean isDeref, Collection<ICPPFunction> functionBindings, boolean returnDependent) { - IType type= fieldOwnerExpressionType; - if (!isDeref) - return type; - - // Bug 205964: as long as the type is a class type, recurse. - // Be defensive and allow a max of 20 levels. - for (int j = 0; j < 20; j++) { - IType classType= getUltimateTypeUptoPointers(type); - if (!(classType instanceof ICPPClassType)) - break; - - IScope scope = ((ICPPClassType) classType).getCompositeScope(); - if (scope == null || scope instanceof ICPPInternalUnknownScope) - break; - - /* - * 13.5.6-1: An expression x->m is interpreted as (x.operator->())->m for a - * class object x of type T - * - * Construct an AST fragment for x.operator-> which the lookup routines can - * examine for type information. - */ - - ICPPEvaluation[] args= { new EvalFixed(type, LVALUE, IntegralValue.UNKNOWN) }; - ICPPFunction op= CPPSemantics.findOverloadedOperator(null, args, classType, - OverloadableOperator.ARROW, LookupMode.NO_GLOBALS); + IType type = fieldOwnerExpressionType; + if (!isDeref) + return type; + + // Bug 205964: as long as the type is a class type, recurse. + // Be defensive and allow a max of 20 levels. + for (int j = 0; j < 20; j++) { + IType classType = getUltimateTypeUptoPointers(type); + if (!(classType instanceof ICPPClassType)) + break; + + IScope scope = ((ICPPClassType) classType).getCompositeScope(); + if (scope == null || scope instanceof ICPPInternalUnknownScope) + break; + + /* + * 13.5.6-1: An expression x->m is interpreted as (x.operator->())->m for a + * class object x of type T + * + * Construct an AST fragment for x.operator-> which the lookup routines can + * examine for type information. + */ + + ICPPEvaluation[] args = { new EvalFixed(type, LVALUE, IntegralValue.UNKNOWN) }; + ICPPFunction op = CPPSemantics.findOverloadedOperator(null, args, classType, OverloadableOperator.ARROW, + LookupMode.NO_GLOBALS); if (op == null) break; @@ -248,9 +246,9 @@ public class EvalMemberAccess extends CPPDependentEvaluation { if (CPPTemplates.isDependentType(type)) { return returnDependent - // The type resulting from dereferecing 'type' + // The type resulting from dereferecing 'type' ? new TypeOfDependentExpression(new EvalUnary(IASTUnaryExpression.op_star, - new EvalFixed(type, LVALUE, IntegralValue.UNKNOWN), null, + new EvalFixed(type, LVALUE, IntegralValue.UNKNOWN), null, CPPSemantics.getCurrentLookupPoint())) : null; } @@ -300,8 +298,7 @@ public class EvalMemberAccess extends CPPDependentEvaluation { fieldType = SemanticUtil.addQualifiers(fieldType, false, cvq1.isVolatile() || cvq2.isVolatile(), cvq2.isRestrict()); } else { - fieldType = SemanticUtil.addQualifiers(fieldType, cvq1.isConst(), cvq1.isVolatile(), - cvq2.isRestrict()); + fieldType = SemanticUtil.addQualifiers(fieldType, cvq1.isConst(), cvq1.isVolatile(), cvq2.isRestrict()); } return fieldType; } @@ -375,8 +372,7 @@ public class EvalMemberAccess extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) - throws CoreException { + public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { boolean isDeref = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; ValueCategory ownerValueCat; if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) { @@ -415,7 +411,6 @@ public class EvalMemberAccess extends CPPDependentEvaluation { getTemplateDefinition()); } - private boolean isMemberAccessThroughThisPointer() { if (fOwnerEval == null) { return true; @@ -460,8 +455,7 @@ public class EvalMemberAccess extends CPPDependentEvaluation { } } - EvalReference evalRef = new EvalReference(record, - new EvalCompositeAccess(evaluatedOwner, fieldPos), + EvalReference evalRef = new EvalReference(record, new EvalCompositeAccess(evaluatedOwner, fieldPos), getTemplateDefinition()); return evalRef; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java index d989d3f1a2e..f233936ac35 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalNaryTypeId.java @@ -32,28 +32,28 @@ import org.eclipse.core.runtime.CoreException; public class EvalNaryTypeId extends CPPDependentEvaluation { private final Operator fOperator; private final IType[] fOperands; - + private boolean fCheckedValueDependent; private boolean fIsValueDependent; - + public EvalNaryTypeId(Operator operator, IType[] operands, IASTNode pointOfDefinition) { this(operator, operands, findEnclosingTemplate(pointOfDefinition)); } - + public EvalNaryTypeId(Operator operator, IType[] operands, IBinding templateDefinition) { super(templateDefinition); fOperator = operator; fOperands = operands; } - + public Operator getOperator() { return fOperator; } - + public IType[] getOperands() { return fOperands; } - + @Override public boolean isInitializerList() { return false; @@ -93,10 +93,9 @@ public class EvalNaryTypeId extends CPPDependentEvaluation { return false; } EvalNaryTypeId o = (EvalNaryTypeId) other; - return fOperator == o.fOperator - && areEquivalentTypes(fOperands, o.fOperands); + return fOperator == o.fOperator && areEquivalentTypes(fOperands, o.fOperands); } - + @Override public IType getType() { switch (fOperator) { @@ -112,7 +111,7 @@ public class EvalNaryTypeId extends CPPDependentEvaluation { if (isValueDependent()) { return DependentValue.create(this); } - + return ValueFactory.evaluateNaryTypeIdExpression(fOperator, fOperands, getTemplateDefinition()); } @@ -131,8 +130,7 @@ public class EvalNaryTypeId extends CPPDependentEvaluation { } @Override - public ICPPEvaluation computeForFunctionCall(ActivationRecord record, - ConstexprEvaluationContext context) { + public ICPPEvaluation computeForFunctionCall(ActivationRecord record, ConstexprEvaluationContext context) { return this; } @@ -140,8 +138,7 @@ public class EvalNaryTypeId extends CPPDependentEvaluation { public int determinePackSize(ICPPTemplateParameterMap tpMap) { int result = 0; for (int i = 0; i < fOperands.length; i++) { - result = CPPTemplates.combinePackSize(result, - CPPTemplates.determinePackSize(fOperands[i], tpMap)); + result = CPPTemplates.combinePackSize(result, CPPTemplates.determinePackSize(fOperands[i], tpMap)); } return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java index 39cccd6bf24..323b6c78755 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPackExpansion.java @@ -80,15 +80,15 @@ public class EvalPackExpansion extends CPPDependentEvaluation { EvalPackExpansion o = (EvalPackExpansion) other; return fExpansionPattern.isEquivalentTo(o.fExpansionPattern); } - + @Override public IType getType() { if (fType == null) { IType type = fExpansionPattern.getType(); if (type == null) { - fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + fType = ProblemType.UNKNOWN_FOR_EXPRESSION; } else { - fType= new CPPParameterPackType(type); + fType = new CPPParameterPackType(type); } } return fType; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java index c627a1c7e3b..cc24f8ab9b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalPointer.java @@ -34,7 +34,8 @@ public final class EvalPointer extends EvalReference { this(record, referredSubValue, templateDefinition, referredSubValue.getElementId()); } - public EvalPointer(ActivationRecord record, EvalCompositeAccess referredSubValue, IBinding templateDefinition, int offset) { + public EvalPointer(ActivationRecord record, EvalCompositeAccess referredSubValue, IBinding templateDefinition, + int offset) { super(record, referredSubValue, templateDefinition); setPosition(offset); } @@ -46,10 +47,11 @@ public final class EvalPointer extends EvalReference { public EvalReference dereference() { if (referredSubValue != null) { - final EvalCompositeAccess pointedToValue = new EvalCompositeAccess(referredSubValue.getParent(), getPosition()); + final EvalCompositeAccess pointedToValue = new EvalCompositeAccess(referredSubValue.getParent(), + getPosition()); return new EvalReference(owningRecord, pointedToValue, getTemplateDefinition()); - } else { - return new EvalReference(owningRecord,referredBinding, getTemplateDefinition()); + } else { + return new EvalReference(owningRecord, referredBinding, getTemplateDefinition()); } } @@ -80,7 +82,8 @@ public final class EvalPointer extends EvalReference { } private boolean subValuePositionOutOfrange() { - return referredSubValue != null && (position - referredSubValue.getParent().getValue().numberOfSubValues() > 0 || position < 0); + return referredSubValue != null + && (position - referredSubValue.getParent().getValue().numberOfSubValues() > 0 || position < 0); } @Override @@ -98,16 +101,18 @@ public final class EvalPointer extends EvalReference { public EvalPointer copy() { if (referredSubValue != null) { return new EvalPointer(owningRecord, referredSubValue, getTemplateDefinition(), position); - } else { + } else { return new EvalPointer(owningRecord, referredBinding, getTemplateDefinition()); } } public static EvalPointer createFromAddress(EvalReference reference) { if (reference.referredSubValue != null) { - return new EvalPointer(reference.owningRecord, reference.referredSubValue, reference.getTemplateDefinition()); - } else { - return new EvalPointer(reference.owningRecord, reference.referredBinding, reference.getTemplateDefinition()); + return new EvalPointer(reference.owningRecord, reference.referredSubValue, + reference.getTemplateDefinition()); + } else { + return new EvalPointer(reference.owningRecord, reference.referredBinding, + reference.getTemplateDefinition()); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java index cf3e12a8625..44a5d3ebe46 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalReference.java @@ -40,7 +40,8 @@ public class EvalReference extends CPPDependentEvaluation { this(owningRecord, referredBinding, findEnclosingTemplate(point)); } - public EvalReference(ActivationRecord owningRecord, EvalCompositeAccess referredSubValue, IBinding templateDefinition) { + public EvalReference(ActivationRecord owningRecord, EvalCompositeAccess referredSubValue, + IBinding templateDefinition) { super(templateDefinition); this.owningRecord = owningRecord; this.referredSubValue = referredSubValue; @@ -50,11 +51,11 @@ public class EvalReference extends CPPDependentEvaluation { EvalReference(ActivationRecord owningRecord, EvalCompositeAccess referredSubValue, IASTNode point) { this(owningRecord, referredSubValue, findEnclosingTemplate(point)); } - + public ActivationRecord getOwningRecord() { return owningRecord; } - + public EvalCompositeAccess getReferredSubValue() { return referredSubValue; } @@ -90,7 +91,7 @@ public class EvalReference extends CPPDependentEvaluation { // only arises as an intermediate artifact during constexpr processing. return false; } - + @Override public IType getType() { return getTargetEvaluation().getType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index 153a6f29243..407172f8f77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -62,7 +62,7 @@ public class EvalTypeId extends CPPDependentEvaluation { private final IType fInputType; private final ICPPEvaluation[] fArguments; private final boolean fRepresentsNewExpression; - private boolean fUsesBracedInitList; // Whether the constructor call uses { ... } instead of (...). + private boolean fUsesBracedInitList; // Whether the constructor call uses { ... } instead of (...). private IType fOutputType; private ICPPFunction fConstructor = CPPFunction.UNINITIALIZED_FUNCTION; @@ -71,29 +71,27 @@ public class EvalTypeId extends CPPDependentEvaluation { private boolean fCheckedIsConstantExpression; private boolean fIsConstantExpression; - public EvalTypeId(IType type, IASTNode pointOfDefinition, boolean usesBracedInitList, - ICPPEvaluation... arguments) { + public EvalTypeId(IType type, IASTNode pointOfDefinition, boolean usesBracedInitList, ICPPEvaluation... arguments) { this(type, findEnclosingTemplate(pointOfDefinition), false, usesBracedInitList, arguments); } - public EvalTypeId(IType type, IBinding templateDefinition, boolean forNewExpression, - boolean usesBracedInitList, ICPPEvaluation... arguments) { + public EvalTypeId(IType type, IBinding templateDefinition, boolean forNewExpression, boolean usesBracedInitList, + ICPPEvaluation... arguments) { super(templateDefinition); if (arguments == null) throw new NullPointerException("arguments"); //$NON-NLS-1$ if (!CPPTemplates.isDependentType(type)) type = SemanticUtil.getNestedType(type, TDEF); - fInputType= type; - fArguments= arguments; + fInputType = type; + fArguments = arguments; fRepresentsNewExpression = forNewExpression; fUsesBracedInitList = usesBracedInitList; } - public static EvalTypeId createForNewExpression(IType type, IASTNode pointOfDefinition, - boolean usesBracedInitList, ICPPEvaluation... arguments) { - return new EvalTypeId(type, findEnclosingTemplate(pointOfDefinition), true, usesBracedInitList, - arguments); + public static EvalTypeId createForNewExpression(IType type, IASTNode pointOfDefinition, boolean usesBracedInitList, + ICPPEvaluation... arguments) { + return new EvalTypeId(type, findEnclosingTemplate(pointOfDefinition), true, usesBracedInitList, arguments); } public IType getInputType() { @@ -125,7 +123,7 @@ public class EvalTypeId extends CPPDependentEvaluation { @Override public IType getType() { if (fOutputType == null) { - fOutputType= computeType(); + fOutputType = computeType(); } return fOutputType; } @@ -156,12 +154,12 @@ public class EvalTypeId extends CPPDependentEvaluation { if (EvalUtil.isCompilerGeneratedCtor(ctor)) { return CompositeValue.create(classType); } else if (ctor == AGGREGATE_INITIALIZATION) { - return CompositeValue.create(new EvalInitList(fArguments, getTemplateDefinition()), - classType); + return CompositeValue.create(new EvalInitList(fArguments, getTemplateDefinition()), classType); } else if (ctor != null) { - EvalConstructor evalCtor = new EvalConstructor(classType, (ICPPConstructor) ctor, - fArguments, getTemplateDefinition()); - ICPPEvaluation computedEvalCtor = evalCtor.computeForFunctionCall(new ActivationRecord(), new ConstexprEvaluationContext()); + EvalConstructor evalCtor = new EvalConstructor(classType, (ICPPConstructor) ctor, fArguments, + getTemplateDefinition()); + ICPPEvaluation computedEvalCtor = evalCtor.computeForFunctionCall(new ActivationRecord(), + new ConstexprEvaluationContext()); return computedEvalCtor.getValue(); } else { return IntegralValue.ERROR; @@ -170,22 +168,22 @@ public class EvalTypeId extends CPPDependentEvaluation { if (fArguments.length == 0 || isEmptyInitializerList(fArguments)) { if (inputType instanceof ICPPBasicType) { switch (((ICPPBasicType) inputType).getKind()) { - case eInt: - case eInt128: - case eDouble: - case eBoolean: - case eFloat: - case eFloat128: - case eNullPtr: - case eChar: - case eChar16: - case eChar32: - case eWChar: - return IntegralValue.create(0l); - case eUnspecified: - case eVoid: - default: - return IntegralValue.UNKNOWN; + case eInt: + case eInt128: + case eDouble: + case eBoolean: + case eFloat: + case eFloat128: + case eNullPtr: + case eChar: + case eChar16: + case eChar32: + case eWChar: + return IntegralValue.create(0l); + case eUnspecified: + case eVoid: + default: + return IntegralValue.UNKNOWN; } } } @@ -196,7 +194,8 @@ public class EvalTypeId extends CPPDependentEvaluation { } private boolean isEmptyInitializerList(ICPPEvaluation[] arguments) { - return arguments.length == 1 && arguments[0] instanceof EvalInitList && ((EvalInitList) arguments[0]).getClauses().length == 0; + return arguments.length == 1 && arguments[0] instanceof EvalInitList + && ((EvalInitList) arguments[0]).getClauses().length == 0; } @Override @@ -229,8 +228,7 @@ public class EvalTypeId extends CPPDependentEvaluation { } private boolean computeIsConstantExpression() { - return !fRepresentsNewExpression - && areAllConstantExpressions(fArguments) + return !fRepresentsNewExpression && areAllConstantExpressions(fArguments) && isNullOrConstexprFunc(getConstructor()); } @@ -240,12 +238,11 @@ public class EvalTypeId extends CPPDependentEvaluation { return false; } EvalTypeId o = (EvalTypeId) other; - return fInputType.isSameType(o.fInputType) - && areEquivalentEvaluations(fArguments, o.fArguments) - && fRepresentsNewExpression == o.fRepresentsNewExpression - && fUsesBracedInitList == o.fUsesBracedInitList; + return fInputType.isSameType(o.fInputType) && areEquivalentEvaluations(fArguments, o.fArguments) + && fRepresentsNewExpression == o.fRepresentsNewExpression + && fUsesBracedInitList == o.fUsesBracedInitList; } - + @Override public ValueCategory getValueCategory() { return valueCategoryFromReturnType(fInputType); @@ -294,8 +291,7 @@ public class EvalTypeId extends CPPDependentEvaluation { } } - LookupData data = new LookupData(classType.getNameCharArray(), null, - CPPSemantics.getCurrentLookupPoint()); + LookupData data = new LookupData(classType.getNameCharArray(), null, CPPSemantics.getCurrentLookupPoint()); data.foundItems = constructors; data.setFunctionArguments(false, arguments); try { @@ -339,8 +335,7 @@ public class EvalTypeId extends CPPDependentEvaluation { IType type = parameterTypes[0]; if (type instanceof ICPPSpecialization) { IBinding specialized = ((ICPPSpecialization) type).getSpecializedBinding(); - if (specialized instanceof ICPPClassTemplate - && template.isSameType((IType) specialized)) { + if (specialized instanceof ICPPClassTemplate && template.isSameType((IType) specialized)) { result = ArrayUtil.append(result, ctor); } } @@ -367,32 +362,30 @@ public class EvalTypeId extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) - throws CoreException { - IType type= buffer.unmarshalType(); - ICPPEvaluation[] args= null; - int len= buffer.getInt(); + public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + IType type = buffer.unmarshalType(); + ICPPEvaluation[] args = null; + int len = buffer.getInt(); args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { - args[i]= buffer.unmarshalEvaluation(); + args[i] = buffer.unmarshalEvaluation(); } - IBinding templateDefinition= buffer.unmarshalBinding(); + IBinding templateDefinition = buffer.unmarshalBinding(); boolean forNewExpression = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; boolean usesBracedInitList = (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; - EvalTypeId result = new EvalTypeId(type, templateDefinition, forNewExpression, usesBracedInitList, - args); + EvalTypeId result = new EvalTypeId(type, templateDefinition, forNewExpression, usesBracedInitList, args); return result; } @Override public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) { - ICPPEvaluation[] args= instantiateCommaSeparatedSubexpressions(fArguments, context, maxDepth); + ICPPEvaluation[] args = instantiateCommaSeparatedSubexpressions(fArguments, context, maxDepth); IType type = CPPTemplates.instantiateType(fInputType, context); if (args == fArguments && type == fInputType) return this; - EvalTypeId result = new EvalTypeId(type, getTemplateDefinition(), fRepresentsNewExpression, - fUsesBracedInitList, args); + EvalTypeId result = new EvalTypeId(type, getTemplateDefinition(), fRepresentsNewExpression, fUsesBracedInitList, + args); if (!result.isTypeDependent()) { IType simplifiedType = SemanticUtil.getNestedType(type, SemanticUtil.TDEF); @@ -410,12 +403,11 @@ public class EvalTypeId extends CPPDependentEvaluation { } @Override - public ICPPEvaluation computeForFunctionCall(ActivationRecord record, - ConstexprEvaluationContext context) { + public ICPPEvaluation computeForFunctionCall(ActivationRecord record, ConstexprEvaluationContext context) { ICPPFunction constructor = getConstructor(); if (constructor != null && constructor instanceof ICPPConstructor) { - return new EvalConstructor(fInputType, (ICPPConstructor) constructor, fArguments, - getTemplateDefinition()).computeForFunctionCall(record, context); + return new EvalConstructor(fInputType, (ICPPConstructor) constructor, fArguments, getTemplateDefinition()) + .computeForFunctionCall(record, context); } ICPPEvaluation[] args = fArguments; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index c0d75bbe097..3d281195b7f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -79,17 +79,17 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.Pair; import org.eclipse.core.runtime.CoreException; public class EvalUnary extends CPPDependentEvaluation { - private static final ICPPEvaluation ZERO_EVAL = new EvalFixed(CPPSemantics.INT_TYPE, PRVALUE, IntegralValue.create(0)); + private static final ICPPEvaluation ZERO_EVAL = new EvalFixed(CPPSemantics.INT_TYPE, PRVALUE, + IntegralValue.create(0)); private final int fOperator; private final ICPPEvaluation fArgument; private final IBinding fAddressOfQualifiedNameBinding; - private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION; + private ICPPFunction fOverload = CPPFunction.UNINITIALIZED_FUNCTION; private IType fType; private boolean fCheckedIsConstantExpression; private boolean fIsConstantExpression; - public EvalUnary(int operator, ICPPEvaluation operand, IBinding addressOfQualifiedNameBinding, IASTNode pointOfDefinition) { this(operator, operand, addressOfQualifiedNameBinding, findEnclosingTemplate(pointOfDefinition)); @@ -98,9 +98,9 @@ public class EvalUnary extends CPPDependentEvaluation { public EvalUnary(int operator, ICPPEvaluation operand, IBinding addressOfQualifiedNameBinding, IBinding templateDefinition) { super(templateDefinition); - fOperator= operator; - fArgument= operand; - fAddressOfQualifiedNameBinding= addressOfQualifiedNameBinding; + fOperator = operator; + fArgument = operand; + fAddressOfQualifiedNameBinding = addressOfQualifiedNameBinding; } public int getOperator() { @@ -170,8 +170,7 @@ public class EvalUnary extends CPPDependentEvaluation { } private boolean computeIsConstantExpression() { - return fArgument.isConstantExpression() - && isNullOrConstexprFunc(getOverload()); + return fArgument.isConstantExpression() && isNullOrConstexprFunc(getOverload()); } @Override @@ -180,19 +179,18 @@ public class EvalUnary extends CPPDependentEvaluation { return false; } EvalUnary o = (EvalUnary) other; - return fOperator == o.fOperator - && fArgument.isEquivalentTo(o.fArgument); + return fOperator == o.fOperator && fArgument.isEquivalentTo(o.fArgument); } - + public ICPPFunction getOverload() { if (fOverload == CPPFunction.UNINITIALIZED_FUNCTION) { - fOverload= computeOverload(); + fOverload = computeOverload(); } return fOverload; } private ICPPFunction computeOverload() { - OverloadableOperator op = OverloadableOperator.fromUnaryExpression(fOperator); + OverloadableOperator op = OverloadableOperator.fromUnaryExpression(fOperator); if (op == null) return null; @@ -200,30 +198,30 @@ public class EvalUnary extends CPPDependentEvaluation { return null; if (fAddressOfQualifiedNameBinding instanceof ICPPMember) { - ICPPMember member= (ICPPMember) fAddressOfQualifiedNameBinding; + ICPPMember member = (ICPPMember) fAddressOfQualifiedNameBinding; if (!member.isStatic()) return null; } - IType type = fArgument.getType(); + IType type = fArgument.getType(); type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); if (!CPPSemantics.isUserDefined(type)) return null; ICPPEvaluation[] args; - if (fOperator == op_postFixDecr || fOperator == op_postFixIncr) { - args = new ICPPEvaluation[] { fArgument, ZERO_EVAL }; - } else { - args = new ICPPEvaluation[] { fArgument }; - } - return CPPSemantics.findOverloadedOperator(getTemplateDefinitionScope(), args, type, - op, LookupMode.LIMITED_GLOBALS); + if (fOperator == op_postFixDecr || fOperator == op_postFixIncr) { + args = new ICPPEvaluation[] { fArgument, ZERO_EVAL }; + } else { + args = new ICPPEvaluation[] { fArgument }; + } + return CPPSemantics.findOverloadedOperator(getTemplateDefinitionScope(), args, type, op, + LookupMode.LIMITED_GLOBALS); } @Override public IType getType() { if (fType == null) - fType= computeType(); + fType = computeType(); return fType; } @@ -235,7 +233,7 @@ public class EvalUnary extends CPPDependentEvaluation { if (overload != null) return ExpressionTypes.typeFromFunctionCall(overload); - switch (fOperator) { + switch (fOperator) { case op_sizeof: case op_sizeofParameterPack: return CPPVisitor.get_SIZE_T(); @@ -245,11 +243,11 @@ public class EvalUnary extends CPPDependentEvaluation { return CPPSemantics.VOID_TYPE; case op_amper: if (fAddressOfQualifiedNameBinding instanceof ICPPMember) { - ICPPMember member= (ICPPMember) fAddressOfQualifiedNameBinding; + ICPPMember member = (ICPPMember) fAddressOfQualifiedNameBinding; if (!member.isStatic()) { try { - return new CPPPointerToMemberType(member.getType(), member.getClassOwner(), - false, false, false); + return new CPPPointerToMemberType(member.getType(), member.getClassOwner(), false, false, + false); } catch (DOMException e) { return e.getProblem(); } @@ -257,14 +255,14 @@ public class EvalUnary extends CPPDependentEvaluation { } return new CPPPointerType(fArgument.getType()); case op_star: - IType type= fArgument.getType(); + IType type = fArgument.getType(); type = prvalueTypeWithResolvedTypedefs(type); - if (type instanceof IPointerType) { - return glvalueType(((IPointerType) type).getType()); + if (type instanceof IPointerType) { + return glvalueType(((IPointerType) type).getType()); + } + if (type instanceof ISemanticProblem) { + return type; } - if (type instanceof ISemanticProblem) { - return type; - } return ProblemType.UNKNOWN_FOR_EXPRESSION; case op_noexcept: case op_not: @@ -282,7 +280,7 @@ public class EvalUnary extends CPPDependentEvaluation { } private IType promoteType(IType type, boolean allowPointer) { - final IType t1 = prvalueType(type); + final IType t1 = prvalueType(type); final IType t2 = SemanticUtil.getNestedType(t1, TDEF); if (allowPointer) { if (t2 instanceof CPPClosureType) { @@ -295,7 +293,7 @@ public class EvalUnary extends CPPDependentEvaluation { return t1; } } - final IType t3= CPPArithmeticConversion.promoteCppType(t2); + final IType t3 = CPPArithmeticConversion.promoteCppType(t2); if (t3 == null && !(t2 instanceof IBasicType)) return ProblemType.UNKNOWN_FOR_EXPRESSION; return (t3 == null || t3 == t2) ? t1 : t3; @@ -320,31 +318,29 @@ public class EvalUnary extends CPPDependentEvaluation { if (!overload.isConstexpr()) return IntegralValue.ERROR; ICPPEvaluation eval = new EvalBinding(overload, null, (IBinding) null); - arg = new EvalFunctionCall(new ICPPEvaluation[] {eval, arg}, null, (IBinding) null); + arg = new EvalFunctionCall(new ICPPEvaluation[] { eval, arg }, null, (IBinding) null); return arg.getValue(); } } switch (fOperator) { - case op_sizeof: { - SizeAndAlignment info = - SizeofCalculator.getSizeAndAlignment(fArgument.getType()); - return info == null ? IntegralValue.UNKNOWN : IntegralValue.create(info.size); - } - case op_alignOf: { - SizeAndAlignment info = - SizeofCalculator.getSizeAndAlignment(fArgument.getType()); - return info == null ? IntegralValue.UNKNOWN : IntegralValue.create(info.alignment); - } - case op_noexcept: - return IntegralValue.UNKNOWN; // TODO(sprigogin): Implement - case op_sizeofParameterPack: - IValue opVal = fArgument.getValue(); - return IntegralValue.create(opVal.numberOfSubValues()); - case op_typeid: - return IntegralValue.UNKNOWN; // TODO(sprigogin): Implement - case op_throw: - return IntegralValue.UNKNOWN; // TODO(sprigogin): Implement + case op_sizeof: { + SizeAndAlignment info = SizeofCalculator.getSizeAndAlignment(fArgument.getType()); + return info == null ? IntegralValue.UNKNOWN : IntegralValue.create(info.size); + } + case op_alignOf: { + SizeAndAlignment info = SizeofCalculator.getSizeAndAlignment(fArgument.getType()); + return info == null ? IntegralValue.UNKNOWN : IntegralValue.create(info.alignment); + } + case op_noexcept: + return IntegralValue.UNKNOWN; // TODO(sprigogin): Implement + case op_sizeofParameterPack: + IValue opVal = fArgument.getValue(); + return IntegralValue.create(opVal.numberOfSubValues()); + case op_typeid: + return IntegralValue.UNKNOWN; // TODO(sprigogin): Implement + case op_throw: + return IntegralValue.UNKNOWN; // TODO(sprigogin): Implement } IValue val = arg.getValue(); @@ -357,19 +353,19 @@ public class EvalUnary extends CPPDependentEvaluation { @Override public ValueCategory getValueCategory() { ICPPFunction overload = getOverload(); - if (overload != null) - return valueCategoryFromFunctionCall(overload); + if (overload != null) + return valueCategoryFromFunctionCall(overload); - switch (fOperator) { + switch (fOperator) { case op_typeid: - case op_star: - case op_prefixDecr: - case op_prefixIncr: + case op_star: + case op_prefixDecr: + case op_prefixIncr: return LVALUE; - default: + default: return PRVALUE; - } - } + } + } @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { @@ -380,12 +376,11 @@ public class EvalUnary extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) - throws CoreException { - int op= buffer.getByte(); - ICPPEvaluation arg= buffer.unmarshalEvaluation(); - IBinding binding= buffer.unmarshalBinding(); - IBinding templateDefinition= buffer.unmarshalBinding(); + public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + int op = buffer.getByte(); + ICPPEvaluation arg = buffer.unmarshalEvaluation(); + IBinding binding = buffer.unmarshalBinding(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalUnary(op, arg, binding, templateDefinition); } @@ -395,7 +390,7 @@ public class EvalUnary extends CPPDependentEvaluation { IBinding binding = fAddressOfQualifiedNameBinding; if (binding instanceof ICPPUnknownBinding) { try { - binding= CPPTemplates.resolveUnknown((ICPPUnknownBinding) binding, context); + binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) binding, context); } catch (DOMException e) { } } @@ -411,13 +406,13 @@ public class EvalUnary extends CPPDependentEvaluation { private ICPPEvaluation createOperatorOverloadEvaluation(ICPPFunction overload, ICPPEvaluation arg) { IBinding templateDefinition = getTemplateDefinition(); if (overload instanceof ICPPMethod) { - EvalMemberAccess opAccess = new EvalMemberAccess(arg.getType(), ValueCategory.LVALUE, overload, - arg, false, templateDefinition); - ICPPEvaluation[] args = new ICPPEvaluation[]{opAccess}; + EvalMemberAccess opAccess = new EvalMemberAccess(arg.getType(), ValueCategory.LVALUE, overload, arg, false, + templateDefinition); + ICPPEvaluation[] args = new ICPPEvaluation[] { opAccess }; return new EvalFunctionCall(args, arg, templateDefinition); } else { EvalBinding op = new EvalBinding(overload, overload.getType(), templateDefinition); - ICPPEvaluation[] args = new ICPPEvaluation[]{op, arg}; + ICPPEvaluation[] args = new ICPPEvaluation[] { op, arg }; return new EvalFunctionCall(args, null, templateDefinition); } } @@ -439,7 +434,8 @@ public class EvalUnary extends CPPDependentEvaluation { final ICPPEvaluation updateable = vp.getFirst(); final ICPPEvaluation fixed = vp.getSecond(); - ICPPEvaluation evalUnary = fixed == fArgument || fixed == EvalFixed.INCOMPLETE ? this : new EvalUnary(fOperator, fixed, fAddressOfQualifiedNameBinding, getTemplateDefinition()); + ICPPEvaluation evalUnary = fixed == fArgument || fixed == EvalFixed.INCOMPLETE ? this + : new EvalUnary(fOperator, fixed, fAddressOfQualifiedNameBinding, getTemplateDefinition()); if (fOperator == op_star) { if (fixed instanceof EvalPointer) { EvalPointer evalPointer = (EvalPointer) fixed; @@ -470,7 +466,8 @@ public class EvalUnary extends CPPDependentEvaluation { applyPointerArithmetics(evalPointer); return evalPointer; } else { - EvalFixed newValue = new EvalFixed(evalUnary.getType(), evalUnary.getValueCategory(), evalUnary.getValue()); + EvalFixed newValue = new EvalFixed(evalUnary.getType(), evalUnary.getValueCategory(), + evalUnary.getValue()); if (updateable instanceof EvalReference) { EvalReference evalRef = (EvalReference) updateable; evalRef.update(newValue); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java index b46c50c8204..bf8bb5ca297 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java @@ -70,8 +70,8 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { public EvalUnaryTypeID(int operator, IType type, IBinding templateDefinition) { super(templateDefinition); - fOperator= operator; - fOrigType= type; + fOperator = operator; + fOrigType = type; } public int getOperator() { @@ -145,14 +145,13 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { return false; } EvalUnaryTypeID o = (EvalUnaryTypeID) other; - return fOperator == o.fOperator - && fOrigType.isSameType(o.fOrigType); + return fOperator == o.fOperator && fOrigType.isSameType(o.fOrigType); } - + @Override public IType getType() { if (fType == null) - fType= computeType(); + fType = computeType(); return fType; } @@ -203,7 +202,7 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { @Override public ValueCategory getValueCategory() { return fOperator == op_typeid ? LVALUE : PRVALUE; - } + } @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { @@ -214,9 +213,9 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { } public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - int op= buffer.getByte(); - IType arg= buffer.unmarshalType(); - IBinding templateDefinition= buffer.unmarshalBinding(); + int op = buffer.getByte(); + IType arg = buffer.unmarshalType(); + IBinding templateDefinition = buffer.unmarshalBinding(); return new EvalUnaryTypeID(op, arg, templateDefinition); } @@ -242,14 +241,14 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { public boolean referencesTemplateParameter() { return CPPTemplates.isDependentType(fOrigType); } - + private ICPPEvaluation instantiateBySubstitution(InstantiationContext context) { IType type = CPPTemplates.instantiateType(fOrigType, context); if (type == fOrigType) return this; return new EvalUnaryTypeID(fOperator, type, getTemplateDefinition()); } - + private ICPPEvaluation instantiateSizeofParameterPack(InstantiationContext context) { if (fOrigType instanceof ICPPTemplateParameter) { ICPPTemplateParameter pack = (ICPPTemplateParameter) fOrigType; @@ -268,14 +267,14 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { } } if (havePackExpansion) { - // TODO(bug 530103): + // TODO(bug 530103): // This will only handle correctly the case where there is a single argument // which is a pack expansion, and no concrete arguments. // To correctly handle cases with multiple pack expansions, or a mixture // of concrete arguments and pack expansions, we need to do the following: // - For each pack expansion, find the parameter pack P which it's // expanding (if it's expanding multiple parameter packs, any one - // should be sufficient), and construct an EvalUnaryTypeId representing + // should be sufficient), and construct an EvalUnaryTypeId representing // sizeof...(P). // - Construct an EvalBinary tree representing the sum of |concreteArgCount| // and the EvalUnaryTypeIds from the previous step. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java index 36963efb4fe..3c18ebdc69d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUtil.java @@ -53,7 +53,8 @@ public class EvalUtil { public static IValue getConditionDeclValue(ExecSimpleDeclaration conditionDeclExec, ActivationRecord record, ConstexprEvaluationContext context) { - ICPPBinding declaredBinding = ((ExecDeclarator) conditionDeclExec.getDeclaratorExecutions()[0]).getDeclaredBinding(); + ICPPBinding declaredBinding = ((ExecDeclarator) conditionDeclExec.getDeclaratorExecutions()[0]) + .getDeclaredBinding(); conditionDeclExec.executeForFunctionCall(record, context.recordStep()); return record.getVariable(declaredBinding).computeForFunctionCall(record, context).getValue(); } @@ -81,23 +82,18 @@ public class EvalUtil { // A return value != null means that there was a return, break or continue in that statement. public static ICPPExecution executeStatement(ICPPExecution exec, ActivationRecord record, ConstexprEvaluationContext context) { - if (exec instanceof ExecExpressionStatement - || exec instanceof ExecDeclarationStatement - || exec instanceof ExecCase - || exec instanceof ExecDefault) { + if (exec instanceof ExecExpressionStatement || exec instanceof ExecDeclarationStatement + || exec instanceof ExecCase || exec instanceof ExecDefault) { exec.executeForFunctionCall(record, context.recordStep()); return null; } - if (exec instanceof ExecCompoundStatement - || exec instanceof ExecWhile - || exec instanceof ExecFor - || exec instanceof ExecRangeBasedFor - || exec instanceof ExecDo - || exec instanceof ExecIf + if (exec instanceof ExecCompoundStatement || exec instanceof ExecWhile || exec instanceof ExecFor + || exec instanceof ExecRangeBasedFor || exec instanceof ExecDo || exec instanceof ExecIf || exec instanceof ExecSwitch) { ICPPExecution innerResult = exec.executeForFunctionCall(record, context.recordStep()); - if (innerResult instanceof ExecReturn || innerResult instanceof ExecBreak || innerResult instanceof ExecContinue) { + if (innerResult instanceof ExecReturn || innerResult instanceof ExecBreak + || innerResult instanceof ExecContinue) { return innerResult; } else if (innerResult != null) { return ExecIncomplete.INSTANCE; @@ -109,8 +105,8 @@ public class EvalUtil { } private static boolean isUpdateable(ICPPEvaluation eval) { - return eval instanceof EvalBinding || (eval instanceof EvalReference && !(eval instanceof EvalPointer)) || - eval instanceof EvalCompositeAccess; + return eval instanceof EvalBinding || (eval instanceof EvalReference && !(eval instanceof EvalPointer)) + || eval instanceof EvalCompositeAccess; } /** @@ -146,8 +142,13 @@ public class EvalUtil { this.second = second; } - public T1 getFirst() { return first; } - public T2 getSecond() { return second; } + public T1 getFirst() { + return first; + } + + public T2 getSecond() { + return second; + } } public static boolean isCompilerGeneratedCtor(IBinding ctor) { @@ -173,14 +174,14 @@ public class EvalUtil { IValue initialValue = variable.getInitialValue(); ICPPEvaluation valueEval = null; - if ((initialValue != null && initialValue.getEvaluation() != null) || - (initialValue == null && nestedType instanceof ICPPClassType)) { + if ((initialValue != null && initialValue.getEvaluation() != null) + || (initialValue == null && nestedType instanceof ICPPClassType)) { final ICPPEvaluation initializerEval = initialValue == null ? null : initialValue.getEvaluation(); if (initializerEval == EvalFixed.INCOMPLETE) { return null; } ExecDeclarator declaratorExec = new ExecDeclarator(variable, initializerEval); - + ConstexprEvaluationContext context = new ConstexprEvaluationContext(); if (declaratorExec.executeForFunctionCall(record, context) != ExecIncomplete.INSTANCE) { valueEval = record.getVariable(declaratorExec.getDeclaredBinding()); @@ -189,8 +190,8 @@ public class EvalUtil { valueEval = new EvalFixed(type, ValueCategory.LVALUE, initialValue); } - if (valueEval != null && (valueEval == EvalFixed.INCOMPLETE || - valueEval.getValue() == IntegralValue.UNKNOWN)) { + if (valueEval != null + && (valueEval == EvalFixed.INCOMPLETE || valueEval.getValue() == IntegralValue.UNKNOWN)) { return null; } return valueEval; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecConstructorChain.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecConstructorChain.java index 9f5e27fd46a..89cbac99be1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecConstructorChain.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecConstructorChain.java @@ -34,8 +34,7 @@ public class ExecConstructorChain implements ICPPExecution { public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { Map<IBinding, ICPPEvaluation> instantiatedInitializers = new HashMap<>(); for (Entry<IBinding, ICPPEvaluation> initializer : ccInitializers.entrySet()) { - instantiatedInitializers.put( - CPPEvaluation.instantiateBinding(initializer.getKey(), context, maxDepth), + instantiatedInitializers.put(CPPEvaluation.instantiateBinding(initializer.getKey(), context, maxDepth), initializer.getValue().instantiate(context, maxDepth)); } return new ExecConstructorChain(instantiatedInitializers); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java index 15d5a140237..eb7a10a2ee8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecDeclarator.java @@ -75,7 +75,7 @@ public final class ExecDeclarator implements ICPPExecution { ICPPEvaluation[] clauses = initList.getClauses(); if (clauses.length != 1) return eval; - + // Never unwrap initializers for array types. if (targetType instanceof IArrayType) return eval; @@ -86,20 +86,18 @@ public final class ExecDeclarator implements ICPPExecution { ICPPEvaluation clause = clauses[0]; if (targetType instanceof ICPPClassType && !clause.getType().isSameType(targetType)) return eval; - + // Otherwise unwrap. return clause; } - - private ICPPEvaluation createInitialValue(IType type, ActivationRecord record, - ConstexprEvaluationContext context) { + + private ICPPEvaluation createInitialValue(IType type, ActivationRecord record, ConstexprEvaluationContext context) { if (initializerEval == null) return createDefaultInitializedCompositeValue(type); IType nestedType = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE); - ICPPEvaluation computedInitializerEval = - initializerEval.computeForFunctionCall(record, context.recordStep()); + ICPPEvaluation computedInitializerEval = initializerEval.computeForFunctionCall(record, context.recordStep()); // In some contexts, unwrap 1-element initializer lists. computedInitializerEval = maybeUnwrapInitList(computedInitializerEval, nestedType); @@ -112,8 +110,7 @@ public final class ExecDeclarator implements ICPPExecution { if (nestedType instanceof IArrayType && !isCStringType(nestedType)) { if (computedInitializerEval instanceof EvalInitList) { - IValue value = CompositeValue.create((EvalInitList) computedInitializerEval, - (IArrayType) nestedType); + IValue value = CompositeValue.create((EvalInitList) computedInitializerEval, (IArrayType) nestedType); return new EvalFixed(type, computedInitializerEval.getValueCategory(), value); } // TODO(sprigogin): Should something else be done here? @@ -121,14 +118,12 @@ public final class ExecDeclarator implements ICPPExecution { } if (isValueInitialization(computedInitializerEval)) { - ICPPEvaluation defaultValue = - new EvalTypeId(type, computedInitializerEval.getTemplateDefinition(), false, false, - ICPPEvaluation.EMPTY_ARRAY); + ICPPEvaluation defaultValue = new EvalTypeId(type, computedInitializerEval.getTemplateDefinition(), false, + false, ICPPEvaluation.EMPTY_ARRAY); return new EvalFixed(type, defaultValue.getValueCategory(), defaultValue.getValue()); } - return new EvalFixed(type, computedInitializerEval.getValueCategory(), - computedInitializerEval.getValue()); + return new EvalFixed(type, computedInitializerEval.getValueCategory(), computedInitializerEval.getValue()); } private static ICPPEvaluation createDefaultInitializedCompositeValue(IType type) { @@ -157,7 +152,7 @@ public final class ExecDeclarator implements ICPPExecution { return createReferenceFromBinding(record, templateDefinition, (EvalBinding) initValue); if (initValue instanceof EvalBinary && computedInitializerEval instanceof EvalCompositeAccess) - return createReferenceFromCompositeAccess(record, templateDefinition, + return createReferenceFromCompositeAccess(record, templateDefinition, (EvalCompositeAccess) computedInitializerEval); return EvalFixed.INCOMPLETE; @@ -190,8 +185,8 @@ public final class ExecDeclarator implements ICPPExecution { return eval.getType() instanceof IArrayType; } - private static ICPPEvaluation createReferenceFromBinding(ActivationRecord record, - IBinding templateDefinition, EvalBinding evalBinding) { + private static ICPPEvaluation createReferenceFromBinding(ActivationRecord record, IBinding templateDefinition, + EvalBinding evalBinding) { return new EvalReference(record, evalBinding.getBinding(), templateDefinition); } @@ -200,8 +195,8 @@ public final class ExecDeclarator implements ICPPExecution { return new EvalReference(record, evalCompAccess, templateDefinition); } - private static ICPPEvaluation createPointerFromCompositeAccess(ActivationRecord record, - IBinding templateDefinition, EvalCompositeAccess evalCompAccess) { + private static ICPPEvaluation createPointerFromCompositeAccess(ActivationRecord record, IBinding templateDefinition, + EvalCompositeAccess evalCompAccess) { return new EvalPointer(record, evalCompAccess, templateDefinition); } @@ -230,8 +225,7 @@ public final class ExecDeclarator implements ICPPExecution { } else { ICPPSpecialization owner = context.getContextSpecialization(); if (owner instanceof ICPPClassSpecialization) { - newDeclaredBinding = (ICPPBinding) - ((ICPPClassSpecialization) owner).specializeMember(declaredBinding); + newDeclaredBinding = (ICPPBinding) ((ICPPClassSpecialization) owner).specializeMember(declaredBinding); } else { // TODO: Non-class owners should also have a specializeMember() function which // implements a caching mechanism. @@ -239,8 +233,8 @@ public final class ExecDeclarator implements ICPPExecution { } } - ICPPEvaluation newInitializerEval = - initializerEval == null ? null : initializerEval.instantiate(context, maxDepth); + ICPPEvaluation newInitializerEval = initializerEval == null ? null + : initializerEval.instantiate(context, maxDepth); return new ExecDeclarator(newDeclaredBinding, newInitializerEval); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecFor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecFor.java index d086c04b69b..033be213e39 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecFor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecFor.java @@ -25,7 +25,8 @@ public class ExecFor implements ICPPExecution { private final ICPPEvaluation iterationEval; private final ICPPExecution bodyExec; - public ExecFor(ICPPExecution initializerExec, ICPPEvaluation conditionExprEval, ExecSimpleDeclaration conditionDeclExec, ICPPEvaluation iterationEval, ICPPExecution bodyExec) { + public ExecFor(ICPPExecution initializerExec, ICPPEvaluation conditionExprEval, + ExecSimpleDeclaration conditionDeclExec, ICPPEvaluation iterationEval, ICPPExecution bodyExec) { this.initializerExec = initializerExec; this.conditionExprEval = conditionExprEval; this.conditionDeclExec = conditionDeclExec; @@ -35,7 +36,8 @@ public class ExecFor implements ICPPExecution { @Override public ICPPExecution executeForFunctionCall(ActivationRecord record, ConstexprEvaluationContext context) { - for (evaluateInitializationStatement(record, context); conditionSatisfied(record, context); evaluateIterationExpression(record, context)) { + for (evaluateInitializationStatement(record, context); conditionSatisfied(record, + context); evaluateIterationExpression(record, context)) { if (context.getStepsPerformed() >= ConstexprEvaluationContext.MAX_CONSTEXPR_EVALUATION_STEPS) { return ExecIncomplete.INSTANCE; } @@ -75,19 +77,23 @@ public class ExecFor implements ICPPExecution { @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { - ICPPExecution newInitializerExec = initializerExec != null ? initializerExec.instantiate(context, maxDepth) : null; - ICPPEvaluation newConditionExprEval = conditionExprEval != null ? conditionExprEval.instantiate(context, maxDepth) : null; - ExecSimpleDeclaration newConditionDeclExec = conditionDeclExec != null ? (ExecSimpleDeclaration) conditionDeclExec.instantiate(context, maxDepth) : null; + ICPPExecution newInitializerExec = initializerExec != null ? initializerExec.instantiate(context, maxDepth) + : null; + ICPPEvaluation newConditionExprEval = conditionExprEval != null + ? conditionExprEval.instantiate(context, maxDepth) + : null; + ExecSimpleDeclaration newConditionDeclExec = conditionDeclExec != null + ? (ExecSimpleDeclaration) conditionDeclExec.instantiate(context, maxDepth) + : null; ICPPEvaluation newIterationEval = iterationEval != null ? iterationEval.instantiate(context, maxDepth) : null; ICPPExecution newBodyExec = bodyExec.instantiate(context, maxDepth); - if (newInitializerExec == initializerExec && - newConditionExprEval == conditionExprEval && - newConditionDeclExec == conditionDeclExec && - newIterationEval == iterationEval && - newBodyExec == bodyExec) { + if (newInitializerExec == initializerExec && newConditionExprEval == conditionExprEval + && newConditionDeclExec == conditionDeclExec && newIterationEval == iterationEval + && newBodyExec == bodyExec) { return this; } - return new ExecFor(newInitializerExec, newConditionExprEval, newConditionDeclExec, newIterationEval, newBodyExec); + return new ExecFor(newInitializerExec, newConditionExprEval, newConditionDeclExec, newIterationEval, + newBodyExec); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIf.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIf.java index 6db11e7fd16..41d39c15f48 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIf.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIf.java @@ -26,7 +26,8 @@ public class ExecIf implements ICPPExecution { private final ICPPExecution thenClauseExec; private final ICPPExecution elseClauseExec; - public ExecIf(boolean isConstexpr, ICPPExecution initStmtExec, ICPPEvaluation conditionExprEval, ExecSimpleDeclaration conditionDeclExec, ICPPExecution thenClauseExec, ICPPExecution elseClauseExec) { + public ExecIf(boolean isConstexpr, ICPPExecution initStmtExec, ICPPEvaluation conditionExprEval, + ExecSimpleDeclaration conditionDeclExec, ICPPExecution thenClauseExec, ICPPExecution elseClauseExec) { this.isConstexpr = isConstexpr; this.initStmtExec = initStmtExec; this.conditionExprEval = conditionExprEval; @@ -58,8 +59,12 @@ public class ExecIf implements ICPPExecution { @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { ICPPExecution newInitStmtExec = initStmtExec != null ? initStmtExec.instantiate(context, maxDepth) : null; - ICPPEvaluation newConditionExprEval = conditionExprEval != null ? conditionExprEval.instantiate(context, maxDepth) : null; - ExecSimpleDeclaration newConditionDeclExec = conditionDeclExec != null ? (ExecSimpleDeclaration) conditionDeclExec.instantiate(context, maxDepth) : null; + ICPPEvaluation newConditionExprEval = conditionExprEval != null + ? conditionExprEval.instantiate(context, maxDepth) + : null; + ExecSimpleDeclaration newConditionDeclExec = conditionDeclExec != null + ? (ExecSimpleDeclaration) conditionDeclExec.instantiate(context, maxDepth) + : null; ICPPExecution newThenClauseExec = null; ICPPExecution newElseClauseExec = null; @@ -68,7 +73,7 @@ public class ExecIf implements ICPPExecution { if (newConditionExprEval.getValue().numberValue().intValue() != 0) { /* * We can't just "return newThenClauseExec" here, because the condition - * might have side effects so it needs to be preserved in the instantiated + * might have side effects so it needs to be preserved in the instantiated * execution even if one of its branch has become null */ newThenClauseExec = thenClauseExec.instantiate(context, maxDepth); @@ -80,11 +85,13 @@ public class ExecIf implements ICPPExecution { newElseClauseExec = elseClauseExec != null ? elseClauseExec.instantiate(context, maxDepth) : null; } - if (newInitStmtExec == initStmtExec && newConditionExprEval == conditionExprEval && newConditionDeclExec == conditionDeclExec - && newThenClauseExec == thenClauseExec && newElseClauseExec == elseClauseExec) { + if (newInitStmtExec == initStmtExec && newConditionExprEval == conditionExprEval + && newConditionDeclExec == conditionDeclExec && newThenClauseExec == thenClauseExec + && newElseClauseExec == elseClauseExec) { return this; } - return new ExecIf(isConstexpr, newInitStmtExec, newConditionExprEval, newConditionDeclExec, newThenClauseExec, newElseClauseExec); + return new ExecIf(isConstexpr, newInitStmtExec, newConditionExprEval, newConditionDeclExec, newThenClauseExec, + newElseClauseExec); } @Override @@ -108,6 +115,7 @@ public class ExecIf implements ICPPExecution { ExecSimpleDeclaration conditionDeclExec = (ExecSimpleDeclaration) buffer.unmarshalExecution(); ICPPExecution thenClauseExec = buffer.unmarshalExecution(); ICPPExecution elseClauseExec = buffer.unmarshalExecution(); - return new ExecIf(isConstexpr, initStmtExec, conditionExprEval, conditionDeclExec, thenClauseExec, elseClauseExec); + return new ExecIf(isConstexpr, initStmtExec, conditionExprEval, conditionDeclExec, thenClauseExec, + elseClauseExec); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIncomplete.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIncomplete.java index 88631ccbecf..6ab1df368c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIncomplete.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecIncomplete.java @@ -20,7 +20,8 @@ import org.eclipse.core.runtime.CoreException; public class ExecIncomplete implements ICPPExecution { public static ExecIncomplete INSTANCE = new ExecIncomplete(); - private ExecIncomplete() {} + private ExecIncomplete() { + } @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecRangeBasedFor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecRangeBasedFor.java index 48ca9b8f09f..9ca8c447790 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecRangeBasedFor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecRangeBasedFor.java @@ -43,7 +43,8 @@ public class ExecRangeBasedFor implements ICPPExecution { private final ICPPFunction end; private final ICPPExecution bodyExec; - public ExecRangeBasedFor(ExecSimpleDeclaration declarationExec, ICPPEvaluation initClauseEval, ICPPFunction begin, ICPPFunction end, ICPPExecution bodyExec) { + public ExecRangeBasedFor(ExecSimpleDeclaration declarationExec, ICPPEvaluation initClauseEval, ICPPFunction begin, + ICPPFunction end, ICPPExecution bodyExec) { this.declarationExec = declarationExec; this.initClauseEval = initClauseEval; this.begin = begin; @@ -51,12 +52,14 @@ public class ExecRangeBasedFor implements ICPPExecution { this.bodyExec = bodyExec; } - private ICPPExecution loopOverArray(IVariable rangeVar, ICPPEvaluation valueRange, ActivationRecord record, ConstexprEvaluationContext context) { + private ICPPExecution loopOverArray(IVariable rangeVar, ICPPEvaluation valueRange, ActivationRecord record, + ConstexprEvaluationContext context) { ICPPEvaluation[] range = valueRange.getValue().getAllSubValues(); for (int i = 0; i < range.length; i++) { ICPPEvaluation value = new EvalFixed(range[i].getType(), range[i].getValueCategory(), range[i].getValue()); if (rangeVar.getType() instanceof ICPPReferenceType) { - value = new EvalReference(record, new EvalCompositeAccess(valueRange, i), value.getTemplateDefinition()); + value = new EvalReference(record, new EvalCompositeAccess(valueRange, i), + value.getTemplateDefinition()); } record.update(rangeVar, value); @@ -72,12 +75,13 @@ public class ExecRangeBasedFor implements ICPPExecution { return null; } - private ICPPExecution loopOverObject(IVariable rangeVar, ICPPEvaluation rangeEval, boolean rangeIsConst, ICPPClassType classType, ActivationRecord record, ConstexprEvaluationContext context) { + private ICPPExecution loopOverObject(IVariable rangeVar, ICPPEvaluation rangeEval, boolean rangeIsConst, + ICPPClassType classType, ActivationRecord record, ConstexprEvaluationContext context) { if (begin != null && end != null) { ICPPEvaluation beginEval = callFunction(classType, begin, rangeEval, record, context); ICPPEvaluation endEval = callFunction(classType, end, rangeEval, record, context); boolean isRef = rangeVar.getType() instanceof ICPPReferenceType; - + for (; !isEqual(beginEval, endEval); beginEval = inc(record, beginEval, context)) { record.update(rangeVar, deref(beginEval, isRef, record, context)); @@ -96,14 +100,15 @@ public class ExecRangeBasedFor implements ICPPExecution { } private static boolean isEqual(ICPPEvaluation a, ICPPEvaluation b) { - Number result = new EvalBinary(IASTBinaryExpression.op_equals, a, b, a.getTemplateDefinition()).getValue().numberValue(); + Number result = new EvalBinary(IASTBinaryExpression.op_equals, a, b, a.getTemplateDefinition()).getValue() + .numberValue(); return result != null && result.longValue() != 0; } - private static ICPPEvaluation deref(ICPPEvaluation ptr, boolean isRef, ActivationRecord record, + private static ICPPEvaluation deref(ICPPEvaluation ptr, boolean isRef, ActivationRecord record, ConstexprEvaluationContext context) { - ICPPEvaluation derefEval = new EvalUnary(ICPPASTUnaryExpression.op_star, ptr, null, - ptr.getTemplateDefinition()).computeForFunctionCall(record, context); + ICPPEvaluation derefEval = new EvalUnary(ICPPASTUnaryExpression.op_star, ptr, null, ptr.getTemplateDefinition()) + .computeForFunctionCall(record, context); if (isRef) { return derefEval; } else { @@ -111,24 +116,23 @@ public class ExecRangeBasedFor implements ICPPExecution { } } - private static ICPPEvaluation inc(ActivationRecord record, ICPPEvaluation ptr, - ConstexprEvaluationContext context) { + private static ICPPEvaluation inc(ActivationRecord record, ICPPEvaluation ptr, ConstexprEvaluationContext context) { return new EvalUnary(IASTUnaryExpression.op_prefixIncr, ptr, null, ptr.getTemplateDefinition()) .computeForFunctionCall(record, context); } - private static ICPPEvaluation callFunction(ICPPClassType classType, ICPPFunction func, - ICPPEvaluation rangeEval, ActivationRecord record, ConstexprEvaluationContext context) { + private static ICPPEvaluation callFunction(ICPPClassType classType, ICPPFunction func, ICPPEvaluation rangeEval, + ActivationRecord record, ConstexprEvaluationContext context) { EvalFunctionCall call = null; IBinding templateDefinition = rangeEval.getTemplateDefinition(); if (func instanceof ICPPMethod) { - EvalMemberAccess memberAccess = new EvalMemberAccess(classType, ValueCategory.LVALUE, func, - rangeEval, false, templateDefinition); - ICPPEvaluation[] args = new ICPPEvaluation[]{ memberAccess }; + EvalMemberAccess memberAccess = new EvalMemberAccess(classType, ValueCategory.LVALUE, func, rangeEval, + false, templateDefinition); + ICPPEvaluation[] args = new ICPPEvaluation[] { memberAccess }; call = new EvalFunctionCall(args, rangeEval, templateDefinition); } else { EvalBinding op = new EvalBinding(func, func.getType(), templateDefinition); - ICPPEvaluation[] args = new ICPPEvaluation[]{ op, rangeEval}; + ICPPEvaluation[] args = new ICPPEvaluation[] { op, rangeEval }; call = new EvalFunctionCall(args, null, templateDefinition); } return call.computeForFunctionCall(record, context); @@ -160,7 +164,8 @@ public class ExecRangeBasedFor implements ICPPExecution { @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { - ExecSimpleDeclaration newDeclarationExec = (ExecSimpleDeclaration) declarationExec.instantiate(context, maxDepth); + ExecSimpleDeclaration newDeclarationExec = (ExecSimpleDeclaration) declarationExec.instantiate(context, + maxDepth); ICPPEvaluation newInitClauseEval = initClauseEval.instantiate(context, maxDepth); // TODO: This isn't the correct way to instantiate the 'begin' and 'end' functions, because // if the range type is dependent, ADL may find different functions to call after instantiation. @@ -185,11 +190,8 @@ public class ExecRangeBasedFor implements ICPPExecution { } ICPPExecution newBodyExec = bodyExec.instantiate(context, maxDepth); - if (newDeclarationExec == declarationExec && - newInitClauseEval == initClauseEval && - newBegin == begin && - newEnd == end && - newBodyExec == bodyExec) { + if (newDeclarationExec == declarationExec && newInitClauseEval == initClauseEval && newBegin == begin + && newEnd == end && newBodyExec == bodyExec) { return this; } return new ExecRangeBasedFor(newDeclarationExec, newInitClauseEval, newBegin, newEnd, newBodyExec); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecSwitch.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecSwitch.java index 7d8deeeddce..832e67244dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecSwitch.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecSwitch.java @@ -25,7 +25,8 @@ public class ExecSwitch implements ICPPExecution { private final ExecSimpleDeclaration controllerDeclExec; private final ICPPExecution[] bodyStmtExecutions; - public ExecSwitch(ICPPExecution initStmtExec, ICPPEvaluation controllerExprEval, ExecSimpleDeclaration controllerDeclExec, ICPPExecution[] bodyStmtExecutions) { + public ExecSwitch(ICPPExecution initStmtExec, ICPPEvaluation controllerExprEval, + ExecSimpleDeclaration controllerDeclExec, ICPPExecution[] bodyStmtExecutions) { this.initStmtExec = initStmtExec; this.controllerExprEval = controllerExprEval; this.controllerDeclExec = controllerDeclExec; @@ -64,8 +65,8 @@ public class ExecSwitch implements ICPPExecution { return bodyStmtExecutions.length; } - private boolean isSatisfiedCaseStatement(ICPPExecution stmtExec, IValue controllerValue, - ActivationRecord record, ConstexprEvaluationContext context) { + private boolean isSatisfiedCaseStatement(ICPPExecution stmtExec, IValue controllerValue, ActivationRecord record, + ConstexprEvaluationContext context) { if (stmtExec instanceof ExecCase) { ExecCase caseStmtExec = (ExecCase) stmtExec; caseStmtExec = (ExecCase) caseStmtExec.executeForFunctionCall(record, context); @@ -79,8 +80,12 @@ public class ExecSwitch implements ICPPExecution { @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { ICPPExecution newInitStmtExec = initStmtExec != null ? initStmtExec.instantiate(context, maxDepth) : null; - ICPPEvaluation newControllerExprEval = controllerExprEval != null ? controllerExprEval.instantiate(context, maxDepth) : null; - ExecSimpleDeclaration newControllerDeclExec = controllerDeclExec != null ? (ExecSimpleDeclaration) controllerDeclExec.instantiate(context, maxDepth) : null; + ICPPEvaluation newControllerExprEval = controllerExprEval != null + ? controllerExprEval.instantiate(context, maxDepth) + : null; + ExecSimpleDeclaration newControllerDeclExec = controllerDeclExec != null + ? (ExecSimpleDeclaration) controllerDeclExec.instantiate(context, maxDepth) + : null; ICPPExecution[] newBodyStmtExecutions = new ICPPExecution[bodyStmtExecutions.length]; boolean executionsDidChange = false; for (int i = 0; i < bodyStmtExecutions.length; i++) { @@ -92,7 +97,8 @@ public class ExecSwitch implements ICPPExecution { newBodyStmtExecutions[i] = newBodyStmtExec; } - if (newInitStmtExec == initStmtExec && newControllerExprEval == controllerExprEval && newControllerDeclExec == controllerDeclExec && !executionsDidChange) { + if (newInitStmtExec == initStmtExec && newControllerExprEval == controllerExprEval + && newControllerDeclExec == controllerDeclExec && !executionsDidChange) { return this; } return new ExecSwitch(newInitStmtExec, newControllerExprEval, newControllerDeclExec, newBodyStmtExecutions); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecWhile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecWhile.java index f34a70c0734..552361b4e80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecWhile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExecWhile.java @@ -23,7 +23,8 @@ public class ExecWhile implements ICPPExecution { private final ExecSimpleDeclaration conditionDeclExec; private final ICPPExecution bodyExec; - public ExecWhile(ICPPEvaluation conditionExprEval, ExecSimpleDeclaration conditionDeclExec, ICPPExecution bodyExec) { + public ExecWhile(ICPPEvaluation conditionExprEval, ExecSimpleDeclaration conditionDeclExec, + ICPPExecution bodyExec) { this.conditionExprEval = conditionExprEval; this.conditionDeclExec = conditionDeclExec; this.bodyExec = bodyExec; @@ -59,10 +60,15 @@ public class ExecWhile implements ICPPExecution { @Override public ICPPExecution instantiate(InstantiationContext context, int maxDepth) { - ICPPEvaluation newConditionExprEval = conditionExprEval != null ? conditionExprEval.instantiate(context, maxDepth) : null; - ExecSimpleDeclaration newConditionDeclExec = conditionDeclExec != null ? (ExecSimpleDeclaration) conditionDeclExec.instantiate(context, maxDepth) : null; + ICPPEvaluation newConditionExprEval = conditionExprEval != null + ? conditionExprEval.instantiate(context, maxDepth) + : null; + ExecSimpleDeclaration newConditionDeclExec = conditionDeclExec != null + ? (ExecSimpleDeclaration) conditionDeclExec.instantiate(context, maxDepth) + : null; ICPPExecution newBodyExec = bodyExec.instantiate(context, maxDepth); - if (newConditionExprEval == conditionExprEval && newConditionDeclExec == conditionDeclExec && newBodyExec == bodyExec) { + if (newConditionExprEval == conditionExprEval && newConditionDeclExec == conditionDeclExec + && newBodyExec == bodyExec) { return this; } return new ExecWhile(newConditionExprEval, newConditionDeclExec, newBodyExec); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java index 3120e141a63..4498ed7edb5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/ExpressionTypes.java @@ -52,9 +52,9 @@ public class ExpressionTypes { } public static ValueCategory valueCategoryFromReturnType(IType r) { - r= SemanticUtil.getNestedType(r, TDEF); + r = SemanticUtil.getNestedType(r, TDEF); if (r instanceof ICPPReferenceType) { - ICPPReferenceType refType= (ICPPReferenceType) r; + ICPPReferenceType refType = (ICPPReferenceType) r; if (!refType.isRValueReference()) { return ValueCategory.LVALUE; } @@ -67,9 +67,9 @@ public class ExpressionTypes { } public static IType typeFromFunctionCall(IType functionType) { - IType t= SemanticUtil.getNestedType(functionType, TDEF | REF | CVTYPE); + IType t = SemanticUtil.getNestedType(functionType, TDEF | REF | CVTYPE); if (t instanceof IPointerType) { - t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); + t = SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); } if (t instanceof IFunctionType) { t = typeFromReturnType(((IFunctionType) t).getReturnType()); @@ -84,7 +84,7 @@ public class ExpressionTypes { } public static IType typeFromReturnType(IType type) { - IType t= SemanticUtil.getNestedType(type, TDEF); + IType t = SemanticUtil.getNestedType(type, TDEF); if (t instanceof ICPPReferenceType) { return glvalueType(type); } @@ -131,8 +131,8 @@ public class ExpressionTypes { private static IType makeConst(IType type) { if (type instanceof ICQualifierType) { ICQualifierType qualifierType = ((ICQualifierType) type); - return new CQualifierType(qualifierType.getType(), - true, qualifierType.isVolatile(), qualifierType.isRestrict()); + return new CQualifierType(qualifierType.getType(), true, qualifierType.isVolatile(), + qualifierType.isRestrict()); } return new CQualifierType(type, true, false, false); } @@ -140,8 +140,8 @@ public class ExpressionTypes { private static IType makeVolatile(IType type) { if (type instanceof ICQualifierType) { ICQualifierType qualifierType = ((ICQualifierType) type); - return new CQualifierType(qualifierType.getType(), - qualifierType.isConst(), true, qualifierType.isRestrict()); + return new CQualifierType(qualifierType.getType(), qualifierType.isConst(), true, + qualifierType.isRestrict()); } return new CQualifierType(type, false, true, false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java index fd97f2c519a..a4833904dca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java @@ -48,15 +48,15 @@ class FunctionCost { private boolean fIsDirectCopyCtor; public FunctionCost(ICPPFunction fn, int paramCount) { - fFunction= fn; - fCosts= new Cost[paramCount]; - fValueCategories= new ValueCategory[paramCount]; + fFunction = fn; + fCosts = new Cost[paramCount]; + fValueCategories = new ValueCategory[paramCount]; } public FunctionCost(ICPPFunction fn, Cost cost) { - fFunction= fn; - fCosts= new Cost[] {cost}; - fValueCategories= null; // no udc will be performed + fFunction = fn; + fCosts = new Cost[] { cost }; + fValueCategories = null; // no udc will be performed } public int getLength() { @@ -68,8 +68,8 @@ class FunctionCost { } public void setCost(int idx, Cost cost, ValueCategory valueCat) { - fCosts[idx]= cost; - fValueCategories[idx]= valueCat; + fCosts[idx] = cost; + fValueCategories[idx] = valueCat; } public ICPPFunction getFunction() { @@ -97,7 +97,7 @@ class FunctionCost { public boolean performUDC() throws DOMException { for (int i = 0; i < fCosts.length; i++) { Cost cost = fCosts[i]; - Cost udcCost= null; + Cost udcCost = null; switch (cost.isDeferredUDC()) { case NONE: continue; @@ -106,7 +106,7 @@ class FunctionCost { (ICPPClassType) cost.target, false); break; case INIT_BY_CONVERSION: - IType uqSource= getNestedType(cost.source, TDEF | REF | CVTYPE); + IType uqSource = getNestedType(cost.source, TDEF | REF | CVTYPE); udcCost = Conversions.initializationByConversion(fValueCategories[i], cost.source, (ICPPClassType) uqSource, cost.target, false, allowsContextualBooleanConversion()); break; @@ -132,9 +132,9 @@ class FunctionCost { private boolean allowsContextualBooleanConversion() { char[] functionName = fFunction.getNameCharArray(); - return Arrays.equals(functionName, OverloadableOperator.AND.toCharArray()) || - Arrays.equals(functionName, OverloadableOperator.OR.toCharArray()) || - Arrays.equals(functionName, OverloadableOperator.NOT.toCharArray()); + return Arrays.equals(functionName, OverloadableOperator.AND.toCharArray()) + || Arrays.equals(functionName, OverloadableOperator.OR.toCharArray()) + || Arrays.equals(functionName, OverloadableOperator.NOT.toCharArray()); } /** @@ -149,10 +149,10 @@ class FunctionCost { // In order for this function to be better than the previous best, it must // have at least one parameter match that is better that the corresponding // match for the other function, and none that are worse. - int idx= getLength() - 1; - int idxOther= other.getLength() - 1; + int idx = getLength() - 1; + int idxOther = other.getLength() - 1; for (; idx >= 0 && idxOther >= 0; idx--, idxOther--) { - Cost cost= getCost(idx); + Cost cost = getCost(idx); if (!cost.converts()) { haveWorse = true; haveBetter = false; @@ -168,8 +168,8 @@ class FunctionCost { final ICPPFunction f2 = other.getFunction(); if (!haveWorse && !haveBetter) { // If they are both template functions, we can order them that way - ICPPFunctionTemplate asTemplate= asTemplate(f1); - ICPPFunctionTemplate otherAsTemplate= asTemplate(f2); + ICPPFunctionTemplate asTemplate = asTemplate(f1); + ICPPFunctionTemplate otherAsTemplate = asTemplate(f2); final boolean isTemplate = asTemplate != null; final boolean otherIsTemplate = otherAsTemplate != null; @@ -179,19 +179,19 @@ class FunctionCost { } else if (!isTemplate && otherIsTemplate) { haveBetter = true; } else if (isTemplate && otherIsTemplate) { - TypeSelection ts= SemanticUtil.isConversionOperator(f1) ? RETURN_TYPE : PARAMETERS; - int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts); + TypeSelection ts = SemanticUtil.isConversionOperator(f1) ? RETURN_TYPE : PARAMETERS; + int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts); if (order < 0) { - haveBetter= true; + haveBetter = true; } else if (order > 0) { - haveWorse= true; + haveWorse = true; } } } if (haveBetter == haveWorse) { // 7.3.3-15 Using declarations in classes can be overridden - int cmp= overridesUsingDeclaration(f1, f2); + int cmp = overridesUsingDeclaration(f1, f2); if (cmp != 0) return cmp; @@ -213,8 +213,8 @@ class FunctionCost { final ICPPMethod m1 = (ICPPMethod) f1; final ICPPMethod m2 = (ICPPMethod) f2; - ICPPClassType o1= m1.getClassOwner(); - ICPPClassType o2= m2.getClassOwner(); + ICPPClassType o1 = m1.getClassOwner(); + ICPPClassType o2 = m2.getClassOwner(); if (o1.isSameType(o2)) return 0; @@ -226,15 +226,15 @@ class FunctionCost { if (!parameterTypesMatch(ft1, ft2)) return 0; - int diff= SemanticUtil.calculateInheritanceDepth(o2, o1); + int diff = SemanticUtil.calculateInheritanceDepth(o2, o1); if (diff >= 0) return diff; return -SemanticUtil.calculateInheritanceDepth(o1, o2); } private boolean parameterTypesMatch(final ICPPFunctionType ft1, final ICPPFunctionType ft2) { - IType[] p1= ft1.getParameterTypes(); - IType[] p2= ft2.getParameterTypes(); + IType[] p1 = ft1.getParameterTypes(); + IType[] p2 = ft2.getParameterTypes(); if (p1.length != p2.length) { if (p1.length == 0) return p2.length == 1 && SemanticUtil.isVoidType(p2[0]); @@ -255,27 +255,27 @@ class FunctionCost { if (other == null) return false; - boolean haveWorse= false; - int idx= getLength() - 1; - int idxOther= other.getLength() - 1; + boolean haveWorse = false; + int idx = getLength() - 1; + int idxOther = other.getLength() - 1; for (; idx >= 0 && idxOther >= 0; idx--, idxOther--) { - Cost cost= getCost(idx); + Cost cost = getCost(idx); if (!cost.converts()) return true; - Cost otherCost= other.getCost(idxOther); + Cost otherCost = other.getCost(idxOther); int cmp; if (cost.isDeferredUDC() != DeferredUDC.NONE) { - cmp= cost.getRank().compareTo(otherCost.getRank()); + cmp = cost.getRank().compareTo(otherCost.getRank()); } else { - cmp= cost.compareTo(otherCost); + cmp = cost.compareTo(otherCost); } if (cmp < 0) return false; if (cmp > 0) - haveWorse= true; + haveWorse = true; } return haveWorse; @@ -283,7 +283,7 @@ class FunctionCost { private static ICPPFunctionTemplate asTemplate(IFunction function) { if (function instanceof ICPPSpecialization) { - IBinding original= ((ICPPSpecialization) function).getSpecializedBinding(); + IBinding original = ((ICPPSpecialization) function).getSpecializedBinding(); if (original instanceof ICPPFunctionTemplate) { return (ICPPFunctionTemplate) original; } @@ -292,7 +292,7 @@ class FunctionCost { } public void setIsDirectInitWithCopyCtor(boolean val) { - fIsDirectCopyCtor= val; + fIsDirectCopyCtor = val; } public boolean isDirectInitWithCopyCtor() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionSetType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionSetType.java index 48206e80b5e..e97d1e73852 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionSetType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionSetType.java @@ -31,8 +31,8 @@ public class FunctionSetType implements IType { private final boolean fPointerType; public FunctionSetType(CPPFunctionSet set, boolean addressOf) { - fFunctionSet= set; - fPointerType= addressOf; + fFunctionSet = set; + fPointerType = addressOf; } @Override @@ -52,7 +52,7 @@ public class FunctionSetType implements IType { public Cost costForTarget(IType paramType) { IBinding result = CPPSemantics.resolveTargetedFunction(paramType, fFunctionSet); if (result instanceof ICPPFunction && !(result instanceof IProblemBinding)) { - Cost c= new Cost(paramType, paramType, Rank.IDENTITY); + Cost c = new Cost(paramType, paramType, Rank.IDENTITY); c.setSelectedFunction((ICPPFunction) result); return c; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java index 222664a9074..a3f2f3e6e8e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java @@ -112,7 +112,8 @@ public class HeuristicResolver { */ public static IScope findConcreteScopeForType(IType type) { if (type instanceof ICPPUnknownType) { - type = resolveUnknownType((ICPPUnknownType) type, SemanticUtil.TDEF | SemanticUtil.REF | SemanticUtil.CVTYPE); + type = resolveUnknownType((ICPPUnknownType) type, + SemanticUtil.TDEF | SemanticUtil.REF | SemanticUtil.CVTYPE); } type = SemanticUtil.getNestedType(type, SemanticUtil.PTR); if (type instanceof ICompositeType) { @@ -139,12 +140,10 @@ public class HeuristicResolver { * An extension of CPPDeferredClassInstance that implements ICPPClassSpecialization, * allowing its members to be specialized via specializeMember(). */ - private static class CPPDependentClassInstance extends CPPDeferredClassInstance - implements ICPPClassSpecialization { + private static class CPPDependentClassInstance extends CPPDeferredClassInstance implements ICPPClassSpecialization { public CPPDependentClassInstance(ICPPDeferredClassInstance deferredInstance) { - super(chooseTemplateForDeferredInstance(deferredInstance), - deferredInstance.getTemplateArguments()); + super(chooseTemplateForDeferredInstance(deferredInstance), deferredInstance.getTemplateArguments()); } @Override @@ -209,7 +208,7 @@ public class HeuristicResolver { public ICPPClassType[] getNestedClasses(IASTNode point) { throw new UnsupportedOperationException(); } - + @Override public ICPPUsingDeclaration[] getUsingDeclarations(IASTNode point) { throw new UnsupportedOperationException(); @@ -236,8 +235,7 @@ public class HeuristicResolver { return false; } HeuristicLookup otherLookup = (HeuristicLookup) other; - return scope == otherLookup.scope - && CharArrayUtils.equals(name, otherLookup.name); + return scope == otherLookup.scope && CharArrayUtils.equals(name, otherLookup.name); } @Override @@ -287,8 +285,7 @@ public class HeuristicResolver { lookupType = specializationContext.getSpecializedBinding(); break; } else if (lookupType instanceof ICPPDeferredClassInstance) { - specializationContext = new CPPDependentClassInstance( - (ICPPDeferredClassInstance) lookupType); + specializationContext = new CPPDependentClassInstance((ICPPDeferredClassInstance) lookupType); lookupType = specializationContext.getSpecializedBinding(); break; } @@ -307,9 +304,8 @@ public class HeuristicResolver { resolvedType = null; } } - - resolvedType = SemanticUtil.getNestedType(resolvedType, - SemanticUtil.CVTYPE | SemanticUtil.TDEF); + + resolvedType = SemanticUtil.getNestedType(resolvedType, SemanticUtil.CVTYPE | SemanticUtil.TDEF); if (resolvedType == lookupType || !(resolvedType instanceof ICPPUnknownType)) { lookupType = resolvedType; @@ -402,15 +398,14 @@ public class HeuristicResolver { } /** - * Heuristically choose between the primary template and any partial specializations + * Heuristically choose between the primary template and any partial specializations * for a deferred template instance. */ private static ICPPClassTemplate chooseTemplateForDeferredInstance(ICPPDeferredClassInstance instance) { ICPPClassTemplate template = instance.getClassTemplate(); if (!instance.isExplicitSpecialization()) { try { - IBinding partial = CPPTemplates.selectSpecialization(template, - instance.getTemplateArguments(), false); + IBinding partial = CPPTemplates.selectSpecialization(template, instance.getTemplateArguments(), false); if (partial != null && partial instanceof ICPPTemplateInstance) return (ICPPClassTemplate) ((ICPPTemplateInstance) partial).getTemplateDefinition(); } catch (DOMException e) { @@ -496,8 +491,7 @@ public class HeuristicResolver { if (result instanceof ICPPClassTemplate) { result = (IType) CPPTemplates.instantiate((ICPPClassTemplate) result, args); } else if (result instanceof ICPPAliasTemplate) { - result = (IType) CPPTemplates.instantiateAliasTemplate((ICPPAliasTemplate) result, - args); + result = (IType) CPPTemplates.instantiateAliasTemplate((ICPPAliasTemplate) result, args); } } return result; @@ -518,8 +512,8 @@ public class HeuristicResolver { return new IBinding[] { chooseTemplateForDeferredInstance((ICPPDeferredClassInstance) binding) }; } else if (binding instanceof ICPPUnknownMember) { Set<HeuristicLookup> lookupSet = new HashSet<>(); - return lookInside(((ICPPUnknownMember) binding).getOwnerType(), false, - binding.getNameCharArray(), null, lookupSet); + return lookInside(((ICPPUnknownMember) binding).getOwnerType(), false, binding.getNameCharArray(), null, + lookupSet); } else if (binding instanceof ICPPUnknownType) { IType resolved = resolveUnknownType((ICPPUnknownType) binding); if (resolved != binding && resolved instanceof IBinding) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/InitializerListType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/InitializerListType.java index b16ff9eb59d..899b724597e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/InitializerListType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/InitializerListType.java @@ -25,7 +25,7 @@ public class InitializerListType implements IType, ISerializableType { private final EvalInitList fInitializerList; public InitializerListType(EvalInitList exprEvalInitList) { - fInitializerList= exprEvalInitList; + fInitializerList = exprEvalInitList; } public EvalInitList getEvaluation() { @@ -49,7 +49,7 @@ public class InitializerListType implements IType, ISerializableType { @Override public String toString() { - return "InitializerListType"; //$NON-NLS-1$ + return "InitializerListType"; //$NON-NLS-1$ } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java index 2ce69d6a559..218d34adee5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java @@ -86,10 +86,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; */ public class LookupData extends ScopeLookupData { private static final ICPPTemplateArgument[] UNINITIALIZED_TEMPLATE_ARGUMENTS = {}; - public Map<ICPPNamespaceScope, List<ICPPNamespaceScope>> usingDirectives= Collections.emptyMap(); + public Map<ICPPNamespaceScope, List<ICPPNamespaceScope>> usingDirectives = Collections.emptyMap(); /** Used to ensure we don't visit things more than once. */ - public ObjectSet<IScope> visited= new ObjectSet<>(1); + public ObjectSet<IScope> visited = new ObjectSet<>(1); public boolean contentAssist; @@ -103,7 +103,7 @@ public class LookupData extends ScopeLookupData { public boolean forUsingDeclaration; public boolean namespacesOnly; - /** When computing the cost of a method call, treat the first argument as the implied object. */ + /** When computing the cost of a method call, treat the first argument as the implied object. */ public boolean argsContainImpliedObject; /** In list-initialization **/ public boolean fNoNarrowing; @@ -132,12 +132,12 @@ public class LookupData extends ScopeLookupData { public LookupData(char[] name, ICPPTemplateArgument[] templateArgs, IASTNode lookupPoint) { super(name, lookupPoint); - fTemplateArguments= templateArgs; + fTemplateArguments = templateArgs; } public LookupData(char[] name, ICPPTemplateArgument[] templateArgs, IASTTranslationUnit tu) { super(name, tu); - fTemplateArguments= templateArgs; + fTemplateArguments = templateArgs; } @Override @@ -146,52 +146,51 @@ public class LookupData extends ScopeLookupData { } private void configureWith(final IASTName name) { - IASTName tn= name; + IASTName tn = name; if (tn.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { - tn= (IASTName) tn.getParent(); + tn = (IASTName) tn.getParent(); } IASTNode parent = tn.getParent(); - IASTNode nameParent= parent; + IASTNode nameParent = parent; if (parent instanceof ICPPASTQualifiedName) { final ICPPASTQualifiedName qn = (ICPPASTQualifiedName) parent; if (qn.getLastName() != tn) { // For resolving template id ambiguities we need to consider non-types. if (!(tn instanceof ICPPASTTemplateId)) { - typesOnly= true; + typesOnly = true; } } else { - nameParent= parent.getParent(); + nameParent = parent.getParent(); } final ICPPASTNameSpecifier[] qualifier = qn.getQualifier(); if (qn.isFullyQualified()) { - qualified= true; + qualified = true; } else if (qualifier.length > 0) { if (qualifier[0] != tn) { - qualified= true; + qualified = true; } } } - if (nameParent instanceof ICPPASTBaseSpecifier - || nameParent instanceof ICPPASTElaboratedTypeSpecifier + if (nameParent instanceof ICPPASTBaseSpecifier || nameParent instanceof ICPPASTElaboratedTypeSpecifier || nameParent instanceof ICPPASTCompositeTypeSpecifier) { - typesOnly= true; + typesOnly = true; } else if (nameParent instanceof ICPPASTUsingDeclaration) { - forUsingDeclaration= true; + forUsingDeclaration = true; } else if (nameParent instanceof ICPPASTUsingDirective || nameParent instanceof ICPPASTNamespaceAlias) { // [basic.lookup.udir]: Only namespace names are considered - namespacesOnly= true; + namespacesOnly = true; } else if (nameParent instanceof IASTDeclarator) { - fDeclarator= (IASTDeclarator) nameParent; + fDeclarator = (IASTDeclarator) nameParent; } else if (nameParent instanceof IASTFieldReference) { - qualified= true; + qualified = true; if (nameParent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { - fFunctionCall= true; + fFunctionCall = true; } } else if (nameParent instanceof IASTIdExpression) { if (nameParent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { - fFunctionCall= true; + fFunctionCall = true; } } } @@ -202,7 +201,7 @@ public class LookupData extends ScopeLookupData { public IASTDeclaration forDeclaration() { IASTNode node = fDeclarator; while (node instanceof IASTDeclarator) - node= node.getParent(); + node = node.getParent(); if (node instanceof IASTSimpleDeclaration || node instanceof IASTFunctionDefinition) return (IASTDeclaration) node; @@ -219,7 +218,7 @@ public class LookupData extends ScopeLookupData { if (n == null) return false; - IASTDeclaration decl= forDeclaration(); + IASTDeclaration decl = forDeclaration(); if (decl != null) { if (n.getParent() instanceof ICPPASTTemplateId) n = (IASTName) n.getParent(); @@ -231,7 +230,7 @@ public class LookupData extends ScopeLookupData { } public boolean forExplicitFunctionInstantiation() { - IASTDeclaration decl= forDeclaration(); + IASTDeclaration decl = forDeclaration(); return decl != null && decl.getParent() instanceof ICPPASTExplicitTemplateInstantiation; } @@ -239,90 +238,84 @@ public class LookupData extends ScopeLookupData { return fFunctionCall; } - public static boolean checkWholeClassScope(IASTName name) { - if (name == null) - return true; - - IASTNode node = name.getParent(); - while (node instanceof IASTName) { - name= (IASTName) node; - node= name.getParent(); - } - - final ASTNodeProperty nameProp = name.getPropertyInParent(); - if (nameProp == IASTIdExpression.ID_NAME || - nameProp == IASTFieldReference.FIELD_NAME || - nameProp == ICASTFieldDesignator.FIELD_NAME || - nameProp == ICPPASTFieldDesignator.FIELD_NAME || - nameProp == ICPPASTUsingDirective.QUALIFIED_NAME || - nameProp == ICPPASTUsingDeclaration.NAME || - nameProp == IASTFunctionCallExpression.FUNCTION_NAME || - nameProp == IASTNamedTypeSpecifier.NAME || - nameProp == ICPPASTConstructorChainInitializer.MEMBER_ID) { - // Potentially we need to consider the entire class scope - } else { - return false; - } - - for (; node != null; node= node.getParent()) { - // 3.3.7-5 - if (node.getParent() instanceof IASTFunctionDefinition) { - // In a function body - final ASTNodeProperty prop = node.getPropertyInParent(); - if (prop == IASTFunctionDefinition.DECL_SPECIFIER || - prop == IASTFunctionDefinition.DECLARATOR) { - return false; - } - IASTNode parent = node.getParent(); + public static boolean checkWholeClassScope(IASTName name) { + if (name == null) + return true; + + IASTNode node = name.getParent(); + while (node instanceof IASTName) { + name = (IASTName) node; + node = name.getParent(); + } + + final ASTNodeProperty nameProp = name.getPropertyInParent(); + if (nameProp == IASTIdExpression.ID_NAME || nameProp == IASTFieldReference.FIELD_NAME + || nameProp == ICASTFieldDesignator.FIELD_NAME || nameProp == ICPPASTFieldDesignator.FIELD_NAME + || nameProp == ICPPASTUsingDirective.QUALIFIED_NAME || nameProp == ICPPASTUsingDeclaration.NAME + || nameProp == IASTFunctionCallExpression.FUNCTION_NAME || nameProp == IASTNamedTypeSpecifier.NAME + || nameProp == ICPPASTConstructorChainInitializer.MEMBER_ID) { + // Potentially we need to consider the entire class scope + } else { + return false; + } + + for (; node != null; node = node.getParent()) { + // 3.3.7-5 + if (node.getParent() instanceof IASTFunctionDefinition) { + // In a function body + final ASTNodeProperty prop = node.getPropertyInParent(); + if (prop == IASTFunctionDefinition.DECL_SPECIFIER || prop == IASTFunctionDefinition.DECLARATOR) { + return false; + } + IASTNode parent = node.getParent(); while (parent != null) { if (parent instanceof ICPPASTCompositeTypeSpecifier) return true; - parent= parent.getParent(); + parent = parent.getParent(); } // No inline method. return false; - } - if (node instanceof IASTInitializerList || node instanceof IASTEqualsInitializer) { - if (node.getPropertyInParent() == IASTDeclarator.INITIALIZER) { - IASTNode decl= node.getParent(); - while (decl instanceof IASTDeclarator) { - decl= decl.getParent(); - } - if (decl instanceof IASTParameterDeclaration) { - // Default argument - IASTNode parent = decl.getParent(); - while (parent != null) { - if (parent instanceof ICPPASTCompositeTypeSpecifier) - return true; - parent= parent.getParent(); - } - // Not within a class definition - return false; - } - - if (decl instanceof IASTSimpleDeclaration && - decl.getPropertyInParent() == IASTCompositeTypeSpecifier.MEMBER_DECLARATION) { - // Initializer of non-static data member - IASTDeclSpecifier declSpec= ((IASTSimpleDeclaration) decl).getDeclSpecifier(); - if (declSpec.getStorageClass() != IASTDeclSpecifier.sc_static) { - return true; - } - // Continue search, we could still be in a method. - } - } - } - } - return false; - } - - public static boolean typesOnly(IASTName tn) { + } + if (node instanceof IASTInitializerList || node instanceof IASTEqualsInitializer) { + if (node.getPropertyInParent() == IASTDeclarator.INITIALIZER) { + IASTNode decl = node.getParent(); + while (decl instanceof IASTDeclarator) { + decl = decl.getParent(); + } + if (decl instanceof IASTParameterDeclaration) { + // Default argument + IASTNode parent = decl.getParent(); + while (parent != null) { + if (parent instanceof ICPPASTCompositeTypeSpecifier) + return true; + parent = parent.getParent(); + } + // Not within a class definition + return false; + } + + if (decl instanceof IASTSimpleDeclaration + && decl.getPropertyInParent() == IASTCompositeTypeSpecifier.MEMBER_DECLARATION) { + // Initializer of non-static data member + IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); + if (declSpec.getStorageClass() != IASTDeclSpecifier.sc_static) { + return true; + } + // Continue search, we could still be in a method. + } + } + } + } + return false; + } + + public static boolean typesOnly(IASTName tn) { if (tn.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { - tn= (IASTName) tn.getParent(); + tn = (IASTName) tn.getParent(); } IASTNode parent = tn.getParent(); - if (parent instanceof ICPPASTBaseSpecifier - || parent instanceof ICPPASTElaboratedTypeSpecifier + if (parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTElaboratedTypeSpecifier || parent instanceof ICPPASTCompositeTypeSpecifier) { return true; } else if (parent instanceof ICPPASTQualifiedName) { @@ -332,53 +325,53 @@ public class LookupData extends ScopeLookupData { } } return false; - } - - public boolean hasResultOrProblem() { - return problem != null || hasResults(); - } - - public boolean hasResults() { - if (foundItems == null) - return false; - if (foundItems instanceof Object[]) - return ((Object[]) foundItems).length != 0; - if (foundItems instanceof CharArrayObjectMap) - return ((CharArrayObjectMap<?>) foundItems).size() != 0; - return false; - } - - public boolean hasTypeOrMemberFunctionOrVariableResult() { - if (foundItems == null) - return false; - if (foundItems instanceof Object[]) { - for (Object item : (Object[]) foundItems) { - if (item instanceof ICPPMethod || item instanceof IType || item instanceof IVariable) { - return true; - } - } - } - return false; - } - - /** - * Returns the implied object type, or {@code null} if there is no implied object. - */ - public IType getImpliedObjectType() { - if (fImpliedObjectType == null) { - fImpliedObjectType= determineImpliedObjectType(); - } - return fImpliedObjectType; - } + } + + public boolean hasResultOrProblem() { + return problem != null || hasResults(); + } + + public boolean hasResults() { + if (foundItems == null) + return false; + if (foundItems instanceof Object[]) + return ((Object[]) foundItems).length != 0; + if (foundItems instanceof CharArrayObjectMap) + return ((CharArrayObjectMap<?>) foundItems).size() != 0; + return false; + } + + public boolean hasTypeOrMemberFunctionOrVariableResult() { + if (foundItems == null) + return false; + if (foundItems instanceof Object[]) { + for (Object item : (Object[]) foundItems) { + if (item instanceof ICPPMethod || item instanceof IType || item instanceof IVariable) { + return true; + } + } + } + return false; + } /** - * Explicitly sets the implied object type. - * This method is for use in cases where implied object type cannot - * be determined automatically because there is no lookup name. - */ - public void setImpliedObjectType(IType impliedObjectType) { - fImpliedObjectType = impliedObjectType; - } + * Returns the implied object type, or {@code null} if there is no implied object. + */ + public IType getImpliedObjectType() { + if (fImpliedObjectType == null) { + fImpliedObjectType = determineImpliedObjectType(); + } + return fImpliedObjectType; + } + + /** + * Explicitly sets the implied object type. + * This method is for use in cases where implied object type cannot + * be determined automatically because there is no lookup name. + */ + public void setImpliedObjectType(IType impliedObjectType) { + fImpliedObjectType = impliedObjectType; + } private IType determineImpliedObjectType() { IASTName tn = getLookupName(); @@ -386,15 +379,15 @@ public class LookupData extends ScopeLookupData { return null; if (tn.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { - tn= (IASTName) tn.getParent(); + tn = (IASTName) tn.getParent(); } IASTNode parent = tn.getParent(); - IASTNode nameParent= parent; + IASTNode nameParent = parent; if (parent instanceof ICPPASTQualifiedName) { final ICPPASTQualifiedName qn = (ICPPASTQualifiedName) parent; if (qn.getLastName() == tn) { - nameParent= parent.getParent(); + nameParent = parent.getParent(); } } @@ -413,32 +406,32 @@ public class LookupData extends ScopeLookupData { return null; } - /** + /** * Returns the category of the implied object, or {@code null} if there is no implied object. * @see ValueCategory - */ - public ValueCategory getImpliedObjectValueCategory() { - if (fImpliedObjectValueCategory == null) { - fImpliedObjectValueCategory= determineImpliedObjectValueCategory(); - } - return fImpliedObjectValueCategory; - } - - private ValueCategory determineImpliedObjectValueCategory() { + */ + public ValueCategory getImpliedObjectValueCategory() { + if (fImpliedObjectValueCategory == null) { + fImpliedObjectValueCategory = determineImpliedObjectValueCategory(); + } + return fImpliedObjectValueCategory; + } + + private ValueCategory determineImpliedObjectValueCategory() { IASTName tn = getLookupName(); if (tn == null) return null; if (tn.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME) { - tn= (IASTName) tn.getParent(); + tn = (IASTName) tn.getParent(); } IASTNode parent = tn.getParent(); - IASTNode nameParent= parent; + IASTNode nameParent = parent; if (parent instanceof ICPPASTQualifiedName) { final ICPPASTQualifiedName qn = (ICPPASTQualifiedName) parent; if (qn.getLastName() == tn) { - nameParent= parent.getParent(); + nameParent = parent.getParent(); } } @@ -456,7 +449,7 @@ public class LookupData extends ScopeLookupData { } public boolean forFriendship() { - IASTName lookupName= getLookupName(); + IASTName lookupName = getLookupName(); if (lookupName == null) return false; @@ -499,7 +492,7 @@ public class LookupData extends ScopeLookupData { } public boolean checkClassContainingFriend() { - IASTName lookupName= getLookupName(); + IASTName lookupName = getLookupName(); if (lookupName == null || lookupName instanceof ICPPASTQualifiedName) return false; @@ -524,25 +517,25 @@ public class LookupData extends ScopeLookupData { } public void setFunctionArguments(boolean containsImpliedObject, ICPPEvaluation... exprs) { - argsContainImpliedObject= containsImpliedObject; - functionArgs= exprs; + argsContainImpliedObject = containsImpliedObject; + functionArgs = exprs; functionArgTypes = null; } public void setFunctionArguments(boolean containsImpliedObject, IASTInitializerClause... exprs) { - ICPPEvaluation[] evals= new ICPPEvaluation[exprs.length]; + ICPPEvaluation[] evals = new ICPPEvaluation[exprs.length]; for (int i = 0; i < evals.length; i++) { - evals[i]= ((ICPPASTInitializerClause) exprs[i]).getEvaluation(); + evals[i] = ((ICPPASTInitializerClause) exprs[i]).getEvaluation(); } setFunctionArguments(containsImpliedObject, evals); } public IType[] getFunctionArgumentTypes() { if (functionArgTypes == null && functionArgs != null) { - functionArgTypes= new IType[functionArgs.length]; + functionArgTypes = new IType[functionArgs.length]; for (int i = 0; i < functionArgs.length; i++) { ICPPEvaluation e = functionArgs[i]; - functionArgTypes[i]= getSimplifiedType(e.getType()); + functionArgTypes[i] = getSimplifiedType(e.getType()); } } return functionArgTypes; @@ -550,9 +543,9 @@ public class LookupData extends ScopeLookupData { public ValueCategory[] getFunctionArgumentValueCategories() { if (functionArgValueCategories == null) { - ICPPEvaluation[] args= functionArgs; + ICPPEvaluation[] args = functionArgs; if (args != null) { - functionArgValueCategories= new ValueCategory[args.length]; + functionArgValueCategories = new ValueCategory[args.length]; for (int i = 0; i < args.length; i++) { final ICPPEvaluation arg = args[i]; functionArgValueCategories[i] = arg.getValueCategory(); @@ -585,7 +578,7 @@ public class LookupData extends ScopeLookupData { } public int getFunctionArgumentPackExpansionCount() { - int count= 0; + int count = 0; if (functionArgs != null) { for (ICPPEvaluation arg : functionArgs) { if (arg instanceof EvalPackExpansion) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/NamespaceTypeCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/NamespaceTypeCollector.java index 813163f976e..ae20e33dc2d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/NamespaceTypeCollector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/NamespaceTypeCollector.java @@ -39,10 +39,10 @@ class NamespaceTypeCollector extends ASTVisitor { private final ICPPASTInternalScope fScope; public NamespaceTypeCollector(ICPPASTInternalScope scope) { - fScope= scope; - shouldVisitDeclarations= true; - shouldVisitStatements= true; - shouldVisitParameterDeclarations= true; + fScope = scope; + shouldVisitDeclarations = true; + shouldVisitStatements = true; + shouldVisitParameterDeclarations = true; } @Override @@ -51,20 +51,20 @@ class NamespaceTypeCollector extends ASTVisitor { IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration; ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) simpleDeclaration.getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator[] declarators= simpleDeclaration.getDeclarators(); + IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); for (IASTDeclarator declarator : declarators) { - IASTDeclarator innermost= null; + IASTDeclarator innermost = null; while (declarator != null) { if (declarator instanceof IASTAmbiguousDeclarator) { - innermost= null; + innermost = null; break; } - innermost= declarator; - declarator= declarator.getNestedDeclarator(); + innermost = declarator; + declarator = declarator.getNestedDeclarator(); } if (innermost != null) { IASTName declaratorName = innermost.getName(); - ASTInternal.addName(fScope, declaratorName); + ASTInternal.addName(fScope, declaratorName); } } } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) { @@ -80,7 +80,7 @@ class NamespaceTypeCollector extends ASTVisitor { ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) funcDefinition.getDeclSpecifier(); if (declSpec.isFriend()) { IASTFunctionDeclarator declarator = funcDefinition.getDeclarator(); - ASTInternal.addName(fScope, declarator.getName()); + ASTInternal.addName(fScope, declarator.getName()); } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) { addNonSimpleElabSpec((ICPPASTElaboratedTypeSpecifier) declSpec); } @@ -90,7 +90,6 @@ class NamespaceTypeCollector extends ASTVisitor { return PROCESS_SKIP; } - @Override public int visit(IASTParameterDeclaration declaration) { IASTDeclSpecifier declSpec = declaration.getDeclSpecifier(); @@ -104,7 +103,7 @@ class NamespaceTypeCollector extends ASTVisitor { if (elabSpec.getKind() != IASTElaboratedTypeSpecifier.k_enum) { final IASTName name = elabSpec.getName(); if (!(name instanceof ICPPASTQualifiedName)) { - ASTInternal.addName(fScope, name); + ASTInternal.addName(fScope, name); } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 8a620fba889..902d49cf82d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -96,23 +96,23 @@ import org.eclipse.cdt.internal.core.index.IIndexScope; public class SemanticUtil { private static final char[] OPERATOR_CHARS = Keywords.OPERATOR.toCharArray(); // Cache of overloadable operator names for fast lookup. Used by isConversionOperator. - private static final CharArraySet cas= new CharArraySet(OverloadableOperator.values().length); + private static final CharArraySet cas = new CharArraySet(OverloadableOperator.values().length); // Resolve typedefs. - public static final int TDEF = 0x01; + public static final int TDEF = 0x01; // Resolve typedefs, but only if necessary for a nested type transformation. public static final int COND_TDEF = 0x02; - public static final int REF = 0x04; - public static final int CVTYPE = 0x08; - public static final int ALLCVQ = 0x10; - public static final int PTR = 0x20; - public static final int MPTR = 0x40; - public static final int ARRAY = 0x80; + public static final int REF = 0x04; + public static final int CVTYPE = 0x08; + public static final int ALLCVQ = 0x10; + public static final int PTR = 0x20; + public static final int MPTR = 0x40; + public static final int ARRAY = 0x80; static { - final int OPERATOR_SPC= OPERATOR_CHARS.length + 1; + final int OPERATOR_SPC = OPERATOR_CHARS.length + 1; for (OverloadableOperator op : OverloadableOperator.values()) { - char[] name= op.toCharArray(); + char[] name = op.toCharArray(); cas.put(CharArrayUtils.subarray(name, OPERATOR_SPC, name.length)); } } @@ -126,9 +126,9 @@ public class SemanticUtil { * @return an array of conversion operators. */ public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz) throws DOMException { - ICPPMethod[] conversionOps= ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + ICPPMethod[] conversionOps = ICPPMethod.EMPTY_CPPMETHOD_ARRAY; if (clazz instanceof ICPPDeferredClassInstance) { - clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); + clazz = (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); } ICPPMethod[] methods; // For a closure type, getDeclaredMethods() does not return the conversion @@ -144,7 +144,7 @@ public class SemanticUtil { if (methods != null) { for (ICPPMethod method : methods) { if (isConversionOperator(method)) { - conversionOps= ArrayUtil.append(conversionOps, method); + conversionOps = ArrayUtil.append(conversionOps, method); } } } @@ -160,10 +160,10 @@ public class SemanticUtil { * @return an array of conversion operators. */ public static ICPPMethod[] getConversionOperators(ICPPClassType clazz) throws DOMException { - ICPPMethod[] methods= ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - ObjectSet<ICPPClassType> ancestry= inheritanceClosure(clazz); + ICPPMethod[] methods = ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + ObjectSet<ICPPClassType> ancestry = inheritanceClosure(clazz); for (int i = 0; i < ancestry.size(); i++) { - methods= ArrayUtil.addAll(methods, getDeclaredConversionOperators(ancestry.keyAt(i))); + methods = ArrayUtil.addAll(methods, getDeclaredConversionOperators(ancestry.keyAt(i))); } return methods; } @@ -174,21 +174,21 @@ public class SemanticUtil { * @throws DOMException */ public static ObjectSet<ICPPClassType> inheritanceClosure(ICPPClassType root) throws DOMException { - ObjectSet<ICPPClassType> done= new ObjectSet<>(2); - ObjectSet<ICPPClassType> current= new ObjectSet<>(2); + ObjectSet<ICPPClassType> done = new ObjectSet<>(2); + ObjectSet<ICPPClassType> current = new ObjectSet<>(2); current.put(root); for (int count = 0; count < CPPSemantics.MAX_INHERITANCE_DEPTH && !current.isEmpty(); count++) { - ObjectSet<ICPPClassType> next= new ObjectSet<>(2); + ObjectSet<ICPPClassType> next = new ObjectSet<>(2); for (int i = 0; i < current.size(); i++) { - ICPPClassType clazz= current.keyAt(i); + ICPPClassType clazz = current.keyAt(i); done.put(clazz); for (ICPPBase base : clazz.getBases()) { - IBinding binding= base.getBaseClass(); + IBinding binding = base.getBaseClass(); if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { - ICPPClassType ct= (ICPPClassType) binding; + ICPPClassType ct = (ICPPClassType) binding; if (!done.containsKey(ct)) { next.put(ct); } @@ -196,7 +196,7 @@ public class SemanticUtil { } } - current= next; + current = next; } return done; @@ -208,10 +208,10 @@ public class SemanticUtil { */ public static final boolean isConversionOperator(ICPPFunction method) { if (method instanceof ICPPMethod) { - final char[] name= method.getNameCharArray(); - if (name.length > OPERATOR_CHARS.length + 1 && name[OPERATOR_CHARS.length] == ' ' && - CharArrayUtils.equals(name, 0, OPERATOR_CHARS.length, OPERATOR_CHARS)) { - return !cas.containsKey(name, OPERATOR_CHARS.length + 1, name.length - (OPERATOR_CHARS.length+1)); + final char[] name = method.getNameCharArray(); + if (name.length > OPERATOR_CHARS.length + 1 && name[OPERATOR_CHARS.length] == ' ' + && CharArrayUtils.equals(name, 0, OPERATOR_CHARS.length, OPERATOR_CHARS)) { + return !cas.containsKey(name, OPERATOR_CHARS.length + 1, name.length - (OPERATOR_CHARS.length + 1)); } } return false; @@ -219,19 +219,15 @@ public class SemanticUtil { public static CVQualifier getCVQualifier(IType t) { if (t instanceof IQualifierType) { - IQualifierType qt= (IQualifierType) t; - return qt.isConst() - ? qt.isVolatile() ? CONST_VOLATILE : CONST - : qt.isVolatile() ? VOLATILE : NONE; + IQualifierType qt = (IQualifierType) t; + return qt.isConst() ? qt.isVolatile() ? CONST_VOLATILE : CONST : qt.isVolatile() ? VOLATILE : NONE; } if (t instanceof IPointerType) { - IPointerType pt= (IPointerType) t; + IPointerType pt = (IPointerType) t; return pt.isConst() - ? pt.isVolatile() - ? pt.isRestrict() ? CONST_VOLATILE_RESTRICT : CONST_VOLATILE + ? pt.isVolatile() ? pt.isRestrict() ? CONST_VOLATILE_RESTRICT : CONST_VOLATILE : pt.isRestrict() ? CONST_RESTRICT : CONST - : pt.isVolatile() - ? pt.isRestrict() ? VOLATILE_RESTRICT : VOLATILE + : pt.isVolatile() ? pt.isRestrict() ? VOLATILE_RESTRICT : VOLATILE : pt.isRestrict() ? RESTRICT : NONE; } if (t instanceof IArrayType) { @@ -266,31 +262,31 @@ public class SemanticUtil { * Descends into typedefs, references, etc. as specified by options. */ public static IType getNestedType(IType type, int options) { - final boolean tdef= (options & TDEF) != 0; - final boolean cond_tdef= (options & COND_TDEF) != 0; - final boolean ptr= (options & PTR) != 0; - final boolean mptr= (options & MPTR) != 0; - final boolean allcvq= (options & ALLCVQ) != 0; - final boolean cvtype= (options & CVTYPE) != 0; + final boolean tdef = (options & TDEF) != 0; + final boolean cond_tdef = (options & COND_TDEF) != 0; + final boolean ptr = (options & PTR) != 0; + final boolean mptr = (options & MPTR) != 0; + final boolean allcvq = (options & ALLCVQ) != 0; + final boolean cvtype = (options & CVTYPE) != 0; IType beforeTypedefs = null; while (true) { - IType t= null; + IType t = null; if (type instanceof ITypedef) { if (tdef || cond_tdef) { if (beforeTypedefs == null && cond_tdef) { beforeTypedefs = type; } - t= ((ITypedef) type).getType(); + t = ((ITypedef) type).getType(); } } else if (type instanceof IPointerType) { final boolean isMbrPtr = type instanceof ICPPPointerToMemberType; if ((ptr && !isMbrPtr) || (mptr && isMbrPtr)) { - t= ((IPointerType) type).getType(); + t = ((IPointerType) type).getType(); beforeTypedefs = null; } else if (allcvq) { - IPointerType pt= (IPointerType) type; + IPointerType pt = (IPointerType) type; if (pt.isConst() || pt.isVolatile() || pt.isRestrict()) { if (pt instanceof ICPPPointerToMemberType) { final IType memberOfClass = ((ICPPPointerToMemberType) pt).getMemberOfClass(); @@ -304,22 +300,22 @@ public class SemanticUtil { final IQualifierType qt = (IQualifierType) type; final IType qttgt = qt.getType(); if (allcvq || cvtype) { - t= qttgt; + t = qttgt; beforeTypedefs = null; } else if (tdef || cond_tdef) { - t= getNestedType(qttgt, options); + t = getNestedType(qttgt, options); if (t == qttgt) return qt; return addQualifiers(t, qt.isConst(), qt.isVolatile(), false); } } else if (type instanceof IArrayType) { - final IArrayType atype= (IArrayType) type; + final IArrayType atype = (IArrayType) type; if ((options & ARRAY) != 0) { - t= atype.getType(); + t = atype.getType(); beforeTypedefs = null; } else if (allcvq) { - IType nested= atype.getType(); - IType newNested= getNestedType(nested, ALLCVQ); + IType nested = atype.getType(); + IType newNested = getNestedType(nested, ALLCVQ); if (nested == newNested) return type; return replaceNestedType((ITypeContainer) atype, newNested); @@ -327,11 +323,11 @@ public class SemanticUtil { } else if (type instanceof ICPPReferenceType) { final ICPPReferenceType rt = (ICPPReferenceType) type; if ((options & REF) != 0) { - t= rt.getType(); + t = rt.getType(); beforeTypedefs = null; } else if (tdef) { // A typedef within the reference type can influence whether the reference is lvalue or rvalue - IType nested= rt.getType(); + IType nested = rt.getType(); IType newNested = getNestedType(nested, TDEF); if (nested == newNested) return type; @@ -346,7 +342,7 @@ public class SemanticUtil { return type; } - type= t; + type = t; } } @@ -365,23 +361,23 @@ public class SemanticUtil { if (ret == r && params == ps) { return type; } - return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), - ft.hasRefQualifier(), ft.isRValueReference(), ft.takesVarArgs()); + return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), ft.hasRefQualifier(), + ft.isRValueReference(), ft.takesVarArgs()); } if (type instanceof ITypedef) { - IType t= ((ITypedef) type).getType(); + IType t = ((ITypedef) type).getType(); if (t != null) return getSimplifiedType(t); return type; } if (type instanceof ITypeContainer) { final ITypeContainer tc = (ITypeContainer) type; - final IType nestedType= tc.getType(); + final IType nestedType = tc.getType(); if (nestedType == null) return type; - IType newType= getSimplifiedType(nestedType); + IType newType = getSimplifiedType(nestedType); if (newType != nestedType) { return replaceNestedType(tc, newType); } @@ -418,7 +414,7 @@ public class SemanticUtil { // Do not to add unnecessary qualifications (bug 24908). if (type instanceof IQualifierType) { - IQualifierType qt= (IQualifierType) type; + IQualifierType qt = (IQualifierType) type; return addQualifiers(newNestedType, qt.isConst(), qt.isVolatile(), false); } @@ -460,7 +456,7 @@ public class SemanticUtil { IType result = null; ITypeContainer containerType = null; - for (IType t = type; ; t = containerType.getType()) { + for (IType t = type;; t = containerType.getType()) { IType newType = t == nestedType ? typedefType : (IType) t.clone(); if (result == null) result = newType; @@ -483,19 +479,19 @@ public class SemanticUtil { if (t instanceof ISemanticProblem) { return false; } else if (t instanceof IFunctionType) { - IFunctionType ft= (IFunctionType) t; + IFunctionType ft = (IFunctionType) t; for (IType parameterType : ft.getParameterTypes()) { if (!isValidType(parameterType)) return false; } - t= ft.getReturnType(); + t = ft.getReturnType(); } else if (t instanceof ICPPPointerToMemberType) { - ICPPPointerToMemberType mptr= (ICPPPointerToMemberType) t; + ICPPPointerToMemberType mptr = (ICPPPointerToMemberType) t; if (!isValidType(mptr.getMemberOfClass())) return false; - t= mptr.getType(); + t = mptr.getType(); } else if (t instanceof ITypeContainer) { - t= ((ITypeContainer) t).getType(); + t = ((ITypeContainer) t).getType(); } else { return true; } @@ -559,14 +555,14 @@ public class SemanticUtil { return ((ASTTranslationUnit) ast).mapToASTScope(scope); } } else if (scope.getKind() == EScopeKind.eGlobal) { - CCorePlugin.log(new Exception( - "The point argument was not provided. Returning the global index scope.")); //$NON-NLS-1$ + CCorePlugin + .log(new Exception("The point argument was not provided. Returning the global index scope.")); //$NON-NLS-1$ } } return scope; } - public static void recordPartialSpecialization(ICPPClassTemplatePartialSpecialization indexSpec, + public static void recordPartialSpecialization(ICPPClassTemplatePartialSpecialization indexSpec, ICPPClassTemplatePartialSpecialization astSpec, IASTNode point) { if (point != null) { IASTTranslationUnit ast = point.getTranslationUnit(); @@ -575,9 +571,8 @@ public class SemanticUtil { } } } - - public static ICPPClassTemplatePartialSpecialization mapToAST( - ICPPClassTemplatePartialSpecialization indexSpec) { + + public static ICPPClassTemplatePartialSpecialization mapToAST(ICPPClassTemplatePartialSpecialization indexSpec) { IASTNode point = CPPSemantics.getCurrentLookupPoint(); if (point != null) { IASTTranslationUnit ast = point.getTranslationUnit(); @@ -593,15 +588,15 @@ public class SemanticUtil { IType[] result = types; for (int i = 0; i < types.length; i++) { final IType type = types[i]; - final IType newType= getSimplifiedType(type); + final IType newType = getSimplifiedType(type); if (result != types) { - result[i]= newType; + result[i] = newType; } else if (type != newType) { result = new IType[types.length]; if (i > 0) { System.arraycopy(types, 0, result, 0, i); } - result[i]= newType; + result[i] = newType; } } return result; @@ -611,18 +606,18 @@ public class SemanticUtil { // Don't create a new array until it's really needed. ICPPTemplateArgument[] result = args; for (int i = 0; i < args.length; i++) { - final ICPPTemplateArgument arg= args[i]; - ICPPTemplateArgument newArg= arg; + final ICPPTemplateArgument arg = args[i]; + ICPPTemplateArgument newArg = arg; if (arg != null) { newArg = getSimplifiedArgument(arg); if (result != args) { - result[i]= newArg; + result[i] = newArg; } else if (arg != newArg) { result = new ICPPTemplateArgument[args.length]; if (i > 0) { System.arraycopy(args, 0, result, 0, i); } - result[i]= newArg; + result[i] = newArg; } } } @@ -631,8 +626,8 @@ public class SemanticUtil { public static ICPPTemplateArgument getSimplifiedArgument(final ICPPTemplateArgument arg) { if (arg.isTypeValue()) { - final IType type= arg.getTypeValue(); - final IType newType= getSimplifiedType(type); + final IType type = arg.getTypeValue(); + final IType newType = getSimplifiedType(type); if (newType != type) { return new CPPTemplateTypeArgument(newType, arg.getOriginalTypeValue()); } @@ -647,31 +642,29 @@ public class SemanticUtil { public static IType addQualifiers(IType baseType, boolean cnst, boolean vol, boolean restrict) { if (cnst || vol || restrict) { if (baseType instanceof IQualifierType) { - IQualifierType qt= (IQualifierType) baseType; + IQualifierType qt = (IQualifierType) baseType; if ((cnst && !qt.isConst()) || (vol && !qt.isVolatile())) { return new CPPQualifierType(qt.getType(), cnst || qt.isConst(), vol || qt.isVolatile()); } return baseType; } else if (baseType instanceof ICPPPointerToMemberType) { - ICPPPointerToMemberType pt= (ICPPPointerToMemberType) baseType; - if ((cnst && !pt.isConst()) || (vol && !pt.isVolatile()) - || (restrict && !pt.isRestrict())) { - return new CPPPointerToMemberType(pt.getType(), pt.getMemberOfClass(), - cnst || pt.isConst(), vol || pt.isVolatile(), restrict || pt.isRestrict()); + ICPPPointerToMemberType pt = (ICPPPointerToMemberType) baseType; + if ((cnst && !pt.isConst()) || (vol && !pt.isVolatile()) || (restrict && !pt.isRestrict())) { + return new CPPPointerToMemberType(pt.getType(), pt.getMemberOfClass(), cnst || pt.isConst(), + vol || pt.isVolatile(), restrict || pt.isRestrict()); } return baseType; } else if (baseType instanceof IPointerType) { - IPointerType pt= (IPointerType) baseType; - if ((cnst && !pt.isConst()) || (vol && !pt.isVolatile()) - || (restrict && !pt.isRestrict())) { - return new CPPPointerType(pt.getType(), - cnst || pt.isConst(), vol || pt.isVolatile(), restrict || pt.isRestrict()); + IPointerType pt = (IPointerType) baseType; + if ((cnst && !pt.isConst()) || (vol && !pt.isVolatile()) || (restrict && !pt.isRestrict())) { + return new CPPPointerType(pt.getType(), cnst || pt.isConst(), vol || pt.isVolatile(), + restrict || pt.isRestrict()); } return baseType; } else if (baseType instanceof IArrayType) { - IArrayType at= (IArrayType) baseType; - IType nested= at.getType(); - IType newNested= addQualifiers(nested, cnst, vol, restrict); + IArrayType at = (IArrayType) baseType; + IType nested = at.getType(); + IType newNested = addQualifiers(nested, cnst, vol, restrict); if (newNested != nested && at instanceof ITypeContainer) { return replaceNestedType((ITypeContainer) at, newNested); } @@ -716,9 +709,9 @@ public class SemanticUtil { while (true) { for (int i = 0; b1 instanceof ICPPNamespaceAlias && i < 20; i++) - b1= ((ICPPNamespaceAlias) b1).getBinding(); + b1 = ((ICPPNamespaceAlias) b1).getBinding(); for (int i = 0; b2 instanceof ICPPNamespaceAlias && i < 20; i++) - b2= ((ICPPNamespaceAlias) b2).getBinding(); + b2 = ((ICPPNamespaceAlias) b2).getBinding(); if (b1 == null) return b2 == null; @@ -736,7 +729,7 @@ public class SemanticUtil { public static boolean isVoidType(IType ptype) { while (ptype instanceof ITypedef) { - ptype= ((ITypedef) ptype).getType(); + ptype = ((ITypedef) ptype).getType(); } if (ptype instanceof IBasicType) { return ((IBasicType) ptype).getKind() == Kind.eVoid; @@ -781,24 +774,23 @@ public class SemanticUtil { if (maxdepth > 0 && type instanceof ICPPClassType && baseClass instanceof ICPPClassType) { ICPPClassType clazz = (ICPPClassType) type; if (clazz instanceof ICPPDeferredClassInstance) { - clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); + clazz = (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); } // The base classes may have changed since the definition of clazz was indexed. clazz = (ICPPClassType) mapToAST(clazz); for (ICPPBase cppBase : clazz.getBases()) { - IBinding base= cppBase.getBaseClass(); + IBinding base = cppBase.getBaseClass(); if (base instanceof IType && hashSet.add(base)) { - IType tbase= (IType) base; - if (tbase.isSameType(baseClass) || - (baseClass instanceof ICPPSpecialization && // Allow some flexibility with templates. + IType tbase = (IType) base; + if (tbase.isSameType(baseClass) || (baseClass instanceof ICPPSpecialization && // Allow some flexibility with templates. ((IType) ((ICPPSpecialization) baseClass).getSpecializedBinding()).isSameType(tbase))) { return 1; } if (tbase instanceof ICPPClassType) { - int n= calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass); + int n = calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass); if (n > 0) return n + 1; } @@ -867,36 +859,36 @@ public class SemanticUtil { * @param type the type of the variable */ public static IValue getValueOfInitializer(IASTInitializer init, IType type) { - IASTInitializerClause clause= null; + IASTInitializerClause clause = null; CPPSemantics.pushLookupPoint(init); try { if (init instanceof IASTEqualsInitializer) { - clause= ((IASTEqualsInitializer) init).getInitializerClause(); + clause = ((IASTEqualsInitializer) init).getInitializerClause(); } else if (init instanceof ICPPASTConstructorInitializer) { - IASTInitializerClause[] args= ((ICPPASTConstructorInitializer) init).getArguments(); + IASTInitializerClause[] args = ((ICPPASTConstructorInitializer) init).getArguments(); if (args.length == 1 && args[0] instanceof IASTExpression) { - IType typeUpToPointers= SemanticUtil.getUltimateTypeUptoPointers(type); + IType typeUpToPointers = SemanticUtil.getUltimateTypeUptoPointers(type); if (typeUpToPointers instanceof IPointerType || typeUpToPointers instanceof IBasicType) { - clause= args[0]; + clause = args[0]; } } } else if (init instanceof ICPPASTInitializerList) { - ICPPASTInitializerList list= (ICPPASTInitializerList) init; + ICPPASTInitializerList list = (ICPPASTInitializerList) init; switch (list.getSize()) { case 0: return IntegralValue.create(0); case 1: - clause= list.getClauses()[0]; + clause = list.getClauses()[0]; break; default: return ((ICPPASTInitializerList) init).getEvaluation().getValue(); - + } } if (clause instanceof IASTExpression) { return ValueFactory.create((IASTExpression) clause); } - + if (clause instanceof ICPPASTInitializerList) { return ((ICPPASTInitializerList) clause).getEvaluation().getValue(); } @@ -924,13 +916,13 @@ public class SemanticUtil { } static IType[] addImplicitParameterType(IType[] types, ICPPMethod m) { - IType t= CPPSemantics.getImplicitParameterType(m); + IType t = CPPSemantics.getImplicitParameterType(m); return concatTypes(t, types); } static IType[] concatTypes(final IType t, IType[] types) { - IType[] result= new IType[types.length + 1]; - result[0]= t; + IType[] result = new IType[types.length + 1]; + result[0] = t; System.arraycopy(types, 0, result, 1, types.length); return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java index 7c050841097..8561efa3163 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPExecution; import org.eclipse.core.runtime.CoreException; class SignatureBuilder implements ITypeMarshalBuffer { - private static final short NULL_TYPE = 0x0000; + private static final short NULL_TYPE = 0x0000; private static final short UNSTORABLE_TYPE = 0x001D; private final StringBuilder fBuffer; @@ -37,7 +37,7 @@ class SignatureBuilder implements ITypeMarshalBuffer { * Constructor for input buffer. */ public SignatureBuilder() { - fBuffer= new StringBuilder(); + fBuffer = new StringBuilder(); } @Override @@ -84,7 +84,7 @@ class SignatureBuilder implements ITypeMarshalBuffer { // a need to write it to the index, but it can appear in a signature // during partial ordering of function templates. appendSeparator(); - fBuffer.append("Unique(@"); //$NON-NLS-1$ + fBuffer.append("Unique(@"); //$NON-NLS-1$ fBuffer.append(Integer.toHexString(System.identityHashCode(type))); fBuffer.append(')'); } else { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 4e22aa5b5c6..9cf6aee19ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -91,9 +91,8 @@ public class TemplateArgumentDeduction { * parameters. * 14.8.2.1 */ - static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template, - ICPPTemplateArgument[] tmplArgs, List<IType> fnArgs, List<ValueCategory> argIsLValue, - CPPTemplateParameterMap map) throws DOMException { + static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template, ICPPTemplateArgument[] tmplArgs, + List<IType> fnArgs, List<ValueCategory> argIsLValue, CPPTemplateParameterMap map) throws DOMException { final ICPPTemplateParameter[] tmplParams = template.getTemplateParameters(); if (tmplArgs != null && !addExplicitArguments(template, tmplParams, tmplArgs, map)) @@ -115,64 +114,64 @@ public class TemplateArgumentDeduction { IType[] fnPars = template.getType().getParameterTypes(); final int fnParCount = fnPars.length; final ICPPTemplateParameter[] tmplPars = template.getTemplateParameters(); - TemplateArgumentDeduction deduct= - new TemplateArgumentDeduction(tmplPars, map, new CPPTemplateParameterMap(fnParCount), 0); - IType fnParPack= null; - argLoop: for (int j= 0; j < fnArgs.size(); j++) { + TemplateArgumentDeduction deduct = new TemplateArgumentDeduction(tmplPars, map, + new CPPTemplateParameterMap(fnParCount), 0); + IType fnParPack = null; + argLoop: for (int j = 0; j < fnArgs.size(); j++) { IType par; if (fnParPack != null) { - par= fnParPack; + par = fnParPack; deduct.incPackOffset(); } else if (j < fnParCount) { - par= fnPars[j]; + par = fnPars[j]; if (par instanceof ICPPParameterPackType) { if (j != fnParCount - 1) - continue argLoop; // Non-deduced context + continue argLoop; // Non-deduced context - par= fnParPack= ((ICPPParameterPackType) par).getType(); - deduct= new TemplateArgumentDeduction(deduct, fnArgs.size() - j); + par = fnParPack = ((ICPPParameterPackType) par).getType(); + deduct = new TemplateArgumentDeduction(deduct, fnArgs.size() - j); } } else { break; } - par= CPPTemplates.instantiateType(par, new InstantiationContext(map)); + par = CPPTemplates.instantiateType(par, new InstantiationContext(map)); if (!SemanticUtil.isValidType(par)) return false; if (CPPTemplates.isDependentType(par)) { IType arg = fnArgs.get(j); - par= SemanticUtil.getNestedType(par, SemanticUtil.TDEF); // adjustParameterType preserves typedefs + par = SemanticUtil.getNestedType(par, SemanticUtil.TDEF); // adjustParameterType preserves typedefs // C++11: 14.9.2.1-1 if (arg instanceof InitializerListType) { - par= SemanticUtil.getNestedType(par, TDEF | REF | CVTYPE); + par = SemanticUtil.getNestedType(par, TDEF | REF | CVTYPE); // Check if this is a deduced context. - IType inner= Conversions.getInitListType(par); + IType inner = Conversions.getInitListType(par); if (inner != null) { final EvalInitList eval = ((InitializerListType) arg).getEvaluation(); for (ICPPEvaluation clause : eval.getClauses()) { - if (!deduceFromFunctionArg(inner, clause.getType(), - clause.getValueCategory(), deduct)) + if (!deduceFromFunctionArg(inner, clause.getType(), clause.getValueCategory(), deduct)) return false; } } } else if (arg instanceof FunctionSetType) { // 14.8.2.1-6 Handling of overloaded function sets - ICPPFunction[] fs= ((FunctionSetType) arg).getFunctionSet().getBindings(); + ICPPFunction[] fs = ((FunctionSetType) arg).getFunctionSet().getBindings(); for (ICPPFunction f : fs) { if (f instanceof ICPPFunctionTemplate) continue argLoop; // Non-deduced context } // Do trial deduction - CPPTemplateParameterMap success= null; - Set<String> handled= new HashSet<>(); + CPPTemplateParameterMap success = null; + Set<String> handled = new HashSet<>(); for (ICPPFunction f : fs) { - arg= f.getType(); + arg = f.getType(); if (f instanceof ICPPMethod && !f.isStatic()) { - arg= new CPPPointerToMemberType(arg, ((ICPPMethod) f).getClassOwner(), false, false, false); + arg = new CPPPointerToMemberType(arg, ((ICPPMethod) f).getClassOwner(), false, false, + false); } if (handled.add(ASTTypeUtil.getType(arg, true))) { final CPPTemplateParameterMap state = deduct.saveState(); @@ -181,7 +180,7 @@ public class TemplateArgumentDeduction { deduct.restoreState(state); continue argLoop; // Non-deduced context } - success= deduct.saveState(); + success = deduct.saveState(); } deduct.restoreState(state); } @@ -205,8 +204,8 @@ public class TemplateArgumentDeduction { ICPPTemplateArgument arg = deduct.fDeducedArgs.getArgument(tpar); if (arg != null) { IType type1 = ((ICPPTemplateNonTypeParameter) tpar).getType(); - type1= CPPTemplates.instantiateType(type1, new InstantiationContext(map)); - IType type2= arg.getTypeOfNonTypeValue(); + type1 = CPPTemplates.instantiateType(type1, new InstantiationContext(map)); + IType type2 = arg.getTypeOfNonTypeValue(); // Template-argument deduced from an array bound may be of any integral type. if (type2 instanceof TypeOfValueDeducedFromArraySize && isIntegralType(type1)) { IValue value = isBooleanType(type1) ? IntegralValue.create(true) : arg.getNonTypeValue(); @@ -251,7 +250,7 @@ public class TemplateArgumentDeduction { private static boolean deduceFromFunctionArg(IType par, IType arg, ValueCategory valueCat, TemplateArgumentDeduction deduct) throws DOMException { - boolean isReferenceTypeParameter= false; + boolean isReferenceTypeParameter = false; if (par instanceof ICPPReferenceType) { // Cannot deduce a reference type from a void type. if (SemanticUtil.isVoidType(arg)) { @@ -260,41 +259,40 @@ public class TemplateArgumentDeduction { // If P is an rvalue reference to a cv-unqualified template parameter and the argument // is an lvalue, the type "lvalue reference to A" is used in place of A for type // deduction. - isReferenceTypeParameter= true; + isReferenceTypeParameter = true; final ICPPReferenceType refPar = (ICPPReferenceType) par; - if (refPar.isRValueReference() && refPar.getType() instanceof ICPPTemplateParameter && - valueCat == LVALUE) { - arg= new CPPReferenceType(getSimplifiedType(arg), false); + if (refPar.isRValueReference() && refPar.getType() instanceof ICPPTemplateParameter && valueCat == LVALUE) { + arg = new CPPReferenceType(getSimplifiedType(arg), false); } else { - arg= getArgumentTypeForDeduction(arg, true); + arg = getArgumentTypeForDeduction(arg, true); } - par= SemanticUtil.getNestedType(par, REF | TDEF); + par = SemanticUtil.getNestedType(par, REF | TDEF); } else { - arg= getArgumentTypeForDeduction(arg, false); + arg = getArgumentTypeForDeduction(arg, false); } // 14.8.2.1-3 - CVQualifier cvPar= SemanticUtil.getCVQualifier(par); - CVQualifier cvArg= SemanticUtil.getCVQualifier(arg); + CVQualifier cvPar = SemanticUtil.getCVQualifier(par); + CVQualifier cvArg = SemanticUtil.getCVQualifier(arg); if (cvPar == cvArg || (isReferenceTypeParameter && cvPar.isAtLeastAsQualifiedAs(cvArg))) { - IType pcheck= SemanticUtil.getNestedType(par, CVTYPE); + IType pcheck = SemanticUtil.getNestedType(par, CVTYPE); if (!(pcheck instanceof ICPPTemplateParameter)) { - par= pcheck; - arg= SemanticUtil.getNestedType(arg, CVTYPE); - IType argcheck= arg; + par = pcheck; + arg = SemanticUtil.getNestedType(arg, CVTYPE); + IType argcheck = arg; if (par instanceof IPointerType && arg instanceof IPointerType) { - pcheck= ((IPointerType) par).getType(); - argcheck= ((IPointerType) arg).getType(); + pcheck = ((IPointerType) par).getType(); + argcheck = ((IPointerType) arg).getType(); if (pcheck instanceof ICPPTemplateParameter) { - pcheck= null; + pcheck = null; } else { - cvPar= SemanticUtil.getCVQualifier(pcheck); - cvArg= SemanticUtil.getCVQualifier(argcheck); + cvPar = SemanticUtil.getCVQualifier(pcheck); + cvArg = SemanticUtil.getCVQualifier(argcheck); if (cvPar.isAtLeastAsQualifiedAs(cvArg)) { - pcheck= SemanticUtil.getNestedType(pcheck, CVTYPE); - argcheck= SemanticUtil.getNestedType(argcheck, CVTYPE); + pcheck = SemanticUtil.getNestedType(pcheck, CVTYPE); + argcheck = SemanticUtil.getNestedType(argcheck, CVTYPE); } else { - pcheck= null; + pcheck = null; } } } @@ -303,14 +301,14 @@ public class TemplateArgumentDeduction { if (pcheck instanceof ICPPTemplateInstance && argcheck instanceof ICPPClassType) { ICPPTemplateInstance pInst = (ICPPTemplateInstance) pcheck; - ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst); + ICPPClassTemplate pTemplate = getPrimaryTemplate(pInst); if (pTemplate != null) { ICPPClassType[] aInstances = findBaseInstances((ICPPClassType) argcheck, pTemplate); boolean attempted = false; for (ICPPClassType aInst : aInstances) { if (aInst != null && aInst != argcheck) { - par= pcheck; - arg= aInst; + par = pcheck; + arg = aInst; attempted = true; if (deduct.fromType(par, arg, true, false)) { return true; @@ -334,24 +332,23 @@ public class TemplateArgumentDeduction { * @param point * @throws DOMException */ - static ICPPTemplateArgument[] deduceForAddressOf(ICPPFunctionTemplate template, - ICPPTemplateArgument[] tmplArgs, IFunctionType arg, CPPTemplateParameterMap map) - throws DOMException { + static ICPPTemplateArgument[] deduceForAddressOf(ICPPFunctionTemplate template, ICPPTemplateArgument[] tmplArgs, + IFunctionType arg, CPPTemplateParameterMap map) throws DOMException { final ICPPTemplateParameter[] tmplParams = template.getTemplateParameters(); if (!addExplicitArguments(template, tmplParams, tmplArgs, map)) return null; - IType par= template.getType(); + IType par = template.getType(); InstantiationContext context = new InstantiationContext(map); - par= CPPTemplates.instantiateType(par, context); + par = CPPTemplates.instantiateType(par, context); if (!SemanticUtil.isValidType(par)) return null; - boolean isDependentPar= CPPTemplates.isDependentType(par); + boolean isDependentPar = CPPTemplates.isDependentType(par); if (isDependentPar) { - TemplateArgumentDeduction deduct= - new TemplateArgumentDeduction(tmplParams, map, new CPPTemplateParameterMap(tmplParams.length), 0); - par= SemanticUtil.getNestedType(par, SemanticUtil.TDEF); + TemplateArgumentDeduction deduct = new TemplateArgumentDeduction(tmplParams, map, + new CPPTemplateParameterMap(tmplParams.length), 0); + par = SemanticUtil.getNestedType(par, SemanticUtil.TDEF); if (arg != null && !deduct.fromType(par, arg, false, false)) return null; if (!map.addDeducedArgs(deduct.fDeducedArgs)) @@ -362,7 +359,7 @@ public class TemplateArgumentDeduction { return null; if (isDependentPar) - par= CPPTemplates.instantiateType(par, context); + par = CPPTemplates.instantiateType(par, context); if (arg == null || arg.isSameType(par)) { return createArguments(map, tmplParams); @@ -374,17 +371,17 @@ public class TemplateArgumentDeduction { * Deduce arguments for a user defined conversion template * 14.8.2.3 */ - static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template, IType conversionType, + static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template, IType conversionType, CPPTemplateParameterMap map) throws DOMException { final ICPPTemplateParameter[] tmplParams = template.getTemplateParameters(); final int length = tmplParams.length; ICPPTemplateArgument[] result = new ICPPTemplateArgument[length]; - IType a= SemanticUtil.getSimplifiedType(conversionType); - IType p= template.getType().getReturnType(); - p= getArgumentTypeForDeduction(p, a instanceof ICPPReferenceType); - a= SemanticUtil.getNestedType(a, SemanticUtil.REF | SemanticUtil.TDEF); - TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(tmplParams, null, map, 0); + IType a = SemanticUtil.getSimplifiedType(conversionType); + IType p = template.getType().getReturnType(); + p = getArgumentTypeForDeduction(p, a instanceof ICPPReferenceType); + a = SemanticUtil.getNestedType(a, SemanticUtil.REF | SemanticUtil.TDEF); + TemplateArgumentDeduction deduct = new TemplateArgumentDeduction(tmplParams, null, map, 0); if (!deduct.fromType(p, a, true, false)) { return null; } @@ -393,13 +390,13 @@ public class TemplateArgumentDeduction { for (int i = 0; i < length; i++) { if (result[i] == null) { final ICPPTemplateParameter tpar = tmplParams[i]; - ICPPTemplateArgument deducedArg= map.getArgument(tpar); + ICPPTemplateArgument deducedArg = map.getArgument(tpar); if (deducedArg == null) { - deducedArg= CPPTemplates.instantiateArgument(tpar.getDefaultValue(), context); + deducedArg = CPPTemplates.instantiateArgument(tpar.getDefaultValue(), context); if (!CPPTemplates.isValidArgument(deducedArg)) return null; } - result[i]= deducedArg; + result[i] = deducedArg; } } return result; @@ -409,22 +406,21 @@ public class TemplateArgumentDeduction { * Deduce arguments for a function declaration * 14.8.2.6 */ - static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template, - ICPPTemplateArgument[] args, ICPPFunctionType ftype, CPPTemplateParameterMap map) - throws DOMException { + static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template, ICPPTemplateArgument[] args, + ICPPFunctionType ftype, CPPTemplateParameterMap map) throws DOMException { final ICPPTemplateParameter[] tmplParams = template.getTemplateParameters(); if (!addExplicitArguments(template, tmplParams, args, map)) return null; - IType a= SemanticUtil.getSimplifiedType(ftype); + IType a = SemanticUtil.getSimplifiedType(ftype); InstantiationContext context = new InstantiationContext(map); - IType p= CPPTemplates.instantiateType(template.getType(), context); + IType p = CPPTemplates.instantiateType(template.getType(), context); if (!SemanticUtil.isValidType(p)) return null; - TemplateArgumentDeduction deduct= - new TemplateArgumentDeduction(tmplParams, map, new CPPTemplateParameterMap(tmplParams.length), 0); + TemplateArgumentDeduction deduct = new TemplateArgumentDeduction(tmplParams, map, + new CPPTemplateParameterMap(tmplParams.length), 0); if (!deduct.fromType(p, a, false, false)) { return null; } @@ -435,7 +431,7 @@ public class TemplateArgumentDeduction { if (!verifyDeduction(tmplParams, map, true)) return null; - IType type= CPPTemplates.instantiateType(p, context); + IType type = CPPTemplates.instantiateType(p, context); if (!ftype.isSameType(type)) return null; @@ -450,37 +446,37 @@ public class TemplateArgumentDeduction { try { final int fnParCount = fnPars.length; final int fnArgCount = fnArgs.length; - int result= 0; - TemplateArgumentDeduction deduct= - new TemplateArgumentDeduction(tmplPars, new CPPTemplateParameterMap(0), new CPPTemplateParameterMap(fnParCount), 0); - IType fnParPack= null; - Set<Integer> usedTemplateParIds= new HashSet<>(); - for (int j= 0; j < fnArgCount; j++) { + int result = 0; + TemplateArgumentDeduction deduct = new TemplateArgumentDeduction(tmplPars, new CPPTemplateParameterMap(0), + new CPPTemplateParameterMap(fnParCount), 0); + IType fnParPack = null; + Set<Integer> usedTemplateParIds = new HashSet<>(); + for (int j = 0; j < fnArgCount; j++) { IType par; if (fnParPack != null) { - par= fnParPack; + par = fnParPack; deduct.incPackOffset(); - } else { + } else { if (j >= fnParCount) return -1; - par= fnPars[j]; + par = fnPars[j]; if (par instanceof ICPPParameterPackType) { if (j != fnParCount - 1) - continue; // non-deduced context + continue; // non-deduced context - par= fnParPack= ((ICPPParameterPackType) par).getType(); - deduct= new TemplateArgumentDeduction(deduct, fnArgs.length - j); + par = fnParPack = ((ICPPParameterPackType) par).getType(); + deduct = new TemplateArgumentDeduction(deduct, fnArgs.length - j); } } IType arg = fnArgs[j]; addReferencedTemplateParameters(par, usedTemplateParIds); - int cmpSpecialized= deduceForPartialOrdering(par, arg, deduct); + int cmpSpecialized = deduceForPartialOrdering(par, arg, deduct); if (cmpSpecialized < 0) return cmpSpecialized; if (cmpSpecialized > 0) - result= cmpSpecialized; + result = cmpSpecialized; } return verifyDeductionForPartialOrdering(tmplPars, usedTemplateParIds, deduct.fDeducedArgs) ? result : -1; } catch (DOMException e) { @@ -542,8 +538,8 @@ public class TemplateArgumentDeduction { * but for partial ordering purposes a template parameter may remain without a value provided * it is not used in the types being used for partial ordering. */ - private static boolean verifyDeductionForPartialOrdering(ICPPTemplateParameter[] pars, - Set<Integer> usedParIds, CPPTemplateParameterMap tpMap) { + private static boolean verifyDeductionForPartialOrdering(ICPPTemplateParameter[] pars, Set<Integer> usedParIds, + CPPTemplateParameterMap tpMap) { for (ICPPTemplateParameter tpar : pars) { if (usedParIds.contains(tpar.getParameterID())) { if (tpar.isParameterPack()) { @@ -563,19 +559,20 @@ public class TemplateArgumentDeduction { return true; } - private static int deduceForPartialOrdering(IType par, IType arg, TemplateArgumentDeduction deduct) throws DOMException { - par= getNestedType(par, TDEF); - arg= getNestedType(arg, TDEF); - boolean isMoreCVQualified= false; + private static int deduceForPartialOrdering(IType par, IType arg, TemplateArgumentDeduction deduct) + throws DOMException { + par = getNestedType(par, TDEF); + arg = getNestedType(arg, TDEF); + boolean isMoreCVQualified = false; if (par instanceof ICPPReferenceType && arg instanceof ICPPReferenceType) { - par= getNestedType(par, REF | TDEF); - arg= getNestedType(arg, REF | TDEF); - CVQualifier cvp= getCVQualifier(par); - CVQualifier cva= getCVQualifier(arg); - isMoreCVQualified= cva.isMoreQualifiedThan(cvp); + par = getNestedType(par, REF | TDEF); + arg = getNestedType(arg, REF | TDEF); + CVQualifier cvp = getCVQualifier(par); + CVQualifier cva = getCVQualifier(arg); + isMoreCVQualified = cva.isMoreQualifiedThan(cvp); } - par= getNestedType(par, TDEF | REF | ALLCVQ); - arg= getNestedType(arg, TDEF | REF | ALLCVQ); + par = getNestedType(par, TDEF | REF | ALLCVQ); + arg = getNestedType(arg, TDEF | REF | ALLCVQ); if (!deduct.fromType(par, arg, false, false)) return -1; @@ -588,21 +585,21 @@ public class TemplateArgumentDeduction { */ public static boolean addExplicitArguments(ICPPFunctionTemplate template, final ICPPTemplateParameter[] tmplParams, ICPPTemplateArgument[] tmplArgs, CPPTemplateParameterMap map) { - tmplArgs= SemanticUtil.getSimplifiedArguments(tmplArgs); - ICPPTemplateParameter tmplParam= null; - int packOffset= -1; + tmplArgs = SemanticUtil.getSimplifiedArguments(tmplArgs); + ICPPTemplateParameter tmplParam = null; + int packOffset = -1; for (int i = 0; i < tmplArgs.length; i++) { if (packOffset < 0 || tmplParam == null) { if (i >= tmplParams.length) return false; - tmplParam= tmplParams[i]; + tmplParam = tmplParams[i]; if (tmplParam.isParameterPack()) { - packOffset= i; + packOffset = i; } } - ICPPTemplateArgument tmplArg= tmplArgs[i]; - tmplArg= CPPTemplates.matchTemplateParameterAndArgument(template, tmplParam, tmplArg, map); + ICPPTemplateArgument tmplArg = tmplArgs[i]; + tmplArg = CPPTemplates.matchTemplateParameterAndArgument(template, tmplParam, tmplArg, map); if (tmplArg == null) return false; @@ -612,8 +609,8 @@ public class TemplateArgumentDeduction { } if (packOffset >= 0) { - final int packSize= tmplArgs.length- packOffset; - ICPPTemplateArgument[] pack= new ICPPTemplateArgument[packSize]; + final int packSize = tmplArgs.length - packOffset; + ICPPTemplateArgument[] pack = new ICPPTemplateArgument[packSize]; System.arraycopy(tmplArgs, packOffset, pack, 0, packSize); map.put(tmplParam, pack); } @@ -622,15 +619,15 @@ public class TemplateArgumentDeduction { private static ICPPTemplateArgument[] createArguments(CPPTemplateParameterMap map, final ICPPTemplateParameter[] tmplParams) { - List<ICPPTemplateArgument> result= new ArrayList<>(tmplParams.length); + List<ICPPTemplateArgument> result = new ArrayList<>(tmplParams.length); for (ICPPTemplateParameter tpar : tmplParams) { if (tpar.isParameterPack()) { - ICPPTemplateArgument[] deducedArgs= map.getPackExpansion(tpar); + ICPPTemplateArgument[] deducedArgs = map.getPackExpansion(tpar); if (deducedArgs == null) return null; result.addAll(Arrays.asList(deducedArgs)); } else { - ICPPTemplateArgument deducedArg= map.getArgument(tpar); + ICPPTemplateArgument deducedArg = map.getArgument(tpar); if (deducedArg == null) { return null; } @@ -649,20 +646,20 @@ public class TemplateArgumentDeduction { return findBaseInstances(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet<>()); } - private static ICPPClassType[] findBaseInstances(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, + private static ICPPClassType[] findBaseInstances(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet<Object> handled) throws DOMException { if (a instanceof ICPPTemplateInstance) { ICPPTemplateInstance inst = (ICPPTemplateInstance) a; - ICPPClassTemplate tmpl= getPrimaryTemplate(inst); + ICPPClassTemplate tmpl = getPrimaryTemplate(inst); if (pTemplate.isSameType(tmpl)) return new ICPPClassType[] { a }; } ICPPClassType[] results = ICPPClassType.EMPTY_CLASS_ARRAY; if (maxdepth-- > 0) { for (ICPPBase cppBase : a.getBases()) { - IBinding base= cppBase.getBaseClass(); + IBinding base = cppBase.getBaseClass(); if (base instanceof ICPPClassType && handled.add(base)) { - ICPPClassType[] inst= findBaseInstances((ICPPClassType) base, pTemplate, maxdepth, handled); + ICPPClassType[] inst = findBaseInstances((ICPPClassType) base, pTemplate, maxdepth, handled); results = ArrayUtil.addAll(results, inst); } } @@ -671,7 +668,7 @@ public class TemplateArgumentDeduction { } private static ICPPClassTemplate getPrimaryTemplate(ICPPTemplateInstance inst) throws DOMException { - ICPPTemplateDefinition template= inst.getTemplateDefinition(); + ICPPTemplateDefinition template = inst.getTemplateDefinition(); if (template instanceof ICPPClassTemplatePartialSpecialization) { return ((ICPPClassTemplatePartialSpecialization) template).getPrimaryClassTemplate(); } else if (template instanceof ICPPClassTemplate) { @@ -692,7 +689,7 @@ public class TemplateArgumentDeduction { private static IType getArgumentTypeForDeduction(IType type, boolean parameterIsAReferenceType) { type = SemanticUtil.getSimplifiedType(type); if (type instanceof ICPPReferenceType) { - type = ((ICPPReferenceType) type).getType(); + type = ((ICPPReferenceType) type).getType(); } IType result = type; if (!parameterIsAReferenceType) { @@ -710,23 +707,22 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from pairs of template arguments. */ - public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars, - final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map) - throws DOMException { - TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(pars, null, map, 0); + public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars, final ICPPTemplateArgument[] p, + final ICPPTemplateArgument[] a, CPPTemplateParameterMap map) throws DOMException { + TemplateArgumentDeduction deduct = new TemplateArgumentDeduction(pars, null, map, 0); if (p == null) { return false; } - boolean containsPackExpansion= false; - for (int j= 0; j < p.length; j++) { + boolean containsPackExpansion = false; + for (int j = 0; j < p.length; j++) { if (p[j].isPackExpansion()) { deduct = new TemplateArgumentDeduction(deduct, a.length - j); - containsPackExpansion= true; + containsPackExpansion = true; if (j != p.length - 1) { - return false; // A pack expansion must be the last argument to the specialization. + return false; // A pack expansion must be the last argument to the specialization. } ICPPTemplateArgument pattern = p[j].getExpansionPattern(); - for (int i= j; i < a.length; i++) { + for (int i = j; i < a.length; i++) { if (i != j) deduct.incPackOffset(); if (!deduct.fromTemplateArgument(pattern, a[i])) { @@ -736,7 +732,7 @@ public class TemplateArgumentDeduction { break; } else { if (j >= a.length) { - return false; // Not enough arguments. + return false; // Not enough arguments. } if (!deduct.fromTemplateArgument(p[j], a[j])) { return false; @@ -744,7 +740,7 @@ public class TemplateArgumentDeduction { } } if (!containsPackExpansion && p.length < a.length) - return false; // Too many arguments. + return false; // Too many arguments. return verifyDeduction(pars, map, false); } @@ -753,7 +749,7 @@ public class TemplateArgumentDeduction { InstantiationContext context = new InstantiationContext(tpMap); for (ICPPTemplateParameter tpar : pars) { if (tpar.isParameterPack()) { - ICPPTemplateArgument[] deducedArgs= tpMap.getPackExpansion(tpar); + ICPPTemplateArgument[] deducedArgs = tpMap.getPackExpansion(tpar); if (deducedArgs == null) { context.addToParameterMap(tpar, ICPPTemplateArgument.EMPTY_ARGUMENTS); } else { @@ -763,11 +759,11 @@ public class TemplateArgumentDeduction { } } } else { - ICPPTemplateArgument deducedArg= tpMap.getArgument(tpar); + ICPPTemplateArgument deducedArg = tpMap.getArgument(tpar); if (deducedArg == null && useDefaults) { - deducedArg= tpar.getDefaultValue(); + deducedArg = tpar.getDefaultValue(); if (deducedArg != null) { - deducedArg= CPPTemplates.instantiateArgument(deducedArg, context); + deducedArg = CPPTemplates.instantiateArgument(deducedArg, context); if (CPPTemplates.isValidArgument(deducedArg)) { context.addToParameterMap(tpar, deducedArg); } @@ -780,7 +776,6 @@ public class TemplateArgumentDeduction { return true; } - private final CPPTemplateParameterMap fExplicitArgs; private CPPTemplateParameterMap fDeducedArgs; private Set<Integer> fTemplateParameterPacks; @@ -789,14 +784,14 @@ public class TemplateArgumentDeduction { private TemplateArgumentDeduction(ICPPTemplateParameter[] tpars, CPPTemplateParameterMap explicit, CPPTemplateParameterMap result, int packSize) { - fExplicitArgs= explicit; - fDeducedArgs= result; - fPackSize= packSize; - fPackOffset= packSize > 0 ? 0 : -1; + fExplicitArgs = explicit; + fDeducedArgs = result; + fPackSize = packSize; + fPackOffset = packSize > 0 ? 0 : -1; for (ICPPTemplateParameter tpar : tpars) { if (tpar.isParameterPack()) { if (fTemplateParameterPacks == null) { - fTemplateParameterPacks= new HashSet<>(); + fTemplateParameterPacks = new HashSet<>(); } fTemplateParameterPacks.add(tpar.getParameterID()); } @@ -804,11 +799,11 @@ public class TemplateArgumentDeduction { } private TemplateArgumentDeduction(TemplateArgumentDeduction base, int packSize) { - fExplicitArgs= base.fExplicitArgs; - fDeducedArgs= base.fDeducedArgs; - fTemplateParameterPacks= base.fTemplateParameterPacks; - fPackSize= packSize; - fPackOffset= packSize > 0 ? 0 : -1; + fExplicitArgs = base.fExplicitArgs; + fDeducedArgs = base.fDeducedArgs; + fTemplateParameterPacks = base.fTemplateParameterPacks; + fPackSize = packSize; + fPackOffset = packSize > 0 ? 0 : -1; } private CPPTemplateParameterMap saveState() { @@ -816,7 +811,7 @@ public class TemplateArgumentDeduction { } private void restoreState(CPPTemplateParameterMap saved) { - fDeducedArgs= saved; + fDeducedArgs = saved; } private void incPackOffset() { @@ -827,18 +822,17 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from one pair of template arguments. */ - private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a) - throws DOMException { + private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a) throws DOMException { if (p.isNonTypeValue() != a.isNonTypeValue()) return false; if (p.isNonTypeValue()) { - IValue tval= p.getNonTypeValue(); + IValue tval = p.getNonTypeValue(); if (IntegralValue.referencesTemplateParameter(tval)) { - int parId= IntegralValue.isTemplateParameter(tval); + int parId = IntegralValue.isTemplateParameter(tval); if (parId >= 0) { - ICPPTemplateArgument old= fDeducedArgs.getArgument(parId, fPackOffset); + ICPPTemplateArgument old = fDeducedArgs.getArgument(parId, fPackOffset); if (old == null) { return deduce(parId, a); } @@ -848,7 +842,7 @@ public class TemplateArgumentDeduction { return true; } } - IValue sval= a.getNonTypeValue(); + IValue sval = a.getNonTypeValue(); return tval.equals(sval); } @@ -893,7 +887,8 @@ public class TemplateArgumentDeduction { if (!(a instanceof IPointerType)) return false; final IPointerType ptrA = (IPointerType) a; - if (!allowCVQConversion && (ptrP.isConst() != ptrA.isConst() || ptrP.isVolatile() != ptrA.isVolatile())) + if (!allowCVQConversion + && (ptrP.isConst() != ptrA.isConst() || ptrP.isVolatile() != ptrA.isVolatile())) return false; a = ptrA.getType(); } @@ -911,19 +906,20 @@ public class TemplateArgumentDeduction { if (!(a instanceof IArrayType)) { return false; } - IArrayType aa= (IArrayType) a; - IArrayType pa= (IArrayType) p; - IValue as= aa.getSize(); - IValue ps= pa.getSize(); + IArrayType aa = (IArrayType) a; + IArrayType pa = (IArrayType) p; + IValue as = aa.getSize(); + IValue ps = pa.getSize(); if (as != ps) { if (as == null || ps == null) return false; - int parID= IntegralValue.isTemplateParameter(ps); + int parID = IntegralValue.isTemplateParameter(ps); if (parID >= 0) { - ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset); + ICPPTemplateArgument old = fDeducedArgs.getArgument(parID, fPackOffset); if (old == null) { - if (!deduce(parID, new CPPTemplateNonTypeArgument(as, new TypeOfValueDeducedFromArraySize()))) { + if (!deduce(parID, + new CPPTemplateNonTypeArgument(as, new TypeOfValueDeducedFromArraySize()))) { return false; } } else if (!as.equals(old.getNonTypeValue())) { @@ -938,18 +934,18 @@ public class TemplateArgumentDeduction { } else if (p instanceof IQualifierType) { final CVQualifier cvqP = SemanticUtil.getCVQualifier(p); final CVQualifier cvqA = SemanticUtil.getCVQualifier(a); - CVQualifier remaining= CVQualifier.NONE; + CVQualifier remaining = CVQualifier.NONE; if (cvqP != cvqA) { if (!allowCVQConversion && !cvqA.isAtLeastAsQualifiedAs(cvqP)) return false; - remaining= cvqA.remove(cvqP); + remaining = cvqA.remove(cvqP); } p = SemanticUtil.getNestedType(p, ALLCVQ); a = SemanticUtil.getNestedType(a, ALLCVQ); if (p instanceof IQualifierType) return false; if (remaining != CVQualifier.NONE) { - a= SemanticUtil.addQualifiers(a, remaining.isConst(), remaining.isVolatile(), + a = SemanticUtil.addQualifiers(a, remaining.isConst(), remaining.isVolatile(), remaining.isRestrict()); } } else if (p instanceof ICPPFunctionType) { @@ -960,7 +956,7 @@ public class TemplateArgumentDeduction { if (a instanceof FunctionSetType) { // 14.8.2.1-6 Handling of overloaded function sets. CPPTemplateParameterMap success = null; - ICPPFunction[] fs= ((FunctionSetType) a).getFunctionSet().getBindings(); + ICPPFunction[] fs = ((FunctionSetType) a).getFunctionSet().getBindings(); for (ICPPFunction f : fs) { ICPPFunctionType fta = f.getType(); final CPPTemplateParameterMap saved = saveState(); @@ -981,8 +977,8 @@ public class TemplateArgumentDeduction { } return false; } else if (p instanceof ICPPTemplateParameter) { - ICPPTemplateArgument current= - fDeducedArgs.getArgument(((ICPPTemplateParameter) p).getParameterID(), fPackOffset); + ICPPTemplateArgument current = fDeducedArgs.getArgument(((ICPPTemplateParameter) p).getParameterID(), + fPackOffset); if (current != null) { if (current.isNonTypeValue()) return false; @@ -998,13 +994,13 @@ public class TemplateArgumentDeduction { return fromTemplateInstance((ICPPTemplateInstance) p, (ICPPTemplateInstance) a); } else if (p instanceof ICPPUnknownBinding) { if (!verifyNonDeduced) - return true; // An unknown type may match anything. + return true; // An unknown type may match anything. - // Verify that the resolved binding matches the argument type. + // Verify that the resolved binding matches the argument type. InstantiationContext context = new InstantiationContext(fDeducedArgs); IBinding binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) p, context); if (binding instanceof ICPPUnknownBinding) - return true; // An unknown type may match anything. + return true; // An unknown type may match anything. return binding instanceof IType && ((IType) binding).isSameType(a); } else { @@ -1015,16 +1011,15 @@ public class TemplateArgumentDeduction { return false; } - private boolean fromTemplateInstance(ICPPTemplateInstance pInst, ICPPTemplateInstance aInst) - throws DOMException { - ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst); - ICPPClassTemplate aTemplate= getPrimaryTemplate(aInst); + private boolean fromTemplateInstance(ICPPTemplateInstance pInst, ICPPTemplateInstance aInst) throws DOMException { + ICPPClassTemplate pTemplate = getPrimaryTemplate(pInst); + ICPPClassTemplate aTemplate = getPrimaryTemplate(aInst); if (pTemplate == null || aTemplate == null) return false; if (pTemplate instanceof ICPPTemplateTemplateParameter) { final int tparId = ((ICPPTemplateTemplateParameter) pTemplate).getParameterID(); - ICPPTemplateArgument current= fDeducedArgs.getArgument(tparId, fPackOffset); + ICPPTemplateArgument current = fDeducedArgs.getArgument(tparId, fPackOffset); if (current != null) { if (current.isNonTypeValue() || !current.getTypeValue().isSameType(aTemplate)) return false; @@ -1046,31 +1041,29 @@ public class TemplateArgumentDeduction { if (pArgs.length != aArgs.length) { if (pArgs.length == 0 || pArgs.length > aArgs.length + 1) return false; - ICPPTemplateArgument lastPParam= pArgs[pArgs.length - 1]; + ICPPTemplateArgument lastPParam = pArgs[pArgs.length - 1]; if (!lastPParam.isPackExpansion()) return false; } - ICPPTemplateArgument expansionPattern= null; - TemplateArgumentDeduction deduct= this; + ICPPTemplateArgument expansionPattern = null; + TemplateArgumentDeduction deduct = this; for (int i = 0; i < aArgs.length; i++) { ICPPTemplateArgument p; if (expansionPattern != null) { - p= expansionPattern; + p = expansionPattern; deduct.incPackOffset(); - InstantiationContext context = - new InstantiationContext(fExplicitArgs, deduct.fPackOffset); - p= CPPTemplates.instantiateArgument(p, context); + InstantiationContext context = new InstantiationContext(fExplicitArgs, deduct.fPackOffset); + p = CPPTemplates.instantiateArgument(p, context); if (!CPPTemplates.isValidArgument(p)) return false; } else { - p= pArgs[i]; + p = pArgs[i]; if (p.isPackExpansion()) { - p= expansionPattern= p.getExpansionPattern(); - deduct= new TemplateArgumentDeduction(this, aArgs.length - i); - InstantiationContext context = - new InstantiationContext(fExplicitArgs, deduct.fPackOffset); - p= CPPTemplates.instantiateArgument(p, context); + p = expansionPattern = p.getExpansionPattern(); + deduct = new TemplateArgumentDeduction(this, aArgs.length - i); + InstantiationContext context = new InstantiationContext(fExplicitArgs, deduct.fPackOffset); + p = CPPTemplates.instantiateArgument(p, context); if (!CPPTemplates.isValidArgument(p)) return false; } @@ -1081,13 +1074,10 @@ public class TemplateArgumentDeduction { return true; } - private boolean fromFunctionType(ICPPFunctionType ftp, ICPPFunctionType fta) - throws DOMException { - if (ftp.isConst() != fta.isConst() || - ftp.isVolatile() != fta.isVolatile() || - ftp.takesVarArgs() != fta.takesVarArgs() || - ftp.hasRefQualifier() != fta.hasRefQualifier() || - ftp.isRValueReference() != fta.isRValueReference()) { + private boolean fromFunctionType(ICPPFunctionType ftp, ICPPFunctionType fta) throws DOMException { + if (ftp.isConst() != fta.isConst() || ftp.isVolatile() != fta.isVolatile() + || ftp.takesVarArgs() != fta.takesVarArgs() || ftp.hasRefQualifier() != fta.hasRefQualifier() + || ftp.isRValueReference() != fta.isRValueReference()) { return false; } @@ -1101,30 +1091,28 @@ public class TemplateArgumentDeduction { return true; if (pParams.length == 0 || pParams.length > aParams.length + 1) return false; - IType lastPParam= pParams[pParams.length - 1]; + IType lastPParam = pParams[pParams.length - 1]; if (!(lastPParam instanceof ICPPParameterPackType)) return false; } - IType parameterPack= null; - TemplateArgumentDeduction deduct= this; + IType parameterPack = null; + TemplateArgumentDeduction deduct = this; for (int i = 0; i < aParams.length; i++) { IType p; if (parameterPack != null) { - p= parameterPack; + p = parameterPack; deduct.incPackOffset(); - InstantiationContext context = - new InstantiationContext(fExplicitArgs, deduct.fPackOffset); - p= CPPTemplates.instantiateType(p, context); + InstantiationContext context = new InstantiationContext(fExplicitArgs, deduct.fPackOffset); + p = CPPTemplates.instantiateType(p, context); if (!SemanticUtil.isValidType(p)) return false; } else { - p= pParams[i]; + p = pParams[i]; if (p instanceof ICPPParameterPackType) { - p= parameterPack= ((ICPPParameterPackType) p).getType(); - deduct= new TemplateArgumentDeduction(this, aParams.length - i); - InstantiationContext context = - new InstantiationContext(fExplicitArgs, deduct.fPackOffset); - p= CPPTemplates.instantiateType(p, context); + p = parameterPack = ((ICPPParameterPackType) p).getType(); + deduct = new TemplateArgumentDeduction(this, aParams.length - i); + InstantiationContext context = new InstantiationContext(fExplicitArgs, deduct.fPackOffset); + p = CPPTemplates.instantiateType(p, context); if (!SemanticUtil.isValidType(p)) return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java index 016537046de..2029bd9b9ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java @@ -37,22 +37,22 @@ public class TypeOfDependentExpression extends CPPUnknownBinding implements ICPP public TypeOfDependentExpression(ICPPEvaluation evaluation) { this(evaluation, true); } - + public TypeOfDependentExpression(ICPPEvaluation evaluation, boolean isForDecltype) { super(null); fEvaluation = evaluation; fIsForDecltype = isForDecltype; fIsForTemplateAuto = false; } - + public ICPPEvaluation getEvaluation() { return fEvaluation; } - + public boolean isForDecltype() { return fIsForDecltype; } - + public void setIsForDecltype(boolean isForDecltype) { fIsForDecltype = isForDecltype; } @@ -101,7 +101,7 @@ public class TypeOfDependentExpression extends CPPUnknownBinding implements ICPP } public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { - ICPPEvaluation eval= buffer.unmarshalEvaluation(); + ICPPEvaluation eval = buffer.unmarshalEvaluation(); if (eval != null) { boolean isForDecltype = (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; boolean isForTemplateAuto = (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfUnknownMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfUnknownMember.java index 0556f5ba72d..ab5c7e38357 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfUnknownMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfUnknownMember.java @@ -31,7 +31,7 @@ public class TypeOfUnknownMember extends CPPUnknownBinding implements ICPPUnknow private final CPPUnknownMember fMember; public TypeOfUnknownMember(CPPUnknownMember member) { - super(("decltype(" + member.getName() + ")").toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ + super(("decltype(" + member.getName() + ")").toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ fMember = member; } @@ -41,8 +41,7 @@ public class TypeOfUnknownMember extends CPPUnknownBinding implements ICPPUnknow @Override public boolean isSameType(IType type) { - return type instanceof TypeOfUnknownMember - && fMember == ((TypeOfUnknownMember) type).fMember; + return type instanceof TypeOfUnknownMember && fMember == ((TypeOfUnknownMember) type).fMember; } @Override @@ -51,11 +50,14 @@ public class TypeOfUnknownMember extends CPPUnknownBinding implements ICPPUnknow fMember.marshal(buffer); } - public static IType unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) + throws CoreException { short firstBytesForMember = buffer.getShort(); if ((firstBytesForMember & ITypeMarshalBuffer.KIND_MASK) != ITypeMarshalBuffer.UNKNOWN_MEMBER) - throw new CoreException(CCorePlugin.createStatus("Expected an unknown memebr, first bytes=" + firstBytesForMember)); //$NON-NLS-1$ - return new TypeOfUnknownMember((CPPUnknownMember) CPPUnknownMember.unmarshal(fragment, firstBytesForMember, buffer)); + throw new CoreException( + CCorePlugin.createStatus("Expected an unknown memebr, first bytes=" + firstBytesForMember)); //$NON-NLS-1$ + return new TypeOfUnknownMember( + (CPPUnknownMember) CPPUnknownMember.unmarshal(fragment, firstBytesForMember, buffer)); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java index a9730404937..c49ce2ec56d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java @@ -57,22 +57,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction; * A collection of static methods for determining type traits. */ public class TypeTraits { - private static final ICPPBasicType[] SIGNED_UNDERLYING_ENUM_TYPES = { - CPPBasicType.INT, - CPPBasicType.LONG, - CPPBasicType.LONG_LONG, - CPPBasicType.INT128 - }; - private static final ICPPBasicType[] UNSIGNED_UNDERLYING_ENUM_TYPES = { - CPPBasicType.UNSIGNED_INT, - CPPBasicType.UNSIGNED_LONG, - CPPBasicType.UNSIGNED_LONG_LONG, - CPPBasicType.UNSIGNED_INT128 - }; - - private TypeTraits() {} - + private static final ICPPBasicType[] SIGNED_UNDERLYING_ENUM_TYPES = { CPPBasicType.INT, CPPBasicType.LONG, + CPPBasicType.LONG_LONG, CPPBasicType.INT128 }; + private static final ICPPBasicType[] UNSIGNED_UNDERLYING_ENUM_TYPES = { CPPBasicType.UNSIGNED_INT, + CPPBasicType.UNSIGNED_LONG, CPPBasicType.UNSIGNED_LONG_LONG, CPPBasicType.UNSIGNED_INT128 }; + private TypeTraits() { + } public static boolean isDefaultedMethod(ICPPMethod method) { if (method instanceof ICPPInternalFunction) { @@ -86,7 +77,6 @@ public class TypeTraits { return false; } - /** * From $3.9 / 10: * A type is a literal type if it is: @@ -329,8 +319,8 @@ public class TypeTraits { if (!field.isStatic()) { IType type = field.getType(); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); - if (type instanceof ICPPClassType && !classType.isSameType(type) && - !hasTrivialCopyCtor((ICPPClassType) type)) { + if (type instanceof ICPPClassType && !classType.isSameType(type) + && !hasTrivialCopyCtor((ICPPClassType) type)) { return false; } } @@ -368,8 +358,8 @@ public class TypeTraits { if (!field.isStatic()) { IType type = field.getType(); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); - if (type instanceof ICPPClassType && !classType.isSameType(type) && - !hasTrivialDefaultConstructor((ICPPClassType) type, maxdepth - 1)) { + if (type instanceof ICPPClassType && !classType.isSameType(type) + && !hasTrivialDefaultConstructor((ICPPClassType) type, maxdepth - 1)) { return false; } } @@ -397,7 +387,7 @@ public class TypeTraits { private static boolean hasTrivialDestructor(ICPPClassType classType, Set<ICPPClassType> checkedClasses) { if (!checkedClasses.add(classType)) - return true; // Checked already. + return true; // Checked already. for (ICPPMethod method : classType.getDeclaredMethods()) { if (method.isDestructor() && !isDefaultedMethod(method)) @@ -411,8 +401,7 @@ public class TypeTraits { if (!field.isStatic()) { IType type = field.getType(); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); - if (type instanceof ICPPClassType && - !hasTrivialDestructor((ICPPClassType) type, checkedClasses)) { + if (type instanceof ICPPClassType && !hasTrivialDestructor((ICPPClassType) type, checkedClasses)) { return false; } } @@ -479,7 +468,7 @@ public class TypeTraits { if (CPPTemplates.isDependentType(type)) { return new CPPUnaryTypeTransformation(Operator.underlying_type, type); } - + type = SemanticUtil.getSimplifiedType(type); if (!(type instanceof ICPPEnumeration)) { return ProblemType.ENUMERATION_EXPECTED; @@ -519,7 +508,7 @@ public class TypeTraits { return type; } } - return types[types.length - 1]; // Assume it fits into the largest type provided. + return types[types.length - 1]; // Assume it fits into the largest type provided. } /** @@ -574,19 +563,19 @@ public class TypeTraits { /** * Returns true if 'typeToConstruct' is constructible from arguments * of type 'argumentTypes', as defined in [meta.unary.prop]. - * + * * If 'checkTrivial' is true, additionally checks if 'typeToConstruct' * is trivially constructible from said argument types. */ - public static boolean isConstructible(IType typeToConstruct, IType[] argumentTypes, - IBinding pointOfDefinition, boolean checkTrivial) { + public static boolean isConstructible(IType typeToConstruct, IType[] argumentTypes, IBinding pointOfDefinition, + boolean checkTrivial) { IType type = SemanticUtil.getSimplifiedType(typeToConstruct); if (!(type instanceof ICPPClassType)) { return true; } // Invent (the evaluation of) a type constructor expression of the form "T(declval<Args>()...)". // (The standard says a variable declaration of the form "T t(declval<Args>()...)", - // but we don't currently type-check variable initialization, and a type constructor expression + // but we don't currently type-check variable initialization, and a type constructor expression // should have the same semantics.) ICPPEvaluation[] arguments = new ICPPEvaluation[argumentTypes.length]; for (int i = 0; i < argumentTypes.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/UniqueType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/UniqueType.java index ad43f9badb9..b7fe54ba2c2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/UniqueType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/UniqueType.java @@ -22,7 +22,7 @@ class UniqueType implements IType { private boolean fForParameterPack; public UniqueType(boolean forParameterPack) { - fForParameterPack= forParameterPack; + fForParameterPack = forParameterPack; } @Override |