1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-05-30 16:22:23 -07:00
parent 224b4ef3a3
commit 3604f812ce
18 changed files with 2296 additions and 2371 deletions

View file

@ -376,9 +376,10 @@ public class AST2BaseTest extends BaseTestCase {
protected void assertInstances(CPPNameCollector collector, IBinding binding, int num) throws Exception {
int count = 0;
for (int i = 0; i < collector.size(); i++)
for (int i = 0; i < collector.size(); i++) {
if (collector.getName(i).resolveBinding() == binding)
count++;
}
assertEquals(num, count);
}

View file

@ -127,7 +127,6 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
* Testcases on the AST.
*/
public class AST2Tests extends AST2BaseTest {
private static final int NUM_TESTS = 3;
public static TestSuite suite() {
@ -2229,18 +2228,12 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) {
IASTFunctionDefinition def1 = (IASTFunctionDefinition) tu
.getDeclarations()[0];
IFunction f = (IFunction) def1.getDeclarator().getName()
.resolveBinding();
IASTFunctionDefinition def2 = (IASTFunctionDefinition) tu
.getDeclarations()[1];
IFunction f2 = (IFunction) def2.getDeclarator().getName()
.resolveBinding();
IASTFunctionDefinition def3 = (IASTFunctionDefinition) tu
.getDeclarations()[2];
IFunction f3 = (IFunction) def3.getDeclarator().getName()
.resolveBinding();
IASTFunctionDefinition def1 = (IASTFunctionDefinition) tu.getDeclarations()[0];
IFunction f = (IFunction) def1.getDeclarator().getName().resolveBinding();
IASTFunctionDefinition def2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
IFunction f2 = (IFunction) def2.getDeclarator().getName().resolveBinding();
IASTFunctionDefinition def3 = (IASTFunctionDefinition) tu.getDeclarations()[2];
IFunction f3 = (IFunction) def3.getDeclarator().getName().resolveBinding();
IFunctionType ft = f.getType();
IFunctionType ft2 = f2.getType();
@ -2251,17 +2244,15 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(((IPointerType) ft2.getReturnType()).getType() instanceof IBasicType);
assertTrue(ft3.getReturnType() instanceof IPointerType);
assertTrue(((IPointerType) ft3.getReturnType()).getType() instanceof IFunctionType);
assertTrue(((IFunctionType) ((IPointerType) ft3.getReturnType())
.getType()).getReturnType() instanceof IBasicType);
assertTrue(((IFunctionType) ((IPointerType) ft3.getReturnType()).getType()).getReturnType()
instanceof IBasicType);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(def1.getDeclarator().getName()
.resolveBinding());
IASTName[] decls = tu.getDeclarationsInAST(def1.getDeclarator().getName().resolveBinding());
assertEquals(decls.length, 1);
assertEquals(decls[0], def1.getDeclarator().getName());
decls = tu.getDeclarationsInAST(def2.getDeclarator().getName()
.resolveBinding());
decls = tu.getDeclarationsInAST(def2.getDeclarator().getName().resolveBinding());
assertEquals(decls.length, 1);
assertEquals(decls[0], def2.getDeclarator().getName());
@ -2276,8 +2267,7 @@ public class AST2Tests extends AST2BaseTest {
// any parameter to type function returning T is adjusted to be pointer to
// function returning T
public void testParmToFunction() throws Exception {
IASTTranslationUnit tu = parse(
"int f(int g(void)) { return g();}", ParserLanguage.C); //$NON-NLS-1$
IASTTranslationUnit tu = parse("int f(int g(void)) { return g();}", ParserLanguage.C);
assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) {
IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0];
@ -2300,7 +2290,8 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(def.getDeclarator() instanceof IASTStandardFunctionDeclarator);
IASTName name_g = ((IASTStandardFunctionDeclarator) def.getDeclarator())
.getParameters()[0].getDeclarator().getName();
IASTName name_g_call = ((IASTIdExpression) ((IASTFunctionCallExpression) ((IASTReturnStatement) ((IASTCompoundStatement) def
IASTName name_g_call =
((IASTIdExpression) ((IASTFunctionCallExpression) ((IASTReturnStatement) ((IASTCompoundStatement) def
.getBody()).getStatements()[0]).getReturnValue())
.getFunctionNameExpression()).getName();
IASTName[] decls = tu.getDeclarationsInAST(name_g_call.resolveBinding());
@ -2312,15 +2303,13 @@ public class AST2Tests extends AST2BaseTest {
}
public void testArrayPointerFunction() throws Exception {
IASTTranslationUnit tu = parse(
"int (*v[])(int *x, int *y);", ParserLanguage.C); //$NON-NLS-1$
IASTTranslationUnit tu = parse("int (*v[])(int *x, int *y);", ParserLanguage.C);
assertTrue(tu.isFrozen());
for (int i = 0; i < NUM_TESTS; i++) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getNestedDeclarator().getName()
.resolveBinding();
IVariable v = (IVariable) ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0])
.getNestedDeclarator().getName().resolveBinding();
IType vt_1 = v.getType();
assertTrue(vt_1 instanceof IArrayType);
@ -2348,8 +2337,8 @@ public class AST2Tests extends AST2BaseTest {
.getDeclarators()[0]).getNestedDeclarator().getName()
.resolveBinding());
assertEquals(decls.length, 1);
assertEquals(decls[0], ((IASTStandardFunctionDeclarator) decl
.getDeclarators()[0]).getNestedDeclarator().getName());
assertEquals(decls[0], ((IASTStandardFunctionDeclarator) decl.getDeclarators()[0])
.getNestedDeclarator().getName());
tu = validateCopy(tu);
}
@ -2396,8 +2385,8 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(decls.length, 1);
assertEquals(decls[0], name_DWORD);
decls = tu.getDeclarationsInAST(((IASTNamedTypeSpecifier) decl2
.getDeclSpecifier()).getName().resolveBinding());
decls = tu.getDeclarationsInAST(((IASTNamedTypeSpecifier) decl2.getDeclSpecifier())
.getName().resolveBinding());
assertEquals(decls.length, 1);
assertEquals(decls[0], name_DWORD);
@ -7347,7 +7336,6 @@ public class AST2Tests extends AST2BaseTest {
assertFalse(((IASTPreprocessorIfdefStatement) stmts[1]).taken());
}
// void a() {
// typedef float size_t;
// sizeof(10); // wrong - getExpressionType returns float

View file

@ -13,8 +13,8 @@ package org.eclipse.cdt.core.settings.model.extension;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
public abstract class CLanguageData extends CDataObject {
protected CLanguageData() {
protected CLanguageData() {
}
// public abstract CDataObject[] getChildrenOfKind(int kind);

View file

@ -328,7 +328,6 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
* This occurs during the SetCProjectDescription Operation
*/
void switchToCachedConfigurationDescriptions() throws CoreException {
for (Map.Entry<String, ICConfigurationDescription> e : fCfgMap.entrySet()) {
if (e.getValue() instanceof CConfigurationDescription) {
CConfigurationDescription cfgDes = (CConfigurationDescription) e.getValue();
@ -401,7 +400,6 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
if (cfgDes != null) {
cfgDes.removeConfiguration();
}
}
void configurationRemoved(CConfigurationDescription des) {
@ -432,7 +430,6 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
if (getConfigurationRelations() == CONFIGS_LINK_SETTINGS_AND_ACTIVE)
fSettingCfgInfo.setConfiguration(cfg);
}
@Override
@ -559,9 +556,10 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
if (fStorage.isModified())
return true;
for(ICConfigurationDescription cfgDes : fCfgMap.values())
for (ICConfigurationDescription cfgDes : fCfgMap.values()) {
if (cfgDes.isModified())
return true;
}
return false;
}
@ -641,10 +639,11 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
@Override
public void setSessionProperty(QualifiedName name, Object value) {
if(value != null)
if (value != null) {
fPropertiesMap.put(name, value);
else
} else {
fPropertiesMap.remove(name);
}
fIsModified = true;
}
@ -735,6 +734,4 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
fIsModified = true;
}
}

View file

@ -20,7 +20,6 @@ package org.eclipse.cdt.core.dom.ast;
* @since 5.0
*/
public interface IASTNodeSelector {
/**
* Returns the name for the exact given range, or <code>null</code> if there is no such node.
* Will not return an implicit name.

View file

@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IType extends Cloneable {
public static final IType[] EMPTY_TYPE_ARRAY = new IType[0];
public static final IType[] EMPTY_TYPE_ARRAY = {};
public static final ASTTypeMatcher TYPE_MATCHER = new ASTTypeMatcher();
public Object clone();

View file

@ -15,7 +15,6 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ITypedef extends IBinding, IType {
/**
* Returns the type that this thing is a typedef of
*/

View file

@ -19,9 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IType;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPPointerToMemberType extends IPointerType {
/**
* Get the class to whose members this points to.
* Returns the class to whose members this points to.
* @return Either ICPPClassType or ICPPTeplateTypeParameter.
*/
public IType getMemberOfClass();

View file

@ -190,7 +190,8 @@ public abstract class ArithmeticConversion {
return signedType;
}
return createBasicType(signedType.getKind(), changeModifier(signedType.getModifiers(), IBasicType.IS_SIGNED, IBasicType.IS_UNSIGNED));
return createBasicType(signedType.getKind(),
changeModifier(signedType.getModifiers(), IBasicType.IS_SIGNED, IBasicType.IS_UNSIGNED));
}
private IBasicType promote(IType type, Domain domain) {

View file

@ -54,11 +54,7 @@ public class CASTBinaryExpression extends ASTNode
copy.op = op;
copy.setOperand1(operand1 == null ? null : operand1.copy(style));
copy.setOperand2(operand2 == null ? null : operand2.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override

View file

@ -30,7 +30,6 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression,
private int operator;
private IASTExpression operand;
public CASTUnaryExpression() {
}
@ -46,13 +45,9 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression,
@Override
public CASTUnaryExpression copy(CopyStyle style) {
CASTUnaryExpression copy = new CASTUnaryExpression(operator, operand == null ? null
: operand.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
CASTUnaryExpression copy =
new CASTUnaryExpression(operator, operand == null ? null : operand.copy(style));
return copy(copy, style);
}
@Override
@ -91,7 +86,7 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression,
}
}
if( operand != null ) if( !operand.accept( action ) ) return false;
if (operand != null && !operand.accept(action)) return false;
if (action.shouldVisitExpressions) {
switch (action.leave(this)) {
@ -105,8 +100,7 @@ public class CASTUnaryExpression extends ASTNode implements IASTUnaryExpression,
@Override
public void replace(IASTNode child, IASTNode other) {
if( child == operand )
{
if (child == operand) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
operand = (IASTExpression) other;

View file

@ -11,8 +11,8 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion;
public class CPPArithmeticConversion extends ArithmeticConversion {

View file

@ -23,9 +23,9 @@ 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=null;
private char[] name=null;
private IScope scope=null;
private IType type;
private char[] name;
private IScope scope;
public CPPImplicitTypedef(IType type, char[] name, IScope scope) {
super(null);
@ -135,5 +135,4 @@ public class CPPImplicitTypedef extends CPPTypedef {
public boolean isGloballyQualified() {
return true;
}
}

View file

@ -38,20 +38,20 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.PlatformObject;
/**
* Binding for a c++ function parameter
* Binding for a c++ function parameter.
*/
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);
}
}
private IType fType = null;
private IASTName[] fDeclarations = null;
private IType fType;
private IASTName[] fDeclarations;
private int fPosition;
public CPPParameter(IASTName name, int pos) {
this.fDeclarations = new IASTName[] { name };
fPosition= pos;
@ -67,17 +67,11 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
return getType() instanceof ICPPParameterPackType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations()
*/
@Override
public IASTNode[] getDeclarations() {
return fDeclarations;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
*/
@Override
public IASTNode getDefinition() {
return null;
@ -121,17 +115,12 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
@Override
public String getName() {
return new String(getNameCharArray());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
@Override
public char[] getNameCharArray() {
IASTName name = getPrimaryDeclaration();
@ -140,26 +129,17 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
return CharArrayUtils.EMPTY;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
@Override
public IScope getScope() {
return CPPVisitor.getContainingScope(getPrimaryDeclaration());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
*/
public IASTNode getPhysicalNode() {
if (fDeclarations != null)
return fDeclarations[0];
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
*/
@Override
public IType getType() {
if (fType == null && fDeclarations != null) {
@ -175,75 +155,48 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
return fType;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
*/
@Override
public boolean isStatic() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
*/
@Override
public String[] getQualifiedName() {
return new String[] { getName() };
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedNameCharArray()
*/
@Override
public char[][] getQualifiedNameCharArray() {
return new char[][] { getNameCharArray() };
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
@Override
public boolean isGloballyQualified() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
@Override
public void addDefinition(IASTNode node) {
addDeclaration(node);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
@Override
public boolean isExtern() {
// 7.1.1-5 extern can not be used in the declaration of a parameter
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
@Override
public boolean isMutable() {
// 7.1.1-8 mutable can only apply to class members
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
@Override
public boolean isAuto() {
return hasStorageClass(IASTDeclSpecifier.sc_auto);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
@Override
public boolean isRegister() {
return hasStorageClass(IASTDeclSpecifier.sc_register);

View file

@ -35,7 +35,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
private IType type;
public CPPTypedef(IASTName name) {
// bug 223020 even though qualified names are not legal, we need to deal with them.
// 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();
}
@ -105,7 +105,7 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
try {
t = (IType) super.clone();
} catch (CloneNotSupportedException e) {
//not going to happen
// Not going to happen
}
return t;
}

View file

@ -2017,7 +2017,8 @@ public class CPPVisitor extends ASTQueries {
return createAutoType(autoInitClause, declSpec, declarator);
}
private static IType createAutoType(IASTInitializerClause initClause, IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
private static IType createAutoType(IASTInitializerClause initClause, IASTDeclSpecifier declSpec,
IASTDeclarator declarator) {
// C++0x: 7.1.6.4
if (initClause == null || !autoTypeDeclSpecs.get().add(declSpec)) {
// Detected a self referring auto type, e.g.: auto x = x;

View file

@ -26,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
/**
* Methods for computing the type of an expression
*/
@ -41,7 +40,6 @@ public class ExpressionTypes {
return Conversions.lvalue_to_rvalue(type);
}
public static ValueCategory valueCategoryFromFunctionCall(ICPPFunction function) {
final ICPPFunctionType ft = function.getType();
return valueCategoryFromReturnType(ft.getReturnType());