ctf: Introducing the ByteArrayDefinition
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 13 Jun 2014 15:24:57 +0000 (11:24 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 20 Jun 2014 17:34:42 +0000 (13:34 -0400)
This patch introduces a special acceleration that will make sequences
and arrays read faster when it's an array of bytes or a  string, as the
CTF spec specifies that they are aligned on 8 bits and always 8 bits wide
per character.

Sequences and arrays can either be ArrayDefinitions or
ByteArrayDefintions.

This patch gives a 20% acceleration in sequential reading.

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Change-Id: I7933268b7f9271f74f7d59339ea9b8343fdb021e
Reviewed-on: https://git.eclipse.org/r/26084
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
31 files changed:
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclaration2Test.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinition2Test.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/TestAll.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java
org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/AbstractArrayDefinition.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ScopedDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDefinition.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ByteArrayDefinition.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfEventFieldTest.java
org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfEventField.java

index 2e7224009c0ecd28837b985baa93841dbfa3293d..b74d65fa3ece13ff343495b4367883478b28e2ab 100644 (file)
@@ -23,12 +23,12 @@ import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java
new file mode 100644 (file)
index 0000000..0777ed5
--- /dev/null
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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:
+ *     Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>ArrayDeclaration2Test</code> contains tests for the class
+ * <code>{@link ArrayDeclaration}</code>.
+ *
+ * @author Matthew Khouzam
+ * @version $Revision: 1.0 $
+ */
+public class ArrayDeclaration2Test {
+
+    private ArrayDeclaration fixture;
+
+    /**
+     * Perform pre-test initialization.
+     */
+    @Before
+    public void setUp() {
+        fixture = new ArrayDeclaration(1, new StringDeclaration());
+    }
+
+    /**
+     * Run the ArrayDeclaration(int,Declaration) constructor test.
+     */
+    @Test
+    public void testArrayDeclaration() {
+        int length = 1;
+        IDeclaration elemType = new StringDeclaration();
+        ArrayDeclaration result = new ArrayDeclaration(length, elemType);
+
+        assertNotNull(result);
+        String left = "[declaration] array[";
+        String right = result.toString().substring(0, left.length());
+        assertEquals(left, right);
+        assertEquals(1, result.getLength());
+    }
+
+    /**
+     * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
+     * test.
+     *
+     * @throws CTFReaderException
+     *             error in the bitbuffer
+     */
+    @Test
+    public void testCreateDefinition() throws CTFReaderException {
+        String fieldName = "";
+        IDefinitionScope definitionScope = null;
+        AbstractArrayDefinition result;
+        byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+        ByteBuffer byb = ByteBuffer.wrap(array);
+        BitBuffer bb = new BitBuffer(byb);
+        result = fixture.createDefinition(definitionScope, fieldName, bb);
+
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Declaration getElementType() method test.
+     */
+    @Test
+    public void testGetElementType() {
+        IDeclaration result = fixture.getElementType();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the int getLength() method test.
+     */
+    @Test
+    public void testGetLength() {
+        int result = fixture.getLength();
+        assertEquals(1, result);
+    }
+
+    /**
+     * Run the boolean isString() method test.
+     */
+    @Test
+    public void testIsString_ownDefs() {
+        // it's an array of strings, not a string
+        assertFalse(fixture.isString());
+    }
+
+    /**
+     * Run the boolean isString() method test.
+     */
+    @Test
+    public void testIsString_complex() {
+        final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
+        ArrayDeclaration ad = new ArrayDeclaration(0, id);
+
+        boolean result = ad.isString();
+
+        assertTrue(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString() {
+        String result = fixture.toString();
+        String left = "[declaration] array[";
+        String right = result.substring(0, left.length());
+
+        assertEquals(left, right);
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java
deleted file mode 100644 (file)
index aed530b..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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:
- *     Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.*;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>ArrayDeclarationTest</code> contains tests for the class
- * <code>{@link ArrayDeclaration}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class ArrayDeclarationTest {
-
-    private ArrayDeclaration fixture;
-
-    /**
-     * Perform pre-test initialization.
-     */
-    @Before
-    public void setUp() {
-        fixture = new ArrayDeclaration(1, new StringDeclaration());
-    }
-
-    /**
-     * Run the ArrayDeclaration(int,Declaration) constructor test.
-     */
-    @Test
-    public void testArrayDeclaration() {
-        int length = 1;
-        IDeclaration elemType = new StringDeclaration();
-        ArrayDeclaration result = new ArrayDeclaration(length, elemType);
-
-        assertNotNull(result);
-        String left = "[declaration] array[";
-        String right = result.toString().substring(0, left.length());
-        assertEquals(left, right);
-        assertEquals(1, result.getLength());
-    }
-
-    /**
-     * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
-     * test.
-     *
-     * @throws CTFReaderException
-     *             error in the bitbuffer
-     */
-    @Test
-    public void testCreateDefinition() throws CTFReaderException {
-        String fieldName = "";
-        IDefinitionScope definitionScope = null;
-        ArrayDefinition result;
-        byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
-        ByteBuffer byb = ByteBuffer.wrap(array);
-        BitBuffer bb = new BitBuffer(byb);
-        result = fixture.createDefinition(definitionScope, fieldName, bb);
-
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Declaration getElementType() method test.
-     */
-    @Test
-    public void testGetElementType() {
-        IDeclaration result = fixture.getElementType();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the int getLength() method test.
-     */
-    @Test
-    public void testGetLength() {
-        int result = fixture.getLength();
-        assertEquals(1, result);
-    }
-
-    /**
-     * Run the boolean isString() method test.
-     */
-    @Test
-    public void testIsString_ownDefs() {
-        // it's an array of strings, not a string
-        assertFalse(fixture.isString());
-    }
-
-    /**
-     * Run the boolean isString() method test.
-     */
-    @Test
-    public void testIsString_complex() {
-        final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
-        ArrayDeclaration ad = new ArrayDeclaration(0, id);
-
-        boolean result = ad.isString();
-
-        assertTrue(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString() {
-        String result = fixture.toString();
-        String left = "[declaration] array[";
-        String right = result.substring(0, left.length());
-
-        assertEquals(left, right);
-    }
-}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java
new file mode 100644 (file)
index 0000000..276d095
--- /dev/null
@@ -0,0 +1,256 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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:
+ *     Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>ArrayDefinition2Test</code> contains tests for the class
+ * <code>{@link ArrayDefinition}</code>.
+ *
+ */
+public class ArrayDefinition2Test {
+
+    @NonNull private CTFTrace trace = new CTFTrace();
+    private ArrayDefinition charArrayFixture;
+    private ArrayDefinition stringArrayFixture;
+    private ArrayDefinition longArrayFixture;
+
+    /**
+     * Perform pre-test initialization.
+     *
+     * structDef shouldn't be null after parsing the CTFTraceReader object, so
+     * we can ignore the warning.
+     */
+    @Before
+    public void setUp() {
+        charArrayFixture = createCharArray();
+        stringArrayFixture = createStringArray();
+        longArrayFixture = createLongArray();
+    }
+
+    private ArrayDefinition createLongArray() {
+        IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8);
+        List<Definition> defs = createIntDefs(10, 32);
+        ArrayDefinition temp = setUpDeclaration(decl, defs);
+        return temp;
+    }
+
+    private ArrayDefinition createCharArray() {
+        IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8);
+        List<Definition> defs = createIntDefs(4, 8);
+        ArrayDefinition temp = setUpDeclaration(decl, defs);
+        return temp;
+    }
+
+    private ArrayDefinition createStringArray() {
+        StringDeclaration strDecl = new StringDeclaration();
+        List<Definition> defs = createDefs();
+        ArrayDefinition temp = setUpDeclaration(strDecl, defs);
+        return temp;
+    }
+
+    private ArrayDefinition setUpDeclaration(IDeclaration decl,
+            @NonNull List<Definition> defs) {
+        ArrayDeclaration ad = new ArrayDeclaration(0, decl);
+        ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs);
+        return temp;
+    }
+
+    private @NonNull
+    static List<Definition> createIntDefs(int size, int bits) {
+        List<Definition> defs = new ArrayList<>(size);
+        for (int i = 0; i < size; i++) {
+            String content = "test" + i;
+            defs.add(new IntegerDefinition(IntegerDeclaration.createDeclaration(bits, false,
+                    16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content, i));
+        }
+        return defs;
+    }
+
+    private @NonNull
+    static List<Definition> createDefs() {
+        int size = 4;
+        List<Definition> defs = new ArrayList<>();
+        for (int i = 0; i < size; i++) {
+            String content = "test" + i;
+            defs.add(new StringDefinition(
+                    new StringDeclaration(Encoding.UTF8), null, content, content));
+        }
+        return defs;
+    }
+
+    /**
+     * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
+     * constructor test.
+     */
+    @Test
+    public void testArrayDefinition_baseDeclaration() {
+        ArrayDeclaration declaration = (ArrayDeclaration) charArrayFixture.getDeclaration();
+        String fieldName = "";
+
+        @SuppressWarnings("null")
+        ArrayDefinition result = new ArrayDefinition(declaration, this.trace, fieldName, Arrays.asList(new Definition[0]));
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
+     * constructor test.
+     */
+    @Test
+    public void testArrayDefinition_newDeclaration() {
+        ArrayDeclaration declaration = new ArrayDeclaration(0,
+                new StringDeclaration());
+        IDefinitionScope definitionScope = getDefinitionScope();
+
+        String fieldName = "";
+        @SuppressWarnings("null")
+        ArrayDefinition result = new ArrayDefinition(declaration, definitionScope, fieldName , Arrays.asList(new Definition[0]));
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the ArrayDeclaration getDeclaration() method test.
+     */
+    @Test
+    public void testGetDeclaration() {
+        ArrayDeclaration result = (ArrayDeclaration) charArrayFixture.getDeclaration();
+
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Definition getDefinitions().get(int) method test.
+     */
+    @Test
+    public void testgetElem_noDefs() {
+        int i = 0;
+        Definition result = charArrayFixture.getDefinitions().get(i);
+
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Definition getDefinitions().get(int) method test.
+     */
+    @Test
+    public void testgetElem_withDefs() {
+        List<Definition> defs = createDefs();
+        IDefinitionScope definitionScope = getDefinitionScope();
+        ArrayDefinition ad = new ArrayDefinition((CompoundDeclaration) charArrayFixture.getDeclaration(), definitionScope, "test", defs);
+        int j = 1;
+
+        Definition result = ad.getDefinitions().get(j);
+
+        assertNotNull(result);
+    }
+
+    @NonNull private static IDefinitionScope getDefinitionScope() {
+        return new IDefinitionScope() {
+
+            @Override
+            public Definition lookupDefinition(String lookupPath) {
+                return null;
+            }
+
+            @Override
+            public LexicalScope getScopePath() {
+                return null;
+            }
+        };
+    }
+
+    /**
+     * Run the void read(BitBuffer) method test.
+     *
+     * @throws CTFReaderException
+     *             error
+     */
+    @Test
+    public void testRead_noDefs() throws CTFReaderException {
+        BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
+        charArrayFixture.getDeclaration().createDefinition(null, "test", input);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString_char() {
+        String result = charArrayFixture.toString();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString_long() {
+        String result = longArrayFixture.toString();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString_string() {
+        String result = stringArrayFixture.toString();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString_withDefs() {
+        String result = charArrayFixture.toString();
+
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToStringStringArray() {
+        String result = stringArrayFixture.toString();
+
+        assertNotNull(result);
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
deleted file mode 100644 (file)
index 822e512..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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:
- *     Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>ArrayDefinitionTest</code> contains tests for the class
- * <code>{@link ArrayDefinition}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class ArrayDefinitionTest {
-
-    @NonNull private CTFTrace trace = new CTFTrace();
-    private ArrayDefinition charArrayFixture;
-    private ArrayDefinition stringArrayFixture;
-    private ArrayDefinition longArrayFixture;
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * structDef shouldn't be null after parsing the CTFTraceReader object, so
-     * we can ignore the warning.
-     */
-    @Before
-    public void setUp() {
-        charArrayFixture = createCharArray();
-        stringArrayFixture = createStringArray();
-        longArrayFixture = createLongArray();
-    }
-
-    private ArrayDefinition createLongArray() {
-        IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8);
-        List<Definition> defs = createIntDefs(10, 32);
-        ArrayDefinition temp = setUpDeclaration(decl, defs);
-        return temp;
-    }
-
-    private ArrayDefinition createCharArray() {
-        IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8);
-        List<Definition> defs = createIntDefs(4, 8);
-        ArrayDefinition temp = setUpDeclaration(decl, defs);
-        return temp;
-    }
-
-    private ArrayDefinition createStringArray() {
-        StringDeclaration strDecl = new StringDeclaration();
-        List<Definition> defs = createDefs();
-        ArrayDefinition temp = setUpDeclaration(strDecl, defs);
-        return temp;
-    }
-
-    private ArrayDefinition setUpDeclaration(IDeclaration decl,
-            @NonNull List<Definition> defs) {
-        ArrayDeclaration ad = new ArrayDeclaration(0, decl);
-        ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs);
-        return temp;
-    }
-
-    private @NonNull
-    static List<Definition> createIntDefs(int size, int bits) {
-        List<Definition> defs = new ArrayList<>(size);
-        for (int i = 0; i < size; i++) {
-            String content = "test" + i;
-            defs.add(new IntegerDefinition(IntegerDeclaration.createDeclaration(bits, false,
-                    16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content, i));
-        }
-        return defs;
-    }
-
-    private @NonNull
-    static List<Definition> createDefs() {
-        int size = 4;
-        List<Definition> defs = new ArrayList<>();
-        for (int i = 0; i < size; i++) {
-            String content = "test" + i;
-            defs.add(new StringDefinition(
-                    new StringDeclaration(Encoding.UTF8), null, content, content));
-        }
-        return defs;
-    }
-
-    /**
-     * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
-     * constructor test.
-     */
-    @Test
-    public void testArrayDefinition_baseDeclaration() {
-        ArrayDeclaration declaration = charArrayFixture.getDeclaration();
-        String fieldName = "";
-
-        @SuppressWarnings("null")
-        ArrayDefinition result = new ArrayDefinition(declaration, this.trace, fieldName, Arrays.asList(new Definition[0]));
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
-     * constructor test.
-     */
-    @Test
-    public void testArrayDefinition_newDeclaration() {
-        ArrayDeclaration declaration = new ArrayDeclaration(0,
-                new StringDeclaration());
-        IDefinitionScope definitionScope = getDefinitionScope();
-
-        String fieldName = "";
-        @SuppressWarnings("null")
-        ArrayDefinition result = new ArrayDefinition(declaration, definitionScope, fieldName , Arrays.asList(new Definition[0]));
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the ArrayDeclaration getDeclaration() method test.
-     */
-    @Test
-    public void testGetDeclaration() {
-        ArrayDeclaration result = charArrayFixture.getDeclaration();
-
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Definition getElem(int) method test.
-     */
-    @Test
-    public void testGetElem_noDefs() {
-        int i = 0;
-        Definition result = charArrayFixture.getElem(i);
-
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Definition getElem(int) method test.
-     */
-    @Test
-    public void testGetElem_withDefs() {
-        List<Definition> defs = createDefs();
-        IDefinitionScope definitionScope = getDefinitionScope();
-        ArrayDefinition ad = new ArrayDefinition(charArrayFixture.getDeclaration(), definitionScope, "test", defs);
-        int j = 1;
-
-        Definition result = ad.getElem(j);
-
-        assertNotNull(result);
-    }
-
-    @NonNull private static IDefinitionScope getDefinitionScope() {
-        return new IDefinitionScope() {
-
-            @Override
-            public Definition lookupDefinition(String lookupPath) {
-                return null;
-            }
-
-            @Override
-            public LexicalScope getScopePath() {
-                return null;
-            }
-        };
-    }
-
-    /**
-     * Run the void read(BitBuffer) method test.
-     *
-     * @throws CTFReaderException
-     *             error
-     */
-    @Test
-    public void testRead_noDefs() throws CTFReaderException {
-        BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
-        charArrayFixture.getDeclaration().createDefinition(null, "test", input);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString_char() {
-        String result = charArrayFixture.toString();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString_long() {
-        String result = longArrayFixture.toString();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString_string() {
-        String result = stringArrayFixture.toString();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString_withDefs() {
-        String result = charArrayFixture.toString();
-
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToStringStringArray() {
-        String result = stringArrayFixture.toString();
-
-        assertNotNull(result);
-    }
-}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclaration2Test.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclaration2Test.java
new file mode 100644 (file)
index 0000000..861f079
--- /dev/null
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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:
+ *     Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * The class <code>SequenceDeclarationTest</code> contains tests for the class
+ * <code>{@link SequenceDeclaration}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class SequenceDeclaration2Test {
+
+    @NonNull private static final String FIELD_NAME = "LengthName";
+
+    private SequenceDeclaration fixture;
+    @NonNull private BitBuffer input = new BitBuffer();
+
+    @Before
+    public void setUp() {
+        fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
+        byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+        ByteBuffer byb = ByteBuffer.wrap(array);
+        input = new BitBuffer(byb);
+    }
+
+    /**
+     * Run the SequenceDeclaration(String,Declaration) constructor test.
+     */
+    @Test
+    public void testSequenceDeclaration() {
+        String lengthName = "";
+        IDeclaration elemType = new StringDeclaration();
+
+        SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
+        assertNotNull(result);
+        String string = "[declaration] sequence[";
+        assertEquals(string, result.toString().substring(0, string.length()));
+    }
+
+    /**
+     * Run the SequenceDefinition createDefinition(DefinitionScope,String)
+     * method test.
+     *
+     * @throws CTFReaderException
+     *             an error in the bitbuffer
+     */
+    @Test
+    public void testCreateDefinition() throws CTFReaderException {
+        long seqLen = 2;
+        IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
+        StructDeclaration structDec = new StructDeclaration(0);
+        structDec.addField(FIELD_NAME, id);
+        StructDefinition structDef = new StructDefinition(
+                structDec,
+                null,
+                "x",
+                ImmutableList.of(FIELD_NAME),
+                new Definition[] {
+                        new IntegerDefinition(
+                                id,
+                                null,
+                                FIELD_NAME,
+                                seqLen)
+                });
+        AbstractArrayDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Declaration getElementType() method test.
+     */
+    @Test
+    public void testGetElementType() {
+        IDeclaration result = fixture.getElementType();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString() {
+        String result = fixture.toString();
+        String left = "[declaration] sequence[";
+        assertEquals(left, result.substring(0, left.length()));
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java
deleted file mode 100644 (file)
index dbdf621..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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:
- *     Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * The class <code>SequenceDeclarationTest</code> contains tests for the class
- * <code>{@link SequenceDeclaration}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class SequenceDeclarationTest {
-
-    @NonNull private static final String FIELD_NAME = "LengthName";
-
-    private SequenceDeclaration fixture;
-    @NonNull private BitBuffer input = new BitBuffer();
-
-    @Before
-    public void setUp() {
-        fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
-        byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
-        ByteBuffer byb = ByteBuffer.wrap(array);
-        input = new BitBuffer(byb);
-    }
-
-    /**
-     * Run the SequenceDeclaration(String,Declaration) constructor test.
-     */
-    @Test
-    public void testSequenceDeclaration() {
-        String lengthName = "";
-        IDeclaration elemType = new StringDeclaration();
-
-        SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
-        assertNotNull(result);
-        String string = "[declaration] sequence[";
-        assertEquals(string, result.toString().substring(0, string.length()));
-    }
-
-    /**
-     * Run the SequenceDefinition createDefinition(DefinitionScope,String)
-     * method test.
-     *
-     * @throws CTFReaderException
-     *             an error in the bitbuffer
-     */
-    @Test
-    public void testCreateDefinition() throws CTFReaderException {
-        long seqLen = 2;
-        IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
-        StructDeclaration structDec = new StructDeclaration(0);
-        structDec.addField(FIELD_NAME, id);
-        StructDefinition structDef = new StructDefinition(
-                structDec,
-                null,
-                "x",
-                ImmutableList.of(FIELD_NAME),
-                new Definition[] {
-                        new IntegerDefinition(
-                                id,
-                                null,
-                                FIELD_NAME,
-                                seqLen)
-                });
-        SequenceDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Declaration getElementType() method test.
-     */
-    @Test
-    public void testGetElementType() {
-        IDeclaration result = fixture.getElementType();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString() {
-        String result = fixture.toString();
-        String left = "[declaration] sequence[";
-        assertEquals(left, result.substring(0, left.length()));
-    }
-}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinition2Test.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinition2Test.java
new file mode 100644 (file)
index 0000000..c981f48
--- /dev/null
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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:
+ *     Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ByteArrayDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * The class <code>SequenceDefinition2Test</code> contains tests for the class
+ * <code>{@link SequenceDefinition2}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class SequenceDefinition2Test {
+
+    private ByteArrayDefinition fixture;
+    private final static int seqLen = 15;
+
+    private static ImmutableList<String> wrap(String s) {
+        return ImmutableList.<String> builder().add(s).build();
+    }
+
+    /**
+     * Perform pre-test initialization.
+     *
+     * @throws CTFReaderException
+     */
+    @Before
+    public void setUp() throws CTFReaderException {
+        fixture = initString();
+    }
+
+    private static ByteArrayDefinition initString() throws CTFReaderException {
+        StructDeclaration structDec;
+        StructDefinition structDef;
+
+        int len = 8;
+        IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
+        String lengthName = "LengthName";
+        structDec = new StructDeclaration(0);
+        structDec.addField(lengthName, id);
+
+        structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
+
+        SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
+        BitBuffer input = new BitBuffer(
+                java.nio.ByteBuffer.allocateDirect(seqLen * len));
+        for (int i = 0; i < seqLen; i++) {
+            input.putInt(i);
+        }
+
+        ByteArrayDefinition ret = (ByteArrayDefinition) sd.createDefinition(structDef, "TestX", input);
+        assertNotNull(ret);
+        return ret;
+    }
+
+    /**
+     * Run the FixedStringDefinition(SequenceDeclaration,DefinitionScope,String)
+     * constructor test.
+     */
+    @Test
+    public void testFixedStringDefinition() {
+        assertNotNull(fixture);
+    }
+
+    /**
+     * Run the SequenceDeclaration getDeclaration() method test.
+     */
+    @Test
+    public void testGetDeclaration() {
+        SequenceDeclaration result = (SequenceDeclaration) fixture.getDeclaration();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Definition getElem(int) method test.
+     */
+    @Test
+    public void testGetElem() {
+        int i = 1;
+        Definition result = fixture.getDefinitions().get(i);
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString() {
+        String result = fixture.toString();
+        assertNotNull(result);
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java
deleted file mode 100644 (file)
index 4a5e5ad..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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:
- *     Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.ByteOrder;
-
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * The class <code>SequenceDefinitionTest</code> contains tests for the class
- * <code>{@link SequenceDefinition}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class SequenceDefinitionTest {
-
-    private SequenceDefinition fixture;
-    private final static int seqLen = 15;
-
-    private static ImmutableList<String> wrap(String s) {
-        return ImmutableList.<String> builder().add(s).build();
-    }
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * @throws CTFReaderException
-     */
-    @Before
-    public void setUp() throws CTFReaderException {
-        StructDeclaration structDec;
-        StructDefinition structDef;
-
-        IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
-        String lengthName = "LengthName";
-        structDec = new StructDeclaration(0);
-        structDec.addField(lengthName, id);
-        structDef = new StructDefinition(structDec, null, "x",
-                wrap(lengthName),
-                new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
-
-        SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
-        BitBuffer input = new BitBuffer(
-                java.nio.ByteBuffer.allocateDirect(seqLen * 8));
-        for (int i = 0; i < seqLen; i++) {
-            input.putInt(i);
-        }
-
-        fixture = sd.createDefinition(structDef, "TestX", input);
-        assert (fixture != null);
-    }
-
-    private static SequenceDefinition initNonString() throws CTFReaderException {
-        StructDeclaration structDec;
-        StructDefinition structDef;
-
-        int len = 32;
-        IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
-        String lengthName = "LengthName";
-        structDec = new StructDeclaration(0);
-        structDec.addField(lengthName, id);
-
-        structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
-
-        SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
-        BitBuffer input = new BitBuffer(
-                java.nio.ByteBuffer.allocateDirect(seqLen * len));
-        for (int i = 0; i < seqLen; i++) {
-            input.putInt(i);
-        }
-
-        SequenceDefinition ret = sd.createDefinition(structDef, "TestX", input);
-        assertNotNull(ret);
-        return ret;
-    }
-
-    /**
-     * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
-     * constructor test.
-     */
-    @Test
-    public void testSequenceDefinition() {
-        assertNotNull(fixture);
-    }
-
-    /**
-     * Run the SequenceDeclaration getDeclaration() method test.
-     */
-    @Test
-    public void testGetDeclaration() {
-        SequenceDeclaration result = fixture.getDeclaration();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Definition getElem(int) method test.
-     */
-    @Test
-    public void testGetElem() {
-        int i = 1;
-        Definition result = fixture.getElem(i);
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the int getLength() method test.
-     */
-    @Test
-    public void testGetLength() {
-        int result = fixture.getLength();
-
-        assertEquals(seqLen, result);
-    }
-
-    /**
-     * Run the boolean isString() method test.
-     */
-    @Test
-    public void testIsString() {
-        boolean result = fixture.getDeclaration().isString();
-        assertTrue(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString() {
-        String result = fixture.toString();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString_nonString() throws Exception {
-        fixture = initNonString();
-        String result = fixture.toString();
-        assertNotNull(result);
-    }
-}
index ce4a57afcb2dfb38a3067a700206947842b227c9..5183f971d96c3c6f9b9032183d95816c2e19ab55 100644 (file)
@@ -19,14 +19,12 @@ import java.nio.ByteBuffer;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
@@ -34,6 +32,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -135,8 +134,7 @@ public class StructDefinitionTest {
     @Test
     public void testLookupArray() {
         String name = INT_ID;
-        ArrayDefinition result = fixture.lookupArray(name);
-
+        AbstractArrayDefinition result = fixture.lookupArray2(name);
         assertNull(result);
     }
 
@@ -185,9 +183,9 @@ public class StructDefinitionTest {
      * Run the SequenceDefinition lookupSequence(String) method test.
      */
     @Test
-    public void testLookupSequence() {
+    public void testLookupFixedStringDefinition() {
         String name = SEQUENCE_ID;
-        SequenceDefinition result = fixture.lookupSequence(name);
+        AbstractArrayDefinition result = fixture.lookupArray2(name);
         assertNotNull(result);
     }
 
index 87b306b2456b2be3dbc987c702fd820ef8f44032..7b537be19030a66a1b8007b83e0e50d9450807e8 100644 (file)
@@ -24,8 +24,8 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-    ArrayDeclarationTest.class,
-    ArrayDefinitionTest.class,
+    ArrayDeclaration2Test.class,
+    ArrayDefinition2Test.class,
     DefinitionTest.class,
     EnumDeclarationTest.class,
     EnumDefinitionTest.class,
@@ -35,8 +35,8 @@ import org.junit.runners.Suite;
     IntegerDeclarationTest.class,
     IntegerDefinitionTest.class,
     IntegerEndiannessTest.class,
-    SequenceDeclarationTest.class,
-    SequenceDefinitionTest.class,
+    SequenceDeclaration2Test.class,
+    SequenceDefinition2Test.class,
     StringDeclarationTest.class,
     StringDefinitionTest.class,
     StructDeclarationTest.class,
index 9a30f6c8f20a66427932ce53055ee1a1eaeaf3ea..da10efecd928234103b07a3e559f279c93819022 100644 (file)
@@ -21,8 +21,7 @@ import java.nio.ByteOrder;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
@@ -30,7 +29,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
@@ -38,6 +36,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -219,7 +218,7 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupArray() {
-        ArrayDefinition result = fixture.lookupArray(ENUM_3);
+        AbstractArrayDefinition result = fixture.lookupArray2(ENUM_3);
         assertNull(result);
     }
 
@@ -251,15 +250,6 @@ public class VariantDefinitionTest {
         assertNull(result);
     }
 
-    /**
-     * Run the SequenceDefinition lookupSequence(String) method test.
-     */
-    @Test
-    public void testLookupSequence_1() {
-        SequenceDefinition result = fixture.lookupSequence(ENUM_4);
-        assertNull(result);
-    }
-
     /**
      * Run the StringDefinition lookupString(String) method test.
      */
index 04087070b65f3488fbe358ed8444c66c37e2e3df..82ab45bfa3cb72b792968c25dfb475532ca1e859 100644 (file)
@@ -20,6 +20,7 @@ Export-Package: org.eclipse.linuxtools.ctf.core,
  org.eclipse.linuxtools.internal.ctf.core.event;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
  org.eclipse.linuxtools.internal.ctf.core.event.metadata;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
  org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
+ org.eclipse.linuxtools.internal.ctf.core.event.types;x-friends:="org.eclipse.linuxtools.ctf.core.tests,org.eclipse.linuxtools.tmf.ctf.core,org.eclipse.linuxtools.tmf.ctf.core.tests",
  org.eclipse.linuxtools.internal.ctf.core.trace;x-friends:="org.eclipse.linuxtools.ctf.core.tests"
 Import-Package: com.google.common.base,
  com.google.common.collect,
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/AbstractArrayDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/AbstractArrayDefinition.java
new file mode 100644 (file)
index 0000000..f724f25
--- /dev/null
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+
+/**
+ * Array definition, used for compound definitions and fixed length strings
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public abstract class AbstractArrayDefinition extends Definition {
+
+    /**
+     * Constructor
+     *
+     * @param declaration
+     *            the event declaration
+     *
+     * @param definitionScope
+     *            the definition is in a scope, (normally a struct) what is it?
+     * @param fieldName
+     *            the name of the definition. (it is a field in the parent
+     *            scope)
+     */
+    public AbstractArrayDefinition(IDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName) {
+        super(declaration, definitionScope, fieldName);
+    }
+
+    /**
+     * Get the defintions, an array is a collection of definitions
+     *
+     * @return the definitions
+     */
+    public abstract List<Definition> getDefinitions();
+
+}
\ No newline at end of file
index d0d9691c8d4d905a73bb252482bc2b4d9981c9d5..2a729ac41281268aad30d387dce567ccd1ef828b 100644 (file)
@@ -32,10 +32,12 @@ import com.google.common.collect.Multimap;
  * can refer to any type not containing the type of the array being declared (no
  * circular dependency). The length is the number of elements in an array.
  *
+ * @deprecated use {@link org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration}
  * @version 1.0
  * @author Matthew Khouzam
  * @author Simon Marchi
  */
+@Deprecated
 public class ArrayDeclaration extends Declaration {
 
     // ------------------------------------------------------------------------
@@ -128,6 +130,7 @@ public class ArrayDeclaration extends Declaration {
     /**
      * @since 3.0
      */
+    @Deprecated
     @Override
     public ArrayDefinition createDefinition(IDefinitionScope definitionScope,
             @NonNull String fieldName, BitBuffer input) throws CTFReaderException {
index 695de3cddd8c25866e37db09d8be183cd6460900..9fff73be2874d1219620b801769f6defc45a6267 100644 (file)
@@ -30,11 +30,13 @@ import com.google.common.collect.ImmutableList;
  * can refer to any type not containing the type of the array being declared (no
  * circular dependency). The length is the number of elements in an array.
  *
+ * @deprecated use {@link AbstractArrayDefinition}
  * @version 1.0
  * @author Matthew Khouzam
  * @author Simon Marchi
  */
 @NonNullByDefault
+@Deprecated
 public final class ArrayDefinition extends Definition {
 
     // ------------------------------------------------------------------------
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java
new file mode 100644 (file)
index 0000000..2f6ab4f
--- /dev/null
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+
+/**
+ * Parent of sequences and arrays
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public abstract class CompoundDeclaration extends Declaration {
+
+    /**
+     * Get the element type
+     *
+     * @return the type of element in the array
+     */
+    public abstract IDeclaration getElementType();
+
+}
index ceeb2ded2e4e31f198a9b068b070e81fa4d0f8c4..4d3d51b21760784c59e2ae62a8f3a5b77885341a 100644 (file)
@@ -199,7 +199,8 @@ public class IntegerDeclaration extends Declaration {
         fBase = base;
 
         @SuppressWarnings("null")
-        @NonNull ByteOrder actualByteOrder = (byteOrder == null ? ByteOrder.nativeOrder() : byteOrder);
+        @NonNull
+        ByteOrder actualByteOrder = (byteOrder == null ? ByteOrder.nativeOrder() : byteOrder);
         fByteOrder = actualByteOrder;
 
         fEncoding = encoding;
@@ -260,6 +261,16 @@ public class IntegerDeclaration extends Declaration {
         return (fLength == 8) && (fEncoding != Encoding.NONE);
     }
 
+    /**
+     * Is the integer an unsigned byte (8 bits and no sign)?
+     *
+     * @return is the integer an unsigned byte
+     * @since 3.1
+     */
+    public boolean isUnsignedByte() {
+        return (fLength == 8) && (!fSigned);
+    }
+
     /**
      * Get the length in bits for this integer
      *
@@ -329,7 +340,8 @@ public class IntegerDeclaration extends Declaration {
          */
 
         @SuppressWarnings("null")
-        @NonNull BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).subtract(BigInteger.ONE);
+        @NonNull
+        BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).subtract(BigInteger.ONE);
         return ret;
     }
 
@@ -342,7 +354,8 @@ public class IntegerDeclaration extends Declaration {
     public BigInteger getMinValue() {
         if (!fSigned) {
             @SuppressWarnings("null")
-            @NonNull BigInteger ret = BigInteger.ZERO;
+            @NonNull
+            BigInteger ret = BigInteger.ZERO;
             return ret;
         }
 
@@ -356,7 +369,8 @@ public class IntegerDeclaration extends Declaration {
          * (1 << N).
          */
         @SuppressWarnings("null")
-        @NonNull BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).negate();
+        @NonNull
+        BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).negate();
         return ret;
     }
 
index 36ace368ea3eea45eaae8abbb0e64adf616ca88f..f8b7158b87e253264c2445c7c62f86edbdc2bd60 100644 (file)
@@ -48,9 +48,23 @@ public abstract class ScopedDefinition extends Definition implements IDefinition
      *
      * @param name
      *            the name of the array
-     * @return the array or null if a definition is not found or it does not
-     *         match the desired datatype.
+     * @return the array or null.
+     */
+    @Nullable
+    public AbstractArrayDefinition lookupArray2(String name){
+        Definition def = lookupDefinition(name);
+        return (AbstractArrayDefinition) ((def instanceof AbstractArrayDefinition) ? def : null);
+    }
+
+    /**
+     * Lookup an array in a struct. If the name returns a non-array (like an
+     * int) then the method returns null
+     *
+     * @param name
+     *            the name of the array
+     * @return the array or null.
      */
+    @Deprecated
     @Nullable
     public ArrayDefinition lookupArray(String name) {
         Definition def = lookupDefinition(name);
@@ -97,6 +111,7 @@ public abstract class ScopedDefinition extends Definition implements IDefinition
      *         match the desired datatype.
      * @since 3.0
      */
+    @Deprecated
     @Nullable
     public SequenceDefinition lookupSequence(String name) {
         Definition def = lookupDefinition(name);
index 811321df5baa7007d0da249a7fed8dafdb988312..e1131e1db1e7c0041ae34cdc83b128df5bad18b4 100644 (file)
@@ -29,11 +29,12 @@ import com.google.common.collect.Multimap;
  *
  * An array where the size is fixed but declared in the trace, unlike array
  * where it is declared with a literal
- *
+ * @deprecated use {@link org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration}
  * @version 1.0
  * @author Matthew Khouzam
  * @author Simon Marchi
  */
+@Deprecated
 public class SequenceDeclaration extends Declaration {
 
     // ------------------------------------------------------------------------
index 44e2fdf4c1feefc379a9a7b31a309fa3a5be4f08..3f0a29004861fca15ae08dd5344efe80c2e4bf94 100644 (file)
@@ -26,14 +26,14 @@ import com.google.common.collect.ImmutableList;
  * An array where the size is fixed but declared in the trace, unlike array
  * where it is declared with a literal
  *
+ * @deprecated use {@link AbstractArrayDefinition}
  * @version 1.0
  * @author Matthew Khouzam
  * @author Simon Marchi
  */
+@Deprecated
 public final class SequenceDefinition extends Definition {
 
-    // TODO: investigate merging with arraydefinition
-
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
index af7f964085460cff0fbd36e7ee879cf4d36b001a..7c5c624aa7720775a226bc788a5ac9360d4859ca 100644 (file)
@@ -25,7 +25,6 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
@@ -33,6 +32,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
 
index 5982864a463d95c0a6c64779a925978fe07b8287..cacc47e8a50a1bee166a9e192f91c60e9ca090d1 100644 (file)
@@ -40,13 +40,13 @@ import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.event.CTFCallsiteComparator;
 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
 
 /**
  * A CTF trace on the file system.
index f76f055b8821c541ad4f4097e1b14a282261646a..c0432642be2c7595ab2841c7bafd2b6477f02302 100644 (file)
@@ -14,7 +14,10 @@ package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.util.UUID;
 
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 
 /**
@@ -65,9 +68,9 @@ public final class Utils {
     /**
      * Performs an unsigned long comparison on two unsigned long numbers.
      *
-     * <strong> As Java does not support unsigned types and arithmetic, parameters
-     *       are received encoded as a signed long (two-complement) but the
-     *       operation is an unsigned comparator.</strong>
+     * <strong> As Java does not support unsigned types and arithmetic,
+     * parameters are received encoded as a signed long (two-complement) but the
+     * operation is an unsigned comparator.</strong>
      *
      * @param left
      *            Left operand of the comparator.
@@ -102,9 +105,50 @@ public final class Utils {
      * @return the UUID
      * @throws CTFReaderException
      *             if the definition contains less than 16 elements
-     * @since 3.0
+     * @since 3.1
      */
-    public static UUID getUUIDfromDefinition(ArrayDefinition uuidDef) throws CTFReaderException {
+    public static UUID getUUIDfromDefinition(AbstractArrayDefinition uuidDef) throws CTFReaderException {
+        byte[] uuidArray = new byte[16];
+        IDeclaration declaration = uuidDef.getDeclaration();
+        if (!(declaration instanceof CompoundDeclaration)) {
+            throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$
+        }
+        CompoundDeclaration uuidDec = (CompoundDeclaration) declaration;
+
+        IDeclaration uuidElem = uuidDec.getElementType();
+        if (!(uuidElem instanceof IntegerDeclaration)) {
+            throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$
+        }
+        IntegerDeclaration intUuidElem = (IntegerDeclaration) uuidElem;
+        if (!intUuidElem.isUnsignedByte()) {
+            throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$
+        }
+        for (int i = 0; i < uuidArray.length; i++) {
+            IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getDefinitions().get(i);
+            if (uuidByteDef == null) {
+                throw new CTFReaderException("UUID incomplete, only " + i + " bytes available"); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            uuidArray[i] = (byte) uuidByteDef.getValue();
+        }
+
+        UUID uuid = Utils.makeUUID(uuidArray);
+        return uuid;
+    }
+
+    /**
+     * Gets a UUID from an array defintion
+     *
+     * @param uuidDef
+     *            the array defintions, must contain integer bytes
+     * @return the UUID
+     * @throws CTFReaderException
+     *             if the definition contains less than 16 elements
+     * @since 3.1
+     * @deprecated use
+     *             {@link Utils#getUUIDfromDefinition(AbstractArrayDefinition uuidDef)}
+     */
+    @Deprecated
+    public static UUID getUUIDfromDefinition(org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition uuidDef) throws CTFReaderException {
         byte[] uuidArray = new byte[16];
 
         for (int i = 0; i < uuidArray.length; i++) {
index 202997e9b61f6ba184ceac6acfd0ce5a21dd754f..c4c517f7bc7e5ff48cc90777d5cbddcb65a66733 100644 (file)
@@ -31,22 +31,22 @@ import org.antlr.runtime.tree.CommonTree;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.parser.CTFParser;
 import org.eclipse.linuxtools.internal.ctf.core.Activator;
 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
 
 /**
  * IOStructGen
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java
new file mode 100644 (file)
index 0000000..4475552
--- /dev/null
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+/**
+ * A CTF array declaration
+ *
+ * Arrays are fixed-length. Their length is declared in the type declaration
+ * within the meta-data. They contain an array of "inner type" elements, which
+ * can refer to any type not containing the type of the array being declared (no
+ * circular dependency). The length is the number of elements in an array.
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public final class ArrayDeclaration extends CompoundDeclaration {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final int fLength;
+    private final IDeclaration fElemType;
+
+    /**
+     * <pre>
+     * Cache where we can pre-generate the children names
+     * Key&colon; parent name
+     * Value&colon; children names
+     * ex: field &#8594; &lbrace;field&lbrack;0&rbrack;, field&lbrack;1&rbrack;, &hellip; field&lbrack;n&rbrack;&rbrace;
+     * </pre>
+     *
+     * TODO: investigate performance
+     */
+    private final ArrayListMultimap<String, String> fChildrenNames = ArrayListMultimap.create();
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     *
+     * @param length
+     *            how many elements in the array
+     * @param elemType
+     *            what type of element is in the array
+     */
+    public ArrayDeclaration(int length, IDeclaration elemType) {
+        fLength = length;
+        fElemType = elemType;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    @Override
+    public IDeclaration getElementType() {
+        return fElemType;
+    }
+
+    /**
+     * Get the length of the array
+     *
+     * @return the length of the array
+     */
+    public int getLength() {
+        return fLength;
+    }
+
+    /**
+     * Sometimes, strings are encoded as an array of 1-byte integers (each one
+     * being an UTF-8 byte).
+     *
+     * @return true if this array is in fact an UTF-8 string. false if it's a
+     *         "normal" array of generic Definition's.
+     */
+    public boolean isString() {
+        if (fElemType instanceof IntegerDeclaration) {
+            /*
+             * If the first byte is a "character", we'll consider the whole
+             * array a character string.
+             */
+            IntegerDeclaration elemInt = (IntegerDeclaration) fElemType;
+            if (elemInt.isCharacter()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public long getAlignment() {
+        return getElementType().getAlignment();
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    public AbstractArrayDefinition createDefinition(IDefinitionScope definitionScope,
+            @NonNull String fieldName, BitBuffer input) throws CTFReaderException {
+        alignRead(input);
+        if (isString()) {
+            byte[] data = new byte[fLength];
+            input.get(data);
+            return new ByteArrayDefinition(this, definitionScope, fieldName, data);
+        }
+        List<Definition> definitions = read(input, definitionScope, fieldName);
+        return new ArrayDefinition(this, definitionScope, fieldName, definitions);
+    }
+
+    @Override
+    public String toString() {
+        /* Only used for debugging */
+        return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
+    }
+
+    @NonNull
+    private List<Definition> read(@NonNull BitBuffer input, IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
+        Builder<Definition> definitions = new ImmutableList.Builder<>();
+        if (!fChildrenNames.containsKey(fieldName)) {
+            for (int i = 0; i < fLength; i++) {
+                fChildrenNames.put(fieldName, fieldName + '[' + i + ']');
+            }
+        }
+        List<String> elemNames = fChildrenNames.get(fieldName);
+        for (int i = 0; i < fLength; i++) {
+            String name = elemNames.get(i);
+            if (name == null) {
+                throw new IllegalStateException();
+            }
+            definitions.add(fElemType.createDefinition(definitionScope, name, input));
+        }
+        @SuppressWarnings("null")
+        @NonNull ImmutableList<Definition> ret = definitions.build();
+        return ret;
+    }
+
+    @Override
+    public int getMaximumSize() {
+        long val = (long) fLength * fElemType.getMaximumSize();
+        return (int) Math.min(Integer.MAX_VALUE, val);
+    }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDefinition.java
new file mode 100644 (file)
index 0000000..c6d4832
--- /dev/null
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * A CTF array definition
+ *
+ * Arrays are fixed-length. Their length is declared in the type declaration
+ * within the meta-data. They contain an array of "inner type" elements, which
+ * can refer to any type not containing the type of the array being declared (no
+ * circular dependency). The length is the number of elements in an array.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public final class ArrayDefinition extends AbstractArrayDefinition {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final ImmutableList<Definition> fDefinitions;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     *
+     * @param declaration
+     *            the parent declaration
+     * @param definitionScope
+     *            the parent scope
+     * @param fieldName
+     *            the field name
+     * @param definitions
+     *            the content of the array
+     */
+    public ArrayDefinition(CompoundDeclaration declaration,
+            @Nullable IDefinitionScope definitionScope,
+            String fieldName,
+            List<Definition> definitions) {
+        super(declaration, definitionScope, fieldName);
+        @SuppressWarnings("null")
+        @NonNull ImmutableList<Definition> list = ImmutableList.copyOf(definitions);
+        fDefinitions = list;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    @Override
+    public List<Definition> getDefinitions() {
+        return fDefinitions;
+    }
+
+    /**
+     * Get the the number of elements in the array
+     *
+     * @return how many elements in the array
+     */
+    public int getLength() {
+        return fDefinitions.size();
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String toString() {
+        StringBuilder b = new StringBuilder();
+        b.append('[');
+        Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
+        b.append(joiner.join(fDefinitions));
+        b.append(']');
+        @SuppressWarnings("null")
+        @NonNull String ret = b.toString();
+        return ret;
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ByteArrayDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ByteArrayDefinition.java
new file mode 100644 (file)
index 0000000..ddda448
--- /dev/null
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * A fixed length string definition
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public final class ByteArrayDefinition extends AbstractArrayDefinition {
+
+    private final byte[] fContent;
+    private transient @Nullable List<Definition> fDefs;
+
+    /**
+     * An fixed length string declaration, it's created by sequence or array
+     * defintions
+     *
+     * @param declaration
+     *            the declaration
+     * @param definitionScope
+     *            the definition scope
+     * @param fieldName
+     *            the field name
+     * @param content
+     *            the string content
+     */
+    public ByteArrayDefinition(CompoundDeclaration declaration,
+            @Nullable IDefinitionScope definitionScope,
+            String fieldName,
+            byte[] content) {
+        super(declaration, definitionScope, fieldName);
+        fContent = content;
+
+    }
+
+    @Override
+    public synchronized List<Definition> getDefinitions() {
+        List<Definition> defs = fDefs;
+        if (defs == null) {
+            ImmutableList.Builder<Definition> builder = new ImmutableList.Builder<>();
+            for (int i = 0; i < fContent.length; i++) {
+                IntegerDeclaration charDecl = IntegerDeclaration.UINT_8_DECL;
+                String fieldName = getFieldName() + '[' + i + ']';
+                byte fieldValue = fContent[i];
+                builder.add(new IntegerDefinition(charDecl, getDefinitionScope(), fieldName, fieldValue));
+            }
+            @SuppressWarnings("null")
+            @NonNull List<Definition> ret = builder.build();
+            fDefs = ret;
+            return ret;
+        }
+
+        return defs;
+    }
+
+    @Override
+    public String toString() {
+        /*
+         * the string is a byte array and may contain more than the string plus
+         * a null char, this will truncate it back to a null char
+         */
+        int pos = -1;
+        for (int i = 0; i < fContent.length; i++) {
+            if (fContent[i] == 0) {
+                pos = i;
+                break;
+            }
+        }
+        byte[] bytes = (pos != -1) ? (Arrays.copyOf(fContent, pos)) : fContent;
+        return new String(bytes);
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java
new file mode 100644 (file)
index 0000000..b7289d4
--- /dev/null
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson, Ecole Polytechnique de Montreal 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: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.Multimap;
+
+/**
+ * A CTF sequence declaration.
+ *
+ * An array where the size is fixed but declared in the trace, unlike array
+ * where it is declared with a literal
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public class SequenceDeclaration extends CompoundDeclaration {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final IDeclaration fElemType;
+    private final String fLengthName;
+    private final Multimap<String, String> fPaths = ArrayListMultimap.create();
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     *
+     * @param lengthName
+     *            the name of the field describing the length
+     * @param elemType
+     *            The element type
+     */
+    public SequenceDeclaration(String lengthName, IDeclaration elemType) {
+        fElemType = elemType;
+        fLengthName = lengthName;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    @Override
+    public IDeclaration getElementType() {
+        return fElemType;
+    }
+
+    /**
+     * Gets the name of the length field
+     *
+     * @return the name of the length field
+     */
+    public String getLengthName() {
+        return fLengthName;
+    }
+
+    @Override
+    public long getAlignment() {
+        return getElementType().getAlignment();
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Is the Sequence a string?
+     *
+     * @return true, if the elements are chars, false otherwise
+     */
+    public boolean isString() {
+        IntegerDeclaration elemInt;
+        IDeclaration elementType = getElementType();
+        if (elementType instanceof IntegerDeclaration) {
+            elemInt = (IntegerDeclaration) elementType;
+            if (elemInt.isCharacter()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public AbstractArrayDefinition createDefinition(
+            IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException {
+        Definition lenDef = null;
+
+        if (definitionScope != null) {
+            lenDef = definitionScope.lookupDefinition(getLengthName());
+        }
+
+        if (lenDef == null) {
+            throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$
+        }
+
+        if (!(lenDef instanceof IntegerDefinition)) {
+            throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$
+        }
+
+        IntegerDefinition lengthDefinition = (IntegerDefinition) lenDef;
+
+        if (lengthDefinition.getDeclaration().isSigned()) {
+            throw new CTFReaderException("Sequence length must not be signed"); //$NON-NLS-1$
+        }
+
+        long length = lengthDefinition.getValue();
+        if ((length > Integer.MAX_VALUE) || (!input.canRead((int) length * fElemType.getMaximumSize()))) {
+            throw new CTFReaderException("Sequence length too long " + length); //$NON-NLS-1$
+        }
+
+        if (isString()) {
+            // Don't create "useless" definitions
+            byte[] data = new byte[(int) length];
+            input.get(data);
+            return new ByteArrayDefinition(this, definitionScope, fieldName, data);
+        }
+        Collection<String> collection = fPaths.get(fieldName);
+        while (collection.size() < length) {
+            fPaths.put(fieldName, fieldName + '[' + collection.size() + ']');
+        }
+        List<String> paths = (List<String>) fPaths.get(fieldName);
+        Builder<Definition> definitions = new ImmutableList.Builder<>();
+        for (int i = 0; i < length; i++) {
+            @SuppressWarnings("null")
+            @NonNull String elemName = paths.get(i);
+            definitions.add(fElemType.createDefinition(definitionScope, elemName, input));
+        }
+        @SuppressWarnings("null")
+        @NonNull ImmutableList<Definition> build = definitions.build();
+        return new ArrayDefinition(this, definitionScope, fieldName, build);
+    }
+
+    @Override
+    public String toString() {
+        /* Only used for debugging */
+        return "[declaration] sequence[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
+    }
+
+    @Override
+    public int getMaximumSize() {
+        return Integer.MAX_VALUE;
+    }
+
+}
\ No newline at end of file
index cbece6b4035f84e258c546c8fe495c42cbac6394..2ae1c5384c91c5167df84a9eb713f0aa61efaf4a 100644 (file)
@@ -22,18 +22,18 @@ import java.nio.ByteOrder;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEventField;
 import org.junit.Before;
 import org.junit.Test;
@@ -190,7 +190,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_float() {
-        Definition fieldDef = fixture.lookupArray(ARRAY_FLOAT);
+        Definition fieldDef = fixture.lookupArray2(ARRAY_FLOAT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[2.0, 2.0]", result.toString());
     }
@@ -211,7 +211,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_int() {
-        Definition fieldDef = fixture.lookupArray(ARRAY_INT);
+        Definition fieldDef = fixture.lookupArray2(ARRAY_INT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[2, 2]", result.toString());
     }
@@ -254,7 +254,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_string() {
-        Definition fieldDef = fixture.lookupArray(ARRAY_STR);
+        Definition fieldDef = fixture.lookupArray2(ARRAY_STR);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[two, two]", result.toString());
     }
@@ -275,7 +275,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_struct() {
-        Definition fieldDef = fixture.lookupArray(ARRAY_STRUCT);
+        Definition fieldDef = fixture.lookupArray2(ARRAY_STRUCT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[[str=two, int=2], [str=two, int=2]]", result.toString());
     }
@@ -296,7 +296,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_enum() {
-        Definition fieldDef = fixture.lookupArray(ARRAY_ENUM);
+        Definition fieldDef = fixture.lookupArray2(ARRAY_ENUM);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[float, float]", result.toString());
     }
@@ -317,7 +317,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_variant() {
-        Definition fieldDef = fixture.lookupArray(ARRAY_VARIANT);
+        Definition fieldDef = fixture.lookupArray2(ARRAY_VARIANT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[float=2.0, float=2.0]", result.toString());
     }
index 4fa6b557ba9c4e6fd762d3996e216dd86c71fc31..858a02921cc7bc74eb4538a3ec25c545ce17391a 100644 (file)
@@ -19,19 +19,21 @@ package org.eclipse.linuxtools.tmf.ctf.core;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ByteArrayDefinition;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
 
@@ -103,47 +105,46 @@ public abstract class CtfTmfEventField extends TmfEventField {
 
         } else if (fieldDef instanceof ArrayDefinition) {
             ArrayDefinition arrayDef = (ArrayDefinition) fieldDef;
-
-            if (arrayDef.getDeclaration().isString()) {
-                /* This is an array of UTF-8 bytes, a.k.a. a String! */
-                field = new CTFStringField(fieldName, fieldDef.toString());
+            IDeclaration decl = arrayDef.getDeclaration();
+            if (!(decl instanceof CompoundDeclaration)) {
+                throw new IllegalArgumentException("Array definitions should only come from sequence or array declarations"); //$NON-NLS-1$
+            }
+            CompoundDeclaration arrDecl = (CompoundDeclaration) decl;
+            IDeclaration elemType = null;
+            Collection<Definition> definitions = arrayDef.getDefinitions();
+            elemType = arrDecl.getElementType();
+            if (elemType instanceof IntegerDeclaration) {
+                /* Array of integers => CTFIntegerArrayField */
+                IntegerDeclaration elemIntType = (IntegerDeclaration) elemType;
+                long[] values = new long[arrayDef.getLength()];
+                for (int i = 0; i < arrayDef.getLength(); i++) {
+                    Definition elem = arrayDef.getDefinitions().get(i);
+                    if (elem == null) {
+                        break;
+                    }
+                    values[i] = ((IntegerDefinition) elem).getValue();
+                }
+                field = new CTFIntegerArrayField(fieldName, values,
+                        elemIntType.getBase(),
+                        elemIntType.isSigned());
 
             } else {
                 /* Arrays of elements of any other type */
-                List<Definition> definitions = arrayDef.getDefinitions();
-                CtfTmfEventField[] elements = new CtfTmfEventField[definitions.size()];
-
+                CtfTmfEventField[] elements = new CtfTmfEventField[arrayDef.getLength()];
                 /* Parse the elements of the array. */
-                for (int i = 0; i < definitions.size(); i++) {
+                int i = 0;
+                for (Definition definition : definitions) {
                     CtfTmfEventField curField = CtfTmfEventField.parseField(
-                            definitions.get(i), fieldName + '[' + i + ']');
+                            definition, fieldName + '[' + i + ']');
                     elements[i] = curField;
+                    i++;
                 }
 
                 field = new CTFArrayField(fieldName, elements);
             }
-        } else if (fieldDef instanceof SequenceDefinition) {
-            SequenceDefinition seqDef = (SequenceDefinition) fieldDef;
-            SequenceDeclaration seqDecl = seqDef.getDeclaration();
-
-            if (seqDef.getLength() == 0) {
-                /* Some sequences have length = 0. Simply use an empty string */
-                field = new CTFStringField(fieldName, ""); //$NON-NLS-1$
-            } else if (seqDecl.isString()) {
-                /* Interpret this sequence as a String */
-                field = new CTFStringField(fieldName, seqDef.toString());
-            } else if (seqDecl.getElementType() instanceof IntegerDeclaration) {
-                /* Sequence of integers => CTFIntegerArrayField */
-                long[] values = new long[seqDef.getLength()];
-                for (int i = 0; i < seqDef.getLength(); i++) {
-                    values[i] = ((IntegerDefinition) seqDef.getElem(i)).getValue();
-                }
-                field = new CTFIntegerArrayField(fieldName, values,
-                        ((IntegerDeclaration) seqDecl.getElementType()).getBase(),
-                        ((IntegerDeclaration) seqDecl.getElementType()).isSigned());
-
-            }
-            /* Add other Sequence types here */
+        } else if (fieldDef instanceof ByteArrayDefinition) {
+            /* This is an array of ascii bytes, a.k.a. a String! */
+            field = new CTFStringField(fieldName, fieldDef.toString());
 
         } else if (fieldDef instanceof StructDefinition) {
             StructDefinition strDef = (StructDefinition) fieldDef;
This page took 0.057862 seconds and 5 git commands to generate.