ctf: better enum and variant verification
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / event / metadata / IOStructGen.java
index 936a34e0236e1795e4109652bdb410ae1be4ca9a..195ac07ce05f2d2004571e00149cf7c733223b7a 100644 (file)
@@ -1,13 +1,15 @@
 /*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ * Copyright (c) 2011, 2013 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 Design and Grammar
- * Contributors: Francis Giraldeau - Initial API and implementation
+ * Contributors:
+ *     Matthew Khouzam - Initial Design and Grammar
+ *     Francis Giraldeau - Initial API and implementation
+ *     Simon Marchi - Initial API and implementation
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.ctf.core.event.metadata;
@@ -15,16 +17,19 @@ package org.eclipse.linuxtools.internal.ctf.core.event.metadata;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
 import java.nio.ByteOrder;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import org.antlr.runtime.tree.CommonTree;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
 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;
@@ -36,18 +41,12 @@ 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.Stream;
 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.trace.Stream;
 
-/*
- * Asserts throughout this class denote the assumptions we can make because of
- * the way the grammar generates the AST.
- *
- * There is also an assert at the beginning of each function that receives a
- * tree node to make sure that the node is indeed of the type the function is
- * expecting.
- */
 /**
  * IOStructGen
  */
@@ -57,7 +56,7 @@ public class IOStructGen {
     // Attributes
     // ------------------------------------------------------------------------
 
-    static private final boolean DEBUG_ = false;
+    private static final boolean DEBUG = false;
 
     /**
      * The trace
@@ -75,7 +74,7 @@ public class IOStructGen {
     // ------------------------------------------------------------------------
 
     /**
-     * Constuctor
+     * Constructor
      *
      * @param tree
      *            the tree (ANTLR generated) with the parsed TSDL data.
@@ -109,13 +108,11 @@ public class IOStructGen {
      * @throws ParseException
      */
     private void parseRoot(CommonTree root) throws ParseException {
-        assert (root.getType() == CTFParser.ROOT);
 
         List<CommonTree> children = root.getChildren();
-        assert (children != null);
         java.io.FileOutputStream fos = null;
         java.io.OutputStreamWriter out = null;
-        if (DEBUG_) {
+        if (DEBUG) {
             try {
                 fos = new java.io.FileOutputStream("/tmp/astInfo.txt"); //$NON-NLS-1$
                 out = new java.io.OutputStreamWriter(fos, "UTF-8"); //$NON-NLS-1$
@@ -134,23 +131,24 @@ public class IOStructGen {
         List<CommonTree> declarations = new ArrayList<CommonTree>();
         List<CommonTree> environments = new ArrayList<CommonTree>();
         List<CommonTree> clocks = new ArrayList<CommonTree>();
+        List<CommonTree> callsites = new ArrayList<CommonTree>();
         /* Create a new declaration scope with no parent. */
         pushScope();
 
         try {
             for (CommonTree child : children) {
-                if (DEBUG_) {
+                final int type = child.getType();
+                if (DEBUG) {
                     out.write(child.toString()
-                            + " -> " + child.getType() + '\n'); //$NON-NLS-1$
+                            + " -> " + type + '\n'); //$NON-NLS-1$
                 }
-                switch (child.getType()) {
+                switch (type) {
                 case CTFParser.DECLARATION:
                     declarations.add(child);
                     break;
                 case CTFParser.TRACE:
                     if (traceNode != null) {
-                        throw new ParseException(
-                                "Only one trace block is allowed"); //$NON-NLS-1$
+                        throw new ParseException("Only one trace block is allowed"); //$NON-NLS-1$
                     }
                     traceNode = child;
                     break;
@@ -166,45 +164,53 @@ public class IOStructGen {
                 case CTFParser.ENV:
                     environments.add(child);
                     break;
+                case CTFParser.CALLSITE:
+                    callsites.add(child);
+                    break;
                 default:
                     childTypeError(child);
                 }
             }
+            if (DEBUG) {
+                out.write("Declarations\n"); //$NON-NLS-1$
+            }
+            for (CommonTree decl : declarations) {
+                if (DEBUG) {
+                    out.write(decl.toString() + '\n');
+                }
+                parseRootDeclaration(decl);
+            }
+            if (traceNode == null) {
+                throw new ParseException("Missing trace block"); //$NON-NLS-1$
+            }
 
-            if (DEBUG_) {
+            parseTrace(traceNode);
+
+            if (DEBUG) {
                 out.write("Environments\n"); //$NON-NLS-1$
             }
             for (CommonTree environment : environments) {
                 parseEnvironment(environment);
             }
-            if (DEBUG_) {
+            if (DEBUG) {
                 out.write("Clocks\n"); //$NON-NLS-1$
             }
             for (CommonTree clock : clocks) {
                 parseClock(clock);
             }
-            if (DEBUG_) {
-                out.write("Declarations\n"); //$NON-NLS-1$
-            }
-            for (CommonTree decl : declarations) {
-                if (DEBUG_) {
-                    out.write(decl.toString() + '\n');
-                }
-                parseRootDeclaration(decl);
+            if (DEBUG) {
+                out.write("Callsites\n"); //$NON-NLS-1$
             }
-
-            if (traceNode == null) {
-                throw new ParseException("Missing trace block"); //$NON-NLS-1$
+            for (CommonTree callsite : callsites) {
+                parseCallsite(callsite);
             }
 
-            parseTrace(traceNode);
-
-            if (DEBUG_) {
+            if (DEBUG) {
                 out.write("Streams\n"); //$NON-NLS-1$
             }
             if (streams.size() > 0) {
                 for (CommonTree stream : streams) {
-                    if (DEBUG_) {
+                    if (DEBUG) {
                         try {
                             out.write(stream.toString() + '\n');
                         } catch (IOException e) {
@@ -218,21 +224,19 @@ public class IOStructGen {
                 trace.addStream(new Stream(trace));
             }
 
-            if (DEBUG_) {
+            if (DEBUG) {
                 out.write("Events\n"); //$NON-NLS-1$
             }
             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);
+                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);
                     out.write("Name = " + name + " Id = " + id + '\n'); //$NON-NLS-1$ //$NON-NLS-2$
                 }
             }
 
-            if (DEBUG_) {
+            if (DEBUG) {
                 out.close();
                 fos.close();
             }
@@ -242,6 +246,41 @@ public class IOStructGen {
         popScope();
     }
 
+    private void parseCallsite(CommonTree callsite) {
+
+        List<CommonTree> children = callsite.getChildren();
+        String name = null;
+        String funcName = null;
+        long lineNumber = -1;
+        long ip = -1;
+        String fileName = null;
+
+        for (CommonTree child : children) {
+            String left;
+            /* this is a regex to find the leading and trailing quotes */
+            final String regex = "^\"|\"$"; //$NON-NLS-1$
+            /*
+             * this is to replace the previous quotes with nothing...
+             * effectively deleting them
+             */
+            final String nullString = ""; //$NON-NLS-1$
+            left = child.getChild(0).getChild(0).getChild(0).getText();
+            if (left.equals("name")) { //$NON-NLS-1$
+                name = child.getChild(1).getChild(0).getChild(0).getText().replaceAll(regex, nullString);
+            } else if (left.equals("func")) { //$NON-NLS-1$
+                funcName = child.getChild(1).getChild(0).getChild(0).getText().replaceAll(regex, nullString);
+            } else if (left.equals("ip")) { //$NON-NLS-1$
+                /* trim the 0x */
+                ip = Long.parseLong(child.getChild(1).getChild(0).getChild(0).getText().substring(2), 16);
+            } else if (left.equals("file")) { //$NON-NLS-1$
+                fileName = child.getChild(1).getChild(0).getChild(0).getText().replaceAll(regex, nullString);
+            } else if (left.equals("line")) { //$NON-NLS-1$
+                lineNumber = Long.parseLong(child.getChild(1).getChild(0).getChild(0).getText());
+            }
+        }
+        trace.addCallsite(name, funcName, ip, fileName, lineNumber);
+    }
+
     private void parseEnvironment(CommonTree environment) {
         List<CommonTree> children = environment.getChildren();
         for (CommonTree child : children) {
@@ -257,28 +296,26 @@ public class IOStructGen {
         List<CommonTree> children = clock.getChildren();
         CTFClock ctfClock = new CTFClock();
         for (CommonTree child : children) {
-            final String key = child.getChild(0).getChild(0).getChild(0)
-                    .getText();
+            final String key = child.getChild(0).getChild(0).getChild(0).getText();
             final CommonTree value = (CommonTree) child.getChild(1).getChild(0).getChild(0);
             final int type = value.getType();
             switch (type) {
             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);
@@ -288,12 +325,11 @@ public class IOStructGen {
             }
 
         }
-        String NameValue = ctfClock.getName();
-        trace.addClock(NameValue, ctfClock);
+        String nameValue = ctfClock.getName();
+        trace.addClock(nameValue, ctfClock);
     }
 
     private void parseTrace(CommonTree traceNode) throws ParseException {
-        assert (traceNode.getType() == CTFParser.TRACE);
 
         List<CommonTree> children = traceNode.getChildren();
         if (children == null) {
@@ -333,47 +369,40 @@ public class IOStructGen {
 
     private void parseTraceDeclaration(CommonTree traceDecl)
             throws ParseException {
-        assert ((traceDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (traceDecl
-                .getType() == CTFParser.CTF_EXPRESSION_VAL));
 
         /* There should be a left and right */
-        assert (traceDecl.getChildCount() == 2);
 
         CommonTree leftNode = (CommonTree) traceDecl.getChild(0);
-        assert (leftNode.getType() == CTFParser.CTF_LEFT);
         CommonTree rightNode = (CommonTree) traceDecl.getChild(1);
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
 
         List<CommonTree> leftStrings = leftNode.getChildren();
-        assert (leftStrings != null);
 
-        if (!isUnaryString(leftStrings.get(0))) {
-            throw new ParseException(
-                    "Left side of CTF assignment must be a string"); //$NON-NLS-1$
+        if (!isAnyUnaryString(leftStrings.get(0))) {
+            throw new ParseException("Left side of CTF assignment must be a string"); //$NON-NLS-1$
         }
 
         String left = concatenateUnaryStrings(leftStrings);
 
-        if (left.equals(CTFStrings.MAJOR)) {
-            if (trace.majortIsSet()) {
+        if (left.equals(MetadataStrings.MAJOR)) {
+            if (trace.majorIsSet()) {
                 throw new ParseException("major is already set"); //$NON-NLS-1$
             }
 
             trace.setMajor(getMajorOrMinor(rightNode));
-        } else if (left.equals(CTFStrings.MINOR)) {
+        } else if (left.equals(MetadataStrings.MINOR)) {
             if (trace.minorIsSet()) {
                 throw new ParseException("minor is already set"); //$NON-NLS-1$
             }
 
             trace.setMinor(getMajorOrMinor(rightNode));
-        } else if (left.equals(CTFStrings.UUID_STRING)) {
+        } else if (left.equals(MetadataStrings.UUID_STRING)) {
             UUID uuid = getUUID(rightNode);
 
             /*
              * If uuid was already set by a metadata packet, compare it to see
              * if it matches
              */
-            if (trace.UUIDIsSet()) {
+            if (trace.uuidIsSet()) {
                 if (trace.getUUID().compareTo(uuid) != 0) {
                     throw new ParseException("UUID mismatch. Packet says " //$NON-NLS-1$
                             + trace.getUUID() + " but metadata says " + uuid); //$NON-NLS-1$
@@ -382,7 +411,7 @@ public class IOStructGen {
                 trace.setUUID(uuid);
             }
 
-        } else if (left.equals(CTFStrings.BYTE_ORDER)) {
+        } else if (left.equals(MetadataStrings.BYTE_ORDER)) {
             ByteOrder byteOrder = getByteOrder(rightNode);
 
             /*
@@ -398,8 +427,19 @@ public class IOStructGen {
                 }
             } else {
                 trace.setByteOrder(byteOrder);
+                final DeclarationScope parentScope = scope.getParentScope();
+                String types[] = parentScope.getTypeNames();
+
+                for (String type : types) {
+                    IDeclaration d = parentScope.lookupType(type);
+                    if (d instanceof IntegerDeclaration) {
+                        addByteOrder(byteOrder, parentScope, type, (IntegerDeclaration) d);
+                    } else if (d instanceof StructDeclaration) {
+                        setAlign(parentScope, (StructDeclaration) d, byteOrder);
+                    }
+                }
             }
-        } else if (left.equals(CTFStrings.PACKET_HEADER)) {
+        } else if (left.equals(MetadataStrings.PACKET_HEADER)) {
             if (trace.packetHeaderIsSet()) {
                 throw new ParseException("packet.header already defined"); //$NON-NLS-1$
             }
@@ -407,8 +447,7 @@ public class IOStructGen {
             CommonTree typeSpecifier = (CommonTree) rightNode.getChild(0);
 
             if (typeSpecifier.getType() != CTFParser.TYPE_SPECIFIER_LIST) {
-                throw new ParseException(
-                        "packet.header expects a type specifier"); //$NON-NLS-1$
+                throw new ParseException("packet.header expects a type specifier"); //$NON-NLS-1$
             }
 
             IDeclaration packetHeaderDecl = parseTypeSpecifierList(
@@ -420,12 +459,71 @@ public class IOStructGen {
 
             trace.setPacketHeader((StructDeclaration) packetHeaderDecl);
         } else {
-            throw new ParseException("Unknown trace attribute : " + left); //$NON-NLS-1$
+            Activator.log(IStatus.WARNING, Messages.IOStructGen_UnknownTraceAttributeWarning + " " + left); //$NON-NLS-1$
+        }
+    }
+
+    private static void addByteOrder(ByteOrder byteOrder,
+            final DeclarationScope parentScope, String name,
+            IntegerDeclaration decl) throws ParseException {
+
+        if (decl.getByteOrder() == null) {
+            IntegerDeclaration newI;
+            newI = new IntegerDeclaration(decl.getLength(), decl.isSigned(),
+                    decl.getBase(), byteOrder, decl.getEncoding(),
+                    decl.getClock(), decl.getAlignment());
+            parentScope.replaceType(name, newI);
+        }
+    }
+
+    private void setAlign(DeclarationScope parentScope, StructDeclaration sd,
+            ByteOrder byteOrder) throws ParseException {
+
+        for (String s : sd.getFieldsList()) {
+            IDeclaration d = sd.getFields().get(s);
+
+            if (d instanceof StructDeclaration) {
+                setAlign(parentScope, (StructDeclaration) d, byteOrder);
+
+            } else if (d instanceof VariantDeclaration) {
+                setAlign(parentScope, (VariantDeclaration) d, byteOrder);
+
+            } else if (d instanceof IntegerDeclaration) {
+                IntegerDeclaration decl = (IntegerDeclaration) d;
+                if (decl.getByteOrder() == null) {
+                    IntegerDeclaration newI;
+                    newI = new IntegerDeclaration(decl.getLength(),
+                            decl.isSigned(), decl.getBase(), byteOrder,
+                            decl.getEncoding(), decl.getClock(),
+                            decl.getAlignment());
+                    sd.getFields().put(s, newI);
+                }
+            }
+        }
+    }
+
+    private void setAlign(DeclarationScope parentScope, VariantDeclaration vd,
+            ByteOrder byteOrder) throws ParseException {
+
+        for (String s : vd.getFields().keySet()) {
+            IDeclaration d = vd.getFields().get(s);
+
+            if (d instanceof StructDeclaration) {
+                setAlign(parentScope, (StructDeclaration) d, byteOrder);
+
+            } else if (d instanceof IntegerDeclaration) {
+                IntegerDeclaration decl = (IntegerDeclaration) d;
+                IntegerDeclaration newI;
+                newI = new IntegerDeclaration(decl.getLength(),
+                        decl.isSigned(), decl.getBase(), byteOrder,
+                        decl.getEncoding(), decl.getClock(),
+                        decl.getAlignment());
+                vd.getFields().put(s, newI);
+            }
         }
     }
 
     private void parseStream(CommonTree streamNode) throws ParseException {
-        assert (streamNode.getType() == CTFParser.STREAM);
 
         Stream stream = new Stream(trace);
 
@@ -456,9 +554,8 @@ public class IOStructGen {
 
         if (stream.isIdSet()) {
             if (!trace.packetHeaderIsSet()
-                    || !trace.getPacketHeader().hasField(CTFStrings.STREAM_ID)) {
-                throw new ParseException(
-                        "Stream has an ID, but there is no stream_id field in packet header."); //$NON-NLS-1$
+                    || !trace.getPacketHeader().hasField(MetadataStrings.STREAM_ID)) {
+                throw new ParseException("Stream has an ID, but there is no stream_id field in packet header."); //$NON-NLS-1$
             }
         }
 
@@ -469,28 +566,21 @@ public class IOStructGen {
 
     private void parseStreamDeclaration(CommonTree streamDecl, Stream stream)
             throws ParseException {
-        assert ((streamDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (streamDecl
-                .getType() == CTFParser.CTF_EXPRESSION_VAL));
 
         /* There should be a left and right */
-        assert (streamDecl.getChildCount() == 2);
 
         CommonTree leftNode = (CommonTree) streamDecl.getChild(0);
-        assert (leftNode.getType() == CTFParser.CTF_LEFT);
         CommonTree rightNode = (CommonTree) streamDecl.getChild(1);
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
 
         List<CommonTree> leftStrings = leftNode.getChildren();
-        assert (leftStrings != null);
 
-        if (!isUnaryString(leftStrings.get(0))) {
-            throw new ParseException(
-                    "Left side of CTF assignment must be a string"); //$NON-NLS-1$
+        if (!isAnyUnaryString(leftStrings.get(0))) {
+            throw new ParseException("Left side of CTF assignment must be a string"); //$NON-NLS-1$
         }
 
         String left = concatenateUnaryStrings(leftStrings);
 
-        if (left.equals(CTFStrings.ID)) {
+        if (left.equals(MetadataStrings.ID)) {
             if (stream.isIdSet()) {
                 throw new ParseException("stream id already defined"); //$NON-NLS-1$
             }
@@ -498,7 +588,7 @@ public class IOStructGen {
             long streamID = getStreamID(rightNode);
 
             stream.setId(streamID);
-        } else if (left.equals(CTFStrings.EVENT_HEADER)) {
+        } else if (left.equals(MetadataStrings.EVENT_HEADER)) {
             if (stream.isEventHeaderSet()) {
                 throw new ParseException("event.header already defined"); //$NON-NLS-1$
             }
@@ -506,8 +596,7 @@ public class IOStructGen {
             CommonTree typeSpecifier = (CommonTree) rightNode.getChild(0);
 
             if (typeSpecifier.getType() != CTFParser.TYPE_SPECIFIER_LIST) {
-                throw new ParseException(
-                        "event.header expects a type specifier"); //$NON-NLS-1$
+                throw new ParseException("event.header expects a type specifier"); //$NON-NLS-1$
             }
 
             IDeclaration eventHeaderDecl = parseTypeSpecifierList(
@@ -518,7 +607,7 @@ public class IOStructGen {
             }
 
             stream.setEventHeader((StructDeclaration) eventHeaderDecl);
-        } else if (left.equals(CTFStrings.EVENT_CONTEXT)) {
+        } else if (left.equals(MetadataStrings.EVENT_CONTEXT)) {
             if (stream.isEventContextSet()) {
                 throw new ParseException("event.context already defined"); //$NON-NLS-1$
             }
@@ -526,8 +615,7 @@ public class IOStructGen {
             CommonTree typeSpecifier = (CommonTree) rightNode.getChild(0);
 
             if (typeSpecifier.getType() != CTFParser.TYPE_SPECIFIER_LIST) {
-                throw new ParseException(
-                        "event.context expects a type specifier"); //$NON-NLS-1$
+                throw new ParseException("event.context expects a type specifier"); //$NON-NLS-1$
             }
 
             IDeclaration eventContextDecl = parseTypeSpecifierList(
@@ -538,7 +626,7 @@ public class IOStructGen {
             }
 
             stream.setEventContext((StructDeclaration) eventContextDecl);
-        } else if (left.equals(CTFStrings.PACKET_CONTEXT)) {
+        } else if (left.equals(MetadataStrings.PACKET_CONTEXT)) {
             if (stream.isPacketContextSet()) {
                 throw new ParseException("packet.context already defined"); //$NON-NLS-1$
             }
@@ -546,8 +634,7 @@ public class IOStructGen {
             CommonTree typeSpecifier = (CommonTree) rightNode.getChild(0);
 
             if (typeSpecifier.getType() != CTFParser.TYPE_SPECIFIER_LIST) {
-                throw new ParseException(
-                        "packet.context expects a type specifier"); //$NON-NLS-1$
+                throw new ParseException("packet.context expects a type specifier"); //$NON-NLS-1$
             }
 
             IDeclaration packetContextDecl = parseTypeSpecifierList(
@@ -559,12 +646,11 @@ public class IOStructGen {
 
             stream.setPacketContext((StructDeclaration) packetContextDecl);
         } else {
-            throw new ParseException("Unknown stream attribute : " + left); //$NON-NLS-1$
+            Activator.log(IStatus.WARNING, Messages.IOStructGen_UnknownStreamAttributeWarning + " " + left); //$NON-NLS-1$
         }
     }
 
     private void parseEvent(CommonTree eventNode) throws ParseException {
-        assert (eventNode.getType() == CTFParser.EVENT);
 
         List<CommonTree> children = eventNode.getChildren();
         if (children == null) {
@@ -603,8 +689,7 @@ public class IOStructGen {
          */
         if (!event.streamIsSet()) {
             if (trace.nbStreams() > 1) {
-                throw new ParseException(
-                        "Event without stream_id with more than one stream"); //$NON-NLS-1$
+                throw new ParseException("Event without stream_id with more than one stream"); //$NON-NLS-1$
             }
 
             /*
@@ -618,8 +703,7 @@ public class IOStructGen {
             if (stream != null) {
                 event.setStream(stream);
             } else {
-                throw new ParseException(
-                        "Event without stream_id, but there is no stream without id"); //$NON-NLS-1$
+                throw new ParseException("Event without stream_id, but there is no stream without id"); //$NON-NLS-1$
             }
         }
 
@@ -633,28 +717,21 @@ public class IOStructGen {
 
     private void parseEventDeclaration(CommonTree eventDecl,
             EventDeclaration event) throws ParseException {
-        assert ((eventDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (eventDecl
-                .getType() == CTFParser.CTF_EXPRESSION_VAL));
 
         /* There should be a left and right */
-        assert (eventDecl.getChildCount() == 2);
 
         CommonTree leftNode = (CommonTree) eventDecl.getChild(0);
-        assert (leftNode.getType() == CTFParser.CTF_LEFT);
         CommonTree rightNode = (CommonTree) eventDecl.getChild(1);
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
 
         List<CommonTree> leftStrings = leftNode.getChildren();
-        assert (leftStrings != null);
 
-        if (!isUnaryString(leftStrings.get(0))) {
-            throw new ParseException(
-                    "Left side of CTF assignment must be a string"); //$NON-NLS-1$
+        if (!isAnyUnaryString(leftStrings.get(0))) {
+            throw new ParseException("Left side of CTF assignment must be a string"); //$NON-NLS-1$
         }
 
         String left = concatenateUnaryStrings(leftStrings);
 
-        if (left.equals(CTFStrings.NAME2)) {
+        if (left.equals(MetadataStrings.NAME2)) {
             if (event.nameIsSet()) {
                 throw new ParseException("name already defined"); //$NON-NLS-1$
             }
@@ -662,7 +739,7 @@ public class IOStructGen {
             String name = getEventName(rightNode);
 
             event.setName(name);
-        } else if (left.equals(CTFStrings.ID)) {
+        } else if (left.equals(MetadataStrings.ID)) {
             if (event.idIsSet()) {
                 throw new ParseException("id already defined"); //$NON-NLS-1$
             }
@@ -670,7 +747,7 @@ public class IOStructGen {
             long id = getEventID(rightNode);
 
             event.setId(id);
-        } else if (left.equals(CTFStrings.STREAM_ID)) {
+        } else if (left.equals(MetadataStrings.STREAM_ID)) {
             if (event.streamIsSet()) {
                 throw new ParseException("stream id already defined"); //$NON-NLS-1$
             }
@@ -684,7 +761,7 @@ public class IOStructGen {
             }
 
             event.setStream(stream);
-        } else if (left.equals(CTFStrings.CONTEXT)) {
+        } else if (left.equals(MetadataStrings.CONTEXT)) {
             if (event.contextIsSet()) {
                 throw new ParseException("context already defined"); //$NON-NLS-1$
             }
@@ -703,7 +780,7 @@ public class IOStructGen {
             }
 
             event.setContext((StructDeclaration) contextDecl);
-        } else if (left.equals(CTFStrings.FIELDS_STRING)) {
+        } else if (left.equals(MetadataStrings.FIELDS_STRING)) {
             if (event.fieldsIsSet()) {
                 throw new ParseException("fields already defined"); //$NON-NLS-1$
             }
@@ -721,18 +798,18 @@ 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(MetadataStrings.LOGLEVEL2)) {
+            long logLevel = parseUnaryInteger((CommonTree) rightNode.getChild(0));
             event.setLogLevel(logLevel);
         } else {
-            throw new ParseException("Unknown event attribute : " + left); //$NON-NLS-1$
+            /* Custom event attribute, we'll add it to the attributes map */
+            String right = parseUnaryString((CommonTree) rightNode.getChild(0));
+            event.setCustomAttribute(left, right);
         }
     }
 
@@ -745,10 +822,8 @@ public class IOStructGen {
      */
     private void parseRootDeclaration(CommonTree declaration)
             throws ParseException {
-        assert (declaration.getType() == CTFParser.DECLARATION);
 
         List<CommonTree> children = declaration.getChildren();
-        assert (children != null);
 
         for (CommonTree child : children) {
             switch (child.getType()) {
@@ -776,10 +851,8 @@ public class IOStructGen {
      * @throws ParseException
      */
     private void parseTypealias(CommonTree typealias) throws ParseException {
-        assert (typealias.getType() == CTFParser.TYPEALIAS);
 
         List<CommonTree> children = typealias.getChildren();
-        assert (children != null);
 
         CommonTree target = null;
         CommonTree alias = null;
@@ -787,11 +860,9 @@ public class IOStructGen {
         for (CommonTree child : children) {
             switch (child.getType()) {
             case CTFParser.TYPEALIAS_TARGET:
-                assert (target == null);
                 target = child;
                 break;
             case CTFParser.TYPEALIAS_ALIAS:
-                assert (alias == null);
                 alias = child;
                 break;
             default:
@@ -800,16 +871,11 @@ public class IOStructGen {
             }
         }
 
-        assert (target != null);
-        assert (alias != null);
-
         IDeclaration targetDeclaration = parseTypealiasTarget(target);
 
-        if (targetDeclaration instanceof VariantDeclaration) {
-            if (((VariantDeclaration) targetDeclaration).isTagged()) {
-                throw new ParseException(
-                        "Typealias of untagged variant is not permitted"); //$NON-NLS-1$
-            }
+        if ((targetDeclaration instanceof VariantDeclaration)
+                && ((VariantDeclaration) targetDeclaration).isTagged()) {
+            throw new ParseException("Typealias of untagged variant is not permitted"); //$NON-NLS-1$
         }
 
         String aliasString = parseTypealiasAlias(alias);
@@ -828,10 +894,8 @@ public class IOStructGen {
      */
     private IDeclaration parseTypealiasTarget(CommonTree target)
             throws ParseException {
-        assert (target.getType() == CTFParser.TYPEALIAS_TARGET);
 
         List<CommonTree> children = target.getChildren();
-        assert (children != null);
 
         CommonTree typeSpecifierList = null;
         CommonTree typeDeclaratorList = null;
@@ -841,11 +905,9 @@ public class IOStructGen {
         for (CommonTree child : children) {
             switch (child.getType()) {
             case CTFParser.TYPE_SPECIFIER_LIST:
-                assert (typeSpecifierList == null);
                 typeSpecifierList = child;
                 break;
             case CTFParser.TYPE_DECLARATOR_LIST:
-                assert (typeDeclaratorList == null);
                 typeDeclaratorList = child;
                 break;
             default:
@@ -854,8 +916,6 @@ public class IOStructGen {
             }
         }
 
-        assert (typeSpecifierList != null);
-
         if (typeDeclaratorList != null) {
             /*
              * Only allow one declarator
@@ -865,8 +925,7 @@ public class IOStructGen {
              * types.
              */
             if (typeDeclaratorList.getChildCount() != 1) {
-                throw new ParseException(
-                        "Only one type declarator is allowed in the typealias target"); //$NON-NLS-1$
+                throw new ParseException("Only one type declarator is allowed in the typealias target"); //$NON-NLS-1$
             }
 
             typeDeclarator = (CommonTree) typeDeclaratorList.getChild(0);
@@ -902,10 +961,8 @@ public class IOStructGen {
      */
     private static String parseTypealiasAlias(CommonTree alias)
             throws ParseException {
-        assert (alias.getType() == CTFParser.TYPEALIAS_ALIAS);
 
         List<CommonTree> children = alias.getChildren();
-        assert (children != null);
 
         CommonTree typeSpecifierList = null;
         CommonTree typeDeclaratorList = null;
@@ -915,11 +972,9 @@ public class IOStructGen {
         for (CommonTree child : children) {
             switch (child.getType()) {
             case CTFParser.TYPE_SPECIFIER_LIST:
-                assert (typeSpecifierList == null);
                 typeSpecifierList = child;
                 break;
             case CTFParser.TYPE_DECLARATOR_LIST:
-                assert (typeDeclaratorList == null);
                 typeDeclaratorList = child;
                 break;
             default:
@@ -936,15 +991,12 @@ public class IOStructGen {
              * eg: "typealias uint8_t := puint8_t *, **;" is not permitted.
              */
             if (typeDeclaratorList.getChildCount() != 1) {
-                throw new ParseException(
-                        "Only one type declarator is allowed in the typealias alias"); //$NON-NLS-1$
+                throw new ParseException("Only one type declarator is allowed in the typealias alias"); //$NON-NLS-1$
             }
 
             typeDeclarator = (CommonTree) typeDeclaratorList.getChild(0);
 
-            List<CommonTree> typeDeclaratorChildren = typeDeclarator
-                    .getChildren();
-            assert (typeDeclaratorChildren != null);
+            List<CommonTree> typeDeclaratorChildren = typeDeclarator.getChildren();
 
             for (CommonTree child : typeDeclaratorChildren) {
                 switch (child.getType()) {
@@ -954,7 +1006,6 @@ public class IOStructGen {
                 case CTFParser.IDENTIFIER:
                     throw new ParseException("Identifier (" + child.getText() //$NON-NLS-1$
                             + ") not expected in the typealias target"); //$NON-NLS-1$
-                    /* break; */
                 default:
                     childTypeError(child);
                     break;
@@ -975,35 +1026,26 @@ public class IOStructGen {
      *             If there is an error creating the declaration.
      */
     private void parseTypedef(CommonTree typedef) throws ParseException {
-        assert (typedef.getType() == CTFParser.TYPEDEF);
 
-        CommonTree typeDeclaratorListNode = (CommonTree) typedef
-                .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
-        assert (typeDeclaratorListNode != null);
+        CommonTree typeDeclaratorListNode = (CommonTree) typedef.getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
 
-        CommonTree typeSpecifierListNode = (CommonTree) typedef
-                .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
-        assert (typeSpecifierListNode != null);
+        CommonTree typeSpecifierListNode = (CommonTree) typedef.getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
 
-        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode
-                .getChildren();
-        assert (typeDeclaratorList != null);
+        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode.getChildren();
 
         for (CommonTree typeDeclaratorNode : typeDeclaratorList) {
             StringBuilder identifierSB = new StringBuilder();
 
-            IDeclaration type_declaration = parseTypeDeclarator(
+            IDeclaration typeDeclaration = parseTypeDeclarator(
                     typeDeclaratorNode, typeSpecifierListNode, identifierSB);
 
-            if (type_declaration instanceof VariantDeclaration) {
-                if (((VariantDeclaration) type_declaration).isTagged()) {
-                    throw new ParseException(
-                            "Typealias of untagged variant is not permitted"); //$NON-NLS-1$
-                }
+            if ((typeDeclaration instanceof VariantDeclaration)
+                    && ((VariantDeclaration) typeDeclaration).isTagged()) {
+                throw new ParseException("Typealias of untagged variant is not permitted"); //$NON-NLS-1$
             }
 
             getCurrentScope().registerType(identifierSB.toString(),
-                    type_declaration);
+                    typeDeclaration);
         }
     }
 
@@ -1026,10 +1068,6 @@ public class IOStructGen {
     private IDeclaration parseTypeDeclarator(CommonTree typeDeclarator,
             CommonTree typeSpecifierList, StringBuilder identifierSB)
             throws ParseException {
-        if (typeDeclarator != null) {
-            assert (typeDeclarator.getType() == CTFParser.TYPE_DECLARATOR);
-        }
-        assert (typeSpecifierList.getType() == CTFParser.TYPE_SPECIFIER_LIST);
 
         IDeclaration declaration = null;
         List<CommonTree> children = null;
@@ -1040,7 +1078,6 @@ public class IOStructGen {
         /* Separate the tokens by type */
         if (typeDeclarator != null) {
             children = typeDeclarator.getChildren();
-            assert (children != null);
             for (CommonTree child : children) {
 
                 switch (child.getType()) {
@@ -1048,7 +1085,6 @@ public class IOStructGen {
                     pointers.add(child);
                     break;
                 case CTFParser.IDENTIFIER:
-                    assert (identifier == null);
                     identifier = child;
                     break;
                 case CTFParser.LENGTH:
@@ -1073,7 +1109,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);
 
@@ -1083,7 +1119,6 @@ public class IOStructGen {
                  * it is an array or a sequence.
                  */
                 List<CommonTree> lengthChildren = length.getChildren();
-                assert (lengthChildren != null);
 
                 CommonTree first = lengthChildren.get(0);
                 if (isUnaryInteger(first)) {
@@ -1096,10 +1131,14 @@ public class IOStructGen {
 
                     /* Create the array declaration. */
                     declaration = new ArrayDeclaration(arrayLength, declaration);
-                } else if (isUnaryString(first)) {
+                } else if (isAnyUnaryString(first)) {
                     /* Sequence */
                     String lengthName = concatenateUnaryStrings(lengthChildren);
 
+                    /* check that lengthName was declared */
+                    if (isSignedIntegerField(lengthName)) {
+                        throw new ParseException("Sequence declared with length that is not an unsigned integer"); //$NON-NLS-1$
+                    }
                     /* Create the sequence declaration. */
                     declaration = new SequenceDeclaration(lengthName,
                             declaration);
@@ -1116,6 +1155,15 @@ public class IOStructGen {
         return declaration;
     }
 
+    private boolean isSignedIntegerField(String lengthName) throws ParseException {
+        IDeclaration decl = getCurrentScope().lookupIdentifierRecursive(lengthName);
+        if (decl instanceof IntegerDeclaration) {
+            return ((IntegerDeclaration) decl).isSigned();
+        }
+        throw new ParseException("Is not an integer: " + lengthName); //$NON-NLS-1$
+
+    }
+
     /**
      * Parses a type specifier list and returns the corresponding declaration.
      *
@@ -1130,7 +1178,6 @@ public class IOStructGen {
      */
     private IDeclaration parseTypeSpecifierList(CommonTree typeSpecifierList,
             List<CommonTree> pointerList) throws ParseException {
-        assert (typeSpecifierList.getType() == CTFParser.TYPE_SPECIFIER_LIST);
         IDeclaration declaration = null;
 
         /*
@@ -1138,13 +1185,9 @@ public class IOStructGen {
          * determine which type it belongs to.
          */
         CommonTree firstChild = (CommonTree) typeSpecifierList.getChild(0);
-        assert (firstChild != null); /* grammar */
 
         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 +1224,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,29 +1254,24 @@ 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(
-                            "Left side of ctf expression must be a string"); //$NON-NLS-1$
+                if (!isAnyUnaryString(leftStrings.get(0))) {
+                    throw new ParseException("Left side of ctf expression must be a string"); //$NON-NLS-1$
                 }
                 String left = concatenateUnaryStrings(leftStrings);
 
-                if (left.equals(CTFStrings.EXP_DIG)) {
+                if (left.equals(MetadataStrings.EXP_DIG)) {
                     exponent = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0));
-                } else if (left.equals(CTFStrings.BYTE_ORDER)) {
+                } else if (left.equals(MetadataStrings.BYTE_ORDER)) {
                     byteOrder = getByteOrder(rightNode);
-                } else if (left.equals(CTFStrings.MANT_DIG)) {
+                } else if (left.equals(MetadataStrings.MANT_DIG)) {
                     mantissa = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0));
-                } else if (left.equals(CTFStrings.ALIGN)) {
+                } else if (left.equals(MetadataStrings.ALIGN)) {
                     alignment = getAlignment(rightNode);
                 } else {
                     throw new ParseException("Float: unknown attribute " + left); //$NON-NLS-1$
@@ -1261,7 +1298,6 @@ public class IOStructGen {
 
         floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, alignment);
 
-        assert (floatDeclaration != null);
         return floatDeclaration;
 
     }
@@ -1285,7 +1321,7 @@ public class IOStructGen {
                 typeSpecifierList, pointerList);
 
         /* Use the string representation to search the type in the current scope */
-        IDeclaration decl = getCurrentScope().rlookupType(
+        IDeclaration decl = getCurrentScope().lookupTypeRecursive(
                 typeStringRepresentation);
 
         if (decl == null) {
@@ -1306,7 +1342,6 @@ public class IOStructGen {
      */
     private IntegerDeclaration parseInteger(CommonTree integer)
             throws ParseException {
-        assert (integer.getType() == CTFParser.INTEGER);
 
         List<CommonTree> children = integer.getChildren();
 
@@ -1336,29 +1371,24 @@ 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(
-                            "Left side of ctf expression must be a string"); //$NON-NLS-1$
+                if (!isAnyUnaryString(leftStrings.get(0))) {
+                    throw new ParseException("Left side of ctf expression must be a string"); //$NON-NLS-1$
                 }
                 String left = concatenateUnaryStrings(leftStrings);
 
                 if (left.equals("signed")) { //$NON-NLS-1$
                     signed = getSigned(rightNode);
-                } else if (left.equals(CTFStrings.BYTE_ORDER)) {
+                } else if (left.equals(MetadataStrings.BYTE_ORDER)) {
                     byteOrder = getByteOrder(rightNode);
                 } else if (left.equals("size")) { //$NON-NLS-1$
                     size = getSize(rightNode);
-                } else if (left.equals(CTFStrings.ALIGN)) {
+                } else if (left.equals(MetadataStrings.ALIGN)) {
                     alignment = getAlignment(rightNode);
                 } else if (left.equals("base")) { //$NON-NLS-1$
                     base = getBase(rightNode);
@@ -1367,7 +1397,7 @@ 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$
+                    Activator.log(IStatus.WARNING, Messages.IOStructGen_UnknownIntegerAttributeWarning + " " + left); //$NON-NLS-1$
                 }
 
                 break;
@@ -1392,7 +1422,6 @@ public class IOStructGen {
         integerDeclaration = new IntegerDeclaration((int) size, signed, base,
                 byteOrder, encoding, clock, alignment);
 
-        assert (integerDeclaration != null);
         return integerDeclaration;
     }
 
@@ -1402,7 +1431,6 @@ public class IOStructGen {
 
     private static StringDeclaration parseString(CommonTree string)
             throws ParseException {
-        assert (string.getType() == CTFParser.STRING);
 
         List<CommonTree> children = string.getChildren();
         StringDeclaration stringDeclaration = null;
@@ -1418,19 +1446,14 @@ 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(
-                                "Left side of ctf expression must be a string"); //$NON-NLS-1$
+                    if (!isAnyUnaryString(leftStrings.get(0))) {
+                        throw new ParseException("Left side of ctf expression must be a string"); //$NON-NLS-1$
                     }
                     String left = concatenateUnaryStrings(leftStrings);
 
@@ -1464,10 +1487,8 @@ public class IOStructGen {
      */
     private StructDeclaration parseStruct(CommonTree struct)
             throws ParseException {
-        assert (struct.getType() == CTFParser.STRUCT);
 
         List<CommonTree> children = struct.getChildren();
-        assert (children != null);
 
         /* The return value */
         StructDeclaration structDeclaration = null;
@@ -1489,11 +1510,8 @@ public class IOStructGen {
             case CTFParser.STRUCT_NAME: {
                 hasName = true;
 
-                assert (child.getChildCount() == 1);
-                CommonTree structNameIdentifier = (CommonTree) child
-                        .getChild(0);
+                CommonTree structNameIdentifier = (CommonTree) child.getChild(0);
 
-                assert (structNameIdentifier.getType() == CTFParser.IDENTIFIER);
                 structName = structNameIdentifier.getText();
 
                 break;
@@ -1506,9 +1524,7 @@ public class IOStructGen {
                 break;
             }
             case CTFParser.ALIGN: {
-                assert (child.getChildCount() == 1);
-                CommonTree structAlignExpression = (CommonTree) child
-                        .getChild(0);
+                CommonTree structAlignExpression = (CommonTree) child.getChild(0);
 
                 structAlign = getAlignment(structAlignExpression);
 
@@ -1563,7 +1579,7 @@ public class IOStructGen {
                 /* Name and !body */
 
                 /* Lookup the name in the current scope. */
-                structDeclaration = getCurrentScope().rlookupStruct(structName);
+                structDeclaration = getCurrentScope().lookupStructRecursive(structName);
 
                 /*
                  * If not found, it means that a struct with such name has not
@@ -1581,7 +1597,6 @@ public class IOStructGen {
             }
         }
 
-        assert (structDeclaration != null);
         return structDeclaration;
     }
 
@@ -1597,7 +1612,6 @@ public class IOStructGen {
      */
     private void parseStructBody(CommonTree structBody,
             StructDeclaration structDeclaration) throws ParseException {
-        assert (structBody.getType() == CTFParser.STRUCT_BODY);
 
         List<CommonTree> structDeclarations = structBody.getChildren();
 
@@ -1639,38 +1653,28 @@ public class IOStructGen {
      */
     private void parseStructDeclaration(CommonTree declaration,
             StructDeclaration struct) throws ParseException {
-        assert (declaration.getType() == CTFParser.SV_DECLARATION);
-
-        List<CommonTree> children = declaration.getChildren();
-        assert (children != null);
 
         /* Get the type specifier list node */
-        CommonTree typeSpecifierListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
-        assert (typeSpecifierListNode != null);
+        CommonTree typeSpecifierListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
 
         /* Get the type declarator list node */
-        CommonTree typeDeclaratorListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
-        assert (typeDeclaratorListNode != null);
+        CommonTree typeDeclaratorListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
 
         /* Get the type declarator list */
-        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode
-                .getChildren();
-        assert (typeDeclaratorList != null);
+        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode.getChildren();
 
         /*
          * For each type declarator, parse the declaration and add a field to
          * the struct
          */
         for (CommonTree typeDeclaratorNode : typeDeclaratorList) {
-            assert (typeDeclaratorNode.getType() == CTFParser.TYPE_DECLARATOR);
 
             StringBuilder identifierSB = new StringBuilder();
 
             IDeclaration decl = parseTypeDeclarator(typeDeclaratorNode,
                     typeSpecifierListNode, identifierSB);
             String fieldName = identifierSB.toString();
+            getCurrentScope().registerIdentifier(fieldName, decl);
 
             if (struct.hasField(fieldName)) {
                 throw new ParseException("struct: duplicate field " //$NON-NLS-1$
@@ -1685,16 +1689,14 @@ public class IOStructGen {
     /**
      * Parses an enum declaration and returns the corresponding declaration.
      *
-     * @param _enum
+     * @param theEnum
      *            An ENUM node.
      * @return The corresponding enum declaration.
      * @throws ParseException
      */
-    private EnumDeclaration parseEnum(CommonTree _enum) throws ParseException {
-        assert (_enum.getType() == CTFParser.ENUM);
+    private EnumDeclaration parseEnum(CommonTree theEnum) throws ParseException {
 
-        List<CommonTree> children = _enum.getChildren();
-        assert (children != null);
+        List<CommonTree> children = theEnum.getChildren();
 
         /* The return value */
         EnumDeclaration enumDeclaration = null;
@@ -1712,28 +1714,16 @@ public class IOStructGen {
         for (CommonTree child : children) {
             switch (child.getType()) {
             case CTFParser.ENUM_NAME: {
-                assert (enumName == null);
-
-                assert (child.getChildCount() == 1);
                 CommonTree enumNameIdentifier = (CommonTree) child.getChild(0);
-
-                assert (enumNameIdentifier.getType() == CTFParser.IDENTIFIER);
                 enumName = enumNameIdentifier.getText();
-
                 break;
             }
             case CTFParser.ENUM_BODY: {
-                assert (enumBody == null);
-
                 enumBody = child;
-
                 break;
             }
             case CTFParser.ENUM_CONTAINER_TYPE: {
-                assert (containerTypeDeclaration == null);
-
                 containerTypeDeclaration = parseEnumContainerType(child);
-
                 break;
             }
             default:
@@ -1747,14 +1737,23 @@ public class IOStructGen {
          * is "int".
          */
         if (containerTypeDeclaration == null) {
-            IDeclaration decl = getCurrentScope().rlookupType("int"); //$NON-NLS-1$
+            IDeclaration enumDecl;
+            /*
+             * it could be because the enum was already declared.
+             */
+            if (enumName != null) {
+                enumDecl = getCurrentScope().lookupEnumRecursive(enumName);
+                if (enumDecl != null) {
+                    return (EnumDeclaration) enumDecl;
+                }
+            }
+
+            IDeclaration decl = getCurrentScope().lookupTypeRecursive("int"); //$NON-NLS-1$
 
             if (decl == null) {
-                throw new ParseException(
-                        "enum container type implicit and type int not defined"); //$NON-NLS-1$
+                throw new ParseException("enum container type implicit and type int not defined"); //$NON-NLS-1$
             } else if (!(decl instanceof IntegerDeclaration)) {
-                throw new ParseException(
-                        "enum container type implicit and type int not an integer"); //$NON-NLS-1$
+                throw new ParseException("enum container type implicit and type int not an integer"); //$NON-NLS-1$
             }
 
             containerTypeDeclaration = (IntegerDeclaration) decl;
@@ -1790,7 +1789,7 @@ public class IOStructGen {
                 /* Name and !body */
 
                 /* Lookup the name in the current scope. */
-                enumDeclaration = getCurrentScope().rlookupEnum(enumName);
+                enumDeclaration = getCurrentScope().lookupEnumRecursive(enumName);
 
                 /*
                  * If not found, it means that an enum with such name has not
@@ -1822,11 +1821,9 @@ public class IOStructGen {
      */
     private void parseEnumBody(CommonTree enumBody,
             EnumDeclaration enumDeclaration) throws ParseException {
-        assert (enumBody.getType() == CTFParser.ENUM_BODY);
 
         List<CommonTree> enumerators = enumBody.getChildren();
         /* enum body can't be empty (unlike struct). */
-        assert (enumerators != null);
 
         pushScope();
 
@@ -1865,30 +1862,23 @@ public class IOStructGen {
     private static long parseEnumEnumerator(CommonTree enumerator,
             EnumDeclaration enumDeclaration, long lastHigh)
             throws ParseException {
-        assert (enumerator.getType() == CTFParser.ENUM_ENUMERATOR);
 
         List<CommonTree> children = enumerator.getChildren();
-        assert (children != null);
 
         long low = 0, high = 0;
         boolean valueSpecified = false;
         String label = null;
 
         for (CommonTree child : children) {
-            if (isUnaryString(child)) {
+            if (isAnyUnaryString(child)) {
                 label = parseUnaryString(child);
             } else if (child.getType() == CTFParser.ENUM_VALUE) {
-                assert (child.getChildCount() == 1);
-                assert (isUnaryInteger((CommonTree) child.getChild(0)));
 
                 valueSpecified = true;
 
                 low = parseUnaryInteger((CommonTree) child.getChild(0));
                 high = low;
             } else if (child.getType() == CTFParser.ENUM_VALUE_RANGE) {
-                assert (child.getChildCount() == 2);
-                assert (isUnaryInteger((CommonTree) child.getChild(0)));
-                assert (isUnaryInteger((CommonTree) child.getChild(1)));
 
                 valueSpecified = true;
 
@@ -1899,8 +1889,6 @@ public class IOStructGen {
             }
         }
 
-        assert (label != null);
-
         if (!valueSpecified) {
             low = lastHigh + 1;
             high = low;
@@ -1914,6 +1902,11 @@ public class IOStructGen {
             throw new ParseException("enum declarator values overlap."); //$NON-NLS-1$
         }
 
+        if (valueSpecified && (BigInteger.valueOf(low).compareTo(enumDeclaration.getContainerType().getMinValue()) == -1 ||
+                BigInteger.valueOf(high).compareTo(enumDeclaration.getContainerType().getMaxValue()) == 1)) {
+            throw new ParseException("enum value is not in range"); //$NON-NLS-1$
+        }
+
         return high;
     }
 
@@ -1930,12 +1923,9 @@ public class IOStructGen {
      */
     private IntegerDeclaration parseEnumContainerType(
             CommonTree enumContainerType) throws ParseException {
-        assert (enumContainerType.getType() == CTFParser.ENUM_CONTAINER_TYPE);
 
         /* Get the child, which should be a type specifier list */
-        assert (enumContainerType.getChildCount() == 1);
-        CommonTree typeSpecifierList = (CommonTree) enumContainerType
-                .getChild(0);
+        CommonTree typeSpecifierList = (CommonTree) enumContainerType.getChild(0);
 
         /* Parse it and get the corresponding declaration */
         IDeclaration decl = parseTypeSpecifierList(typeSpecifierList, null);
@@ -1949,7 +1939,6 @@ public class IOStructGen {
 
     private VariantDeclaration parseVariant(CommonTree variant)
             throws ParseException {
-        assert (variant.getType() == CTFParser.VARIANT);
 
         List<CommonTree> children = variant.getChildren();
         VariantDeclaration variantDeclaration = null;
@@ -1966,33 +1955,24 @@ public class IOStructGen {
         for (CommonTree child : children) {
             switch (child.getType()) {
             case CTFParser.VARIANT_NAME:
-                assert (variantName == null);
 
                 hasName = true;
 
-                assert (child.getChildCount() == 1);
-                CommonTree variantNameIdentifier = (CommonTree) child
-                        .getChild(0);
+                CommonTree variantNameIdentifier = (CommonTree) child.getChild(0);
 
-                assert (variantNameIdentifier.getType() == CTFParser.IDENTIFIER);
                 variantName = variantNameIdentifier.getText();
 
                 break;
             case CTFParser.VARIANT_TAG:
-                assert (variantTag == null);
 
                 hasTag = true;
 
-                assert (child.getChildCount() == 1);
-                CommonTree variantTagIdentifier = (CommonTree) child
-                        .getChild(0);
+                CommonTree variantTagIdentifier = (CommonTree) child.getChild(0);
 
-                assert (variantTagIdentifier.getType() == CTFParser.IDENTIFIER);
                 variantTag = variantTagIdentifier.getText();
 
                 break;
             case CTFParser.VARIANT_BODY:
-                assert (variantBody == null);
 
                 hasBody = true;
 
@@ -2032,7 +2012,7 @@ public class IOStructGen {
                 /* Name and !body */
 
                 /* Lookup the name in the current scope. */
-                variantDeclaration = getCurrentScope().rlookupVariant(
+                variantDeclaration = getCurrentScope().lookupVariantRecursive(
                         variantName);
 
                 /*
@@ -2053,18 +2033,29 @@ public class IOStructGen {
 
         if (hasTag) {
             variantDeclaration.setTag(variantTag);
+
+            IDeclaration decl = getCurrentScope().lookupIdentifierRecursive(variantTag);
+            if (decl == null) {
+                throw new ParseException("Variant tag not found: " + variantTag); //$NON-NLS-1$
+            }
+            if (!(decl instanceof EnumDeclaration)) {
+                throw new ParseException("Variant tag must be an enum: " + variantTag); //$NON-NLS-1$
+            }
+            EnumDeclaration tagDecl = (EnumDeclaration) decl;
+            Set<String> intersection = new HashSet<String>(tagDecl.getLabels());
+            intersection.retainAll(variantDeclaration.getFields().keySet());
+            if (intersection.isEmpty()) {
+                throw new ParseException("Variant contains no values of the tag, impossible to use: " + variantName); //$NON-NLS-1$
+            }
         }
 
-        assert (variantDeclaration != null);
         return variantDeclaration;
     }
 
     private void parseVariantBody(CommonTree variantBody,
             VariantDeclaration variantDeclaration) throws ParseException {
-        assert (variantBody.getType() == CTFParser.VARIANT_BODY);
 
         List<CommonTree> variantDeclarations = variantBody.getChildren();
-        assert (variantDeclarations != null);
 
         pushScope();
 
@@ -2090,44 +2081,37 @@ public class IOStructGen {
 
     private void parseVariantDeclaration(CommonTree declaration,
             VariantDeclaration variant) throws ParseException {
-        assert (declaration.getType() == CTFParser.SV_DECLARATION);
-
-        List<CommonTree> children = declaration.getChildren();
-        assert (children != null);
 
         /* Get the type specifier list node */
-        CommonTree typeSpecifierListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
-        assert (typeSpecifierListNode != null);
+        CommonTree typeSpecifierListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
 
         /* Get the type declarator list node */
-        CommonTree typeDeclaratorListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
-        assert (typeDeclaratorListNode != null);
+        CommonTree typeDeclaratorListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
 
         /* Get the type declarator list */
-        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode
-                .getChildren();
-        assert (typeDeclaratorList != null);
+        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode.getChildren();
 
         /*
          * For each type declarator, parse the declaration and add a field to
          * the variant
          */
         for (CommonTree typeDeclaratorNode : typeDeclaratorList) {
-            assert (typeDeclaratorNode.getType() == CTFParser.TYPE_DECLARATOR);
 
             StringBuilder identifierSB = new StringBuilder();
 
             IDeclaration decl = parseTypeDeclarator(typeDeclaratorNode,
                     typeSpecifierListNode, identifierSB);
 
-            if (variant.hasField(identifierSB.toString())) {
+            String name = identifierSB.toString();
+
+            if (variant.hasField(name)) {
                 throw new ParseException("variant: duplicate field " //$NON-NLS-1$
-                        + identifierSB.toString());
+                        + name);
             }
 
-            variant.addField(identifierSB.toString(), decl);
+            getCurrentScope().registerIdentifier(name, decl);
+
+            variant.addField(name, decl);
         }
     }
 
@@ -2165,10 +2149,8 @@ public class IOStructGen {
     private static void createTypeSpecifierListString(
             CommonTree typeSpecifierList, StringBuilder sb)
             throws ParseException {
-        assert (typeSpecifierList.getType() == CTFParser.TYPE_SPECIFIER_LIST);
 
         List<CommonTree> children = typeSpecifierList.getChildren();
-        assert (children != null);
 
         boolean firstItem = true;
 
@@ -2214,48 +2196,34 @@ public class IOStructGen {
             sb.append(typeSpecifier.getText());
             break;
         case CTFParser.STRUCT: {
-            CommonTree structName = (CommonTree) typeSpecifier
-                    .getFirstChildWithType(CTFParser.STRUCT_NAME);
+            CommonTree structName = (CommonTree) typeSpecifier.getFirstChildWithType(CTFParser.STRUCT_NAME);
             if (structName == null) {
-                throw new ParseException(
-                        "nameless struct found in createTypeSpecifierString"); //$NON-NLS-1$
+                throw new ParseException("nameless struct found in createTypeSpecifierString"); //$NON-NLS-1$
             }
-            assert (structName.getChildCount() == 1);
 
-            CommonTree structNameIdentifier = (CommonTree) structName
-                    .getChild(0);
-            assert (structNameIdentifier.getType() == CTFParser.IDENTIFIER);
+            CommonTree structNameIdentifier = (CommonTree) structName.getChild(0);
 
             sb.append(structNameIdentifier.getText());
             break;
         }
         case CTFParser.VARIANT: {
-            CommonTree variantName = (CommonTree) typeSpecifier
-                    .getFirstChildWithType(CTFParser.VARIANT_NAME);
+            CommonTree variantName = (CommonTree) typeSpecifier.getFirstChildWithType(CTFParser.VARIANT_NAME);
             if (variantName == null) {
-                throw new ParseException(
-                        "nameless variant found in createTypeSpecifierString"); //$NON-NLS-1$
+                throw new ParseException("nameless variant found in createTypeSpecifierString"); //$NON-NLS-1$
             }
-            assert (variantName.getChildCount() == 1);
 
-            CommonTree variantNameIdentifier = (CommonTree) variantName
-                    .getChild(0);
-            assert (variantNameIdentifier.getType() == CTFParser.IDENTIFIER);
+            CommonTree variantNameIdentifier = (CommonTree) variantName.getChild(0);
 
             sb.append(variantNameIdentifier.getText());
             break;
         }
         case CTFParser.ENUM: {
-            CommonTree enumName = (CommonTree) typeSpecifier
-                    .getFirstChildWithType(CTFParser.ENUM_NAME);
+            CommonTree enumName = (CommonTree) typeSpecifier.getFirstChildWithType(CTFParser.ENUM_NAME);
             if (enumName == null) {
-                throw new ParseException(
-                        "nameless enum found in createTypeSpecifierString"); //$NON-NLS-1$
+                throw new ParseException("nameless enum found in createTypeSpecifierString"); //$NON-NLS-1$
             }
-            assert (enumName.getChildCount() == 1);
 
             CommonTree enumNameIdentifier = (CommonTree) enumName.getChild(0);
-            assert (enumNameIdentifier.getType() == CTFParser.IDENTIFIER);
 
             sb.append(enumNameIdentifier.getText());
             break;
@@ -2263,9 +2231,7 @@ public class IOStructGen {
         case CTFParser.FLOATING_POINT:
         case CTFParser.INTEGER:
         case CTFParser.STRING:
-            throw new ParseException(
-                    "CTF type found in createTypeSpecifierString"); //$NON-NLS-1$
-            /* break; */
+            throw new ParseException("CTF type found in createTypeSpecifierString"); //$NON-NLS-1$
         default:
             childTypeError(typeSpecifier);
             break;
@@ -2288,13 +2254,9 @@ public class IOStructGen {
         }
 
         for (CommonTree pointer : pointerList) {
-            assert (pointer.getType() == CTFParser.POINTER);
 
             sb.append(" *"); //$NON-NLS-1$
             if (pointer.getChildCount() > 0) {
-                assert (pointer.getChildCount() == 1);
-                CommonTree constQualifier = (CommonTree) pointer.getChild(0);
-                assert (constQualifier.getType() == CTFParser.CONSTTOK);
 
                 sb.append(" const"); //$NON-NLS-1$
             }
@@ -2304,20 +2266,20 @@ public class IOStructGen {
     /**
      * @param node
      *            The node to check.
-     * @return True if the given node is an unary string or unary integer.
+     * @return True if the given node is an unary string.
      */
-    private static boolean isUnaryExpression(CommonTree node) {
-        return isUnaryInteger(node) || isUnaryString(node);
+    private static boolean isUnaryString(CommonTree node) {
+        return ((node.getType() == CTFParser.UNARY_EXPRESSION_STRING));
     }
 
     /**
      * @param node
      *            The node to check.
-     * @return True if the given node is an unary string.
+     * @return True if the given node is any type of unary string (no quotes,
+     *         quotes, etc).
      */
-    private static boolean isUnaryString(CommonTree node) {
-        return ((node.getType() == CTFParser.UNARY_EXPRESSION_STRING) || (node
-                .getType() == CTFParser.UNARY_EXPRESSION_STRING_QUOTES));
+    private static boolean isAnyUnaryString(CommonTree node) {
+        return ((node.getType() == CTFParser.UNARY_EXPRESSION_STRING) || (node.getType() == CTFParser.UNARY_EXPRESSION_STRING_QUOTES));
     }
 
     /**
@@ -2326,9 +2288,8 @@ public class IOStructGen {
      * @return True if the given node is an unary integer.
      */
     private static boolean isUnaryInteger(CommonTree node) {
-        return ((node.getType() == CTFParser.UNARY_EXPRESSION_DEC)
-                || (node.getType() == CTFParser.UNARY_EXPRESSION_HEX) || (node
-                    .getType() == CTFParser.UNARY_EXPRESSION_OCT));
+        return ((node.getType() == CTFParser.UNARY_EXPRESSION_DEC) ||
+                (node.getType() == CTFParser.UNARY_EXPRESSION_HEX) || (node.getType() == CTFParser.UNARY_EXPRESSION_OCT));
     }
 
     /**
@@ -2344,11 +2305,8 @@ public class IOStructGen {
      * parser.
      */
     private static String parseUnaryString(CommonTree unaryString) {
-        assert (isUnaryString(unaryString));
 
-        assert (unaryString.getChildCount() == 1);
         CommonTree value = (CommonTree) unaryString.getChild(0);
-        assert (value != null);
         String strval = value.getText();
 
         /* Remove quotes */
@@ -2365,24 +2323,19 @@ public class IOStructGen {
      * @param unaryInteger
      *            An unary integer node.
      * @return The integer value.
+     * @throws ParseException on an invalid integer format ("bob" for example)
      */
-    private static long parseUnaryInteger(CommonTree unaryInteger) {
-        assert (isUnaryInteger(unaryInteger));
-
-        assert (unaryInteger.getChildCount() >= 1);
+    private static long parseUnaryInteger(CommonTree unaryInteger) throws ParseException {
 
         List<CommonTree> children = unaryInteger.getChildren();
         CommonTree value = children.get(0);
         String strval = value.getText();
 
         long intval;
-
-        if (unaryInteger.getType() == CTFParser.UNARY_EXPRESSION_DEC) {
-            intval = Long.parseLong(strval, 10);
-        } else if (unaryInteger.getType() == CTFParser.UNARY_EXPRESSION_HEX) {
-            intval = Long.parseLong(strval, 0x10);
-        } else { /* unaryInteger.getType() == CTFParser.UNARY_EXPRESSION_OCT */
-            intval = Long.parseLong(strval, 010); // 010 == 0x08 == 8
+        try {
+            intval = Long.decode(strval);
+        } catch (NumberFormatException e) {
+            throw new ParseException("Invalid integer format: " + strval); //$NON-NLS-1$
         }
 
         /* The rest of children are sign */
@@ -2394,8 +2347,6 @@ public class IOStructGen {
 
     private static long getMajorOrMinor(CommonTree rightNode)
             throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
@@ -2416,12 +2367,10 @@ public class IOStructGen {
     }
 
     private static UUID getUUID(CommonTree rightNode) throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
-        if (isUnaryString(firstChild)) {
+        if (isAnyUnaryString(firstChild)) {
             if (rightNode.getChildCount() > 1) {
                 throw new ParseException("Invalid value for UUID"); //$NON-NLS-1$
             }
@@ -2429,8 +2378,7 @@ public class IOStructGen {
             String uuidstr = parseUnaryString(firstChild);
 
             try {
-                UUID uuid = UUID.fromString(uuidstr);
-                return uuid;
+                return UUID.fromString(uuidstr);
             } catch (IllegalArgumentException e) {
                 throw new ParseException("Invalid format for UUID"); //$NON-NLS-1$
             }
@@ -2448,8 +2396,6 @@ public class IOStructGen {
      */
     private static boolean getSigned(CommonTree rightNode)
             throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         boolean ret = false;
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
@@ -2457,9 +2403,11 @@ public class IOStructGen {
         if (isUnaryString(firstChild)) {
             String strval = concatenateUnaryStrings(rightNode.getChildren());
 
-            if (strval.equals(CTFStrings.TRUE) || strval.equals(CTFStrings.TRUE2)) {
+            if (strval.equals(MetadataStrings.TRUE)
+                    || strval.equals(MetadataStrings.TRUE2)) {
                 ret = true;
-            } else if (strval.equals(CTFStrings.FALSE) || strval.equals(CTFStrings.FALSE2)) {
+            } else if (strval.equals(MetadataStrings.FALSE)
+                    || strval.equals(MetadataStrings.FALSE2)) {
                 ret = false;
             } else {
                 throw new ParseException("Invalid boolean value " //$NON-NLS-1$
@@ -2497,19 +2445,18 @@ public class IOStructGen {
      * @throws ParseException
      */
     private ByteOrder getByteOrder(CommonTree rightNode) throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
         if (isUnaryString(firstChild)) {
             String strval = concatenateUnaryStrings(rightNode.getChildren());
 
-            if (strval.equals(CTFStrings.LE)) {
+            if (strval.equals(MetadataStrings.LE)) {
                 return ByteOrder.LITTLE_ENDIAN;
-            } else if (strval.equals(CTFStrings.BE) || strval.equals(CTFStrings.NETWORK)) {
+            } else if (strval.equals(MetadataStrings.BE)
+                    || strval.equals(MetadataStrings.NETWORK)) {
                 return ByteOrder.BIG_ENDIAN;
-            } else if (strval.equals(CTFStrings.NATIVE)) {
+            } else if (strval.equals(MetadataStrings.NATIVE)) {
                 return trace.getByteOrder();
             } else {
                 throw new ParseException("Invalid value for byte order"); //$NON-NLS-1$
@@ -2538,8 +2485,6 @@ public class IOStructGen {
      * @throws ParseException
      */
     private static long getSize(CommonTree rightNode) throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
@@ -2568,7 +2513,6 @@ public class IOStructGen {
      * @throws ParseException
      */
     private static long getAlignment(CommonTree node) throws ParseException {
-        assert (isUnaryExpression(node) || (node.getType() == CTFParser.CTF_RIGHT));
 
         /*
          * If a CTF_RIGHT node was passed, call getAlignment with the first
@@ -2602,8 +2546,6 @@ public class IOStructGen {
      * @throws ParseException
      */
     private static int getBase(CommonTree rightNode) throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
@@ -2621,18 +2563,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)
-                    || strval.equals(CTFStrings.UNSIGNED_CTE)) {
+            if (strval.equals(MetadataStrings.DECIMAL)
+                    || strval.equals(MetadataStrings.DEC)
+                    || strval.equals(MetadataStrings.DEC_CTE)
+                    || strval.equals(MetadataStrings.INT_MOD)
+                    || strval.equals(MetadataStrings.UNSIGNED_CTE)) {
                 return 10;
-            } else if (strval.equals(CTFStrings.HEXADECIMAL) || strval.equals(CTFStrings.HEX)
-                    || strval.equals(CTFStrings.X) || strval.equals(CTFStrings.X2)
-                    || strval.equals(CTFStrings.POINTER)) {
+            } else if (strval.equals(MetadataStrings.HEXADECIMAL)
+                    || strval.equals(MetadataStrings.HEX)
+                    || strval.equals(MetadataStrings.X)
+                    || strval.equals(MetadataStrings.X2)
+                    || strval.equals(MetadataStrings.POINTER)) {
                 return 16;
-            } else if (strval.equals(CTFStrings.OCTAL) || strval.equals(CTFStrings.OCT)
-                    || strval.equals(CTFStrings.OCTAL_CTE)) {
+            } else if (strval.equals(MetadataStrings.OCTAL)
+                    || strval.equals(MetadataStrings.OCT)
+                    || strval.equals(MetadataStrings.OCTAL_CTE)) {
                 return 8;
-            } else if (strval.equals(CTFStrings.BINARY) || strval.equals(CTFStrings.BIN)) {
+            } else if (strval.equals(MetadataStrings.BINARY)
+                    || strval.equals(MetadataStrings.BIN)) {
                 return 2;
             } else {
                 throw new ParseException("Invalid value for base"); //$NON-NLS-1$
@@ -2652,18 +2600,17 @@ public class IOStructGen {
      */
     private static Encoding getEncoding(CommonTree rightNode)
             throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
         if (isUnaryString(firstChild)) {
             String strval = concatenateUnaryStrings(rightNode.getChildren());
 
-            if (strval.equals(CTFStrings.UTF8)) {
+            if (strval.equals(MetadataStrings.UTF8)) {
                 return Encoding.UTF8;
-            } else if (strval.equals(CTFStrings.ASCII)) {
+            } else if (strval.equals(MetadataStrings.ASCII)) {
                 return Encoding.ASCII;
-            } else if (strval.equals(CTFStrings.NONE)) {
+            } else if (strval.equals(MetadataStrings.NONE)) {
                 return Encoding.NONE;
             } else {
                 throw new ParseException("Invalid value for encoding"); //$NON-NLS-1$
@@ -2673,8 +2620,6 @@ public class IOStructGen {
     }
 
     private static long getStreamID(CommonTree rightNode) throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
@@ -2692,12 +2637,10 @@ public class IOStructGen {
 
     private static String getEventName(CommonTree rightNode)
             throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
-        if (isUnaryString(firstChild)) {
+        if (isAnyUnaryString(firstChild)) {
             String str = concatenateUnaryStrings(rightNode.getChildren());
 
             return str;
@@ -2706,8 +2649,6 @@ public class IOStructGen {
     }
 
     private static long getEventID(CommonTree rightNode) throws ParseException {
-        assert (rightNode.getType() == CTFParser.CTF_RIGHT);
-        assert (rightNode.getChildCount() > 0);
 
         CommonTree firstChild = (CommonTree) rightNode.getChild(0);
 
@@ -2732,7 +2673,6 @@ public class IOStructGen {
      * @return The string representation of the unary string chain.
      */
     private static String concatenateUnaryStrings(List<CommonTree> strings) {
-        assert ((strings != null) && (strings.size() > 0));
 
         StringBuilder sb = new StringBuilder();
 
@@ -2747,9 +2687,6 @@ public class IOStructGen {
                 continue;
             }
 
-            assert ((ref.getType() == CTFParser.ARROW) || (ref.getType() == CTFParser.DOT));
-            assert (ref.getChildCount() == 1);
-
             CommonTree id = (CommonTree) ref.getChild(0);
 
             if (ref.getType() == CTFParser.ARROW) {
@@ -2797,7 +2734,6 @@ public class IOStructGen {
      * Removes the top declaration scope from the scope stack.
      */
     private void popScope() {
-        assert (scope != null);
         scope = scope.getParentScope();
     }
 
@@ -2807,7 +2743,6 @@ public class IOStructGen {
      * @return The current declaration scope.
      */
     private DeclarationScope getCurrentScope() {
-        assert (scope != null);
         return scope;
     }
 
This page took 0.048019 seconds and 5 git commands to generate.