diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index 2eca9e19471..d9db2e1e08c 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -84,6 +84,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
@@ -5429,4 +5430,41 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(offset, token.getOffset());
assertEquals(image.length(), token.getLength());
}
+
+ // int a= 1+2-3*4+10/2; // -4
+ // int b= a+4;
+ // int* c= &b;
+ // enum X {e0, e4=4, e5, e2=2, e3};
+ public void testValues() throws Exception {
+ final String code= getAboveComment();
+ boolean isCpp= false;
+ do {
+ BindingAssertionHelper bh= new BindingAssertionHelper(code, false);
+ IVariable v= (IVariable) bh.assertNonProblem("a=", 1);
+ checkValue(v.getInitialValue(), -4);
+ v= (IVariable) bh.assertNonProblem("b=", 1);
+ checkValue(v.getInitialValue(), 0);
+ v= (IVariable) bh.assertNonProblem("c=", 1);
+ assertNull(v.getInitialValue().numericalValue());
+
+ IEnumerator e= (IEnumerator) bh.assertNonProblem("e0", 2);
+ checkValue(e.getValue(), 0);
+ e= (IEnumerator) bh.assertNonProblem("e2", 2);
+ checkValue(e.getValue(), 2);
+ e= (IEnumerator) bh.assertNonProblem("e3", 2);
+ checkValue(e.getValue(), 3);
+ e= (IEnumerator) bh.assertNonProblem("e4", 2);
+ checkValue(e.getValue(), 4);
+ e= (IEnumerator) bh.assertNonProblem("e5", 2);
+ checkValue(e.getValue(), 5);
+ isCpp= !isCpp;
+ } while (isCpp);
+ }
+
+ private void checkValue(IValue initialValue, int i) {
+ assertNotNull(initialValue);
+ final Long numericalValue = initialValue.numericalValue();
+ assertNotNull(numericalValue);
+ assertEquals(i, numericalValue.intValue());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java
index 780bd51aecd..2594d6fbdbf 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java
@@ -19,10 +19,12 @@ import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
/**
@@ -373,4 +375,39 @@ public class IndexCBindingResolutionTest extends IndexBindingResolutionTestBase
getBindingFromASTName("a= 1", 1);
getBindingFromASTName("b= 1", 1);
}
+
+ // int a= 1+2-3*4+10/2; // -4
+ // int b= a+4;
+ // int* c= &b;
+ // enum X {e0, e4=4, e5, e2=2, e3};
+
+ // void ref() {
+ // a; b; c; e0; e2; e3; e4; e5;
+ // }
+ public void testValues() throws Exception {
+ IVariable v= (IVariable) getBindingFromASTName("a;", 1);
+ checkValue(v.getInitialValue(), -4);
+ v= (IVariable) getBindingFromASTName("b;", 1);
+ checkValue(v.getInitialValue(), 0);
+ v= (IVariable) getBindingFromASTName("c;", 1);
+ assertNull(v.getInitialValue().numericalValue());
+
+ IEnumerator e= (IEnumerator) getBindingFromASTName("e0", 2);
+ checkValue(e.getValue(), 0);
+ e= (IEnumerator) getBindingFromASTName("e2", 2);
+ checkValue(e.getValue(), 2);
+ e= (IEnumerator) getBindingFromASTName("e3", 2);
+ checkValue(e.getValue(), 3);
+ e= (IEnumerator) getBindingFromASTName("e4", 2);
+ checkValue(e.getValue(), 4);
+ e= (IEnumerator) getBindingFromASTName("e5", 2);
+ checkValue(e.getValue(), 5);
+ }
+
+ private void checkValue(IValue initialValue, int i) {
+ assertNotNull(initialValue);
+ final Long numericalValue = initialValue.numericalValue();
+ assertNotNull(numericalValue);
+ assertEquals(i, numericalValue.intValue());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java
index d8fc7e18c87..1fc40c4abef 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java
@@ -26,6 +26,8 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
+import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
@@ -1324,6 +1326,40 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
IBinding foo3= getBindingFromASTName("foo(e)", 3);
}
+ // int a= 1+2-3*4+10/2; // -4
+ // int b= a+4;
+ // int* c= &b;
+ // enum X {e0, e4=4, e5, e2=2, e3};
+
+ // void ref() {
+ // a; b; c; e0; e2; e3; e4; e5;
+ // }
+ public void testValues() throws Exception {
+ IVariable v= (IVariable) getBindingFromASTName("a;", 1);
+ checkValue(v.getInitialValue(), -4);
+ v= (IVariable) getBindingFromASTName("b;", 1);
+ checkValue(v.getInitialValue(), 0);
+ v= (IVariable) getBindingFromASTName("c;", 1);
+ assertNull(v.getInitialValue().numericalValue());
+
+ IEnumerator e= (IEnumerator) getBindingFromASTName("e0", 2);
+ checkValue(e.getValue(), 0);
+ e= (IEnumerator) getBindingFromASTName("e2", 2);
+ checkValue(e.getValue(), 2);
+ e= (IEnumerator) getBindingFromASTName("e3", 2);
+ checkValue(e.getValue(), 3);
+ e= (IEnumerator) getBindingFromASTName("e4", 2);
+ checkValue(e.getValue(), 4);
+ e= (IEnumerator) getBindingFromASTName("e5", 2);
+ checkValue(e.getValue(), 5);
+ }
+
+ private void checkValue(IValue initialValue, int i) {
+ assertNotNull(initialValue);
+ final Long numericalValue = initialValue.numericalValue();
+ assertNotNull(numericalValue);
+ assertEquals(i, numericalValue.intValue());
+ }
/* CPP assertion helpers */
/* ##################################################################### */
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java
index fe78b1db04b..52d618fb496 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java
@@ -21,10 +21,12 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
@@ -172,6 +174,27 @@ public class IndexUpdateTests extends IndexTestBase {
}
}
+ private void checkValue(String name, Long value) throws Exception {
+ fIndex.acquireReadLock();
+ try {
+ IBinding b = findBinding(name);
+ IValue v= null;
+ if (b instanceof IVariable)
+ v= ((IVariable) b).getInitialValue();
+ else if (b instanceof IEnumerator)
+ v= ((IEnumerator) b).getValue();
+ else
+ fail();
+
+ if (value == null)
+ assertNull(v);
+ else
+ assertEquals(value, v.numericalValue());
+ } finally {
+ fIndex.releaseReadLock();
+ }
+ }
+
private void checkVariable(IVariable var, String type, String[] modifiers) throws DOMException {
assertEquals(msg(), type, ASTTypeUtil.getType(var.getType()));
checkModifier(modifiers, AUTO, var.isAuto());
@@ -823,5 +846,56 @@ public class IndexUpdateTests extends IndexTestBase {
fIndex.releaseReadLock();
}
}
+
+ // int global;
+ // struct C {int mem;};
+ // enum E {e0};
+
+ // int global=1;
+ // struct C {int mem=1;};
+ // enum E {e0=1};
+
+ // int global;
+ // struct C {int mem;};
+ // enum E {e0};
+ public void testValuesC() throws Exception {
+ setupFile(3, false);
+ checkValue("global", null);
+ checkValue("C::mem", null);
+ checkValue("e0", 0L);
+ updateFile();
+ checkValue("global", 1L);
+ checkValue("C::mem", 1L);
+ checkValue("e0", 1L);
+ updateFile();
+ checkValue("global", null);
+ checkValue("C::mem", null);
+ checkValue("e0", 0L);
+ }
+ // int global;
+ // struct C {int mem;};
+ // enum E {e0};
+
+ // int global=1;
+ // struct C {int mem=1;};
+ // enum E {e0=1};
+
+ // int global;
+ // struct C {int mem;};
+ // enum E {e0};
+ public void testValuesCPP() throws Exception {
+ setupFile(3, true);
+ checkValue("global", null);
+ checkValue("C::mem", null);
+ checkValue("e0", 0L);
+ updateFile();
+ checkValue("global", 1L);
+ checkValue("C::mem", 1L);
+ checkValue("e0", 1L);
+ updateFile();
+ checkValue("global", null);
+ checkValue("C::mem", null);
+ checkValue("e0", 0L);
+ }
}
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 eb9093db230..94bdfb465db 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
@@ -47,8 +47,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* This is a utility class to help convert AST elements to Strings corresponding to the
* AST element's type.
- *
- * @author dsteffle
*/
public class ASTTypeUtil {
private static final String COMMA_SPACE = ", "; //$NON-NLS-1$
@@ -371,20 +369,17 @@ public class ASTTypeUtil {
}
}
- try {
- if (((IQualifierType) type).isConst()) {
- if (needSpace) {
- result.append(SPACE); needSpace = false;
- }
- result.append(Keywords.CONST); needSpace = true;
+ if (((IQualifierType) type).isConst()) {
+ if (needSpace) {
+ result.append(SPACE); needSpace = false;
}
- if (((IQualifierType) type).isVolatile()) {
- if (needSpace) {
- result.append(SPACE); needSpace = false;
- }
- result.append(Keywords.VOLATILE); needSpace = true;
+ result.append(Keywords.CONST); needSpace = true;
+ }
+ if (((IQualifierType) type).isVolatile()) {
+ if (needSpace) {
+ result.append(SPACE); needSpace = false;
}
- } catch (DOMException e) {
+ result.append(Keywords.VOLATILE); needSpace = true;
}
} else if (type instanceof ITypedef) {
result.append(((ITypedef) type).getNameCharArray());
@@ -552,11 +547,7 @@ public class ASTTypeUtil {
*/
public static boolean isConst(IType type) {
if (type instanceof IQualifierType) {
- try {
- return ((IQualifierType) type).isConst();
- } catch (DOMException e) {
- return false;
- }
+ return ((IQualifierType) type).isConst();
} else if (type instanceof ITypeContainer) {
try {
return isConst(((ITypeContainer) type).getType());
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java
index c4b75f6ef4b..982cabbae5d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java
@@ -6,16 +6,15 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
-
-/*
- * Created on Dec 8, 2004
- */
package org.eclipse.cdt.core.dom.ast;
/**
- * @author aniefer
+ * Interface for basic types.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IBasicType extends IType {
@@ -28,11 +27,9 @@ public interface IBasicType extends IType {
public int getType() throws DOMException;
/**
- * Returns the IASTExpression for the value of this type. May be null.
- *
- * @return IASTExpression or null
- * @throws DOMException
+ * @deprecated, types don't have values.
*/
+ @Deprecated
public IASTExpression getValue() throws DOMException;
public static final int t_unspecified = IASTSimpleDeclSpecifier.t_unspecified;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java
index 3acaf38cfab..3de619003ad 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IEnumerator.java
@@ -1,21 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
*******************************************************************************/
-
-/*
- * Created on Nov 23, 2004
- */
package org.eclipse.cdt.core.dom.ast;
/**
- * @author aniefer
+ * Interface for enumerators.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IEnumerator extends IBinding {
/**
@@ -25,4 +23,10 @@ public interface IEnumerator extends IBinding {
* @return the type of the enumeration
*/
public IType getType() throws DOMException;
+
+ /**
+ * Returns the value assigned to this enumerator.
+ * @since 5.1
+ */
+ public IValue getValue();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java
index 2924198d98d..85b4803f7ca 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java
@@ -1,12 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * Doug Schaefer (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -14,8 +15,14 @@ package org.eclipse.cdt.core.dom.ast;
* Represents a parameter to a function. The scope of the parameter is
* the function that declared this parameter.
*
- * @author Doug Schaefer
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IParameter extends IVariable {
public static final IParameter [] EMPTY_PARAMETER_ARRAY = new IParameter[0];
+
+ /**
+ * Inherited from {@link IVariable}, always returns null
.
+ * @since 5.1
+ */
+ IValue getInitialValue();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java
index 1608c7cb3c3..fc9fc2e06e1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IQualifierType.java
@@ -6,29 +6,26 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
-
-/*
- * Created on Dec 8, 2004
- */
package org.eclipse.cdt.core.dom.ast;
/**
- * @author aniefer
+ * Interface used to qualify types.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IQualifierType extends IType {
/**
- * is this a const type
- * @throws DOMException
+ * Returns whether this is a const type
*/
- public boolean isConst() throws DOMException;
+ public boolean isConst();
/**
- * is this a volatile type
- * @throws DOMException
+ * Returns whether this is a volatile type
*/
- public boolean isVolatile() throws DOMException;
+ public boolean isVolatile();
/**
* get the type that this is qualifying
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java
new file mode 100644
index 00000000000..aa3f02378a0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.ast;
+
+/**
+ * Models a value of a variable, enumerator or expression.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @since 5.1
+ */
+public interface IValue {
+ /**
+ * Returns the value as a number, or null
if this is not possible.
+ */
+ Long numericalValue();
+
+ /**
+ * Returns a canonical representation that is suitable for distinguishing
+ * constant values for the purpose of template instantiation.
+ * The representation may not be used to display the value.
+ */
+ String getCanonicalRepresentation();
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java
index 6bd00e5b88f..6f3b38dafb9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java
@@ -6,28 +6,47 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * Doug Schaefer (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
- * @author Doug Schaefer
+ * Interface for all sorts of variables: local, parameter, global, field.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IVariable extends IBinding {
/**
- * @return the type of the variable
+ * Returns the type of the variable
*/
public IType getType() throws DOMException;
+ /**
+ * Returns the value for a variable with an initializer,
+ * or null
otherwise.
+ * @since 5.1
+ */
+ public IValue getInitialValue();
/**
- * Does this function have the static storage-class specifier
- * similarily for extern, auto, register
- * @throws DOMException
+ * Returns whether this variable is declared static.
*/
public boolean isStatic() throws DOMException;
+
+ /**
+ * Returns whether this variable is declared extern.
+ */
public boolean isExtern() throws DOMException;
+
+ /**
+ * Returns whether this variable is an automatic variable.
+ */
public boolean isAuto() throws DOMException;
+
+ /**
+ * Returns whether this variable is declared register.
+ */
public boolean isRegister() throws DOMException;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java
new file mode 100644
index 00000000000..a888330d461
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IValue;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
+
+/**
+ * Base class for c- and c++ enumerators.
+ */
+public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, IASTAmbiguityParent {
+
+ private IASTName name;
+ private IASTExpression value;
+ private IValue integralValue;
+
+
+ public ASTEnumerator() {
+ }
+
+ public ASTEnumerator(IASTName name, IASTExpression value) {
+ setName(name);
+ setValue(value);
+ }
+
+ public void setName(IASTName name) {
+ this.name = name;
+ if (name != null) {
+ name.setParent(this);
+ name.setPropertyInParent(ENUMERATOR_NAME);
+ }
+ }
+
+ public IASTName getName() {
+ return name;
+ }
+
+ public void setValue(IASTExpression expression) {
+ this.value = expression;
+ if (expression != null) {
+ expression.setParent(this);
+ expression.setPropertyInParent(ENUMERATOR_VALUE);
+ }
+ }
+
+ public IASTExpression getValue() {
+ return value;
+ }
+
+ @Override
+ public boolean accept( ASTVisitor action ){
+ if( action.shouldVisitEnumerators ){
+ switch( action.visit( this ) ){
+ case ASTVisitor.PROCESS_ABORT : return false;
+ case ASTVisitor.PROCESS_SKIP : return true;
+ default : break;
+ }
+ }
+ if( name != null ) if( !name.accept( action ) ) return false;
+ if( value != null ) if( !value.accept( action ) ) return false;
+ if( action.shouldVisitEnumerators ){
+ switch( action.leave( this ) ){
+ case ASTVisitor.PROCESS_ABORT : return false;
+ case ASTVisitor.PROCESS_SKIP : return true;
+ default : break;
+ }
+ }
+ return true;
+ }
+
+
+ public int getRoleForName(IASTName n) {
+ if (n == name)
+ return r_definition;
+
+ return r_reference;
+ }
+
+ public void replace(IASTNode child, IASTNode other) {
+ if( child == value)
+ {
+ other.setPropertyInParent( child.getPropertyInParent() );
+ other.setParent( child.getParent() );
+ value = (IASTExpression) other;
+ }
+ }
+
+ public IValue getIntegralValue() {
+ if (integralValue == null) {
+ IASTNode parent= getParent();
+ if (parent instanceof IASTEnumerationSpecifier)
+ createEnumValues((IASTEnumerationSpecifier) parent);
+ if (integralValue == null) {
+ integralValue= Value.UNKNOWN;
+ }
+ }
+ return integralValue;
+ }
+
+ private void createEnumValues(IASTEnumerationSpecifier parent) {
+ IASTEnumerator[] etors= parent.getEnumerators();
+ int cv= -1;
+ boolean isknown= true;
+ for (IASTEnumerator etor : etors) {
+ cv++;
+ IASTExpression expr= etor.getValue();
+ if (expr != null) {
+ IValue val= Value.create(expr);
+ Long nv= val.numericalValue();
+ isknown= false;
+ if (nv != null) {
+ isknown= true;
+ cv= nv.intValue();
+ }
+ }
+ if (etor instanceof ASTEnumerator) {
+ ((ASTEnumerator) etor).integralValue= isknown ? Value.create(cv) : Value.UNKNOWN;
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java
index 57a4381310e..cdd0f5df12e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java
@@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
@@ -27,17 +28,17 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType;
+import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinVariable;
import org.eclipse.cdt.internal.core.dom.parser.c.CFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction;
import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitTypedef;
-import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinVariable;
import org.eclipse.cdt.internal.core.dom.parser.c.CPointerType;
import org.eclipse.cdt.internal.core.dom.parser.c.CQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPBasicType;
@@ -47,8 +48,6 @@ import org.eclipse.core.runtime.PlatformObject;
/**
* This is the IBuiltinBindingsProvider used to implement the "Other" built-in GCC symbols defined:
* http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins
- *
- * @author dsteffle
*/
public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
/**
@@ -2407,6 +2406,10 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
public IBinding getOwner() {
return null;
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
static public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter {
@@ -2499,5 +2502,9 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
public IBinding getOwner() {
return null;
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
new file mode 100644
index 00000000000..2f89b927501
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
@@ -0,0 +1,291 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser;
+
+import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
+import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.IBasicType;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
+import org.eclipse.cdt.core.dom.ast.IValue;
+import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator;
+import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException;
+
+/**
+ * Represents values of variables, enumerators or expressions. The primary purpose of the representation
+ * is to support instantiation of templates with non-type template parameters.
+ */
+public class Value implements IValue {
+ public final static IValue UNKNOWN= new Value(""); //$NON-NLS-1$
+
+ private final static IValue[] TYPICAL= {new Value(String.valueOf(0)),
+ new Value(String.valueOf(1)), new Value(String.valueOf(2)), new Value(String.valueOf(3)),
+ new Value(String.valueOf(4)), new Value(String.valueOf(5)), new Value(String.valueOf(6))};
+
+ private static class UnknownValueException extends Exception {}
+ private static UnknownValueException UNKNOWN_EX= new UnknownValueException();
+
+ private final String fValue;
+ private Value(String rep) {
+ fValue= rep;
+ }
+ public String getCanonicalRepresentation() {
+ return fValue;
+ }
+
+ public Long numericalValue() {
+ try {
+ return Long.parseLong(fValue);
+ } catch (NumberFormatException e) {
+ }
+ return null;
+ }
+
+ public static IValue create(long value) {
+ if (value >=0 && value < TYPICAL.length)
+ return TYPICAL[(int) value];
+ return new Value(String.valueOf(value));
+ }
+
+ public static IValue create(IASTExpression expr) {
+ try {
+ Object obj= evaluate(expr, 20);
+ if (obj instanceof Long)
+ return create(((Long) obj).longValue());
+ return new Value(obj.toString());
+ } catch (UnknownValueException e) {
+ }
+ return UNKNOWN;
+ }
+
+ public static IValue fromCanonicalRepresentation(String rep) {
+ if (rep.equals(UNKNOWN.getCanonicalRepresentation()))
+ return UNKNOWN;
+
+ try {
+ return create(Long.parseLong(rep));
+ } catch (NumberFormatException e) {}
+
+ return new Value(rep);
+ }
+
+ /**
+ * Computes the canonical representation of the value of the expression. Returns a {@code Long} for
+ * numerical values or a {@code String}, otherwise.
+ * @throws UnknownValueException
+ */
+ @SuppressWarnings("nls")
+ private static Object evaluate(IASTExpression e, int maxdepth) throws UnknownValueException {
+ if (maxdepth < 0 || e == null)
+ throw UNKNOWN_EX;
+
+ if (e instanceof IASTArraySubscriptExpression) {
+ IASTArraySubscriptExpression sub= (IASTArraySubscriptExpression) e;
+ return evaluate(sub.getArrayExpression(), maxdepth) + "," +
+ evaluate(sub.getSubscriptExpression(), maxdepth) + ",[]";
+ }
+ if (e instanceof IASTBinaryExpression) {
+ return evaluateBinaryExpression((IASTBinaryExpression) e, maxdepth);
+ }
+ if (e instanceof IASTUnaryExpression) {
+ return evaluateUnaryExpression((IASTUnaryExpression) e, maxdepth);
+ }
+ if (e instanceof IASTCastExpression) {
+ return evaluate(((IASTCastExpression) e).getOperand(), maxdepth);
+ }
+ if (e instanceof IASTConditionalExpression) {
+ IASTConditionalExpression cexpr= (IASTConditionalExpression) e;
+ Object o= evaluate(cexpr.getLogicalConditionExpression(), maxdepth);
+ if (o instanceof Long) {
+ Long v= (Long) o;
+ if (v.longValue() == 0) {
+ return evaluate(cexpr.getNegativeResultExpression(), maxdepth);
+ }
+ final IASTExpression pe = cexpr.getPositiveResultExpression();
+ if (pe == null) // gnu-extension allows to omit the positive expression.
+ return o;
+ return evaluate(pe, maxdepth);
+ }
+
+ final IASTExpression pe = cexpr.getPositiveResultExpression();
+ Object po= pe == null ? o : evaluate(pe, maxdepth);
+ return o + "," + evaluate(cexpr.getNegativeResultExpression(), maxdepth) + "," + po + '?';
+ }
+ if (e instanceof IASTIdExpression) {
+ if (e instanceof IASTIdExpression) {
+ IBinding b= ((IASTIdExpression) e).getName().resolveBinding();
+ if (b instanceof ICPPTemplateParameter) {
+ if (b instanceof ICPPTemplateNonTypeParameter) {
+ return evaluate((ICPPTemplateParameter) b);
+ }
+ throw UNKNOWN_EX;
+ } else if (b instanceof IVariable) {
+ IValue cv= ((IVariable) b).getInitialValue();
+ if (cv != null) {
+ return toObject(cv);
+ }
+ } else if (b instanceof IEnumerator) {
+ IValue cv= ((IEnumerator) b).getValue();
+ return toObject(cv);
+ }
+ try {
+ if (b instanceof ICPPBinding)
+ return ((ICPPBinding) b).getQualifiedName();
+ return b.getName();
+ } catch (DOMException e1) {
+ throw UNKNOWN_EX;
+ }
+ }
+ return evaluate(e, --maxdepth); // prevent recursion
+ }
+ if (e instanceof IASTLiteralExpression) {
+ if (e.getExpressionType() instanceof IBasicType) {
+ try {
+ return ExpressionEvaluator.getNumber(e.toString().toCharArray());
+ } catch (EvalException e1) {
+ throw UNKNOWN_EX;
+ }
+ }
+ return e.toString();
+ }
+ throw UNKNOWN_EX;
+ }
+
+ private static Object toObject(IValue cv) throws UnknownValueException {
+ if (cv == Value.UNKNOWN)
+ throw UNKNOWN_EX;
+
+ Long lv= cv.numericalValue();
+ if (lv != null)
+ return lv;
+ return cv.getCanonicalRepresentation();
+ }
+
+ @SuppressWarnings("nls")
+ private static String evaluate(ICPPTemplateParameter param) {
+ // mstodo add support for parameter positions first.
+ return "#" ;//+Integer.toHexString(param.getParameterPosition());
+ }
+
+ @SuppressWarnings("nls")
+ private static Object evaluateUnaryExpression(IASTUnaryExpression ue, int maxdepth) throws UnknownValueException {
+ final int unaryOp= ue.getOperator();
+ if (unaryOp == IASTUnaryExpression.op_amper || unaryOp == IASTUnaryExpression.op_star)
+ throw UNKNOWN_EX;
+
+ final Object value= evaluate(ue.getOperand(), maxdepth);
+ if (value instanceof Long) {
+ long v= (Long) value;
+ switch(unaryOp) {
+ case IASTUnaryExpression.op_prefixIncr:
+ case IASTUnaryExpression.op_postFixIncr:
+ return ++v;
+ case IASTUnaryExpression.op_prefixDecr :
+ case IASTUnaryExpression.op_postFixDecr:
+ return --v;
+ case IASTUnaryExpression.op_bracketedPrimary:
+ case IASTUnaryExpression.op_plus:
+ return value;
+ case IASTUnaryExpression.op_minus:
+ return -v;
+ case IASTUnaryExpression.op_tilde:
+ return ~v;
+ case IASTUnaryExpression.op_not:
+ return v == 0 ? 1 : 0;
+ }
+ }
+ switch (unaryOp) {
+ case IASTUnaryExpression.op_bracketedPrimary:
+ case IASTUnaryExpression.op_plus:
+ return value;
+ }
+
+ return value + "," + ASTSignatureUtil.getUnaryOperatorString(ue);
+ }
+
+ @SuppressWarnings("nls")
+ private static Object evaluateBinaryExpression(IASTBinaryExpression be, int maxdepth) throws UnknownValueException {
+ final Object o1= evaluate(be.getOperand1(), maxdepth);
+ final Object o2= evaluate(be.getOperand2(), maxdepth);
+
+ final int op= be.getOperator();
+ if (o1 instanceof Long && o2 instanceof Long) {
+ long v1= (Long) o1;
+ long v2= (Long) o2;
+ switch(op) {
+ case IASTBinaryExpression.op_multiply:
+ return v1*v2;
+ case IASTBinaryExpression.op_divide:
+ if (v2 == 0)
+ throw UNKNOWN_EX;
+ return v1/v2;
+ case IASTBinaryExpression.op_modulo:
+ if (v2 == 0)
+ throw UNKNOWN_EX;
+ return v1 % v2;
+ case IASTBinaryExpression.op_plus:
+ return v1+v2;
+ case IASTBinaryExpression.op_minus:
+ return v1-v2;
+ case IASTBinaryExpression.op_shiftLeft:
+ return v1 << v2;
+ case IASTBinaryExpression.op_shiftRight:
+ return v1 >> v2;
+ case IASTBinaryExpression.op_lessThan:
+ return v1 < v2 ? 1 : 0;
+ case IASTBinaryExpression.op_greaterThan:
+ return v1 > v2 ? 1 : 0;
+ case IASTBinaryExpression.op_lessEqual:
+ return v1 <= v2 ? 1 : 0;
+ case IASTBinaryExpression.op_greaterEqual:
+ return v1 >= v2 ? 1 : 0;
+ case IASTBinaryExpression.op_binaryAnd:
+ return v1&v2;
+ case IASTBinaryExpression.op_binaryXor:
+ return v1^v2;
+ case IASTBinaryExpression.op_binaryOr:
+ return v1|v2;
+ case IASTBinaryExpression.op_logicalAnd:
+ return v1 != 0 && v2 != 0 ? 1 : 0;
+ case IASTBinaryExpression.op_logicalOr:
+ return v1 != 0 || v2 != 0 ? 1 : 0;
+ case IASTBinaryExpression.op_equals:
+ return v1 == v2 ? 1 : 0;
+ case IASTBinaryExpression.op_notequals:
+ return v1 != v2 ? 1 : 0;
+ case IASTBinaryExpression.op_max:
+ return Math.max(v1, v2);
+ case IASTBinaryExpression.op_min:
+ return Math.min(v1, v2);
+ }
+ }
+ switch (op) {
+ case IASTBinaryExpression.op_equals:
+ return o1.equals(o2) ? 1 : 0;
+ case IASTBinaryExpression.op_notequals:
+ return !o1.equals(o2) ? 1 : 0;
+ }
+
+ return o1 + "," + o2 + "," + ASTSignatureUtil.getBinaryOperatorString(be);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java
index 77773734401..d37b3827853 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java
@@ -6,94 +6,23 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Yuan Zhang / Beth Tibbitts (IBM Research)
+ * John Camelon (IBM Rational Software) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
-import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
+import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator;
/**
- * @author jcamelon
+ * C-specific enumerator
*/
-public class CASTEnumerator extends ASTNode implements IASTEnumerator, IASTAmbiguityParent {
-
- private IASTName name;
- private IASTExpression value;
-
-
+public class CASTEnumerator extends ASTEnumerator {
public CASTEnumerator() {
+ super();
}
public CASTEnumerator(IASTName name, IASTExpression value) {
- setName(name);
- setValue(value);
+ super(name, value);
}
-
- public void setName(IASTName name) {
- this.name = name;
- if (name != null) {
- name.setParent(this);
- name.setPropertyInParent(ENUMERATOR_NAME);
- }
- }
-
- public IASTName getName() {
- return name;
- }
-
- public void setValue(IASTExpression expression) {
- this.value = expression;
- if (expression != null) {
- expression.setParent(this);
- expression.setPropertyInParent(ENUMERATOR_VALUE);
- }
- }
-
- public IASTExpression getValue() {
- return value;
- }
-
- @Override
- public boolean accept( ASTVisitor action ){
- if( action.shouldVisitEnumerators ){
- switch( action.visit( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- if( name != null ) if( !name.accept( action ) ) return false;
- if( value != null ) if( !value.accept( action ) ) return false;
- if( action.shouldVisitEnumerators ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- return true;
- }
-
-
- public int getRoleForName(IASTName n) {
- if( n == name )return r_definition;
- return r_unclear;
- }
-
- public void replace(IASTNode child, IASTNode other) {
- if( child == value)
- {
- other.setPropertyInParent( child.getPropertyInParent() );
- other.setParent( child.getParent() );
- value = (IASTExpression) other;
- }
- }
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java
index 04c2cbaa4e4..56256b09ee5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -21,23 +21,28 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.internal.core.dom.Linkage;
+import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.core.runtime.PlatformObject;
/**
- * @author aniefer
+ * C-specific binding for enumerators.
*/
public class CEnumerator extends PlatformObject implements IEnumerator {
public static class CEnumeratorProblem extends ProblemBinding implements IEnumerator {
public CEnumeratorProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg );
}
-
public IType getType() throws DOMException {
throw new DOMException( this );
}
+ public IValue getValue() {
+ return Value.UNKNOWN;
+ }
}
private final IASTName enumeratorName;
@@ -83,4 +88,12 @@ public class CEnumerator extends PlatformObject implements IEnumerator {
public IBinding getOwner() throws DOMException {
return CVisitor.findEnclosingFunction(enumeratorName);
}
+
+ public IValue getValue() {
+ IASTNode parent= enumeratorName.getParent();
+ if (parent instanceof ASTEnumerator)
+ return ((ASTEnumerator) parent).getIntegralValue();
+
+ return Value.UNKNOWN;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java
deleted file mode 100644
index da14b3b7b77..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Markus Schorn (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.parser.c;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.IVariable;
-import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-/**
- * @author aniefer
- */
-public class CExternalVariable extends PlatformObject implements ICExternalBinding, IVariable {
- private IASTTranslationUnit tu;
- private IASTName name;
- /**
- * @param name
- */
- public CExternalVariable( IASTTranslationUnit tu, IASTName name ) {
- this.name = name;
- this.tu = tu;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
- */
- public String getName() {
- return name.toString();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
- */
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
- */
- public IScope getScope() {
- return tu.getScope();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
- */
- public IType getType() {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
- */
- public boolean isStatic() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
- */
- public boolean isExtern() {
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
- */
- public boolean isAuto() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
- */
- public boolean isRegister() {
- return false;
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public IBinding getOwner() {
- return null;
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java
index dfa849d219a..746eb6a8b22 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java
@@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.core.runtime.PlatformObject;
@@ -125,4 +126,8 @@ public class CKnRParameter extends PlatformObject implements IParameter {
public IBinding getOwner() throws DOMException {
return CVisitor.findEnclosingFunction(declaration);
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java
index 432d09406ae..b6f08650087 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java
@@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
@@ -55,6 +56,9 @@ public class CParameter extends PlatformObject implements IParameter {
public boolean isRegister() throws DOMException {
throw new DOMException( this );
}
+ public IValue getInitialValue() {
+ return null;
+ }
}
private IASTName [] declarations;
@@ -197,4 +201,8 @@ public class CParameter extends PlatformObject implements IParameter {
return CVisitor.findEnclosingFunction(declarations[0]);
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java
index feb1da22935..71c5506abf2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java
@@ -16,16 +16,21 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.core.runtime.PlatformObject;
/**
@@ -52,6 +57,9 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa
public boolean isRegister() throws DOMException {
throw new DOMException( this );
}
+ public IValue getInitialValue() {
+ return null;
+ }
}
private IASTName [] declarations = null;
private IType type = null;
@@ -151,4 +159,40 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa
return CVisitor.findDeclarationOwner(declarations[0], true);
}
+
+ public IValue getInitialValue() {
+ if (declarations != null) {
+ for (IASTName decl : declarations) {
+ if (decl == null)
+ break;
+ final IValue val= getInitialValue(decl);
+ if (val != null)
+ return val;
+ }
+ }
+ return null;
+ }
+
+ private IValue getInitialValue(IASTName name) {
+ IASTDeclarator dtor= findDeclarator(name);
+ if (dtor != null) {
+ IASTInitializer init= dtor.getInitializer();
+ if (init instanceof IASTInitializerExpression) {
+ IASTExpression expr= ((IASTInitializerExpression) init).getExpression();
+ if (expr != null)
+ return Value.create(expr);
+ }
+ if (init != null)
+ return Value.UNKNOWN;
+ }
+ return null;
+ }
+
+ private IASTDeclarator findDeclarator(IASTName name) {
+ IASTNode node = name.getParent();
+ if (!(node instanceof IASTDeclarator))
+ return null;
+
+ return CVisitor.findOutermostDeclarator((IASTDeclarator) node);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java
index ef5a000d124..73848a44185 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java
@@ -6,92 +6,24 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
-import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
+import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator;
/**
- * @author jcamelon
+ * C++-specific enumerator.
*/
-public class CPPASTEnumerator extends ASTNode implements IASTEnumerator, IASTAmbiguityParent {
-
- private IASTName name;
- private IASTExpression value;
-
-
+public class CPPASTEnumerator extends ASTEnumerator {
public CPPASTEnumerator() {
+ super();
}
public CPPASTEnumerator(IASTName name, IASTExpression value) {
- setName(name);
- setValue(value);
+ super(name, value);
}
-
- public void setName(IASTName name) {
- this.name = name;
- if (name != null) {
- name.setParent(this);
- name.setPropertyInParent(ENUMERATOR_NAME);
- }
- }
-
- public IASTName getName() {
- return name;
- }
-
- public void setValue(IASTExpression expression) {
- this.value = expression;
- if (expression != null) {
- expression.setParent(this);
- expression.setPropertyInParent(ENUMERATOR_VALUE);
- }
- }
-
- public IASTExpression getValue() {
- return value;
- }
-
- @Override
- public boolean accept( ASTVisitor action ){
- if( action.shouldVisitEnumerators ){
- switch( action.visit( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- if( name != null ) if( !name.accept( action ) ) return false;
- if( value != null ) if( !value.accept( action ) ) return false;
-
- if( action.shouldVisitEnumerators ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- return true;
- }
-
- public int getRoleForName(IASTName n) {
- if( name == n )
- return r_definition;
- return r_reference;
- }
-
- public void replace(IASTNode child, IASTNode other) {
- if( child == value ) {
- other.setPropertyInParent( child.getPropertyInParent() );
- other.setParent( child.getParent() );
- value = (IASTExpression) other;
- }
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java
index 46b062cbb45..b5a188a2e02 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java
@@ -6,12 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
-/*
- * Created on Dec 10, 2004
- */
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
@@ -23,28 +20,28 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/**
- * @author aniefer
+ * Integral c++ type.
*/
public class CPPBasicType implements ICPPBasicType {
protected int qualifierBits = 0;
protected int type;
- protected IASTExpression value = null;
+ protected IASTExpression expression = null;
- public CPPBasicType( int t, int bits ){
+ public CPPBasicType(int t, int bits) {
type = t;
qualifierBits = bits;
- if( type == IBasicType.t_unspecified ){
- if( (qualifierBits & ( IS_LONG | IS_SHORT | IS_SIGNED | IS_UNSIGNED )) != 0 )
+ if (type == IBasicType.t_unspecified) {
+ if ((qualifierBits & (IS_LONG | IS_SHORT | IS_SIGNED | IS_UNSIGNED)) != 0)
type = IBasicType.t_int;
}
}
- public CPPBasicType( int t, int bits, IASTExpression val ){
+ public CPPBasicType(int t, int bits, IASTExpression fromExpression) {
type = t;
qualifierBits = bits;
- value = val;
+ expression= fromExpression;
}
public boolean isSameType( IType object ) {
@@ -116,17 +113,25 @@ public class CPPBasicType implements ICPPBasicType {
return t;
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IBasicType#getValue()
- */
+ /**
+ * @deprecated types don't have values
+ */
+ @Deprecated
public IASTExpression getValue() {
- return value;
+ return expression;
}
- public void setValue( IASTExpression val ){
- value = val;
+ public void setFromExpression(IASTExpression val) {
+ expression = val;
}
+ /**
+ * Returns the expression the type was created for, or null
.
+ */
+ public IASTExpression getCreatedFromExpression() {
+ return expression;
+ }
+
public int getQualifierBits() {
return qualifierBits;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java
index b8c64887648..1cc6e7f1773 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java
@@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -20,14 +21,17 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.internal.core.dom.Linkage;
+import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.PlatformObject;
/**
- * @author aniefer
+ * Binding for a c++ enumerator.
*/
public class CPPEnumerator extends PlatformObject implements IEnumerator, ICPPInternalBinding {
@@ -133,4 +137,12 @@ public class CPPEnumerator extends PlatformObject implements IEnumerator, ICPPIn
public IBinding getOwner() throws DOMException {
return CPPVisitor.findDeclarationOwner(enumName, true);
}
+
+ public IValue getValue() {
+ final IASTNode parent= enumName.getParent();
+ if (parent instanceof ASTEnumerator)
+ return ((ASTEnumerator) parent).getIntegralValue();
+
+ return Value.UNKNOWN;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java
index 09f70b4149c..69ccf01df65 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -15,15 +15,17 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
- * @author aniefer
+ * Binding for a specialization of a field.
*/
public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField {
private IType type = null;
+ private IValue value= null;
public CPPFieldSpecialization( IBinding orig, ICPPClassType owner, ObjectMap argMap ) {
super(orig, owner, argMap);
@@ -76,4 +78,10 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie
return getClassOwner();
}
+ public IValue getInitialValue() {
+ if (value == null) {
+ value= specializeValue(getField().getInitialValue());
+ }
+ return value;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java
index 7f2749a9e47..20219023d86 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
@@ -34,7 +35,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.PlatformObject;
/**
- * @author aniefer
+ * Binding for a c++ function parameter
*/
public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPInternalBinding {
public static class CPPParameterProblem extends ProblemBinding implements ICPPParameter {
@@ -74,6 +75,9 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
public boolean isExternC() {
return false;
}
+ public IValue getInitialValue() {
+ return null;
+ }
}
private IType type = null;
@@ -301,4 +305,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
public IBinding getOwner() throws DOMException {
return CPPVisitor.findEnclosingFunction(declarations[0]);
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java
index fa7e09d82a0..354acb4e51a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -14,11 +14,12 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.ICPPParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
- * @author aniefer
+ * Binding for a specialization of a parameter.
*/
public class CPPParameterSpecialization extends CPPSpecialization implements ICPPParameter {
private IType type = null;
@@ -83,4 +84,8 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP
public boolean isExternC() {
return false;
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java
index 33a6d15c968..d178c84846e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
@@ -31,7 +32,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.PlatformObject;
/**
- * @author aniefer
+ * Base class for all specializations in the AST. Note the specialization may also be created on behalf
+ * of the index. The index may be concurrently be accessed (read-only) from different threads. So there
+ * is a need to synchronize non-final members.
*/
public abstract class CPPSpecialization extends PlatformObject implements ICPPSpecialization, ICPPInternalBinding {
private IBinding owner;
@@ -53,7 +56,11 @@ public abstract class CPPSpecialization extends PlatformObject implements ICPPSp
return CPPTemplates.instantiateType(type, argumentMap, null);
}
}
-
+
+ public IValue specializeValue(IValue value) {
+ return CPPTemplates.instantiateValue(value, argumentMap);
+ }
+
public IBinding getSpecializedBinding() {
return specialized;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java
index bfdbcb73e38..ea9df687e46 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java
@@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Andrew Niefer (IBM Corporation) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -18,11 +19,12 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
- * @author aniefer
+ * Binding for a non-type template parameter.
*/
public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
ICPPTemplateNonTypeParameter {
@@ -87,4 +89,8 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
}
+ public IValue getInitialValue() {
+ return null;
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java
index 3aecb30f964..ba4b114a5fb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java
@@ -17,13 +17,20 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
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.ICPPVariable;
@@ -31,7 +38,9 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
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.PlatformObject;
/**
@@ -74,6 +83,9 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
public boolean isRegister() throws DOMException {
throw new DOMException(this);
}
+ public IValue getInitialValue() {
+ return null;
+ }
}
private IASTName declarations[] = null;
@@ -362,4 +374,44 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
public String toString() {
return getName();
}
+
+ public IValue getInitialValue() {
+ if (definition != null) {
+ final IValue val= getInitialValue(definition);
+ if (val != null)
+ return val;
+ }
+ if (declarations != null) {
+ for (IASTName decl : declarations) {
+ if (decl == null)
+ break;
+ final IValue val= getInitialValue(decl);
+ if (val != null)
+ return val;
+ }
+ }
+ return null;
+ }
+
+ private IValue getInitialValue(IASTName name) {
+ IASTDeclarator dtor= findDeclarator(name);
+ if (dtor != null) {
+ IASTInitializer init= dtor.getInitializer();
+ if (init instanceof IASTInitializerExpression) {
+ IASTExpression expr= ((IASTInitializerExpression) init).getExpression();
+ if (expr != null)
+ return Value.create(expr);
+ } else if (init instanceof ICPPASTConstructorInitializer) {
+ IType type= SemanticUtil.getUltimateTypeUptoPointers(getType());
+ if (type instanceof IPointerType || type instanceof IBasicType) {
+ IASTExpression expr= ((ICPPASTConstructorInitializer) init).getExpression();
+ if (expr != null)
+ return Value.create(expr);
+ }
+ }
+ if (init != null)
+ return Value.UNKNOWN;
+ }
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
index e7adbea25f8..06c6a574995 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
@@ -43,6 +43,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
@@ -872,6 +873,13 @@ public class CPPTemplates {
}
return spec;
}
+
+ public static IValue instantiateValue(IValue value, ObjectMap argMap) {
+ if (value == null)
+ return null;
+ // mstodo instantiate values
+ return value;
+ }
/**
* This method propagates the specialization of a member to the types used by the member.
@@ -1693,7 +1701,7 @@ public class CPPTemplates {
CPPASTLiteralExpression exp = new CPPASTLiteralExpression();
exp.setValue(String.valueOf(i));
CPPBasicType temp = (CPPBasicType) t.clone();
- temp.setValue(exp);
+ temp.setFromExpression(exp); // mstodo is that necessary??
args[i] = temp;
}
} else {
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 edf968bfa7e..c47dfff0fb8 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
@@ -1586,10 +1586,11 @@ public class CPPVisitor {
// Currently, CPPBasicType objects are also used to represent non-type template argument
// values. We must ensure the initializer expression is attached to the type if available.
+ // mstodo can be removed
if (declarator.getInitializer() instanceof IASTInitializerExpression) {
IType utype= getUltimateTypeUptoPointers(baseType);
if (utype instanceof CPPBasicType) {
- ((CPPBasicType)utype).setValue(((IASTInitializerExpression) declarator.getInitializer()).getExpression());
+ ((CPPBasicType)utype).setFromExpression(((IASTInitializerExpression) declarator.getInitializer()).getExpression());
}
}
@@ -1895,7 +1896,7 @@ public class CPPVisitor {
case IASTBinaryExpression.op_equals:
case IASTBinaryExpression.op_notequals:
CPPBasicType basicType= new CPPBasicType(ICPPBasicType.t_bool, 0);
- basicType.setValue(expression);
+ basicType.setFromExpression(expression);
return basicType;
case IASTBinaryExpression.op_plus:
IType t2 = getExpressionType(binary.getOperand2());
@@ -1921,7 +1922,7 @@ public class CPPVisitor {
} catch (DOMException e) {
}
basicType= new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED);
- basicType.setValue(expression);
+ basicType.setFromExpression(expression);
return basicType;
}
return t1;
@@ -1999,7 +2000,7 @@ public class CPPVisitor {
}
return new CPPPointerType(type);
} else if (type instanceof CPPBasicType) {
- ((CPPBasicType) type).setValue(expression);
+ ((CPPBasicType) type).setFromExpression(expression);
}
return type;
} else if (expression instanceof ICPPASTFieldReference) {
@@ -2161,7 +2162,7 @@ public class CPPVisitor {
if (makelong > 1) {
flags |= ICPPBasicType.IS_LONG_LONG;
GPPBasicType result = new GPPBasicType(IBasicType.t_int, flags, null);
- result.setValue(expression);
+ result.setFromExpression(expression);
return result;
}
@@ -2386,7 +2387,9 @@ public class CPPVisitor {
/**
* @param e1
* @return the first non id-expression by following values assigned to basic types.
+ * @deprecated mstodo remove
*/
+ @Deprecated
public static final IASTExpression reverseConstantPropagationLookup(IASTExpression e1) {
try {
for (int i= 0; e1 instanceof IASTIdExpression && i < 8; i++) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java
index f62d1d0cfcf..501eb609051 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java
@@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
@@ -627,8 +628,8 @@ public class Conversions {
if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_char &&
s instanceof IQualifierType) {
IType qt = ((IQualifierType) s).getType();
- if (qt instanceof IBasicType) {
- IASTExpression val = ((IBasicType) qt).getValue();
+ if (qt instanceof CPPBasicType) {
+ IASTExpression val = ((CPPBasicType) qt).getCreatedFromExpression();
canConvert = (val != null &&
val instanceof IASTLiteralExpression &&
((IASTLiteralExpression)val).getKind() == IASTLiteralExpression.lk_string_literal);
@@ -738,9 +739,10 @@ public class Conversions {
IType t = getUltimateType(trg, tHolder, true);
IType sPrev= sHolder[0], tPrev= tHolder[0];
- if (src instanceof IBasicType && trg instanceof IPointerType) {
+ if (src instanceof CPPBasicType && trg instanceof IPointerType) {
//4.10-1 an integral constant expression of integer type that evaluates to 0 can be converted to a pointer type
- IASTExpression exp = ((IBasicType)src).getValue();
+ IASTExpression exp = ((CPPBasicType)src).getCreatedFromExpression();
+ // mstodo improve by checking evaluation
if (exp instanceof IASTLiteralExpression &&
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant) {
try {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java
index 3c7ead4de10..60f553f24e6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java
@@ -32,10 +32,10 @@ public class QualifierTypeClone implements IQualifierType, ITypeContainer, IInde
}
return type;
}
- public boolean isConst() throws DOMException {
+ public boolean isConst() {
return delegate.isConst();
}
- public boolean isVolatile() throws DOMException {
+ public boolean isVolatile() {
return delegate.isVolatile();
}
public boolean isSameType(IType type) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java
index 51ecefd7a8a..ff9cd970ea8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Symbian Software Systems and others.
+ * Copyright (c) 2007, 2008 Symbian Software Systems 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:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
@@ -21,11 +21,11 @@ public class CompositeQualifierType extends CompositeTypeContainer implements IQ
super((ITypeContainer) qualifierType, cf);
}
- public boolean isConst() throws DOMException {
+ public boolean isConst() {
return ((IQualifierType)type).isConst();
}
- public boolean isVolatile() throws DOMException {
+ public boolean isVolatile() {
return ((IQualifierType)type).isVolatile();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumerator.java
index 3d20ad43b87..c4ecb8f7e6c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCEnumerator.java
@@ -1,18 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2007 Symbian Software Systems and others.
+ * Copyright (c) 2007, 2008 Symbian Software Systems 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:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@@ -25,4 +26,8 @@ class CompositeCEnumerator extends CompositeCBinding implements IEnumerator {
public IType getType() throws DOMException {
return cf.getCompositeType((IIndexType)((IEnumerator)rbinding).getType());
}
+
+ public IValue getValue() {
+ return ((IEnumerator)rbinding).getValue();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCParameter.java
index 330610ac393..4ad910c02a7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCParameter.java
@@ -1,18 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2007 Symbian Software Systems and others.
+ * Copyright (c) 2007, 2008 Symbian Software Systems 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:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@@ -44,4 +45,7 @@ class CompositeCParameter extends CompositeCBinding implements IParameter {
return ((IParameter)rbinding).isStatic();
}
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCVariable.java
index 726a9225a3e..b0660ff5299 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCVariable.java
@@ -1,17 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2007 Symbian Software Systems and others.
+ * Copyright (c) 2007, 2008 Symbian Software Systems 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:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
@@ -44,4 +45,7 @@ class CompositeCVariable extends CompositeCBinding implements IVariable {
return ((IVariable)rbinding).isStatic();
}
+ public IValue getInitialValue() {
+ return ((IVariable)rbinding).getInitialValue();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerator.java
index 918ed3f248e..4a5764339e2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerator.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@@ -25,4 +26,8 @@ class CompositeCPPEnumerator extends CompositeCPPBinding implements IEnumerator
IType type = ((IEnumerator)rbinding).getType();
return cf.getCompositeType((IIndexType)type);
}
+
+ public IValue getValue() {
+ return ((IEnumerator)rbinding).getValue();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java
index 40356e8d351..ef79fb15d70 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.index.IIndexType;
@@ -52,4 +53,8 @@ class CompositeCPPVariable extends CompositeCPPBinding implements ICPPVariable {
public boolean isStatic() throws DOMException {
return ((ICPPVariable)rbinding).isStatic();
}
+
+ public IValue getInitialValue() {
+ return ((ICPPVariable)rbinding).getInitialValue();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java
index 7bf2a887c94..65059db1b11 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ExpressionEvaluator.java
@@ -23,12 +23,12 @@ import org.eclipse.cdt.core.parser.util.CharArrayMap;
/**
* Used to evaluate expressions in preprocessor directives.
*/
-class ExpressionEvaluator {
- static class EvalException extends Exception {
+public class ExpressionEvaluator {
+ public static class EvalException extends Exception {
private int fProblemID;
private char[] fProblemArg;
- public EvalException(int problemID, char[] problemArg) {
+ private EvalException(int problemID, char[] problemArg) {
fProblemID= problemID;
fProblemArg= problemArg;
}
@@ -47,6 +47,9 @@ class ExpressionEvaluator {
private ArrayList fMacrosInDefinedExpressions= new ArrayList();
private LocationMap fLocationMap;
+ ExpressionEvaluator() {
+ }
+
public boolean evaluate(TokenList condition, CharArrayMap macroDictionary, LocationMap map) throws EvalException {
fTokens= condition.first();
fDictionary= macroDictionary;
@@ -331,8 +334,7 @@ class ExpressionEvaluator {
return 1;
}
- private long getNumber(char[] image) throws EvalException {
-
+ public static long getNumber(char[] image) throws EvalException {
// Integer constants written in binary are a non-standard extension
// supported by GCC since 4.3 and by some other C compilers
// They consist of a prefix 0b or 0B, followed by a sequence of 0 and 1 digits
@@ -409,7 +411,7 @@ class ExpressionEvaluator {
}
}
- private long getNumber(char[] tokenImage, int from, int to, int base, int problemID) throws EvalException {
+ private static long getNumber(char[] tokenImage, int from, int to, int base, int problemID) throws EvalException {
if (from == to) {
throw new EvalException(problemID, tokenImage);
}
@@ -433,7 +435,7 @@ class ExpressionEvaluator {
return result;
}
- private int getDigit(char c) {
+ private static int getDigit(char c) {
switch(c) {
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
return c-'0';
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
index 780aa4bc77e..1482c94e085 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
* Andrew Ferguson (Symbian)
@@ -90,9 +90,7 @@ import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
/**
- * The PDOM Database.
- *
- * @author Doug Schaefer
+ * Database for storing semantic information for one project.
*/
public class PDOM extends PlatformObject implements IPDOM {
/**
@@ -180,6 +178,7 @@ public class PDOM extends PlatformObject implements IPDOM {
* 71.0 - proper support for anonymous unions, bug 206450
* 72.0 - store project-relative paths for resources that belong to the project, bug 239472
* 72.1 - store flag for pure virtual methods.
+ * 73.0 - add values for variables and enumerations, bug
*/
public static final int LINKAGES = Database.DATA_AREA;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java
index ed7b51b7e7a..30b158b000f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java
@@ -6,11 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.CCorePlugin;
@@ -30,8 +29,7 @@ import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Doug Schaefer
- *
+ * Type qualifier for the index.
*/
public class PDOMQualifierType extends PDOMNode implements IQualifierType, ICQualifierType,
ITypeContainer, IIndexType {
@@ -103,7 +101,7 @@ public class PDOMQualifierType extends PDOMNode implements IQualifierType, ICQua
return pdom.getDB().getByte(record + FLAGS);
}
- public boolean isConst() throws DOMException {
+ public boolean isConst() {
try {
return (getFlags() & CONST) != 0;
} catch (CoreException e) {
@@ -112,7 +110,7 @@ public class PDOMQualifierType extends PDOMNode implements IQualifierType, ICQua
}
}
- public boolean isVolatile() throws DOMException {
+ public boolean isVolatile() {
try {
return (getFlags() & VOLATILE) != 0;
} catch (CoreException e) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java
index 80d2b83ac9b..e0d8670ae4d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumerator.java
@@ -1,42 +1,49 @@
/*******************************************************************************
- * Copyright (c) 2006 QNX Software Systems and others.
+ * Copyright (c) 2006, 2008 QNX Software Systems 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:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
+import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Doug Schaefer
- *
+ * Binding for c enumerator in the index.
*/
class PDOMCEnumerator extends PDOMBinding implements IEnumerator {
private static final int ENUMERATION = PDOMBinding.RECORD_SIZE + 0;
private static final int NEXT_ENUMERATOR = PDOMBinding.RECORD_SIZE + 4;
+ private static final int VALUE= PDOMBinding.RECORD_SIZE + 8;
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
+ protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 12;
public PDOMCEnumerator(PDOM pdom, PDOMNode parent, IEnumerator enumerator, PDOMCEnumeration enumeration)
throws CoreException {
super(pdom, parent, enumerator.getNameCharArray());
- pdom.getDB().putInt(record + ENUMERATION, enumeration.getRecord());
+
+ final Database db = pdom.getDB();
+ db.putInt(record + ENUMERATION, enumeration.getRecord());
+ storeValue(db, enumerator);
enumeration.addEnumerator(this);
}
@@ -54,6 +61,21 @@ class PDOMCEnumerator extends PDOMBinding implements IEnumerator {
return IIndexCBindingConstants.CENUMERATOR;
}
+ private void storeValue(final Database db, IEnumerator enumerator) throws CoreException {
+ IValue value= enumerator.getValue();
+ if (value != null) {
+ Long val= value.numericalValue();
+ db.putInt(record + VALUE, val == null ? -1 : val.intValue());
+ }
+ }
+
+ @Override
+ public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
+ if (newBinding instanceof IEnumerator)
+ storeValue(pdom.getDB(), (IEnumerator) newBinding);
+ }
+
+
public PDOMCEnumerator getNextEnumerator() throws CoreException {
int value = pdom.getDB().getInt(record + NEXT_ENUMERATOR);
return value != 0 ? new PDOMCEnumerator(pdom, value) : null;
@@ -73,4 +95,13 @@ class PDOMCEnumerator extends PDOMBinding implements IEnumerator {
}
}
+ public IValue getValue() {
+ try {
+ int val= pdom.getDB().getInt(record + VALUE);
+ return Value.create(val);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ return Value.UNKNOWN;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java
index ed8a740e03d..bec67249341 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
@@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
@@ -33,9 +34,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
- * A parameter to a function or a method
- *
- * @author Doug Schaefer
+ * Binding for a function parameter in the index.
*/
class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
@@ -195,4 +194,8 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
public IIndexFile getLocalToFile() throws CoreException {
return null;
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCVariable.java
index 423bc7e17a5..dfa16a4880e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCVariable.java
@@ -1,16 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 QNX Software Systems and others.
+ * Copyright (c) 2006, 2008 QNX Software Systems 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:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
* IBM Corporation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.CCorePlugin;
@@ -18,10 +17,13 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
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.IVariable;
import org.eclipse.cdt.internal.core.Util;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
+import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
@@ -29,52 +31,70 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Doug Schaefer
- *
+ * Database representation for c-variables
*/
class PDOMCVariable extends PDOMBinding implements IVariable {
/**
- * Offset of pointer to type information for this parameter
+ * Offset of pointer to type information for this variable
* (relative to the beginning of the record).
*/
private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE + 0;
-
+
+ /**
+ * Offset of pointer to value information for this variable
+ * (relative to the beginning of the record).
+ */
+ private static final int VALUE_OFFSET = PDOMBinding.RECORD_SIZE + 4;
+
/**
* Offset of annotation information (relative to the beginning of the
* record).
*/
- private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 4;
+ private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 8;
/**
* The size in bytes of a PDOMCVariable record in the database.
*/
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 5;
+ protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9;
public PDOMCVariable(PDOM pdom, PDOMNode parent, IVariable variable) throws CoreException {
super(pdom, parent, variable.getNameCharArray());
try {
+ final Database db = pdom.getDB();
setType(parent.getLinkageImpl(), variable.getType());
- pdom.getDB().putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(variable));
+ db.putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(variable));
+
+ setValue(db, variable);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
+
+ private void setValue(final Database db, IVariable variable) throws CoreException {
+ IValue val= variable.getInitialValue();
+ db.putInt(record + VALUE_OFFSET, val == null ? 0 : db.newString(val.getCanonicalRepresentation()).getRecord());
+ }
@Override
public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
if (newBinding instanceof IVariable) {
+ final Database db = pdom.getDB();
IVariable var= (IVariable) newBinding;
IType mytype= getType();
+ int valueRec= db.getInt(record + VALUE_OFFSET);
try {
IType newType= var.getType();
setType(linkage, newType);
- if (mytype != null) {
+ db.putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(var));
+ setValue(db, var);
+
+ if (mytype != null)
linkage.deleteType(mytype, record);
- }
- pdom.getDB().putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(var));
+ if (valueRec != 0)
+ db.getString(valueRec).delete();
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
@@ -110,6 +130,19 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
}
}
+ public IValue getInitialValue() {
+ try {
+ final Database db = pdom.getDB();
+ int valRec = db.getInt(record + VALUE_OFFSET);
+ if (valRec == 0)
+ return null;
+ return Value.fromCanonicalRepresentation(db.getString(valRec).getString());
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ return null;
+ }
+ }
+
public boolean isStatic() throws DOMException {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java
index 268fcda7b0d..92152a9275e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java
@@ -6,37 +6,46 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
+import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Doug Schaefer
- *
+ * Binding for a c++ enumerator in the index.
*/
class PDOMCPPEnumerator extends PDOMCPPBinding implements IEnumerator {
private static final int ENUMERATION = PDOMBinding.RECORD_SIZE + 0;
private static final int NEXT_ENUMERATOR = PDOMBinding.RECORD_SIZE + 4;
+ private static final int VALUE= PDOMBinding.RECORD_SIZE + 8;
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
-
+ protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 12;
+
public PDOMCPPEnumerator(PDOM pdom, PDOMNode parent, IEnumerator enumerator, PDOMCPPEnumeration enumeration)
throws CoreException {
super(pdom, parent, enumerator.getNameCharArray());
- pdom.getDB().putInt(record + ENUMERATION, enumeration.getRecord());
+
+ final Database db = pdom.getDB();
+ db.putInt(record + ENUMERATION, enumeration.getRecord());
+ storeValue(db, enumerator);
enumeration.addEnumerator(this);
}
@@ -54,6 +63,20 @@ class PDOMCPPEnumerator extends PDOMCPPBinding implements IEnumerator {
return IIndexCPPBindingConstants.CPPENUMERATOR;
}
+ private void storeValue(final Database db, IEnumerator enumerator) throws CoreException {
+ IValue value= enumerator.getValue();
+ if (value != null) {
+ Long val= value.numericalValue();
+ db.putInt(record + VALUE, val == null ? -1 : val.intValue());
+ }
+ }
+
+ @Override
+ public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
+ if (newBinding instanceof IEnumerator)
+ storeValue(pdom.getDB(), (IEnumerator) newBinding);
+ }
+
public PDOMCPPEnumerator getNextEnumerator() throws CoreException {
int value = pdom.getDB().getInt(record + NEXT_ENUMERATOR);
return value != 0 ? new PDOMCPPEnumerator(pdom, value) : null;
@@ -72,4 +95,14 @@ class PDOMCPPEnumerator extends PDOMCPPBinding implements IEnumerator {
return null;
}
}
+
+ public IValue getValue() {
+ try {
+ int val= pdom.getDB().getInt(record + VALUE);
+ return Value.create(val);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ return Value.UNKNOWN;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java
index 1a44bd6c1ee..7909782c20d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Bryan Wilkinson (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@@ -15,30 +15,38 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.internal.core.Util;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
+import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Bryan Wilkinson
- *
+ * Binding for a specialization of a field, used in the index.
*/
class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
ICPPField {
private static final int TYPE = PDOMCPPSpecialization.RECORD_SIZE + 0;
+ /**
+ * Offset of pointer to value information for this variable
+ * (relative to the beginning of the record).
+ */
+ private static final int VALUE_OFFSET = PDOMBinding.RECORD_SIZE + 4;
+
/**
* The size in bytes of a PDOMCPPFieldSpecialization record in the database.
*/
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 4;
+ protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8;
public PDOMCPPFieldSpecialization(PDOM pdom, PDOMNode parent,
ICPPField field, PDOMBinding specialized)
@@ -46,11 +54,17 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
super(pdom, parent, (ICPPSpecialization) field, specialized);
try {
+ final Database db = pdom.getDB();
IType type = field.getType();
PDOMNode typeNode = getLinkageImpl().addType(this, type);
if (typeNode != null) {
- pdom.getDB().putInt(record + TYPE, typeNode.getRecord());
+ db.putInt(record + TYPE, typeNode.getRecord());
}
+ IValue val= field.getInitialValue();
+ if (val != null) {
+ db.putInt(record + VALUE_OFFSET, db.newString(val.getCanonicalRepresentation()).getRecord());
+ }
+
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
@@ -90,6 +104,19 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
return null;
}
+ public IValue getInitialValue() {
+ try {
+ final Database db = pdom.getDB();
+ int valRec = db.getInt(record + VALUE_OFFSET);
+ if (valRec == 0)
+ return null;
+ return Value.fromCanonicalRepresentation(db.getString(valRec).toString());
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ return null;
+ }
+ }
+
public boolean isAuto() throws DOMException {
return getField().isAuto();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java
index a9332feef44..370178384cb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java
@@ -6,17 +6,17 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.internal.core.Util;
@@ -33,9 +33,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
- * A parameter to a function or a method
- *
- * @author Doug Schaefer
+ * Binding for a parameter of a c++ function in the index.
*/
class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBinding {
@@ -259,4 +257,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
public IIndexFile getLocalToFile() throws CoreException {
return null;
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java
index 9b7e93b1a18..278abd6f4d0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 QNX Software Systems and others.
+ * Copyright (c) 2007, 2008 QNX Software Systems 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:
- * QNX - Initial API and implementation
+ * Bryan Wilkinson (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.internal.core.Util;
@@ -24,8 +25,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Bryan Wilkinson
- *
+ * Binding for a specialization of a parameter in the index.
*/
class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements ICPPParameter {
/**
@@ -140,4 +140,7 @@ class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements IC
return false;
}
+ public IValue getInitialValue() {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java
index 6ea53fdb67e..dd7b7eed68e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java
@@ -6,11 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
@@ -18,9 +17,11 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
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.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.Util;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@@ -32,28 +33,33 @@ import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Doug Schaefer
- *
+ * Binding for a c++ variable in the index, serves as a base class for fields.
*/
class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
/**
- * Offset of pointer to type information for this parameter
+ * Offset of pointer to type information for this variable
* (relative to the beginning of the record).
*/
private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE + 0;
+ /**
+ * Offset of pointer to value information for this variable
+ * (relative to the beginning of the record).
+ */
+ private static final int VALUE_OFFSET = PDOMBinding.RECORD_SIZE + 4;
+
/**
* Offset of annotation information (relative to the beginning of the
* record).
*/
- protected static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 4; // byte
+ protected static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 8; // byte
/**
* The size in bytes of a PDOMCPPVariable record in the database.
*/
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 5;
+ protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9;
public PDOMCPPVariable(PDOM pdom, PDOMNode parent, IVariable variable) throws CoreException {
super(pdom, parent, variable.getNameCharArray());
@@ -63,23 +69,34 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
Database db = pdom.getDB();
setType(parent.getLinkageImpl(), variable.getType());
db.putByte(record + ANNOTATIONS, encodeFlags(variable));
+ setValue(db, variable);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
+ private void setValue(Database db, IVariable variable) throws CoreException {
+ IValue val= variable.getInitialValue();
+ db.putInt(record + VALUE_OFFSET, val == null ? 0 : db.newString(val.getCanonicalRepresentation()).getRecord());
+ }
+
@Override
public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
if (newBinding instanceof IVariable) {
+ final Database db = pdom.getDB();
IVariable var= (IVariable) newBinding;
IType mytype= getType();
+ int valueRec= db.getInt(record + VALUE_OFFSET);
try {
IType newType= var.getType();
setType(linkage, newType);
- pdom.getDB().putByte(record + ANNOTATIONS, PDOMCPPAnnotation.encodeAnnotation(var));
- if (mytype != null) {
+ db.putByte(record + ANNOTATIONS, encodeFlags(var));
+ setValue(db, var);
+ if (mytype != null)
linkage.deleteType(mytype, record);
- }
+ if (valueRec != 0)
+ db.getString(valueRec).delete();
+
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
@@ -124,6 +141,19 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
return null;
}
}
+
+ public IValue getInitialValue() {
+ try {
+ final Database db = pdom.getDB();
+ int valRec = db.getInt(record + VALUE_OFFSET);
+ if (valRec == 0)
+ return null;
+ return Value.fromCanonicalRepresentation(db.getString(valRec).getString());
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ return null;
+ }
+ }
public boolean isAuto() throws DOMException {
return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java
index 620b53662e5..9a7d6768833 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java
@@ -17,7 +17,9 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.dom.Linkage;
+import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.core.runtime.PlatformObject;
@@ -74,4 +76,8 @@ public class C99Enumerator extends PlatformObject implements IC99Binding, IEnume
}
return null;
}
+
+ public IValue getValue() {
+ return Value.UNKNOWN;
+ }
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java
index b48a46f3648..42c141b42d8 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java
@@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
@@ -119,4 +120,8 @@ public class C99Variable extends PlatformObject implements IC99Binding, IVariabl
return CVisitor.findDeclarationOwner((IASTNode) scope.getScopeName(), true);
}
+
+ public IValue getInitialValue() {
+ return null;
+ }
}