import org.antlr.runtime.ANTLRReaderStream;
import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.MismatchedTokenException;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.eclipse.linuxtools.ctf.parser.CTFLexer;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
/**
- * <b><u>Metadata</u></b>
- * <p>
- * Represents a metadata file
+ * The CTF trace metadata file
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ * @author Simon Marchi
*/
public class Metadata {
/**
* Name of the metadata file in the trace directory
*/
- final String METADATA_FILENAME = "metadata"; //$NON-NLS-1$
+ final static String METADATA_FILENAME = "metadata"; //$NON-NLS-1$
/**
* Size of the metadata packet header, in bytes, computed by hand.
*/
- final int METADATA_PACKET_HEADER_SIZE = 37;
+ final static int METADATA_PACKET_HEADER_SIZE = 37;
// ------------------------------------------------------------------------
// Attributes
* Parse the metadata file.
*
* @throws CTFReaderException
+ * If there was a problem parsing the metadata
*/
public void parse() throws CTFReaderException {
CTFReaderException tempException = null;
metadataTextInput = new FileReader(metadataFile);
}
- /* Create an ANTLR reader */
- ANTLRReaderStream antlrStream;
- antlrStream = new ANTLRReaderStream(metadataTextInput);
-
- /* Parse the metadata text and get the AST */
- CTFLexer ctfLexer = new CTFLexer(antlrStream);
- CommonTokenStream tokens = new CommonTokenStream(ctfLexer);
- CTFParser ctfParser = new CTFParser(tokens, false);
- parse_return ret;
-
- ret = ctfParser.parse();
-
- CommonTree tree = (CommonTree) ret.getTree();
+ CommonTree tree = createAST(metadataTextInput);
/* Generate IO structures (declarations) */
IOStructGen gen = new IOStructGen(tree, trace);
tempException = new CTFReaderException(e);
} catch (ParseException e) {
tempException = new CTFReaderException(e);
+ } catch (MismatchedTokenException e) {
+ tempException = new CTFReaderException(e);
} catch (RecognitionException e) {
- /*
- * We don't want to expose this ANTLR-specific exception type to the
- * outside..
- */
tempException = new CTFReaderException(e);
}
}
}
+ private static CommonTree createAST(Reader metadataTextInput) throws IOException,
+ RecognitionException {
+ /* Create an ANTLR reader */
+ ANTLRReaderStream antlrStream;
+ antlrStream = new ANTLRReaderStream(metadataTextInput);
+
+ /* Parse the metadata text and get the AST */
+ CTFLexer ctfLexer = new CTFLexer(antlrStream);
+ CommonTokenStream tokens = new CommonTokenStream(ctfLexer);
+ CTFParser ctfParser = new CTFParser(tokens, false);
+ parse_return ret;
+
+ ret = ctfParser.parse();
+
+ CommonTree tree = (CommonTree) ret.getTree();
+ return tree;
+ }
+
/**
* Determines whether the metadata file is packet-based by looking at the
* TSDL magic number. If it is packet-based, it also gives information about
try {
metadataFileChannel.read(magicByteBuffer, 0);
} catch (IOException e) {
- throw new CTFReaderException(
- "Unable to read metadata file channel."); //$NON-NLS-1$
+ throw new CTFReaderException("Unable to read metadata file channel."); //$NON-NLS-1$
}
/* Get the first int from the file */
try {
metadataFileChannel.read(payloadByteBuffer);
} catch (IOException e) {
- throw new CTFReaderException(
- "Error reading metadata packet payload."); //$NON-NLS-1$
+ throw new CTFReaderException("Error reading metadata packet payload."); //$NON-NLS-1$
}
payloadByteBuffer.rewind();