Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java55
1 files changed, 25 insertions, 30 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
index 01284e76398..c55acdea6a7 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
@@ -59,7 +59,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.runtime.CoreException;
/**
- * Useful functions for doing code analysis on c/c++ AST
+ * Useful functions for doing code analysis on C/C++ AST.
*/
public final class CxxAstUtils {
public static class NameFinderVisitor extends ASTVisitor {
@@ -102,10 +102,11 @@ public final class CxxAstUtils {
try {
while (typeName instanceof ITypedef) {
IType t = ((ITypedef) typeName).getType();
- if (t instanceof IBinding)
+ if (t instanceof IBinding) {
typeName = (IBinding) t;
- else
+ } else {
return t;
+ }
}
} catch (Exception e) { // in CDT 6.0 getType throws DOMException
Activator.log(e);
@@ -145,33 +146,32 @@ public final class CxxAstUtils {
}
/**
- * @param astName
- * a name for the declaration
- * @param factory
- * the factory
- * @param index
- * @return
+ * @param astName the name for the declaration
+ * @param factory the factory
+ * @param index the index
+ * @return the created declaration
*/
public static IASTDeclaration createDeclaration(IASTName astName, INodeFactory factory, IIndex index) {
- // Depending on context, either a type or a declaration is easier to
- // infer
+ // Depending on context, either a type or a declaration is easier to infer.
IType inferredType = null;
IASTSimpleDeclaration declaration = null;
inferredType = tryInferTypeFromBinaryExpr(astName);
if (inferredType == null)
declaration = tryInferTypeFromFunctionCall(astName, factory, index);
- // After the inference, create the statement is needed
- if (declaration != null) { // A declaration was generated
+ // After the inference, create the statement is needed.
+ if (declaration != null) {
+ // A declaration was generated.
return declaration;
- } else if (inferredType != null) { // A type was inferred, create the
- // declaration and return it
+ } else if (inferredType != null) {
+ // A type was inferred, create the declaration and return it.
DeclarationGenerator generator = DeclarationGenerator.create(factory);
IASTDeclarator declarator = generator.createDeclaratorFromType(inferredType, astName.toCharArray());
IASTDeclSpecifier declspec = generator.createDeclSpecFromType(inferredType);
IASTSimpleDeclaration simpleDeclaration = factory.newSimpleDeclaration(declspec);
simpleDeclaration.addDeclarator(declarator);
return simpleDeclaration;
- } else { // Fallback - return a `void` declaration
+ } else {
+ // Fallback - return a `void` declaration.
IASTDeclarator declarator = factory.newDeclarator(astName.copy(CopyStyle.withLocations));
IASTSimpleDeclSpecifier declspec = factory.newSimpleDeclSpecifier();
declspec.setType(Kind.eInt);
@@ -192,7 +192,7 @@ public final class CxxAstUtils {
IASTNode binaryExpr = astName.getParent().getParent();
for (IASTNode node : binaryExpr.getChildren()) {
if (node != astName.getParent()) {
- // use this expression as type source
+ // Use this expression as type source.
return ((IASTExpression) node).getExpressionType();
}
}
@@ -239,7 +239,7 @@ public final class CxxAstUtils {
}
try {
index.acquireReadLock();
- Set<IIndexName> declSet = new HashSet<IIndexName>();
+ Set<IIndexName> declSet = new HashSet<>();
// fill declSet with proper declarations
for (IBinding b : bindings) {
if (b instanceof IFunction) {
@@ -251,7 +251,7 @@ public final class CxxAstUtils {
}
}
}
- HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap<ITranslationUnit, IASTTranslationUnit>();
+ HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap<>();
for (IIndexName decl : declSet) {
// for now, just use the first overload found
ITranslationUnit tu = getTranslationUnitFromIndexName(decl);
@@ -260,7 +260,7 @@ public final class CxxAstUtils {
}
IASTTranslationUnit ast = null;
- if(astCache.containsKey(tu)) {
+ if (astCache.containsKey(tu)) {
ast = astCache.get(tu);
} else {
ast = tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
@@ -328,9 +328,9 @@ public final class CxxAstUtils {
* @return Either a type specifier or null
*/
public static IASTCompositeTypeSpecifier getCompositeTypeFromFunction(final IASTFunctionDefinition function, final IIndex index) {
- // return value to be set via visitor
+ // Return value to be set via visitor.
final IASTCompositeTypeSpecifier returnSpecifier[] = { null };
- final HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap<ITranslationUnit, IASTTranslationUnit>();
+ final HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap<>();
function.accept(new ASTVisitor() {
{
shouldVisitDeclarators = true;
@@ -342,8 +342,7 @@ public final class CxxAstUtils {
if (!(name instanceof ICPPASTQualifiedName && name.getParent().getParent() == function))
return PROCESS_CONTINUE;
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
- // A qualified name may have 1 name, but in our case needs to
- // have 2.
+ // A qualified name may have 1 name, but in our case needs to have 2.
// The pre-last name is either a namespace or a class.
if (qname.getChildren().length < 2) {
return PROCESS_CONTINUE;
@@ -388,10 +387,6 @@ public final class CxxAstUtils {
return returnSpecifier[0];
}
- /**
- * @param body
- * @return
- */
public static boolean isThrowStatement(IASTNode body) {
if (!(body instanceof IASTExpressionStatement))
return false;
@@ -409,10 +404,10 @@ public final class CxxAstUtils {
return false;
IASTExpression functionNameExpression = ((IASTFunctionCallExpression) expression).getFunctionNameExpression();
if (functionNameExpression instanceof IASTIdExpression) {
- IASTName name = ((IASTIdExpression)functionNameExpression).getName();
+ IASTName name = ((IASTIdExpression) functionNameExpression).getName();
IBinding binding = name.resolveBinding();
- if (binding!=null && binding instanceof IFunction && ((IFunction)binding).isNoReturn()) {
+ if (binding != null && binding instanceof IFunction && ((IFunction) binding).isNoReturn()) {
return true;
}
}

Back to the top