mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +02:00
Bug 432701 - Move code that determines the value of an initializer to SemanticUtil
Change-Id: I0fcbad27155d875b420ce99cd9e9ba202448cc59 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/26418 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
ab5c43e46a
commit
6cbdabfbec
4 changed files with 48 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2014 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Nathan Ridge
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -35,6 +36,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
|
@ -220,7 +222,7 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
|
|||
return false;
|
||||
}
|
||||
|
||||
public IASTInitializer getDefaultValue() {
|
||||
public IASTInitializer getInitializer() {
|
||||
if (fDeclarations == null)
|
||||
return null;
|
||||
for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) {
|
||||
|
@ -236,7 +238,7 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
|
|||
|
||||
@Override
|
||||
public boolean hasDefaultValue() {
|
||||
return getDefaultValue() != null;
|
||||
return getInitializer() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,23 +18,16 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
|
@ -340,30 +333,7 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
|
|||
if (dtor != null) {
|
||||
IASTInitializer init= dtor.getInitializer();
|
||||
if (init != null) {
|
||||
IASTInitializerClause clause= null;
|
||||
if (init instanceof IASTEqualsInitializer) {
|
||||
clause= ((IASTEqualsInitializer) init).getInitializerClause();
|
||||
} else if (init instanceof ICPPASTConstructorInitializer) {
|
||||
IASTInitializerClause[] args= ((ICPPASTConstructorInitializer) init).getArguments();
|
||||
if (args.length == 1 && args[0] instanceof IASTExpression) {
|
||||
IType type= SemanticUtil.getUltimateTypeUptoPointers(getType());
|
||||
if (type instanceof IPointerType || type instanceof IBasicType) {
|
||||
clause= args[0];
|
||||
}
|
||||
}
|
||||
} else if (init instanceof ICPPASTInitializerList) {
|
||||
ICPPASTInitializerList list= (ICPPASTInitializerList) init;
|
||||
switch (list.getSize()) {
|
||||
case 0:
|
||||
return Value.create(0);
|
||||
case 1:
|
||||
clause= list.getClauses()[0];
|
||||
}
|
||||
}
|
||||
if (clause instanceof IASTExpression) {
|
||||
return Value.create((IASTExpression) clause, maxDepth);
|
||||
}
|
||||
return Value.UNKNOWN;
|
||||
return SemanticUtil.getValueOfInitializer(init, getType(), maxDepth);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2013 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2014 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -28,11 +28,15 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
|
@ -44,6 +48,8 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
|
@ -61,6 +67,7 @@ import org.eclipse.cdt.core.parser.util.CharArraySet;
|
|||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
|
||||
|
@ -755,4 +762,37 @@ public class SemanticUtil {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the initializer of a variable.
|
||||
* @param init the initializer's AST node
|
||||
* @param type the type of the variable
|
||||
* @param maxDepth maximum recursion depth
|
||||
*/
|
||||
public static IValue getValueOfInitializer(IASTInitializer init, IType type, int maxDepth) {
|
||||
IASTInitializerClause clause= null;
|
||||
if (init instanceof IASTEqualsInitializer) {
|
||||
clause= ((IASTEqualsInitializer) init).getInitializerClause();
|
||||
} else if (init instanceof ICPPASTConstructorInitializer) {
|
||||
IASTInitializerClause[] args= ((ICPPASTConstructorInitializer) init).getArguments();
|
||||
if (args.length == 1 && args[0] instanceof IASTExpression) {
|
||||
IType typeUpToPointers= SemanticUtil.getUltimateTypeUptoPointers(type);
|
||||
if (typeUpToPointers instanceof IPointerType || typeUpToPointers instanceof IBasicType) {
|
||||
clause= args[0];
|
||||
}
|
||||
}
|
||||
} else if (init instanceof ICPPASTInitializerList) {
|
||||
ICPPASTInitializerList list= (ICPPASTInitializerList) init;
|
||||
switch (list.getSize()) {
|
||||
case 0:
|
||||
return Value.create(0);
|
||||
case 1:
|
||||
clause= list.getClauses()[0];
|
||||
}
|
||||
}
|
||||
if (clause instanceof IASTExpression) {
|
||||
return Value.create((IASTExpression) clause, maxDepth);
|
||||
}
|
||||
return Value.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ public class QPropertyAttributeProposal {
|
|||
String defValue = null;
|
||||
if (param instanceof CPPParameter) {
|
||||
CPPParameter cppParam = (CPPParameter) param;
|
||||
IASTInitializer defaultValue = cppParam.getDefaultValue();
|
||||
IASTInitializer defaultValue = cppParam.getInitializer();
|
||||
if (defaultValue instanceof IASTEqualsInitializer) {
|
||||
IASTInitializerClause clause = ((IASTEqualsInitializer) defaultValue).getInitializerClause();
|
||||
defValue = clause.toString();
|
||||
|
|
Loading…
Add table
Reference in a new issue