diff options
author | Sergey Prigogin | 2012-12-03 20:35:43 +0000 |
---|---|---|
committer | Sergey Prigogin | 2012-12-04 18:36:07 +0000 |
commit | 530290d37a12bba4caeaa7d4c1a58d9b0a1a361b (patch) | |
tree | 474a3dcaf97c55b5a0b1cbee4ad28b239b1e3d96 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java | |
parent | e2d862e8ed3dffeec5853adcdec94ded06d5b953 (diff) | |
download | org.eclipse.cdt-530290d37a12bba4caeaa7d4c1a58d9b0a1a361b.tar.gz org.eclipse.cdt-530290d37a12bba4caeaa7d4c1a58d9b0a1a361b.tar.xz org.eclipse.cdt-530290d37a12bba4caeaa7d4c1a58d9b0a1a361b.zip |
Bug 395238. Evaluation of constexpr functions. Also few fixes related to
alias templates.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java')
-rw-r--r-- | core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java | 109 |
1 files changed, 88 insertions, 21 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index cd8d776018d..acd531befc0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -18,15 +18,19 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; 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.IASTFunctionDefinition; +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.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -38,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; 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.ICPPClassScope; @@ -52,6 +57,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.ProblemFunctionType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.core.runtime.PlatformObject; @@ -230,17 +236,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt IASTName n = getASTName(); IScope scope = CPPVisitor.getContainingScope(n); if (scope instanceof ICPPClassScope) { - ICPPASTDeclSpecifier declSpec = null; - if (definition != null) { - IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent(); - IASTFunctionDefinition def = (IASTFunctionDefinition) node; - declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier(); - } else { - IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent(); - IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node; - declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier(); - } - if (declSpec.isFriend()) { + ICPPASTDeclSpecifier declSpec = getDeclSpecifier(); + if (declSpec != null && declSpec.isFriend()) { try { while (scope instanceof ICPPClassScope) { scope = scope.getParent(); @@ -252,6 +249,19 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return scope; } + private ICPPASTDeclSpecifier getDeclSpecifier() { + if (definition != null) { + IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent(); + IASTFunctionDefinition def = (IASTFunctionDefinition) node; + return (ICPPASTDeclSpecifier) def.getDeclSpecifier(); + } else if (declarations != null && declarations.length != 0) { + IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent(); + IASTSimpleDeclaration decl = (IASTSimpleDeclaration) node; + return (ICPPASTDeclSpecifier) decl.getDeclSpecifier(); + } + return null; + } + @Override public ICPPFunctionType getType() { if (type == null) { @@ -420,9 +430,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt IASTDeclSpecifier declSpec = null; if (parent instanceof IASTSimpleDeclaration) { - declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); } else if (parent instanceof IASTFunctionDefinition) { - declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); + declSpec = ((IASTFunctionDefinition) parent).getDeclSpecifier(); } if (declSpec != null && declSpec.getStorageClass() == storage) { return true; @@ -437,19 +447,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return false; } - @Override - public boolean isDeleted() { - return isDeletedDefinition(getDefinition()); - } - - public static boolean isDeletedDefinition(IASTNode def) { + static ICPPASTFunctionDefinition getFunctionDefinition(IASTNode def) { while (def != null && !(def instanceof IASTDeclaration)) { def= def.getParent(); } if (def instanceof ICPPASTFunctionDefinition) { - return ((ICPPASTFunctionDefinition) def).isDeleted(); + return (ICPPASTFunctionDefinition) def; } - return false; + return null; } @Override @@ -511,6 +516,26 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return hasStorageClass(this, IASTDeclSpecifier.sc_auto); } + @Override + public boolean isConstexpr() { + ICPPASTDeclSpecifier declSpec = getDeclSpecifier(); + if (declSpec == null) + return false; + return declSpec.isConstexpr(); + } + + @Override + public boolean isDeleted() { + return isDeletedDefinition(getDefinition()); + } + + static boolean isDeletedDefinition(IASTNode def) { + ICPPASTFunctionDefinition functionDefinition = getFunctionDefinition(def); + if (functionDefinition != null) + return functionDefinition.isDeleted(); + return false; + } + @Override public boolean isRegister() { return hasStorageClass(this, IASTDeclSpecifier.sc_register); @@ -608,4 +633,46 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt ICPPASTFunctionDeclarator dtor = getPreferredDtor(); return dtor != null && AttributeUtil.hasNoreturnAttribute(dtor); } + + @Override + public ICPPEvaluation getReturnExpression() { + if (!isConstexpr()) + return null; + if (definition == null) + return EvalFixed.INCOMPLETE; + + IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent(); + return getReturnExpression((IASTFunctionDefinition) node); + } + + static ICPPEvaluation getReturnExpression(IASTFunctionDefinition functionDefinition) { + IASTReturnStatement returnStatement = null; + IASTStatement body = functionDefinition.getBody(); + if (body instanceof IASTReturnStatement) { + returnStatement = (IASTReturnStatement) body; + } else if (body instanceof IASTCompoundStatement) { + for (IASTStatement statement : ((IASTCompoundStatement) body).getStatements()) { + if (statement instanceof IASTReturnStatement) { + if (returnStatement != null) + return EvalFixed.INCOMPLETE; + returnStatement = (IASTReturnStatement) statement; + } + } + } + if (returnStatement == null) + return EvalFixed.INCOMPLETE; // constexpr constructors are not supported yet. + + IASTInitializerClause returnExpression = returnStatement.getReturnArgument(); + if (returnExpression instanceof ICPPASTInitializerClause) + return ((ICPPASTInitializerClause) returnExpression).getEvaluation(); + + return EvalFixed.INCOMPLETE; + } + + public static ICPPEvaluation getReturnExpression(ICPPFunction function) { + if (function instanceof ICPPComputableFunction) { + return ((ICPPComputableFunction) function).getReturnExpression(); + } + return null; + } } |