Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNathan Ridge2018-10-15 02:01:01 -0400
committerNathan Ridge2018-10-28 22:52:37 -0400
commita00346af224c6a60a70151908790272d54d58955 (patch)
tree8f8a27490fdeb86728661972cebfc278524b53d0 /core
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 'core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java20
2 files changed, 29 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index 0c9a244d67..8e5d92a616 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -120,6 +120,12 @@ import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
public class CVisitor extends ASTQueries {
private static final CBasicType UNSIGNED_LONG_INT = new CBasicType(Kind.eInt, IBasicType.IS_LONG | IBasicType.IS_UNSIGNED);
+ // Flags for createType().
+
+ // Given a function declarator, compute only the return type rather than
+ // the entire function type.
+ public static final int ONLY_RETURN_TYPE = 0x1;
+
public static class CollectProblemsAction extends ASTVisitor {
{
shouldVisitDeclarations = true;
@@ -1217,6 +1223,9 @@ public class CVisitor extends ASTQueries {
* @return the IType of the IASTDeclarator parameter
*/
public static IType createType(IASTDeclarator declarator) {
+ return createType(declarator, 0);
+ }
+ public static IType createType(IASTDeclarator declarator, int flags) {
IASTDeclSpecifier declSpec = null;
IASTNode node = declarator.getParent();
@@ -1238,7 +1247,7 @@ public class CVisitor extends ASTQueries {
boolean isParameter = (node instanceof IASTParameterDeclaration || node.getParent() instanceof ICASTKnRFunctionDeclarator);
IType type = createType((ICASTDeclSpecifier) declSpec);
- type = createType(type, declarator);
+ type = createType(type, declarator, flags);
if (isParameter) {
IType paramType = type;
@@ -1271,8 +1280,8 @@ public class CVisitor extends ASTQueries {
return createType(typeId.getAbstractDeclarator());
}
- public static IType createType(IType baseType, IASTDeclarator declarator) {
- if (declarator instanceof IASTFunctionDeclarator)
+ public static IType createType(IType baseType, IASTDeclarator declarator, int flags) {
+ if (((flags & ONLY_RETURN_TYPE) == 0) && declarator instanceof IASTFunctionDeclarator)
return createType(baseType, (IASTFunctionDeclarator) declarator);
IType type = baseType;
@@ -1282,7 +1291,7 @@ public class CVisitor extends ASTQueries {
IASTDeclarator nested = declarator.getNestedDeclarator();
if (nested != null) {
- return createType(type, nested);
+ return createType(type, nested, flags);
}
return type;
}
@@ -1340,7 +1349,7 @@ public class CVisitor extends ASTQueries {
IASTDeclarator nested = declarator.getNestedDeclarator();
if (nested != null) {
- return createType(type, nested);
+ return createType(type, nested, 0);
}
return type;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index f71a7bb68d..a0590edfb7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -249,8 +249,14 @@ public class CPPVisitor extends ASTQueries {
public static final IASTInitializerClause[] NO_ARGS = {};
// Flags for createType().
+
+ // Attempt to resolve placeholders ('auto' and 'decltype(auto)').
public static final int RESOLVE_PLACEHOLDERS = 0x1;
+ // Given a function declarator, compute only the return type rather than
+ // the entire function type.
+ public static final int ONLY_RETURN_TYPE = 0x2;
+
// Common combinations of flags.
public static final int DO_NOT_RESOLVE_PLACEHOLDERS = 0;
@@ -2149,7 +2155,7 @@ public class CPPVisitor extends ASTQueries {
IType type = createType(declSpec);
type = makeConstIfConstexpr(type, declSpec, declarator);
- type = createType(type, declarator);
+ type = createType(type, declarator, flags);
// C++ specification 8.3.4.3 and 8.5.1.4
IASTNode initClause= declarator.getInitializer();
@@ -2537,6 +2543,10 @@ public class CPPVisitor extends ASTQueries {
}
if (returnType != null) {
+ if ((flags & ONLY_RETURN_TYPE) != 0) {
+ return returnType;
+ }
+
// Do not use createFunctionType() because that would decorate the return type
// with pointer operators from e.g. an 'auto &', but we have already done that
// above.
@@ -2601,7 +2611,7 @@ public class CPPVisitor extends ASTQueries {
type = qualifyType(type, declSpec);
type = makeConstIfConstexpr(type, declSpec, declarator);
// Ignore function declarator because we already handled that in createAutoFunctionType().
- return createType(type, declarator, true /* ignore function declarator */);
+ return createType(type, declarator, ONLY_RETURN_TYPE);
}
private static IType makeConstIfConstexpr(IType type, IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
@@ -2621,11 +2631,11 @@ public class CPPVisitor extends ASTQueries {
}
private static IType createType(IType baseType, IASTDeclarator declarator) {
- return createType(baseType, declarator, false);
+ return createType(baseType, declarator, 0);
}
- private static IType createType(IType baseType, IASTDeclarator declarator, boolean ignoreFunctionDeclarator) {
- if (!ignoreFunctionDeclarator && declarator instanceof ICPPASTFunctionDeclarator)
+ private static IType createType(IType baseType, IASTDeclarator declarator, int flags) {
+ if (((flags & ONLY_RETURN_TYPE) == 0) && declarator instanceof ICPPASTFunctionDeclarator)
return createFunctionType(baseType, (ICPPASTFunctionDeclarator) declarator);
IType type = baseType;

Back to the top