diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index ef945c40951..17636abb0f8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -10195,4 +10195,70 @@ public class AST2CPPTests extends AST2TestBase { long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size; assertEquals(pointerSize, BSize); } + + // namespace NS { + // class Enclosing { + // class Inner {}; + // }; + // } + public void testNestedClassScopeInlineDefinition_401661() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bh = new BindingAssertionHelper(code, true); + + ICPPClassType Enclosing = bh.assertNonProblem("Enclosing", 9); + ICPPClassType Inner = bh.assertNonProblem("Inner", 5); + + assertEquals(Enclosing.getCompositeScope(), Inner.getScope()); + } + + // namespace NS { + // class Enclosing { + // class Inner; + // }; + // } + // class NS::Enclosing::Inner{}; + public void testNestedClassScopeSeparateDefinition_401661() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bh = new BindingAssertionHelper(code, true); + + ICPPClassType Enclosing = bh.assertNonProblem("Enclosing", 9); + ICPPClassType Inner = bh.assertNonProblem("Inner;", 5); + + assertEquals(Enclosing.getCompositeScope(), Inner.getScope()); + } + + // namespace NS { + // class Inner {}; + // } + public void testClassScopeInlineDefinition_401661() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bh = new BindingAssertionHelper(code, true); + + ICPPNamespace NamespaceNS = bh.assertNonProblem("NS {", 2); + ICPPClassType Inner = bh.assertNonProblem("Inner", 5); + + assertEquals(NamespaceNS.getNamespaceScope(), Inner.getScope()); + } + + // namespace NS { + // class Inner; + // } + // class NS::Inner{}; + public void testClassScopeSeparateDefinition_401661() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bh = new BindingAssertionHelper(code, true); + + ICPPNamespace NamespaceNS = bh.assertNonProblem("NS {", 2); + ICPPClassType Inner = bh.assertNonProblem("Inner;", 5); + + assertEquals(NamespaceNS.getNamespaceScope(), Inner.getScope()); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 57a89c6ff7b..27d75405018 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7205,6 +7205,23 @@ public class AST2TemplateTests extends AST2TestBase { parseAndCheckBindings(); } + // int fn(int); + // struct S { + // template + // auto operator()(Args... args) -> decltype(fn(args...)); + // }; + // template + // int foo(F); + // template + // void bar(T); + // int main() { + // S s; + // bar(foo(s(0))); + // } + public void testVariadicTemplatesAndFunctionObjects_401479() throws Exception { + parseAndCheckBindings(); + } + // struct S { // void kind(); // }; @@ -7312,4 +7329,26 @@ public class AST2TemplateTests extends AST2TestBase { public void testVariadicNonTypeTemplateParameter_401142() throws Exception { parseAndCheckBindings(); } + + // template + // struct ice_or; + // template <> + // struct ice_or<> { + // static const bool value = false; + // }; + // template + // struct ice_or { + // static const bool value = ice_or::value; + // }; + // template struct S {}; + // template <> + // struct S { + // typedef int type; + // }; + // int main() { + // S::value>::type t; + // } + public void testVariadicNonTypeTemplateParameter_401400() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java index 1ba161f81ad..cb50bdd7c27 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.pdom.tests; import java.io.File; @@ -18,61 +20,56 @@ import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.PDOMStringSet; // copy/pasted from BTreeTests -public class PDOMStringSetTests extends BaseTestCase -{ +public class PDOMStringSetTests extends BaseTestCase { protected File dbFile; protected Database db; protected PDOMStringSet stringSet; protected int rootRecord; - public static Test suite() - { - return suite( PDOMStringSetTests.class ); + public static Test suite() { + return suite(PDOMStringSetTests.class); } @Override - protected void setUp() throws Exception - { - super.setUp(); + protected void setUp() throws Exception { + super.setUp(); - dbFile = File.createTempFile( "pdomstringsettest", "db" ); - db = new Database( dbFile, new ChunkCache(), 0, false ); + dbFile = File.createTempFile("pdomstringsettest", "db"); + db = new Database(dbFile, new ChunkCache(), 0, false); db.setExclusiveLock(); rootRecord = Database.DATA_AREA; - stringSet = new PDOMStringSet( db, rootRecord ); + stringSet = new PDOMStringSet(db, rootRecord); } @Override - protected void tearDown() throws Exception - { + protected void tearDown() throws Exception { db.close(); dbFile.deleteOnExit(); - super.tearDown(); + super.tearDown(); } // Quick tests to exercise the basic functionality. - public void testInterface() throws Exception - { - long val1_rec_a = stringSet.add( "val1" ); - long val2_rec_a = stringSet.add( "val2" ); - long val1_rec_b = stringSet.add( "val1" ); - assertTrue( val1_rec_a != 0 ); - assertTrue( val2_rec_a != 0 ); - assertEquals( val1_rec_a, val1_rec_b ); + public void testInterface() throws Exception { + long val1_rec_a = stringSet.add("val1"); + long val2_rec_a = stringSet.add("val2"); + long val1_rec_b = stringSet.add("val1"); + assertTrue(val1_rec_a != 0); + assertTrue(val2_rec_a != 0); + assertEquals(val1_rec_a, val1_rec_b); - long val1_find = stringSet.find( "val1" ); - long val2_find = stringSet.find( "val2" ); - assertEquals( val1_rec_a, val1_find ); - assertEquals( val2_rec_a, val2_find ); + long val1_find = stringSet.find("val1"); + long val2_find = stringSet.find("val2"); + assertEquals(val1_rec_a, val1_find); + assertEquals(val2_rec_a, val2_find); - long val1_rm = stringSet.remove( "val1" ); - assertEquals( val1_rec_a, val1_rm ); - assertEquals( 0, stringSet.find( "val1" ) ); - assertEquals( val2_rec_a, stringSet.find( "val2" ) ); + long val1_rm = stringSet.remove("val1"); + assertEquals(val1_rec_a, val1_rm); + assertEquals(0, stringSet.find("val1")); + assertEquals(val2_rec_a, stringSet.find("val2")); - stringSet.clearCaches(); - assertEquals( val2_rec_a, stringSet.find( "val2" ) ); - assertEquals( 0, stringSet.find( "val1" ) ); + stringSet.clearCaches(); + assertEquals(val2_rec_a, stringSet.find("val2")); + assertEquals(0, stringSet.find("val1")); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java index 34df365853e..c735691e987 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.pdom.tests; import java.io.File; @@ -25,111 +27,120 @@ import org.eclipse.cdt.internal.core.pdom.tag.PDOMTag; import org.eclipse.cdt.internal.core.pdom.tag.PDOMTagIndex; // copy/pasted from BTreeTests -public class PDOMTagIndexTests extends BaseTestCase -{ +public class PDOMTagIndexTests extends BaseTestCase { private PDOM pdom; - public static Test suite() - { - return suite( PDOMTagIndexTests.class ); + public static Test suite() { + return suite(PDOMTagIndexTests.class); } - private static class MockIndexLocationConverter implements IIndexLocationConverter - { - @Override public IIndexFileLocation fromInternalFormat( String raw ) { return null; } - @Override public String toInternalFormat( IIndexFileLocation location ) { return null; } - } + private static class MockIndexLocationConverter implements + IIndexLocationConverter { + @Override + public IIndexFileLocation fromInternalFormat(String raw) { + return null; + } - @Override - protected void setUp() throws Exception - { - super.setUp(); - - File tmpFile = File.createTempFile( getClass().getSimpleName() + '.' + Double.toString( Math.random() ).substring( 2 ), null ); - pdom = new WritablePDOM( tmpFile, new MockIndexLocationConverter(), LanguageManager.getInstance().getPDOMLinkageFactoryMappings() ); + @Override + public String toInternalFormat(IIndexFileLocation location) { + return null; + } } @Override - protected void tearDown() throws Exception - { - pdom.close(); - super.tearDown(); + protected void setUp() throws Exception { + super.setUp(); + + // Create a dummy instance of the PDOM for the various tests to operate + // upon. Also acquire the PDOM's write lock to simulate the condition + // under which the tag index is normally accessed. + File tmpFile = File.createTempFile(getClass().getSimpleName() + '.' + + Double.toString(Math.random()).substring(2), null); + pdom = new WritablePDOM(tmpFile, new MockIndexLocationConverter(), + LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); + pdom.acquireWriteLock(); + } + + @Override + protected void tearDown() throws Exception { + pdom.close(); + super.tearDown(); } // return the nearest valid record that is less than the specified base private static long lastRecordBase = 1000; - private static long computeValidRecord() - { - lastRecordBase += 1000; - return ( lastRecordBase & ~7L ) | 2; + + private static long computeValidRecord() { + lastRecordBase += 1000; + return (lastRecordBase & ~7L) | 2; } - // A quick sanity test to confirm basic functionality. - public void testSimple() throws Exception - { - String tagger = "tagger_a"; - long rec = computeValidRecord(); + // A quick sanity test to confirm basic functionality. + public void testSimple() throws Exception { + String tagger = "tagger_a"; + long rec = computeValidRecord(); - assertNotNull( PDOMTagIndex.createTag( pdom, rec, tagger, 1 ) ); - assertNotNull( PDOMTagIndex.getTag( pdom, rec, tagger ) ); - } + assertNotNull(PDOMTagIndex.createTag(pdom, rec, tagger, 1)); + assertNotNull(PDOMTagIndex.getTag(pdom, rec, tagger)); + } - public void testMultipleTaggers() throws Exception - { - String tagger_a = "tagger_a"; - String tagger_b = "tagger_b"; - long rec1 = computeValidRecord(); - long rec2 = computeValidRecord(); + public void testMultipleTaggers() throws Exception { + String tagger_a = "tagger_a"; + String tagger_b = "tagger_b"; + long rec1 = computeValidRecord(); + long rec2 = computeValidRecord(); - assertNotNull( PDOMTagIndex.createTag( pdom, rec1, tagger_a, 1 ) ); - assertNotNull( PDOMTagIndex.createTag( pdom, rec1, tagger_b, 1 ) ); - assertNotNull( PDOMTagIndex.createTag( pdom, rec2, tagger_a, 1 ) ); + assertNotNull(PDOMTagIndex.createTag(pdom, rec1, tagger_a, 1)); + assertNotNull(PDOMTagIndex.createTag(pdom, rec1, tagger_b, 1)); + assertNotNull(PDOMTagIndex.createTag(pdom, rec2, tagger_a, 1)); - assertNotNull( PDOMTagIndex.getTag( pdom, rec2, tagger_a ) ); - assertNull( PDOMTagIndex.getTag( pdom, rec2, tagger_b ) ); + assertNotNull(PDOMTagIndex.getTag(pdom, rec2, tagger_a)); + assertNull(PDOMTagIndex.getTag(pdom, rec2, tagger_b)); - Iterable tags1 = PDOMTagIndex.getTags( pdom, rec1 ); - int tag_count = 0; - for( ITag tag : tags1 ) - { - ++tag_count; - assertTrue( tag.getTaggerId().equals( tagger_a ) || tag.getTaggerId().equals( tagger_b ) ); - assertEquals( 1, tag.getDataLen() ); - } - assertEquals( 2, tag_count ); - } + Iterable tags1 = PDOMTagIndex.getTags(pdom, rec1); + int tag_count = 0; + for (ITag tag : tags1) { + ++tag_count; + assertTrue(tag.getTaggerId().equals(tagger_a) + || tag.getTaggerId().equals(tagger_b)); + assertEquals(1, tag.getDataLen()); + } + assertEquals(2, tag_count); + } - public void testReplaceTags() throws Exception - { - String tagger_a = "tagger_a"; - String tagger_b = "tagger_b"; - long rec = computeValidRecord(); + public void testReplaceTags() throws Exception { + String tagger_a = "tagger_a"; + String tagger_b = "tagger_b"; + long rec = computeValidRecord(); - ITag taga = PDOMTagIndex.createTag( pdom, rec, tagger_a, 2 ); - assertNotNull( taga ); - assertTrue( taga instanceof PDOMTag ); - PDOMTag taga_pdom = (PDOMTag)taga; - ITag tagb = PDOMTagIndex.createTag( pdom, rec, tagger_a, 2 ); - assertNotNull( tagb ); + ITag taga = PDOMTagIndex.createTag(pdom, rec, tagger_a, 2); + assertNotNull(taga); + assertTrue(taga instanceof PDOMTag); + PDOMTag taga_pdom = (PDOMTag) taga; + ITag tagb = PDOMTagIndex.createTag(pdom, rec, tagger_a, 2); + assertNotNull(tagb); - // replacement should delete tags for taggers that are no longer present and shorter tags - // should be modified in place - PDOMTagIndex.setTags( pdom, rec, Arrays.asList( new Tag( tagger_a, 1 ) ) ); - assertNull( PDOMTagIndex.getTag( pdom, rec, tagger_b ) ); - ITag shorter_ = PDOMTagIndex.getTag( pdom, rec, tagger_a ); - assertNotNull( shorter_ ); - assertTrue( shorter_ instanceof PDOMTag ); - PDOMTag shorter_pdom = (PDOMTag)shorter_; - assertEquals( taga_pdom.getRecord(), shorter_pdom.getRecord() ); + // replacement should delete tags for taggers that are no longer present + // and shorter tags + // should be modified in place + PDOMTagIndex.setTags(pdom, rec, + Arrays. asList(new Tag(tagger_a, 1))); + assertNull(PDOMTagIndex.getTag(pdom, rec, tagger_b)); + ITag shorter_ = PDOMTagIndex.getTag(pdom, rec, tagger_a); + assertNotNull(shorter_); + assertTrue(shorter_ instanceof PDOMTag); + PDOMTag shorter_pdom = (PDOMTag) shorter_; + assertEquals(taga_pdom.getRecord(), shorter_pdom.getRecord()); - // longer tags should create a new record - PDOMTagIndex.setTags( pdom, rec, Arrays.asList( new Tag( tagger_a, 4 ) ) ); - ITag longer_ = PDOMTagIndex.getTag( pdom, rec, tagger_a ); - assertNotNull( longer_ ); - assertTrue( longer_ instanceof PDOMTag ); - PDOMTag longer_pdom = (PDOMTag)longer_; - assertTrue( taga_pdom.getRecord() != longer_pdom.getRecord() ); + // longer tags should create a new record + PDOMTagIndex.setTags(pdom, rec, + Arrays. asList(new Tag(tagger_a, 4))); + ITag longer_ = PDOMTagIndex.getTag(pdom, rec, tagger_a); + assertNotNull(longer_); + assertTrue(longer_ instanceof PDOMTag); + PDOMTag longer_pdom = (PDOMTag) longer_; + assertTrue(taga_pdom.getRecord() != longer_pdom.getRecord()); - // TODO figure out how to confirm that the original tag was free'd - } + // TODO figure out how to confirm that the original tag was free'd + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameterMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameterMap.java index 2a4b0a11e40..45db3a318da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameterMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameterMap.java @@ -44,6 +44,15 @@ public interface ICPPTemplateParameterMap { */ public ICPPTemplateArgument[] getPackExpansion(ICPPTemplateParameter param); + /** + * If 'param' is not a parameter pack, returns the value for 'param' in the map. + * If 'param' is a parmameter pack, returns the value at position 'packOffset' + * in the pack of values for 'param' in the map. + * Returns null is 'param' is not mapped. + * @since 5.5 + */ + public ICPPTemplateArgument getArgument(ICPPTemplateParameter param, int packOffset); + /** * Returns the array of template parameter positions, for which a mapping exists. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IBindingTagger.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IBindingTagger.java index e5a31f14b72..1829adb1465 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IBindingTagger.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IBindingTagger.java @@ -4,31 +4,36 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.core.dom.ast.tag; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; /** - * Implementations are contributed with the org.eclipse.cdt.core.tagger extension-point. The implementation - * is responsible for populating the tag's data using a given input binding. + * Implementations are contributed with the org.eclipse.cdt.core.tagger extension-point. + * The implementation is responsible for populating the tag's data using a given input binding. * * @see #process(ITagWriter, IBinding, IASTName) * @since 5.5 */ -public interface IBindingTagger -{ +public interface IBindingTagger { /** - * Examine the given input binding to decide if a tag should be created. Use the given tagWriter - * to create data if needed. Return the tag if one was created and null otherwise. A tagger (as - * identified by it's unique id string) is allowed to create only one tag for each binding. + * Examines the given input binding to decide if a tag should be created. Use the given + * tagWriter to create data if needed. Return the tag if one was created and null otherwise. + * A tagger (as identified by it's unique id string) is allowed to create only one tag for each + * binding. * - * @param tagWriter the writer to use for creating new tags - * @param binding the binding to examine when populating the tag (if needed) - * @param ast the AST name from which the binding was created + * @param tagWriter + * the writer to use for creating new tags + * @param binding + * the binding to examine when populating the tag (if needed) + * @param ast + * the AST name from which the binding was created * @return the tag if one was created and null otherwise */ - public ITag process( ITagWriter tagWriter, IBinding binding, IASTName ast ); + public ITag process(ITagWriter tagWriter, IBinding binding, IASTName ast); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITag.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITag.java index 00c0ec9fcf5..a51c712281a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITag.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITag.java @@ -4,38 +4,42 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.core.dom.ast.tag; /** - * Tags are used to annotate {@link ITagReader}'s with extra information. They are created - * by implementations of {@link IBindingTagger} which are contributed using the - * org.eclipse.cdt.core.tagger extension point. The base tag interface is read-only, it - * is extended by the writable {@link IWritableTag}. + * Tags are used to annotate {@link ITagReader}'s with extra information. They are created by + * implementations of {@link IBindingTagger} which are contributed using + * the org.eclipse.cdt.core.tagger extension point. The base tag interface is read-only, it is + * extended by the writable {@link IWritableTag}. * * @see IBindingTagger * @see ITagReader * @see IWritableTag * @since 5.5 */ -public interface ITag -{ +public interface ITag { /** A constant that is returned to indicate a read failure. */ - public static final int Fail = -1; + public static final int FAIL = -1; - /** Return the number of bytes in the tag's data payload. */ + /** Returns the number of bytes in the tag's data payload. */ public int getDataLen(); - /** Return the globally unique id of the tagger that created the receiver. */ + /** Returns the globally unique id of the tagger that created the receiver. */ public String getTaggerId(); - /** Return the byte from the specified offset or {@link #Fail} on failure. */ - public int getByte( int offset ); + /** Returns the byte from the specified offset or {@link #FAIL} on failure. */ + public int getByte(int offset); - /** Return the specified number of bytes from the specified offset. Specify len of -1 to read all - * bytes from the specified offset to the end of the payload. Return null on failure. */ - public byte[] getBytes( int offset, int len ); - - // TODO read methods for all the other types + /** + * Returns the specified number of bytes from the specified offset. Specify {@code len} of -1 + * to read all bytes from the specified offset to the end of the payload. Returns null if + * the given range is not valid. This would be expected if the version of the contributor has + * changed in a way that changes the structure of the data that it stores. Contributors must be + * able to deal with that case. + */ + public byte[] getBytes(int offset, int len); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagReader.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagReader.java index fb9d6ca3f58..96d272b3966 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagReader.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagReader.java @@ -4,11 +4,12 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.core.dom.ast.tag; - /** * An interface that provides read-only access to the tags associated with a particular binding. * @@ -16,18 +17,19 @@ package org.eclipse.cdt.core.dom.ast.tag; * @see ITagService * @since 5.5 */ -public interface ITagReader -{ +public interface ITagReader { /** - * Look for a tag for the receiver, returns null if there is no such tag. + * Looks for a tag for the receiver, returns null if there is no such tag. * - * @param id A string that uniquely identifies the tag to be returned. This value was provided by the contributor - * when the tag was created (see {@link ITagWriter#createTag(String, int)}). + * @param id + * A string that uniquely identifies the tag to be returned. This value was provided + * by the contributor when the tag was created + * (see {@link ITagWriter#createTag(String, int)}). */ - public ITag getTag( String id ); + public ITag getTag(String id); /** - * Return all tags known to the receiver. Does not return null. + * Returns all tags known to the receiver. Does not return null. */ public Iterable getTags(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagService.java index 05e12af7a4b..31a4ad384fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagService.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagService.java @@ -4,27 +4,29 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.core.dom.ast.tag; import org.eclipse.cdt.core.dom.ast.IBinding; /** - * Provides ITagReaders for specific bindings. The kind of the reader will vary based on - * the kind of the input binding. + * Provides ITagReaders for specific bindings. The kind of the reader will vary based on the kind + * of the input binding. * * @see ITag * @see ITagReader * @since 5.5 */ -public interface ITagService -{ +public interface ITagService { /** - * Finds or creates a tag reader for the specified binding or null if a reader cannot - * be associated with this binding. + * Finds or creates a tag reader for the specified binding or null if a reader cannot be + * associated with this binding. * - * @param binding could be null + * @param binding + * could be null */ - public ITagReader findTagReader( IBinding binding ); + public ITagReader findTagReader(IBinding binding); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagWriter.java index 34849ba59fe..50c39180436 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/ITagWriter.java @@ -4,6 +4,9 @@ * 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 Eidsness - Initial implementation */ package org.eclipse.cdt.core.dom.ast.tag; @@ -15,20 +18,22 @@ package org.eclipse.cdt.core.dom.ast.tag; * @see ITagService * @since 5.5 */ -public interface ITagWriter -{ +public interface ITagWriter { /** - * Create and return a new tag for the receiver. E.g., if this writer is associated with a persistent binding, - * then returned tag will read and write from the PDOM database. + * Creates and returns a new tag for the receiver. E.g., if this writer is associated with + * a persistent binding, then returned tag will read and write from the PDOM database. * - * @param id A string that uniquely identifies the tag to be returned. This value will be used by the contributor - * when to find the tag (see {@link ITagReader#getTag(String)}). - * @param len The number of bytes that should be allocated to store the tag's data. + * @param id + * A string that uniquely identifies the tag to be returned. This value will be used + * by the contributor when to find the tag (see {@link ITagReader#getTag(String)}). + * @param len + * The number of bytes that should be allocated to store the tag's data. */ - public IWritableTag createTag( String id, int len ); + public IWritableTag createTag(String id, int len); /** - * Sets the receiver's tags to only the ones provided. Deletes existing tags that are not in the argument list. + * Sets the receiver's tags to only the ones provided. Deletes existing tags that are not in + * the argument list. */ - public boolean setTags( Iterable tags ); + public boolean setTags(Iterable tags); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IWritableTag.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IWritableTag.java index bb6a8eecb33..cf790cd2190 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IWritableTag.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/tag/IWritableTag.java @@ -4,28 +4,30 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.core.dom.ast.tag; /** - * Tags are used to annotate {@link ITagWriter}'s with extra information. They are created - * by implementations of {@link IBindingTagger} which are contributed using the - * org.eclipse.cdt.core.tagger extension point. + * Tags are used to annotate {@link ITagWriter}'s with extra information. They are created by + * implementations of {@link IBindingTagger} which are contributed using + * the org.eclipse.cdt.core.tagger extension point. * * @see IBindingTagger * @see ITagReader * @see ITagWriter * @since 5.5 */ -public interface IWritableTag extends ITag -{ - /** Write the given byte to the given offset in the tag. Return true if successful and false otherwise. */ - public boolean putByte( int offset, byte data ); +public interface IWritableTag extends ITag { + /** Writes the given byte to the given offset in the tag. Returns {@code true} if successful. */ + public boolean putByte(int offset, byte data); - /** Write the argument buffer into the receiver's payload starting at the specified offset. Write the specified - * number of bytes or the full buffer when len is -1. Return true if successful and false otherwise. */ - public boolean putBytes( int offset, byte data[], int len ); - - // TODO write for all types + /** + * Writes the argument buffer into the receiver's payload starting at the specified offset. + * Writes the specified number of bytes or the full buffer when {@code len} is -1. Returns + * {@code true} if successful. + */ + public boolean putBytes(int offset, byte data[], int len); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/NonCachedTaggable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/NonCachedTaggable.java index c74ea936709..7d0a812b86e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/NonCachedTaggable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/NonCachedTaggable.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.core.dom.ast.tag; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -19,78 +21,68 @@ import org.eclipse.cdt.core.dom.ast.tag.ITagWriter; import org.eclipse.cdt.core.dom.ast.tag.IWritableTag; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; -public class NonCachedTaggable implements ITagReader, ITagWriter -{ +public class NonCachedTaggable implements ITagReader, ITagWriter { private final IBinding binding; private IASTName ast; - public NonCachedTaggable( IBinding binding ) - { + public NonCachedTaggable(IBinding binding) { this.binding = binding; } @Override - public IWritableTag createTag( String id, int len ) - { - return new Tag( id, len ); + public IWritableTag createTag(String id, int len) { + return new Tag(id, len); } @Override - public ITag getTag( String id ) - { - return TagManager.getInstance().process( id, this, binding, getAST() ); + public ITag getTag(String id) { + return TagManager.getInstance().process(id, this, binding, getAST()); } @Override - public Iterable getTags() - { - return TagManager.getInstance().process( this, binding, getAST() ); + public Iterable getTags() { + return TagManager.getInstance().process(this, binding, getAST()); } @Override - public boolean setTags( Iterable tags ) - { - // this non-caching implementation has nothing to set, the tags will be regenerated + public boolean setTags(Iterable tags) { + // This non-caching implementation has nothing to set, the tags will be regenerated // when they are queried return true; } - private IASTName getAST() - { - if( ast != null ) + private IASTName getAST() { + if (ast != null) return ast; - if( ! ( binding instanceof ICPPInternalBinding ) ) + if (!(binding instanceof ICPPInternalBinding)) return null; - IASTNode node = getPhysicalNode( (ICPPInternalBinding)binding ); - if( node == null ) + IASTNode node = getPhysicalNode((ICPPInternalBinding) binding); + if (node == null) return null; - return ast = getName( node ); + return ast = getName(node); } - private static IASTNode getPhysicalNode( ICPPInternalBinding binding ) - { + private static IASTNode getPhysicalNode(ICPPInternalBinding binding) { IASTNode node = binding.getDefinition(); - if( node != null ) + if (node != null) return node; IASTNode[] nodes = binding.getDeclarations(); - if( nodes == null - || nodes.length <= 0 ) + if (nodes == null || nodes.length <= 0) return null; return nodes[0]; } - private static IASTName getName( IASTNode node ) - { - if( node instanceof IASTName ) - return (IASTName)node; - if( node instanceof ICPPASTCompositeTypeSpecifier ) - return ( (ICPPASTCompositeTypeSpecifier)node ).getName(); - if( node instanceof IASTDeclarator ) - return ( (IASTDeclarator)node ).getName(); + private static IASTName getName(IASTNode node) { + if (node instanceof IASTName) + return (IASTName) node; + if (node instanceof ICPPASTCompositeTypeSpecifier) + return ((ICPPASTCompositeTypeSpecifier) node).getName(); + if (node instanceof IASTDeclarator) + return ((IASTDeclarator) node).getName(); return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/Tag.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/Tag.java index d0979f421dd..99c18d217a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/Tag.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/Tag.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.core.dom.ast.tag; import org.eclipse.cdt.core.dom.ast.tag.ITag; @@ -16,31 +18,32 @@ import org.eclipse.cdt.core.dom.ast.tag.IWritableTag; * * @see NonCachedTaggable */ -public class Tag implements IWritableTag -{ +public class Tag implements IWritableTag { private final String taggerId; private final byte[] buff; - public Tag( String taggerId, int dataLen ) - { + public Tag(String taggerId, int dataLen) { this.taggerId = taggerId; this.buff = new byte[dataLen]; } - @Override public String getTaggerId() { return taggerId; } - @Override public int getDataLen() { return buff.length; } - - private boolean isInBounds( int offset, int len ) - { - return offset >= 0 - && offset < buff.length - && ( offset + len ) <= buff.length; + @Override + public String getTaggerId() { + return taggerId; } @Override - public boolean putByte( int offset, byte b ) - { - if( ! isInBounds( offset, 1 ) ) + public int getDataLen() { + return buff.length; + } + + private boolean isInBounds(int offset, int len) { + return offset >= 0 && offset < buff.length && (offset + len) <= buff.length; + } + + @Override + public boolean putByte(int offset, byte b) { + if (!isInBounds(offset, 1)) return false; buff[offset] = b; @@ -48,31 +51,28 @@ public class Tag implements IWritableTag } @Override - public boolean putBytes( int offset, byte[] data, int len ) - { + public boolean putBytes(int offset, byte[] data, int len) { len = len >= 0 ? len : data.length; - if( ! isInBounds( offset, len ) ) + if (!isInBounds(offset, len)) return false; - System.arraycopy( data, 0, buff, offset, len ); + System.arraycopy(data, 0, buff, offset, len); return true; } @Override - public int getByte( int offset ) - { - return isInBounds( offset, 1 ) ? buff[offset] : ITag.Fail; + public int getByte(int offset) { + return isInBounds(offset, 1) ? buff[offset] : ITag.FAIL; } @Override - public byte[] getBytes( int offset, int len ) - { + public byte[] getBytes(int offset, int len) { len = len >= 0 ? len : buff.length - offset; - if( ! isInBounds( offset, len ) ) + if (!isInBounds(offset, len)) return null; byte[] data = new byte[len]; - System.arraycopy( buff, offset, data, 0, len ); + System.arraycopy(buff, offset, data, 0, len); return data; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagManager.java index c302fae7e28..8579ed9db37 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagManager.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.core.dom.ast.tag; import java.util.HashMap; @@ -25,83 +27,75 @@ import org.eclipse.cdt.internal.core.pdom.tag.PDOMTaggable; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; -public class TagManager -{ +public class TagManager { + private static final String EXTENSION_POINT = "tagger"; //$NON-NLS-1$ private static TagManager INSTANCE; private Map taggers; - public static TagManager getInstance() - { - if( INSTANCE == null ) + public static TagManager getInstance() { + if (INSTANCE == null) INSTANCE = new TagManager(); return INSTANCE; } - private TagManager() - { + private TagManager() { taggers = loadExtensions(); } - private static final String ExtensionPoint = "tagger"; //$NON-NLS-1$ - - private static Map loadExtensions() - { + private static Map loadExtensions() { Map taggers = new HashMap(); - // load the extensions - IConfigurationElement[] elements - = Platform.getExtensionRegistry().getConfigurationElementsFor( CCorePlugin.PLUGIN_ID, ExtensionPoint ); - for (IConfigurationElement element : elements) - { - TaggerDescriptor desc = new TaggerDescriptor( element ); - taggers.put( desc.getId(), desc ); + // Load the extensions + IConfigurationElement[] elements = Platform.getExtensionRegistry() + .getConfigurationElementsFor(CCorePlugin.PLUGIN_ID, EXTENSION_POINT); + for (IConfigurationElement element : elements) { + TaggerDescriptor desc = new TaggerDescriptor(element); + taggers.put(desc.getId(), desc); } return taggers; } - /** Provide an opportunity for the specified tagger to process the given values. The tagger will only - * run if its enablement expression returns true for the arguments. */ - public ITag process( String taggerId, ITagWriter tagWriter, IBinding binding, IASTName ast ) - { - TaggerDescriptor desc = taggers.get( taggerId ); - if( desc == null ) + /** + * Provides an opportunity for the specified tagger to process the given values. The tagger will + * only run if its enablement expression returns true for the arguments. + */ + public ITag process(String taggerId, ITagWriter tagWriter, IBinding binding, IASTName ast) { + TaggerDescriptor desc = taggers.get(taggerId); + if (desc == null) return null; - IBindingTagger tagger = desc.getBindingTaggerFor( binding, ast ); - return tagger == null ? null : tagger.process( tagWriter, binding, ast ); + IBindingTagger tagger = desc.getBindingTaggerFor(binding, ast); + return tagger == null ? null : tagger.process(tagWriter, binding, ast); } - /** Provide an opportunity for all enabled taggers to process the given values. */ - public Iterable process( ITagWriter tagWriter, IBinding binding, IASTName ast ) - { + /** Provides an opportunity for all enabled taggers to process the given values. */ + public Iterable process(ITagWriter tagWriter, IBinding binding, IASTName ast) { List tags = new LinkedList(); - for( TaggerDescriptor desc : taggers.values() ) - { - IBindingTagger tagger = desc.getBindingTaggerFor( binding, ast ); - if( tagger != null ) - { - ITag tag = tagger.process( tagWriter, binding, ast ); - if( tag != null ) - tags.add( tag ); + for (TaggerDescriptor desc : taggers.values()) { + IBindingTagger tagger = desc.getBindingTaggerFor(binding, ast); + if (tagger != null) { + ITag tag = tagger.process(tagWriter, binding, ast); + if (tag != null) + tags.add(tag); } } return tags; } - /** Add or remove tags from the destination to ensure that it has the same tag information as the source. */ - public void syncTags( IPDOMBinding dst, IBinding src ) - { - if( dst == null ) + /** Adds or removes tags from the destination to ensure that it has the same tag information as the source. */ + public void syncTags(IPDOMBinding dst, IBinding src) { + // don't try to copy any tags when there are no contributors to this extension point + if (dst == null || taggers.isEmpty()) return; - ITagReader tagReader = CCorePlugin.getTagService().findTagReader( src ); - if( tagReader == null ) + ITagReader tagReader = CCorePlugin.getTagService().findTagReader(src); + if (tagReader == null) return; - ITagWriter tagWriter = new PDOMTaggable( dst.getPDOM(), dst.getRecord() ); - tagWriter.setTags( tagReader.getTags() ); + ITagWriter tagWriter = new PDOMTaggable(dst.getPDOM(), dst.getRecord()); + tagWriter.setTags(tagReader.getTags()); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagService.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagService.java index dad4d60895c..c09acbac421 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagService.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TagService.java @@ -4,32 +4,33 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.core.dom.ast.tag; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.tag.ITagReader; import org.eclipse.cdt.core.dom.ast.tag.ITagService; -public class TagService implements ITagService -{ +public class TagService implements ITagService { /** - * First gives the IBinding instance a chance to convert itself, by calling IAdaptable#getAdapter( ITagReader.class ) - * on the binding. If the binding doesn't provide an implementation then a simple, in-memory, non-cached - * implementation is created and returned. + * First gives the IBinding instance a chance to convert itself, by calling + * IAdaptable#getAdapter(ITagReader.class) on the binding. If the binding doesn't provide + * an implementation then a simple, in-memory, non-cached implementation is created and + * returned. */ @Override - public ITagReader findTagReader( IBinding binding ) - { - if( binding == null ) + public ITagReader findTagReader(IBinding binding) { + if (binding == null) return null; - // let the binding adapt to its own tag reader - ITagReader tagReader = (ITagReader)binding.getAdapter( ITagReader.class ); - if( tagReader != null ) + // Let the binding adapt to its own tag reader + ITagReader tagReader = (ITagReader) binding.getAdapter(ITagReader.class); + if (tagReader != null) return tagReader; - return new NonCachedTaggable( binding ); + return new NonCachedTaggable(binding); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TaggerDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TaggerDescriptor.java index c0386142f80..a18cb7ac155 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TaggerDescriptor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/ast/tag/TaggerDescriptor.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.core.dom.ast.tag; import java.util.Arrays; @@ -30,12 +32,12 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; /** - * Internal container for extensions of org.eclipse.cdt.core.tagger. The implementation of the - * tagger is instantiated only after checking the enablement expression (if present) for the - * specified binding. This avoids activating the contributing plugin until it is actually needed. + * Internal container for extensions of org.eclipse.cdt.core.tagger. The implementation of + * the tagger is instantiated only after checking the enablement expression (if present) for + * the specified binding. This avoids activating the contributing plugin until it is actually + * needed. */ -public class TaggerDescriptor -{ +public class TaggerDescriptor { private static final String Attr_LocalId = "local-id"; //$NON-NLS-1$ private static final String Attr_Class = "class"; //$NON-NLS-1$ @@ -46,22 +48,25 @@ public class TaggerDescriptor private String id; private IBindingTagger tagger; - private static final String Var_projectNature = "projectNatures"; //$NON-NLS-1$ - private static final String Var_languageId = "languageId"; //$NON-NLS-1$ + private static final String VAR_PROJECTNATURES = "projectNatures"; //$NON-NLS-1$ + private static final String VAR_LANGUAGEID = "languageId"; //$NON-NLS-1$ - /** An empty implementation of the tagger used as a placeholder in descriptors that are unable to - * load the contributed class. */ - private static final IBindingTagger NullTagger = new IBindingTagger() - { - @Override public ITag process(ITagWriter tagWriter, IBinding binding, IASTName ast) { return null; } + /** + * An empty implementation of the tagger used as a placeholder in descriptors that are unable + * to load the contributed class. + */ + private static final IBindingTagger NULL_TAGGER = new IBindingTagger() { + @Override + public ITag process(ITagWriter tagWriter, IBinding binding, IASTName ast) { + return null; + } }; - public TaggerDescriptor( IConfigurationElement element ) - { + public TaggerDescriptor(IConfigurationElement element) { this.element = element; Expression expr = null; - IConfigurationElement[] children = element.getChildren( ExpressionTagNames.ENABLEMENT ); + IConfigurationElement[] children = element.getChildren(ExpressionTagNames.ENABLEMENT); switch (children.length) { case 0: fStatus = Boolean.TRUE; @@ -69,114 +74,104 @@ public class TaggerDescriptor case 1: try { ExpressionConverter parser = ExpressionConverter.getDefault(); - expr = parser.perform( children[0] ); + expr = parser.perform(children[0]); } catch (CoreException e) { - CCorePlugin.log( "Error in enablement expression of " + id, e ); //$NON-NLS-1$ + CCorePlugin.log("Error in enablement expression of " + id, e); //$NON-NLS-1$ } break; default: - CCorePlugin.log( "Too many enablement expressions for " + id ); //$NON-NLS-1$ + CCorePlugin.log("Too many enablement expressions for " + id); //$NON-NLS-1$ fStatus = Boolean.FALSE; break; } enablementExpression = expr; } - public String getId() - { - if( id != null ) + public String getId() { + if (id != null) return id; String globalId = element.getContributor().getName(); - String localId = element.getAttribute( Attr_LocalId ); + String localId = element.getAttribute(Attr_LocalId); // there must be a valid local id - if( localId == null ) - { + if (localId == null) { String extId = element.getDeclaringExtension().getSimpleIdentifier(); - CCorePlugin.log( "Invalid extension " + globalId + '.' + extId + " must provide tagger's local-id" ); //$NON-NLS-1$ //$NON-NLS-2$ + CCorePlugin.log("Invalid extension " + globalId + '.' + extId //$NON-NLS-1$ + + " must provide tagger's local-id"); //$NON-NLS-1$ return null; } // the extension should not include the plugin id, but return immediately if it does - if( localId.startsWith( globalId ) - && localId.length() > globalId.length() ) + if (localId.startsWith(globalId) && localId.length() > globalId.length()) return localId; // make sure the local id has real content - if( localId.isEmpty() ) - { + if (localId.isEmpty()) { String extId = element.getDeclaringExtension().getSimpleIdentifier(); - CCorePlugin.log( "Invalid extension " + globalId + '.' + extId + " must provide value for tagger's local-id" ); //$NON-NLS-1$ //$NON-NLS-2$ + CCorePlugin.log("Invalid extension " + globalId + '.' + extId //$NON-NLS-1$ + + " must provide value for tagger's local-id"); //$NON-NLS-1$ return null; } // otherwise prepend with the globalId, and ensure a dot between them - if( localId.charAt( 0 ) == '.' ) + if (localId.charAt(0) == '.') return globalId + localId; - return globalId + '.' + localId; + return globalId + '.' + localId; } - private boolean matches( ITranslationUnit tu ) - { - // if the enablement expression is missing or structurally invalid, then return immediately - if( fStatus != null ) + private boolean matches(ITranslationUnit tu) { + // If the enablement expression is missing or structurally invalid, then return immediately + if (fStatus != null) return fStatus.booleanValue(); - // if there is no tu, then the enablement expression cannot be evaluated, assume that all taggers - // are needed - if( tu == null ) + // If there is no tu, then the enablement expression cannot be evaluated, assume that all + // taggers are needed + if (tu == null) return true; - if( enablementExpression != null ) - try - { + if (enablementExpression != null) + try { IProject project = null; ICProject cProject = tu.getCProject(); - if( cProject != null ) + if (cProject != null) project = cProject.getProject(); - EvaluationContext evalContext = new EvaluationContext( null, project ); + EvaluationContext evalContext = new EvaluationContext(null, project); // if the project is not accessible, then only taggers that don't care about it will // get a chance to run - if( project != null ) - { + if (project != null) { String[] natures = project.getDescription().getNatureIds(); - evalContext.addVariable( Var_projectNature, Arrays.asList( natures ) ); + evalContext.addVariable(VAR_PROJECTNATURES, Arrays.asList(natures)); } ILanguage language = tu.getLanguage(); - if( language != null ) - evalContext.addVariable( Var_languageId, language.getId() ); + if (language != null) + evalContext.addVariable(VAR_LANGUAGEID, language.getId()); - return enablementExpression.evaluate( evalContext ) == EvaluationResult.TRUE; - } - catch( CoreException e ) - { - CCorePlugin.log( "Error while evaluating enablement expression for " + id, e ); //$NON-NLS-1$ + return enablementExpression.evaluate(evalContext) == EvaluationResult.TRUE; + } catch (CoreException e) { + CCorePlugin.log("Error while evaluating enablement expression for " + id, e); //$NON-NLS-1$ } fStatus = Boolean.FALSE; return false; } - private IBindingTagger getTagger() - { - if( tagger == null ) - synchronized( this ) - { - if( tagger == null ) - { - try { tagger = (IBindingTagger)element.createExecutableExtension( Attr_Class ); } - catch( CoreException e ) - { + private IBindingTagger getTagger() { + if (tagger == null) + synchronized (this) { + if (tagger == null) { + try { + tagger = (IBindingTagger) element.createExecutableExtension(Attr_Class); + } catch (CoreException e) { String id = element.getDeclaringExtension().getNamespaceIdentifier() + '.' - + element.getDeclaringExtension().getSimpleIdentifier(); - CCorePlugin.log( "Error in class attribute of " + id, e ); //$NON-NLS-1$ + + element.getDeclaringExtension().getSimpleIdentifier(); + CCorePlugin.log("Error in class attribute of " + id, e); //$NON-NLS-1$ // mark the tagger with an empty implementation to prevent future load attempts - tagger = NullTagger; + tagger = NULL_TAGGER; } } } @@ -185,18 +180,17 @@ public class TaggerDescriptor } // Activates the plugin if needed. - public IBindingTagger getBindingTaggerFor( IBinding binding, IASTName ast ) - { + public IBindingTagger getBindingTaggerFor(IBinding binding, IASTName ast) { // If there isn't an ast with an AST-TU accessible, then there is no way to defer processing, - // just return the tagger and let it try to sort things out. E.g., this happens for built-in + // just return the tagger and let it try to sort things out. E.g., this happens for built-in // things. - if( ast == null ) + if (ast == null) return getTagger(); IASTTranslationUnit astTU = ast.getTranslationUnit(); - if( astTU == null ) + if (astTU == null) return getTagger(); // Otherwise evaluate the enablement expression for this TU - return matches( astTU.getOriginatingTranslationUnit() ) ? getTagger() : null; + return matches(astTU.getOriginatingTranslationUnit()) ? getTagger() : null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java index 470ea5f1943..c163a7d07ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2013 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Markus Schorn - initial API and implementation * Thomas Corbat * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -22,45 +23,56 @@ import org.eclipse.core.runtime.CoreException; * Buffer for marshalling and unmarshalling types. */ public interface ITypeMarshalBuffer { - final static byte BASIC_TYPE= 1; - final static byte POINTER_TYPE= 2; - final static byte ARRAY_TYPE= 3; - final static byte CVQUALIFIER_TYPE= 4; - final static byte FUNCTION_TYPE= 5; - final static byte REFERENCE_TYPE= 6; - final static byte POINTER_TO_MEMBER_TYPE= 7; - final static byte PACK_EXPANSION_TYPE= 8; - final static byte PROBLEM_TYPE= 9; - final static byte VALUE= 10; - final static byte DEPENDENT_EXPRESSION_TYPE= 11; - final static byte UNKNOWN_MEMBER= 12; - final static byte UNKNOWN_MEMBER_CLASS_INSTANCE= 13; - final static byte DEFERRED_CLASS_INSTANCE= 14; - final static byte ALIAS_TEMPLATE = 15; + final static byte BASIC_TYPE = 0x01; + final static byte POINTER_TYPE = 0x02; + final static byte ARRAY_TYPE = 0x03; + final static byte CVQUALIFIER_TYPE = 0x04; + final static byte FUNCTION_TYPE = 0x05; + final static byte REFERENCE_TYPE = 0x06; + final static byte POINTER_TO_MEMBER_TYPE = 0x07; + final static byte PACK_EXPANSION_TYPE = 0x08; + final static byte PROBLEM_TYPE = 0x09; + final static byte VALUE = 0x0A; + final static byte DEPENDENT_EXPRESSION_TYPE = 0x0B; + final static byte UNKNOWN_MEMBER = 0x0C; + final static byte UNKNOWN_MEMBER_CLASS_INSTANCE = 0x0D; + final static byte DEFERRED_CLASS_INSTANCE = 0x0E; + final static byte ALIAS_TEMPLATE = 0x0F; + // Can add more types up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. final static byte - EVAL_BINARY= 1, - EVAL_BINARY_TYPE_ID = 2, - EVAL_BINDING = 3, - EVAL_COMMA = 4, - EVAL_COMPOUND = 5, - EVAL_CONDITIONAL = 6, - EVAL_FIXED= 7, - EVAL_FUNCTION_CALL= 8, - EVAL_FUNCTION_SET= 9, - EVAL_ID= 10, - EVAL_INIT_LIST= 11, - EVAL_MEMBER_ACCESS= 12, - EVAL_TYPE_ID= 13, - EVAL_UNARY= 14, - EVAL_UNARY_TYPE_ID = 15; + EVAL_BINARY = 0x01, + EVAL_BINARY_TYPE_ID = 0x02, + EVAL_BINDING = 0x03, + EVAL_COMMA = 0x04, + EVAL_COMPOUND = 0x05, + EVAL_CONDITIONAL = 0x06, + EVAL_FIXED = 0x07, + EVAL_FUNCTION_CALL = 0x08, + EVAL_FUNCTION_SET = 0x09, + EVAL_ID = 0x0A, + EVAL_INIT_LIST = 0x0B, + EVAL_MEMBER_ACCESS = 0x0C, + EVAL_PARAMETER_PACK = 0x0D, + EVAL_TYPE_ID = 0x0E, + EVAL_UNARY = 0x0F, + EVAL_UNARY_TYPE_ID = 0x10; + // Can add more evaluations up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. - static final byte KIND_MASK= 15; + static final short KIND_MASK = 0x001F; - final static int FLAG1 = 0x10; - final static int FLAG2 = 0x20; - final static int FLAG3 = 0x40; - final static int FLAG4 = 0x80; + final static short FIRST_FLAG = 0x0020; + + final static short FLAG1 = 0x0020; + final static short FLAG2 = 0x0040; + final static short FLAG3 = 0x0080; + final static short FLAG4 = 0x0100; + final static short FLAG5 = 0x0200; + final static short FLAG6 = 0x0400; + final static short FLAG7 = 0x0800; + // Can add more flags up to LAST_FLAG. + + final static short LAST_FLAG = 0x2000; CoreException unmarshallingError(); @@ -72,6 +84,11 @@ public interface ITypeMarshalBuffer { int getByte() throws CoreException; int getFixedInt() throws CoreException; + /** + * Reads a 16-bit integer stored in the variable length base-128 encoding. + */ + public short getShort() throws CoreException; + /** * Reads a 32-bit integer stored in the variable length base-128 encoding. */ @@ -92,6 +109,12 @@ public interface ITypeMarshalBuffer { void putByte(byte data); void putFixedInt(int data); + /** + * Writes a 16-bit integer in the variable length base-128 encoding. + * @param value the value to write + */ + public void putShort(short value); + /** * Writes a 32-bit integer in the variable length base-128 encoding. Each byte, except the last * byte, has the most significant bit set – this indicates that there are further bytes to come. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java index fdeddcf8d21..797bf9278c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemFunctionType.java @@ -28,11 +28,11 @@ public class ProblemFunctionType extends ProblemType implements ICPPFunctionType @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - buffer.putByte((byte) (ITypeMarshalBuffer.PROBLEM_TYPE | ITypeMarshalBuffer.FLAG1)); + buffer.putShort((short) (ITypeMarshalBuffer.PROBLEM_TYPE | ITypeMarshalBuffer.FLAG1)); buffer.putInt(getID()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { return new ProblemFunctionType(buffer.getInt()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java index 8c6852c2935..48d9b49696a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java @@ -56,13 +56,13 @@ public class ProblemType implements IProblemType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.PROBLEM_TYPE); + buffer.putShort(ITypeMarshalBuffer.PROBLEM_TYPE); buffer.putInt(getID()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) - return ProblemFunctionType.unmarshal(firstByte, buffer); + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) + return ProblemFunctionType.unmarshal(firstBytes, buffer); return new ProblemType(buffer.getInt()); } 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 index 5a5673d05f8..700f42d10e1 100644 --- 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 @@ -154,41 +154,41 @@ public class Value implements IValue { return IBinding.EMPTY_BINDING_ARRAY; } - public void marshall(ITypeMarshalBuffer buf) throws CoreException { + public void marshal(ITypeMarshalBuffer buf) throws CoreException { if (UNKNOWN == this) { - buf.putByte((byte) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG1)); + buf.putShort((short) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG1)); } else { Long num= numericalValue(); if (num != null) { long lv= num; if (lv >= 0) { - buf.putByte((byte) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG2)); + buf.putShort((short) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG2)); buf.putLong(lv); } else { - buf.putByte((byte) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG3)); + buf.putShort((short) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG3)); buf.putLong(-lv); } } else if (fFixedValue != null) { - buf.putByte((byte) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG4)); + buf.putShort((short) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG4)); buf.putCharArray(fFixedValue); } else { - buf.putByte((ITypeMarshalBuffer.VALUE)); + buf.putShort(ITypeMarshalBuffer.VALUE); fEvaluation.marshal(buf, true); } } } public static IValue unmarshal(ITypeMarshalBuffer buf) throws CoreException { - int firstByte= buf.getByte(); - if (firstByte == TypeMarshalBuffer.NULL_TYPE) + short firstBytes= buf.getShort(); + if (firstBytes == TypeMarshalBuffer.NULL_TYPE) return null; - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) + if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) return Value.UNKNOWN; - if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) + if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) return Value.create(buf.getLong()); - if ((firstByte & ITypeMarshalBuffer.FLAG3) != 0) + if ((firstBytes & ITypeMarshalBuffer.FLAG3) != 0) return Value.create(-buf.getLong()); - if ((firstByte & ITypeMarshalBuffer.FLAG4) != 0) + if ((firstBytes & ITypeMarshalBuffer.FLAG4) != 0) return new Value(buf.getCharArray(), null); ISerializableEvaluation eval= buf.unmarshalEvaluation(); @@ -280,6 +280,8 @@ public class Value implements IValue { } public static IValue incrementedValue(IValue value, int increment) { + if (value == UNKNOWN) + return UNKNOWN; Long val = value.numericalValue(); if (val != null) { return create(val.longValue() + increment); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java index 42a3be333bf..e18c5720b2d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java @@ -160,35 +160,28 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.ARRAY_TYPE; - int flags= 0; + short firstBytes = ITypeMarshalBuffer.ARRAY_TYPE; long nval= -1; IValue val= null; - if (isConst()) flags |= 0x01; - if (isVolatile()) flags |= 0x02; - if (isRestrict()) flags |= 0x04; - if (isStatic()) flags |= 0x08; - if (isVariableLength()) flags |= 0x10; - if (flags != 0) { - firstByte |= ITypeMarshalBuffer.FLAG1; - } + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + if (isStatic()) firstBytes |= ITypeMarshalBuffer.FLAG4; + if (isVariableLength()) firstBytes |= ITypeMarshalBuffer.FLAG5; val= getSize(); if (val != null) { - firstByte |= ITypeMarshalBuffer.FLAG2; + firstBytes |= ITypeMarshalBuffer.FLAG6; Long num= val.numericalValue(); if (num != null) { nval= num; if (nval >= 0) { - firstByte |= ITypeMarshalBuffer.FLAG3; + firstBytes |= ITypeMarshalBuffer.FLAG7; } } } - buffer.putByte((byte) firstByte); - if (flags != 0) { - buffer.putByte((byte) flags); - } + buffer.putShort(firstBytes); if (nval >= 0) { buffer.putLong(nval); } else if (val != null) { @@ -197,21 +190,20 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - int flags= 0; + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IValue value= null; - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) { - flags= buffer.getByte(); - } - if ((firstByte & ITypeMarshalBuffer.FLAG3) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG7) != 0) { value = Value.create(buffer.getLong()); - } else if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + } else if ((firstBytes & ITypeMarshalBuffer.FLAG6) != 0) { value = buffer.unmarshalValue(); } IType nested= buffer.unmarshalType(); - CArrayType result= new CArrayType(nested, (flags & 0x01) != 0, (flags & 0x02) != 0, (flags & 0x04) != 0, value); - result.setIsStatic((flags & 0x08) != 0); - result.setIsVariableLength((flags & 0x10) != 0); + CArrayType result= new CArrayType(nested, + (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG3) != 0, value); + result.setIsStatic((firstBytes & ITypeMarshalBuffer.FLAG4) != 0); + result.setIsVariableLength((firstBytes & ITypeMarshalBuffer.FLAG5) != 0); return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java index bd3d0b23c36..0ac2f77d745 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java @@ -60,6 +60,7 @@ public class CBasicType implements ICBasicType, ISerializableType { } private static Kind getKind(ICASTSimpleDeclSpecifier sds) { + // Note: when adding a new kind, marshal() and unnmarshal() may need to be revised. switch (sds.getType()) { case IASTSimpleDeclSpecifier.t_bool: return Kind.eBoolean; @@ -170,25 +171,21 @@ public class CBasicType implements ICBasicType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { final int kind= getKind().ordinal(); - final int shiftedKind= kind * ITypeMarshalBuffer.FLAG1; + final int shiftedKind= kind * ITypeMarshalBuffer.FIRST_FLAG; final int modifiers= getModifiers(); - if (shiftedKind < ITypeMarshalBuffer.FLAG4 && modifiers == 0) { - buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); + if (modifiers == 0) { + buffer.putShort((short) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); } else { - buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | ITypeMarshalBuffer.FLAG4)); - buffer.putByte((byte) kind); + buffer.putShort((short) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind | ITypeMarshalBuffer.LAST_FLAG)); buffer.putByte((byte) modifiers); } } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - final boolean dense= (firstByte & ITypeMarshalBuffer.FLAG4) == 0; + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + final boolean haveModifiers= (firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0; int modifiers= 0; - int kind; - if (dense) { - kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; - } else { - kind= buffer.getByte(); + int kind= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG-1))/ITypeMarshalBuffer.FIRST_FLAG; + if (haveModifiers) { modifiers= buffer.getByte(); } return new CBasicType(Kind.values()[kind], modifiers); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java index 7eda549d946..986e24f1961 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java @@ -78,16 +78,16 @@ public class CFunctionType implements IFunctionType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.FUNCTION_TYPE; + short firstBytes = ITypeMarshalBuffer.FUNCTION_TYPE; int len= parameters.length & 0xffff; - int codedLen= len * ITypeMarshalBuffer.FLAG1; - if (codedLen < ITypeMarshalBuffer.FLAG4) { - firstByte |= codedLen; - buffer.putByte((byte) firstByte); + int codedLen= len * ITypeMarshalBuffer.FIRST_FLAG; + if (codedLen < ITypeMarshalBuffer.LAST_FLAG) { + firstBytes |= codedLen; + buffer.putShort(firstBytes); } else { - firstByte |= ITypeMarshalBuffer.FLAG4; - buffer.putByte((byte) firstByte); + firstBytes |= ITypeMarshalBuffer.LAST_FLAG; + buffer.putShort(firstBytes); buffer.putInt(len); } @@ -97,12 +97,12 @@ public class CFunctionType implements IFunctionType, ISerializableType { } } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len; - if (((firstByte & ITypeMarshalBuffer.FLAG4) != 0)) { + if (((firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0)) { len= buffer.getInt(); } else { - len= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + len= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG-1))/ITypeMarshalBuffer.FIRST_FLAG; } IType rt= buffer.unmarshalType(); IType[] pars= new IType[len]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java index 61b76051203..89477b01764 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java @@ -94,17 +94,17 @@ public class CPointerType implements ICPointerType, ITypeContainer, ISerializabl @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.POINTER_TYPE; - if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstByte |= ITypeMarshalBuffer.FLAG3; - buffer.putByte((byte) firstByte); + short firstBytes = ITypeMarshalBuffer.POINTER_TYPE; + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + buffer.putShort(firstBytes); buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); - return new CPointerType(nested, firstByte/ITypeMarshalBuffer.FLAG1); + return new CPointerType(nested, firstBytes/ITypeMarshalBuffer.FLAG1); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java index 23ff677f145..604be21a982 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java @@ -144,17 +144,17 @@ public class CQualifierType implements ICQualifierType, ITypeContainer, ISeriali @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.CVQUALIFIER_TYPE; - if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstByte |= ITypeMarshalBuffer.FLAG3; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.CVQUALIFIER_TYPE; + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + buffer.putShort(firstBytes); buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); - return new CQualifierType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, - (firstByte & ITypeMarshalBuffer.FLAG2) != 0, (firstByte & ITypeMarshalBuffer.FLAG3) != 0); + return new CQualifierType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java index 56695296b2a..58747fd9592 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java @@ -11,8 +11,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; - import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -21,9 +19,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression; 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.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.Value; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalParameterPack; /** * Implementation of pack expansion expression. @@ -70,13 +66,7 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac @Override public ICPPEvaluation getEvaluation() { if (fEvaluation == null) { - IType type = fPattern.getExpressionType(); - if (type == null) { - type= ProblemType.UNKNOWN_FOR_EXPRESSION; - } else { - type= new CPPParameterPackType(type); - } - fEvaluation= new EvalFixed(type, PRVALUE, Value.create(((ICPPASTExpression) fPattern).getEvaluation())); + fEvaluation = new EvalParameterPack(((ICPPASTExpression) fPattern).getEvaluation(), this); } return fEvaluation; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java index bae0b088cbd..b0bf15eab83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPAliasTemplateInstance.java @@ -111,14 +111,14 @@ public class CPPAliasTemplateInstance extends PlatformObject @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte = ITypeMarshalBuffer.ALIAS_TEMPLATE; - buffer.putByte((byte) firstByte); + short firstBytes = ITypeMarshalBuffer.ALIAS_TEMPLATE; + buffer.putShort(firstBytes); buffer.putCharArray(name); buffer.marshalType(aliasedType); buffer.marshalBinding(aliasTemplate); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { char[] name = buffer.getCharArray(); IType unmarshalledAliasedTypeInstance = buffer.unmarshalType(); ICPPAliasTemplate unmarshalledAlias = (ICPPAliasTemplate)buffer.unmarshalBinding(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java index 32555a25f86..bcef9a11210 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java @@ -111,11 +111,11 @@ public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableTy @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - final byte firstByte = ITypeMarshalBuffer.ARRAY_TYPE; + final short firstBytes = ITypeMarshalBuffer.ARRAY_TYPE; IValue val= getSize(); if (val == null) { - buffer.putByte(firstByte); + buffer.putShort(firstBytes); buffer.marshalType(getType()); return; } @@ -124,22 +124,22 @@ public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableTy if (num != null) { long lnum= num; if (lnum >= 0) { - buffer.putByte((byte) (firstByte | ITypeMarshalBuffer.FLAG1)); + buffer.putShort((short) (firstBytes | ITypeMarshalBuffer.FLAG1)); buffer.putLong(lnum); buffer.marshalType(getType()); return; } } - buffer.putByte((byte) (firstByte | ITypeMarshalBuffer.FLAG2)); + buffer.putShort((short) (firstBytes | ITypeMarshalBuffer.FLAG2)); buffer.marshalValue(val); buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IValue value= null; - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) { value = Value.create(buffer.getLong()); - } else if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + } else if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) { value = buffer.unmarshalValue(); } IType nested= buffer.unmarshalType(); 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 146430c12ff..625c1bd4b02 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 @@ -85,6 +85,7 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } static Kind getKind(final int simpleDeclSpecType) { + // Note: when adding a new kind, marshal() and unnmarshal() may need to be revised. switch (simpleDeclSpecType) { case IASTSimpleDeclSpecifier.t_bool: return Kind.eBoolean; @@ -224,25 +225,21 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { final int kind= getKind().ordinal(); - final int shiftedKind= kind * ITypeMarshalBuffer.FLAG1; + final int shiftedKind= kind * ITypeMarshalBuffer.FIRST_FLAG; final int modifiers= getModifiers(); - if (shiftedKind < ITypeMarshalBuffer.FLAG4 && modifiers == 0) { - buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); + if (modifiers == 0) { + buffer.putShort((short) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); } else { - buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | ITypeMarshalBuffer.FLAG4)); - buffer.putByte((byte) kind); + buffer.putShort((short) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind | ITypeMarshalBuffer.LAST_FLAG)); buffer.putByte((byte) modifiers); } } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - final boolean dense= (firstByte & ITypeMarshalBuffer.FLAG4) == 0; + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + final boolean haveModifiers= (firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0; int modifiers= 0; - int kind; - if (dense) { - kind= (firstByte & (ITypeMarshalBuffer.FLAG4 - 1)) / ITypeMarshalBuffer.FLAG1; - } else { - kind= buffer.getByte(); + int kind= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG - 1)) / ITypeMarshalBuffer.FIRST_FLAG; + if (haveModifiers) { modifiers= buffer.getByte(); } return new CPPBasicType(Kind.values()[kind], modifiers); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 7d88b8900a2..d5cee05e031 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -117,10 +117,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp private ICPPClassType typeInIndex; public CPPClassType(IASTName name, IBinding indexBinding) { - if (name instanceof ICPPASTQualifiedName) { - IASTName[] ns = ((ICPPASTQualifiedName) name).getNames(); - name = ns[ns.length - 1]; - } + name = stripQualifier(name); IASTNode parent = name.getParent(); while (parent instanceof IASTName) parent = parent.getParent(); @@ -195,7 +192,8 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public IScope getScope() { IASTName name = definition != null ? definition : declarations[0]; - + name = stripQualifier(name); + IScope scope = CPPVisitor.getContainingScope(name); if (definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) { IASTNode node = declarations[0].getParent().getParent(); @@ -406,4 +404,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp } return false; } + + private IASTName stripQualifier(IASTName name) { + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ ns.length - 1 ]; + } + return name; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java index 5b4cc473cc4..605f88708d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java @@ -227,8 +227,8 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE; + buffer.putShort(firstBytes); buffer.marshalBinding(fClassTemplate); buffer.putInt(fArguments.length); for (ICPPTemplateArgument arg : fArguments) { @@ -236,7 +236,7 @@ public class CPPDeferredClassInstance extends CPPUnknownBinding implements ICPPD } } - public static ICPPDeferredClassInstance unmarshal(IIndexFragment fragment, int firstByte, + public static ICPPDeferredClassInstance unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IBinding template= buffer.unmarshalBinding(); int argcount= buffer.getInt(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java index 1655e0beba4..f39a368a208 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java @@ -136,12 +136,12 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.FUNCTION_TYPE; - if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; - if (takesVarArgs()) firstByte |= ITypeMarshalBuffer.FLAG3; + short firstBytes= ITypeMarshalBuffer.FUNCTION_TYPE; + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (takesVarArgs()) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG3; - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.putInt(parameters.length); buffer.marshalType(returnType); @@ -150,14 +150,16 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { } } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getInt(); IType rt= buffer.unmarshalType(); IType[] pars= new IType[len]; for (int i = 0; i < pars.length; i++) { pars[i]= buffer.unmarshalType(); } - return new CPPFunctionType(rt, pars, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, - (firstByte & ITypeMarshalBuffer.FLAG2) != 0, (firstByte & ITypeMarshalBuffer.FLAG3) != 0); + return new CPPFunctionType(rt, pars, + (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, // const + (firstBytes & ITypeMarshalBuffer.FLAG3) != 0, // volatile + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0); // takes varargs } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java index 03bfac229b7..708ae3450c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterPackType.java @@ -72,12 +72,12 @@ public class CPPParameterPackType implements ICPPParameterPackType, ITypeContain @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.PACK_EXPANSION_TYPE; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.PACK_EXPANSION_TYPE; + buffer.putShort(firstBytes); buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); if (nested == null) return new ProblemBinding(null, IProblemBinding.SEMANTIC_INVALID_TYPE); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java index 57ba7226e1e..2c253c00595 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java @@ -97,20 +97,20 @@ public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointe @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.POINTER_TO_MEMBER_TYPE; - if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstByte |= ITypeMarshalBuffer.FLAG3; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.POINTER_TO_MEMBER_TYPE; + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + buffer.putShort(firstBytes); buffer.marshalType(getType()); buffer.marshalType(getMemberOfClass()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); IType memberOf= buffer.unmarshalType(); - return new CPPPointerToMemberType(nested, memberOf, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, - (firstByte & ITypeMarshalBuffer.FLAG2) != 0, - (firstByte & ITypeMarshalBuffer.FLAG3) != 0); + return new CPPPointerToMemberType(nested, memberOf, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java index 47fcc5db617..7993228e425 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java @@ -108,20 +108,20 @@ public class CPPPointerType implements IPointerType, ITypeContainer, ISerializab @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.POINTER_TYPE; - if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; - if (isRestrict()) firstByte |= ITypeMarshalBuffer.FLAG3; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.POINTER_TYPE; + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3; + buffer.putShort(firstBytes); final IType nestedType = getType(); buffer.marshalType(nestedType); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); - return new CPPPointerType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, - (firstByte & ITypeMarshalBuffer.FLAG2) != 0, - (firstByte & ITypeMarshalBuffer.FLAG3) != 0); + return new CPPPointerType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG3) != 0); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java index 28fad2be5be..df4c9201694 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java @@ -92,16 +92,16 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerial @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.CVQUALIFIER_TYPE; - if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; - if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.CVQUALIFIER_TYPE; + if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2; + buffer.putShort(firstBytes); buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); - return new CPPQualifierType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, - (firstByte & ITypeMarshalBuffer.FLAG2) != 0); + return new CPPQualifierType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, + (firstBytes & ITypeMarshalBuffer.FLAG2) != 0); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java index a8a64ea435b..abcf69bee9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java @@ -109,16 +109,16 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer, ISer @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.REFERENCE_TYPE; + short firstBytes= ITypeMarshalBuffer.REFERENCE_TYPE; if (isRValueReference()) { - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; } - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalType(getType()); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType nested= buffer.unmarshalType(); - return new CPPReferenceType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0); + return new CPPReferenceType(nested, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java index d18ff891a0e..866ecda85e2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalParameterPack; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; import org.eclipse.core.runtime.Assert; @@ -90,9 +91,8 @@ public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument { IType t= ((ICPPParameterPackType) type).getType(); if (t != null) { ICPPEvaluation evaluation; - if (fEvaluation instanceof EvalFixed) { - EvalFixed fixed = (EvalFixed) fEvaluation; - evaluation = new EvalFixed(t, fixed.getValueCategory(), fixed.getValue()); + if (fEvaluation instanceof EvalParameterPack) { + evaluation = ((EvalParameterPack) fEvaluation).getExpansionPattern(); } else { evaluation = new EvalTypeId(t, fEvaluation.getTemplateDefinition(), fEvaluation); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java index c1c7c5db9fa..2cc251a30d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameterMap.java @@ -114,6 +114,7 @@ public class CPPTemplateParameterMap implements ICPPTemplateParameterMap { return null; } + @Override public ICPPTemplateArgument getArgument(ICPPTemplateParameter tpar, int packOffset) { return getArgument(tpar.getParameterID(), packOffset); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java index a48d638f138..d65aa05790e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java @@ -82,8 +82,8 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.UNKNOWN_MEMBER_CLASS_INSTANCE; - buffer.putByte((byte) firstByte); + short firstBytes= ITypeMarshalBuffer.UNKNOWN_MEMBER_CLASS_INSTANCE; + buffer.putShort(firstBytes); buffer.marshalType(getOwnerType()); buffer.putCharArray(getNameCharArray()); buffer.putInt(arguments.length); @@ -92,7 +92,7 @@ public class CPPUnknownClassInstance extends CPPUnknownMemberClass implements IC } } - public static ICPPUnknownMemberClassInstance unmarshal(IIndexFragment fragment, int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ICPPUnknownMemberClassInstance unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType owner= buffer.unmarshalType(); char[] name = buffer.getCharArray(); int argcount= buffer.getInt(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java index 0866fd3d83f..db6db9d5fb4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownMember.java @@ -49,24 +49,24 @@ public class CPPUnknownMember extends CPPUnknownBinding implements ICPPUnknownMe @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= ITypeMarshalBuffer.UNKNOWN_MEMBER; + short firstBytes= ITypeMarshalBuffer.UNKNOWN_MEMBER; if (this instanceof ICPPField) { - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; } else if (this instanceof ICPPMethod) { - firstByte |= ITypeMarshalBuffer.FLAG2; + firstBytes |= ITypeMarshalBuffer.FLAG2; } - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalType(getOwnerType()); buffer.putCharArray(getNameCharArray()); } - public static IBinding unmarshal(IIndexFragment fragment, int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IBinding unmarshal(IIndexFragment fragment, short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType owner= buffer.unmarshalType(); char[] name = buffer.getCharArray(); - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) { return new PDOMCPPUnknownField(fragment, owner, name); - } else if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + } else if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) { return new PDOMCPPUnknownMethod(fragment, owner, name); } return new PDOMCPPUnknownMemberClass(fragment, owner, name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java index 650a36cc4bb..d90736f33af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPDependentEvaluation.java @@ -17,8 +17,11 @@ 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.cpp.ICPPASTTemplateDeclaration; +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.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; @@ -94,6 +97,63 @@ public abstract class CPPDependentEvaluation extends CPPEvaluation { buffer.marshalBinding(getTemplateDefinition()); } + /** + * Instantiate evaluations that represent subexpressions separated by commas. + * If a subexpression is a pack expansion expression, and the template parameter map + * contains a mapping for the parameter pack(s) that occur in its expansion pattern, + * the expansion pattern is instantiated once for each mapped template argument, + * and the resulting evaluations are returned in place of the pack expansion. + * + * This code is similar to CPPTemplates.instantiateArguments(), but applies to evaluations + * rather than template arguments. + */ + protected static ICPPEvaluation[] instantiateCommaSeparatedSubexpressions( + ICPPEvaluation[] subexpressions, ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] result = subexpressions; + int resultShift = 0; + for (int i = 0; i < subexpressions.length; i++) { + ICPPEvaluation origEval = subexpressions[i]; + ICPPEvaluation newEval; + if (origEval instanceof EvalParameterPack) { + origEval = ((EvalParameterPack) origEval).getExpansionPattern(); + if (origEval == null) { + newEval = EvalFixed.INCOMPLETE; + } else { + int packSize = origEval.determinePackSize(tpMap); + if (packSize == CPPTemplates.PACK_SIZE_FAIL || packSize == CPPTemplates.PACK_SIZE_NOT_FOUND) { + newEval = EvalFixed.INCOMPLETE; + } else if (packSize == CPPTemplates.PACK_SIZE_DEFER) { + newEval = origEval; + } else { + int shift = packSize - 1; + ICPPEvaluation[] newResult = new ICPPEvaluation[subexpressions.length + resultShift + shift]; + System.arraycopy(result, 0, newResult, 0, i + resultShift); + for (int j = 0; j < packSize; ++j) { + newEval = origEval.instantiate(tpMap, j, within, maxdepth, point); + newResult[i + resultShift + j] = newEval; + } + result = newResult; + resultShift += shift; + continue; + } + } + } else { + newEval = origEval.instantiate(tpMap, packOffset, within, maxdepth, point); + } + + if (result != subexpressions) + result[i + resultShift] = newEval; + else if (newEval != origEval) { + assert resultShift == 0; + result = new ICPPEvaluation[subexpressions.length]; + System.arraycopy(subexpressions, 0, result, 0, i); + result[i] = newEval; + } + } + return result; + } + /** * Used to defer the resolution of a template definition until it is needed, * to avoid recursion. The only valid operation on this binding is resolve(). 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 403516e53a8..1a3adf30e78 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 @@ -344,7 +344,7 @@ public class CPPVisitor extends ASTQueries { if (inScope == null) return false; - IBinding pb= names[names.length-2].resolvePreBinding(); + IBinding pb= names[names.length - 2].resolvePreBinding(); if (pb instanceof IProblemBinding) return false; @@ -930,11 +930,11 @@ public class CPPVisitor extends ASTQueries { if (name instanceof ICPPASTQualifiedName) { IASTName[] names = ((ICPPASTQualifiedName) name).getNames(); if (names.length >= 2) { - IBinding b= names[names.length-2].resolvePreBinding(); + IBinding b= names[names.length - 2].resolvePreBinding(); if (b instanceof IType) { IType classType= getNestedType((IType) b, TDEF); if (classType instanceof ICPPClassType) { - final char[] dtorName = names[names.length-1].getLookupKey(); + final char[] dtorName = names[names.length - 1].getLookupKey(); final char[] className = ((ICPPClassType) classType).getNameCharArray(); return CharArrayUtils.equals(dtorName, className); } @@ -1303,7 +1303,7 @@ public class CPPVisitor extends ASTQueries { IASTName name = findInnermostDeclarator(fnDeclarator).getName(); if (name instanceof ICPPASTQualifiedName) { IASTName[] ns = ((ICPPASTQualifiedName) name).getNames(); - name = ns[ns.length -1]; + name = ns[ns.length - 1]; } return getContainingScope(name); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java index bb919a9960d..79bd8aa5d78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java @@ -331,14 +331,14 @@ public class EvalBinary extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_BINARY); + buffer.putShort(ITypeMarshalBuffer.EVAL_BINARY); buffer.putByte((byte) fOperator); buffer.marshalEvaluation(fArg1, includeValue); buffer.marshalEvaluation(fArg2, includeValue); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); ICPPEvaluation arg1= (ICPPEvaluation) buffer.unmarshalEvaluation(); ICPPEvaluation arg2= (ICPPEvaluation) buffer.unmarshalEvaluation(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java index 8521bfa51c1..ef523a74551 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java @@ -109,14 +109,14 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_BINARY_TYPE_ID); + buffer.putShort(ITypeMarshalBuffer.EVAL_BINARY_TYPE_ID); buffer.putByte((byte) fOperator.ordinal()); buffer.marshalType(fType1); buffer.marshalType(fType2); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); IType arg1= buffer.unmarshalType(); IType arg2= buffer.unmarshalType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index 17a09e84790..cd6b3f000fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; @@ -246,6 +247,12 @@ public class EvalBinding extends CPPDependentEvaluation { } if (binding instanceof ICPPTemplateNonTypeParameter) { IType type= ((ICPPTemplateNonTypeParameter) binding).getType(); + // If the binding is a non-type parameter pack, it must have been + // referenced from inside the expansion pattern of a pack expansion. + // In such a context, the type of the binding is the type of each + // parameter in the parameter pack, not the type of the pack itself. + if (type instanceof ICPPParameterPackType) + type = ((ICPPParameterPackType) type).getType(); return prvalueType(type); } if (binding instanceof IVariable) { @@ -293,24 +300,24 @@ public class EvalBinding extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - byte firstByte = ITypeMarshalBuffer.EVAL_BINDING; + short firstBytes = ITypeMarshalBuffer.EVAL_BINDING; ICPPFunction parameterOwner = getParameterOwner(); if (parameterOwner != null) { // A function parameter cannot be marshalled directly. We are storing the owning // function and the parameter position instead. - buffer.putByte((byte) (ITypeMarshalBuffer.EVAL_BINDING | ITypeMarshalBuffer.FLAG1)); + buffer.putShort((short) (ITypeMarshalBuffer.EVAL_BINDING | ITypeMarshalBuffer.FLAG1)); buffer.marshalBinding(parameterOwner); buffer.putInt(getFunctionParameterPosition()); } else { - buffer.putByte(firstByte); + buffer.putShort(firstBytes); buffer.marshalBinding(fBinding); } buffer.marshalType(fFixedType ? fType : null); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) { ICPPFunction parameterOwner= (ICPPFunction) buffer.unmarshalBinding(); int parameterPosition= buffer.getInt(); IType type= buffer.unmarshalType(); @@ -329,14 +336,16 @@ public class EvalBinding extends CPPDependentEvaluation { ICPPClassSpecialization within, int maxdepth, IASTNode point) { IBinding origBinding = getBinding(); if (origBinding instanceof ICPPTemplateNonTypeParameter) { - ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateNonTypeParameter) origBinding); + ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateNonTypeParameter) origBinding, packOffset); if (argument != null && argument.isNonTypeValue()) { return argument.getNonTypeEvaluation(); } - // TODO(sprigogin): Do we need something similar for pack expansion? } else if (origBinding instanceof ICPPParameter) { ICPPParameter parameter = (ICPPParameter) origBinding; IType origType = parameter.getType(); + if (origType instanceof ICPPParameterPackType && packOffset != -1) { + origType = ((ICPPParameterPackType) origType).getType(); + } IType instantiatedType = CPPTemplates.instantiateType(origType, tpMap, packOffset, within, point); if (origType != instantiatedType) { return new EvalFixed(instantiatedType, ValueCategory.LVALUE, Value.create(this)); @@ -373,6 +382,10 @@ public class EvalBinding extends CPPDependentEvaluation { if (binding instanceof ICPPUnknownBinding) { return CPPTemplates.determinePackSize((ICPPUnknownBinding) binding, tpMap); } + if (binding instanceof ICPPParameter && ((ICPPParameter) binding).isParameterPack()) { + ICPPParameterPackType type = (ICPPParameterPackType) ((ICPPParameter) binding).getType(); + return CPPTemplates.determinePackSize(type.getType(), tpMap); + } if (binding instanceof ICPPSpecialization) { binding = ((ICPPSpecialization) binding).getSpecializedBinding(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java index 889a2f0ce07..85678480412 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java @@ -159,7 +159,7 @@ public class EvalComma extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_COMMA); + buffer.putShort(ITypeMarshalBuffer.EVAL_COMMA); buffer.putInt(fArguments.length); for (ICPPEvaluation arg : fArguments) { buffer.marshalEvaluation(arg, includeValue); @@ -167,7 +167,7 @@ public class EvalComma extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getInt(); ICPPEvaluation[] args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java index 6e8f0486710..571dd363b57 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java @@ -81,12 +81,12 @@ public class EvalCompound extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_COMPOUND); + buffer.putShort(ITypeMarshalBuffer.EVAL_COMPOUND); buffer.marshalEvaluation(fDelegate, includeValue); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); IBinding templateDefinition= buffer.unmarshalBinding(); return new EvalCompound(arg, templateDefinition); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java index c130d0f763b..77e669385c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java @@ -309,22 +309,22 @@ public class EvalConditional extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - int firstByte = ITypeMarshalBuffer.EVAL_CONDITIONAL; + short firstBytes = ITypeMarshalBuffer.EVAL_CONDITIONAL; if (fPositiveThrows) - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; if (fNegativeThrows) - firstByte |= ITypeMarshalBuffer.FLAG2; + firstBytes |= ITypeMarshalBuffer.FLAG2; - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalEvaluation(fCondition, includeValue); buffer.marshalEvaluation(fPositive, includeValue); buffer.marshalEvaluation(fNegative, includeValue); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - boolean pth= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; - boolean nth= (firstByte & ITypeMarshalBuffer.FLAG2) != 0; + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + boolean pth= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; + boolean nth= (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; ICPPEvaluation cond= (ICPPEvaluation) buffer.unmarshalEvaluation(); ICPPEvaluation pos= (ICPPEvaluation) buffer.unmarshalEvaluation(); ICPPEvaluation neg= (ICPPEvaluation) buffer.unmarshalEvaluation(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java index 343a7621f18..9041faf7c08 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java @@ -116,37 +116,37 @@ public class EvalFixed extends CPPEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { includeValue= includeValue && fValue != Value.UNKNOWN; - int firstByte = ITypeMarshalBuffer.EVAL_FIXED; + short firstBytes = ITypeMarshalBuffer.EVAL_FIXED; if (includeValue) - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; switch (fValueCategory) { - case LVALUE: - firstByte |= ITypeMarshalBuffer.FLAG2; - break; case PRVALUE: - firstByte |= ITypeMarshalBuffer.FLAG3; + firstBytes |= ITypeMarshalBuffer.FLAG2; + break; + case LVALUE: + firstBytes |= ITypeMarshalBuffer.FLAG3; break; default: break; } - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalType(fType); if (includeValue) { buffer.marshalValue(fValue); } } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - final boolean readValue= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + final boolean readValue= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; IValue value; ValueCategory cat; - switch (firstByte & (ITypeMarshalBuffer.FLAG2 | ITypeMarshalBuffer.FLAG3)) { + switch (firstBytes & (ITypeMarshalBuffer.FLAG2 | ITypeMarshalBuffer.FLAG3)) { case ITypeMarshalBuffer.FLAG2: - cat= LVALUE; + cat= PRVALUE; break; case ITypeMarshalBuffer.FLAG3: - cat= PRVALUE; + cat= LVALUE; break; default: cat= XVALUE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java index 7df4e724073..d6660dee6b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java @@ -174,7 +174,7 @@ public class EvalFunctionCall extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_FUNCTION_CALL); + buffer.putShort(ITypeMarshalBuffer.EVAL_FUNCTION_CALL); buffer.putInt(fArguments.length); for (ICPPEvaluation arg : fArguments) { buffer.marshalEvaluation(arg, includeValue); @@ -182,7 +182,7 @@ public class EvalFunctionCall extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getInt(); ICPPEvaluation[] args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { @@ -195,17 +195,8 @@ public class EvalFunctionCall extends CPPDependentEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = fArguments; - for (int i = 0; i < fArguments.length; i++) { - ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (arg != fArguments[i]) { - if (args == fArguments) { - args = new ICPPEvaluation[fArguments.length]; - System.arraycopy(fArguments, 0, args, 0, fArguments.length); - } - args[i] = arg; - } - } + ICPPEvaluation[] args = instantiateCommaSeparatedSubexpressions(fArguments, tpMap, + packOffset, within, maxdepth, point); if (args == fArguments) return this; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java index a267dd3f409..c2620582117 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java @@ -109,13 +109,13 @@ public class EvalFunctionSet extends CPPDependentEvaluation { public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { final ICPPFunction[] bindings = fFunctionSet.getBindings(); final ICPPTemplateArgument[] args = fFunctionSet.getTemplateArguments(); - int firstByte = ITypeMarshalBuffer.EVAL_FUNCTION_SET; + short firstBytes = ITypeMarshalBuffer.EVAL_FUNCTION_SET; if (fAddressOf) - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; if (args != null) - firstByte |= ITypeMarshalBuffer.FLAG2; + firstBytes |= ITypeMarshalBuffer.FLAG2; - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.putInt(bindings.length); for (ICPPFunction binding : bindings) { buffer.marshalBinding(binding); @@ -129,15 +129,15 @@ public class EvalFunctionSet extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - final boolean addressOf= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + final boolean addressOf= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; int bindingCount= buffer.getInt(); ICPPFunction[] bindings= new ICPPFunction[bindingCount]; for (int i = 0; i < bindings.length; i++) { bindings[i]= (ICPPFunction) buffer.unmarshalBinding(); } ICPPTemplateArgument[] args= null; - if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) { int len= buffer.getInt(); args = new ICPPTemplateArgument[len]; for (int i = 0; i < args.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 49960745ddc..bf6318bced9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -145,15 +145,15 @@ public class EvalID extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - int firstByte = ITypeMarshalBuffer.EVAL_ID; + short firstBytes = ITypeMarshalBuffer.EVAL_ID; if (fAddressOf) - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; if (fQualified) - firstByte |= ITypeMarshalBuffer.FLAG2; + firstBytes |= ITypeMarshalBuffer.FLAG2; if (fTemplateArgs != null) - firstByte |= ITypeMarshalBuffer.FLAG3; + firstBytes |= ITypeMarshalBuffer.FLAG3; - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalEvaluation(fFieldOwner, false); buffer.putCharArray(fName); buffer.marshalBinding(fNameOwner); @@ -166,14 +166,14 @@ public class EvalID extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - final boolean addressOf= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; - final boolean qualified= (firstByte & ITypeMarshalBuffer.FLAG2) != 0; + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + final boolean addressOf= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; + final boolean qualified= (firstBytes & ITypeMarshalBuffer.FLAG2) != 0; ICPPEvaluation fieldOwner= (ICPPEvaluation) buffer.unmarshalEvaluation(); char[] name= buffer.getCharArray(); IBinding nameOwner= buffer.unmarshalBinding(); ICPPTemplateArgument[] args= null; - if ((firstByte & ITypeMarshalBuffer.FLAG3) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG3) != 0) { int len= buffer.getInt(); args = new ICPPTemplateArgument[len]; for (int i = 0; i < args.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java index 8364ff49b94..3da037ea5e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java @@ -91,7 +91,7 @@ public class EvalInitList extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_INIT_LIST); + buffer.putShort(ITypeMarshalBuffer.EVAL_INIT_LIST); buffer.putInt(fClauses.length); for (ICPPEvaluation arg : fClauses) { buffer.marshalEvaluation(arg, includeValue); @@ -99,7 +99,7 @@ public class EvalInitList extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int len= buffer.getInt(); ICPPEvaluation[] args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { @@ -112,17 +112,8 @@ public class EvalInitList extends CPPDependentEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] clauses = fClauses; - for (int i = 0; i < fClauses.length; i++) { - ICPPEvaluation clause = fClauses[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (clause != fClauses[i]) { - if (clauses == fClauses) { - clauses = new ICPPEvaluation[fClauses.length]; - System.arraycopy(fClauses, 0, clauses, 0, fClauses.length); - } - clauses[i] = clause; - } - } + ICPPEvaluation[] clauses = instantiateCommaSeparatedSubexpressions(fClauses, tpMap, + packOffset, within, maxdepth, point); if (clauses == fClauses) return this; return new EvalInitList(clauses, getTemplateDefinition()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java index 240ab162e65..90149b8358d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java @@ -295,27 +295,27 @@ public class EvalMemberAccess extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - int firstByte = ITypeMarshalBuffer.EVAL_MEMBER_ACCESS; + short firstBytes = ITypeMarshalBuffer.EVAL_MEMBER_ACCESS; if (fIsPointerDeref) - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; if (fOwnerValueCategory == LVALUE) { - firstByte |= ITypeMarshalBuffer.FLAG2; + firstBytes |= ITypeMarshalBuffer.FLAG2; } else if (fOwnerValueCategory == XVALUE) { - firstByte |= ITypeMarshalBuffer.FLAG3; + firstBytes |= ITypeMarshalBuffer.FLAG3; } - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalType(fOwnerType); buffer.marshalBinding(fMember); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - boolean isDeref= (firstByte & ITypeMarshalBuffer.FLAG1) != 0; + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + boolean isDeref= (firstBytes & ITypeMarshalBuffer.FLAG1) != 0; ValueCategory ownerValueCat; - if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG2) != 0) { ownerValueCat= LVALUE; - } else if ((firstByte & ITypeMarshalBuffer.FLAG3) != 0) { + } else if ((firstBytes & ITypeMarshalBuffer.FLAG3) != 0) { ownerValueCat= XVALUE; } else { ownerValueCat= PRVALUE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalParameterPack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalParameterPack.java new file mode 100644 index 00000000000..4b6d921accc --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalParameterPack.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2013 Nathan Ridge. + * 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: + * Nathan Ridge - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; + +import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameterPackType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; +import org.eclipse.core.runtime.CoreException; + +/** + * Evaluation for a pack expansion expression. + */ +public class EvalParameterPack extends CPPDependentEvaluation { + + private ICPPEvaluation fExpansionPattern; + private IType fType; + + public EvalParameterPack(ICPPEvaluation expansionPattern, IASTNode pointOfDefinition) { + this(expansionPattern, findEnclosingTemplate(pointOfDefinition)); + } + public EvalParameterPack(ICPPEvaluation expansionPattern, IBinding templateDefinition) { + super(templateDefinition); + fExpansionPattern = expansionPattern; + } + + public ICPPEvaluation getExpansionPattern() { + return fExpansionPattern; + } + + @Override + public boolean isInitializerList() { + return fExpansionPattern.isInitializerList(); + } + + @Override + public boolean isFunctionSet() { + return fExpansionPattern.isFunctionSet(); + } + + @Override + public boolean isTypeDependent() { + return fExpansionPattern.isTypeDependent(); + } + + @Override + public boolean isValueDependent() { + return fExpansionPattern.isValueDependent(); + } + + @Override + public IType getTypeOrFunctionSet(IASTNode point) { + if (fType == null) { + IType type = fExpansionPattern.getTypeOrFunctionSet(point); + if (type == null) { + fType= ProblemType.UNKNOWN_FOR_EXPRESSION; + } else { + fType= new CPPParameterPackType(type); + } + } + return fType; + } + + @Override + public IValue getValue(IASTNode point) { + return Value.create(fExpansionPattern); + } + + @Override + public ValueCategory getValueCategory(IASTNode point) { + return ValueCategory.PRVALUE; + } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation expansionPattern = fExpansionPattern.instantiate(tpMap, packOffset, within, maxdepth, point); + if (expansionPattern == fExpansionPattern) + return this; + return new EvalParameterPack(expansionPattern, getTemplateDefinition()); + } + + @Override + public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap, + int maxdepth, IASTNode point) { + ICPPEvaluation expansionPattern = fExpansionPattern.computeForFunctionCall(parameterMap, maxdepth, point); + if (expansionPattern == fExpansionPattern) + return this; + return new EvalParameterPack(expansionPattern, getTemplateDefinition()); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.PACK_SIZE_NOT_FOUND; + } + + @Override + public boolean referencesTemplateParameter() { + return fExpansionPattern.referencesTemplateParameter(); + } + + @Override + public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { + buffer.putShort(ITypeMarshalBuffer.EVAL_PARAMETER_PACK); + buffer.marshalEvaluation(fExpansionPattern, includeValue); + marshalTemplateDefinition(buffer); + } + + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { + ICPPEvaluation expansionPattern = (ICPPEvaluation) buffer.unmarshalEvaluation(); + IBinding templateDefinition = buffer.unmarshalBinding(); + return new EvalParameterPack(expansionPattern, templateDefinition); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index 60b06027cd3..59cccee4e1a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -121,11 +121,11 @@ public class EvalTypeId extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - int firstByte = ITypeMarshalBuffer.EVAL_TYPE_ID; + short firstBytes = ITypeMarshalBuffer.EVAL_TYPE_ID; if (includeValue) - firstByte |= ITypeMarshalBuffer.FLAG1; + firstBytes |= ITypeMarshalBuffer.FLAG1; - buffer.putByte((byte) firstByte); + buffer.putShort(firstBytes); buffer.marshalType(fInputType); if (includeValue) { buffer.putInt(fArguments.length); @@ -136,10 +136,10 @@ public class EvalTypeId extends CPPDependentEvaluation { marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { IType type= buffer.unmarshalType(); ICPPEvaluation[] args= null; - if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) { + if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) { int len= buffer.getInt(); args = new ICPPEvaluation[len]; for (int i = 0; i < args.length; i++) { @@ -153,19 +153,9 @@ public class EvalTypeId extends CPPDependentEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = fArguments; - if (fArguments != null) { - for (int i = 0; i < fArguments.length; i++) { - ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); - if (arg != fArguments[i]) { - if (args == fArguments) { - args = new ICPPEvaluation[fArguments.length]; - System.arraycopy(fArguments, 0, args, 0, fArguments.length); - } - args[i] = arg; - } - } - } + ICPPEvaluation[] args = null; + if (fArguments != null) + args = instantiateCommaSeparatedSubexpressions(fArguments, tpMap, packOffset, within, maxdepth, point); IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); if (args == fArguments && type == fInputType) return this; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index f3dc221be57..147d903871d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -300,14 +300,14 @@ public class EvalUnary extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_UNARY); + buffer.putShort(ITypeMarshalBuffer.EVAL_UNARY); buffer.putByte((byte) fOperator); buffer.marshalEvaluation(fArgument, includeValue); buffer.marshalBinding(fAddressOfQualifiedNameBinding); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); IBinding binding= buffer.unmarshalBinding(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java index c7ade038d89..417c079a99f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java @@ -175,13 +175,13 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation { @Override public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.EVAL_UNARY_TYPE_ID); + buffer.putShort(ITypeMarshalBuffer.EVAL_UNARY_TYPE_ID); buffer.putByte((byte) fOperator); buffer.marshalType(fOrigType); marshalTemplateDefinition(buffer); } - public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static ISerializableEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { int op= buffer.getByte(); IType arg= buffer.unmarshalType(); IBinding templateDefinition= buffer.unmarshalBinding(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java index eb52bce8ca3..d3f5602b7e4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java @@ -64,7 +64,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -518,7 +517,7 @@ public class LookupData extends ScopeLookupData { int count= 0; if (functionArgs != null) { for (ICPPEvaluation arg : functionArgs) { - if (arg instanceof EvalFixed && arg.getTypeOrFunctionSet(null) instanceof ICPPParameterPackType) + if (arg instanceof EvalParameterPack) count++; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java index 7ec523e7b46..684dbec2302 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java @@ -25,8 +25,8 @@ import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.core.runtime.CoreException; class SignatureBuilder implements ITypeMarshalBuffer { - private static final byte NULL_TYPE= 0; - private static final byte UNSTORABLE_TYPE= (byte) -1; + private static final short NULL_TYPE = 0x0000; + private static final short UNSTORABLE_TYPE = 0x001D; private final StringBuilder fBuffer; @@ -51,7 +51,7 @@ class SignatureBuilder implements ITypeMarshalBuffer { if (binding instanceof ISerializableType) { ((ISerializableType) binding).marshal(this); } else if (binding == null) { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } else { appendSeparator(); if (binding instanceof ICPPBinding) { @@ -73,19 +73,19 @@ class SignatureBuilder implements ITypeMarshalBuffer { if (type instanceof ISerializableType) { ((ISerializableType) type).marshal(this); } else if (type == null) { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } else if (type instanceof IBinding) { marshalBinding((IBinding) type); } else { assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - putByte(UNSTORABLE_TYPE); + putShort(UNSTORABLE_TYPE); } } @Override public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException { if (eval == null) { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } else { eval.marshal(this, includeValues); } @@ -94,16 +94,16 @@ class SignatureBuilder implements ITypeMarshalBuffer { @Override public void marshalValue(IValue value) throws CoreException { if (value instanceof Value) { - ((Value) value).marshall(this); + ((Value) value).marshal(this); } else { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } } @Override public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { if (arg.isNonTypeValue()) { - putByte(VALUE); + putShort(VALUE); arg.getNonTypeEvaluation().marshal(this, true); } else { marshalType(arg.getTypeValue()); @@ -122,6 +122,12 @@ class SignatureBuilder implements ITypeMarshalBuffer { fBuffer.append(value); } + @Override + public void putShort(short value) { + appendSeparator(); + fBuffer.append(value); + } + @Override public void putInt(int value) { appendSeparator(); @@ -187,6 +193,11 @@ class SignatureBuilder implements ITypeMarshalBuffer { throw new UnsupportedOperationException(); } + @Override + public short getShort() throws CoreException { + throw new UnsupportedOperationException(); + } + @Override public int getInt() throws CoreException { throw new UnsupportedOperationException(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java index d77e3e96595..c1bccc5280b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java @@ -63,11 +63,11 @@ public class TypeOfDependentExpression implements ICPPUnknownType, ISerializable @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { - buffer.putByte(ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE); + buffer.putShort(ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE); buffer.marshalEvaluation(fEvaluation, false); } - public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException { ISerializableEvaluation eval= buffer.unmarshalEvaluation(); if (eval instanceof ICPPEvaluation) return new TypeOfDependentExpression((ICPPEvaluation) eval); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index 3589b59cfa7..aa0d6e90467 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java @@ -85,6 +85,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionSet; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalID; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalInitList; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalMemberAccess; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalParameterPack; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUnary; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUnaryTypeID; @@ -375,6 +376,14 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { e= new EvalMemberAccess(a2, e.getOwnerValueCategory(), b2, e.isPointerDeref(), templateDefinition2); return e; } + if (eval instanceof EvalParameterPack) { + EvalParameterPack e = (EvalParameterPack) eval; + ICPPEvaluation a = e.getExpansionPattern(); + ICPPEvaluation a2 = getCompositeEvaluation(a); + if (a != a2 || templateDefinition != templateDefinition2) + e = new EvalParameterPack(a2, templateDefinition2); + return e; + } if (eval instanceof EvalTypeId) { EvalTypeId e= (EvalTypeId) eval; IType a = e.getInputType(); @@ -535,6 +544,10 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { return new CompositeCPPTypedefSpecialization(this, (ICPPBinding) binding); } else if (binding instanceof ICPPUsingDeclaration) { return new CompositeCPPUsingDeclarationSpecialization(this, (ICPPUsingDeclaration) binding); + } else if (binding instanceof ICPPEnumeration) { + return new CompositeCPPEnumerationSpecialization(this, (ICPPEnumeration) binding); + } else if (binding instanceof IEnumerator) { + return new CompositeCPPEnumeratorSpecialization(this, (IEnumerator) binding); } else { throw new CompositingNotImplementedError("Composite binding unavailable for " + binding + " " + binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerationSpecialization.java new file mode 100644 index 00000000000..139f53ecf68 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumerationSpecialization.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2013 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.cpp; + +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +class CompositeCPPEnumerationSpecialization extends CompositeCPPEnumeration implements ICPPSpecialization { + public CompositeCPPEnumerationSpecialization(ICompositesFactory cf, ICPPEnumeration delegate) { + super(cf, delegate); + } + + @Override + public IBinding getSpecializedBinding() { + return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); + } + + @Override + public ICPPTemplateParameterMap getTemplateParameterMap() { + IBinding owner= getOwner(); + if (owner instanceof ICPPSpecialization) { + return ((ICPPSpecialization) owner).getTemplateParameterMap(); + } + return CPPTemplateParameterMap.EMPTY; + } + + @Override + @Deprecated + public ObjectMap getArgumentMap() { + return TemplateInstanceUtil.getArgumentMap(cf, rbinding); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumeratorSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumeratorSpecialization.java new file mode 100644 index 00000000000..bc6ad7c1ec6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumeratorSpecialization.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2013 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.cpp; + +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +class CompositeCPPEnumeratorSpecialization extends CompositeCPPEnumerator implements ICPPSpecialization { + public CompositeCPPEnumeratorSpecialization(ICompositesFactory cf, IEnumerator delegate) { + super(cf, delegate); + } + + @Override + public IBinding getSpecializedBinding() { + return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); + } + + @Override + public ICPPTemplateParameterMap getTemplateParameterMap() { + IBinding owner= getOwner(); + if (owner instanceof ICPPSpecialization) { + return ((ICPPSpecialization) owner).getTemplateParameterMap(); + } + return CPPTemplateParameterMap.EMPTY; + } + + @Override + @Deprecated + public ObjectMap getArgumentMap() { + return TemplateInstanceUtil.getArgumentMap(cf, rbinding); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java index fede76028e2..c9fd5d36780 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTypedefSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTypedefSpecialization.java index 3e6b2e1069c..75a711eb54c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTypedefSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTypedefSpecialization.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index df417262095..e579274828d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -1006,9 +1006,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter { IASTTranslationUnit ast= createAST(lang, codeReader, scanInfo, isSource, fASTOptions, ctx, pm); fStatistics.fParsingTime += System.currentTimeMillis() - start; if (ast != null) { - // Give the new AST-TU a chance to recognize its translation unit before it is written + // Give the new AST a chance to recognize its translation unit before it is written // to the index. - ( (ASTTranslationUnit)ast ).setOriginatingTranslationUnit( (ITranslationUnit)tu ); + ((ASTTranslationUnit) ast).setOriginatingTranslationUnit((ITranslationUnit) tu); writeToIndex(lang.getLinkageID(), ast, codeReader, ctx, pm); } } catch (CoreException e) { 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 387ee12009b..9c4e5668329 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 @@ -209,7 +209,7 @@ public class PDOM extends PlatformObject implements IPDOM { * 113.0 - Changed marshaling of values, bug 327878 * #114.0# - Partial specializations for class template specializations, bug 332884. * - Corrected signatures for function templates, bug 335062. <> - * + * * CDT 8.1 development (versions not supported on the 8.0.x branch) * 120.0 - Enumerators in global index, bug 356235 * 120.1 - Specializations of using declarations, bug 357293. @@ -218,7 +218,7 @@ public class PDOM extends PlatformObject implements IPDOM { * 123.0 - Combined file size and encoding hash code. * 124.0 - GCC attributes and NO_RETURN flag for functions. * #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <> - * + * * CDT 8.2 development (versions not supported on the 8.1.x branch) * 130.0 - Dependent expressions, bug 299911. * 131.0 - Dependent expressions part 2, bug 299911. @@ -231,12 +231,13 @@ public class PDOM extends PlatformObject implements IPDOM { * 138.0 - Constexpr functions, bug 395238. * 139.0 - More efficient and robust storage of types and template arguments, bug 395243. * 140.0 - Enumerators with dependent values, bug 389009. - * 140.1 - Mechanism for tagging nodes with extended data, bug TODO - * 141.0 - Storing enclosing template bindings for evaluations, bug 399829 + * 140.1 - Mechanism for tagging nodes with extended data, bug 400020 + * 141.0 - Storing enclosing template bindings for evaluations, bug 399829. + * 142.0 - Changed marshalling of evaluations to allow more than 15 evaluation kinds, bug 401479. */ - private static final int MIN_SUPPORTED_VERSION= version(141, 0); - private static final int MAX_SUPPORTED_VERSION= version(141, Short.MAX_VALUE); - private static final int DEFAULT_VERSION = version(141, 0); + private static final int MIN_SUPPORTED_VERSION= version(142, 0); + private static final int MAX_SUPPORTED_VERSION= version(142, Short.MAX_VALUE); + private static final int DEFAULT_VERSION = version(142, 0); private static int version(int major, int minor) { return (major << 16) + minor; @@ -465,10 +466,8 @@ public class PDOM extends PlatformObject implements IPDOM { } public PDOMTagIndex getTagIndex() throws CoreException { - if (tagIndex == null) - { - // tag index can only be stored in database versions 139.1 or greater - tagIndex = new PDOMTagIndex( db.getVersion() >= version( 139, 1 ) ? db : null, TAG_INDEX ); + if (tagIndex == null) { + tagIndex = new PDOMTagIndex(db, TAG_INDEX); } return tagIndex; } @@ -483,7 +482,7 @@ public class PDOM extends PlatformObject implements IPDOM { } /** - * Returns the index of files containg unresolved includes. + * Returns the index of files containing unresolved includes. */ public BTree getIndexOfFilesWithUnresolvedIncludes() throws CoreException { if (indexOfFiledWithUnresolvedIncludes == null) { @@ -562,7 +561,7 @@ public class PDOM extends PlatformObject implements IPDOM { }); return files.toArray(new IIndexFragmentFile[files.size()]); } - + protected IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location, ISignificantMacros sigMacros) throws CoreException { PDOMLinkage linkage= createLinkage(linkageID); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/PDOMStringSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/PDOMStringSet.java index 976278d06e7..3c2774c21e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/PDOMStringSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/PDOMStringSet.java @@ -4,6 +4,9 @@ * 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 Eidsness - Initial implementation */ package org.eclipse.cdt.internal.core.pdom.db; @@ -14,27 +17,25 @@ import java.util.Map; import org.eclipse.core.runtime.CoreException; /** - * A container for storing a set of strings in the Database. The container allows only one - * instance of each string to be stored. + * A container for storing a set of strings in the Database. The container allows only one instance of each + * string to be stored. *

- * This implementation should only be used when the set is expected to be small. It uses a - * singly linked list for storing strings in Database. Which means that a linear lookup is needed - * to find strings in the list. An in-memory, lazily-loaded, cache is provided so the list will - * only be fully retrieved once in the lifetime of this instance. A BTree will be more efficient - * for larger sets. + * This implementation should only be used when the set is expected to be small. It uses a singly linked list + * for storing strings in Database. Which means that a linear lookup is needed to find strings in the list. An + * in-memory, lazily-loaded, cache is provided so the list will only be fully retrieved once in the lifetime + * of this instance. A BTree will be more efficient for larger sets. */ -public class PDOMStringSet -{ +public class PDOMStringSet { private final Database db; private long ptr; private long head; private long loaded; + // A lazily initialized, in-memory cache that maps a persisted string to its storage record. private Map lazyCache; - public PDOMStringSet( Database db, long ptr ) throws CoreException - { + public PDOMStringSet(Database db, long ptr) throws CoreException { this.db = db; this.ptr = ptr; @@ -42,119 +43,107 @@ public class PDOMStringSet loaded = 0; } - public void clearCaches() - { + public void clearCaches() { head = 0; loaded = 0; - if( lazyCache != null ) + if (lazyCache != null) lazyCache = null; } - private long getHead() throws CoreException - { - if( head == 0 ) - head = db.getRecPtr( ptr ); + private long getHead() throws CoreException { + if (head == 0) + head = db.getRecPtr(ptr); return head; } - // A simple enum describing the type of the information that is stored in the Database. Each + // A simple enum describing the type of the information that is stored in the Database. Each // enumerator represents a single field in the persistent structure and is able to answer its // offset in that structure. - private static enum NodeType - { - Next, - Item, - _last; + private static enum NodeType { + Next, Item, _last; // NOTE: All fields are pointers, if that changes then these initializations will need - // to be updated. + // to be updated. public final long offset = ordinal() * Database.PTR_SIZE; - public static final int sizeof = (int)_last.offset; + public static final int sizeof = (int) _last.offset; /** Return the value of the pointer stored in this field in the given instance. */ - public long get( Database db, long instance ) throws CoreException - { - return db.getRecPtr( instance + offset ); + public long get(Database db, long instance) throws CoreException { + return db.getRecPtr(instance + offset); } /** Store the given pointer into this field in the given instance. */ - public void put( Database db, long instance, long value ) throws CoreException - { - db.putRecPtr( instance + offset, value ); + public void put(Database db, long instance, long value) throws CoreException { + db.putRecPtr(instance + offset, value); } } /** - * Adds the given string to the receiving set. May cause the entire list to be loaded from the - * Database while testing for uniqueness. Returns the record of the string that was inserted into - * the list. + * Adds the given string to the receiving set. May cause the entire list to be loaded from the Database + * while testing for uniqueness. Returns the record of the string that was inserted into the list. */ - public long add( String str ) throws CoreException - { - long record = find( str ); - if( record != 0 ) + public long add(String str) throws CoreException { + long record = find(str); + if (record != 0) return record; - IString string = db.newString( str ); + IString string = db.newString(str); record = string.getRecord(); - long new_node = db.malloc( NodeType.sizeof ); - NodeType.Next.put( db, new_node, getHead() ); - NodeType.Item.put( db, new_node, record ); + long new_node = db.malloc(NodeType.sizeof); + NodeType.Next.put(db, new_node, getHead()); + NodeType.Item.put(db, new_node, record); - if( lazyCache == null ) + if (lazyCache == null) lazyCache = new HashMap(); - lazyCache.put( str, record ); + lazyCache.put(str, record); // If the Database has already been partially searched, then the loaded pointer will be after the - // head. Since we've already put this new record into the lazy cache, there is no reason to try to - // load it again. We put the new node at the start of the list so that it will be before the loaded + // head. Since we've already put this new record into the lazy cache, there is no reason to try to + // load it again. We put the new node at the start of the list so that it will be before the loaded // pointer. head = new_node; - if( loaded == 0 ) + if (loaded == 0) loaded = new_node; - db.putRecPtr( ptr, new_node ); + db.putRecPtr(ptr, new_node); return record; } /** - * Search for the given string in the receiver. This could cause the entire list to be loaded from - * the Database. The results are cached, so the list will only be loaded one time during the lifetime - * of this instance. Returns the record of the String. + * Search for the given string in the receiver. This could cause the entire list to be loaded from the + * Database. The results are cached, so the list will only be loaded one time during the lifetime of this + * instance. Returns the record of the String. */ - public long find( String str ) throws CoreException - { - if( lazyCache != null ) - { - Long l = lazyCache.get( str ); - if( l != null ) + public long find(String str) throws CoreException { + if (lazyCache != null) { + Long l = lazyCache.get(str); + if (l != null) return l.longValue(); } // if there is nothing in the Database, then there is nothing to load - if( getHead() == 0 ) + if (getHead() == 0) return 0; // otherwise prepare the cache for the data that is about to be loaded - if( lazyCache == null ) + if (lazyCache == null) lazyCache = new HashMap(); // if nothing has been loaded, then start loading with the head node, otherwise continue // loading from whatever is after the last loaded node - long curr = loaded == 0 ? getHead() : NodeType.Next.get( db, loaded ); - while( curr != 0 ) - { - long next = NodeType.Next.get( db, curr ); - long item = NodeType.Item.get( db, curr ); + long curr = loaded == 0 ? getHead() : NodeType.Next.get(db, loaded); + while (curr != 0) { + long next = NodeType.Next.get(db, curr); + long item = NodeType.Item.get(db, curr); - IString string = db.getString( item ); + IString string = db.getString(item); // put the value into the cache - lazyCache.put( string.getString(), Long.valueOf( item ) ); + lazyCache.put(string.getString(), Long.valueOf(item)); // return immediately if this is the target - if( string.compare( str, true ) == 0 ) + if (string.compare(str, true) == 0) return item; // otherwise keep looking @@ -168,31 +157,27 @@ public class PDOMStringSet /** * Return a pointer to the record of the String that was removed. */ - public long remove( String str ) throws CoreException - { - if( lazyCache != null ) - lazyCache.remove( str ); + public long remove(String str) throws CoreException { + if (lazyCache != null) + lazyCache.remove(str); long prev = 0; long curr = getHead(); - while( curr != 0 ) - { - long next = NodeType.Next.get( db, curr ); - long item = NodeType.Item.get( db, curr ); + while (curr != 0) { + long next = NodeType.Next.get(db, curr); + long item = NodeType.Item.get(db, curr); - IString string = db.getString( item ); + IString string = db.getString(item); - if( string.compare( str, true ) == 0 ) - { - if( head != curr ) - NodeType.Next.put( db, prev, next ); - else - { - db.putRecPtr( ptr, next ); + if (string.compare(str, true) == 0) { + if (head != curr) + NodeType.Next.put(db, prev, next); + else { + db.putRecPtr(ptr, next); head = next; } - db.free( curr ); + db.free(curr); return item; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java index 99d99e82e3f..bb3af31e2a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java @@ -35,10 +35,10 @@ import org.eclipse.core.runtime.CoreException; */ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { public static final byte[] EMPTY= { 0, 0, 0, 0, 0, 0 }; - public static final byte NULL_TYPE= 0; - public static final byte INDIRECT_TYPE= (byte) -1; - public static final byte BINDING_TYPE= (byte) -2; - public static final byte UNSTORABLE_TYPE= (byte) -3; + public static final byte NULL_TYPE = 0x00; + public static final byte INDIRECT_TYPE = 0x1F; + public static final byte BINDING_TYPE = 0x1E; + public static final byte UNSTORABLE_TYPE = 0x1D; public static final IType UNSTORABLE_TYPE_PROBLEM = new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED); @@ -83,13 +83,13 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { if (binding instanceof ISerializableType) { ((ISerializableType) binding).marshal(this); } else if (binding == null) { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } else { PDOMNode pb= fLinkage.addTypeBinding(binding); if (pb == null) { - putByte(UNSTORABLE_TYPE); + putShort(UNSTORABLE_TYPE); } else { - putByte(BINDING_TYPE); + putShort(BINDING_TYPE); putByte((byte) 0); putRecordPointer(pb.getRecord()); } @@ -98,19 +98,17 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { @Override public IBinding unmarshalBinding() throws CoreException { - if (fPos >= fBuffer.length) - throw unmarshallingError(); - - byte firstByte= fBuffer[fPos]; - if (firstByte == BINDING_TYPE) { - fPos += 2; + int oldPos = fPos; + short firstBytes = getShort(); + if (firstBytes == BINDING_TYPE) { + fPos += 1; long rec= getRecordPointer(); return (IBinding) fLinkage.getNode(rec); - } else if (firstByte == NULL_TYPE || firstByte == UNSTORABLE_TYPE) { - fPos++; + } else if (firstBytes == NULL_TYPE || firstBytes == UNSTORABLE_TYPE) { return null; } + fPos = oldPos; // fLinkage.unmarshalBinding() will read firstBytes again return fLinkage.unmarshalBinding(this); } @@ -119,40 +117,37 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { if (type instanceof ISerializableType) { ((ISerializableType) type).marshal(this); } else if (type == null) { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } else if (type instanceof IBinding) { marshalBinding((IBinding) type); } else { assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - putByte(UNSTORABLE_TYPE); + putShort(UNSTORABLE_TYPE); } } @Override public IType unmarshalType() throws CoreException { - if (fPos >= fBuffer.length) - throw unmarshallingError(); - - byte firstByte= fBuffer[fPos]; - if (firstByte == BINDING_TYPE) { - fPos += 2; + int oldPos = fPos; + short firstBytes = getShort(); + if (firstBytes == BINDING_TYPE) { + fPos += 1; long rec= getRecordPointer(); return (IType) fLinkage.getNode(rec); - } else if (firstByte == NULL_TYPE) { - fPos++; + } else if (firstBytes == NULL_TYPE) { return null; - } else if (firstByte == UNSTORABLE_TYPE) { - fPos++; + } else if (firstBytes == UNSTORABLE_TYPE) { return UNSTORABLE_TYPE_PROBLEM; } + fPos = oldPos; // fLinkage.unmarshalType() will read firstBytes again return fLinkage.unmarshalType(this); } @Override public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException { if (eval == null) { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } else { eval.marshal(this, includeValues); } @@ -160,23 +155,15 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { @Override public ISerializableEvaluation unmarshalEvaluation() throws CoreException { - if (fPos >= fBuffer.length) - throw unmarshallingError(); - - byte firstByte= fBuffer[fPos]; - if (firstByte == NULL_TYPE) { - fPos++; - return null; - } return fLinkage.unmarshalEvaluation(this); } @Override public void marshalValue(IValue value) throws CoreException { if (value instanceof Value) { - ((Value) value).marshall(this); + ((Value) value).marshal(this); } else { - putByte(NULL_TYPE); + putShort(NULL_TYPE); } } @@ -191,7 +178,7 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { @Override public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { if (arg.isNonTypeValue()) { - putByte(VALUE); + putShort(VALUE); arg.getNonTypeEvaluation().marshal(this, true); } else { final IType typeValue = arg.getTypeValue(); @@ -207,11 +194,12 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { @Override public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { - int firstByte= getByte(); - if (firstByte == VALUE) { + int oldPos = fPos; + short firstBytes = getShort(); + if (firstBytes == VALUE) { return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation(), null); } else { - fPos--; + fPos = oldPos; IType type = unmarshalType(); IType originalType = unmarshalType(); if (originalType == null || originalType == UNSTORABLE_TYPE_PROBLEM) @@ -284,6 +272,11 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { return result; } + @Override + public void putShort(short value) { + putInt(value); + } + @Override public void putInt(int value) { do { @@ -306,6 +299,14 @@ public final class TypeMarshalBuffer implements ITypeMarshalBuffer { } while (value != 0); } + @Override + public short getShort() throws CoreException { + int result = getInt(); + if (result > Short.MAX_VALUE) + unmarshallingError(); + return (short) result; + } + @Override public int getInt() throws CoreException { int b = getByte(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 233bda56d5a..bbe90bf06f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -50,41 +50,42 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4 private static final int FIRST_REF_OFFSET = PDOMNamedNode.RECORD_SIZE + 8; // size 4 private static final int LOCAL_TO_FILE = PDOMNamedNode.RECORD_SIZE + 12; // size 4 - + @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 16; private byte hasDeclaration= -1; - + protected PDOMBinding(PDOMLinkage linkage, PDOMNode parent, char[] name) throws CoreException { super(linkage, parent, name); } - + public PDOMBinding(PDOMLinkage linkage, long record) { super(linkage, record); } - + @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object getAdapter(Class adapter) { if (adapter.isAssignableFrom(PDOMBinding.class)) return this; - // Any PDOMBinding can have a persistent tag. These tags should be deleted when the PDOMBinding - // is deleted. However, PDOMBinding's don't get deleted, so there is no way to trigger deleting - // of the tags. If the implementation is changed so that PDOMBindings do get deleted, then call: - // PDOMTagIndex.setTags( getPDOM(), pdomBinding.record, Collections.emptyList() ); + // Any PDOMBinding can have a persistent tag. These tags should be deleted when + // the PDOMBinding is deleted. However, PDOMBinding's don't get deleted, so there is no way + // to trigger deleting of the tags. If the implementation is changed so that PDOMBindings + // do get deleted, then it should call: + // PDOMTagIndex.setTags(getPDOM(), pdomBinding.record, Collections.emptyList()); // to clear out all tags for the binding. - if (adapter == ITagReader.class) - return new PDOMTaggable( getPDOM(), getRecord() ); + if (adapter.isAssignableFrom(ITagReader.class)) + return new PDOMTaggable(getPDOM(), getRecord()); return null; } - + /** * Is the binding as the record orphaned, i.e., has no declarations * or references. * Watch out, a binding may also be used in a type (e.g. pointer to class) - * + * * @param pdom * @param record * @return true if the binding is orphaned. @@ -96,7 +97,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding && db.getRecPtr(record + FIRST_DEF_OFFSET) == 0 && db.getRecPtr(record + FIRST_REF_OFFSET) == 0; } - + @Override public final boolean hasDeclaration() throws CoreException { if (hasDeclaration == -1) { @@ -111,7 +112,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } return hasDeclaration != 0; } - + public final void addDeclaration(PDOMName name) throws CoreException { PDOMName first = getFirstDeclaration(); if (first != null) { @@ -120,7 +121,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } setFirstDeclaration(name); } - + public final void addDefinition(PDOMName name) throws CoreException { PDOMName first = getFirstDefinition(); if (first != null) { @@ -129,7 +130,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } setFirstDefinition(name); } - + public final void addReference(PDOMName name) throws CoreException { PDOMName first = getFirstReference(); if (first != null) { @@ -138,37 +139,37 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } setFirstReference(name); } - + public PDOMName getFirstDeclaration() throws CoreException { long namerec = getDB().getRecPtr(record + FIRST_DECL_OFFSET); return namerec != 0 ? new PDOMName(getLinkage(), namerec) : null; } - + public void setFirstDeclaration(PDOMName name) throws CoreException { long namerec = name != null ? name.getRecord() : 0; getDB().putRecPtr(record + FIRST_DECL_OFFSET, namerec); } - + public PDOMName getFirstDefinition() throws CoreException { long namerec = getDB().getRecPtr(record + FIRST_DEF_OFFSET); return namerec != 0 ? new PDOMName(getLinkage(), namerec) : null; } - + public void setFirstDefinition(PDOMName name) throws CoreException { long namerec = name != null ? name.getRecord() : 0; getDB().putRecPtr(record + FIRST_DEF_OFFSET, namerec); } - + public PDOMName getFirstReference() throws CoreException { long namerec = getDB().getRecPtr(record + FIRST_REF_OFFSET); return namerec != 0 ? new PDOMName(getLinkage(), namerec) : null; } - + public void setFirstReference(PDOMName name) throws CoreException { long namerec = name != null ? name.getRecord() : 0; getDB().putRecPtr(record + FIRST_REF_OFFSET, namerec); } - + @Override public final PDOMFile getLocalToFile() throws CoreException { final long filerec = getLocalToFileRec(getDB(), record); @@ -206,7 +207,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } return CharArrayUtils.EMPTY; } - + public IIndexScope getParent() { try { IBinding parent = getParentBinding(); @@ -218,12 +219,12 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } return null; } - + @Override public final IIndexScope getScope() { - // The parent node in the binding hierarchy is the scope. + // The parent node in the binding hierarchy is the scope. try { - IBinding parent= getParentBinding(); + IBinding parent= getParentBinding(); while (parent != null) { if (parent instanceof ICPPClassType) { return (IIndexScope) ((ICPPClassType) parent).getCompositeScope(); @@ -233,7 +234,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding final ICPPEnumeration enumeration = (ICPPEnumeration) parent; if (enumeration.isScoped()) { return (IIndexScope) enumeration.asScope(); - } + } parent= ((PDOMNamedNode) parent).getParentBinding(); } else if (parent instanceof IIndexScope) { return (IIndexScope) parent; @@ -247,7 +248,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } return null; } - + @Override public IIndexFragment getFragment() { return getPDOM(); @@ -255,7 +256,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding @Override abstract protected int getRecordSize(); // superclass's implementation is no longer valid - + /* For debug purposes only. * @see java.lang.Object#toString() */ @@ -276,15 +277,15 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } else { return getName() + "()"; //$NON-NLS-1$ } - } + } return getName(); } - + /** * For debug purposes only. * @param linkage * @param value - * @return String representation of value. + * @return String representation of value. */ protected static String getConstantNameForValue(PDOMLinkage linkage, int value) { Class c= linkage.getClass(); @@ -307,7 +308,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } return Integer.toString(value); } - + public PDOMName getScopeName() { try { PDOMName name = getFirstDefinition(); @@ -324,7 +325,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding public String[] getQualifiedName() { return new String[] { getName() }; } - + @Override final public boolean isFileLocal() throws CoreException { return getDB().getRecPtr(record + LOCAL_TO_FILE) != 0; @@ -337,11 +338,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding /** * Compares two binding fully qualified names. If b0 has - * less segments than b1 then -1 is returned, if b0 has + * less segments than b1 then -1 is returned, if b0 has * more segments than b1 then 1 is returned. If the segment * lengths are equal then comparison is lexicographical on each * component name, beginning with the most nested name and working - * outward. + * outward. * If one of the bindings in the hierarchy is file-local it is treated as a different * binding. * The first non-zero comparison is returned as the result. @@ -355,7 +356,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding */ private static int comparePDOMBindingQNs(PDOMBinding b0, PDOMBinding b1) { try { - int cmp = 0; + int cmp = 0; do { IString s0 = b0.getDBName(), s1 = b1.getDBName(); cmp = s0.compare(s1, true); @@ -380,7 +381,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } /** - * Compares two PDOMBinding objects in accordance with + * Compares two PDOMBinding objects in accordance with * {@link IIndexFragmentBindingComparator#compare(IIndexFragmentBinding, IIndexFragmentBinding)} * @param other * @return comparison result, -1, 0, or 1. @@ -394,14 +395,14 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding } return cmp; } - + /** * Returns whether pdomCompareTo returns zero */ public final boolean pdomEquals(PDOMBinding other) { return pdomCompareTo(other)==0; } - + @Override public final int getBindingConstant() { return getNodeType(); @@ -409,11 +410,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding /** * The binding is reused by a declaration or definition, we may need to update modifiers. - * @throws CoreException + * @throws CoreException */ public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException { } - + @Override final public void delete(PDOMLinkage linkage) throws CoreException { assert false; @@ -427,7 +428,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding public int getAdditionalNameFlags(int standardFlags, IASTName name) { return 0; } - + public final IBinding getBinding(IASTName name, boolean resolve) { return getBinding(name, resolve, null); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index 77608c1b493..e2982667677 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -99,9 +99,9 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { getPDOM().putCachedResult(inputBinding, pdomBinding); } - // Synchronize the tags associated with the persistent binding to match the set that is - // associated with the input binding. - TagManager.getInstance().syncTags( pdomBinding, inputBinding ); + // Synchronize the tags associated with the persistent binding to match the set that + // is associated with the input binding. + TagManager.getInstance().syncTags(pdomBinding, inputBinding); return pdomBinding; } @@ -114,9 +114,10 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { pdomBinding.update(this, fromBinding); - // Update the tags based on the tags from the new binding. This was in PDOMBinding.update, but - // I found that not all subclasses (e.g., PDOMCPPFunction) call the parent implementation. - TagManager.getInstance().syncTags( pdomBinding, fromBinding ); + // Update the tags based on the tags from the new binding. This cannot be done in + // PDOMBinding.update, because not all subclasses (e.g., PDOMCFunction) call + // the superclass implementation. + TagManager.getInstance().syncTags(pdomBinding, fromBinding); } return pdomBinding; } @@ -344,23 +345,23 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { @Override public IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= buffer.getByte(); - switch((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + short firstBytes= buffer.getShort(); + switch((firstBytes & ITypeMarshalBuffer.KIND_MASK)) { case ITypeMarshalBuffer.ARRAY_TYPE: - return CArrayType.unmarshal(firstByte, buffer); + return CArrayType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.BASIC_TYPE: - return CBasicType.unmarshal(firstByte, buffer); + return CBasicType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.CVQUALIFIER_TYPE: - return CQualifierType.unmarshal(firstByte, buffer); + return CQualifierType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.FUNCTION_TYPE: - return CFunctionType.unmarshal(firstByte, buffer); + return CFunctionType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.POINTER_TYPE: - return CPointerType.unmarshal(firstByte, buffer); + return CPointerType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.PROBLEM_TYPE: - return ProblemType.unmarshal(firstByte, buffer); + return ProblemType.unmarshal(firstBytes, buffer); } - throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$ + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first bytes=" + firstBytes)); //$NON-NLS-1$ } @Override 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 3d85ab48e7f..0f1c7b116a1 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 @@ -111,6 +111,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionSet; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalID; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalInitList; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalMemberAccess; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalParameterPack; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUnary; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUnaryTypeID; @@ -122,6 +123,7 @@ import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; +import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; @@ -360,9 +362,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { addImplicitMethods(pdomBinding, (ICPPClassType) binding, fromName); } - // Synchronize the tags associated with the persistent binding to match the set that is - // associated with the input binding. - TagManager.getInstance().syncTags( pdomBinding, inputBinding ); + // Synchronize the tags associated with the persistent binding to match + // the set that is associated with the input binding. + TagManager.getInstance().syncTags(pdomBinding, inputBinding); } } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); @@ -376,9 +378,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { pdomBinding.update(this, fromBinding); - // Update the tags based on the tags from the new binding. This was in PDOMBinding.update, but - // I found that not all subclasses (e.g., PDOMCPPFunction) call the parent implementation. - TagManager.getInstance().syncTags( pdomBinding, fromBinding ); + // Update the tags based on the tags from the new binding. This cannot be done in + // PDOMBinding.update, because not all subclasses (e.g., PDOMCPPFunction) call + // the superclass implementation. + TagManager.getInstance().syncTags(pdomBinding, fromBinding); } return pdomBinding; @@ -1105,94 +1108,98 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { @Override public IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= buffer.getByte(); - switch ((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + short firstBytes= buffer.getShort(); + switch ((firstBytes & ITypeMarshalBuffer.KIND_MASK)) { case ITypeMarshalBuffer.ARRAY_TYPE: - return CPPArrayType.unmarshal(firstByte, buffer); + return CPPArrayType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.BASIC_TYPE: - return CPPBasicType.unmarshal(firstByte, buffer); + return CPPBasicType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.CVQUALIFIER_TYPE: - return CPPQualifierType.unmarshal(firstByte, buffer); + return CPPQualifierType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.FUNCTION_TYPE: - return CPPFunctionType.unmarshal(firstByte, buffer); + return CPPFunctionType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.POINTER_TYPE: - return CPPPointerType.unmarshal(firstByte, buffer); + return CPPPointerType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.PROBLEM_TYPE: - return ProblemType.unmarshal(firstByte, buffer); + return ProblemType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.REFERENCE_TYPE: - return CPPReferenceType.unmarshal(firstByte, buffer); + return CPPReferenceType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.PACK_EXPANSION_TYPE: - return CPPParameterPackType.unmarshal(firstByte, buffer); + return CPPParameterPackType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.POINTER_TO_MEMBER_TYPE: - return CPPPointerToMemberType.unmarshal(firstByte, buffer); + return CPPPointerToMemberType.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE: - return TypeOfDependentExpression.unmarshal(firstByte, buffer); + return TypeOfDependentExpression.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.UNKNOWN_MEMBER: - IBinding binding= CPPUnknownMember.unmarshal(getPDOM(), firstByte, buffer); + IBinding binding= CPPUnknownMember.unmarshal(getPDOM(), firstBytes, buffer); if (binding instanceof IType) return (IType) binding; break; case ITypeMarshalBuffer.UNKNOWN_MEMBER_CLASS_INSTANCE: - return CPPUnknownClassInstance.unmarshal(getPDOM(), firstByte, buffer); + return CPPUnknownClassInstance.unmarshal(getPDOM(), firstBytes, buffer); case ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE: - return CPPDeferredClassInstance.unmarshal(getPDOM(), firstByte, buffer); + return CPPDeferredClassInstance.unmarshal(getPDOM(), firstBytes, buffer); case ITypeMarshalBuffer.ALIAS_TEMPLATE: - return CPPAliasTemplateInstance.unmarshal(firstByte, buffer); + return CPPAliasTemplateInstance.unmarshal(firstBytes, buffer); } - throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$ + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first bytes=" + firstBytes)); //$NON-NLS-1$ } @Override public IBinding unmarshalBinding(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= buffer.getByte(); - switch ((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + short firstBytes= buffer.getShort(); + switch ((firstBytes & ITypeMarshalBuffer.KIND_MASK)) { case ITypeMarshalBuffer.UNKNOWN_MEMBER: - return CPPUnknownMember.unmarshal(getPDOM(), firstByte, buffer); + return CPPUnknownMember.unmarshal(getPDOM(), firstBytes, buffer); case ITypeMarshalBuffer.UNKNOWN_MEMBER_CLASS_INSTANCE: - return CPPUnknownClassInstance.unmarshal(getPDOM(), firstByte, buffer); + return CPPUnknownClassInstance.unmarshal(getPDOM(), firstBytes, buffer); case ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE: - return CPPDeferredClassInstance.unmarshal(getPDOM(), firstByte, buffer); + return CPPDeferredClassInstance.unmarshal(getPDOM(), firstBytes, buffer); } - throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$ + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first bytes=" + firstBytes)); //$NON-NLS-1$ } @Override public ISerializableEvaluation unmarshalEvaluation(ITypeMarshalBuffer buffer) throws CoreException { - int firstByte= buffer.getByte(); - switch ((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + short firstBytes= buffer.getShort(); + if (firstBytes == TypeMarshalBuffer.NULL_TYPE) + return null; + switch ((firstBytes & ITypeMarshalBuffer.KIND_MASK)) { case ITypeMarshalBuffer.EVAL_BINARY: - return EvalBinary.unmarshal(firstByte, buffer); + return EvalBinary.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_BINARY_TYPE_ID: - return EvalBinaryTypeId.unmarshal(firstByte, buffer); + return EvalBinaryTypeId.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_BINDING: - return EvalBinding.unmarshal(firstByte, buffer); + return EvalBinding.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_COMMA: - return EvalComma.unmarshal(firstByte, buffer); + return EvalComma.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_COMPOUND: - return EvalCompound.unmarshal(firstByte, buffer); + return EvalCompound.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_CONDITIONAL: - return EvalConditional.unmarshal(firstByte, buffer); + return EvalConditional.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_FIXED: - return EvalFixed.unmarshal(firstByte, buffer); + return EvalFixed.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_FUNCTION_CALL: - return EvalFunctionCall.unmarshal(firstByte, buffer); + return EvalFunctionCall.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_FUNCTION_SET: - return EvalFunctionSet.unmarshal(firstByte, buffer); + return EvalFunctionSet.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_ID: - return EvalID.unmarshal(firstByte, buffer); + return EvalID.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_INIT_LIST: - return EvalInitList.unmarshal(firstByte, buffer); + return EvalInitList.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_MEMBER_ACCESS: - return EvalMemberAccess.unmarshal(firstByte, buffer); + return EvalMemberAccess.unmarshal(firstBytes, buffer); + case ITypeMarshalBuffer.EVAL_PARAMETER_PACK: + return EvalParameterPack.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_TYPE_ID: - return EvalTypeId.unmarshal(firstByte, buffer); + return EvalTypeId.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_UNARY: - return EvalUnary.unmarshal(firstByte, buffer); + return EvalUnary.unmarshal(firstBytes, buffer); case ITypeMarshalBuffer.EVAL_UNARY_TYPE_ID: - return EvalUnaryTypeID.unmarshal(firstByte, buffer); + return EvalUnaryTypeID.unmarshal(firstBytes, buffer); } - throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal an evaluation, first byte=" + firstByte)); //$NON-NLS-1$ + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal an evaluation, first bytes=" + firstBytes)); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/BTreeIterable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/BTreeIterable.java index 1ea29d1fff7..c5774014f73 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/BTreeIterable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/BTreeIterable.java @@ -4,8 +4,10 @@ * 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 Eidsness - Initial implementation */ - package org.eclipse.cdt.internal.core.pdom.tag; import java.util.Collections; @@ -18,61 +20,67 @@ import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.core.runtime.CoreException; -public class BTreeIterable implements Iterable -{ - public static interface Descriptor - { - public int compare( long record ) throws CoreException; - public T create( long record ); +public class BTreeIterable implements Iterable { + public static interface Descriptor { + public int compare(long record) throws CoreException; + + public T create(long record); } private final BTree btree; private final Descriptor descriptor; - public BTreeIterable( BTree btree, Descriptor descriptor ) - { + public BTreeIterable(BTree btree, Descriptor descriptor) { this.btree = btree; this.descriptor = descriptor; } @Override - public Iterator iterator() - { + public Iterator iterator() { Visitor v = new Visitor(); - try { btree.accept( v ); } - catch( CoreException e ) { CCorePlugin.log( e ); return Collections.emptyList().iterator(); } - return new BTreeIterator( v.records ); + try { + btree.accept(v); + } catch (CoreException e) { + CCorePlugin.log(e); + return Collections. emptyList().iterator(); + } + return new BTreeIterator(v.records); } - private class Visitor implements IBTreeVisitor - { + private class Visitor implements IBTreeVisitor { public final List records = new LinkedList(); @Override - public int compare( long record ) throws CoreException - { - return BTreeIterable.this.descriptor.compare( record ); + public int compare(long record) throws CoreException { + return BTreeIterable.this.descriptor.compare(record); } @Override - public boolean visit( long record ) throws CoreException - { - records.add( Long.valueOf( record ) ); + public boolean visit(long record) throws CoreException { + records.add(Long.valueOf(record)); return true; } } - private class BTreeIterator implements Iterator - { + private class BTreeIterator implements Iterator { private final Iterator records; - public BTreeIterator( Iterable records ) - { + public BTreeIterator(Iterable records) { this.records = records.iterator(); } - @Override public void remove() { } - @Override public boolean hasNext() { return records.hasNext(); } - @Override public T next() { return BTreeIterable.this.descriptor.create( records.next() ); } + @Override + public void remove() { + } + + @Override + public boolean hasNext() { + return records.hasNext(); + } + + @Override + public T next() { + return BTreeIterable.this.descriptor.create(records.next()); + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTag.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTag.java index ed7bfe63347..c332fcc5b83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTag.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTag.java @@ -4,6 +4,9 @@ * 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 Eidsness - Initial implementation */ package org.eclipse.cdt.internal.core.pdom.tag; @@ -15,185 +18,192 @@ import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.core.runtime.CoreException; -public class PDOMTag implements IWritableTag -{ +/** + * A container for storing tags in the PDOM. The storage format is as follows: + * + *

+ * PDOMTag
+ * {
+ *     u4 node_record; # pointer to the node that is being tagged
+ *     u4 tagger_id;   # pointer to the string that identifies the tagger that
+ *                     # created this tag
+ *     u4 data_len;    # number of bytes stored in this tag's payload
+ *     u1[];           # a buffer for storing the tag's payload
+ * };
+ * 
+ * + * Each tag points to the contributing tagger id, the record that is being tagged. Finally, it stores a buffer + * for the tag's payload. The buffer is read and written by the contributor of the tag. + */ +public class PDOMTag implements IWritableTag { private final Database db; private final long record; private String taggerId; private int dataLen = -1; - private static enum Fields - { - Node, - TaggerId, - DataLen, - Data; + private static enum Fields { + Node, TaggerId, DataLen, Data; public final long offset = ordinal() * Database.PTR_SIZE; - public static int sizeof( int datalen ) { return (int)Data.offset + datalen; } - public long getRecPtr( Database db, long instance, long data_offset ) throws CoreException - { - return db.getRecPtr( instance + offset + data_offset ); + public static int sizeof(int datalen) { + return (int) Data.offset + datalen; } - public void putRecPtr( Database db, long instance, long data_offset, long value ) throws CoreException - { - db.putRecPtr( instance + offset + data_offset, value ); + public long getRecPtr(Database db, long instance, long data_offset) throws CoreException { + return db.getRecPtr(instance + offset + data_offset); } - public void put( Database db, long instance, long data_offset, byte value ) throws CoreException - { - db.putByte( instance + offset + data_offset, value ); + public void putRecPtr(Database db, long instance, long data_offset, long value) + throws CoreException { + db.putRecPtr(instance + offset + data_offset, value); } - public void put( Database db, long instance, byte[] data, long data_offset, int len ) throws CoreException - { - db.putBytes( instance + offset + data_offset, data, len ); + public void put(Database db, long instance, long data_offset, byte value) + throws CoreException { + db.putByte(instance + offset + data_offset, value); } - public byte getByte( Database db, long instance, long data_offset ) throws CoreException - { - return db.getByte( instance + offset + data_offset ); + public void put(Database db, long instance, byte[] data, long data_offset, int len) + throws CoreException { + db.putBytes(instance + offset + data_offset, data, len); } - public byte[] getBytes( Database db, long instance, long data_offset, int len ) throws CoreException - { + public byte getByte(Database db, long instance, long data_offset) throws CoreException { + return db.getByte(instance + offset + data_offset); + } + + public byte[] getBytes(Database db, long instance, long data_offset, int len) + throws CoreException { byte[] data = new byte[len]; - db.getBytes( instance + offset + data_offset, data ); + db.getBytes(instance + offset + data_offset, data); return data; } - public void put( Database db, long instance, long data_offset, int value ) throws CoreException - { - db.putInt( instance + offset + data_offset, value ); + public void put(Database db, long instance, long data_offset, int value) + throws CoreException { + db.putInt(instance + offset + data_offset, value); } - public int getInt( Database db, long instance, long data_offset ) throws CoreException - { - return db.getInt( instance + offset + data_offset ); + public int getInt(Database db, long instance, long data_offset) throws CoreException { + return db.getInt(instance + offset + data_offset); } } - public PDOMTag( Database db, long record ) - { + public PDOMTag(Database db, long record) { this.db = db; this.record = record; } - public PDOMTag( Database db, int dataLen ) throws CoreException - { + public PDOMTag(Database db, int dataLen) throws CoreException { this.db = db; - this.record = db.malloc( Fields.sizeof( dataLen ) ); + this.record = db.malloc(Fields.sizeof(dataLen)); this.dataLen = dataLen; - Fields.DataLen.put( db, record, 0, dataLen ); + Fields.DataLen.put(db, record, 0, dataLen); } - public long getNode() throws CoreException - { - return Fields.Node.getRecPtr( db, record, 0 ); + public long getNode() throws CoreException { + return Fields.Node.getRecPtr(db, record, 0); } @Override - public String getTaggerId() - { - if( taggerId == null ) - try - { - long taggerIdRecord = Fields.TaggerId.getRecPtr( db, record, 0 ); - taggerId = taggerIdRecord == 0L ? new String() : db.getString( taggerIdRecord ).getString(); - } - catch( CoreException e ) - { - CCorePlugin.log( e ); + public String getTaggerId() { + if (taggerId == null) + try { + long taggerIdRecord = Fields.TaggerId.getRecPtr(db, record, 0); + taggerId = taggerIdRecord == 0L ? new String() : db.getString(taggerIdRecord) + .getString(); + } catch (CoreException e) { + CCorePlugin.log(e); } return taggerId; } @Override - public int getDataLen() - { - if( dataLen < 0 ) - try { dataLen = Fields.DataLen.getInt( db, record, 0 ); } - catch( CoreException e ) { CCorePlugin.log( e ); return 0; } + public int getDataLen() { + if (dataLen < 0) + try { + dataLen = Fields.DataLen.getInt(db, record, 0); + } catch (CoreException e) { + CCorePlugin.log(e); + return 0; + } return dataLen; } - public long getRecord() { return record; } + public long getRecord() { + return record; + } /** - * Create and return a new PDOMTag that has the same node/taggerId as the receiver but with the - * specified data. Return null on failure. + * Create and return a new PDOMTag that has the same node/taggerId as the receiver but with the specified + * data. Return null on failure. */ - public PDOMTag cloneWith( byte[] data ) throws CoreException - { + public PDOMTag cloneWith(byte[] data) throws CoreException { PDOMTag partialTag = null; - try - { - long existing_node = Fields.Node.getRecPtr( db, record, 0 ); - long existing_id = Fields.TaggerId.getRecPtr( db, record, 0 ); + try { + long existing_node = Fields.Node.getRecPtr(db, record, 0); + long existing_id = Fields.TaggerId.getRecPtr(db, record, 0); - partialTag = new PDOMTag( db, data.length ); - Fields.Node.putRecPtr( db, partialTag.record, 0, existing_node ); - Fields.TaggerId.putRecPtr( db, partialTag.record, 0, existing_id ); - if( partialTag.putBytes( 0, data, data.length ) ) - { + partialTag = new PDOMTag(db, data.length); + Fields.Node.putRecPtr(db, partialTag.record, 0, existing_node); + Fields.TaggerId.putRecPtr(db, partialTag.record, 0, existing_id); + if (partialTag.putBytes(0, data, data.length)) { PDOMTag tag = partialTag; partialTag = null; return tag; } - } - finally - { - if( partialTag != null ) + } finally { + if (partialTag != null) partialTag.delete(); } return null; } - public void delete() - { - if( db != null - && record != 0 ) - try { db.free( record ); } - catch( CoreException e ) { CCorePlugin.log( e ); } + public void delete() { + if (db != null && record != 0) + try { + db.free(record); + } catch (CoreException e) { + CCorePlugin.log(e); + } } - public static class BTreeComparator implements IBTreeComparator - { + public static class BTreeComparator implements IBTreeComparator { private final Database db; - public BTreeComparator( Database db ) { this.db = db; } + + public BTreeComparator(Database db) { + this.db = db; + } @Override - public int compare(long record1, long record2) throws CoreException - { - if( record1 == record2 ) + public int compare(long record1, long record2) throws CoreException { + if (record1 == record2) return 0; - long node1 = Fields.Node.getRecPtr( db, record1, 0 ); - long node2 = Fields.Node.getRecPtr( db, record2, 0 ); - if( node1 < node2 ) + long node1 = Fields.Node.getRecPtr(db, record1, 0); + long node2 = Fields.Node.getRecPtr(db, record2, 0); + if (node1 < node2) return -1; - if( node1 > node2 ) + if (node1 > node2) return 1; - long tagger1 = Fields.TaggerId.getRecPtr( db, record1, 0 ); - long tagger2 = Fields.TaggerId.getRecPtr( db, record2, 0 ); - if( tagger1 < tagger2 ) + long tagger1 = Fields.TaggerId.getRecPtr(db, record1, 0); + long tagger2 = Fields.TaggerId.getRecPtr(db, record2, 0); + if (tagger1 < tagger2) return -1; - if( tagger1 > tagger2 ) + if (tagger1 > tagger2) return 1; return 0; } } - public static class BTreeVisitor implements IBTreeVisitor - { + public static class BTreeVisitor implements IBTreeVisitor { private final Database db; private final long node2; private final long tagger2; @@ -201,8 +211,7 @@ public class PDOMTag implements IWritableTag public boolean hasResult = false; public long tagRecord = 0; - public BTreeVisitor( Database db, long node2, long tagger2 ) - { + public BTreeVisitor(Database db, long node2, long tagger2) { this.db = db; this.node2 = node2; this.tagger2 = tagger2; @@ -210,16 +219,16 @@ public class PDOMTag implements IWritableTag @Override public int compare(long record1) throws CoreException { - long node1 = Fields.Node.getRecPtr( db, record1, 0 ); - if( node1 < node2 ) + long node1 = Fields.Node.getRecPtr(db, record1, 0); + if (node1 < node2) return -1; - if( node1 > node2 ) + if (node1 > node2) return 1; - long tagger1 = Fields.TaggerId.getRecPtr( db, record1, 0 ); - if( tagger1 < tagger2 ) + long tagger1 = Fields.TaggerId.getRecPtr(db, record1, 0); + if (tagger1 < tagger2) return -1; - if( tagger1 > tagger2 ) + if (tagger1 > tagger2) return 1; return 0; @@ -233,80 +242,82 @@ public class PDOMTag implements IWritableTag } } - public void setNode( long node ) throws CoreException - { - Fields.Node.putRecPtr( db, record, 0, node ); + public void setNode(long node) throws CoreException { + Fields.Node.putRecPtr(db, record, 0, node); } - public void setTaggerId( long idRecord ) throws CoreException - { - Fields.TaggerId.putRecPtr( db, record, 0, idRecord ); + public void setTaggerId(long idRecord) throws CoreException { + Fields.TaggerId.putRecPtr(db, record, 0, idRecord); } - private boolean isInBounds( int offset, int len ) - { + private boolean isInBounds(int offset, int len) { int data_len = getDataLen(); - return offset >= 0 - && offset < data_len - && ( offset + len ) <= data_len; + return offset >= 0 && offset < data_len && (offset + len) <= data_len; } @Override - public boolean putByte( int offset, byte data ) - { - if( ! isInBounds( offset, 1 ) ) + public boolean putByte(int offset, byte data) { + if (!isInBounds(offset, 1)) return false; - try { Fields.Data.put( db, record, offset, data ); return true; } - catch( CoreException e ) { CCorePlugin.log( e ); return false; } + try { + Fields.Data.put(db, record, offset, data); + return true; + } catch (CoreException e) { + CCorePlugin.log(e); + return false; + } } @Override - public boolean putBytes( int offset, byte[] data, int len ) - { + public boolean putBytes(int offset, byte[] data, int len) { boolean fullWrite = len < 0; - if( fullWrite ) + if (fullWrite) len = data.length; - if( ! isInBounds( offset, len ) ) + if (!isInBounds(offset, len)) return false; - try - { - Fields.Data.put( db, record, data, offset, len ); + try { + Fields.Data.put(db, record, data, offset, len); // if the new buffer replaces all of the existing one, then modify the receiver's stored length int currLen = getDataLen(); - if( fullWrite - && offset == 0 - && currLen > len ) - { - Fields.DataLen.put( db, record, 0, len ); + if (fullWrite && offset == 0 && currLen > len) { + Fields.DataLen.put(db, record, 0, len); dataLen = len; } return true; + } catch (CoreException e) { + CCorePlugin.log(e); + return false; } - catch( CoreException e ) { CCorePlugin.log( e ); return false; } } @Override - public int getByte( int offset ) - { - if( ! isInBounds( offset, 1 ) ) - return Fail; + public int getByte(int offset) { + if (!isInBounds(offset, 1)) + return FAIL; - try { return Fields.Data.getByte( db, record, offset ); } - catch( CoreException e ) { CCorePlugin.log( e ); return Fail; } + try { + return Fields.Data.getByte(db, record, offset); + } catch (CoreException e) { + CCorePlugin.log(e); + return FAIL; + } } @Override - public byte[] getBytes( int offset, int len ) - { + public byte[] getBytes(int offset, int len) { len = len >= 0 ? len : getDataLen() - offset; - if( ! isInBounds( offset, len ) ) + if (!isInBounds(offset, len)) return null; - try { return Fields.Data.getBytes( db, record, offset, len ); } - catch( CoreException e ) { CCorePlugin.log( e ); return null; } + try { + return Fields.Data.getBytes(db, record, offset, len); + } catch (CoreException e) { + CCorePlugin.log(e); + return null; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagIndex.java index 8cd0c86c9f9..614ba8f34d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagIndex.java @@ -4,6 +4,9 @@ * 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 Eidsness - Initial implementation */ package org.eclipse.cdt.internal.core.pdom.tag; @@ -24,17 +27,13 @@ import org.eclipse.core.runtime.CoreException; /** * Not thread-safe. */ -public class PDOMTagIndex -{ +public class PDOMTagIndex { private final Database db; private final long ptr; private long rootRecord; - private static enum Fields - { - TaggerIds, - Tags, - _last; + private static enum Fields { + TaggerIds, Tags, _last; public final long offset = ordinal() * Database.PTR_SIZE; public static int sizeof = _last.ordinal() * Database.PTR_SIZE; @@ -43,89 +42,75 @@ public class PDOMTagIndex private PDOMStringSet taggerIds; private BTree tags; - public PDOMTagIndex( Database db, long ptr ) throws CoreException - { + public PDOMTagIndex(Database db, long ptr) throws CoreException { this.db = db; this.ptr = ptr; this.rootRecord = 0; } - private long getFieldAddress( Fields field ) throws CoreException - { - if( rootRecord == 0 ) - rootRecord = db.getRecPtr( ptr ); + private long getFieldAddress(Fields field) throws CoreException { + if (rootRecord == 0) + rootRecord = db.getRecPtr(ptr); - if( rootRecord == 0 ) - { - rootRecord = db.malloc( Fields.sizeof ); - db.putRecPtr( ptr, rootRecord ); + if (rootRecord == 0) { + rootRecord = db.malloc(Fields.sizeof); + db.putRecPtr(ptr, rootRecord); } return rootRecord + field.offset; } - private PDOMStringSet getTaggerIds() throws CoreException - { - if( taggerIds == null ) - taggerIds = new PDOMStringSet( db, getFieldAddress( Fields.TaggerIds ) ); + private PDOMStringSet getTaggerIds() throws CoreException { + if (taggerIds == null) + taggerIds = new PDOMStringSet(db, getFieldAddress(Fields.TaggerIds)); return taggerIds; } - private BTree getTagsBTree() throws CoreException - { - if( tags == null ) - tags = new BTree( db, getFieldAddress( Fields.Tags ), new PDOMTag.BTreeComparator( db ) ); + private BTree getTagsBTree() throws CoreException { + if (tags == null) + tags = new BTree(db, getFieldAddress(Fields.Tags), new PDOMTag.BTreeComparator(db)); return tags; } /** - * Return the record storing the specified tagger id. Create a new record if needed. + * Return the record storing the specified tagger id. Create a new record if needed. */ - private long getIdRecord( String taggerId, boolean createIfNeeded ) - { + private long getIdRecord(String taggerId, boolean createIfNeeded) { assert taggerId != null; - assert ! taggerId.isEmpty(); + assert !taggerId.isEmpty(); - if( db == null - || taggerId == null - || taggerId.isEmpty() - || ( taggerIds == null && ! createIfNeeded ) ) + if (db == null || taggerId == null || taggerId.isEmpty() + || (taggerIds == null && !createIfNeeded)) return 0L; - try - { - long record = getTaggerIds().find( taggerId ); - if( record == 0 - && createIfNeeded ) - record = getTaggerIds().add( taggerId ); + try { + long record = getTaggerIds().find(taggerId); + if (record == 0 && createIfNeeded) + record = getTaggerIds().add(taggerId); return record; - } - catch( CoreException e ) - { - CCorePlugin.log( e ); + } catch (CoreException e) { + CCorePlugin.log(e); } return 0L; } - private IWritableTag createTag( long record, String id, int len ) - { - if( db == null ) + private IWritableTag createTag(long record, String id, int len) { + if (db == null) return null; - long idRecord = getIdRecord( id, true ); - if( idRecord == 0L ) + long idRecord = getIdRecord(id, true); + if (idRecord == 0L) return null; - try - { - PDOMTag tag = new PDOMTag( db, len ); - tag.setNode( record ); - tag.setTaggerId( idRecord ); + try { + PDOMTag tag = new PDOMTag(db, len); + tag.setNode(record); + tag.setTaggerId(idRecord); // return the tag if it was properly inserted - long inserted = getTagsBTree().insert( tag.getRecord() ); - if( inserted == tag.getRecord() ) + long inserted = getTagsBTree().insert(tag.getRecord()); + if (inserted == tag.getRecord()) return tag; // TODO check that the existing record has the same length @@ -133,147 +118,152 @@ public class PDOMTagIndex // otherwise destroy this provisional one and return the tag that was actually inserted // TODO figure out what this case means tag.delete(); - return inserted == 0 ? null : new PDOMTag( db, inserted ); - } - catch( CoreException e ) - { - CCorePlugin.log( e ); + return inserted == 0 ? null : new PDOMTag(db, inserted); + } catch (CoreException e) { + CCorePlugin.log(e); } return null; } - private ITag getTag( long record, String id ) - { - if( db == null ) + private ITag getTag(long record, String id) { + if (db == null) return null; - long idRecord = getIdRecord( id, false ); - if( idRecord == 0L ) + long idRecord = getIdRecord(id, false); + if (idRecord == 0L) return null; - PDOMTag.BTreeVisitor v = new PDOMTag.BTreeVisitor( db, record, idRecord ); - try { getTagsBTree().accept( v ); } - catch( CoreException e ) { CCorePlugin.log( e ); } + PDOMTag.BTreeVisitor v = new PDOMTag.BTreeVisitor(db, record, idRecord); + try { + getTagsBTree().accept(v); + } catch (CoreException e) { + CCorePlugin.log(e); + } - return v.hasResult ? new PDOMTag( db, v.tagRecord ) : null; + return v.hasResult ? new PDOMTag(db, v.tagRecord) : null; } - private Iterable getTags( long binding_record ) - { + private Iterable getTags(long binding_record) { BTree btree = null; - try { btree = getTagsBTree(); } - catch( CoreException e ) { CCorePlugin.log( e ); return Collections.emptyList(); } + try { + btree = getTagsBTree(); + } catch (CoreException e) { + CCorePlugin.log(e); + return Collections.emptyList(); + } - final Long bindingRecord = Long.valueOf( binding_record ); - return - new BTreeIterable( - btree, - new BTreeIterable.Descriptor() - { - @Override public ITag create( long record ) { return new PDOMTag( db, record ); } - @Override - public int compare( long test_record ) throws CoreException - { - long test_node = new PDOMTag( db, test_record ).getNode(); + final Long bindingRecord = Long.valueOf(binding_record); + return new BTreeIterable(btree, new BTreeIterable.Descriptor() { + @Override + public ITag create(long record) { + return new PDOMTag(db, record); + } - // -1 if record < key, 0 if record == key, 1 if record > key - return Long.valueOf( test_node ).compareTo( bindingRecord ); - } - } ); + @Override + public int compare(long test_record) throws CoreException { + long test_node = new PDOMTag(db, test_record).getNode(); + + // -1 if record < key, 0 if record == key, 1 if record > key + return Long.valueOf(test_node).compareTo(bindingRecord); + } + }); } - private boolean setTags( long binding_record, Iterable tags ) - { - // There could be several tags for the given record in the database, one for each taggerId. We need - // to delete all of those tags and replace them with given list. The incoming tags are first put - // into a map, indexed by their taggerId. Then we examine the btree of tags to find all tags for this - // record. In each case we decide whether to delete or update the tag. Tags of the same size can be + private boolean setTags(long binding_record, Iterable tags) { + // There could be several tags for the given record in the database, one for each taggerId. We need + // to delete all of those tags and replace them with given list. The incoming tags are first put + // into a map, indexed by their taggerId. Then we examine the btree of tags to find all tags for this + // record. In each case we decide whether to delete or update the tag. Tags of the same size can be // updated in place, otherwise the tag needs to be deleted and recreated. final Map newTags = new HashMap(); - for( ITag tag : tags ) - { - ITag dupTag = newTags.put( tag.getTaggerId(), tag ); - if( dupTag != null ) - CCorePlugin.log( "Duplicate incoming tag for record " + binding_record + " from taggerId " + tag.getTaggerId() ); //$NON-NLS-1$ //$NON-NLS-2$ + for (ITag tag : tags) { + ITag dupTag = newTags.put(tag.getTaggerId(), tag); + if (dupTag != null) + CCorePlugin + .log("Duplicate incoming tag for record " + binding_record + " from taggerId " + tag.getTaggerId()); //$NON-NLS-1$ //$NON-NLS-2$ } BTree btree = null; - try { btree = getTagsBTree(); } - catch( CoreException e ) { CCorePlugin.log( e ); return false; } + try { + btree = getTagsBTree(); + } catch (CoreException e) { + CCorePlugin.log(e); + return false; + } - PDOMTagSynchronizer sync = new PDOMTagSynchronizer( db, Long.valueOf( binding_record ), newTags ); + PDOMTagSynchronizer sync = new PDOMTagSynchronizer(db, Long.valueOf(binding_record), + newTags); // visit the full tree, then return true on success and false on failure - try { btree.accept( sync ); } - catch( CoreException e ) { CCorePlugin.log( e ); return false; } + try { + btree.accept(sync); + } catch (CoreException e) { + CCorePlugin.log(e); + return false; + } - // Complete the synchronization (delete/insert the records that could not be modified in-place). This + // Complete the synchronization (delete/insert the records that could not be modified in-place). This // will only have something to do when a tag has changed length, which should be a rare. - sync.synchronize( btree ); + sync.synchronize(btree); // insert any new tags that are left in the incoming list - for( ITag newTag : newTags.values() ) - { - IWritableTag pdomTag = createTag( binding_record, newTag.getTaggerId(), newTag.getDataLen() ); - pdomTag.putBytes( 0, newTag.getBytes( 0, -1 ), -1 ); + for (ITag newTag : newTags.values()) { + IWritableTag pdomTag = createTag(binding_record, newTag.getTaggerId(), + newTag.getDataLen()); + pdomTag.putBytes(0, newTag.getBytes(0, -1), -1); } return true; } - private static PDOMTagIndex getTagIndex( PDOM pdom ) - { - if( pdom == null ) + private static PDOMTagIndex getTagIndex(PDOM pdom) { + if (pdom == null) return null; - try - { + try { PDOMTagIndex index = pdom.getTagIndex(); return index.db == null ? null : index; + } catch (CoreException e) { + CCorePlugin.log(e); } - catch( CoreException e ) { CCorePlugin.log(e); } return null; } // common implementations - public static IWritableTag createTag( PDOM pdom, long record, String id, int len ) - { - PDOMTagIndex index = getTagIndex( pdom ); - if( index == null ) + public static IWritableTag createTag(PDOM pdom, long record, String id, int len) { + PDOMTagIndex index = getTagIndex(pdom); + if (index == null) return null; - return index.createTag( record, id, len ); + return index.createTag(record, id, len); } - public static ITag getTag( PDOM pdom, long record, String id ) - { - PDOMTagIndex index = getTagIndex( pdom ); - if( index == null ) + public static ITag getTag(PDOM pdom, long record, String id) { + PDOMTagIndex index = getTagIndex(pdom); + if (index == null) return null; - return index.getTag( record, id ); + return index.getTag(record, id); } - public static Iterable getTags( PDOM pdom, long record ) - { - PDOMTagIndex index = getTagIndex( pdom ); - if( index == null ) + public static Iterable getTags(PDOM pdom, long record) { + PDOMTagIndex index = getTagIndex(pdom); + if (index == null) return Collections.emptyList(); - return index.getTags( record ); + return index.getTags(record); } - public static boolean setTags( PDOM pdom, long record, Iterable tags ) - { - if( record == 0 ) + public static boolean setTags(PDOM pdom, long record, Iterable tags) { + if (record == 0) return true; - PDOMTagIndex index = getTagIndex( pdom ); - if( index == null ) + PDOMTagIndex index = getTagIndex(pdom); + if (index == null) return false; - return index.setTags( record, tags ); + return index.setTags(record, tags); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagSynchronizer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagSynchronizer.java index aca9c277272..4043e44d8fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagSynchronizer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTagSynchronizer.java @@ -4,6 +4,9 @@ * 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 Eidsness - Initial implementation */ package org.eclipse.cdt.internal.core.pdom.tag; @@ -19,8 +22,10 @@ import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.core.runtime.CoreException; -public class PDOMTagSynchronizer implements IBTreeVisitor -{ +/** + * An implementation utility for synchronizing the tags between source and destination nodes. + */ +public class PDOMTagSynchronizer implements IBTreeVisitor { private final Database db; private final Long searchRecord; private final Map newTags; @@ -28,39 +33,37 @@ public class PDOMTagSynchronizer implements IBTreeVisitor private final List toRemove = new LinkedList(); private final List toInsert = new LinkedList(); - public PDOMTagSynchronizer( Database db, Long searchRecord, Map newTags ) - { + public PDOMTagSynchronizer(Database db, Long searchRecord, Map newTags) { this.db = db; this.searchRecord = searchRecord; this.newTags = newTags; } /** - * Complete the synchronization by deleting and inserting all required records. Return - * true if successful and false otherwise. + * Complete the synchronization by deleting and inserting all required records. Return true if successful + * and false otherwise. */ - public boolean synchronize( BTree tree ) - { - for( Long rm : toRemove ) - try - { + public boolean synchronize(BTree tree) { + for (Long rm : toRemove) + try { long record = rm.longValue(); - tree.delete( record ); - db.free( record ); - } - catch( CoreException e ) - { - CCorePlugin.log( e ); + tree.delete(record); + db.free(record); + } catch (CoreException e) { + CCorePlugin.log(e); } toRemove.clear(); - for( Long insert : toInsert ) - try { tree.insert( insert.longValue() ); } - catch( CoreException e ) - { - CCorePlugin.log( e ); - try { db.free( insert.longValue() ); } - catch( CoreException e1 ) { CCorePlugin.log( e1 ); } + for (Long insert : toInsert) + try { + tree.insert(insert.longValue()); + } catch (CoreException e) { + CCorePlugin.log(e); + try { + db.free(insert.longValue()); + } catch (CoreException e1) { + CCorePlugin.log(e1); + } } toInsert.clear(); @@ -68,35 +71,32 @@ public class PDOMTagSynchronizer implements IBTreeVisitor } @Override - public int compare( long test_record ) throws CoreException - { + public int compare(long test_record) throws CoreException { // TODO this is the same as BTreeIterable.Descriptor.compare - long test_node = new PDOMTag( db, test_record ).getNode(); + long test_node = new PDOMTag(db, test_record).getNode(); // -1 if record < key, 0 if record == key, 1 if record > key - return Long.valueOf( test_node ).compareTo( searchRecord ); + return Long.valueOf(test_node).compareTo(searchRecord); } @Override - public boolean visit( long existing_record ) throws CoreException - { - PDOMTag existingTag = new PDOMTag( db, existing_record ); + public boolean visit(long existing_record) throws CoreException { + PDOMTag existingTag = new PDOMTag(db, existing_record); String taggerId = existingTag.getTaggerId(); - ITag newTag = newTags.remove( taggerId ); - if( newTag == null ) - toRemove.add( Long.valueOf( existing_record ) ); - else if( newTag.getDataLen() > existingTag.getDataLen() ) - { - toRemove.add( Long.valueOf( existing_record ) ); + ITag newTag = newTags.remove(taggerId); + if (newTag == null) { + toRemove.add(Long.valueOf(existing_record)); + } else if (newTag.getDataLen() > existingTag.getDataLen()) { + toRemove.add(Long.valueOf(existing_record)); - PDOMTag pdomTag = existingTag.cloneWith( newTag.getBytes( 0, -1 ) ); - if( pdomTag != null ) - toInsert.add( Long.valueOf( pdomTag.getRecord() ) ); - } - else if( ! existingTag.putBytes( 0, newTag.getBytes( 0, -1 ), -1 ) ) - CCorePlugin.log( "Unable to modify data of tag record " + existing_record + " from taggerId " + taggerId ); //$NON-NLS-1$ //$NON-NLS-2$ + PDOMTag pdomTag = existingTag.cloneWith(newTag.getBytes(0, -1)); + if (pdomTag != null) + toInsert.add(Long.valueOf(pdomTag.getRecord())); + } else if (!existingTag.putBytes(0, newTag.getBytes(0, -1), -1)) + CCorePlugin + .log("Unable to modify data of tag record " + existing_record + " from taggerId " + taggerId); //$NON-NLS-1$ //$NON-NLS-2$ // try to visit the full tree return true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTaggable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTaggable.java index e7a04c839ed..5714ee6655b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTaggable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/tag/PDOMTaggable.java @@ -4,6 +4,9 @@ * 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 Eidsness - Initial implementation */ package org.eclipse.cdt.internal.core.pdom.tag; @@ -14,38 +17,35 @@ import org.eclipse.cdt.core.dom.ast.tag.ITagWriter; import org.eclipse.cdt.core.dom.ast.tag.IWritableTag; import org.eclipse.cdt.internal.core.pdom.PDOM; -public class PDOMTaggable implements ITagReader, ITagWriter -{ +/** + * A container for things that can be tagged and then stored in the index database. + */ +public class PDOMTaggable implements ITagReader, ITagWriter { private final PDOM pdom; private final long record; - public PDOMTaggable( PDOM pdom, long record ) - { + public PDOMTaggable(PDOM pdom, long record) { this.pdom = pdom; this.record = record; } @Override - public IWritableTag createTag( String id, int len ) - { - return PDOMTagIndex.createTag( pdom, record, id, len ); + public IWritableTag createTag(String id, int len) { + return PDOMTagIndex.createTag(pdom, record, id, len); } @Override - public ITag getTag( String id ) - { - return PDOMTagIndex.getTag( pdom, record, id ); + public ITag getTag(String id) { + return PDOMTagIndex.getTag(pdom, record, id); } @Override - public Iterable getTags() - { - return PDOMTagIndex.getTags( pdom, record ); + public Iterable getTags() { + return PDOMTagIndex.getTags(pdom, record); } @Override - public boolean setTags( Iterable tags ) - { - return PDOMTagIndex.setTags( pdom, record, tags ); + public boolean setTags(Iterable tags) { + return PDOMTagIndex.setTags(pdom, record, tags); } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index b5fc7a7384f..8db644358f2 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -208,7 +208,7 @@ public class CCorePlugin extends Plugin { /** * @noreference This field is not intended to be referenced by clients. */ - public CDTLogWriter cdtLog = null; + public CDTLogWriter cdtLog; private volatile CProjectDescriptionManager fNewCProjectDescriptionManager; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java index 73152183612..ae89d9ef715 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java @@ -283,11 +283,15 @@ public class UserDefinedEnvironmentSupplier extends } public boolean setWorkspaceEnvironment(StorableEnvironment env) { - StorableEnvironment oldEnv = getEnvironment(null); + IEnvironmentVariable[] oldVariables = fWorkspaceVariables.getVariables(); + IEnvironmentVariable[] newVariables = env.getVariables(); - fWorkspaceVariables = new StorableEnvironment(env, false); + fWorkspaceVariables.deleteAll(); + fWorkspaceVariables.setVariales(newVariables); + fWorkspaceVariables.setAppendEnvironment(env.appendEnvironment()); + fWorkspaceVariables.setAppendContributedEnvironment(env.appendContributedEnvironment()); - EnvironmentChangeEvent event = createEnvironmentChangeEvent(fWorkspaceVariables.getVariables(), oldEnv.getVariables()); + EnvironmentChangeEvent event = createEnvironmentChangeEvent(newVariables, oldVariables); storeWorkspaceEnvironment(true); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index c4da1712865..be1b39a2939 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -2467,6 +2467,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int visit(IASTTypeIdExpression node) { + if (enclosedInMacroExpansion(node)) { + return PROCESS_SKIP; + } scribe.printNextToken(peekNextToken()); scribe.printNextToken(Token.tLPAREN); node.getTypeId().accept(this); @@ -2598,6 +2601,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int visit(IASTUnaryExpression node) { + if (enclosedInMacroExpansion(node)) { + return PROCESS_SKIP; + } final IASTExpression operand= node.getOperand(); final int operator= node.getOperator(); switch (operator) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java index 156a062bdfe..78f52af8a9c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2010 QNX Software Systems and others. + * Copyright (c) 2002, 2013 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 @@ -31,22 +31,18 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.corext.util.Strings; -import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -/* - * CViewLabelProvider +/** + * Label provider for "C/C++ Projects" view. */ public class CViewLabelProvider extends AppearanceAwareLabelProvider { - public CViewLabelProvider(long textFlags, int imageFlags) { super(textFlags, imageFlags); } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ @Override public String getText(Object element) { if (element instanceof IncludeReferenceProxy) { @@ -103,22 +99,23 @@ public class CViewLabelProvider extends AppearanceAwareLabelProvider { return Strings.markLTR(new StyledString(getText(element))); } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - */ @Override public Image getImage(Object element) { String imageKey = null; if (element instanceof IncludeReferenceProxy) { IIncludeReference reference = ((IncludeReferenceProxy)element).getReference(); - IContainer containerInclude = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(reference.getPath()); - if (containerInclude != null) { - ICProject cproject = reference.getCProject(); - IProject project = (cproject != null) ? cproject.getProject() : null; + IPath path = reference.getPath(); + ICProject cproject = reference.getCProject(); + IProject project = (cproject != null) ? cproject.getProject() : null; + for (IContainer containerInclude : ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(URIUtil.toURI(path.makeAbsolute()))) { IProject projectInclude = containerInclude.getProject(); boolean isProjectRelative = projectInclude != null && projectInclude.equals(project); imageKey = LanguageSettingsImages.getImageKey(ICSettingEntry.INCLUDE_PATH, ICSettingEntry.VALUE_WORKSPACE_PATH, isProjectRelative); - } else { + if (isProjectRelative) { + break; + } + } + if (imageKey == null) { imageKey = CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER; } } else if (element instanceof IIncludeReference) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java index faa75e6c8ae..7eb84d28c27 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java @@ -38,7 +38,6 @@ import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.AbstractPropertyDialog; import org.eclipse.cdt.internal.ui.ImageCombo; -import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; /** @@ -47,11 +46,11 @@ import org.eclipse.cdt.internal.ui.newui.Messages; public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private static final String SLASH = "/"; //$NON-NLS-1$ - private ICConfigurationDescription cfgDescription; - private IProject project; - private ICLanguageSettingEntry entry; - private boolean clearValue; - private int kind; + private final ICConfigurationDescription cfgDescription; + private final IProject project; + private final ICLanguageSettingEntry initialEntry; + private final int initialKind; + private final boolean clearValue; private Composite compositeArea; private Label iconComboKind; @@ -116,9 +115,9 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { super(parent, ""); //$NON-NLS-1$ this.cfgDescription = cfgDescription; this.project = cfgDescription.getProjectDescription().getProject(); - this.entry = null; + this.initialEntry = null; + this.initialKind = kind; this.clearValue = true; - this.kind = kind; } /** @@ -129,8 +128,8 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { super(parent, ""); //$NON-NLS-1$ this.cfgDescription = cfgDescription; this.project = cfgDescription.getProjectDescription().getProject(); - this.entry = entry; - this.kind = entry != null ? entry.getKind() : ICSettingEntry.INCLUDE_PATH; + this.initialEntry = entry; + this.initialKind = entry != null ? entry.getKind() : ICSettingEntry.INCLUDE_PATH; this.clearValue = clearValue; } @@ -211,7 +210,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { gd.horizontalAlignment = SWT.RIGHT; iconComboKind.setLayoutData(gd); iconComboKind.setText(Messages.LanguageSettingEntryDialog_SelectKind); - int kindToComboIndex = kindToComboIndex(kind); + int kindToComboIndex = kindToComboIndex(initialKind); iconComboKind.setImage(comboKindImages[kindToComboIndex]); // Combo for the setting entry kind @@ -248,14 +247,14 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { comboPathCategory.add(pathCategories[i], pathCategoryImages[i]); } int pcindex = COMBO_PATH_INDEX_PROJECT; - if (entry != null) { - if ((entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == 0) { + if (initialEntry != null) { + if ((initialEntry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == 0) { pcindex = COMBO_PATH_INDEX_FILESYSTEM; } else { - if (entry.getName().startsWith(SLASH)) { - pcindex = COMBO_PATH_INDEX_WORKSPACE; - } else { + if (LanguageSettingsImages.isProjectRelative(initialEntry)) { pcindex = COMBO_PATH_INDEX_PROJECT; + } else { + pcindex = COMBO_PATH_INDEX_WORKSPACE; } } } @@ -286,8 +285,12 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Dir/File/Name input inputName = new Text(compositeArea, SWT.SINGLE | SWT.BORDER); - if (entry!=null && !clearValue) { - inputName.setText(entry.getName()); + if (initialEntry != null && !clearValue) { + String name = initialEntry.getName(); + if (pcindex == COMBO_PATH_INDEX_PROJECT && LanguageSettingsImages.isProjectRelative(initialEntry)) { + name = LanguageSettingsImages.toProjectRelative(name); + } + inputName.setText(name); } gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); gd.horizontalSpan = 2; @@ -334,14 +337,14 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Value input. Located after the other controls to get sufficient width int comboPathWidth = comboPathCategory.computeSize(SWT.DEFAULT, SWT.NONE).x; inputValue = new Text(compositeArea, SWT.SINGLE | SWT.BORDER); - if (entry != null && !clearValue) { - inputValue.setText(entry.getValue()); + if (initialEntry != null && !clearValue) { + inputValue.setText(initialEntry.getValue()); } gd = new GridData(SWT.FILL, SWT.NONE, false, false); gd.widthHint = comboPathWidth; inputValue.setLayoutData(gd); - if (entry != null && kind == ICSettingEntry.MACRO && !clearValue) { + if (initialEntry != null && initialKind == ICSettingEntry.MACRO && !clearValue) { inputValue.setFocus(); inputValue.setSelection(0, inputValue.getText().length()); } @@ -357,7 +360,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Checkbox "Built-In" checkBoxBuiltIn = new Button(compCheckboxes, SWT.CHECK); checkBoxBuiltIn.setText(Messages.LanguageSettingEntryDialog_BuiltInFlag); - checkBoxBuiltIn.setSelection(entry != null && (entry.getFlags() & ICSettingEntry.BUILTIN) != 0); + checkBoxBuiltIn.setSelection(initialEntry != null && (initialEntry.getFlags() & ICSettingEntry.BUILTIN) != 0); gd = new GridData(GridData.FILL_HORIZONTAL); checkBoxBuiltIn.setLayoutData(gd); checkBoxBuiltIn.addSelectionListener(new SelectionListener() { @@ -375,7 +378,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Checkbox "Contains system includes" checkBoxSystem = new Button(compCheckboxes, SWT.CHECK); checkBoxSystem.setText(Messages.LanguageSettingEntryDialog_ContainsSystemHeaders); - checkBoxSystem.setSelection(entry != null && (entry.getFlags() & ICSettingEntry.LOCAL) == 0); + checkBoxSystem.setSelection(initialEntry != null && (initialEntry.getFlags() & ICSettingEntry.LOCAL) == 0); gd = new GridData(GridData.FILL_HORIZONTAL); checkBoxSystem.setLayoutData(gd); checkBoxSystem.addSelectionListener(new SelectionListener() { @@ -393,7 +396,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Checkbox "Framework folder" checkBoxFramework = new Button(compCheckboxes, SWT.CHECK); checkBoxFramework.setText(Messages.LanguageSettingEntryDialog_FrameworkFolder); - checkBoxFramework.setSelection(entry != null && (entry.getFlags() & ICSettingEntry.FRAMEWORKS_MAC) != 0); + checkBoxFramework.setSelection(initialEntry != null && (initialEntry.getFlags() & ICSettingEntry.FRAMEWORKS_MAC) != 0); gd = new GridData(GridData.FILL_HORIZONTAL); checkBoxFramework.setLayoutData(gd); checkBoxFramework.addSelectionListener(new SelectionListener() { @@ -496,7 +499,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { boolean isProjectSelected = (indexPathKind == COMBO_PATH_INDEX_PROJECT); boolean isWorkspaceSelected = (indexPathKind == COMBO_PATH_INDEX_WORKSPACE); boolean isFilesystemSelected = (indexPathKind == COMBO_PATH_INDEX_FILESYSTEM); - + String path = inputName.getText().trim(); if (path.isEmpty()) { buttonOk.setEnabled(false); @@ -504,7 +507,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { buttonOk.setEnabled((isProjectSelected && !path.startsWith(SLASH)) || (isWorkspaceSelected && path.startsWith(SLASH)) || isFilesystemSelected); } - + buttonVars.setEnabled(isFilesystemSelected); } @@ -515,28 +518,38 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { public void buttonPressed(SelectionEvent e) { String str = null; if (e.widget.equals(buttonOk)) { - String name = inputName.getText().trim(); - text1 = name; - String value = inputValue.getText().trim(); + text1 = inputName.getText().trim(); result = true; + String name = text1; int flagBuiltIn = checkBoxBuiltIn.isVisible() && checkBoxBuiltIn.getSelection() ? ICSettingEntry.BUILTIN : 0; - int flagSystem = checkBoxSystem.isVisible() && checkBoxSystem.getSelection() ? 0 : ICSettingEntry.LOCAL; - int flagFramework = checkBoxFramework.isVisible() && checkBoxFramework.getSelection() ? ICSettingEntry.FRAMEWORKS_MAC : 0; - int indexPathKind = comboPathCategory.getSelectionIndex(); + int flags = flagBuiltIn; + int kind = comboKind.getSelectionIndex(); - boolean isProjectPath = indexPathKind == COMBO_PATH_INDEX_PROJECT; - boolean isWorkspacePath = (kind != COMBO_INDEX_MACRO) && (isProjectPath || indexPathKind == COMBO_PATH_INDEX_WORKSPACE); - int flagWorkspace = isWorkspacePath ? ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED : 0; - int flags = flagBuiltIn | flagWorkspace | flagSystem | flagFramework; + if (kind != COMBO_INDEX_MACRO) { + int flagSystem = checkBoxSystem.isVisible() && checkBoxSystem.getSelection() ? 0 : ICSettingEntry.LOCAL; + int flagFramework = checkBoxFramework.isVisible() && checkBoxFramework.getSelection() ? ICSettingEntry.FRAMEWORKS_MAC : 0; + + int indexPathKind = comboPathCategory.getSelectionIndex(); + boolean isProjectPath = indexPathKind == COMBO_PATH_INDEX_PROJECT; + boolean isWorkspacePath = indexPathKind == COMBO_PATH_INDEX_WORKSPACE; + int flagWorkspace = (isWorkspacePath || isProjectPath) ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; + int flagResolved = isWorkspacePath && !name.contains("$") ? ICSettingEntry.RESOLVED : 0; //$NON-NLS-1$ + flags = flagBuiltIn | flagWorkspace | flagResolved | flagSystem | flagFramework; + + if (isProjectPath) { + name = LanguageSettingsImages.fromProjectRelative(name); + } + } ICLanguageSettingEntry entry = null; - switch (kind) { + switch (comboKind.getSelectionIndex()) { case COMBO_INDEX_INCLUDE_DIR: entry = CDataUtil.createCIncludePathEntry(name, flags); break; case COMBO_INDEX_MACRO: // Note that value=null is not supported by CMacroEntry + String value = inputValue.getText().trim(); entry = CDataUtil.createCMacroEntry(name, value, flags); break; case COMBO_INDEX_INCLUDE_FILE: diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index dd41893d473..c01dcdcd081 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Andrew Gvozdev and others. + * Copyright (c) 2010, 2013 Andrew Gvozdev 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 @@ -58,7 +58,6 @@ import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; -import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; @@ -156,11 +155,15 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { public String getText(Object element) { if (element instanceof ICLanguageSettingEntry) { ICLanguageSettingEntry entry = (ICLanguageSettingEntry) element; - String s = entry.getName(); - if ((entry.getKind() == ICSettingEntry.MACRO) && (entry.getFlags()&ICSettingEntry.UNDEFINED) == 0) { - s = s + '=' + entry.getValue(); + String text = entry.getName(); + if (entry.getKind() == ICSettingEntry.MACRO) { + if ((entry.getFlags() & ICSettingEntry.UNDEFINED) == 0) { + text = text + '=' + entry.getValue(); + } + } else if (LanguageSettingsImages.isProjectRelative(entry)) { + text = LanguageSettingsImages.toProjectRelative(text); } - return s; + return text; } return super.getText(element); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsImages.java similarity index 69% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsImages.java index 92044bf3e66..feb38597b99 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsImages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Andrew Gvozdev and others. + * Copyright (c) 2010, 2013 Andrew Gvozdev 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 @@ -8,10 +8,8 @@ * Contributors: * Andrew Gvozdev - Initial API and implementation *******************************************************************************/ +package org.eclipse.cdt.internal.ui.language.settings.providers; -package org.eclipse.cdt.internal.ui.newui; - -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; @@ -24,17 +22,66 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.cdt.core.settings.model.ACPathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.utils.UNCPathConverter; +import org.eclipse.cdt.internal.ui.newui.Messages; + /** * Helper class to provide unified images for {@link ICLanguageSettingEntry}. */ public class LanguageSettingsImages { + private static final String PROJ_NAME_PREFIX = "/${ProjName}/"; //$NON-NLS-1$ + + /** + * Check if the language settings entry should be presented as "project-relative" in UI. + * + * @param entry - language settings entry to check. + * @return {@code true} if the entry should be displayed as "project-relative", {@code false} otherwise. + */ + public static boolean isProjectRelative(ICLanguageSettingEntry entry) { + if (entry instanceof ACPathEntry) { + String path = entry.getName(); + return ((ACPathEntry) entry).isValueWorkspacePath() && path.startsWith(PROJ_NAME_PREFIX); + } + return false; + } + + /** + * Convert path used by {@link ICLanguageSettingEntry} to label representing project-relative portion. + * + * @param path - path to convert to label in project-relative format. + * @return label to be used to display the path in UI. + */ + public static String toProjectRelative(String path) { + if (path.startsWith(LanguageSettingsImages.PROJ_NAME_PREFIX)) { + return path.substring(LanguageSettingsImages.PROJ_NAME_PREFIX.length()); + } + return path; + } + + /** + * Convert label for project-relative path back to path representation carried by {@link ICLanguageSettingEntry}. + * + * @param label - label in project-relative format. + * @return path to be used by {@link ICLanguageSettingEntry}. + */ + public static String fromProjectRelative(String label) { + return LanguageSettingsImages.PROJ_NAME_PREFIX + label; + } + + /** + * Returns image for the given {@link ICLanguageSettingEntry} from internally managed repository including + * necessary overlays for given configuration description. + * + * @param kind - kind of {@link ICLanguageSettingEntry}, i.e. {@link ICSettingEntry#INCLUDE_PATH} etc. + * @param flags - flags of {@link ICSettingEntry}. + * @param isProjectRelative specifies if the image should present "project-relative" icon. + * @return the image for the entry with appropriate overlays. + */ public static Image getImage(int kind, int flags, boolean isProjectRelative) { String imageKey = getImageKey(kind, flags, isProjectRelative); if (imageKey != null) { @@ -52,19 +99,35 @@ public class LanguageSettingsImages { * @return the image for the entry with appropriate overlays. */ public static Image getImage(ICLanguageSettingEntry entry, ICConfigurationDescription cfgDescription) { - String projectName = null; + int kind = entry.getKind(); + int flags = entry.getFlags(); + boolean isProjectRelative = isProjectRelative(entry); - if (cfgDescription != null) { - ICProjectDescription prjDescription = cfgDescription.getProjectDescription(); - if (prjDescription != null) { - IProject project = prjDescription.getProject(); - if (project != null) { - projectName = project.getName(); - } + String imageKey = getImageKey(kind, flags, isProjectRelative); + if (imageKey != null) { + if ((flags & ICSettingEntry.UNDEFINED) != 0) { + return CDTSharedImages.getImageOverlaid(imageKey, CDTSharedImages.IMG_OVR_INACTIVE, IDecoration.BOTTOM_LEFT); } - } - return getImage(entry, projectName, cfgDescription); + String overlayKey=null; + IStatus status = getStatus(entry, cfgDescription); + switch (status.getSeverity()) { + case IStatus.ERROR: + overlayKey = CDTSharedImages.IMG_OVR_ERROR; + break; + case IStatus.WARNING: + overlayKey = CDTSharedImages.IMG_OVR_WARNING; + break; + case IStatus.INFO: + overlayKey = CDTSharedImages.IMG_OVR_WARNING; + break; + } + if (overlayKey != null) { + return CDTSharedImages.getImageOverlaid(imageKey, overlayKey, IDecoration.BOTTOM_LEFT); + } + return CDTSharedImages.getImage(imageKey); + } + return null; } /** @@ -114,50 +177,6 @@ public class LanguageSettingsImages { return imageKey; } - /** - * Returns image for the given entry from internally managed repository including - * necessary overlays. - * - * @param entry - language settings entry to get an image for. - * @param projectName - pass project name if available. That lets put "project" metaphor - * on the image. Pass {@code null} if no project name is available. - * @param cfgDescription - configuration description of the entry. - * @return the image for the entry with appropriate overlays. - */ - private static Image getImage(ICLanguageSettingEntry entry, String projectName, ICConfigurationDescription cfgDescription) { - int kind = entry.getKind(); - int flags = entry.getFlags(); - boolean isWorkspacePath = (flags & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; - String path = entry.getName(); - boolean isProjectRelative = (projectName != null) && isWorkspacePath && path.startsWith(IPath.SEPARATOR + projectName + IPath.SEPARATOR); - - String imageKey = getImageKey(kind, flags, isProjectRelative); - if (imageKey != null) { - if ((flags & ICSettingEntry.UNDEFINED) != 0) { - return CDTSharedImages.getImageOverlaid(imageKey, CDTSharedImages.IMG_OVR_INACTIVE, IDecoration.BOTTOM_LEFT); - } - - if (entry instanceof ACPathEntry) { - String overlayKey=null; - IStatus status = getStatus(entry, cfgDescription); - switch (status.getSeverity()) { - case IStatus.ERROR: - overlayKey = CDTSharedImages.IMG_OVR_ERROR; - break; - case IStatus.WARNING: - overlayKey = CDTSharedImages.IMG_OVR_WARNING; - break; - case IStatus.INFO: - overlayKey = CDTSharedImages.IMG_OVR_WARNING; - break; - } - return CDTSharedImages.getImageOverlaid(imageKey, overlayKey, IDecoration.BOTTOM_LEFT); - } - return CDTSharedImages.getImage(imageKey); - } - return null; - } - /** * Checking if the entry points to existing or accessible location. * @param entry - resolved entry diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/RegexErrorParserOptionPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/RegexErrorParserOptionPage.java index 62505a1fe5e..b3953ac2777 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/RegexErrorParserOptionPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/RegexErrorParserOptionPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Andrew Gvozdev and others. + * Copyright (c) 2009, 2013 Andrew Gvozdev and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Andrew Gvozdev - Initial API and implementation + * IBM Corporation *******************************************************************************/ package org.eclipse.cdt.ui.dialogs; @@ -24,12 +25,18 @@ import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnViewerEditor; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ComboBoxCellEditor; import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.TableViewerEditor; +import org.eclipse.jface.viewers.TableViewerFocusCellManager; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; @@ -326,7 +333,23 @@ public final class RegexErrorParserOptionPage extends AbstractCOptionPage { fTableViewer = new TableViewer(fTable); fTableViewer.setUseHashlookup(true); fTableViewer.setContentProvider(new ArrayContentProvider()); - + + //Bug 307542 - [Accessibility] Error Parser Options table should be accessible by keyboard + TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(fTableViewer,new FocusCellOwnerDrawHighlighter(fTableViewer)); + ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(fTableViewer) { + @Override + protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { + return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL + || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION + || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && (event.keyCode == SWT.CR || event.character == ' ')) + || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; + } + }; + + TableViewerEditor.create(fTableViewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL + | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR + | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); + createSeverityColumn(); createPatternColumn(); createFileColumn(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java index eb3401f86d9..c9005b518a4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java @@ -72,8 +72,8 @@ import org.eclipse.cdt.core.settings.model.MultiLanguageSetting; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProvidersPage; -import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/EnvironmentTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/EnvironmentTab.java index 175be00e0b0..f7121612144 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/EnvironmentTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/EnvironmentTab.java @@ -593,6 +593,7 @@ public class EnvironmentTab extends AbstractCPropertyTab { } vars = null; super.performOK(); + updateData(); } @Override diff --git a/doc/org.eclipse.cdt.doc.user/help.css b/doc/org.eclipse.cdt.doc.user/help.css old mode 100644 new mode 100755 index 797473964ab..fc9c54455aa --- a/doc/org.eclipse.cdt.doc.user/help.css +++ b/doc/org.eclipse.cdt.doc.user/help.css @@ -42,6 +42,9 @@ th { font-weight: bold } display: none; } +.menu td { vertical-align: top; } +td.menu_name {font-weight: bold;} + /* Mike Behm's addition to the style sheet */ .userinput { font-family: monospace; } .guitab, .important, .guibutton, .selectblue, .guimenu, .guilabel, diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_menu_edit.png b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_edit.png old mode 100644 new mode 100755 index e319b230205..fa85205cb52 Binary files a/doc/org.eclipse.cdt.doc.user/images/cdt_menu_edit.png and b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_edit.png differ diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_menu_file.png b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_file.png index 4ad536dce44..5bf1dd53c87 100644 Binary files a/doc/org.eclipse.cdt.doc.user/images/cdt_menu_file.png and b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_file.png differ diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_menu_source.png b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_source.png new file mode 100755 index 00000000000..d293d2bb8cb Binary files /dev/null and b/doc/org.eclipse.cdt.doc.user/images/cdt_menu_source.png differ diff --git a/doc/org.eclipse.cdt.doc.user/images/cdt_menubar.png b/doc/org.eclipse.cdt.doc.user/images/cdt_menubar.png index a1bbe79d1a8..44a91de3a73 100644 Binary files a/doc/org.eclipse.cdt.doc.user/images/cdt_menubar.png and b/doc/org.eclipse.cdt.doc.user/images/cdt_menubar.png differ diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_o_menu.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_o_menu.htm old mode 100644 new mode 100755 index 18cf71e4c7f..06217f65a24 --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_o_menu.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_o_menu.htm @@ -11,7 +11,7 @@

C/C++ Menubar

This section describes the menubar options available from the C/C++ perspective.

-

CDT main menu

@@ -19,6 +19,8 @@ alt="CDT main menu"> Edit Menu actions
+Source Menu actions
+ Refactor Menu actions
Navigate Menu actions
@@ -30,7 +32,7 @@ alt="CDT main menu"> Run Menu actions
Window Menu actions
-

IBM Copyright Statement +

IBM Copyright Statement

\ No newline at end of file diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_edit.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_edit.htm old mode 100644 new mode 100755 index 2e5fe91a171..feebc7e83d8 --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_edit.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_edit.htm @@ -1,6 +1,5 @@ - @@ -8,189 +7,213 @@ -

Edit Menu actions

- -

Selecting Edit Menu

-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameFunctionKeyboard Shortcut
UndoRevert the last change in the editor Ctrl+Z
Redo Revert an undone change Ctrl+Y
CutCopies the currently selected text or element to the clipboard and removes the element. On elements, the remove is not performed before the clipboard is pasted. Ctrl+X
CopyCopies the currently selected text or elements to the clipboard Ctrl+C
Paste Paste the current content as text to the editor, or as a sibling or child element to the a currently selected element.  Ctrl+V
Delete Delete the current text or element selection. Delete
Select AllSelect all the editor content.. Ctrl+A
Find / ReplaceOpen the Find / Replace dialog. Editor only. Ctrl+F
Find NextFinds the next occurrence of the currently selected text. Editor only. Ctrl+K
Find PreviousFinds the previous occurrence of the currently selected text. Editor only. Ctrl+Shift+K
Incremental Find NextStarts the incremental find mode. After invocation, enter the search text as instructed in the status bar. Editor only. Ctrl+J
Incremental Find PreviousStarts the incremental find mode. After invocation, enter the search text as instructed in the status bar. Editor only. Ctrl+Shift+J
Add Bookmark...Add a bookmark to the current text selection or selected element. 
Add Task...Add a user defined task to the current text selection or selected element. Alt+Enter
Add to working setAdd current resource to selected Working Set Ctrl+I
Remove from working setRemove current resource from Working Set Ctrl+Shift+I
Smart Insert ModeToggles editor's Smart Insert Mode Ctrl+Shift+Insert
Show Tooltip DescriptionDisplays tooltip description, where applicable.F2
Word CompletionCompletes current word in editor.Alt+/
Quick fixCall quick fix dialog for selected warning/error. Ctrl+1
Content AssistOpens a context assist dialog at the current cursor position to bring up Java code assist proposals and templates. See the Templates preference page for available templates - Window > Preferences > C/C++ > Editor > Templates and go to the Editor preference page - Window > Preferences > C/C++ > Editor > Content Assist for configuring the behavior of content assist. Ctrl+Space
Parameter HintsOpens Parameter Hints dialog. Editor onlyCtrl+Shift+Space
Shift RightShifts text Right. Editor only 
Shift LeftShifts text Right. Editor only 
FormatFormats text. Editor onlyCtrl+Shift+F
Add IncludeAdd include to current file. Editor only Ctrl+Shift+N
Set Encoding... Toggles the encoding of the currently shown text content. 
-

- - -

Note: Other Edit options are used with the JDT. Refer to the Java Development User Guide for details.

- -

-IBM Copyright Statement -

-
+
+

Edit Menu actions

+

+ Selecting Edit Menu +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ IBM Copyright Statement +

+
+ \ No newline at end of file diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_file.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_file.htm old mode 100644 new mode 100755 index 2ef7d4914e5..f30d686bdeb --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_file.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_file.htm @@ -1,141 +1,148 @@ - File Menu actions - - -

File Menu actions

-

Selecting File Menu

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameFunctionKeyboard Shortcut
NewCreate a new project, folder, or file.Alt+Shift+N
Open File...Open existing file. 
CloseClose the current editor. - If the editor contains unsaved data, a save request dialog is shown.Ctrl+F4
Close AllClose all editors. - If editors contains unsaved data, a save request dialog will be shown.Ctrl+Shift+F4
SaveSave the content of the current editor. - Disabled if the editor does not contain unsaved changes.Ctrl+S
Save AsSave the content of the current editor under a new name. 
Save AllSave the content of the current editor. - Disabled if no editor contains unsaved changes.Ctrl+Shift+S
RevertRevert the content of the current editor back to the content of the saved file. - Disabled if the editor does not contain unsaved changes. 
MoveMove a resource. 
RenameRenames a resource.F2
RefreshRefreshes the content of the selected element with the local file system. - When launched from no specific selection, this command refreshes all projects.F5
Convert Line Delimiters to (submenu)Changes line delimiters either to Windows, or UNIX, or Mac OS9 format. 
PrintPrints the content of the current editor. Enabled when an editor has the focus.Ctrl+P
Switch workspace...Relaunches Eclipse with a new workspace. 
ImportOpens the Import dialog and shows all import wizards. 
ExportOpens the Export dialog and shows all export wizards. 
PropertiesOpens the property pages of the select elements.Alt+Enter
ExitExit Eclipse 
-

- -

-IBM Copyright Statement -

-
+
+

File Menu actions

+

+ Selecting File Menu +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ IBM Copyright Statement +

+
+ \ No newline at end of file diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_navigate.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_navigate.htm old mode 100644 new mode 100755 index bad8cc190da..040681fcade --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_navigate.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_navigate.htm @@ -13,21 +13,21 @@

Selecting Navigate Menu

- +
- - - + + + - - + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + - + - - - + + + - - - + + + - - - + + + - - + - + - - + - + - - + - + - - + - + - - + - + diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_project.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_project.htm old mode 100644 new mode 100755 index 3ee5ce890cd..143baaaa5ad --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_project.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_m_project.htm @@ -14,31 +14,31 @@

Selecting Project Menu

-

+

- + - + - + - + - + - + - + - + - + - + - +