1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 16:56:04 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-10-04 16:09:29 -07:00
parent 3edce39739
commit c09afdc574
6 changed files with 77 additions and 85 deletions

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
@ -19,10 +19,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IValue;
/** /**
* Base class for c- and c++ enumerators. * Base class for C and C++ enumerators.
*/ */
public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, IASTAmbiguityParent { public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, IASTAmbiguityParent {
private IASTName name; private IASTName name;
private IASTExpression value; private IASTExpression value;
private IValue integralValue; private IValue integralValue;
@ -68,27 +67,26 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
} }
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitEnumerators ){ if (action.shouldVisitEnumerators) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
if( name != null ) if( !name.accept( action ) ) return false; if (name != null && !name.accept(action)) return false;
if( value != null ) if( !value.accept( action ) ) return false; if (value != null && !value.accept(action)) return false;
if( action.shouldVisitEnumerators ){ if (action.shouldVisitEnumerators) {
switch( action.leave( this ) ){ switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
return true; return true;
} }
public int getRoleForName(IASTName n) { public int getRoleForName(IASTName n) {
if (n == name) if (n == name)
return r_definition; return r_definition;
@ -97,11 +95,10 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( child == value) if (child == value) {
{ other.setPropertyInParent(child.getPropertyInParent());
other.setPropertyInParent( child.getPropertyInParent() ); other.setParent(child.getParent());
other.setParent( child.getParent() ); value = (IASTExpression) other;
value = (IASTExpression) other;
} }
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -20,11 +20,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CPPASTDeclarationStatement extends ASTNode implements public class CPPASTDeclarationStatement extends ASTNode
IASTDeclarationStatement, IASTAmbiguityParent { implements IASTDeclarationStatement, IASTAmbiguityParent {
private IASTDeclaration declaration; private IASTDeclaration declaration;
public CPPASTDeclarationStatement() { public CPPASTDeclarationStatement() {
} }
@ -61,30 +59,29 @@ public class CPPASTDeclarationStatement extends ASTNode implements
} }
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitStatements ){ if (action.shouldVisitStatements) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
if( declaration != null ) if( !declaration.accept( action ) ) return false; if (declaration != null && !declaration.accept(action)) return false;
if( action.shouldVisitStatements ){ if (action.shouldVisitStatements) {
switch( action.leave( this ) ){ switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
return true; return true;
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( declaration == child ) if (declaration == child) {
{ other.setParent(child.getParent());
other.setParent( child.getParent() ); other.setPropertyInParent(child.getPropertyInParent());
other.setPropertyInParent( child.getPropertyInParent() );
declaration = (IASTDeclaration) other; declaration = (IASTDeclaration) other;
} }
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -20,19 +20,19 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
public class CPPASTDefaultStatement extends ASTNode implements IASTDefaultStatement { public class CPPASTDefaultStatement extends ASTNode implements IASTDefaultStatement {
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitStatements ){ if (action.shouldVisitStatements) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
if( action.shouldVisitStatements ){ if (action.shouldVisitStatements) {
switch( action.leave( this ) ){ switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
return true; return true;

View file

@ -143,7 +143,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() { public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() {
if (definition != null) { if (definition != null) {
IASTNode node = definition; IASTNode node = definition;
while(node instanceof IASTName) while (node instanceof IASTName)
node = node.getParent(); node = node.getParent();
if (node instanceof ICPPASTCompositeTypeSpecifier) if (node instanceof ICPPASTCompositeTypeSpecifier)
return (ICPPASTCompositeTypeSpecifier)node; return (ICPPASTCompositeTypeSpecifier)node;
@ -154,7 +154,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
private ICPPASTElaboratedTypeSpecifier getElaboratedTypeSpecifier() { private ICPPASTElaboratedTypeSpecifier getElaboratedTypeSpecifier() {
if (declarations != null) { if (declarations != null) {
IASTNode node = declarations[0]; IASTNode node = declarations[0];
while(node instanceof IASTName) while (node instanceof IASTName)
node = node.getParent(); node = node.getParent();
if (node instanceof ICPPASTElaboratedTypeSpecifier) if (node instanceof ICPPASTElaboratedTypeSpecifier)
return (ICPPASTElaboratedTypeSpecifier)node; return (ICPPASTElaboratedTypeSpecifier)node;
@ -180,7 +180,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
&& !getElaboratedTypeSpecifier().isFriend()) { && !getElaboratedTypeSpecifier().isFriend()) {
// 3.3.1.5 class-key identifier ; // 3.3.1.5 class-key identifier ;
} else { } else {
while(scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) { while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) {
try { try {
scope = scope.getParent(); scope = scope.getParent();
} catch (DOMException e1) { } catch (DOMException e1) {

View file

@ -6,12 +6,12 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Niefer (IBM) - Initial API and implementation * Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Mike Kucera (IBM) * Mike Kucera (IBM)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
@ -220,11 +220,11 @@ public class CPPSemantics {
* The maximum depth to search ancestors before assuming infinite looping. * The maximum depth to search ancestors before assuming infinite looping.
*/ */
public static final int MAX_INHERITANCE_DEPTH= 16; public static final int MAX_INHERITANCE_DEPTH= 16;
public static final ASTNodeProperty STRING_LOOKUP_PROPERTY = public static final ASTNodeProperty STRING_LOOKUP_PROPERTY =
new ASTNodeProperty("CPPSemantics.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$ new ASTNodeProperty("CPPSemantics.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$
public static final String EMPTY_NAME = ""; //$NON-NLS-1$ 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',' '};
private static final char[] CALL_FUNCTION = "call-function".toCharArray(); //$NON-NLS-1$ private static final char[] CALL_FUNCTION = "call-function".toCharArray(); //$NON-NLS-1$
public static final IType VOID_TYPE = new CPPBasicType(Kind.eVoid, 0); public static final IType VOID_TYPE = new CPPBasicType(Kind.eVoid, 0);
public static final IType INT_TYPE = new CPPBasicType(Kind.eInt, 0); public static final IType INT_TYPE = new CPPBasicType(Kind.eInt, 0);
@ -232,12 +232,12 @@ public class CPPSemantics {
// Set to true for debugging. // Set to true for debugging.
public static boolean traceBindingResolution = false; public static boolean traceBindingResolution = false;
public static int traceIndent= 0; public static int traceIndent= 0;
// special return value for costForFunctionCall // special return value for costForFunctionCall
private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0); private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0);
static protected IBinding resolveBinding(IASTName name) { static protected IBinding resolveBinding(IASTName name) {
if (traceBindingResolution) { if (traceBindingResolution) {
for (int i = 0; i < traceIndent; i++) for (int i = 0; i < traceIndent; i++)
System.out.print(" "); //$NON-NLS-1$ System.out.print(" "); //$NON-NLS-1$
System.out.println("Resolving " + name + ':' + ((ASTNode) name).getOffset()); //$NON-NLS-1$ System.out.println("Resolving " + name + ':' + ((ASTNode) name).getOffset()); //$NON-NLS-1$
traceIndent++; traceIndent++;
@ -245,10 +245,10 @@ public class CPPSemantics {
if (name instanceof CPPASTNameBase) { if (name instanceof CPPASTNameBase) {
((CPPASTNameBase) name).incResolutionDepth(); ((CPPASTNameBase) name).incResolutionDepth();
} }
// 1: get some context info off of the name to figure out what kind of lookup we want // 1: get some context info off of the name to figure out what kind of lookup we want
LookupData data = createLookupData(name); LookupData data = createLookupData(name);
try { try {
// 2: lookup // 2: lookup
lookup(data, null); lookup(data, null);
@ -274,7 +274,7 @@ public class CPPSemantics {
binding = postResolution(binding, data); binding = postResolution(binding, data);
if (traceBindingResolution) { if (traceBindingResolution) {
traceIndent--; traceIndent--;
for (int i = 0; i < traceIndent; i++) for (int i = 0; i < traceIndent; i++)
System.out.print(" "); //$NON-NLS-1$ 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$ " to " + DebugUtil.toStringWithClass(binding) + ':' + System.identityHashCode(binding)); //$NON-NLS-1$
@ -290,7 +290,7 @@ public class CPPSemantics {
private static IBinding postResolution(IBinding binding, LookupData data) { private static IBinding postResolution(IBinding binding, LookupData data) {
if (binding instanceof IProblemBinding) if (binding instanceof IProblemBinding)
return binding; return binding;
if (binding == null && data.checkClassContainingFriend()) { if (binding == null && data.checkClassContainingFriend()) {
// 3.4.1-10 if we don't find a name used in a friend declaration in the member declaration's class // 3.4.1-10 if we don't find a name used in a friend declaration in the member declaration's class
// we should look in the class granting friendship // we should look in the class granting friendship
@ -311,21 +311,21 @@ public class CPPSemantics {
// Explicit type conversion in functional notation // Explicit type conversion in functional notation
if (binding instanceof ICPPClassTemplate && data.astName instanceof ICPPASTTemplateId) { if (binding instanceof ICPPClassTemplate && data.astName instanceof ICPPASTTemplateId) {
final IASTNode parent = data.astName.getParent(); final IASTNode parent = data.astName.getParent();
if (parent instanceof IASTIdExpression && if (parent instanceof IASTIdExpression &&
parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
return binding; return binding;
} }
} }
/* 14.6.1-1: /* 14.6.1-1:
* Within the scope of a class template, when the name of the template is neither qualified nor * Within the scope of a class template, when the name of the template is neither qualified nor
* followed by <, it is equivalent to the name followed by the template parameters enclosed in <>. * followed by <, it is equivalent to the name followed by the template parameters enclosed in <>.
*/ */
if (binding instanceof ICPPClassTemplate && !(binding instanceof ICPPClassSpecialization) && if (binding instanceof ICPPClassTemplate && !(binding instanceof ICPPClassSpecialization) &&
!(binding instanceof ICPPTemplateParameter) && !(data.astName instanceof ICPPASTTemplateId)) { !(binding instanceof ICPPTemplateParameter) && !(data.astName instanceof ICPPASTTemplateId)) {
ASTNodeProperty prop = data.astName.getPropertyInParent(); ASTNodeProperty prop = data.astName.getPropertyInParent();
if (prop != ICPPASTTemplateId.TEMPLATE_NAME && prop != ICPPASTQualifiedName.SEGMENT_NAME) { if (prop != ICPPASTTemplateId.TEMPLATE_NAME && prop != ICPPASTQualifiedName.SEGMENT_NAME) {
// You cannot use a class template name outside of the class template scope, // You cannot use a class template name outside of the class template scope,
// mark it as a problem. // mark it as a problem.
IBinding replacement= CPPTemplates.isUsedInClassTemplateScope((ICPPClassTemplate) binding, data.astName); IBinding replacement= CPPTemplates.isUsedInClassTemplateScope((ICPPClassTemplate) binding, data.astName);
if (replacement != null) { if (replacement != null) {
@ -369,7 +369,7 @@ public class CPPSemantics {
} }
} }
} }
if (binding instanceof IType) { if (binding instanceof IType) {
IType t = getNestedType((IType) binding, TDEF); IType t = getNestedType((IType) binding, TDEF);
if (t instanceof ICPPClassType && convertClassToConstructor(data.astName)) { if (t instanceof ICPPClassType && convertClassToConstructor(data.astName)) {
@ -2041,8 +2041,7 @@ public class CPPSemantics {
return type; return type;
} }
if (fns.size() > 0) { if (fns.size() > 0) {
final ICPPFunction[] fnArray = fns.keyArray(ICPPFunction.class); final ICPPFunction[] fnArray = fns.keyArray(ICPPFunction.class);
if (type != null && overrulesByRelevance(data, type, fnArray)) { if (type != null && overrulesByRelevance(data, type, fnArray)) {
@ -2351,8 +2350,7 @@ public class CPPSemantics {
Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject); Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject);
if (tmp.length == 0 || tmp[0] == null) if (tmp.length == 0 || tmp[0] == null)
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
int viableCount= 0; int viableCount= 0;
for (IFunction f : tmp) { for (IFunction f : tmp) {
if (f instanceof ICPPUnknownBinding) { if (f instanceof ICPPUnknownBinding) {
@ -2681,7 +2679,7 @@ public class CPPSemantics {
return CONTAINS_DEPENDENT_TYPES; return CONTAINS_DEPENDENT_TYPES;
Context ctx= Context.ORDINARY; Context ctx= Context.ORDINARY;
if (j==0 && sourceLen == 1 && fn instanceof ICPPConstructor) { if (j == 0 && sourceLen == 1 && fn instanceof ICPPConstructor) {
if (paramType instanceof ICPPReferenceType) { if (paramType instanceof ICPPReferenceType) {
if (((ICPPConstructor) fn).getClassOwner().isSameType(getNestedType(paramType, TDEF|REF|CVTYPE))) { if (((ICPPConstructor) fn).getClassOwner().isSameType(getNestedType(paramType, TDEF|REF|CVTYPE))) {
ctx= Context.FIRST_PARAM_OF_DIRECT_COPY_CTOR; ctx= Context.FIRST_PARAM_OF_DIRECT_COPY_CTOR;
@ -3586,7 +3584,7 @@ public class CPPSemantics {
} }
return result; return result;
} }
if (obj instanceof IASTName) { if (obj instanceof IASTName) {
return addContentAssistBinding(result, ((IASTName) obj).resolveBinding()); return addContentAssistBinding(result, ((IASTName) obj).resolveBinding());
} }
@ -3615,7 +3613,7 @@ public class CPPSemantics {
Object[] items = (Object[]) data.foundItems; Object[] items = (Object[]) data.foundItems;
if (items == null) if (items == null)
return new IBinding[0]; return new IBinding[0];
ObjectSet<IBinding> set = new ObjectSet<IBinding>(items.length); ObjectSet<IBinding> set = new ObjectSet<IBinding>(items.length);
IBinding binding = null; IBinding binding = null;
for (Object item : items) { for (Object item : items) {

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Sergey Prigogin (Google) - initial API and implementation * Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom; package org.eclipse.cdt.internal.core.pdom;