import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.parser.CTFParser;
-import org.eclipse.linuxtools.internal.ctf.core.Activator;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
// Constructor
// ------------------------------------------------------------------------
+ /**
+ * Constuctor
+ * @param tree the tree (antlr generated) with the parsed TSDL data.
+ * @param trace the trace containing the places to put all the read metadata
+ */
public IOStructGen(CommonTree tree, CTFTrace trace) {
this.trace = trace;
this.tree = tree;
}
+ /**
+ * Parse the tree and populate the trace defined in the constructor.
+ * @throws ParseException
+ */
public void generate() throws ParseException {
parseRoot(tree);
}
}
for (CommonTree event : events) {
parseEvent(event);
- CommonTree name = (CommonTree) event.getChild(0).getChild(1)
- .getChild(0).getChild(0);
- if (DEBUG_) {
- out.write("Name = " + name); //$NON-NLS-1$
- }
- 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$
}
}
String left = concatenateUnaryStrings(leftStrings);
- if (left.equals("major")) { //$NON-NLS-1$
+ if (left.equals(CTFStrings.MAJOR)) {
if (trace.majortIsSet()) {
throw new ParseException("major is already set"); //$NON-NLS-1$
}
trace.setMajor(getMajorOrMinor(rightNode));
- } else if (left.equals("minor")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.MINOR)) {
if (trace.minorIsSet()) {
throw new ParseException("minor is already set"); //$NON-NLS-1$
}
trace.setMinor(getMajorOrMinor(rightNode));
- } else if (left.equals("uuid")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.UUID_STRING)) {
UUID uuid = getUUID(rightNode);
/*
trace.setUUID(uuid);
}
- } else if (left.equals("byte_order")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.BYTE_ORDER)) {
ByteOrder byteOrder = getByteOrder(rightNode);
/*
} else {
trace.setByteOrder(byteOrder);
}
- } else if (left.equals("packet.header")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.PACKET_HEADER)) {
if (trace.packetHeaderIsSet()) {
throw new ParseException("packet.header already defined"); //$NON-NLS-1$
}
}
}
- if (stream.idIsSet()) {
+ if (stream.isIdSet()) {
if (!trace.packetHeaderIsSet()
- || !trace.getPacketHeader().hasField("stream_id")) { //$NON-NLS-1$
+ || !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$
}
String left = concatenateUnaryStrings(leftStrings);
- if (left.equals("id")) { //$NON-NLS-1$
- if (stream.idIsSet()) {
+ if (left.equals(CTFStrings.ID)) {
+ if (stream.isIdSet()) {
throw new ParseException("stream id already defined"); //$NON-NLS-1$
}
long streamID = getStreamID(rightNode);
stream.setId(streamID);
- } else if (left.equals("event.header")) { //$NON-NLS-1$
- if (stream.eventHeaderIsSet()) {
+ } else if (left.equals(CTFStrings.EVENT_HEADER)) {
+ if (stream.isEventHeaderSet()) {
throw new ParseException("event.header already defined"); //$NON-NLS-1$
}
}
stream.setEventHeader((StructDeclaration) eventHeaderDecl);
- } else if (left.equals("event.context")) { //$NON-NLS-1$
- if (stream.eventContextIsSet()) {
+ } else if (left.equals(CTFStrings.EVENT_CONTEXT)) {
+ if (stream.isEventContextSet()) {
throw new ParseException("event.context already defined"); //$NON-NLS-1$
}
}
stream.setEventContext((StructDeclaration) eventContextDecl);
- } else if (left.equals("packet.context")) { //$NON-NLS-1$
- if (stream.packetContextIsSet()) {
+ } else if (left.equals(CTFStrings.PACKET_CONTEXT)) {
+ if (stream.isPacketContextSet()) {
throw new ParseException("packet.context already defined"); //$NON-NLS-1$
}
String left = concatenateUnaryStrings(leftStrings);
- if (left.equals("name")) { //$NON-NLS-1$
+ if (left.equals(CTFStrings.NAME2)) {
if (event.nameIsSet()) {
throw new ParseException("name already defined"); //$NON-NLS-1$
}
String name = getEventName(rightNode);
event.setName(name);
- } else if (left.equals("id")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.ID)) {
if (event.idIsSet()) {
throw new ParseException("id already defined"); //$NON-NLS-1$
}
long id = getEventID(rightNode);
event.setId(id);
- } else if (left.equals("stream_id")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.STREAM_ID)) {
if (event.streamIsSet()) {
throw new ParseException("stream id already defined"); //$NON-NLS-1$
}
}
event.setStream(stream);
- } else if (left.equals("context")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.CONTEXT)) {
if (event.contextIsSet()) {
throw new ParseException("context already defined"); //$NON-NLS-1$
}
}
event.setContext((StructDeclaration) contextDecl);
- } else if (left.equals("fields")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.FIELDS_STRING)) {
if (event.fieldsIsSet()) {
throw new ParseException("fields already defined"); //$NON-NLS-1$
}
*/
final StructDeclaration fields = (StructDeclaration) fieldsDecl;
event.setFields(fields);
+ }
+ 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$
}
switch (firstChild.getType()) {
case CTFParser.FLOATING_POINT:
- Activator
- .getDefault()
- .log("parseTypeSpecifierList: floating_point not implemented yet"); //$NON-NLS-1$
+// Activator
+// .getDefault()
+// .log("parseTypeSpecifierList: floating_point not implemented yet"); //$NON-NLS-1$
+ declaration = parseFloat(firstChild);
break;
case CTFParser.INTEGER:
declaration = parseInteger(firstChild);
return declaration;
}
+ private IDeclaration parseFloat(CommonTree floatingPoint) throws ParseException {
+ assert (floatingPoint.getType() == CTFParser.INTEGER);
+
+ List<CommonTree> children = floatingPoint.getChildren();
+
+ /*
+ * If the integer has no attributes, then it is missing the size
+ * attribute which is required
+ */
+ if (children == null) {
+ throw new ParseException("float: missing size attribute"); //$NON-NLS-1$
+ }
+
+ /* The return value */
+ FloatDeclaration floatDeclaration = null;
+ ByteOrder byteOrder = trace.getByteOrder();
+ long alignment = 0;
+ int exponent = 8;
+ int mantissa = 24;
+
+ /* Iterate on all integer children */
+ for (CommonTree child : children) {
+ switch (child.getType()) {
+ case CTFParser.CTF_EXPRESSION_VAL:
+ /*
+ * 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$
+ }
+ String left = concatenateUnaryStrings(leftStrings);
+
+ if (left.equals(CTFStrings.EXP_DIG)) {
+ exponent = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0));
+ } else if (left.equals(CTFStrings.BYTE_ORDER)) {
+ byteOrder = getByteOrder(rightNode);
+ } else if (left.equals(CTFStrings.MANT_DIG)) {
+ mantissa = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0));
+ } else if (left.equals(CTFStrings.ALIGN)) {
+ alignment = getAlignment(rightNode);
+ } else {
+ throw new ParseException("Float: unknown attribute " + left); //$NON-NLS-1$
+ }
+
+ break;
+ default:
+ childTypeError(child);
+ break;
+ }
+ }
+ int size = mantissa + exponent;
+ if (size == 0) {
+ throw new ParseException("Float missing size attribute"); //$NON-NLS-1$
+ }
+
+ if (alignment == 0) {
+ if ((size % 8) == 0) {
+ alignment = 1;
+ } else {
+ alignment = 8;
+ }
+ }
+
+ floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, alignment);
+
+ assert (floatDeclaration != null);
+ return floatDeclaration;
+
+ }
+
/**
* Parses a type specifier list as a user-declared type.
*
if (left.equals("signed")) { //$NON-NLS-1$
signed = getSigned(rightNode);
- } else if (left.equals("byte_order")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.BYTE_ORDER)) {
byteOrder = getByteOrder(rightNode);
} else if (left.equals("size")) { //$NON-NLS-1$
size = getSize(rightNode);
- } else if (left.equals("align")) { //$NON-NLS-1$
+ } else if (left.equals(CTFStrings.ALIGN)) {
alignment = getAlignment(rightNode);
} else if (left.equals("base")) { //$NON-NLS-1$
base = getBase(rightNode);
}
integerDeclaration = new IntegerDeclaration((int) size, signed, base,
- byteOrder, encoding, clock);
+ byteOrder, encoding, clock, alignment);
assert (integerDeclaration != null);
return integerDeclaration;
throw new ParseException("struct " + structName //$NON-NLS-1$
+ " already defined."); //$NON-NLS-1$
}
-
/* Create the declaration */
structDeclaration = new StructDeclaration(structAlign);
if (isUnaryString(firstChild)) {
String strval = concatenateUnaryStrings(rightNode.getChildren());
- if (strval.equals("true") || strval.equals("TRUE")) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (strval.equals(CTFStrings.TRUE) || strval.equals(CTFStrings.TRUE2)) {
ret = true;
- } else if (strval.equals("false") || strval.equals("FALSE")) { //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (strval.equals(CTFStrings.FALSE) || strval.equals(CTFStrings.FALSE2)) {
ret = false;
} else {
throw new ParseException("Invalid boolean value " //$NON-NLS-1$
if (isUnaryString(firstChild)) {
String strval = concatenateUnaryStrings(rightNode.getChildren());
- if (strval.equals("le")) { //$NON-NLS-1$
+ if (strval.equals(CTFStrings.LE)) {
return ByteOrder.LITTLE_ENDIAN;
- } else if (strval.equals("be") || strval.equals("network")) { //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (strval.equals(CTFStrings.BE) || strval.equals(CTFStrings.NETWORK)) {
return ByteOrder.BIG_ENDIAN;
- } else if (strval.equals("native")) { //$NON-NLS-1$
+ } else if (strval.equals(CTFStrings.NATIVE)) {
return trace.getByteOrder();
} else {
throw new ParseException("Invalid value for byte order"); //$NON-NLS-1$
} else if (isUnaryString(firstChild)) {
String strval = concatenateUnaryStrings(rightNode.getChildren());
- if (strval.equals("decimal") || strval.equals("dec") //$NON-NLS-1$ //$NON-NLS-2$
- || strval.equals("d") || strval.equals("i") //$NON-NLS-1$ //$NON-NLS-2$
- || strval.equals("u")) { //$NON-NLS-1$
+ 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("hexadecimal") || strval.equals("hex") //$NON-NLS-1$ //$NON-NLS-2$
- || strval.equals("x") || strval.equals("X") //$NON-NLS-1$ //$NON-NLS-2$
- || strval.equals("p")) { //$NON-NLS-1$
+ } 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("octal") || strval.equals("oct") //$NON-NLS-1$ //$NON-NLS-2$
- || strval.equals("o")) { //$NON-NLS-1$
+ } else if (strval.equals(CTFStrings.OCTAL) || strval.equals(CTFStrings.OCT)
+ || strval.equals(CTFStrings.OCTAL_CTE)) {
return 8;
- } else if (strval.equals("binary") || strval.equals("b")) { //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (strval.equals(CTFStrings.BINARY) || strval.equals(CTFStrings.BIN)) {
return 2;
} else {
throw new ParseException("Invalid value for base"); //$NON-NLS-1$
if (isUnaryString(firstChild)) {
String strval = concatenateUnaryStrings(rightNode.getChildren());
- if (strval.equals("UTF8")) { //$NON-NLS-1$
+ if (strval.equals(CTFStrings.UTF8)) {
return Encoding.UTF8;
- } else if (strval.equals("ASCII")) { //$NON-NLS-1$
+ } else if (strval.equals(CTFStrings.ASCII)) {
return Encoding.ASCII;
- } else if (strval.equals("none")) { //$NON-NLS-1$
+ } else if (strval.equals(CTFStrings.NONE)) {
return Encoding.NONE;
} else {
throw new ParseException("Invalid value for encoding"); //$NON-NLS-1$