Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2018-10-15 06:01:01 +0000
committerNathan Ridge2018-10-29 02:52:37 +0000
commita00346af224c6a60a70151908790272d54d58955 (patch)
tree8f8a27490fdeb86728661972cebfc278524b53d0 /codan/org.eclipse.cdt.codan.core.cxx
parent4689fdee6829bca2938e7f9cb4e9df97b9d264e3 (diff)
downloadorg.eclipse.cdt-a00346af224c6a60a70151908790272d54d58955.tar.gz
org.eclipse.cdt-a00346af224c6a60a70151908790272d54d58955.tar.xz
org.eclipse.cdt-a00346af224c6a60a70151908790272d54d58955.zip
Bug 540112 - Perform C++14 return type deduction in ReturnChecker
As part of this change, ReturnChecker was refactored to compute the return type as an IType, which allowed for removal of some logic in ReturnChecker which duplicated CPPVisitor's type resolution work. Change-Id: I9cd8512164d650a5ee11d2e58fdae477e3c428a2
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.cxx')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java15
1 files changed, 15 insertions, 0 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 ff9f1096118..7f992fc8858 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
@@ -50,6 +50,7 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator;
import org.eclipse.cdt.core.index.IIndex;
@@ -57,6 +58,8 @@ import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
+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.CoreException;
@@ -422,4 +425,16 @@ public final class CxxAstUtils {
}
return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$
}
+
+ @SuppressWarnings("restriction")
+ public static IType getReturnType(IASTFunctionDefinition func) {
+ // We could do this with public API (func.getDeclarator().getName().resolveBinding().getType()
+ // .getReturnType()), but that would trigger resolution of the parameter types as well,
+ // which is needless extra work.
+ if (func instanceof ICPPASTFunctionDefinition) {
+ return CPPVisitor.createType(func.getDeclarator(),
+ CPPVisitor.RESOLVE_PLACEHOLDERS | CPPVisitor.ONLY_RETURN_TYPE);
+ }
+ return CVisitor.createType(func.getDeclarator(), CVisitor.ONLY_RETURN_TYPE);
+ }
}

Back to the top