Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2013-01-30 19:56:20 +0000
committerSergey Prigogin2013-01-30 21:21:42 +0000
commitbe3adb5784c5b1dac1893305e0c64724f1114730 (patch)
tree259dd18de044886d83fe0a916f48d569776eeed0
parent334776a264619399ccd1e531d64ac6335930e5c3 (diff)
downloadorg.eclipse.cdt-be3adb5784c5b1dac1893305e0c64724f1114730.tar.gz
org.eclipse.cdt-be3adb5784c5b1dac1893305e0c64724f1114730.tar.xz
org.eclipse.cdt-be3adb5784c5b1dac1893305e0c64724f1114730.zip
Bug 399142. Proper signatures for types of dependent expressions.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java191
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java204
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java15
4 files changed, 224 insertions, 193 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
index 42ec1b40b31..f2097edf8d8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -45,6 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMemberClassInstance;
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.cdt.internal.core.dom.parser.cpp.semantics.TypeOfDependentExpression;
/**
* This is a utility class to help convert AST elements to Strings corresponding to
@@ -408,6 +409,8 @@ public class ASTTypeUtil {
IQualifierType qt= (IQualifierType) type;
needSpace= appendCVQ(result, needSpace, qt.isConst(), qt.isVolatile(), false);
+ } else if (type instanceof TypeOfDependentExpression) {
+ result.append(((TypeOfDependentExpression) type).getSignature());
} else if (type instanceof ISemanticProblem) {
result.append('?');
} else if (type != null) {
@@ -584,7 +587,7 @@ public class ASTTypeUtil {
if (parenthesis == null) {
parenthesis= new BitSet();
}
- parenthesis.set(postfix.size()-1);
+ parenthesis.set(postfix.size() - 1);
}
appendTypeString(tj, normalize, result);
needParenthesis= false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java
index d1d279b2628..81a51e64dd1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Google, Inc and others.
+ * Copyright (c) 2012, 2013 Google, Inc 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
@@ -11,207 +11,18 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.IValue;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
-import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
-import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.core.runtime.CoreException;
public abstract class CPPEvaluation implements ICPPEvaluation {
- private static class SignatureBuilder implements ITypeMarshalBuffer {
- private static final byte NULL_TYPE= 0;
- private static final byte UNSTORABLE_TYPE= (byte) -1;
-
- private final StringBuilder fBuffer;
-
- /**
- * Constructor for input buffer.
- */
- public SignatureBuilder() {
- fBuffer= new StringBuilder();
- }
-
- @Override
- public String toString() {
- return fBuffer.toString();
- }
-
- public char[] getSignature() {
- return CharArrayUtils.extractChars(fBuffer);
- }
-
- @Override
- public void marshalBinding(IBinding binding) throws CoreException {
- if (binding instanceof ISerializableType) {
- ((ISerializableType) binding).marshal(this);
- } else if (binding == null) {
- putByte(NULL_TYPE);
- } else {
- appendSeparator();
- if (binding instanceof ICPPBinding) {
- if (binding instanceof ICPPTemplateParameter) {
- ICPPTemplateParameter param = (ICPPTemplateParameter) binding;
- fBuffer.append(param.isParameterPack() ? '*' : '#');
- fBuffer.append(param.getParameterID());
- } else {
- fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding));
- }
- } else {
- fBuffer.append(binding.getNameCharArray());
- }
- }
- }
-
- @Override
- public void marshalType(IType type) throws CoreException {
- if (type instanceof ISerializableType) {
- ((ISerializableType) type).marshal(this);
- } else if (type == null) {
- putByte(NULL_TYPE);
- } else if (type instanceof IBinding) {
- marshalBinding((IBinding) type);
- } else {
- assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
- putByte(UNSTORABLE_TYPE);
- }
- }
-
- @Override
- public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException {
- if (eval == null) {
- putByte(NULL_TYPE);
- } else {
- eval.marshal(this, includeValues);
- }
- }
-
- @Override
- public void marshalValue(IValue value) throws CoreException {
- if (value instanceof Value) {
- ((Value) value).marshall(this);
- } else {
- putByte(NULL_TYPE);
- }
- }
-
- @Override
- public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException {
- if (arg.isNonTypeValue()) {
- putByte(VALUE);
- arg.getNonTypeEvaluation().marshal(this, true);
- } else {
- marshalType(arg.getTypeValue());
- }
- }
-
- @Override
- public void putByte(byte value) {
- appendSeparator();
- fBuffer.append(value);
- }
-
- @Override
- public void putFixedInt(int value) {
- appendSeparator();
- fBuffer.append(value);
- }
-
- @Override
- public void putInt(int value) {
- appendSeparator();
- fBuffer.append(value);
- }
-
- @Override
- public void putLong(long value) {
- appendSeparator();
- fBuffer.append(value);
- }
-
- @Override
- public void putCharArray(char[] chars) {
- appendSeparator();
- for (char c : chars) {
- fBuffer.append(c);
- }
- }
-
- private void appendSeparator() {
- if (fBuffer.length() != 0)
- fBuffer.append(' ');
- }
-
- @Override
- public IBinding unmarshalBinding() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IType unmarshalType() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ISerializableEvaluation unmarshalEvaluation() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IValue unmarshalValue() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getByte() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public CoreException unmarshallingError() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getFixedInt() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getInt() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public long getLong() throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public char[] getCharArray() throws CoreException {
- throw new UnsupportedOperationException();
- }
- }
-
CPPEvaluation() {
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java
new file mode 100644
index 00000000000..7ec523e7b46
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Google, Inc 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
+
+import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
+import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
+import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
+import org.eclipse.core.runtime.CoreException;
+
+class SignatureBuilder implements ITypeMarshalBuffer {
+ private static final byte NULL_TYPE= 0;
+ private static final byte UNSTORABLE_TYPE= (byte) -1;
+
+ private final StringBuilder fBuffer;
+
+ /**
+ * Constructor for input buffer.
+ */
+ public SignatureBuilder() {
+ fBuffer= new StringBuilder();
+ }
+
+ @Override
+ public String toString() {
+ return fBuffer.toString();
+ }
+
+ public char[] getSignature() {
+ return CharArrayUtils.extractChars(fBuffer);
+ }
+
+ @Override
+ public void marshalBinding(IBinding binding) throws CoreException {
+ if (binding instanceof ISerializableType) {
+ ((ISerializableType) binding).marshal(this);
+ } else if (binding == null) {
+ putByte(NULL_TYPE);
+ } else {
+ appendSeparator();
+ if (binding instanceof ICPPBinding) {
+ if (binding instanceof ICPPTemplateParameter) {
+ ICPPTemplateParameter param = (ICPPTemplateParameter) binding;
+ fBuffer.append(param.isParameterPack() ? '*' : '#');
+ fBuffer.append(param.getParameterID());
+ } else {
+ fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding));
+ }
+ } else {
+ fBuffer.append(binding.getNameCharArray());
+ }
+ }
+ }
+
+ @Override
+ public void marshalType(IType type) throws CoreException {
+ if (type instanceof ISerializableType) {
+ ((ISerializableType) type).marshal(this);
+ } else if (type == null) {
+ putByte(NULL_TYPE);
+ } else if (type instanceof IBinding) {
+ marshalBinding((IBinding) type);
+ } else {
+ assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ putByte(UNSTORABLE_TYPE);
+ }
+ }
+
+ @Override
+ public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException {
+ if (eval == null) {
+ putByte(NULL_TYPE);
+ } else {
+ eval.marshal(this, includeValues);
+ }
+ }
+
+ @Override
+ public void marshalValue(IValue value) throws CoreException {
+ if (value instanceof Value) {
+ ((Value) value).marshall(this);
+ } else {
+ putByte(NULL_TYPE);
+ }
+ }
+
+ @Override
+ public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException {
+ if (arg.isNonTypeValue()) {
+ putByte(VALUE);
+ arg.getNonTypeEvaluation().marshal(this, true);
+ } else {
+ marshalType(arg.getTypeValue());
+ }
+ }
+
+ @Override
+ public void putByte(byte value) {
+ appendSeparator();
+ fBuffer.append(value);
+ }
+
+ @Override
+ public void putFixedInt(int value) {
+ appendSeparator();
+ fBuffer.append(value);
+ }
+
+ @Override
+ public void putInt(int value) {
+ appendSeparator();
+ fBuffer.append(value);
+ }
+
+ @Override
+ public void putLong(long value) {
+ appendSeparator();
+ fBuffer.append(value);
+ }
+
+ @Override
+ public void putCharArray(char[] chars) {
+ appendSeparator();
+ for (char c : chars) {
+ fBuffer.append(c);
+ }
+ }
+
+ private void appendSeparator() {
+ if (fBuffer.length() != 0)
+ fBuffer.append(' ');
+ }
+
+ @Override
+ public IBinding unmarshalBinding() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IType unmarshalType() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ISerializableEvaluation unmarshalEvaluation() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IValue unmarshalValue() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getByte() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CoreException unmarshallingError() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getFixedInt() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getInt() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLong() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public char[] getCharArray() throws CoreException {
+ throw new UnsupportedOperationException();
+ }
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java
index 6fdd5259adc..d77e3e96595 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. and others.
+ * Copyright (c) 2012, 2013 Wind River Systems, Inc. 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
@@ -7,9 +7,11 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
@@ -48,6 +50,17 @@ public class TypeOfDependentExpression implements ICPPUnknownType, ISerializable
}
}
+ public char[] getSignature() {
+ SignatureBuilder buf = new SignatureBuilder();
+ try {
+ marshal(buf);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ return new char[] { '?' };
+ }
+ return buf.getSignature();
+ }
+
@Override
public void marshal(ITypeMarshalBuffer buffer) throws CoreException {
buffer.putByte(ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE);

Back to the top