From 63e66889402a7c8e5007f970fde3f0dbfc202a48 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Thu, 1 Dec 2016 22:21:12 -0500 Subject: [PATCH] Bug 508254 - Variable initializer that references the variable Change-Id: Ic5b0692db297dead087e4c8479fa0c0f134554da --- .../tests/IndexCPPBindingResolutionTest.java | 19 ++++++++++++++++++- .../core/pdom/dom/cpp/PDOMCPPField.java | 2 +- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 16 ++++++++++++++++ .../core/pdom/dom/cpp/PDOMCPPVariable.java | 12 ++++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) 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 28c7b0ab55d..dd422f7f5a0 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 @@ -62,7 +62,7 @@ import junit.framework.TestSuite; * additionally check that the binding obtained has characteristics as * expected (type,name,etc..) */ -public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { +public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { public static class SingleProject extends IndexCPPBindingResolutionTest { public SingleProject() { setStrategy(new SinglePDOMTestStrategy(true)); } @@ -78,6 +78,11 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti suite.addTest(SingleProject.suite()); suite.addTest(ProjectWithDepProj.suite()); } + + public IndexCPPBindingResolutionTest() { + setStrategy(new SinglePDOMTestStrategy(true)); + } + public static TestSuite suite() { return suite(SingleProject.class); } /* Assertion helpers */ /* ##################################################################### */ @@ -1927,6 +1932,18 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti public void testNameLookupFromArrayModifier_435075() { checkBindings(); } + + // struct S { + // int* a; + // int* b; + // }; + // + // constexpr S waldo = { nullptr, waldo.a }; + + // // empty file + public void testVariableInitializerThatReferencesVariable_508254() throws Exception { + checkBindings(); + } // class NonVirt { // void m(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java index 6e4d5d848e7..4614a68f3b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java @@ -33,7 +33,7 @@ class PDOMCPPField extends PDOMCPPVariable implements ICPPField { @SuppressWarnings("hiding") protected static final int RECORD_SIZE = FIELD_POSITION_OFFSET + 2; - public PDOMCPPField(PDOMLinkage linkage, PDOMNode parent, ICPPField field, boolean setTypeAndValue) + public PDOMCPPField(PDOMCPPLinkage linkage, PDOMNode parent, ICPPField field, boolean setTypeAndValue) throws CoreException { super(linkage, parent, field, setTypeAndValue); setFieldPosition(field); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index c3d50691479..6c90a2a25c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -225,6 +225,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } // Binding types + class ConfigureVariable implements Runnable { + private final PDOMCPPVariable fVariable; + private final IValue fInitialValue; + + public ConfigureVariable(ICPPVariable original, PDOMCPPVariable variable) { + fVariable = variable; + fInitialValue = original.getInitialValue(); + postProcesses.add(this); + } + + @Override + public void run() { + fVariable.initData(fInitialValue); + } + } + class ConfigureTemplateParameters implements Runnable { private final IPDOMCPPTemplateParameter[] fPersisted; private final ICPPTemplateParameter[] fOriginal; 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 205a505d402..ab371778d1b 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 @@ -40,7 +40,7 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable { @SuppressWarnings("hiding") protected static final int RECORD_SIZE = ANNOTATIONS + 1; - public PDOMCPPVariable(PDOMLinkage linkage, PDOMNode parent, ICPPVariable variable, boolean setTypeAndValue) + public PDOMCPPVariable(PDOMCPPLinkage linkage, PDOMNode parent, ICPPVariable variable, boolean setTypeAndValue) throws CoreException { super(linkage, parent, variable.getNameCharArray()); @@ -49,7 +49,15 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable { db.putByte(record + ANNOTATIONS, PDOMCPPAnnotations.encodeVariableAnnotations(variable)); if (setTypeAndValue) { setType(parent.getLinkage(), variable.getType()); - setValue(variable.getInitialValue()); + linkage.new ConfigureVariable(variable, this); + } + } + + public void initData(IValue initialValue) { + try { + setValue(initialValue); + } catch (CoreException e) { + CCorePlugin.log(e); } }