Fix issues with CTF parser.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 24 Jul 2012 21:59:38 +0000 (17:59 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 25 Jul 2012 14:08:17 +0000 (10:08 -0400)
* When an enum is declared in a different scope than it is defined in.
* When there is no stream ID the trace does not generate NPEs.
* When there is no clock offset, a 0 offset is created. (not often)

Change-Id: Ie0e0e09168aa2d91ac52d49e94bc10e1e9ba691f
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/6949
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
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/StreamInputReader.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/trace/Stream.java

index 42e596a0b9237930b50301f4a1d41867e287751d..eac8cb87fbc9236d1cbfa50ec1f5627ec209da17 100644 (file)
@@ -64,6 +64,10 @@ public class CTFTrace implements IDefinitionScope {
     // Attributes
     // ------------------------------------------------------------------------
 
+    private static final String OFFSET = "offset"; //$NON-NLS-1$
+
+
+
     /*
      * (non-Javadoc)
      *
@@ -695,7 +699,11 @@ public class CTFTrace implements IDefinitionScope {
         if (clocks.size() == 1) {
             if (singleClock == null) {
                 singleClock = clocks.get(clocks.keySet().toArray()[0]);
-                singleOffset = (Long) getClock().getProperty("offset"); //$NON-NLS-1$
+                if (singleClock.getProperty(OFFSET) != null) {
+                    singleOffset = (Long) getClock().getProperty(OFFSET);
+                } else {
+                    singleClock.addAttribute(OFFSET, 0);
+                }
             }
             return singleClock;
         }
index 5f712312379c93d9550f283b23279423716fc9dd..6fb5ebb58d68791a2ce88030efa350cbc218def8 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntr
 
 /**
  * A CTF trace event reader. Reads the events of a trace file.
- * 
+ *
  * @version 1.0
  * @author Matthew Khouzam
  * @author Simon Marchi
@@ -184,7 +184,7 @@ public class StreamInputReader {
             }
         }
 
-        /*autogenerate javadoc getter setter
+        /*
          * If an event is available, read it.
          */
         if (this.packetReader.hasMoreEvents()) {
index 936a34e0236e1795e4109652bdb410ae1be4ca9a..a84a467d20d879f6bf65ecbb7e26d95ecbd9d2e6 100644 (file)
@@ -224,10 +224,8 @@ public class IOStructGen {
             for (CommonTree event : events) {
                 parseEvent(event);
                 if (DEBUG_) {
-                    CommonTree name = (CommonTree) event.getChild(0).getChild(1)
-                            .getChild(0).getChild(0);
-                    CommonTree id = (CommonTree) event.getChild(1).getChild(1)
-                            .getChild(0).getChild(0);
+                    CommonTree name = (CommonTree) event.getChild(0).getChild(1).getChild(0).getChild(0);
+                    CommonTree id = (CommonTree) event.getChild(1).getChild(1).getChild(0).getChild(0);
                     out.write("Name = " + name + " Id = " + id + '\n'); //$NON-NLS-1$ //$NON-NLS-2$
                 }
             }
@@ -265,20 +263,19 @@ public class IOStructGen {
             case CTFParser.INTEGER:
             case CTFParser.DECIMAL_LITERAL:
                 /*
-                 * Not a pretty hack, this is to make sure that there is no number
-                 * overflow due to 63 bit integers. The offset should only really
-                 * be an issue in the year 2262. the tracer in C/ASM can write an offset in
-                 * an unsigned 64 bit long. In java, the last bit, being set to 1 will
-                 * be read as a negative number, but since it is too big a positive it will
-                 * throw an exception. this will happen in 2^63 ns from 1970.
-                 * Therefore 293 years from 1970
+                 * Not a pretty hack, this is to make sure that there is no
+                 * number overflow due to 63 bit integers. The offset should
+                 * only really be an issue in the year 2262. the tracer in C/ASM
+                 * can write an offset in an unsigned 64 bit long. In java, the
+                 * last bit, being set to 1 will be read as a negative number,
+                 * but since it is too big a positive it will throw an
+                 * exception. this will happen in 2^63 ns from 1970. Therefore
+                 * 293 years from 1970
                  */
                 Long numValue;
-                try{
+                try {
                     numValue = Long.parseLong(value.getText());
-                }
-                catch( Exception e)
-                {
+                } catch (Exception e) {
                     numValue = 1330938566783103277L;
                 }
                 ctfClock.addAttribute(key, numValue);
@@ -721,15 +718,13 @@ public class IOStructGen {
                 throw new ParseException("fields expects a struct"); //$NON-NLS-1$
             }
             /*
-             * The underscores in the event names.
-             * These underscores were added by the LTTng tracer.
+             * The underscores in the event names. These underscores were added
+             * by the LTTng tracer.
              */
             final StructDeclaration fields = (StructDeclaration) fieldsDecl;
             event.setFields(fields);
-        }
-        else if (left.equals(CTFStrings.LOGLEVEL2)){
-
-            long logLevel = parseUnaryInteger((CommonTree) rightNode.getChild(0)) ;
+        } else if (left.equals(CTFStrings.LOGLEVEL2)) {
+            long logLevel = parseUnaryInteger((CommonTree) rightNode.getChild(0));
             event.setLogLevel(logLevel);
         } else {
             throw new ParseException("Unknown event attribute : " + left); //$NON-NLS-1$
@@ -1073,7 +1068,7 @@ public class IOStructGen {
          * sequence. For example, int a[3][len] means that we have an array of 3
          * (sequences of length 'len' of (int)).
          */
-        if (lengths.size() > 0 ) {
+        if (lengths.size() > 0) {
             /* We begin at the end */
             Collections.reverse(lengths);
 
@@ -1142,9 +1137,6 @@ public class IOStructGen {
 
         switch (firstChild.getType()) {
         case CTFParser.FLOATING_POINT:
-//            Activator
-//                    .getDefault()
-//                    .log("parseTypeSpecifierList: floating_point not implemented yet"); //$NON-NLS-1$
             declaration = parseFloat(firstChild);
             break;
         case CTFParser.INTEGER:
@@ -1181,12 +1173,11 @@ public class IOStructGen {
             childTypeError(firstChild);
         }
 
-        assert (declaration != null);
         return declaration;
     }
 
-    private IDeclaration parseFloat(CommonTree floatingPoint) throws ParseException {
-        assert (floatingPoint.getType() == CTFParser.INTEGER);
+    private IDeclaration parseFloat(CommonTree floatingPoint)
+            throws ParseException {
 
         List<CommonTree> children = floatingPoint.getChildren();
 
@@ -1212,15 +1203,11 @@ public class IOStructGen {
                 /*
                  * An assignment expression must have 2 children, left and right
                  */
-                assert (child.getChildCount() == 2);
 
                 CommonTree leftNode = (CommonTree) child.getChild(0);
-                assert (leftNode.getType() == CTFParser.CTF_LEFT);
                 CommonTree rightNode = (CommonTree) child.getChild(1);
-                assert (rightNode.getType() == CTFParser.CTF_RIGHT);
 
                 List<CommonTree> leftStrings = leftNode.getChildren();
-                assert (leftStrings != null);
 
                 if (!isUnaryString(leftStrings.get(0))) {
                     throw new ParseException(
@@ -1367,7 +1354,8 @@ public class IOStructGen {
                 } else if (left.equals("map")) { //$NON-NLS-1$
                     clock = getClock(rightNode);
                 } else {
-                    throw new ParseException("Integer: unknown attribute " + left); //$NON-NLS-1$
+                    throw new ParseException(
+                            "Integer: unknown attribute " + left); //$NON-NLS-1$
                 }
 
                 break;
@@ -1747,6 +1735,17 @@ public class IOStructGen {
          * is "int".
          */
         if (containerTypeDeclaration == null) {
+            IDeclaration enumDecl;
+            /*
+             * it could be because the enum was already declared.
+             */
+            if (enumName != null) {
+                enumDecl = getCurrentScope().rlookupEnum(enumName);
+                if (enumDecl != null) {
+                    return (EnumDeclaration) enumDecl;
+                }
+            }
+
             IDeclaration decl = getCurrentScope().rlookupType("int"); //$NON-NLS-1$
 
             if (decl == null) {
@@ -2457,9 +2456,11 @@ public class IOStructGen {
         if (isUnaryString(firstChild)) {
             String strval = concatenateUnaryStrings(rightNode.getChildren());
 
-            if (strval.equals(CTFStrings.TRUE) || strval.equals(CTFStrings.TRUE2)) {
+            if (strval.equals(CTFStrings.TRUE)
+                    || strval.equals(CTFStrings.TRUE2)) {
                 ret = true;
-            } else if (strval.equals(CTFStrings.FALSE) || strval.equals(CTFStrings.FALSE2)) {
+            } else if (strval.equals(CTFStrings.FALSE)
+                    || strval.equals(CTFStrings.FALSE2)) {
                 ret = false;
             } else {
                 throw new ParseException("Invalid boolean value " //$NON-NLS-1$
@@ -2507,7 +2508,8 @@ public class IOStructGen {
 
             if (strval.equals(CTFStrings.LE)) {
                 return ByteOrder.LITTLE_ENDIAN;
-            } else if (strval.equals(CTFStrings.BE) || strval.equals(CTFStrings.NETWORK)) {
+            } else if (strval.equals(CTFStrings.BE)
+                    || strval.equals(CTFStrings.NETWORK)) {
                 return ByteOrder.BIG_ENDIAN;
             } else if (strval.equals(CTFStrings.NATIVE)) {
                 return trace.getByteOrder();
@@ -2621,18 +2623,24 @@ public class IOStructGen {
         } else if (isUnaryString(firstChild)) {
             String strval = concatenateUnaryStrings(rightNode.getChildren());
 
-            if (strval.equals(CTFStrings.DECIMAL) || strval.equals(CTFStrings.DEC)
-                    || strval.equals(CTFStrings.DEC_CTE) || strval.equals(CTFStrings.INT_MOD)
+            if (strval.equals(CTFStrings.DECIMAL)
+                    || strval.equals(CTFStrings.DEC)
+                    || strval.equals(CTFStrings.DEC_CTE)
+                    || strval.equals(CTFStrings.INT_MOD)
                     || strval.equals(CTFStrings.UNSIGNED_CTE)) {
                 return 10;
-            } else if (strval.equals(CTFStrings.HEXADECIMAL) || strval.equals(CTFStrings.HEX)
-                    || strval.equals(CTFStrings.X) || strval.equals(CTFStrings.X2)
+            } else if (strval.equals(CTFStrings.HEXADECIMAL)
+                    || strval.equals(CTFStrings.HEX)
+                    || strval.equals(CTFStrings.X)
+                    || strval.equals(CTFStrings.X2)
                     || strval.equals(CTFStrings.POINTER)) {
                 return 16;
-            } else if (strval.equals(CTFStrings.OCTAL) || strval.equals(CTFStrings.OCT)
+            } else if (strval.equals(CTFStrings.OCTAL)
+                    || strval.equals(CTFStrings.OCT)
                     || strval.equals(CTFStrings.OCTAL_CTE)) {
                 return 8;
-            } else if (strval.equals(CTFStrings.BINARY) || strval.equals(CTFStrings.BIN)) {
+            } else if (strval.equals(CTFStrings.BINARY)
+                    || strval.equals(CTFStrings.BIN)) {
                 return 2;
             } else {
                 throw new ParseException("Invalid value for base"); //$NON-NLS-1$
index b3c64dfd88bb10babc75aa88f56303310f6bc6ca..bd9234159c46ce234a82bbb7f51d23f873d69789 100644 (file)
@@ -53,7 +53,7 @@ public class Stream {
     /**
      * Maps event ids to events
      */
-    private HashMap<Long, EventDeclaration> events;
+    private HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
 
     /**
      * The inputs associated to this stream
This page took 0.033326 seconds and 5 git commands to generate.