From 866e5b5194db2e1bdec629ccfdb0d71f07b3142a Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Thu, 15 Mar 2012 14:34:10 -0400 Subject: [PATCH] Contribute native CTF Parser (bug370499) --- .../.classpath | 9 + .../.gitignore | 5 + .../.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 12 + .../META-INF/MANIFEST.MF | 13 + .../Tests/traces/.gitignore | 5 + .../Tests/traces/gen.sh | 59 + .../Tests/traces/trace100m.sh | 1 + .../Tests/traces/trace20m.sh | 1 + .../build.properties | 7 + .../plugin.properties | 3 + org.eclipse.linuxtools.ctf.core.tests/pom.xml | 54 + .../ctf/core/tests/AllCtfCoreTests.java | 41 + .../ctf/core/tests/CtfCorePluginTest.java | 77 + .../ctf/core/tests/CtfCoreTestPlugin.java | 68 + .../linuxtools/ctf/core/tests/TestParams.java | 63 + .../core/tests/event/CTFEventFieldTest.java | 180 + .../ctf/core/tests/event/TestAll.java | 28 + .../ctf/core/tests/io/BitBufferIntTest.java | 290 + .../ctf/core/tests/io/BitBufferTest.java | 207 + .../linuxtools/ctf/core/tests/io/TestAll.java | 28 + .../core/tests/trace/CTFTraceReaderTest.java | 279 + .../ctf/core/tests/trace/CTFTraceTest.java | 306 + .../ctf/core/tests/trace/MetadataTest.java | 78 + .../StreamInputPacketIndexEntryTest.java | 78 + .../trace/StreamInputPacketIndexTest.java | 173 + .../trace/StreamInputPacketReaderTest.java | 188 + .../StreamInputReaderComparatorTest.java | 93 + .../tests/trace/StreamInputReaderTest.java | 189 + ...eamInputReaderTimestampComparatorTest.java | 77 + .../ctf/core/tests/trace/StreamInputTest.java | 140 + .../ctf/core/tests/trace/StreamTest.java | 230 + .../ctf/core/tests/trace/TestAll.java | 37 + .../ctf/core/tests/trace/UtilsTest.java | 121 + .../tests/types/ArrayDeclarationTest.java | 111 + .../core/tests/types/ArrayDefinitionTest.java | 269 + .../ctf/core/tests/types/DefinitionTest.java | 71 + .../core/tests/types/EnumDeclarationTest.java | 133 + .../core/tests/types/EnumDefinitionTest.java | 112 + .../tests/types/EventDeclarationTest.java | 354 + .../tests/types/IntegerDeclarationTest.java | 213 + .../tests/types/IntegerDefinitionTest.java | 140 + .../tests/types/SequenceDeclarationTest.java | 103 + .../tests/types/SequenceDefinitionTest.java | 177 + .../tests/types/StringDeclarationTest.java | 123 + .../tests/types/StringDefinitionTest.java | 161 + .../tests/types/StructDeclarationTest.java | 149 + .../tests/types/StructDefinitionTest.java | 217 + .../ctf/core/tests/types/TestAll.java | 35 + .../tests/types/VariantDeclarationTest.java | 164 + .../tests/types/VariantDefinitionTest.java | 293 + org.eclipse.linuxtools.ctf.core/.classpath | 8 + org.eclipse.linuxtools.ctf.core/.gitignore | 5 + org.eclipse.linuxtools.ctf.core/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 8 + .../META-INF/MANIFEST.MF | 19 + org.eclipse.linuxtools.ctf.core/about.html | 28 + .../build.properties | 6 + org.eclipse.linuxtools.ctf.core/other/lttng | 131 + .../plugin.properties | 3 + org.eclipse.linuxtools.ctf.core/pom.xml | 44 + .../linuxtools/ctf/core/CtfCorePlugin.java | 86 + .../linuxtools/ctf/core/event/CTFClock.java | 37 + .../ctf/core/event/EventDeclaration.java | 211 + .../ctf/core/event/EventDefinition.java | 153 + .../ctf/core/event/io/BitBuffer.java | 510 + .../core/event/metadata/DeclarationScope.java | 311 + .../ctf/core/event/metadata/IOStructGen.java | 2746 +++++ .../metadata/exceptions/ParseException.java | 35 + .../core/event/types/ArrayDeclaration.java | 64 + .../ctf/core/event/types/ArrayDefinition.java | 142 + .../ctf/core/event/types/Definition.java | 74 + .../ctf/core/event/types/Encoding.java | 22 + .../ctf/core/event/types/EnumDeclaration.java | 140 + .../ctf/core/event/types/EnumDefinition.java | 78 + .../ctf/core/event/types/IDeclaration.java | 22 + .../core/event/types/IDefinitionScope.java | 26 + .../core/event/types/IntegerDeclaration.java | 109 + .../core/event/types/IntegerDefinition.java | 93 + .../core/event/types/SequenceDeclaration.java | 64 + .../core/event/types/SequenceDefinition.java | 154 + .../core/event/types/StringDeclaration.java | 69 + .../core/event/types/StringDefinition.java | 87 + .../core/event/types/StructDeclaration.java | 87 + .../core/event/types/StructDefinition.java | 160 + .../core/event/types/VariantDeclaration.java | 80 + .../core/event/types/VariantDefinition.java | 165 + .../ctf/core/trace/CTFReaderException.java | 50 + .../linuxtools/ctf/core/trace/CTFTrace.java | 635 ++ .../ctf/core/trace/CTFTraceReader.java | 415 + .../linuxtools/ctf/core/trace/Metadata.java | 373 + .../linuxtools/ctf/core/trace/Stream.java | 206 + .../ctf/core/trace/StreamInput.java | 348 + .../core/trace/StreamInputPacketIndex.java | 143 + .../trace/StreamInputPacketIndexEntry.java | 97 + .../core/trace/StreamInputPacketReader.java | 465 + .../ctf/core/trace/StreamInputReader.java | 198 + .../trace/StreamInputReaderComparator.java | 51 + .../StreamInputReaderTimestampComparator.java | 57 + .../linuxtools/ctf/core/trace/Utils.java | 108 + org.eclipse.linuxtools.ctf.parser/.classpath | 7 + org.eclipse.linuxtools.ctf.parser/.gitignore | 5 + org.eclipse.linuxtools.ctf.parser/.project | 34 + .../.settings/org.eclipse.jdt.core.prefs | 12 + .../Grammar/CTFLexer.g | 187 + .../Grammar/CTFParser.g | 1003 ++ .../META-INF/MANIFEST.MF | 9 + org.eclipse.linuxtools.ctf.parser/about.html | 28 + .../build.properties | 8 + .../plugin.properties | 3 + org.eclipse.linuxtools.ctf.parser/pom.xml | 44 + .../eclipse/linuxtools/ctf/parser/.gitignore | 2 + .../linuxtools/ctf/parser/CTFLexer.java | 3556 ++++++ .../linuxtools/ctf/parser/CTFParser.java | 9521 +++++++++++++++++ org.eclipse.linuxtools.ctf/.gitignore | 5 + org.eclipse.linuxtools.ctf/.project | 17 + org.eclipse.linuxtools.ctf/build.properties | 4 + org.eclipse.linuxtools.ctf/epl-v10.html | 256 + org.eclipse.linuxtools.ctf/feature.properties | 145 + org.eclipse.linuxtools.ctf/feature.xml | 44 + org.eclipse.linuxtools.ctf/license.html | 164 + org.eclipse.linuxtools.ctf/pom.xml | 25 + .../META-INF/MANIFEST.MF | 1 - .../widgets/TmfTimeStatesCtrl.java | 2 +- pom.xml | 7 +- 125 files changed, 30230 insertions(+), 3 deletions(-) create mode 100644 org.eclipse.linuxtools.ctf.core.tests/.classpath create mode 100644 org.eclipse.linuxtools.ctf.core.tests/.gitignore create mode 100644 org.eclipse.linuxtools.ctf.core.tests/.project create mode 100644 org.eclipse.linuxtools.ctf.core.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.ctf.core.tests/Tests/traces/.gitignore create mode 100755 org.eclipse.linuxtools.ctf.core.tests/Tests/traces/gen.sh create mode 100755 org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace100m.sh create mode 100755 org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m.sh create mode 100644 org.eclipse.linuxtools.ctf.core.tests/build.properties create mode 100644 org.eclipse.linuxtools.ctf.core.tests/plugin.properties create mode 100644 org.eclipse.linuxtools.ctf.core.tests/pom.xml create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCorePluginTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCoreTestPlugin.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/TestAll.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/TestAll.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/UtilsTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/TestAll.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDeclarationTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java create mode 100644 org.eclipse.linuxtools.ctf.core/.classpath create mode 100644 org.eclipse.linuxtools.ctf.core/.gitignore create mode 100644 org.eclipse.linuxtools.ctf.core/.project create mode 100644 org.eclipse.linuxtools.ctf.core/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.ctf.core/about.html create mode 100644 org.eclipse.linuxtools.ctf.core/build.properties create mode 100644 org.eclipse.linuxtools.ctf.core/other/lttng create mode 100644 org.eclipse.linuxtools.ctf.core/plugin.properties create mode 100644 org.eclipse.linuxtools.ctf.core/pom.xml create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CtfCorePlugin.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinitionScope.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java create mode 100644 org.eclipse.linuxtools.ctf.parser/.classpath create mode 100644 org.eclipse.linuxtools.ctf.parser/.gitignore create mode 100644 org.eclipse.linuxtools.ctf.parser/.project create mode 100644 org.eclipse.linuxtools.ctf.parser/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.ctf.parser/Grammar/CTFLexer.g create mode 100644 org.eclipse.linuxtools.ctf.parser/Grammar/CTFParser.g create mode 100644 org.eclipse.linuxtools.ctf.parser/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.ctf.parser/about.html create mode 100644 org.eclipse.linuxtools.ctf.parser/build.properties create mode 100644 org.eclipse.linuxtools.ctf.parser/plugin.properties create mode 100644 org.eclipse.linuxtools.ctf.parser/pom.xml create mode 100644 org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/.gitignore create mode 100644 org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFLexer.java create mode 100644 org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFParser.java create mode 100644 org.eclipse.linuxtools.ctf/.gitignore create mode 100644 org.eclipse.linuxtools.ctf/.project create mode 100644 org.eclipse.linuxtools.ctf/build.properties create mode 100644 org.eclipse.linuxtools.ctf/epl-v10.html create mode 100644 org.eclipse.linuxtools.ctf/feature.properties create mode 100644 org.eclipse.linuxtools.ctf/feature.xml create mode 100644 org.eclipse.linuxtools.ctf/license.html create mode 100644 org.eclipse.linuxtools.ctf/pom.xml diff --git a/org.eclipse.linuxtools.ctf.core.tests/.classpath b/org.eclipse.linuxtools.ctf.core.tests/.classpath new file mode 100644 index 0000000000..f7868c5f53 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/org.eclipse.linuxtools.ctf.core.tests/.gitignore b/org.eclipse.linuxtools.ctf.core.tests/.gitignore new file mode 100644 index 0000000000..8d94ef8deb --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/.gitignore @@ -0,0 +1,5 @@ +bin +@dot +javaCompiler...args +build.xml +target diff --git a/org.eclipse.linuxtools.ctf.core.tests/.project b/org.eclipse.linuxtools.ctf.core.tests/.project new file mode 100644 index 0000000000..a9b9bb4da4 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.ctf.core.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/org.eclipse.linuxtools.ctf.core.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.ctf.core.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..b8d90e8eeb --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Tue Nov 29 10:59:39 EST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..1ce09d696e --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.linuxtools.ctf.core.tests +Bundle-Version: 0.1.0.qualifier +Require-Bundle: org.junit4;bundle-version="4.8.1", + org.eclipse.core.runtime;bundle-version="3.7.0", + org.eclipse.linuxtools.ctf.core, + org.antlr.runtime;bundle-version="3.2.0" +Bundle-ClassPath: . +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: %Bundle-Vendor +Bundle-Activator: org.eclipse.linuxtools.ctf.core.tests.CtfCoreTestPlugin diff --git a/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/.gitignore b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/.gitignore new file mode 100644 index 0000000000..60a0fcc641 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/.gitignore @@ -0,0 +1,5 @@ +/kernel-1 +/kernel-3 +/trace20m +/kernel.txt +/kernel-2 diff --git a/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/gen.sh b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/gen.sh new file mode 100755 index 0000000000..ad503f9844 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/gen.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +if [ $EUID -ne 0 ] +then + echo "Must be run as root" + exit +fi + +if [ $# -ne 2 ] +then + echo "Need 2 arguments, the output folder and the size in MB."; + exit +fi + +path=$1 +size=$2 + +if [ -d $path ]; then + echo "Directory already exists, aborting." + exit 1 +fi + +lttng create -o "$path" + +lttng enable-event -k -a + +lttng start + +echo "Trace started. Do something to generate events." + +while [ $(du --summarize "$path" | cut -f 1) -lt $(($size * 1024)) ] +do + sleep 1 +done + +lttng stop + +lttng destroy + +echo "Final size : " $(du -sh $path) + +if [ -n "$SUDO_USER" ]; then + user=$SUDO_USER + group=$(id -ng $user) + + while true; do + read -p "Do 'chown -Rv $user:$group $path' ? [y/n]" yesno + case $yesno in + [Yy]* ) + chown -Rv $user:$group $path + break; + ;; + [Nn]* ) + break; + ;; + esac + done +fi + diff --git a/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace100m.sh b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace100m.sh new file mode 100755 index 0000000000..5b3da1f2c7 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace100m.sh @@ -0,0 +1 @@ +wget http://nova.polymtl.ca/~simark/trace100m.tgz -O- | tar -xvzf - diff --git a/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m.sh b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m.sh new file mode 100755 index 0000000000..79ad1ebea6 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m.sh @@ -0,0 +1 @@ +wget http://nova.polymtl.ca/~simark/trace20m.tgz -O- | tar -xvzf - diff --git a/org.eclipse.linuxtools.ctf.core.tests/build.properties b/org.eclipse.linuxtools.ctf.core.tests/build.properties new file mode 100644 index 0000000000..b9fc254dd6 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/build.properties @@ -0,0 +1,7 @@ +source.. = src/,\ + Tests/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + Tests/ diff --git a/org.eclipse.linuxtools.ctf.core.tests/plugin.properties b/org.eclipse.linuxtools.ctf.core.tests/plugin.properties new file mode 100644 index 0000000000..d5a36b0dc2 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.linuxtools.tmf.tests +Bundle-Vendor = Eclipse Linux Tools +Bundle-Name = CTF Core Unit Test Suite \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/pom.xml b/org.eclipse.linuxtools.ctf.core.tests/pom.xml new file mode 100644 index 0000000000..d023d87dfc --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + + linuxtools-lttng-parent + org.eclipse.linuxtools.lttng + 0.10.0-SNAPSHOT + + + Linux Tools LTTng CTF Core Unit Test Suite + org.eclipse.linuxtools.ctf + org.eclipse.linuxtools.ctf.core.tests + 0.1.0-SNAPSHOT + eclipse-test-plugin + + + + + + src + + **/*.java + + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + org.eclipse.linuxtools.ctf.core.tests + org.eclipse.linuxtools.ctf.core.tests.AllCtfCoreTests + false + false + org.eclipse.sdk.ide + + + + + + diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java new file mode 100644 index 0000000000..6f01e38fd3 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java @@ -0,0 +1,41 @@ +package org.eclipse.linuxtools.ctf.core.tests; + +import org.junit.runner.JUnitCore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The class TestAll builds a suite that can be used to run all of + * the tests within its package as well as within any subpackages of its + * package. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ CtfCorePluginTest.class, + org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class, + org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class, + org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class, + org.eclipse.linuxtools.ctf.core.tests.trace.UtilsTest.class, + org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class, + +}) +public class AllCtfCoreTests { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + // try { + // ProfileMe.prof_s(); + // } catch (Exception e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + JUnitCore.runClasses(new Class[] { AllCtfCoreTests.class }); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCorePluginTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCorePluginTest.java new file mode 100644 index 0000000000..2498dd4ae0 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCorePluginTest.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011, 2010 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.tests; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.ctf.core.CtfCorePlugin; + +/** + * CtfCorePluginTest + *

+ * Test the CTF core plug-in activator + */ +public class CtfCorePluginTest extends TestCase { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // Plug-in instantiation + static final CtfCorePlugin fPlugin = CtfCorePlugin.getDefault(); + + // ------------------------------------------------------------------------ + // Housekeping + // ------------------------------------------------------------------------ + + /** + * @param name + * the test name + */ + public CtfCorePluginTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ------------------------------------------------------------------------ + // Test cases + // ------------------------------------------------------------------------ + + public static void testCtfCorePluginId() { + assertEquals( + "Plugin ID", "org.eclipse.linuxtools.ctf", CtfCorePlugin.PLUGIN_ID); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public static void testGetDefault() { + CtfCorePlugin plugin = CtfCorePlugin.getDefault(); + assertEquals("getDefault()", plugin, fPlugin); //$NON-NLS-1$ + } + + public static void testLog() { + try { + CtfCorePlugin.getDefault().log("Some message"); //$NON-NLS-1$ + } catch (Exception e) { + fail(); + } + } + +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCoreTestPlugin.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCoreTestPlugin.java new file mode 100644 index 0000000000..388a9dcd23 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/CtfCoreTestPlugin.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2011 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.tests; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * TmfCoreTestPlugin + *

+ * The activator class controls the plug-in life cycle + */ +public class CtfCoreTestPlugin extends Plugin { + + // ======================================================================== + // Attributes + // ======================================================================== + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.ctf.core.tests"; //$NON-NLS-1$ + + // The shared instance + private static CtfCoreTestPlugin plugin; + + // ======================================================================== + // Constructors + // ======================================================================== + + /** + * The constructor + */ + public CtfCoreTestPlugin() { + plugin = this; + } + + // ======================================================================== + // Accessors + // ======================================================================== + + /** + * @return the shared instance + */ + public static CtfCoreTestPlugin getPlugin() { + return plugin; + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java new file mode 100644 index 0000000000..45609ecc84 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java @@ -0,0 +1,63 @@ +package org.eclipse.linuxtools.ctf.core.tests; + +import java.io.File; + +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; + +/** + * Here are the definitions common to all the CTF parser tests. + * + * @author alexmont + * + */ +public abstract class TestParams { + + /* Path to test traces */ + private static final String testTracePath1 = "Tests/traces/trace20m"; //$NON-NLS-1$ + private static CTFTrace testTrace1 = null; + private static CTFTrace testTraceFromFile1 = null; + + private static final File emptyFile = new File(""); //$NON-NLS-1$ + private static CTFTrace emptyTrace = null; + + public static File getEmptyFile() { + return emptyFile; + } + + public static CTFTrace getEmptyTrace() { + if (emptyTrace == null) { + try { + emptyTrace = new CTFTrace(""); //$NON-NLS-1$ + } catch (CTFReaderException e) { + /* We know this trace should exist */ + throw new RuntimeException(e); + } + } + return emptyTrace; + } + + public static CTFTrace createTrace() { + if (testTrace1 == null) { + try { + testTrace1 = new CTFTrace(testTracePath1); + } catch (CTFReaderException e) { + /* We know this trace should exist */ + throw new RuntimeException(e); + } + } + return testTrace1; + } + + public static CTFTrace createTraceFromFile() { + if (testTraceFromFile1 == null) { + try { + testTraceFromFile1 = new CTFTrace(new File(testTracePath1)); + } catch (CTFReaderException e) { + /* We know this trace should exist */ + throw new RuntimeException(e); + } + } + return testTraceFromFile1; + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java new file mode 100644 index 0000000000..e4f4f58597 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java @@ -0,0 +1,180 @@ +package org.eclipse.linuxtools.ctf.core.tests.event; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class CTFEventFieldTest contains tests for the class + * {@link CTFEventField}. + * + * @author ematkho + * @version $Revision: 1.0 $ + * @param + */ +public class CTFEventFieldTest { + + private static final String fieldName = "id"; //$NON-NLS-1$ + + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(CTFEventFieldTest.class); + } + + /** + * Run the CTFEventField parseField(Definition,String) method test. + */ + @Test + public void testParseField_complex() { + int len = 32; + IntegerDeclaration id = new IntegerDeclaration(len, false, len, + ByteOrder.LITTLE_ENDIAN, Encoding.ASCII); + String lengthName = "LengthName"; //$NON-NLS-1$ + StructDeclaration structDec = new StructDeclaration(0); + structDec.addField(lengthName, id); + StructDefinition structDef = new StructDefinition(structDec, null, + lengthName); + + structDef.lookupInteger(lengthName).setValue(32); + SequenceDeclaration sd = new SequenceDeclaration(lengthName, id); + Definition fieldDef = new SequenceDefinition(sd, structDef, "TestX"); //$NON-NLS-1$ + ByteBuffer byb = ByteBuffer.allocate(1024); + for (int i = 0; i < 1024; i++) { + byb.put((byte) i); + } + BitBuffer bb = new BitBuffer(byb); + fieldDef.read(bb); + + assertNotNull(fieldDef); + } + + /** + * Run the CTFEventField parseField(Definition,String) method test. + */ + @Test + public void testParseField_simple() { + Definition fieldDef = new SequenceDefinition(new SequenceDeclaration( + "", new StringDeclaration()), null, fieldName); //$NON-NLS-1$ + + assertNotNull(fieldDef); + } + + /** + * Run the CTFEventField parseField(Definition,String) method test. + */ + @Test + public void testParseField_simple2() { + IntegerDefinition fieldDef = new IntegerDefinition( + new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN, + Encoding.ASCII), null, fieldName); + fieldDef.setValue(1L); + + assertNotNull(fieldDef); + } + + /** + * + */ + @Test + public void testParseField_simple3() { + StringDefinition fieldDef = new StringDefinition( + new StringDeclaration(), null, fieldName); + fieldDef.setString(new StringBuilder("Hello World")); //$NON-NLS-1$ + + String other = fieldName + "=Hello World"; //$NON-NLS-1$ + assertNotNull(fieldDef); + assertEquals(fieldDef.toString(), other); + } + + /** + * Run the CTFEventField parseField(Definition,String) method test. + */ + @Test + public void testParseField_manual() { + Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(20, + new IntegerDeclaration(8, false, 8, null, Encoding.UTF8)), + null, fieldName); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[2]).setValue('l'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[3]).setValue('l'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[4]).setValue('o'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[5]).setValue(' '); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[6]).setValue('W'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[7]).setValue('o'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[8]).setValue('r'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[9]).setValue('l'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[10]).setValue('d'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[11]).setValue(0); + + assertNotNull(fieldDef); + } + + /** + * Run the CTFEventField parseField(Definition,String) method test. + */ + @Test + public void testParseField_manual2() { + Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(12, + new IntegerDeclaration(32, false, 32, null, null)), null, + fieldName); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[2]).setValue('l'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[3]).setValue('l'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[4]).setValue('o'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[5]).setValue(' '); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[6]).setValue('W'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[7]).setValue('o'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[8]).setValue('r'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[9]).setValue('l'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[10]).setValue('d'); + ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[11]).setValue(0); + + assertNotNull(fieldDef); + String other = fieldName + + "={ 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0}"; //$NON-NLS-1$ + assertEquals(other, fieldDef.toString()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java new file mode 100644 index 0000000000..814ce63456 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java @@ -0,0 +1,28 @@ +package org.eclipse.linuxtools.ctf.core.tests.event; + +import org.junit.runner.JUnitCore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The class TestAll builds a suite that can be used to run all of + * the tests within its package as well as within any subpackages of its + * package. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ }) +public class TestAll { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + JUnitCore.runClasses(new Class[] { TestAll.class }); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java new file mode 100644 index 0000000000..aedef19959 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java @@ -0,0 +1,290 @@ +package org.eclipse.linuxtools.ctf.core.tests.io; + +import static org.junit.Assert.assertEquals; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Part of the BitBuffet tests with test the methods to read/write integers. + * These are separated from the main file because the fixture is different. + * + * @author alexmont + * + */ +public class BitBufferIntTest { + + private BitBuffer fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(BitBufferTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + fixture.setByteOrder(ByteOrder.BIG_ENDIAN); + createBuffer(fixture); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + private static void createBuffer(BitBuffer fixture) { + createBuffer(fixture, 16); + } + + private static void createBuffer(BitBuffer fixture, int j) { + byte[] bytes = new byte[j]; + for (int i = 0; i < j; i++) { + bytes[i] = (byte) (i % 0xff); + } + fixture.setByteBuffer(ByteBuffer.wrap(bytes)); + fixture.position(1); + } + + /** + * Run the int getInt() method test. + */ + @Test + public void testGetInt_base() { + int result = fixture.getInt(); + assertEquals(0x020406, result); + } + + /** + * Run the int getInt(int) method test. + */ + @Test + public void testGetInt_pos0() { + fixture.position(0); + int result = fixture.getInt(); + assertEquals(0x010203, result); + } + + /** + * Run the int getInt(int,boolean) method test. + */ + @Test + public void testGetInt_pos1() { + fixture.position(1); + int length = 1; + boolean signed = true; + + int result = fixture.getInt(length, signed); + assertEquals(0, result); + } + + /** + * Run the int getInt(int,boolean) method test. + */ + @Test + public void testGetInt_pos2() { + fixture.position(2); + int length = 0; + boolean signed = true; + + int result = fixture.getInt(length, signed); + assertEquals(0, result); + } + + /** + * Run the int getInt(int,int,boolean) method test. + */ + @Test + public void testGetInt_signed() { + fixture.position(1); + int index = 1; + int length = 0; + boolean signed = true; + + int result = fixture.getInt(index, length, signed); + assertEquals(0, result); + } + + /** + * Run the int getInt(int,int,boolean) method test. + */ + @Test + public void testGetInt_signed_length1() { + fixture.position(1); + int index = 1; + int length = 1; + boolean signed = true; + + int result = fixture.getInt(index, length, signed); + assertEquals(0, result); + } + + /** + * Run the int getInt(int,int,boolean) method test with a little-endian + * BitBuffer. + */ + @Test + public void testGetInt_le1() { + BitBuffer le_fixture = new BitBuffer( + java.nio.ByteBuffer.allocateDirect(128)); + le_fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN); + createBuffer(le_fixture); + le_fixture.position(1); + int index = 1; + int length = 24; + int result = le_fixture.getInt(index, length, false); + + /* 0x020100 downshifted */ + assertEquals(0x810080, result); + } + + /** + * Run the int getInt(int,int,boolean) method test with a little-endian + * BitBuffer. + */ + @Test + public void testGetInt_le2() { + BitBuffer le_fixture = new BitBuffer( + java.nio.ByteBuffer.allocateDirect(128)); + le_fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN); + createBuffer(le_fixture); + le_fixture.position(0); + int index = 0; + int length = 24; + int result = le_fixture.getInt(index, length, false); + assertEquals(0x020100, result); + } + + /** + * Run the int getInt(int,boolean) method test and expect an overflow. + */ + @Test(expected = java.nio.BufferOverflowException.class) + public void testGetInt_invalid() { + BitBuffer small_fixture = new BitBuffer( + java.nio.ByteBuffer.allocateDirect(128)); + small_fixture.setByteOrder(ByteOrder.BIG_ENDIAN); + createBuffer(small_fixture, 2); + small_fixture.position(10); + int length = 32; + boolean signed = true; + + int result = small_fixture.getInt(length, signed); + assertEquals(0, result); + } + + /** + * Run the int getInt(int,int,boolean) method test and expect an overflow. + */ + @Test(expected = java.nio.BufferOverflowException.class) + public void testGetInt_invalid2() { + BitBuffer small_fixture = new BitBuffer( + java.nio.ByteBuffer.allocateDirect(128)); + small_fixture.setByteOrder(ByteOrder.BIG_ENDIAN); + createBuffer(small_fixture, 2); + small_fixture.position(1); + int index = 1; + int length = 64; + boolean signed = true; + + int result = small_fixture.getInt(index, length, signed); + assertEquals(0, result); + } + + /** + * Run the void putInt(int) method test. + */ + @Test + public void testPutInt() { + int value = 1; + fixture.position(1); + fixture.putInt(value); + } + + /** + * Run the void putInt(int,int,boolean) method test. + */ + @Test + public void testPutInt_signed() { + int length = 1; + int value = 1; + + fixture.position(1); + fixture.putInt(length, value); + } + + /** + * Run the void putInt(int,int,int,boolean) method test. + */ + @Test + public void testPutInt_length0() { + int index = 1; + int length = 0; + int value = 1; + + fixture.position(1); + fixture.putInt(index, length, value); + } + + /** + * Run the void putInt(int,int,int,boolean) method test. + */ + @Test + public void testPutInt_length1() { + int index = 1; + int length = 1; + int value = 1; + + fixture.position(1); + fixture.putInt(index, length, value); + } + + /** + * Run the void putInt(int) method test. + */ + @Test + public void testPutInt_hex() { + int value = 0x010203; + + fixture.position(1); + fixture.putInt(value); + int read = fixture.getInt(); + assertEquals(value, read); + } + + /** + * Run the void putInt(int,int,int,boolean) method test. + */ + @Test(expected = java.nio.BufferOverflowException.class) + public void testPutInt_invalid() { + BitBuffer fixture2; + fixture2 = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + fixture2.setByteOrder(ByteOrder.BIG_ENDIAN); + createBuffer(fixture2, 4); + fixture2.position(1); + + int index = 16; + int length = 32; + int value = 1; + + fixture2.putInt(index, length, value); + + int read = fixture2.getInt(1, true); + assertEquals(value, read); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java new file mode 100644 index 0000000000..84d01067ab --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java @@ -0,0 +1,207 @@ +package org.eclipse.linuxtools.ctf.core.tests.io; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class BitBufferTest contains tests for the class + * {@link BitBuffer}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class BitBufferTest { + + private BitBuffer fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(BitBufferTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + fixture.setByteOrder(ByteOrder.BIG_ENDIAN); + fixture.setByteBuffer(ByteBuffer.allocate(0)); + fixture.position(1); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the BitBuffer() constructor test. + */ + @Test + public void testBitBuffer() { + BitBuffer result = new BitBuffer(); + + assertNotNull(result); + assertEquals(0, result.position()); + assertEquals(null, result.getByteBuffer()); + } + + /** + * Run the BitBuffer(ByteBuffer) constructor test. + */ + @Test + public void testBitBuffer_fromByteBuffer() { + ByteBuffer buf = ByteBuffer.allocate(0); + BitBuffer result = new BitBuffer(buf); + + assertNotNull(result); + assertEquals(0, result.position()); + } + + /** + * Run the boolean canRead(int) method test. + */ + @Test + public void testCanRead_1param() { + int length = 1; + boolean result = fixture.canRead(length); + + assertEquals(false, result); + } + + /** + * Run the boolean canRead(int,int) method test. + */ + @Test + public void testCanRead_2params() { + int index = 1; + int length = 1; + boolean result = fixture.canRead(index, length); + + assertEquals(false, result); + } + + /** + * Run the void clear() method test. + */ + @Test + public void testClear() { + fixture.clear(); + } + + /** + * Run the ByteBuffer getByteBuffer() method test. + */ + @Test + public void testGetByteBuffer() { + ByteBuffer result = fixture.getByteBuffer(); + + assertNotNull(result); + assertEquals( + "java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]", result.toString()); //$NON-NLS-1$ + assertEquals(false, result.isDirect()); + assertEquals(true, result.hasArray()); + assertEquals(0, result.arrayOffset()); + assertEquals(0, result.limit()); + assertEquals(0, result.remaining()); + assertEquals(0, result.position()); + assertEquals(0, result.capacity()); + assertEquals(false, result.hasRemaining()); + assertEquals(false, result.isReadOnly()); + } + + /** + * Run the ByteOrder getByteOrder() method test. + */ + @Test + public void testGetByteOrder() { + ByteOrder result = fixture.getByteOrder(); + + assertNotNull(result); + assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$ + } + + /** + * Run the ByteOrder order() method test. + */ + @Test + public void testGetOrder() { + ByteOrder result = fixture.order(); + + assertNotNull(result); + assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$ + } + + /** + * Run the void order(ByteOrder) method test. + */ + @Test + public void testSetOrder() { + ByteOrder order = ByteOrder.BIG_ENDIAN; + + fixture.order(order); + } + + /** + * Run the int position() method test. + */ + @Test + public void testGetPosition() { + int result = fixture.position(); + + assertEquals(1, result); + } + + /** + * Run the void position(int) method test. + */ + @Test + public void testSetPosition() { + int newPosition = 1; + fixture.position(newPosition); + } + + /** + * Run the void setByteBuffer(ByteBuffer) method test. + */ + @Test + public void testSetByteBuffer() { + ByteBuffer buf = ByteBuffer.allocate(0); + fixture.setByteBuffer(buf); + } + + /** + * Run the void setByteBuffer(ByteBuffer) method test. + */ + @Test + public void testSetByteBuffer_null() { + ByteBuffer buf = null; + fixture.setByteBuffer(buf); + } + + /** + * Run the void setByteOrder(ByteOrder) method test. + */ + @Test + public void testSetByteOrder() { + ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; + fixture.setByteOrder(byteOrder); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/TestAll.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/TestAll.java new file mode 100644 index 0000000000..6c02cbe6bb --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/TestAll.java @@ -0,0 +1,28 @@ +package org.eclipse.linuxtools.ctf.core.tests.io; + +import org.junit.runner.JUnitCore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The class TestAll builds a suite that can be used to run all of + * the tests within its package as well as within any subpackages of its + * package. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ BitBufferTest.class, BitBufferIntTest.class }) +public class TestAll { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + JUnitCore.runClasses(new Class[] { TestAll.class }); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java new file mode 100644 index 0000000000..bede1db948 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java @@ -0,0 +1,279 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class CTFTraceReaderTest contains tests for the class + * {@link CTFTraceReader}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class CTFTraceReaderTest { + + CTFTraceReader fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(CTFTraceReaderTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new CTFTraceReader(TestParams.createTrace()); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good + * trace. + */ + @Test + public void testOpen_existing() { + CTFTrace trace = TestParams.createTrace(); + + CTFTraceReader result = new CTFTraceReader(trace); + assertNotNull(result); + } + + /** + * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing + * trace, expect the exception. + * + * @throws CTFReaderException + */ + @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class) + public void testOpen_nonexisting() throws CTFReaderException { + CTFTrace trace = new CTFTrace("badfile.bad"); //$NON-NLS-1$ + + CTFTraceReader result = new CTFTraceReader(trace); + assertNotNull(result); + } + + /** + * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid + * path, expect exception. + * + * @throws CTFReaderException + */ + @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class) + public void testOpen_invalid() throws CTFReaderException { + CTFTrace trace = new CTFTrace(""); //$NON-NLS-1$ + + CTFTraceReader result = new CTFTraceReader(trace); + assertNotNull(result); + } + + /** + * Run the boolean advance() method test. Test advancing normally. + */ + @Test + public void testAdvance_normal() { + boolean result = fixture.advance(); + assertTrue(result); + } + + /** + * Run the boolean advance() method test. Test advancing when we're at the + * end, so we expect that there is no more events. + * + * @throws CTFReaderException + */ + @Test + public void testAdvance_end() throws CTFReaderException { + fixture.goToLastEvent(); + while (fixture.hasMoreEvents()) { + fixture.advance(); + } + boolean result = fixture.advance(); + assertFalse(result); + } + + /** + * Run the CTFTraceReader copy constructor test. + */ + @Test + public void testCopyFrom() { + CTFTraceReader result = fixture.copyFrom(); + assertNotNull(result); + } + + /** + * Test the hashCode method. + */ + @Test + public void testHash() { + int result = fixture.hashCode(); + assertTrue(0 != result); + } + + /** + * Test the equals method. Uses the class-wide 'fixture' and another + * method-local 'fixture2', which both point to the same trace. + * + * Both trace reader are different objects, so they shouldn't "equals" each + * other. + */ + @Test + public void testEquals() { + CTFTraceReader fixture2 = new CTFTraceReader(TestParams.createTrace()); + assertFalse(fixture.equals(fixture2)); + } + + /** + * Run the getCurrentEventDef() method test. Get the first event's + * definition. + */ + @Test + public void testGetCurrentEventDef_first() { + EventDefinition result = fixture.getCurrentEventDef(); + assertNotNull(result); + } + + /** + * Run the getCurrentEventDef() method test. Get the last event's + * definition. + * + * @throws CTFReaderException + */ + @Test + public void testGetCurrentEventDef_last() throws CTFReaderException { + fixture.goToLastEvent(); + EventDefinition result = fixture.getCurrentEventDef(); + assertNotNull(result); + } + + /** + * Run the long getEndTime() method test. + */ + @Test + public void testGetEndTime() { + long result = fixture.getEndTime(); + assertTrue(0L < result); + } + + /** + * Run the long getStartTime() method test. + */ + @Test + public void testGetStartTime() { + long result = fixture.getStartTime(); + assertTrue(0L < result); + } + + /** + * Run the void goToLastEvent() method test. + * + * @throws CTFReaderException + */ + @Test + public void testGoToLastEvent() throws CTFReaderException { + fixture.goToLastEvent(); + long ts1 = fixture.getCurrentEventDef().timestamp; + long ts2 = fixture.getEndTime(); + assertTrue(ts1 == ts2); + } + + /** + * Run the boolean hasMoreEvents() method test. + * + * @throws CTFReaderException + */ + @Test + public void testHasMoreEvents() { + boolean result = fixture.hasMoreEvents(); + assertTrue(result); + } + + /** + * Run the void printStats() method test with no 'width' parameter. + */ + @Test + public void testPrintStats_noparam() { + fixture.advance(); + fixture.printStats(); + } + + /** + * Run the void printStats(int) method test with width = 0. + */ + @Test + public void testPrintStats_width0() { + fixture.advance(); + fixture.printStats(0); + } + + /** + * Run the void printStats(int) method test with width = 1. + */ + @Test + public void testPrintStats_width1() { + fixture.advance(); + fixture.printStats(1); + } + + /** + * Run the void printStats(int) method test with width = 2. + */ + @Test + public void testPrintStats_width2() { + fixture.advance(); + fixture.printStats(2); + } + + /** + * Run the void printStats(int) method test with width = 10. + */ + @Test + public void testPrintStats_width10() { + fixture.advance(); + fixture.printStats(10); + } + + /** + * Run the void printStats(int) method test with width = 100. + */ + @Test + public void testPrintStats_100() { + for (int i = 0; i < 1000; i++) { + fixture.advance(); + } + fixture.printStats(100); + } + + /** + * Run the boolean seek(long) method test. + */ + @Test + public void testSeek() { + long timestamp = 1L; + boolean result = fixture.seek(timestamp); + assertTrue(result); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java new file mode 100644 index 0000000000..bad5b119c0 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java @@ -0,0 +1,306 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.nio.ByteOrder; +import java.util.Map; +import java.util.UUID; + +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class CTFTraceTest contains tests for the class + * {@link CTFTrace}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class CTFTraceTest { + + private CTFTrace fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(CTFTraceTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = TestParams.createTraceFromFile(); + fixture.setMinor(1L); + fixture.setUUID(UUID.randomUUID()); + fixture.setPacketHeader(new StructDeclaration(1L)); + fixture.setMajor(1L); + fixture.setByteOrder(ByteOrder.BIG_ENDIAN); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the CTFTrace(File) constructor test with a known existing trace. + */ + @Test + public void testOpen_existing() { + CTFTrace result = TestParams.createTraceFromFile(); + assertNotNull(result.getUUID()); + } + + /** + * Run the CTFTrace(File) constructor test with an invalid path. + * + * @throws CTFReaderException + */ + @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class) + public void testOpen_invalid() throws CTFReaderException { + File path = new File(""); //$NON-NLS-1$ + CTFTrace result = new CTFTrace(path); + assertNotNull(result); + } + + /** + * Run the boolean UUIDIsSet() method test. + */ + @Test + public void testUUIDIsSet() { + boolean result = fixture.UUIDIsSet(); + assertTrue(result); + } + + /** + * Run the void addStream(Stream) method test. + * + * @throws ParseException + */ + @Test + public void testAddStream() throws ParseException { + Stream stream = new Stream(TestParams.createTrace()); + stream.setId(1L); + fixture.addStream(stream); + } + + /** + * Run the boolean byteOrderIsSet() method test. + */ + @Test + public void testByteOrderIsSet() { + boolean result = fixture.byteOrderIsSet(); + assertTrue(result); + } + + /** + * Run the ByteOrder getByteOrder() method test. + */ + @Test + public void testGetByteOrder_1() { + ByteOrder result = fixture.getByteOrder(); + assertNotNull(result); + } + + /** + * Run the long getMajor() method test. + */ + @Test + public void testGetMajor() { + long result = fixture.getMajor(); + assertEquals(1L, result); + } + + /** + * Run the long getMinor() method test. + */ + @Test + public void testGetMinor() { + long result = fixture.getMinor(); + assertEquals(1L, result); + } + + /** + * Run the StructDeclaration getPacketHeader() method test. + */ + @Test + public void testGetPacketHeader() { + StructDeclaration result = fixture.getPacketHeader(); + assertNotNull(result); + } + + /** + * Run the String getPath() method test. + */ + @Test + public void testGetPath() { + String result = fixture.getPath(); + assertNotNull(result); + } + + /** + * Run the Stream getStream(Long) method test. + */ + @Test + public void testGetStream() { + Long id = new Long(0L); + Stream result = fixture.getStream(id); + assertNotNull(result); + } + + /** + * Run the Map getStreams() method test. + */ + @Test + public void testGetStreams() { + Map result = fixture.getStreams(); + assertNotNull(result); + } + + /** + * Run the File getTraceDirectory() method test. + */ + @Test + public void testGetTraceDirectory() { + File result = fixture.getTraceDirectory(); + assertNotNull(result); + } + + /** + * Run the UUID getUUID() method test. + */ + @Test + public void testGetUUID() { + UUID result = fixture.getUUID(); + assertNotNull(result); + } + + /** + * Run the Definition lookupDefinition(String) method test. + */ + @Test + public void testLookupDefinition() { + String lookupPath = "trace.packet.header"; //$NON-NLS-1$ + Definition result = fixture.lookupDefinition(lookupPath); + assertNotNull(result); + } + + /** + * Run the boolean majortIsSet() method test. + */ + @Test + public void testMajortIsSet() { + boolean result = fixture.majortIsSet(); + assertTrue(result); + } + + /** + * Run the boolean minorIsSet() method test. + */ + @Test + public void testMinorIsSet() { + boolean result = fixture.minorIsSet(); + assertTrue(result); + } + + /** + * Run the int nbStreams() method test. + */ + @Test + public void testNbStreams() { + int result = fixture.nbStreams(); + assertEquals(2, result); + } + + /** + * Run the boolean packetHeaderIsSet() method test with a valid header set. + */ + @Test + public void testPacketHeaderIsSet_valid() { + boolean result = fixture.packetHeaderIsSet(); + assertTrue(result); + } + + /** + * Run the boolean packetHeaderIsSet() method test, without having a valid + * header set. + */ + @Test + public void testPacketHeaderIsSet_invalid() { + CTFTrace fixture2 = TestParams.createTraceFromFile(); + fixture2.setMinor(1L); + fixture2.setUUID(UUID.randomUUID()); + fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */ + fixture2.setMajor(1L); + fixture2.setByteOrder(ByteOrder.BIG_ENDIAN); + + boolean result = fixture2.packetHeaderIsSet(); + assertFalse(result); + } + + /** + * Run the void setByteOrder(ByteOrder) method test. + */ + @Test + public void testSetByteOrder() { + ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; + fixture.setByteOrder(byteOrder); + } + + /** + * Run the void setMajor(long) method test. + */ + @Test + public void testSetMajor() { + long major = 1L; + fixture.setMajor(major); + } + + /** + * Run the void setMinor(long) method test. + */ + @Test + public void testSetMinor() { + long minor = 1L; + fixture.setMinor(minor); + } + + /** + * Run the void setPacketHeader(StructDeclaration) method test. + */ + @Test + public void testSetPacketHeader() { + StructDeclaration packetHeader = new StructDeclaration(1L); + fixture.setPacketHeader(packetHeader); + } + + /** + * Run the void setUUID(UUID) method test. + */ + @Test + public void testSetUUID() { + UUID uuid = UUID.randomUUID(); + fixture.setUUID(uuid); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java new file mode 100644 index 0000000000..077ad141d2 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java @@ -0,0 +1,78 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.Metadata; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class MetadataTest contains tests for the class + * {@link Metadata}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class MetadataTest { + + private Metadata fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(MetadataTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new Metadata(TestParams.createTrace()); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the Metadata(CTFTrace) constructor test. + */ + @Test + public void testMetadata() { + assertNotNull(fixture); + } + + /** + * Run the ByteOrder getDetectedByteOrder() method test. + */ + @Test + public void testGetDetectedByteOrder() { + ByteOrder result = fixture.getDetectedByteOrder(); + assertNull(result); + } + + /** + * Run the void parse() method test. + * + * @throws CTFReaderException + */ + @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class) + public void testParse() throws CTFReaderException { + fixture.parse(); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java new file mode 100644 index 0000000000..c661d262b9 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java @@ -0,0 +1,78 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StreamInputPacketIndexEntryTest contains tests for the + * class {@link StreamInputPacketIndexEntry}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputPacketIndexEntryTest { + + private StreamInputPacketIndexEntry fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputPacketIndexEntryTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new StreamInputPacketIndexEntry(1L); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StreamInputPacketIndexEntry(long) constructor test. + */ + @Test + public void testStreamInputPacketIndexEntry_1() { + String expectedResult = "PacketIndexEntry [offset=1, " + //$NON-NLS-1$ + "timestampBegin=0, timestampEnd=0, " + //$NON-NLS-1$ + "dataOffset=0, packetSize=0, contentSize=0]"; //$NON-NLS-1$ + + assertNotNull(fixture); + assertEquals(expectedResult, fixture.toString()); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String expectedResult = "PacketIndexEntry [offset=1, " + //$NON-NLS-1$ + "timestampBegin=1, timestampEnd=1, " + //$NON-NLS-1$ + "dataOffset=1, packetSize=1, contentSize=1]"; //$NON-NLS-1$ + + fixture.contentSizeBits = 1; + fixture.dataOffsetBits = 1; + fixture.timestampEnd = 1L; + fixture.packetSizeBits = 1; + fixture.timestampBegin = 1L; + + assertEquals(expectedResult, fixture.toString()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java new file mode 100644 index 0000000000..e0e3ad1ef8 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java @@ -0,0 +1,173 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Collection; +import java.util.ListIterator; + +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StreamInputPacketIndexTest contains tests for the + * class {@link StreamInputPacketIndex}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputPacketIndexTest { + + private StreamInputPacketIndex fixture; + private StreamInputPacketIndexEntry entry; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputPacketIndexTest.class); + } + + /** + * Perform pre-test initialization. + * + * @throws CTFReaderException + */ + @Before + public void setUp() throws CTFReaderException { + fixture = new StreamInputPacketIndex(); + fixture.addEntry(new StreamInputPacketIndexEntry(1L)); + entry = new StreamInputPacketIndexEntry(1L); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StreamInputPacketIndex() constructor test. + */ + @Test + public void testStreamInputPacketIndex() { + assertNotNull(fixture); + } + + /** + * Run the void addEntry(StreamInputPacketIndexEntry) method test, by + * specifying only 1 parameter to the entry. + * + * @throws CTFReaderException + */ + @Test + public void testAddEntry_1param() throws CTFReaderException { + entry.packetSizeBits = 0; + fixture.addEntry(entry); + } + + /** + * Run the void addEntry(StreamInputPacketIndexEntry) method test by + * specifying 2 parameters to the entry. + * + * @throws CTFReaderException + */ + @Test + public void testAddEntry_2params() throws CTFReaderException { + entry.packetSizeBits = 1; + entry.contentSizeBits = 0; + fixture.addEntry(entry); + } + + /** + * Run the void addEntry(StreamInputPacketIndexEntry) method test, by + * specifying all 4 parameters to the entry. + * + * @throws CTFReaderException + */ + @Test + public void testAddEntry_4params() throws CTFReaderException { + entry.timestampBegin = 1L; + entry.packetSizeBits = 1; + entry.contentSizeBits = 1; + entry.timestampEnd = 1L; + fixture.addEntry(entry); + } + + /** + * Run the Collection getEntries() method test. + */ + @Test + public void testGetEntries() { + Collection result = fixture.getEntries(); + + assertNotNull(result); + assertEquals(1, result.size()); + } + + /** + * Run the ListIterator listIterator() method + * test, with no parameter to listIterator(). + */ + @Test + public void testListIterator_noparam() { + ListIterator result = fixture.listIterator(); + + assertNotNull(result); + assertEquals(true, result.hasNext()); + assertEquals(-1, result.previousIndex()); + assertEquals(false, result.hasPrevious()); + assertEquals(0, result.nextIndex()); + } + + /** + * Run the ListIterator listIterator(n) method + * test, with n = 1. + */ + @Test + public void testListIterator_withparam() { + ListIterator result = fixture.listIterator(1); + + assertNotNull(result); + assertEquals(false, result.hasNext()); + assertEquals(0, result.previousIndex()); + assertEquals(true, result.hasPrevious()); + assertEquals(1, result.nextIndex()); + assertEquals(false, result.hasNext()); + } + + /** + * Run the ListIterator search(long) method + * test with a valid timestamp. + */ + @Test + public void testSearch_valid() { + ListIterator result = fixture.search(1L); + + assertNotNull(result); + assertEquals(true, result.hasNext()); + assertEquals(-1, result.previousIndex()); + assertEquals(false, result.hasPrevious()); + assertEquals(0, result.nextIndex()); + } + + /** + * Run the ListIterator search(long) method + * test with an invalid timestamp. + */ + @Test(expected = java.lang.IllegalArgumentException.class) + public void testSearch_invalid() { + ListIterator result = fixture.search(-1L); + + assertNotNull(result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java new file mode 100644 index 0000000000..b8aee7bcd3 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java @@ -0,0 +1,188 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.channels.FileChannel; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketReader; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.junit.*; + +/** + * The class StreamInputPacketReaderTest contains tests for the + * class {@link StreamInputPacketReader}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputPacketReaderTest { + + private StreamInputPacketReader fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputPacketReaderTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + // FIXME The test is broken here. "FileChannel" can't be null because we + // need it further in. Heck this whole thing shouldn't be public in the + // first place, perhaps fixing that is the best way to go. + fixture = new StreamInputPacketReader(new StreamInputReader( + new StreamInput(new Stream(TestParams.createTrace()), + (FileChannel) null, TestParams.getEmptyFile()))); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StreamInputPacketReader(StreamInputReader) constructor test. + */ + @Test + public void testStreamInputPacketReader() { + StreamInputReader streamInputReader; + StreamInputPacketReader result; + + streamInputReader = new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile())); + + result = new StreamInputPacketReader(streamInputReader); + + assertNotNull(result); + } + + /** + * Run the int getCPU() method test. + */ + @Test + public void testGetCPU() { + int result = fixture.getCPU(); + assertEquals(0, result); + } + + /** + * Run the StreamInputPacketIndexEntry getCurrentPacket() method test. + */ + @Test + public void testGetCurrentPacket() { + StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(1L); + fixture.setCurrentPacket(sipie); + StreamInputPacketIndexEntry result = fixture.getCurrentPacket(); + assertNotNull(result); + } + + /** + * Run the String getPath() method test. + */ + @Test + public void testGetPath() { + String result = fixture.getPath(); + assertNotNull(result); + } + + /** + * Run the StructDefinition getStreamPacketContextDef() method test. + */ + @Test + public void testGetStreamPacketContextDef() { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + StructDefinition result = fixture.getStreamPacketContextDef(); + assertNotNull(result); + } + + /** + * Run the boolean hasMoreEvents() method test. + */ + @Test + public void testHasMoreEvents() { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + boolean result = fixture.hasMoreEvents(); + assertTrue(result); + } + + /** + * Run the Definition lookupDefinition(String) method test. + */ + @Test + public void testLookupDefinition() { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + String lookupPath = ""; //$NON-NLS-1$ + Definition result = fixture.lookupDefinition(lookupPath); + assertNotNull(result); + } + + /** + * Run the EventDefinition readNextEvent() method test. + * + * @throws CTFReaderException + */ + @Test + public void testReadNextEvent() throws CTFReaderException { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + EventDefinition result = fixture.readNextEvent(); + assertNotNull(result); + } + + /** + * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. + */ + @Test + public void testSetCurrentPacket() { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry( + 1L); + currentPacket.packetSizeBits = 1; + fixture.setCurrentPacket(currentPacket); + } + + /** + * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. + */ + @Test + public void testSetCurrentPacket_2() throws Exception { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + StreamInputPacketIndexEntry currentPacket = null; + fixture.setCurrentPacket(currentPacket); + + } + + /** + * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. + */ + @Test + public void testSetCurrentPacket_3() { + fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); + StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry( + 1L); + currentPacket.timestampBegin = 1L; + currentPacket.packetSizeBits = 1; + + fixture.setCurrentPacket(currentPacket); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java new file mode 100644 index 0000000000..27280c4b23 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java @@ -0,0 +1,93 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.channels.FileChannel; +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReaderComparator; +import org.junit.*; + +/** + * The class StreamInputReaderComparatorTest contains tests for the + * class {@link StreamInputReaderComparator}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputReaderComparatorTest { + + private StreamInputReaderComparator fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputReaderComparatorTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new StreamInputReaderComparator(); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StreamInputReaderComparator() constructor test. + */ + @Test + public void testStreamInputReaderComparator() { + assertNotNull(fixture); + } + + /** + * Run the int compare(StreamInputReader,StreamInputReader) method test. + */ + @Test + public void testCompare() { + StreamInputReader sir1, sir2; + EventDefinition ed1, ed2; + + sir1 = new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile())); + ed1 = new EventDefinition(new EventDeclaration(), + new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile()))); + ed1.timestamp = 1L; + sir1.setCurrentEvent(ed1); + + sir2 = new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile())); + ed2 = new EventDefinition(new EventDeclaration(), + new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile()))); + + ed2.timestamp = 1L; + sir2.setCurrentEvent(ed2); + + int result = fixture.compare(sir1, sir2); + assertEquals(0, result); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java new file mode 100644 index 0000000000..4ecd4be998 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java @@ -0,0 +1,189 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.channels.FileChannel; +import java.util.Set; + +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StreamInputReaderTest contains tests for the class + * {@link StreamInputReader}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputReaderTest { + + private StreamInputReader fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputReaderTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = createStreamInputReader(); + fixture.setName(1); + fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(), + createStreamInputReader())); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + private static StreamInputReader createStreamInputReader() { + CTFTrace trace = TestParams.createTrace(); + Stream s = trace.getStream((long) 0); + Set streamInput = s.getStreamInputs(); + StreamInputReader retVal = null; + for (StreamInput si : streamInput) { + /* + * For the tests, we'll use the stream input corresponding to the + * CPU 0 + */ + if (si.getFilename().endsWith("0_0")) { //$NON-NLS-1$ + retVal = new StreamInputReader(si); + break; + } + } + return retVal; + } + + /** + * Run the StreamInputReader(StreamInput) constructor test, with a valid + * trace. + */ + @Test + public void testStreamInputReader_valid() { + assertNotNull(fixture); + } + + /** + * Run the StreamInputReader(StreamInput) constructor test, with an invalid + * trace. + * + * @throws CTFReaderException + */ + @Test(expected = CTFReaderException.class) + public void testStreamInputReader_invalid() throws CTFReaderException { + StreamInput streamInput = new StreamInput( + new Stream(new CTFTrace("")), (FileChannel) null, TestParams.getEmptyFile()); //$NON-NLS-1$ + + StreamInputReader result = new StreamInputReader(streamInput); + assertNotNull(result); + } + + /** + * Run the int getCPU() method test. + */ + @Test + public void testGetCPU() { + int result = fixture.getCPU(); + assertEquals(0, result); + } + + /** + * Run the EventDefinition getCurrentEvent() method test. + */ + @Test + public void testGetCurrentEvent() { + EventDefinition result = fixture.getCurrentEvent(); + assertNotNull(result); + } + + /** + * Run the StructDefinition getCurrentPacketContext() method test. + */ + @Test + public void testGetCurrentPacketContext() { + StructDefinition result = fixture.getCurrentPacketContext(); + assertNotNull(result); + } + + /** + * Run the int getName() method test. + */ + @Test + public void testGetName() { + int result = fixture.getName(); + assertEquals(1, result); + } + + /** + * Run the StreamInput getStreamInput() method test. + */ + @Test + public void testGetStreamInput() { + StreamInput result = fixture.getStreamInput(); + assertNotNull(result); + } + + /** + * Run the void goToLastEvent() method test. + * + * @throws CTFReaderException + */ + @Test + public void testGoToLastEvent() throws CTFReaderException { + fixture.goToLastEvent(); + } + + /** + * Run the boolean readNextEvent() method test. + */ + @Test + public void testReadNextEvent() { + boolean result = fixture.readNextEvent(); + assertTrue(result); + } + + /** + * Run the void seek(long) method test. Seek by direct timestamp + */ + @Test + public void testSeek_timestamp() { + long timestamp = 1L; + fixture.seek(timestamp); + } + + /** + * Run the seek test. Seek by passing an EventDefinition to which we've + * given the timestamp we want. + */ + @Test + public void testSeek_eventDefinition() { + EventDefinition eventDefinition = new EventDefinition( + new EventDeclaration(), createStreamInputReader()); + eventDefinition.timestamp = 1L; + fixture.setCurrentEvent(eventDefinition); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java new file mode 100644 index 0000000000..d17099eade --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java @@ -0,0 +1,77 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.channels.FileChannel; + +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReaderTimestampComparator; +import org.junit.*; + +/** + * The class StreamInputReaderTimestampComparatorTest contains + * tests for the class {@link StreamInputReaderTimestampComparator} + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputReaderTimestampComparatorTest { + + private StreamInputReaderTimestampComparator fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputReaderTimestampComparatorTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new StreamInputReaderTimestampComparator(); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StreamInputReaderTimestampComparator() constructor test. + */ + @Test + public void testStreamInputReaderTimestampComparator_1() throws Exception { + assertNotNull(fixture); + } + + /** + * Run the int compare(StreamInputReader,StreamInputReader) method test. + */ + @Test + public void testCompare() { + StreamInputReader a, b; + a = new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile())); + a.setCurrentEvent(null); + b = new StreamInputReader(new StreamInput(new Stream( + TestParams.createTrace()), (FileChannel) null, + TestParams.getEmptyFile())); + + int result = fixture.compare(a, b); + assertEquals(0, result); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java new file mode 100644 index 0000000000..84686a073a --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java @@ -0,0 +1,140 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.nio.channels.FileChannel; + +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StreamInputTest contains tests for the class + * {@link StreamInput}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamInputTest { + + private StreamInput fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamInputTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new StreamInput(new Stream(TestParams.createTrace()), + (FileChannel) null, createFile()); + fixture.setTimestampEnd(1L); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + private static File createFile() { + return new File("Tests/traces/trace20m/channel_0"); //$NON-NLS-1$ + } + + /** + * Run the StreamInput(Stream,FileChannel,File) constructor test. + */ + @Test + public void testStreamInput() { + assertNotNull(fixture); + } + + /** + * Run the FileChannel getFileChannel() method test. + */ + @Test + public void testGetFileChannel() { + FileChannel result = fixture.getFileChannel(); + assertNull(result); + } + + /** + * Run the String getFilename() method test. + */ + @Test + public void testGetFilename() { + String result = fixture.getFilename(); + assertNotNull(result); + } + + /** + * Run the StreamInputPacketIndex getIndex() method test. + */ + @Test + public void testGetIndex() { + StreamInputPacketIndex result = fixture.getIndex(); + assertNotNull(result); + } + + /** + * Run the String getPath() method test. + */ + @Test + public void testGetPath() { + String result = fixture.getPath(); + assertNotNull(result); + } + + /** + * Run the Stream getStream() method test. + */ + @Test + public void testGetStream() { + Stream result = fixture.getStream(); + assertNotNull(result); + } + + /** + * Run the long getTimestampEnd() method test. + */ + @Test + public void testGetTimestampEnd() { + long result = fixture.getTimestampEnd(); + assertTrue(0L < result); + } + + /** + * Run the Definition lookupDefinition(String) method test. + */ + @Test + public void testLookupDefinition() { + Definition result = fixture.lookupDefinition("id"); //$NON-NLS-1$ + assertNull(result); + } + + /** + * Run the void setTimestampEnd(long) method test. + */ + @Test + public void testSetTimestampEnd() { + fixture.setTimestampEnd(1L); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java new file mode 100644 index 0000000000..b0b2a5dd20 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java @@ -0,0 +1,230 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.channels.FileChannel; +import java.util.HashMap; +import java.util.Set; + +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StreamTest contains tests for the class + * {@link Stream}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StreamTest { + + private Stream fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StreamTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new Stream(TestParams.createTrace()); + fixture.setEventContext(new StructDeclaration(1L)); + fixture.setPacketContext(new StructDeclaration(1L)); + fixture.setEventHeader(new StructDeclaration(1L)); + fixture.setId(1L); + fixture.addInput(new StreamInput(new Stream(TestParams.createTrace()), + (FileChannel) null, TestParams.getEmptyFile())); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the Stream(CTFTrace) constructor test. + */ + @Test + public void testStream() { + CTFTrace trace = TestParams.createTrace(); + Stream result = new Stream(trace); + assertNotNull(result); + } + + /** + * Run the void addEvent(EventDeclaration) method test with the basic + * event. + * @throws ParseException + */ + @Test + public void testAddEvent_base() throws ParseException { + EventDeclaration event = new EventDeclaration(); + fixture.addEvent(event); + } + + /** + * Run the void addEvent(EventDeclaration) method test with an event + * of which we modified the id. + * @throws ParseException + * + * @throws ParseException + */ + @Test + public void testAddEvent_modifiedEvent() throws ParseException { + EventDeclaration event = new EventDeclaration(); + event.setId(1L); + fixture.addEvent(event); + } + + /** + * Run the boolean eventContextIsSet() method test. + */ + @Test + public void testEventContextIsSet() { + assertTrue(fixture.eventContextIsSet()); + } + + /** + * Run the boolean eventHeaderIsSet() method test. + */ + @Test + public void testEventHeaderIsSet() { + assertTrue(fixture.eventHeaderIsSet()); + } + + /** + * Run the StructDeclaration getEventContextDecl() method test. + */ + @Test + public void testGetEventContextDecl() { + assertNotNull(fixture.getEventContextDecl()); + } + + /** + * Run the StructDeclaration getEventHeaderDecl() method test. + */ + @Test + public void testGetEventHeaderDecl() { + assertNotNull(fixture.getEventHeaderDecl()); + } + + /** + * Run the HashMap getEvents() method test. + */ + @Test + public void testGetEvents() { + HashMap result = fixture.getEvents(); + assertNotNull(result); + } + + /** + * Run the Long getId() method test. + */ + @Test + public void testGetId() { + Long result = fixture.getId(); + assertNotNull(result); + } + + /** + * Run the StructDeclaration getPacketContextDecl() method test. + */ + @Test + public void testGetPacketContextDecl() { + StructDeclaration result = fixture.getPacketContextDecl(); + assertNotNull(result); + } + + /** + * Run the Set getStreamInputs() method test. + */ + @Test + public void testGetStreamInputs() { + Set result = fixture.getStreamInputs(); + assertNotNull(result); + } + + /** + * Run the CTFTrace getTrace() method test. + */ + @Test + public void testGetTrace() { + CTFTrace result = fixture.getTrace(); + assertNotNull(result); + } + + /** + * Run the boolean idIsSet() method test. + */ + @Test + public void testIdIsSet() { + boolean result = fixture.idIsSet(); + assertTrue(result); + } + + /** + * Run the boolean packetContextIsSet() method test. + */ + @Test + public void testPacketContextIsSet() { + boolean result = fixture.packetContextIsSet(); + assertTrue(result); + } + + + /** + * Run the void setEventContext(StructDeclaration) method test. + */ + @Test + public void testSetEventContext() { + StructDeclaration eventContext = new StructDeclaration(1L); + fixture.setEventContext(eventContext); + } + + /** + * Run the void setEventHeader(StructDeclaration) method test. + */ + @Test + public void testSetEventHeader() { + StructDeclaration eventHeader = new StructDeclaration(1L); + fixture.setEventHeader(eventHeader); + } + + /** + * Run the void setId(long) method test. + */ + @Test + public void testSetId() { + long id = 1L; + fixture.setId(id); + } + + /** + * Run the void setPacketContext(StructDeclaration) method test. + */ + @Test + public void testSetPacketContext() { + StructDeclaration packetContext = new StructDeclaration(1L); + fixture.setPacketContext(packetContext); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/TestAll.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/TestAll.java new file mode 100644 index 0000000000..f2e3a982dd --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/TestAll.java @@ -0,0 +1,37 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import org.junit.runner.JUnitCore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The class TestAll builds a suite that can be used to run all of + * the tests within its package as well as within any subpackages of its + * package. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CTFTraceReaderTest.class, + StreamInputTest.class, + StreamInputReaderTimestampComparatorTest.class, + StreamInputReaderTest.class, + StreamInputReaderComparatorTest.class, + // StreamInputPacketReaderTest.class, + StreamInputPacketIndexEntryTest.class, + StreamInputPacketIndexTest.class, StreamTest.class, CTFTraceTest.class, + MetadataTest.class, }) +public class TestAll { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + JUnitCore.runClasses(new Class[] { TestAll.class }); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/UtilsTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/UtilsTest.java new file mode 100644 index 0000000000..1bb13f7122 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/UtilsTest.java @@ -0,0 +1,121 @@ +package org.eclipse.linuxtools.ctf.core.tests.trace; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.eclipse.linuxtools.ctf.core.trace.Utils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class UtilsTest contains tests for the class + * {@link Utils}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class UtilsTest { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(UtilsTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the Utils() constructor test. + */ + @Test + public void testUtils() { + Utils result = new Utils(); + assertNotNull(result); + } + + /** + * Run the UUID makeUUID(byte[]) method test. + */ + @Test + public void testMakeUUID() { + int byteSize = 32; + byte[] bytes = new byte[byteSize]; + for (int i = 0; i < byteSize; i++) { + bytes[i] = (byte) (i); + } + + UUID result = Utils.makeUUID(bytes); + assertNotNull(result); + } + + /** + * Run the UUID makeUUID(byte[]) method test. + */ + @Test + public void testMakeUUID_2() { + byte[] bytes = new byte[] { (byte) 1, (byte) 1, (byte) 0, (byte) 0, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 1, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }; + + UUID result = Utils.makeUUID(bytes); + + assertNotNull(result); + assertEquals(72339069014638592L, result.getLeastSignificantBits()); + assertEquals(72339069014638592L, result.getMostSignificantBits()); + assertEquals("01010000-0000-0000-0101-000000000000", result.toString()); //$NON-NLS-1$ + assertEquals(0, result.variant()); + assertEquals(0, result.version()); + } + + /** + * Run the UUID makeUUID(byte[]) method test. + */ + @Test + public void testMakeUUID_3() { + byte[] bytes = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }; + + UUID result = Utils.makeUUID(bytes); + + assertNotNull(result); + assertEquals(0L, result.getLeastSignificantBits()); + assertEquals(0L, result.getMostSignificantBits()); + assertEquals("00000000-0000-0000-0000-000000000000", result.toString()); //$NON-NLS-1$ + assertEquals(0, result.variant()); + assertEquals(0, result.version()); + } + + /** + * Run the int unsignedCompare(long,long) method test. + */ + @Test + public void testUnsignedCompare() { + long a = 1L; + long b = 1L; + + int result = Utils.unsignedCompare(a, b); + assertEquals(0, result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java new file mode 100644 index 0000000000..8c6a3588f3 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclarationTest.java @@ -0,0 +1,111 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class ArrayDeclarationTest contains tests for the class + * {@link ArrayDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class ArrayDeclarationTest { + + private ArrayDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ArrayDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new ArrayDeclaration(1, new StringDeclaration()); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the ArrayDeclaration(int,Declaration) constructor test. + */ + @Test + public void testArrayDeclaration() { + int length = 1; + IDeclaration elemType = new StringDeclaration(); + ArrayDeclaration result = new ArrayDeclaration(length, elemType); + + assertNotNull(result); + String left = "[declaration] array["; //$NON-NLS-1$ + String right = result.toString().substring(0, left.length()); + assertEquals(left, right); + assertEquals(1, result.getLength()); + } + + /** + * Run the ArrayDefinition createDefinition(DefinitionScope,String) method + * test. + */ + @Test + public void testCreateDefinition() { + String fieldName = ""; //$NON-NLS-1$ + IDefinitionScope definitionScope = null; + ArrayDefinition result; + result = fixture.createDefinition(definitionScope, fieldName); + + assertNotNull(result); + } + + /** + * Run the Declaration getElementType() method test. + */ + @Test + public void testGetElementType() { + IDeclaration result = fixture.getElementType(); + assertNotNull(result); + } + + /** + * Run the int getLength() method test. + */ + @Test + public void testGetLength() { + int result = fixture.getLength(); + assertEquals(1, result); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + String left = "[declaration] array["; //$NON-NLS-1$ + String right = result.substring(0, left.length()); + + assertEquals(left, right); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java new file mode 100644 index 0000000000..f22a6adf41 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java @@ -0,0 +1,269 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class ArrayDefinitionTest contains tests for the class + * {@link ArrayDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class ArrayDefinitionTest { + + private CTFTrace trace; + private ArrayDefinition fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ArrayDefinitionTest.class); + } + + /** + * Perform pre-test initialization. + * + * structDef shouldn't be null after parsing the CTFTraceReader object, so + * we can ignore the warning. + */ + + @Before + public void setUp() { + this.trace = TestParams.createTrace(); + + CTFTraceReader tr = new CTFTraceReader(this.trace); + String name = ""; //$NON-NLS-1$ + StructDefinition structDef = null; + boolean foundArray = false; + + while (tr.hasMoreEvents() && !foundArray) { + tr.advance(); + EventDefinition ed = tr.getCurrentEventDef(); + for (String key : ed.fields.getDefinitions().keySet()) { + structDef = ed.fields; + Definition d = structDef.lookupDefinition(key); + if (d instanceof ArrayDefinition) { + foundArray = true; + name = key; + break; + } + } + } + fixture = structDef.lookupArray(name); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + private static StringDefinition[] createDefs() { + int size = 4; + StringDefinition[] defs = new StringDefinition[size]; + for (int i = 0; i < size; i++) { + + String content = "test" + i; //$NON-NLS-1$ + defs[i] = new StringDefinition( + new StringDeclaration(Encoding.UTF8), null, content); + defs[i].setString(new StringBuilder(content)); + } + return defs; + } + + /** + * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String) + * constructor test. + */ + @Test + public void testArrayDefinition_baseDeclaration() { + ArrayDeclaration declaration = fixture.getDeclaration(); + String fieldName = ""; //$NON-NLS-1$ + + ArrayDefinition result = new ArrayDefinition(declaration, this.trace, + fieldName); + + assertNotNull(result); + } + + /** + * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String) + * constructor test. + */ + @Test + public void testArrayDefinition_newDeclaration() { + ArrayDeclaration declaration = new ArrayDeclaration(0, + new StringDeclaration()); + IDefinitionScope definitionScope = null; + String fieldName = ""; //$NON-NLS-1$ + + ArrayDefinition result = new ArrayDefinition(declaration, + definitionScope, fieldName); + + assertNotNull(result); + } + + /** + * Run the ArrayDeclaration getDeclaration() method test. + */ + @Test + public void testGetDeclaration() { + fixture.setDefinitions(new Definition[] {}); + ArrayDeclaration result = fixture.getDeclaration(); + + assertNotNull(result); + } + + /** + * Run the Definition getElem(int) method test. + */ + @Test + public void testGetElem_noDefs() { + int i = 0; + Definition result = fixture.getElem(i); + + assertNotNull(result); + } + + /** + * Run the Definition getElem(int) method test. + */ + @Test + public void testGetElem_withDefs() { + Definition defs[] = createDefs(); + fixture.setDefinitions(defs); + int j = 1; + + Definition result = fixture.getElem(j); + + assertNotNull(result); + } + + /** + * Run the boolean isString() method test. + */ + @Test + public void testIsString_ownDefs() { + StringDefinition[] defs = createDefs(); + fixture.setDefinitions(defs); + + boolean result = fixture.isString(); + + assertFalse(result); + } + + /** + * Run the boolean isString() method test. + */ + @Test + public void testIsString_complex() { + final IntegerDeclaration id = new IntegerDeclaration(8, false, 16, + ByteOrder.LITTLE_ENDIAN, Encoding.UTF8); + ArrayDeclaration ad = new ArrayDeclaration(0, id); + ArrayDefinition ownFixture = new ArrayDefinition(ad, this.trace, + "Testx"); //$NON-NLS-1$ + + int size = 4; + IntegerDefinition[] defs = new IntegerDefinition[size]; + for (int i = 0; i < size; i++) { + + String content = "test" + i; //$NON-NLS-1$ + defs[i] = new IntegerDefinition(new IntegerDeclaration(8, false, + 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8), null, content); + defs[i].setValue(i); + } + + ownFixture.setDefinitions(defs); + boolean result = ownFixture.isString(); + + assertTrue(result); + } + + /** + * Run the boolean isString() method test. + */ + @Test + public void testIsString_emptyDef() { + fixture.setDefinitions(new Definition[] {}); + boolean result = fixture.isString(); + + assertFalse(result); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead_noDefs() { + BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128)); + + fixture.read(input); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead_withDefs() { + fixture.setDefinitions(new Definition[] {}); + BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + + fixture.read(input); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString_base() { + String result = fixture.toString(); + + assertNotNull(result); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString_withDefs() { + int size = 2; + StringDefinition[] defs = new StringDefinition[size]; + for (int i = 0; i < size; i++) { + defs[i] = new StringDefinition(null, null, ("test" + i)); //$NON-NLS-1$ + } + fixture.setDefinitions(defs); + String result = fixture.toString(); + + assertNotNull(result); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java new file mode 100644 index 0000000000..56af49da16 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java @@ -0,0 +1,71 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertNotNull; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class DefinitionTest contains tests for the class + * {@link Definition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class DefinitionTest { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(DefinitionTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Since Definition is abstract, we'll minimally extend it here to + * instantiate it. + */ + class DefTest extends Definition { + + public DefTest(IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + } + + @Override + public void read(BitBuffer input) { + /* Just a test, no need to implement anything */ + } + + } + + @Test + public void testToString() throws Exception { + Definition fixture = new DefTest(null, "Hello"); //$NON-NLS-1$ + String result = fixture.toString(); + + assertNotNull(result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDeclarationTest.java new file mode 100644 index 0000000000..d0919bc307 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDeclarationTest.java @@ -0,0 +1,133 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.nio.ByteOrder; + +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.EnumDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class EnumDeclarationTest contains tests for the class + * {@link EnumDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class EnumDeclarationTest { + + private EnumDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(EnumDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new EnumDeclaration(new IntegerDeclaration(1, true, 1, + ByteOrder.BIG_ENDIAN, Encoding.ASCII)); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the EnumDeclaration(IntegerDeclaration) constructor test. + */ + @Test + public void testEnumDeclaration() { + IntegerDeclaration containerType = new IntegerDeclaration(1, true, 1, + ByteOrder.BIG_ENDIAN, Encoding.ASCII); + + EnumDeclaration result = new EnumDeclaration(containerType); + + assertNotNull(result); + String left = "[declaration] enum["; //$NON-NLS-1$ + assertEquals(left, result.toString().substring(0, left.length())); + } + + /** + * Run the boolean add(long,long,String) method test. + */ + @Test + public void testAdd() { + long low = 1L; + long high = 1L; + String label = ""; //$NON-NLS-1$ + + boolean result = fixture.add(low, high, label); + + assertTrue(result); + } + + /** + * Run the EnumDefinition createDefinition(DefinitionScope,String) method + * test. + */ + @Test + public void testCreateDefinition() { + IDefinitionScope definitionScope = null; + String fieldName = ""; //$NON-NLS-1$ + + EnumDefinition result = fixture.createDefinition(definitionScope, + fieldName); + + assertNotNull(result); + } + + /** + * Run the String getLabel(long) method test. + */ + @Test + public void testGetLabel() { + long i = 0; + String result = fixture.getLabel(i); + + assertNull(result); + } + + /** + * Run the String query(long) method test. + */ + @Test + public void testQuery() { + long value = 0; + String result = fixture.query(value); + + assertNull(result); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + + String left = "[declaration] enum["; //$NON-NLS-1$ + assertEquals(left, result.substring(0, left.length())); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java new file mode 100644 index 0000000000..eaaed33f34 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java @@ -0,0 +1,112 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +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.EnumDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class EnumDefinitionTest contains tests for the class + * {@link EnumDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class EnumDefinitionTest { + + private EnumDefinition fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(EnumDefinitionTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + EnumDeclaration declaration = new EnumDeclaration( + new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN, + Encoding.ASCII)); + String fieldName = ""; //$NON-NLS-1$ + + fixture = new EnumDefinition(declaration, null, fieldName); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the EnumDefinition(EnumDeclaration,DefinitionScope,String) + * constructor test. + */ + @Test + public void testEnumDefinition() { + assertNotNull(fixture); + } + + /** + * Run the String getValue() method test. + */ + @Test + public void testGetValue() { + String result = fixture.getValue(); + + assertNotNull(result); + } + + /** + * Run the long getIntegerValue() method test. + */ + @Test + public void testGetIntegerValue_one() { + fixture.setIntegerValue(1L); + long result = fixture.getIntegerValue(); + + assertEquals(1L, result); + } + + /** + * Run the String getValue() method test. + */ + @Test + public void testGetIntegerValue_zero() { + fixture.setIntegerValue(0); + long result = fixture.getIntegerValue(); + + assertTrue(0 == result); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead() { + fixture.setIntegerValue(1L); + BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128)); + + fixture.read(input); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java new file mode 100644 index 0000000000..cbee082c99 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java @@ -0,0 +1,354 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.nio.channels.FileChannel; + +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class EventDeclarationTest contains tests for the class + * {@link EventDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class EventDeclarationTest { + + private EventDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(EventDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new EventDeclaration(); + fixture.setContext(new StructDeclaration(1L)); + fixture.setId(1L); + fixture.setFields(new StructDeclaration(1L)); + fixture.setStream(new Stream(TestParams.createTrace())); + fixture.setName(""); //$NON-NLS-1$ + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the EventDeclaration() constructor test. + */ + @Test + public void testEventDeclaration() { + EventDeclaration result = new EventDeclaration(); + assertNotNull(result); + } + + /** + * Run the boolean contextIsSet() method test. + */ + @Test + public void testContextIsSet() { + boolean result = fixture.contextIsSet(); + assertTrue(result); + } + + /** + * Run the boolean contextIsSet() method test. + */ + @Test + public void testContextIsSet_null() { + fixture.setContext((StructDeclaration) null); + + boolean result = fixture.contextIsSet(); + assertFalse(result); + } + + /** + * Run the EventDefinition createDefinition(StreamInputReader) method test. + */ + @Test + public void testCreateDefinition() { + StreamInputReader streamInputReader = new StreamInputReader( + new StreamInput(new Stream(TestParams.createTrace()), + (FileChannel) null, TestParams.getEmptyFile())); + + EventDefinition result = fixture.createDefinition(streamInputReader); + assertNotNull(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals() { + EventDeclaration obj = new EventDeclaration(); + obj.setContext(new StructDeclaration(1L)); + obj.setId(1L); + obj.setFields(new StructDeclaration(1L)); + obj.setStream(new Stream(TestParams.createTrace())); + obj.setName(""); //$NON-NLS-1$ + + assertTrue(fixture.equals(fixture)); + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals_null() { + Object obj = null; + + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals_emptyObject() { + Object obj = new Object(); + + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals_other1() { + EventDeclaration obj = new EventDeclaration(); + obj.setContext(fixture.getContext()); + + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals_other2() { + EventDeclaration obj = new EventDeclaration(); + obj.setContext(new StructDeclaration(1L)); + obj.setFields(new StructDeclaration(1L)); + + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals_other3() { + EventDeclaration obj = new EventDeclaration(); + obj.setContext(new StructDeclaration(1L)); + obj.setId(1L); + obj.setFields(new StructDeclaration(1L)); + + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean equals(Object) method test. + */ + @Test + public void testEquals_other4() { + EventDeclaration obj = new EventDeclaration(); + obj.setContext(new StructDeclaration(1L)); + obj.setId(1L); + obj.setFields(new StructDeclaration(1L)); + obj.setName(""); //$NON-NLS-1$ + + boolean result = fixture.equals(obj); + assertFalse(result); + } + + /** + * Run the boolean fieldsIsSet() method test. + */ + @Test + public void testFieldsIsSet() { + boolean result = fixture.fieldsIsSet(); + assertTrue(result); + } + + /** + * Run the boolean fieldsIsSet() method test. + */ + @Test + public void testFieldsIsSet_null() { + fixture.setFields((StructDeclaration) null); + + boolean result = fixture.fieldsIsSet(); + assertFalse(result); + } + + /** + * Run the StructDeclaration getFields() method test. + */ + @Test + public void testGetFields() { + StructDeclaration result = fixture.getFields(); + assertNotNull(result); + } + + /** + * Run the Long getId() method test. + */ + @Test + public void testGetId() { + Long result = fixture.getId(); + assertNotNull(result); + } + + /** + * Run the String getName() method test. + */ + @Test + public void testGetName() { + String result = fixture.getName(); + assertNotNull(result); + } + + /** + * Run the Stream getStream() method test. + */ + @Test + public void testGetStream() { + Stream result = fixture.getStream(); + assertNotNull(result); + } + + /** + * Run the int hashCode() method test. + */ + @Test + public void testHashCode() { + int result = fixture.hashCode(); + assertTrue(0 != result); + } + + /** + * Run the int hashCode() method test. + */ + @Test + public void testHashCode_null() { + fixture.setStream((Stream) null); + fixture.setName((String) null); + + int result = fixture.hashCode(); + assertTrue(0 != result); + } + + /** + * Run the boolean idIsSet() method test. + */ + @Test + public void testIdIsSet() { + boolean result = fixture.idIsSet(); + assertTrue(result); + } + + /** + * Run the boolean nameIsSet() method test. + */ + @Test + public void testNameIsSet() { + boolean result = fixture.nameIsSet(); + assertTrue(result); + } + + /** + * Run the boolean nameIsSet() method test. + */ + @Test + public void testNameIsSet_null() { + fixture.setName((String) null); + + boolean result = fixture.nameIsSet(); + assertFalse(result); + } + + /** + * Run the boolean streamIsSet() method test. + */ + @Test + public void testStreamIsSet() { + boolean result = fixture.streamIsSet(); + assertTrue(result); + } + + /** + * Run the boolean streamIsSet() method test. + */ + @Test + public void testStreamIsSet_null() { + fixture.setStream((Stream) null); + + boolean result = fixture.streamIsSet(); + assertEquals(false, result); + } + + /** + * Test for the EventDefinition class + */ + @Test + public void testEventDefinition() { + CTFTrace trace = TestParams.createTrace(); + CTFTraceReader tr = new CTFTraceReader(trace); + tr.advance(); + EventDefinition ed = new EventDefinition(null, null); + ed = tr.getCurrentEventDef(); + assertNotNull(ed); + assertNotNull(ed.getPath()); + assertNotNull(ed.getDeclaration()); + assertNotNull(ed.getFields()); + assertNull(ed.getContext()); + assertNotNull(ed.getPacketContext()); + assertNotNull(ed.getCPU()); + assertNotNull(ed.getPacketContext()); + assertNotNull(ed.getStreamInputReader()); + assertNull(ed.lookupDefinition("context")); //$NON-NLS-1$ + assertNotNull(ed.lookupDefinition("fields")); //$NON-NLS-1$ + assertNull(ed.lookupDefinition("other")); //$NON-NLS-1$ + assertNotNull(ed.toString()); + ed.context = ed.getFields(); + assertNotNull(ed.toString()); + + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java new file mode 100644 index 0000000000..7d04c6effe --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java @@ -0,0 +1,213 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class IntegerDeclarationTest contains tests for the class + * {@link IntegerDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class IntegerDeclarationTest { + + private IntegerDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(IntegerDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN, + Encoding.ASCII); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the IntegerDeclaration(int,boolean,int,ByteOrder,Encoding) + * constructor test. + */ + @Test + public void testIntegerDeclaration() { + int len = 1; + boolean signed = true; + int base = 1; + ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; + Encoding encoding = Encoding.ASCII; + + IntegerDeclaration result = new IntegerDeclaration(len, signed, base, + byteOrder, encoding); + + assertNotNull(result); + assertEquals(1, result.getBase()); + assertEquals(false, result.isCharacter()); + String outputValue = "[declaration] integer["; //$NON-NLS-1$ + assertEquals(outputValue, + result.toString().substring(0, outputValue.length())); + assertEquals(1, result.getLength()); + assertEquals(true, result.isSigned()); + } + + /** + * Run the int getBase() method test. + */ + @Test + public void testGetBase() { + int result = fixture.getBase(); + assertEquals(1, result); + } + + /** + * Run the ByteOrder getByteOrder() method test. + */ + @Test + public void testGetByteOrder() { + ByteOrder result = fixture.getByteOrder(); + assertNotNull(result); + assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$ + } + + /** + * Run the Encoding getEncoding() method test. + */ + @Test + public void testGetEncoding() { + Encoding result = fixture.getEncoding(); + assertNotNull(result); + assertEquals("ASCII", result.name()); //$NON-NLS-1$ + assertEquals("ASCII", result.toString()); //$NON-NLS-1$ + assertEquals(1, result.ordinal()); + } + + /** + * Run the int getLength() method test. + */ + @Test + public void testGetLength() { + int result = fixture.getLength(); + assertEquals(1, result); + } + + /** + * Run the boolean isCharacter() method test. + */ + @Test + public void testIsCharacter() { + boolean result = fixture.isCharacter(); + assertEquals(false, result); + } + + /** + * Run the boolean isCharacter() method test. + */ + @Test + public void testIsCharacter_8bytes() { + IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1, + ByteOrder.BIG_ENDIAN, Encoding.ASCII); + + boolean result = fixture8.isCharacter(); + assertEquals(true, result); + } + + /** + * Run the boolean isSigned() method test. + */ + @Test + public void testIsSigned_signed() { + boolean result = fixture.isSigned(); + assertEquals(true, result); + } + + /** + * Run the boolean isSigned() method test. + */ + @Test + public void testIsSigned_unsigned() { + IntegerDeclaration fixture_unsigned = new IntegerDeclaration(1, false, + 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII); + + boolean result = fixture_unsigned.isSigned(); + assertEquals(false, result); + } + + /** + * Run the void setBase(int) method test. + */ + @Test + public void testSetBase() { + int base = 1; + fixture.setBase(base); + } + + /** + * Run the void setByteOrder(ByteOrder) method test. + */ + @Test + public void testSetByteOrder() { + ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; + fixture.setByteOrder(byteOrder); + } + + /** + * Run the void setEncoding(Encoding) method test. + */ + @Test + public void testSetEncoding() { + Encoding encoding = Encoding.ASCII; + fixture.setEncoding(encoding); + } + + /** + * Run the void setLength(int) method test. + */ + @Test + public void testSetLength() { + int length = 1; + fixture.setLength(length); + } + + /** + * Run the void setSigned(boolean) method test. + */ + @Test + public void testSetSigned() { + boolean signed = true; + fixture.setSigned(signed); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + String trunc = result.substring(0, 22); + assertEquals("[declaration] integer[", trunc); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java new file mode 100644 index 0000000000..6070aa694f --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java @@ -0,0 +1,140 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class IntegerDefinitionTest contains tests for the class + * {@link IntegerDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class IntegerDefinitionTest { + + private IntegerDefinition fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(IntegerDefinitionTest.class); + } + + /** + * Perform pre-test initialization. We know the structDef won't be null (or + * else the tests will fail), so we can safely suppress the warning. + */ + @Before + public void setUp() { + CTFTrace trace = TestParams.createTrace(); + CTFTraceReader tr = new CTFTraceReader(trace); + String name = ""; //$NON-NLS-1$ + StructDefinition structDef = null; + boolean found = false; + + while (tr.hasMoreEvents() && !found) { + tr.advance(); + EventDefinition ed = tr.getCurrentEventDef(); + for (String key : ed.fields.getDefinitions().keySet()) { + structDef = ed.fields; + Definition d = structDef.lookupDefinition(key); + if (d instanceof IntegerDefinition) { + found = true; + name = key; + break; + } + } + } + assert (structDef != null); + fixture = structDef.lookupInteger(name); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String) + * constructor test. + */ + @Test + public void testIntegerDefinition() { + IntegerDeclaration declaration = new IntegerDeclaration(1, true, 1, + ByteOrder.BIG_ENDIAN, Encoding.ASCII); + IDefinitionScope definitionScope = null; + String fieldName = ""; //$NON-NLS-1$ + + IntegerDefinition result = new IntegerDefinition(declaration, + definitionScope, fieldName); + assertNotNull(result); + } + + /** + * Run the IntegerDeclaration getDeclaration() method test. + */ + @Test + public void testGetDeclaration() { + fixture.setValue(1L); + + IntegerDeclaration result = fixture.getDeclaration(); + assertNotNull(result); + } + + /** + * Run the long getValue() method test. + */ + @Test + public void testGetValue() { + fixture.setValue(1L); + + long result = fixture.getValue(); + assertEquals(1L, result); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead() { + fixture.setValue(1L); + BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + + fixture.read(input); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + fixture.setValue(1L); + + String result = fixture.toString(); + assertNotNull(result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java new file mode 100644 index 0000000000..ff46131b9d --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java @@ -0,0 +1,103 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class SequenceDeclarationTest contains tests for the class + * {@link SequenceDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class SequenceDeclarationTest { + + private SequenceDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(SequenceDeclarationTest.class); + } + + @Before + public void setUp() { + fixture = new SequenceDeclaration("", new StringDeclaration()); //$NON-NLS-1$ + } + + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the SequenceDeclaration(String,Declaration) constructor test. + */ + @Test + public void testSequenceDeclaration() { + String lengthName = ""; //$NON-NLS-1$ + IDeclaration elemType = new StringDeclaration(); + + SequenceDeclaration result = new SequenceDeclaration(lengthName, + elemType); + assertNotNull(result); + String string = "[declaration] sequence["; //$NON-NLS-1$ + assertEquals(string, result.toString().substring(0, string.length())); + } + + /** + * Run the SequenceDefinition createDefinition(DefinitionScope,String) + * method test. + */ + @Test + public void testCreateDefinition() { + IntegerDeclaration id = new IntegerDeclaration(8, false, 8, + ByteOrder.LITTLE_ENDIAN, Encoding.UTF8); + String fieldName = "LengthName"; //$NON-NLS-1$ + StructDeclaration structDec = new StructDeclaration(0); + structDec.addField(fieldName, id); + StructDefinition structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$ + long seqLen = 10; + structDef.lookupInteger(fieldName).setValue(seqLen); + SequenceDefinition result = this.fixture.createDefinition(structDef, + fieldName); + assertNotNull(result); + } + + /** + * Run the Declaration getElementType() method test. + */ + @Test + public void testGetElementType() { + IDeclaration result = fixture.getElementType(); + assertNotNull(result); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + String left = "[declaration] sequence["; //$NON-NLS-1$ + assertEquals(left, result.substring(0, left.length())); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java new file mode 100644 index 0000000000..ff06a54b76 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java @@ -0,0 +1,177 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.nio.ByteOrder; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class SequenceDefinitionTest contains tests for the class + * {@link SequenceDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class SequenceDefinitionTest { + + private SequenceDefinition fixture; + private final static int seqLen = 15; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(SequenceDefinitionTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + StructDeclaration structDec; + StructDefinition structDef; + + IntegerDeclaration id = new IntegerDeclaration(8, false, 8, + ByteOrder.LITTLE_ENDIAN, Encoding.UTF8); + String lengthName = "LengthName"; //$NON-NLS-1$ + structDec = new StructDeclaration(0); + structDec.addField(lengthName, id); + structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$ + + structDef.lookupInteger(lengthName).setValue(seqLen); + SequenceDeclaration sd = new SequenceDeclaration(lengthName, id); + fixture = new SequenceDefinition(sd, structDef, "TestX"); //$NON-NLS-1$ + BitBuffer input = new BitBuffer( + java.nio.ByteBuffer.allocateDirect(seqLen * 8)); + for (int i = 0; i < seqLen; i++) { + input.putInt(i); + } + fixture.read(input); + assert (fixture != null); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + private static SequenceDefinition initNonString() { + StructDeclaration structDec; + StructDefinition structDef; + + int len = 32; + IntegerDeclaration id = new IntegerDeclaration(len, false, len, + ByteOrder.LITTLE_ENDIAN, Encoding.UTF8); + String lengthName = "LengthName"; //$NON-NLS-1$ + structDec = new StructDeclaration(0); + structDec.addField(lengthName, id); + structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$ + + structDef.lookupInteger(lengthName).setValue(seqLen); + SequenceDeclaration sd = new SequenceDeclaration(lengthName, id); + SequenceDefinition ret = new SequenceDefinition(sd, structDef, "TestX"); //$NON-NLS-1$ + BitBuffer input = new BitBuffer( + java.nio.ByteBuffer.allocateDirect(seqLen * len)); + for (int i = 0; i < seqLen; i++) { + input.putInt(i); + } + ret.read(input); + assertNotNull(ret); + return ret; + } + + /** + * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String) + * constructor test. + */ + @Test + public void testSequenceDefinition() { + assertNotNull(fixture); + } + + /** + * Run the SequenceDeclaration getDeclaration() method test. + */ + @Test + public void testGetDeclaration() { + SequenceDeclaration result = fixture.getDeclaration(); + assertNotNull(result); + } + + /** + * Run the Definition getElem(int) method test. + */ + @Test + public void testGetElem() { + int i = 1; + Definition result = fixture.getElem(i); + assertNotNull(result); + } + + /** + * Run the int getLength() method test. + */ + @Test + public void testGetLength() { + int result = fixture.getLength(); + + assertEquals(seqLen, result); + } + + /** + * Run the boolean isString() method test. + */ + @Test + public void testIsString() { + boolean result = fixture.isString(); + assertTrue(result); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead() { + BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + fixture.read(input); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + assertNotNull(result); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString_nonString() throws Exception { + SequenceDefinition nonStringFixture = initNonString(); + String result = nonStringFixture.toString(); + assertNotNull(result); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDeclarationTest.java new file mode 100644 index 0000000000..a63ad03895 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDeclarationTest.java @@ -0,0 +1,123 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StringDeclarationTest contains tests for the class + * {@link StringDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StringDeclarationTest { + + private StringDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StringDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new StringDeclaration(Encoding.ASCII); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StringDeclaration() constructor test. + */ + @Test + public void testStringDeclaration() { + StringDeclaration result = new StringDeclaration(); + + assertNotNull(result); + String string = "[declaration] string["; //$NON-NLS-1$ + assertEquals(string, result.toString().substring(0, string.length())); + } + + /** + * Run the StringDeclaration(Encoding) constructor test. + */ + @Test + public void testStringDeclaration_2() { + Encoding encoding = Encoding.ASCII; + StringDeclaration result = new StringDeclaration(encoding); + + assertNotNull(result); + String string = "[declaration] string["; //$NON-NLS-1$ + assertEquals(string, result.toString().substring(0, string.length())); + } + + /** + * Run the StringDefinition createDefinition(DefinitionScope,String) method + * test. + */ + @Test + public void testCreateDefinition() { + IDefinitionScope definitionScope = null; + String fieldName = "id"; //$NON-NLS-1$ + StringDefinition result = fixture.createDefinition(definitionScope, + fieldName); + + assertNotNull(result); + } + + /** + * Run the Encoding getEncoding() method test. + */ + @Test + public void testGetEncoding() { + Encoding result = fixture.getEncoding(); + + assertNotNull(result); + assertEquals("ASCII", result.name()); //$NON-NLS-1$ + assertEquals("ASCII", result.toString()); //$NON-NLS-1$ + assertEquals(1, result.ordinal()); + } + + /** + * Run the void setEncoding(Encoding) method test. + */ + @Test + public void testSetEncoding() { + Encoding encoding = Encoding.ASCII; + fixture.setEncoding(encoding); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + String left = "[declaration] string["; //$NON-NLS-1$ + String right = result.substring(0, left.length()); + + assertEquals(left, right); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java new file mode 100644 index 0000000000..12409ef030 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java @@ -0,0 +1,161 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertNotNull; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StringDefinitionTest contains tests for the class + * {@link StringDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StringDefinitionTest { + + private StringDefinition fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StringDefinitionTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + CTFTrace trace = TestParams.createTrace(); + CTFTraceReader tr = new CTFTraceReader(trace); + String name = ""; //$NON-NLS-1$ + StructDefinition structDef = null; + boolean found = false; + + while (tr.hasMoreEvents() && !found) { + tr.advance(); + EventDefinition ed = tr.getCurrentEventDef(); + for (String key : ed.fields.getDefinitions().keySet()) { + structDef = ed.fields; + Definition d = structDef.lookupDefinition(key); + if (d instanceof StringDefinition) { + found = true; + name = key; + break; + } + } + } + fixture = structDef.lookupString(name); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StringDefinition(StringDeclaration,DefinitionScope,String) + * constructor test. + */ + @Test + public void testStringDefinition() { + StringDeclaration declaration = new StringDeclaration(); + IDefinitionScope definitionScope = null; + String fieldName = ""; //$NON-NLS-1$ + + StringDefinition result = new StringDefinition(declaration, + definitionScope, fieldName); + + assertNotNull(result); + } + + /** + * Run the StringDeclaration getDeclaration() method test. + */ + @Test + public void testGetDeclaration() { + fixture.setString(new StringBuilder()); + StringDeclaration result = fixture.getDeclaration(); + assertNotNull(result); + } + + /** + * Run the StringBuilder getString() method test. + */ + @Test + public void testGetString() { + fixture.setString(new StringBuilder()); + StringBuilder result = fixture.getString(); + assertNotNull(result); + } + + /** + * Run the String getValue() method test. + */ + @Test + public void testGetValue() { + fixture.setString(new StringBuilder()); + String result = fixture.getValue(); + assertNotNull(result); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead() { + fixture.setString(new StringBuilder()); + BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); + fixture.read(input); + } + + /** + * Run the void setDeclaration(StringDeclaration) method test. + */ + @Test + public void testSetDeclaration() { + fixture.setString(new StringBuilder()); + StringDeclaration declaration = new StringDeclaration(); + fixture.setDeclaration(declaration); + } + + /** + * Run the void setString(StringBuilder) method test. + */ + @Test + public void testSetString() { + fixture.setString(new StringBuilder()); + StringBuilder string = new StringBuilder(); + fixture.setString(string); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + fixture.setString(new StringBuilder()); + String result = fixture.toString(); + assertNotNull(result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDeclarationTest.java new file mode 100644 index 0000000000..adaead4c4a --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDeclarationTest.java @@ -0,0 +1,149 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.List; + +import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StructDeclarationTest contains tests for the class + * {@link StructDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StructDeclarationTest { + + private StructDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StructDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new StructDeclaration(1L); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StructDeclaration(long) constructor test. + */ + @Test + public void testStructDeclaration() { + assertNotNull(fixture); + assertEquals(1L, fixture.getMinAlign()); + + String regex = "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$"; //$NON-NLS-1$ + assertTrue(fixture.toString().matches(regex)); + } + + /** + * Run the void addField(String,Declaration) method test. + */ + @Test + public void testAddField() { + String name = ""; //$NON-NLS-1$ + IDeclaration declaration = new StringDeclaration(); + fixture.addField(name, declaration); + } + + /** + * Run the StructDefinition createDefinition(DefinitionScope,String) method + * test. + */ + @Test + public void testCreateDefinition() { + String fieldName = ""; //$NON-NLS-1$ + StructDefinition result = fixture.createDefinition(null, fieldName); + assertNotNull(result); + } + + /** + * Run the HashMap getFields() method test. + */ + @Test + public void testGetFields() { + HashMap result = fixture.getFields(); + + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the List getFieldsList() method test. + */ + @Test + public void testGetFieldsList() { + List result = fixture.getFieldsList(); + + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the long getMinAlign() method test. + */ + @Test + public void testGetMinAlign() { + long result = fixture.getMinAlign(); + assertEquals(1L, result); + } + + /** + * Run the boolean hasField(String) method test. + */ + @Test + public void testHasField() { + String name = ""; //$NON-NLS-1$ + boolean result = fixture.hasField(name); + + assertEquals(false, result); + } + + /** + * Run the void setMinAlign(long) method test. + */ + @Test + public void testSetMinAlign() { + long minAlign = 1L; + fixture.setMinAlign(minAlign); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + String trunc = result.substring(0, 21); + + assertEquals("[declaration] struct[", trunc); //$NON-NLS-1$ + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java new file mode 100644 index 0000000000..b5a4d71352 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java @@ -0,0 +1,217 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.nio.ByteBuffer; +import java.util.HashMap; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class StructDefinitionTest contains tests for the class + * {@link StructDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class StructDefinitionTest { + + private StructDefinition fixture; + + private static final String VAR_FIELD_NAME = "SomeVariant"; //$NON-NLS-1$ + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StructDefinitionTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + CTFTrace c = TestParams.createTrace(); + CTFTraceReader tr = new CTFTraceReader(c); + EventDefinition ed = tr.getCurrentEventDef(); + fixture = ed.fields; + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the StructDeclaration getDeclaration() method test. + */ + @Test + public void testGetDeclaration() { + StructDeclaration result = fixture.getDeclaration(); + assertNotNull(result); + } + + /** + * Run the HashMap getDefinitions() method test. + */ + @Test + public void testGetDefinitions_1() { + HashMap result = fixture.getDefinitions(); + assertNotNull(result); + } + + /** + * Run the String getPath() method test. + */ + @Test + public void testGetPath() { + String result = fixture.getPath(); + assertNotNull(result); + } + + /** + * Run the ArrayDefinition lookupArray(String) method test. + */ + @Test + public void testLookupArray() { + String name = "id"; //$NON-NLS-1$ + ArrayDefinition result = fixture.lookupArray(name); + + assertNull(result); + } + + /** + * Run the Definition lookupDefinition(String) method test. + */ + @Test + public void testLookupDefinition() { + String lookupPath = "id"; //$NON-NLS-1$ + Definition result = fixture.lookupDefinition(lookupPath); + + assertNotNull(result); + } + + /** + * Run the EnumDefinition lookupEnum(String) method test. + */ + @Test + public void testLookupEnum() { + String name = ""; //$NON-NLS-1$ + EnumDefinition result = fixture.lookupEnum(name); + + /* There are no enums in the test trace */ + assertNull(result); + } + + /** + * Run the IntegerDefinition lookupInteger(String) method test. + */ + @Test + public void testLookupInteger_1() { + String name = "id"; //$NON-NLS-1$ + IntegerDefinition result = fixture.lookupInteger(name); + + assertNotNull(result); + } + + /** + * Run the IntegerDefinition lookupInteger(String) method test. + */ + @Test + public void testLookupInteger_2() { + String name = VAR_FIELD_NAME; + IntegerDefinition result = fixture.lookupInteger(name); + + assertNull(result); + } + + /** + * Run the SequenceDefinition lookupSequence(String) method test. + */ + @Test + public void testLookupSequence() { + String name = VAR_FIELD_NAME; + SequenceDefinition result = fixture.lookupSequence(name); + + assertNull(result); + } + + /** + * Run the StringDefinition lookupString(String) method test. + */ + @Test + public void testLookupString() { + String name = VAR_FIELD_NAME; + StringDefinition result = fixture.lookupString(name); + + assertNull(result); + } + + /** + * Run the StructDefinition lookupStruct(String) method test. + */ + @Test + public void testLookupStruct() { + String name = VAR_FIELD_NAME; + StructDefinition result = fixture.lookupStruct(name); + + assertNull(result); + } + + /** + * Run the VariantDefinition lookupVariant(String) method test. + */ + @Test + public void testLookupVariant() { + String name = VAR_FIELD_NAME; + VariantDefinition result = fixture.lookupVariant(name); + + assertNull(result); + } + + /** + * Run the void read(BitBuffer) method test. + */ + @Test + public void testRead_() { + ByteBuffer bb = ByteBuffer.allocateDirect(128); + bb.put((byte) 20); + BitBuffer input = new BitBuffer(bb); + + fixture.read(input); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + String result = fixture.toString(); + assertNotNull(result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/TestAll.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/TestAll.java new file mode 100644 index 0000000000..5e6cba8fe4 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/TestAll.java @@ -0,0 +1,35 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import org.junit.runner.JUnitCore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The class TestAll builds a suite that can be used to run all of + * the tests within its package as well as within any subpackages of its + * package. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ StructDefinitionTest.class, IntegerDeclarationTest.class, + EnumDefinitionTest.class, SequenceDeclarationTest.class, + StructDeclarationTest.class, DefinitionTest.class, + IntegerDefinitionTest.class, SequenceDefinitionTest.class, + ArrayDefinitionTest.class, EnumDeclarationTest.class, + StringDeclarationTest.class, ArrayDeclarationTest.class, + VariantDefinitionTest.class, VariantDeclarationTest.class, + StringDefinitionTest.class, EventDeclarationTest.class, }) +public class TestAll { + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + JUnitCore.runClasses(new Class[] { TestAll.class }); + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDeclarationTest.java new file mode 100644 index 0000000000..9aef3b642b --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDeclarationTest.java @@ -0,0 +1,164 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class VariantDeclarationTest contains tests for the class + * {@link VariantDeclaration}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class VariantDeclarationTest { + + private VariantDeclaration fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(VariantDeclarationTest.class); + } + + /** + * Perform pre-test initialization. + */ + @Before + public void setUp() { + fixture = new VariantDeclaration(); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the VariantDeclaration() constructor test. + */ + @Test + public void testVariantDeclaration() { + assertNotNull(fixture); + assertEquals(false, fixture.isTagged()); + String left = "[declaration] variant["; //$NON-NLS-1$ + assertEquals(left, fixture.toString().substring(0, left.length())); + } + + /** + * Run the void addField(String,Declaration) method test. + */ + @Test + public void testAddField() { + fixture.setTag(""); //$NON-NLS-1$ + String tag = ""; //$NON-NLS-1$ + IDeclaration declaration = new StringDeclaration(); + fixture.addField(tag, declaration); + } + + /** + * Run the VariantDefinition createDefinition(DefinitionScope,String) method + * test. + */ + @Test + public void testCreateDefinition() { + fixture.setTag(""); //$NON-NLS-1$ + IDefinitionScope definitionScope = createDefinitionScope(); + String fieldName = ""; //$NON-NLS-1$ + VariantDefinition result = fixture.createDefinition(definitionScope, + fieldName); + + assertNotNull(result); + } + + private static IDefinitionScope createDefinitionScope() { + VariantDeclaration declaration = new VariantDeclaration(); + declaration.setTag(""); //$NON-NLS-1$ + VariantDeclaration variantDeclaration = new VariantDeclaration(); + variantDeclaration.setTag(""); //$NON-NLS-1$ + VariantDefinition variantDefinition = new VariantDefinition( + variantDeclaration, TestParams.createTrace(), ""); //$NON-NLS-1$ + IDefinitionScope definitionScope = new StructDefinition( + new StructDeclaration(1L), variantDefinition, ""); //$NON-NLS-1$ + String fieldName = ""; //$NON-NLS-1$ + + VariantDefinition result = new VariantDefinition(declaration, + definitionScope, fieldName); + return result; + } + + /** + * Run the boolean hasField(String) method test. + */ + @Test + public void testHasField() { + fixture.setTag(""); //$NON-NLS-1$ + String tag = ""; //$NON-NLS-1$ + boolean result = fixture.hasField(tag); + + assertEquals(false, result); + } + + /** + * Run the boolean isTagged() method test. + */ + @Test + public void testIsTagged() { + fixture.setTag(""); //$NON-NLS-1$ + boolean result = fixture.isTagged(); + + assertEquals(true, result); + } + + /** + * Run the boolean isTagged() method test. + */ + @Test + public void testIsTagged_null() { + fixture.setTag((String) null); + boolean result = fixture.isTagged(); + + assertEquals(false, result); + } + + /** + * Run the void setTag(String) method test. + */ + @Test + public void testSetTag() { + fixture.setTag(""); //$NON-NLS-1$ + String tag = ""; //$NON-NLS-1$ + fixture.setTag(tag); + } + + /** + * Run the String toString() method test. + */ + @Test + public void testToString() { + fixture.setTag(""); //$NON-NLS-1$ + String result = fixture.toString(); + String left = "[declaration] variant["; //$NON-NLS-1$ + String right = result.substring(0, left.length()); + + assertEquals(left, right); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java new file mode 100644 index 0000000000..b145b2cf25 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java @@ -0,0 +1,293 @@ +package org.eclipse.linuxtools.ctf.core.tests.types; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.nio.ByteOrder; +import java.util.HashMap; + +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.Encoding; +import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; +import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * The class VariantDefinitionTest contains tests for the class + * {@link VariantDefinition}. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +public class VariantDefinitionTest { + + private VariantDefinition fixture; + + /** + * Launch the test. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(VariantDefinitionTest.class); + } + + /** + * Perform pre-test initialization. + * + * Not sure it needs to be that complicated, oh well... + */ + @Before + public void setUp() { + VariantDeclaration vDecl1, vDecl2, vDecl3; + VariantDefinition vDef1, vDef2; + StructDefinition sDef1, sDef2; + EnumDefinition eDef; + String fName = ""; //$NON-NLS-1$ + + vDecl1 = new VariantDeclaration(); + vDecl2 = new VariantDeclaration(); + vDecl3 = new VariantDeclaration(); + vDecl1.setTag(fName); + vDecl2.setTag(fName); + vDecl3.setTag(fName); + + vDef1 = new VariantDefinition(vDecl2, TestParams.createTrace(), fName); + vDef2 = new VariantDefinition(vDecl3, TestParams.createTrace(), fName); + + sDef1 = new StructDefinition(new StructDeclaration(1L), vDef1, fName); + sDef2 = new StructDefinition(new StructDeclaration(1L), vDef2, fName); + + eDef = new EnumDefinition(new EnumDeclaration(new IntegerDeclaration(1, + true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII)), sDef2, fName); + + fixture = new VariantDefinition(vDecl1, sDef1, fName); + fixture.setTagDefinition(eDef); + fixture.setCurrentField(fName); + } + + /** + * Perform post-test clean-up. + */ + @After + public void tearDown() { + // Add additional tear down code here + } + + /** + * Run the VariantDefinition(VariantDeclaration,DefinitionScope,String) + */ + @Test + public void testVariantDefinition() { + VariantDeclaration declaration = new VariantDeclaration(); + declaration.setTag(""); //$NON-NLS-1$ + VariantDeclaration variantDeclaration = new VariantDeclaration(); + variantDeclaration.setTag(""); //$NON-NLS-1$ + VariantDefinition variantDefinition = new VariantDefinition( + variantDeclaration, TestParams.createTrace(), ""); //$NON-NLS-1$ + IDefinitionScope definitionScope = new StructDefinition( + new StructDeclaration(1L), variantDefinition, ""); //$NON-NLS-1$ + String fieldName = ""; //$NON-NLS-1$ + + VariantDefinition result = new VariantDefinition(declaration, + definitionScope, fieldName); + assertNotNull(result); + } + + /** + * Run the Definition getCurrentField() method test. + */ + @Test + public void testGetCurrentField() { + Definition result = fixture.getCurrentField(); + assertNull(result); + } + + /** + * Run the String getCurrentFieldName() method test. + */ + @Test + public void testGetCurrentFieldName() { + String result = fixture.getCurrentFieldName(); + assertNotNull(result); + } + + /** + * Run the VariantDeclaration getDeclaration() method test. + */ + @Test + public void testGetDeclaration() { + VariantDeclaration result = fixture.getDeclaration(); + assertNotNull(result); + } + + /** + * Run the HashMap getDefinitions() method test. + */ + @Test + public void testGetDefinitions() { + HashMap result = fixture.getDefinitions(); + assertNotNull(result); + } + + /** + * Run the String getPath() method test. + */ + @Test + public void testGetPath() { + String result = fixture.getPath(); + assertNotNull(result); + } + + /** + * Run the EnumDefinition getTagDefinition() method test. + */ + @Test + public void testGetTagDefinition() { + EnumDefinition result = fixture.getTagDefinition(); + assertNotNull(result); + } + + /** + * Run the ArrayDefinition lookupArray(String) method test. + */ + @Test + public void testLookupArray() { + String name = ""; //$NON-NLS-1$ + ArrayDefinition result = fixture.lookupArray(name); + assertNull(result); + } + + /** + * Run the Definition lookupDefinition(String) method test. + */ + @Test + public void testLookupDefinition() { + String lookupPath = ""; //$NON-NLS-1$ + Definition result = fixture.lookupDefinition(lookupPath); + assertNull(result); + } + + /** + * Run the EnumDefinition lookupEnum(String) method test. + */ + @Test + public void testLookupEnum() { + String name = ""; //$NON-NLS-1$ + EnumDefinition result = fixture.lookupEnum(name); + assertNull(result); + } + + /** + * Run the IntegerDefinition lookupInteger(String) method test. + */ + @Test + public void testLookupInteger() { + String name = ""; //$NON-NLS-1$ + IntegerDefinition result = fixture.lookupInteger(name); + assertNull(result); + } + + /** + * Run the SequenceDefinition lookupSequence(String) method test. + */ + @Test + public void testLookupSequence_1() throws Exception { + String name = ""; //$NON-NLS-1$ + SequenceDefinition result = fixture.lookupSequence(name); + assertNull(result); + } + + /** + * Run the StringDefinition lookupString(String) method test. + */ + @Test + public void testLookupString() { + String name = ""; //$NON-NLS-1$ + StringDefinition result = fixture.lookupString(name); + assertNull(result); + } + + /** + * Run the StructDefinition lookupStruct(String) method test. + */ + @Test + public void testLookupStruct() { + String name = ""; //$NON-NLS-1$ + StructDefinition result = fixture.lookupStruct(name); + assertNull(result); + } + + /** + * Run the VariantDefinition lookupVariant(String) method test. + */ + @Test + public void testLookupVariant() { + String name = ""; //$NON-NLS-1$ + VariantDefinition result = fixture.lookupVariant(name); + assertNull(result); + } + + /** + * Run the void setCurrentField(String) method test. + */ + @Test + public void testSetCurrentField() { + String currentField = ""; //$NON-NLS-1$ + fixture.setCurrentField(currentField); + } + + /** + * Run the void setDeclaration(VariantDeclaration) method test. + */ + @Test + public void testSetDeclaration() { + VariantDeclaration declaration = new VariantDeclaration(); + fixture.setDeclaration(declaration); + } + + /** + * Run the void setDefinitions(HashMap) method test. + */ + @Test + public void testSetDefinitions() { + HashMap definitions = new HashMap(); + fixture.setDefinitions(definitions); + } + + /** + * Run the void setTagDefinition(EnumDefinition) method test. + */ + @Test + public void testSetTagDefinition() { + VariantDeclaration vDecl; + VariantDefinition vDef; + StructDefinition structDef; + EnumDefinition tagDefinition; + String fName = ""; //$NON-NLS-1$ + + vDecl = new VariantDeclaration(); + vDecl.setTag(fName); + vDef = new VariantDefinition(vDecl, TestParams.createTrace(), fName); + structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName); + tagDefinition = new EnumDefinition(new EnumDeclaration( + new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN, + Encoding.ASCII)), structDef, fName); + + fixture.setTagDefinition(tagDefinition); + } +} diff --git a/org.eclipse.linuxtools.ctf.core/.classpath b/org.eclipse.linuxtools.ctf.core/.classpath new file mode 100644 index 0000000000..84af479d23 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/org.eclipse.linuxtools.ctf.core/.gitignore b/org.eclipse.linuxtools.ctf.core/.gitignore new file mode 100644 index 0000000000..8d94ef8deb --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/.gitignore @@ -0,0 +1,5 @@ +bin +@dot +javaCompiler...args +build.xml +target diff --git a/org.eclipse.linuxtools.ctf.core/.project b/org.eclipse.linuxtools.ctf.core/.project new file mode 100644 index 0000000000..2811e4d9a4 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.ctf.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.ctf.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.ctf.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..51e35ebe76 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Fri Dec 16 16:21:30 EST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..31fc4870d7 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.linuxtools.ctf.core;singleton:=true +Bundle-Version: 0.1.0.qualifier +Bundle-Activator: org.eclipse.linuxtools.ctf.core.CtfCorePlugin +Bundle-Vendor: %Bundle-Vendor +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.linuxtools.ctf.core, + org.eclipse.linuxtools.ctf.core.event, + org.eclipse.linuxtools.ctf.core.event.io, + org.eclipse.linuxtools.ctf.core.event.metadata, + org.eclipse.linuxtools.ctf.core.event.metadata.exceptions, + org.eclipse.linuxtools.ctf.core.event.types, + org.eclipse.linuxtools.ctf.core.trace +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", + org.antlr.runtime;bundle-version="3.2.0", + org.eclipse.linuxtools.ctf.parser;bundle-version="0.1.0" diff --git a/org.eclipse.linuxtools.ctf.core/about.html b/org.eclipse.linuxtools.ctf.core/about.html new file mode 100644 index 0000000000..c258ef55d8 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.core/build.properties b/org.eclipse.linuxtools.ctf.core/build.properties new file mode 100644 index 0000000000..d944674ba0 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.properties diff --git a/org.eclipse.linuxtools.ctf.core/other/lttng b/org.eclipse.linuxtools.ctf.core/other/lttng new file mode 100644 index 0000000000..1eeecef40f --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/other/lttng @@ -0,0 +1,131 @@ +#!/bin/bash +# LTTng Trace Control bash completion +# + +_lttng_complete_sessions() { + local sessions + if ! _complete_as_root ; then + sessions=$(for i in $(ls -d ~/.lttng/*/); do basename $i; done) + COMPREPLY=( $(compgen -W "${sessions}" -- $cur) ) + #else + # Permission denied, what should we do ? + # sessions=$(for i in $(ls -d ~root/.lttng/*/); do basename $i; done) + #COMPREPLY=( $(compgen -W "${sessions}" -- $cur) ) + fi +} + +_lttng_create() { + local create_opts + create_opts="-h --help -o --output" + + case $prev in + --output|-o) + _filedir -d + return + ;; + esac + + case $cur in + -*) + COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) ) + return + ;; + esac +} + +_lttng_start_stop() { + local start_stop_opts + start_stop_opts="-h --help" + + case $cur in + -*) + COMPREPLY=( $(compgen -W "${start_stop_opts}" -- $cur) ) + ;; + *) + _lttng_complete_sessions + ;; + esac +} + +_lttng_opts() { + local opts + opts=$(lttng --dump-options) + + COMPREPLY=( $(compgen -W "${opts}" -- $cur) ) +} + +_lttng_commands() { + COMPREPLY=( $(compgen -W "$commands" -- $cur) ) +} + +_lttng_before_command() { + # Check if the previous word should alter the behavior + case $prev in + --group|-g) + COMPREPLY=( $(compgen -g -- $cur) ) + return + ;; + esac + + case $cur in + -*) + # If the current word starts with a dash, complete with options + _lttng_opts + ;; + *) + # Otherwise complete with commands + _lttng_commands + ;; + esac +} + +_lttng_after_command() { + case $command_found in + "create") + _lttng_create + ;; + "start"|"stop") + _lttng_start_stop + ;; + esac +} + +_lttng_is_command() { + for command in $commands; do + if [ "$1" == "$command" ]; then + return 0 + fi + done + + return 1 +} + +_lttng() { + local cur prev commands command_found command_found_index + + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + commands=$(lttng --dump-commands) + + command_found="" + command_found_index=-1 + + for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do + _lttng_is_command ${COMP_WORDS[$i]} + if [ $? -eq 0 ]; then + command_found=${COMP_WORDS[$i]} + command_found_index=$i + break + fi + + done + + if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then + _lttng_after_command + else + _lttng_before_command + fi +} + +complete -F _lttng lttng + diff --git a/org.eclipse.linuxtools.ctf.core/plugin.properties b/org.eclipse.linuxtools.ctf.core/plugin.properties new file mode 100644 index 0000000000..a96bea4dd8 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.linuxtools.tmf +Bundle-Vendor = Eclipse Linux Tools +Bundle-Name = CTF Core diff --git a/org.eclipse.linuxtools.ctf.core/pom.xml b/org.eclipse.linuxtools.ctf.core/pom.xml new file mode 100644 index 0000000000..fda00c4d58 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + + linuxtools-lttng-parent + org.eclipse.linuxtools.lttng + 0.10.0-SNAPSHOT + + + Linux Tools LTTng CTF Core Plug-in + org.eclipse.linuxtools.ctf + org.eclipse.linuxtools.ctf.core + 0.1.0-SNAPSHOT + eclipse-plugin + + + + + + src + + **/*.java + + + + + + org.eclipse.tycho + tycho-source-plugin + + + + + diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CtfCorePlugin.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CtfCorePlugin.java new file mode 100644 index 0000000000..7b4bd8e368 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CtfCorePlugin.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 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: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; + +/** + * CtfCorePlugin + *

+ * The activator class controls the plug-in life cycle. No more than one such + * plug-in can exist at any time. + */ +public class CtfCorePlugin extends Plugin { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.ctf"; //$NON-NLS-1$ + + // The shared instance + private static CtfCorePlugin fPlugin; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public CtfCorePlugin() { + setDefault(this); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + public static CtfCorePlugin getDefault() { + return fPlugin; + } + + private static void setDefault(CtfCorePlugin plugin) { + fPlugin = plugin; + } + + // ------------------------------------------------------------------------ + // Plugin + // ------------------------------------------------------------------------ + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + setDefault(this); + } + + @Override + public void stop(BundleContext context) throws Exception { + setDefault(null); + super.stop(context); + } + + // ------------------------------------------------------------------------ + // Logging + // ------------------------------------------------------------------------ + + public void log(String msg) { + log(msg, null); + } + + public void log(String msg, Exception e) { + getLog().log(new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK, msg, e)); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java new file mode 100644 index 0000000000..fc727a155e --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event; + +import java.util.HashMap; + +public class CTFClock { + + final private HashMap properties = new HashMap(); + private String name; + + public void addAttribute(String key, Object value) { + this.properties.put(key, value); + if (key.equals("name")) { //$NON-NLS-1$ + this.name = (String) value; + } + } + + public String getName() { + return name; + } + + public Object getProperty(String key) { + return properties.get(key); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java new file mode 100644 index 0000000000..c6e06f8d5c --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event; + +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; + +/** + * EventDeclaration + *

+ * Represents one type of event. + */ +public class EventDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * Name of the event + */ + private String name; + + /** + * Event context structure declaration + */ + private StructDeclaration context = null; + + /** + * Event fields structure declaration + */ + private StructDeclaration fields = null; + + /** + * Event id (can be null if only event in the stream). + */ + private Long id = null; + + /** + * Stream to which belongs this event. + */ + private Stream stream = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Creates an instance of EventDefinition corresponding to this declaration. + * + * @param streamInputReader + * The StreamInputReader for which this definition is created. + * @return A new EventDefinition. + */ + public EventDefinition createDefinition(StreamInputReader streamInputReader) { + EventDefinition event = new EventDefinition(this, streamInputReader); + + if (context != null) { + event.context = context.createDefinition(event, "context"); //$NON-NLS-1$ + } + + if (this.fields != null) { + event.fields = this.fields.createDefinition(event, "fields"); //$NON-NLS-1$ + } + + return event; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setContext(StructDeclaration context) { + this.context = context; + } + + public void setFields(StructDeclaration fields) { + this.fields = fields; + } + + public StructDeclaration getFields() { + return fields; + } + + public StructDeclaration getContext() { + return context; + } + + public void setId(long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setStream(Stream stream) { + this.stream = stream; + } + + public Stream getStream() { + return stream; + } + + public boolean nameIsSet() { + return name != null; + } + + public boolean contextIsSet() { + return context != null; + } + + public boolean fieldsIsSet() { + return fields != null; + } + + public boolean idIsSet() { + return id != null; + } + + public boolean streamIsSet() { + return stream != null; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof EventDeclaration)) { + return false; + } + EventDeclaration other = (EventDeclaration) obj; + if (context == null) { + if (other.context != null) { + return false; + } + } else if (!context.equals(other.context)) { + return false; + } + if (fields == null) { + if (other.fields != null) { + return false; + } + } else if (!fields.equals(other.fields)) { + return false; + } + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (stream == null) { + if (other.stream != null) { + return false; + } + } else if (!stream.equals(other.stream)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + + ((context == null) ? 0 : context.hashCode()); + result = (prime * result) + ((fields == null) ? 0 : fields.hashCode()); + result = (prime * result) + ((id == null) ? 0 : id.hashCode()); + result = (prime * result) + ((name == null) ? 0 : name.hashCode()); + result = (prime * result) + ((stream == null) ? 0 : stream.hashCode()); + return result; + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java new file mode 100644 index 0000000000..5e3be16ae8 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event; + +import java.util.HashMap; +import java.util.List; + +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; + +/** + * EventDefinition + *

+ * Represents an instance of an event. + */ +public class EventDefinition implements IDefinitionScope { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * The corresponding event declaration. + */ + public final EventDeclaration declaration; + + /** + * The timestamp of the current event. + */ + public long timestamp; + + /** + * The event context structure definition. + */ + public StructDefinition context; + + /** + * The event fields structure definition. + */ + public StructDefinition fields; + + /** + * The StreamInputReader that reads this event definition. + */ + public final StreamInputReader streamInputReader; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs an event definition. + * + * @param declaration + * The corresponding event declaration. + */ + public EventDefinition(EventDeclaration declaration, + StreamInputReader streamInputReader) { + this.declaration = declaration; + this.streamInputReader = streamInputReader; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + @Override + public String getPath() { + return "event"; //$NON-NLS-1$ + } + + public EventDeclaration getDeclaration() { + return declaration; + } + + public StructDefinition getFields() { + return fields; + } + + public StructDefinition getContext() { + return context; + } + + public StreamInputReader getStreamInputReader() { + return streamInputReader; + } + + public StructDefinition getPacketContext() { + return streamInputReader.getCurrentPacketContext(); + } + + public int getCPU() { + return streamInputReader.getCPU(); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public Definition lookupDefinition(String lookupPath) { + if (lookupPath.equals("context")) { //$NON-NLS-1$ + return context; + } else if (lookupPath.equals("fields")) { //$NON-NLS-1$ + return fields; + } else { + return null; + } + } + + @Override + public String toString() { + HashMap f; + List list; + StringBuilder b = new StringBuilder(); + + b.append("Event type: " + declaration.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + b.append("Timestamp: " + Long.toString(timestamp) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + + if (context != null) { + f = context.getDefinitions(); + list = context.getDeclaration().getFieldsList(); + + for (String field : list) { + b.append(field + " : " + f.get(field).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + if (fields != null) { + f = fields.getDefinitions(); + list = fields.getDeclaration().getFieldsList(); + + for (String field : list) { + b.append(field + " : " + f.get(field).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + return b.toString(); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java new file mode 100644 index 0000000000..64dc466dce --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java @@ -0,0 +1,510 @@ +/*******************************************************************************. + * Copyright (c) 2011-2012 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 implementation + * Contributors: Francis Giraldeau - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.io; + +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +/** + * BitBuffer + *

+ * TODO Implement me. Please. + */ +public class BitBuffer { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /* default bit width */ + public static final int BIT_CHAR = 8; + public static final int BIT_SHORT = 16; + public static final int BIT_INT = 32; + public static final int BIT_FLOAT = 32; + public static final int BIT_LONG = 64; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private ByteBuffer buf; + private int pos; + private ByteOrder byteOrder; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public BitBuffer() { + this(null, ByteOrder.BIG_ENDIAN); + } + + public BitBuffer(ByteBuffer buf) { + this(buf, ByteOrder.BIG_ENDIAN); + } + + public BitBuffer(ByteBuffer buf, ByteOrder order) { + setByteBuffer(buf); + order(order); + position(0); + } + + // ------------------------------------------------------------------------ + // 'Get' operations on buffer + // ------------------------------------------------------------------------ + + /** + * Relative get method for reading 32-bit integer. + * + * Reads next four bytes from the current bit position according to current + * byte order. + * + * @return The int value read from the buffer + */ + public int getInt() { + int val = getInt(BIT_INT, true); + pos += BIT_INT; + return val; + } + + /** + * Relative get method for reading integer of length bits. + * + * Reads length bits starting at the current position. The result is + * signed extended if signed is true. The current position is + * increased of length bits. + * + * @param length + * The length in bits of this integer + * @param signed + * The sign extended flag + * @return The int value read from the buffer + */ + public int getInt(int length, boolean signed) { + int val; + if (!canRead(pos, length)) { + throw new BufferOverflowException(); + } + if (length == 0) { + val = 0; + } + if (byteOrder == ByteOrder.LITTLE_ENDIAN) { + val = getIntLE(pos, length, signed); + } else { + val = getIntBE(pos, length, signed); + } + pos += length; + return val; + } + + /** + * Absolute get method for reading integer of length bits. + * + * Reads length bits starting from position index. The result + * is signed extended if signed is true. The current position is + * increased of length bits. + * + * @param index + * The start index in bits + * @param length + * The length in bits to read + * @param signed + * The sign extended flag + * @return The int value read from the buffer + */ + public int getInt(int index, int length, boolean signed) { + if (!canRead(index, length)) { + throw new BufferOverflowException(); + } + if (length == 0) { + return 0; + } + if (byteOrder == ByteOrder.LITTLE_ENDIAN) { + return getIntLE(index, length, signed); + } + return getIntBE(index, length, signed); + } + + private int getIntBE(int index, int length, boolean signed) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask, cache; + int value = 0; + + currByte = startByte; + cache = buf.get(currByte) & 0xFF; + boolean isNeg = (cache & (1 << (BIT_CHAR - (index % BIT_CHAR) - 1))) != 0; + if (signed && isNeg) { + value = ~0; + } + if (startByte == (endByte - 1)) { + cmask = cache >>> ((BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR); + if (((length) % BIT_CHAR) > 0) { + mask = ~((~0) << length); + cmask &= mask; + } + value <<= length; + value |= cmask; + return value; + } + cshift = index % BIT_CHAR; + if (cshift > 0) { + mask = ~((~0) << (BIT_CHAR - cshift)); + cmask = cache & mask; + lshift = BIT_CHAR - cshift; + value <<= lshift; + value |= cmask; + // index += lshift; + currByte++; + } + for (; currByte < (endByte - 1); currByte++) { + value <<= BIT_CHAR; + value |= buf.get(currByte) & 0xFF; + } + lshift = end % BIT_CHAR; + if (lshift > 0) { + mask = ~((~0) << lshift); + cmask = buf.get(currByte) & 0xFF; + cmask >>>= BIT_CHAR - lshift; + cmask &= mask; + value <<= lshift; + value |= cmask; + } else { + value <<= BIT_CHAR; + value |= buf.get(currByte) & 0xFF; + } + return value; + } + + private int getIntLE(int index, int length, boolean signed) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask, cache, mod; + int value = 0; + + currByte = endByte - 1; + cache = buf.get(currByte) & 0xFF; + mod = end % BIT_CHAR; + lshift = (mod > 0) ? mod : BIT_CHAR; + boolean isNeg = (cache & (1 << (lshift - 1))) != 0; + if (signed && isNeg) { + value = ~0; + } + if (startByte == (endByte - 1)) { + cmask = cache >>> (index % BIT_CHAR); + if (((length) % BIT_CHAR) > 0) { + mask = ~((~0) << length); + cmask &= mask; + } + value <<= length; + value |= cmask; + return value; + } + cshift = end % BIT_CHAR; + if (cshift > 0) { + mask = ~((~0) << cshift); + cmask = cache & mask; + value <<= cshift; + value |= cmask; + // end -= cshift; + currByte--; + } + for (; currByte >= (startByte + 1); currByte--) { + value <<= BIT_CHAR; + value |= buf.get(currByte) & 0xFF; + } + lshift = index % BIT_CHAR; + if (lshift > 0) { + mask = ~((~0) << (BIT_CHAR - lshift)); + cmask = buf.get(currByte) & 0xFF; + cmask >>>= lshift; + cmask &= mask; + value <<= (BIT_CHAR - lshift); + value |= cmask; + } else { + value <<= BIT_CHAR; + value |= buf.get(currByte) & 0xFF; + } + return value; + } + + // ------------------------------------------------------------------------ + // 'Put' operations on buffer + // ------------------------------------------------------------------------ + + /** + * Relative put method to write signed 32-bit integer. + * + * Write four bytes starting from current bit position in the buffer + * according to the current byte order. The current position is increased of + * length bits. + * + * @param value + * The int value to write + */ + public void putInt(int value) { + putInt(BIT_INT, value); + } + + /** + * Relative put method to write length bits integer. + * + * Writes length lower-order bits from the provided value, + * starting from current bit position in the buffer. Sequential bytes are + * written according to the current byte order. The sign bit is carried to + * the MSB if signed is true. The sign bit is included in length. The + * current position is increased of length. + * + * @param length + * The number of bits to write + * @param value + * The value to write + */ + public void putInt(int length, int value) { + putInt(this.pos, length, value); + } + + /** + * Absolute put method to write length bits integer. + * + * Writes length lower-order bits from the provided value, + * starting from index position in the buffer. Sequential bytes are + * written according to the current byte order. The sign bit is carried to + * the MSB if signed is true. The sign bit is included in length. The + * current position is increased of length. + * + * @param index + * The start position to write the value + * @param value + * The value to write + * @param length + * The number of bits to write + */ + public void putInt(int index, int length, int value) { + if (!canRead(index, length)) { + throw new BufferOverflowException(); + } + if (length == 0) { + return; + } + if (byteOrder == ByteOrder.LITTLE_ENDIAN) { + putIntLE(index, length, value); + } else { + putIntBE(index, length, value); + } + } + + private void putIntBE(int index, int length, int value) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask; + int correctedValue = value; + + /* + * mask v high bits. Works for unsigned and two complement signed + * numbers which value do not overflow on length bits. + */ + + if (length < BIT_INT) { + correctedValue &= ~(~0 << length); + } + + /* sub byte */ + if (startByte == (endByte - 1)) { + lshift = (BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR; + mask = ~((~0) << lshift); + if ((index % BIT_CHAR) > 0) { + mask |= (~(0)) << (BIT_CHAR - (index % BIT_CHAR)); + } + cmask = correctedValue << lshift; + /* + * low bits are cleared because of lshift and high bits are already + * cleared + */ + cmask &= ~mask; + int b = buf.get(startByte) & 0xFF; + buf.put(startByte, (byte) ((b & mask) | cmask)); + return; + } + + /* head byte contains MSB */ + currByte = endByte - 1; + cshift = end % BIT_CHAR; + if (cshift > 0) { + lshift = BIT_CHAR - cshift; + mask = ~((~0) << lshift); + cmask = correctedValue << lshift; + cmask &= ~mask; + int b = buf.get(currByte) & 0xFF; + buf.put(currByte, (byte) ((b & mask) | cmask)); + correctedValue >>>= cshift; + // end -= cshift; + currByte--; + } + + /* middle byte(s) */ + for (; currByte >= (startByte + 1); currByte--) { + buf.put(currByte, (byte) correctedValue); + correctedValue >>>= BIT_CHAR; + } + /* end byte contains LSB */ + if ((index % BIT_CHAR) > 0) { + mask = (~0) << (BIT_CHAR - (index % BIT_CHAR)); + cmask = correctedValue & ~mask; + int b = buf.get(currByte) & 0xFF; + buf.put(currByte, (byte) ((b & mask) | cmask)); + } else { + buf.put(currByte, (byte) correctedValue); + } + } + + private void putIntLE(int index, int length, int value) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask; + int correctedValue = value; + + /* + * mask v high bits. Works for unsigned and two complement signed + * numbers which value do not overflow on length bits. + */ + + if (length < BIT_INT) { + correctedValue &= ~(~0 << length); + } + + /* sub byte */ + if (startByte == (endByte - 1)) { + lshift = index % BIT_CHAR; + mask = ~((~0) << lshift); + if ((end % BIT_CHAR) > 0) { + mask |= (~(0)) << (end % BIT_CHAR); + } + cmask = correctedValue << lshift; + /* + * low bits are cleared because of lshift and high bits are already + * cleared + */ + cmask &= ~mask; + int b = buf.get(startByte) & 0xFF; + buf.put(startByte, (byte) ((b & mask) | cmask)); + return; + } + + /* head byte */ + currByte = startByte; + cshift = index % BIT_CHAR; + if (cshift > 0) { + mask = ~((~0) << cshift); + cmask = correctedValue << cshift; + cmask &= ~mask; + int b = buf.get(currByte) & 0xFF; + buf.put(currByte, (byte) ((b & mask) | cmask)); + correctedValue >>>= BIT_CHAR - cshift; + // index += BIT_CHAR - cshift; + currByte++; + } + + /* middle byte(s) */ + for (; currByte < (endByte - 1); currByte++) { + buf.put(currByte, (byte) correctedValue); + correctedValue >>>= BIT_CHAR; + } + /* end byte */ + if ((end % BIT_CHAR) > 0) { + mask = (~0) << (end % BIT_CHAR); + cmask = correctedValue & ~mask; + int b = buf.get(currByte) & 0xFF; + buf.put(currByte, (byte) ((b & mask) | cmask)); + } else { + buf.put(currByte, (byte) correctedValue); + } + } + + // ------------------------------------------------------------------------ + // Buffer attributes handling + // ------------------------------------------------------------------------ + + public boolean canRead(int length) { + return canRead(pos, length); + } + + public boolean canRead(int index, int length) { + if (buf == null) { + return false; + } + + if ((index + length) > (buf.capacity() * BIT_CHAR)) { + return false; + } + return true; + } + + public void order(ByteOrder order) { + this.byteOrder = order; + if (buf != null) { + buf.order(order); + } + } + + public ByteOrder order() { + return byteOrder; + } + + public void position(int newPosition) { + this.pos = newPosition; + } + + public int position() { + return pos; + } + + public void setByteBuffer(ByteBuffer buf) { + this.buf = buf; + if (buf != null) { + this.buf.order(byteOrder); + } + clear(); + } + + public ByteBuffer getByteBuffer() { + return buf; + } + + public void setByteOrder(ByteOrder byteOrder) { + this.byteOrder = byteOrder; + } + + public ByteOrder getByteOrder() { + return byteOrder; + } + + public void clear() { + position(0); + + if (buf == null) { + return; + } + buf.clear(); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java new file mode 100644 index 0000000000..57e887ecde --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java @@ -0,0 +1,311 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 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: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.metadata; + +import java.util.HashMap; + +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; + +/** + * DeclarationScope + *

+ * A DeclarationScope keeps track of the various CTF declarations for a given + * scope. + */ +public class DeclarationScope { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private DeclarationScope parentScope = null; + + private final HashMap structs = new HashMap(); + private final HashMap enums = new HashMap(); + private final HashMap variants = new HashMap(); + private final HashMap types = new HashMap(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Creates a declaration scope with no parent. + */ + public DeclarationScope() { + } + + /** + * Creates a declaration scope with the specified parent. + * + * @param parentScope + * The parent of the newly created scope. + */ + public DeclarationScope(DeclarationScope parentScope) { + this.parentScope = parentScope; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + /** + * Returns the parent of the current scope. + * + * @return The parent scope. + */ + public DeclarationScope getParentScope() { + return parentScope; + } + + // ------------------------------------------------------------------------ + // Registration operations + // ------------------------------------------------------------------------ + + /** + * Registers a type declaration. + * + * @param name + * The name of the type. + * @param declaration + * The type declaration. + * @throws ParseException + * if a type with the same name has already been defined. + */ + public void registerType(String name, IDeclaration declaration) + throws ParseException { + /* Check if the type has been defined in the current scope */ + if (types.containsKey(name)) { + throw new ParseException("Type " + name //$NON-NLS-1$ + + " has already been defined."); //$NON-NLS-1$ + } + + /* Add it to the register. */ + types.put(name, declaration); + } + + /** + * Registers a struct declaration. + * + * @param name + * The name of the struct. + * @param declaration + * The declaration of the struct. + * @throws ParseException + * if a struct with the same name has already been registered. + */ + public void registerStruct(String name, StructDeclaration declaration) + throws ParseException { + /* Check if the struct has been defined in the current scope. */ + if (structs.containsKey(name)) { + throw new ParseException("struct " + name //$NON-NLS-1$ + + " has already been defined."); //$NON-NLS-1$ + } + + /* Add it to the register. */ + structs.put(name, declaration); + + /* It also defined a new type, so add it to the type declarations. */ + String struct_prefix = "struct "; //$NON-NLS-1$ + registerType(struct_prefix + name, declaration); + } + + /** + * Registers an enum declaration. + * + * @param name + * The name of the enum. + * @param declaration + * The declaration of the enum. + * @throws ParseException + * if an enum with the same name has already been registered. + */ + public void registerEnum(String name, EnumDeclaration declaration) + throws ParseException { + /* Check if the enum has been defined in the current scope. */ + if (lookupEnum(name) != null) { + throw new ParseException("enum " + name //$NON-NLS-1$ + + " has already been defined."); //$NON-NLS-1$ + } + + /* Add it to the register. */ + enums.put(name, declaration); + + /* It also defined a new type, so add it to the type declarations. */ + String enum_prefix = "enum "; //$NON-NLS-1$ + registerType(enum_prefix + name, declaration); + } + + /** + * Registers a variant declaration. + * + * @param name + * The name of the variant. + * @param declaration + * The declaration of the variant. + * @throws ParseException + * if a variant with the same name has already been registered. + */ + public void registerVariant(String name, VariantDeclaration declaration) + throws ParseException { + /* Check if the variant has been defined in the current scope. */ + if (lookupVariant(name) != null) { + throw new ParseException("variant " + name //$NON-NLS-1$ + + " has already been defined."); //$NON-NLS-1$ + } + + /* Add it to the register. */ + variants.put(name, declaration); + + /* It also defined a new type, so add it to the type declarations. */ + String variant_prefix = "variant "; //$NON-NLS-1$ + registerType(variant_prefix + name, declaration); + } + + // ------------------------------------------------------------------------ + // Lookup operations + // ------------------------------------------------------------------------ + + /** + * Looks up a type declaration in the current scope. + * + * @param name + * The name of the type to search for. + * @return The type declaration, or null if no type with that name has been + * defined. + */ + public IDeclaration lookupType(String name) { + return types.get(name); + } + + /** + * Looks up a type declaration in the current scope and recursively in the + * parent scopes. + * + * @param name + * The name of the type to search for. + * @return The type declaration, or null if no type with that name has been + * defined. + */ + public IDeclaration rlookupType(String name) { + IDeclaration declaration = lookupType(name); + if (declaration != null) { + return declaration; + } else if (parentScope != null) { + return parentScope.rlookupType(name); + } else { + return null; + } + } + + /** + * Looks up a struct declaration. + * + * @param name + * The name of the struct to search for. + * @return The struct declaration, or null if no struct with that name has + * been defined. + */ + public StructDeclaration lookupStruct(String name) { + return structs.get(name); + } + + /** + * Looks up a struct declaration in the current scope and recursively in the + * parent scopes. + * + * @param name + * The name of the struct to search for. + * @return The struct declaration, or null if no struct with that name has + * been defined. + */ + public StructDeclaration rlookupStruct(String name) { + StructDeclaration declaration = lookupStruct(name); + if (declaration != null) { + return declaration; + } else if (parentScope != null) { + return parentScope.rlookupStruct(name); + } else { + return null; + } + } + + /** + * Looks up a enum declaration. + * + * @param name + * The name of the enum to search for. + * @return The enum declaration, or null if no enum with that name has been + * defined. + */ + public EnumDeclaration lookupEnum(String name) { + return enums.get(name); + } + + /** + * Looks up an enum declaration in the current scope and recursively in the + * parent scopes. + * + * @param name + * The name of the enum to search for. + * @return The enum declaration, or null if no enum with that name has been + * defined. + */ + public EnumDeclaration rlookupEnum(String name) { + EnumDeclaration declaration = lookupEnum(name); + if (declaration != null) { + return declaration; + } else if (parentScope != null) { + return parentScope.rlookupEnum(name); + } else { + return null; + } + } + + /** + * Looks up a variant declaration. + * + * @param name + * The name of the variant to search for. + * @return The variant declaration, or null if no variant with that name has + * been defined. + */ + public VariantDeclaration lookupVariant(String name) { + return variants.get(name); + } + + /** + * Looks up a variant declaration in the current scope and recursively in + * the parent scopes. + * + * @param name + * The name of the variant to search for. + * @return The variant declaration, or null if no variant with that name has + * been defined. + */ + public VariantDeclaration rlookupVariant(String name) { + VariantDeclaration declaration = lookupVariant(name); + if (declaration != null) { + return declaration; + } else if (parentScope != null) { + return parentScope.rlookupVariant(name); + } else { + return null; + } + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java new file mode 100644 index 0000000000..b5074ab48d --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/IOStructGen.java @@ -0,0 +1,2746 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 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 + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.metadata; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; + +import org.antlr.runtime.tree.CommonTree; +import org.eclipse.linuxtools.ctf.core.CtfCorePlugin; +import org.eclipse.linuxtools.ctf.core.event.CTFClock; +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +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.IDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.parser.CTFParser; + +/* + * 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. + */ +/* + * Suppress unchecked warnings for things like List children = + * root.getChildren(), because ANTLR doesn't know what generics are. + */ +/** + * IOStructGen + */ +@SuppressWarnings("unchecked") +public class IOStructGen { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + static private final boolean DEBUG_ = false; + + /** + * The trace + */ + private final CTFTrace trace; + private final CommonTree tree; + + /** + * The current declaration scope. + */ + private DeclarationScope scope = null; + + // ------------------------------------------------------------------------ + // Constructor + // ------------------------------------------------------------------------ + + public IOStructGen(CommonTree tree, CTFTrace trace) { + this.trace = trace; + this.tree = tree; + } + + public void generate() throws ParseException { + parseRoot(tree); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Parse the root node. + * + * @param root + * A ROOT node. + * @throws ParseException + */ + private void parseRoot(CommonTree root) throws ParseException { + assert (root.getType() == CTFParser.ROOT); + + List children = root.getChildren(); + assert (children != null); + java.io.FileOutputStream fos = null; + java.io.OutputStreamWriter out = null; + 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$ + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return; + } + } + + CommonTree traceNode = null; + List streams = new ArrayList(); + List events = new ArrayList(); + List declarations = new ArrayList(); + List environments = new ArrayList(); + List clocks = new ArrayList(); + /* Create a new declaration scope with no parent. */ + pushScope(); + + try { + for (CommonTree child : children) { + if (DEBUG_) { + out.write(child.toString() + + " -> " + child.getType() + '\n'); //$NON-NLS-1$ + } + switch (child.getType()) { + 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$ + } + traceNode = child; + break; + case CTFParser.STREAM: + streams.add(child); + break; + case CTFParser.EVENT: + events.add(child); + break; + case CTFParser.CLOCK: + clocks.add(child); + break; + case CTFParser.ENV: + environments.add(child); + break; + default: + childTypeError(child); + } + } + + if (DEBUG_) { + out.write("Environments\n"); //$NON-NLS-1$ + } + for (CommonTree environment : environments) { + parseEnvironment(environment); + } + 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 (traceNode == null) { + throw new ParseException("Missing trace block"); //$NON-NLS-1$ + } + + parseTrace(traceNode); + + if (DEBUG_) { + out.write("Streams\n"); //$NON-NLS-1$ + } + if (streams.size() > 0) { + for (CommonTree stream : streams) { + if (DEBUG_) { + try { + out.write(stream.toString() + '\n'); + } catch (IOException e) { + e.printStackTrace(); + } + } + parseStream(stream); + } + } else { + /* Add an empty stream that will have a null id */ + trace.addStream(new Stream(trace)); + } + + if (DEBUG_) { + out.write("Events\n"); //$NON-NLS-1$ + } + 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_) { + out.write("Name = " + name + " Id = " + id + '\n'); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + if (DEBUG_) { + out.close(); + fos.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + popScope(); + } + + private void parseEnvironment(CommonTree environment) { + List children = environment.getChildren(); + for (CommonTree child : children) { + String left; + String right; + left = child.getChild(0).getChild(0).getChild(0).getText(); + right = child.getChild(1).getChild(0).getChild(0).getText(); + trace.addEnvironmentVar(left, right); + } + } + + private void parseClock(CommonTree clock) { + List children = clock.getChildren(); + CTFClock ctfClock = new CTFClock(); + for (CommonTree child : children) { + 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: + //FIXME + //HACK + //EVIL + Long numValue; + try{ + numValue = Long.parseLong(value.getText()); + } + catch( Exception e) + { + numValue = 1330938566783103277L; + } + ctfClock.addAttribute(key, numValue); + break; + default: + ctfClock.addAttribute(key, value.getText()); + } + + } + String NameValue = ctfClock.getName(); + trace.addClock(NameValue, ctfClock); + } + + private void parseTrace(CommonTree traceNode) throws ParseException { + assert (traceNode.getType() == CTFParser.TRACE); + + List children = traceNode.getChildren(); + if (children == null) { + throw new ParseException("Trace block is empty"); //$NON-NLS-1$ + } + + pushScope(); + + for (CommonTree child : children) { + switch (child.getType()) { + case CTFParser.TYPEALIAS: + parseTypealias(child); + break; + case CTFParser.TYPEDEF: + parseTypedef(child); + break; + case CTFParser.CTF_EXPRESSION_TYPE: + case CTFParser.CTF_EXPRESSION_VAL: + parseTraceDeclaration(child); + break; + default: + childTypeError(child); + break; + } + } + + /* + * If trace byte order was not specified and not using packet based + * metadata + */ + if (trace.getByteOrder() == null) { + throw new ParseException("Trace byte order not set"); //$NON-NLS-1$ + } + + popScope(); + } + + 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 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$ + } + + String left = concatenateUnaryStrings(leftStrings); + + if (left.equals("major")) { //$NON-NLS-1$ + 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$ + 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$ + 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.getUUID().compareTo(uuid) != 0) { + throw new ParseException("UUID mismatch. Packet says " //$NON-NLS-1$ + + trace.getUUID() + " but metadata says " + uuid); //$NON-NLS-1$ + } + } else { + trace.setUUID(uuid); + } + + } else if (left.equals("byte_order")) { //$NON-NLS-1$ + ByteOrder byteOrder = getByteOrder(rightNode); + + /* + * If byte order was already set by a metadata packet, compare it to + * see if it matches + */ + if (trace.getByteOrder() != null) { + if (trace.getByteOrder() != byteOrder) { + throw new ParseException( + "Endianness mismatch. Magic number says " //$NON-NLS-1$ + + trace.getByteOrder() + + " but metadata says " + byteOrder); //$NON-NLS-1$ + } + } else { + trace.setByteOrder(byteOrder); + } + } else if (left.equals("packet.header")) { //$NON-NLS-1$ + if (trace.packetHeaderIsSet()) { + throw new ParseException("packet.header already defined"); //$NON-NLS-1$ + } + + 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$ + } + + IDeclaration packetHeaderDecl = parseTypeSpecifierList( + typeSpecifier, null); + + if (!(packetHeaderDecl instanceof StructDeclaration)) { + throw new ParseException("packet.header expects a struct"); //$NON-NLS-1$ + } + + trace.setPacketHeader((StructDeclaration) packetHeaderDecl); + } else { + throw new ParseException("Unknown trace attribute : " + left); //$NON-NLS-1$ + } + } + + private void parseStream(CommonTree streamNode) throws ParseException { + assert (streamNode.getType() == CTFParser.STREAM); + + Stream stream = new Stream(trace); + + List children = streamNode.getChildren(); + if (children == null) { + throw new ParseException("Empty stream block"); //$NON-NLS-1$ + } + + pushScope(); + + for (CommonTree child : children) { + switch (child.getType()) { + case CTFParser.TYPEALIAS: + parseTypealias(child); + break; + case CTFParser.TYPEDEF: + parseTypedef(child); + break; + case CTFParser.CTF_EXPRESSION_TYPE: + case CTFParser.CTF_EXPRESSION_VAL: + parseStreamDeclaration(child, stream); + break; + default: + childTypeError(child); + break; + } + } + + if (stream.idIsSet()) { + if (!trace.packetHeaderIsSet() + || !trace.getPacketHeader().hasField("stream_id")) { //$NON-NLS-1$ + throw new ParseException( + "Stream has an ID, but there is no stream_id field in packet header."); //$NON-NLS-1$ + } + } + + trace.addStream(stream); + + popScope(); + } + + 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 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$ + } + + String left = concatenateUnaryStrings(leftStrings); + + if (left.equals("id")) { //$NON-NLS-1$ + if (stream.idIsSet()) { + 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()) { + throw new ParseException("event.header already defined"); //$NON-NLS-1$ + } + + 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$ + } + + IDeclaration eventHeaderDecl = parseTypeSpecifierList( + typeSpecifier, null); + + if (!(eventHeaderDecl instanceof StructDeclaration)) { + throw new ParseException("event.header expects a struct"); //$NON-NLS-1$ + } + + stream.setEventHeader((StructDeclaration) eventHeaderDecl); + } else if (left.equals("event.context")) { //$NON-NLS-1$ + if (stream.eventContextIsSet()) { + throw new ParseException("event.context already defined"); //$NON-NLS-1$ + } + + 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$ + } + + IDeclaration eventContextDecl = parseTypeSpecifierList( + typeSpecifier, null); + + if (!(eventContextDecl instanceof StructDeclaration)) { + throw new ParseException("event.context expects a struct"); //$NON-NLS-1$ + } + + stream.setEventContext((StructDeclaration) eventContextDecl); + } else if (left.equals("packet.context")) { //$NON-NLS-1$ + if (stream.packetContextIsSet()) { + throw new ParseException("packet.context already defined"); //$NON-NLS-1$ + } + + 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$ + } + + IDeclaration packetContextDecl = parseTypeSpecifierList( + typeSpecifier, null); + + if (!(packetContextDecl instanceof StructDeclaration)) { + throw new ParseException("packet.context expects a struct"); //$NON-NLS-1$ + } + + stream.setPacketContext((StructDeclaration) packetContextDecl); + } else { + throw new ParseException("Unknown stream attribute : " + left); //$NON-NLS-1$ + } + } + + private void parseEvent(CommonTree eventNode) throws ParseException { + assert (eventNode.getType() == CTFParser.EVENT); + + List children = eventNode.getChildren(); + if (children == null) { + throw new ParseException("Empty event block"); //$NON-NLS-1$ + } + + EventDeclaration event = new EventDeclaration(); + + pushScope(); + + for (CommonTree child : children) { + switch (child.getType()) { + case CTFParser.TYPEALIAS: + parseTypealias(child); + break; + case CTFParser.TYPEDEF: + parseTypedef(child); + break; + case CTFParser.CTF_EXPRESSION_TYPE: + case CTFParser.CTF_EXPRESSION_VAL: + parseEventDeclaration(child, event); + break; + default: + childTypeError(child); + break; + } + } + + if (!event.nameIsSet()) { + throw new ParseException("Event name not set"); //$NON-NLS-1$ + } + + /* + * If the event did not specify a stream, then the trace must be single + * stream + */ + if (!event.streamIsSet()) { + if (trace.nbStreams() > 1) { + throw new ParseException( + "Event without stream_id with more than one stream"); //$NON-NLS-1$ + } + + /* + * If the event did not specify a stream, the only existing stream + * must not have an id. Note: That behavior could be changed, it + * could be possible to just get the only existing stream, whatever + * is its id. + */ + Stream stream = trace.getStream(null); + + if (stream != null) { + event.setStream(stream); + } else { + throw new ParseException( + "Event without stream_id, but there is no stream without id"); //$NON-NLS-1$ + } + } + + /* + * Add the event to the stream. + */ + event.getStream().addEvent(event); + + popScope(); + } + + 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 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$ + } + + String left = concatenateUnaryStrings(leftStrings); + + if (left.equals("name")) { //$NON-NLS-1$ + 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$ + 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$ + if (event.streamIsSet()) { + throw new ParseException("stream id already defined"); //$NON-NLS-1$ + } + + long streamId = getStreamID(rightNode); + + Stream stream = trace.getStream(streamId); + + if (stream == null) { + throw new ParseException("Stream " + streamId + " not found"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + event.setStream(stream); + } else if (left.equals("context")) { //$NON-NLS-1$ + if (event.contextIsSet()) { + throw new ParseException("context already defined"); //$NON-NLS-1$ + } + + CommonTree typeSpecifier = (CommonTree) rightNode.getChild(0); + + if (typeSpecifier.getType() != CTFParser.TYPE_SPECIFIER_LIST) { + throw new ParseException("context expects a type specifier"); //$NON-NLS-1$ + } + + IDeclaration contextDecl = parseTypeSpecifierList(typeSpecifier, + null); + + if (!(contextDecl instanceof StructDeclaration)) { + throw new ParseException("context expects a struct"); //$NON-NLS-1$ + } + + event.setContext((StructDeclaration) contextDecl); + } else if (left.equals("fields")) { //$NON-NLS-1$ + if (event.fieldsIsSet()) { + throw new ParseException("fields already defined"); //$NON-NLS-1$ + } + + CommonTree typeSpecifier = (CommonTree) rightNode.getChild(0); + + if (typeSpecifier.getType() != CTFParser.TYPE_SPECIFIER_LIST) { + throw new ParseException("fields expects a type specifier"); //$NON-NLS-1$ + } + + IDeclaration fieldsDecl = parseTypeSpecifierList(typeSpecifier, + null); + + if (!(fieldsDecl instanceof StructDeclaration)) { + throw new ParseException("fields expects a struct"); //$NON-NLS-1$ + } + /* + * The following is done to remove the underscores in the event + * names. These underscores were added by the LTTng tracer. + */ + StructDeclaration fields = (StructDeclaration) fieldsDecl; + HashMap fieldMap = fields.getFields(); + List fieldsList = fields.getFieldsList(); + HashMap translationMap = new HashMap(); + Set keys = fieldMap.keySet(); + for (String key : keys) { + if (key.startsWith("_", 0)) {//$NON-NLS-1$ + final String newKey = key.substring(1); + translationMap.put(key, newKey); + fieldsList.set(fieldsList.indexOf(key), newKey); + } + } + Iterator> it = translationMap.entrySet() + .iterator(); + while (it.hasNext()) { + final Entry pairs = it.next(); + final String oldKey = pairs.getKey(); + final String newKey = pairs.getValue(); + final IDeclaration value = fieldMap.get(oldKey); + fieldMap.put(newKey, value); + fieldMap.remove(oldKey); + } + event.setFields(fields); + + } else { + throw new ParseException("Unknown event attribute : " + left); //$NON-NLS-1$ + } + } + + /** + * Parses a declaration at the root level. + * + * @param declaration + * The declaration subtree. + * @throws ParseException + */ + private void parseRootDeclaration(CommonTree declaration) + throws ParseException { + assert (declaration.getType() == CTFParser.DECLARATION); + + List children = declaration.getChildren(); + assert (children != null); + + for (CommonTree child : children) { + switch (child.getType()) { + case CTFParser.TYPEDEF: + parseTypedef(child); + break; + case CTFParser.TYPEALIAS: + parseTypealias(child); + break; + case CTFParser.TYPE_SPECIFIER_LIST: + parseTypeSpecifierList(child, null); + break; + default: + childTypeError(child); + } + } + } + + /** + * Parses a typealias node. It parses the target, the alias, and registers + * the type in the current scope. + * + * @param typealias + * A TYPEALIAS node. + * @throws ParseException + */ + private void parseTypealias(CommonTree typealias) throws ParseException { + assert (typealias.getType() == CTFParser.TYPEALIAS); + + List children = typealias.getChildren(); + assert (children != null); + + CommonTree target = null; + CommonTree alias = null; + + 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: + childTypeError(child); + break; + } + } + + 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$ + } + } + + String aliasString = parseTypealiasAlias(alias); + + getCurrentScope().registerType(aliasString, targetDeclaration); + } + + /** + * Parses the target part of a typealias and gets the corresponding + * declaration. + * + * @param target + * A TYPEALIAS_TARGET node. + * @return The corresponding declaration. + * @throws ParseException + */ + private IDeclaration parseTypealiasTarget(CommonTree target) + throws ParseException { + assert (target.getType() == CTFParser.TYPEALIAS_TARGET); + + List children = target.getChildren(); + assert (children != null); + + CommonTree typeSpecifierList = null; + CommonTree typeDeclaratorList = null; + CommonTree typeDeclarator = null; + StringBuilder identifierSB = new StringBuilder(); + + 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: + childTypeError(child); + break; + } + } + + assert (typeSpecifierList != null); + + if (typeDeclaratorList != null) { + /* + * Only allow one declarator + * + * eg: "typealias uint8_t *, ** := puint8_t;" is not permitted, + * otherwise the new type puint8_t would maps to two different + * types. + */ + if (typeDeclaratorList.getChildCount() != 1) { + throw new ParseException( + "Only one type declarator is allowed in the typealias target"); //$NON-NLS-1$ + } + + typeDeclarator = (CommonTree) typeDeclaratorList.getChild(0); + } + + /* Parse the target type and get the declaration */ + IDeclaration targetDeclaration = parseTypeDeclarator(typeDeclarator, + typeSpecifierList, identifierSB); + + /* + * We don't allow identifier in the target + * + * eg: "typealias uint8_t* hello := puint8_t;", the "hello" is not + * permitted + */ + if (identifierSB.length() > 0) { + throw new ParseException("Identifier (" + identifierSB.toString() //$NON-NLS-1$ + + ") not expected in the typealias target"); //$NON-NLS-1$ + } + + return targetDeclaration; + } + + /** + * Parses the alias part of a typealias. It parses the underlying specifier + * list and declarator and creates the string representation that will be + * used to register the type. + * + * @param alias + * A TYPEALIAS_ALIAS node. + * @return The string representation of the alias. + * @throws ParseException + */ + private static String parseTypealiasAlias(CommonTree alias) + throws ParseException { + assert (alias.getType() == CTFParser.TYPEALIAS_ALIAS); + + List children = alias.getChildren(); + assert (children != null); + + CommonTree typeSpecifierList = null; + CommonTree typeDeclaratorList = null; + CommonTree typeDeclarator = null; + List pointers = new LinkedList(); + + 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: + childTypeError(child); + break; + } + } + + /* If there is a type declarator list, extract the pointers */ + if (typeDeclaratorList != null) { + /* + * Only allow one declarator + * + * 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$ + } + + typeDeclarator = (CommonTree) typeDeclaratorList.getChild(0); + + List typeDeclaratorChildren = typeDeclarator + .getChildren(); + assert (typeDeclaratorChildren != null); + + for (CommonTree child : typeDeclaratorChildren) { + switch (child.getType()) { + case CTFParser.POINTER: + pointers.add(child); + break; + 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; + } + } + } + + return createTypeDeclarationString(typeSpecifierList, pointers); + } + + /** + * Parses a typedef node. This creates and registers a new declaration for + * each declarator found in the typedef. + * + * @param typedef + * A TYPEDEF node. + * @throws ParseException + * 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 typeSpecifierListNode = (CommonTree) typedef + .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST); + assert (typeSpecifierListNode != null); + + List typeDeclaratorList = typeDeclaratorListNode + .getChildren(); + assert (typeDeclaratorList != null); + + for (CommonTree typeDeclaratorNode : typeDeclaratorList) { + StringBuilder identifierSB = new StringBuilder(); + + IDeclaration type_declaration = 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$ + } + } + + getCurrentScope().registerType(identifierSB.toString(), + type_declaration); + } + } + + /** + * Parses a pair type declarator / type specifier list and returns the + * corresponding declaration. If it is present, it also writes the + * identifier of the declarator in the given {@link StringBuilder}. + * + * @param typeDeclarator + * A TYPE_DECLARATOR node. + * @param typeSpecifierList + * A TYPE_SPECIFIER_LIST node. + * @param identifierSB + * A StringBuilder that will receive the identifier found in the + * declarator. + * @return The corresponding declaration. + * @throws ParseException + * If there is an error finding or creating the declaration. + */ + 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 children = null; + List pointers = new LinkedList(); + List lengths = new LinkedList(); + CommonTree identifier = null; + + /* Separate the tokens by type */ + if (typeDeclarator != null) { + children = typeDeclarator.getChildren(); + assert (children != null); + for (CommonTree child : children) { + + switch (child.getType()) { + case CTFParser.POINTER: + pointers.add(child); + break; + case CTFParser.IDENTIFIER: + assert (identifier == null); + identifier = child; + break; + case CTFParser.LENGTH: + lengths.add(child); + break; + default: + childTypeError(child); + break; + } + } + + } + + /* + * Parse the type specifier list, which is the "base" type. For example, + * it would be int in int a[3][len]. + */ + declaration = parseTypeSpecifierList(typeSpecifierList, pointers); + + /* + * Each length subscript means that we must create a nested array or + * sequence. For example, int a[3][len] means that we have an array of 3 + * (sequences of length 'len' of (int)). + */ + if (lengths != null) { + /* We begin at the end */ + Collections.reverse(lengths); + + for (CommonTree length : lengths) { + /* + * By looking at the first expression, we can determine whether + * it is an array or a sequence. + */ + List lengthChildren = length.getChildren(); + assert (lengthChildren != null); + + CommonTree first = lengthChildren.get(0); + if (isUnaryInteger(first)) { + /* Array */ + int arrayLength = (int) parseUnaryInteger(first); + + if (arrayLength < 1) { + throw new ParseException("Array length is negative"); //$NON-NLS-1$ + } + + /* Create the array declaration. */ + declaration = new ArrayDeclaration(arrayLength, declaration); + } else if (isUnaryString(first)) { + /* Sequence */ + String lengthName = concatenateUnaryStrings(lengthChildren); + + /* Create the sequence declaration. */ + declaration = new SequenceDeclaration(lengthName, + declaration); + } else { + childTypeError(first); + } + } + } + + if (identifier != null) { + identifierSB.append(identifier.getText()); + } + + return declaration; + } + + /** + * Parses a type specifier list and returns the corresponding declaration. + * + * @param typeSpecifierList + * A TYPE_SPECIFIER_LIST node. + * @param pointerList + * A list of POINTER nodes that apply to the specified type. + * @return The corresponding declaration. + * @throws ParseException + * If the type has not been defined or if there is an error + * creating the declaration. + */ + private IDeclaration parseTypeSpecifierList(CommonTree typeSpecifierList, + List pointerList) throws ParseException { + assert (typeSpecifierList.getType() == CTFParser.TYPE_SPECIFIER_LIST); + IDeclaration declaration = null; + + /* + * By looking at the first element of the type specifier list, we can + * determine which type it belongs to. + */ + CommonTree firstChild = (CommonTree) typeSpecifierList.getChild(0); + assert (firstChild != null); /* grammar */ + + switch (firstChild.getType()) { + case CTFParser.FLOATING_POINT: + CtfCorePlugin + .getDefault() + .log("parseTypeSpecifierList: floating_point not implemented yet"); //$NON-NLS-1$ + break; + case CTFParser.INTEGER: + declaration = parseInteger(firstChild); + break; + case CTFParser.STRING: + declaration = parseString(firstChild); + break; + case CTFParser.STRUCT: + declaration = parseStruct(firstChild); + break; + case CTFParser.VARIANT: + declaration = parseVariant(firstChild); + break; + case CTFParser.ENUM: + declaration = parseEnum(firstChild); + break; + case CTFParser.IDENTIFIER: + case CTFParser.FLOATTOK: + case CTFParser.INTTOK: + case CTFParser.LONGTOK: + case CTFParser.SHORTTOK: + case CTFParser.SIGNEDTOK: + case CTFParser.UNSIGNEDTOK: + case CTFParser.CHARTOK: + case CTFParser.DOUBLETOK: + case CTFParser.VOIDTOK: + case CTFParser.BOOLTOK: + case CTFParser.COMPLEXTOK: + case CTFParser.IMAGINARYTOK: + declaration = parseTypeDeclaration(typeSpecifierList, pointerList); + break; + default: + childTypeError(firstChild); + } + + assert (declaration != null); + return declaration; + } + + /** + * Parses a type specifier list as a user-declared type. + * + * @param typeSpecifierList + * A TYPE_SPECIFIER_LIST node containing a user-declared type. + * @param pointerList + * A list of POINTER nodes that apply to the type specified in + * typeSpecifierList. + * @return The corresponding declaration. + * @throws ParseException + * If the type does not exist (has not been found). + */ + private IDeclaration parseTypeDeclaration(CommonTree typeSpecifierList, + List pointerList) throws ParseException { + /* Create the string representation of the type declaration */ + String typeStringRepresentation = createTypeDeclarationString( + typeSpecifierList, pointerList); + + /* Use the string representation to search the type in the current scope */ + IDeclaration decl = getCurrentScope().rlookupType( + typeStringRepresentation); + + if (decl == null) { + throw new ParseException("Type " + typeStringRepresentation //$NON-NLS-1$ + + " has not been defined."); //$NON-NLS-1$ + } + + return decl; + } + + /** + * Parses an integer declaration node. + * + * @param integer + * An INTEGER node. + * @return The corresponding integer declaration. + * @throws ParseException + */ + private IntegerDeclaration parseInteger(CommonTree integer) + throws ParseException { + assert (integer.getType() == CTFParser.INTEGER); + + List children = integer.getChildren(); + + /* + * If the integer has no attributes, then it is missing the size + * attribute which is required + */ + if (children == null) { + throw new ParseException("integer: missing size attribute"); //$NON-NLS-1$ + } + + /* The return value */ + IntegerDeclaration integerDeclaration = null; + boolean signed = false; + ByteOrder byteOrder = trace.getByteOrder(); + long size = 0; + long alignment = 0; + int base = 10; + @SuppressWarnings("unused") + String clock; + + Encoding encoding = Encoding.NONE; + + /* 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 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("signed")) { //$NON-NLS-1$ + signed = getSigned(rightNode); + } else if (left.equals("byte_order")) { //$NON-NLS-1$ + byteOrder = getByteOrder(rightNode); + } else if (left.equals("size")) { //$NON-NLS-1$ + size = getSize(rightNode); + } else if (left.equals("align")) { //$NON-NLS-1$ + alignment = getAlignment(rightNode); + } else if (left.equals("base")) { //$NON-NLS-1$ + base = getBase(rightNode); + } else if (left.equals("encoding")) { //$NON-NLS-1$ + encoding = getEncoding(rightNode); + } else if (left.equals("map")) { //$NON-NLS-1$ + clock = getClock(rightNode); + } else { + throw new ParseException("Integer: unknown attribute " + left); //$NON-NLS-1$ + } + + break; + default: + childTypeError(child); + break; + } + } + + if (size == 0) { + throw new ParseException("Integer missing size attribute"); //$NON-NLS-1$ + } + + if (alignment == 0) { + if ((size % 8) == 0) { + alignment = 1; + } else { + alignment = 8; + } + } + + integerDeclaration = new IntegerDeclaration((int) size, signed, base, + byteOrder, encoding); + + assert (integerDeclaration != null); + return integerDeclaration; + } + + private String getClock(CommonTree rightNode) { + return rightNode.getChild(1).getChild(0).getChild(0).getText(); + } + + private static StringDeclaration parseString(CommonTree string) + throws ParseException { + assert (string.getType() == CTFParser.STRING); + + List children = string.getChildren(); + StringDeclaration stringDeclaration = null; + + if (children == null) { + stringDeclaration = new StringDeclaration(); + } else { + Encoding encoding = Encoding.UTF8; + 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 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("encoding")) { //$NON-NLS-1$ + encoding = getEncoding(rightNode); + } else { + throw new ParseException("String: unknown attribute " //$NON-NLS-1$ + + left); + } + + break; + default: + childTypeError(child); + break; + } + } + + stringDeclaration = new StringDeclaration(encoding); + } + + return stringDeclaration; + } + + /** + * Parses a struct declaration and returns the corresponding declaration. + * + * @param struct + * An STRUCT node. + * @return The corresponding struct declaration. + * @throws ParseException + */ + private StructDeclaration parseStruct(CommonTree struct) + throws ParseException { + assert (struct.getType() == CTFParser.STRUCT); + + List children = struct.getChildren(); + assert (children != null); + + /* The return value */ + StructDeclaration structDeclaration = null; + + /* Name */ + String structName = null; + boolean hasName = false; + + /* Body */ + CommonTree structBody = null; + boolean hasBody = false; + + /* Align */ + long structAlign = 0; + + /* Loop on all children and identify what we have to work with. */ + for (CommonTree child : children) { + switch (child.getType()) { + case CTFParser.STRUCT_NAME: { + hasName = true; + + assert (child.getChildCount() == 1); + CommonTree structNameIdentifier = (CommonTree) child + .getChild(0); + + assert (structNameIdentifier.getType() == CTFParser.IDENTIFIER); + structName = structNameIdentifier.getText(); + + break; + } + case CTFParser.STRUCT_BODY: { + hasBody = true; + + structBody = child; + + break; + } + case CTFParser.ALIGN: { + assert (child.getChildCount() == 1); + CommonTree structAlignExpression = (CommonTree) child + .getChild(0); + + structAlign = getAlignment(structAlignExpression); + + break; + } + default: + childTypeError(child); + + break; + } + } + + /* + * If a struct has just a body and no name (just like the song, + * "A Struct With No Name" by America (sorry for that...)), it's a + * definition of a new type, so we create the type declaration and + * return it. We can't add it to the declaration scope since there is no + * name, but that's what we want because it won't be possible to use it + * again to declare another field. + * + * If it has just a name, we look it up in the declaration scope and + * return the associated declaration. If it is not found in the + * declaration scope, it means that a struct with that name has not been + * declared, which is an error. + * + * If it has both, then we create the type declaration and register it + * to the current scope. + * + * If it has none, then what are we doing here ? + */ + if (hasBody) { + /* + * If struct has a name, check if already defined in the current + * scope. + */ + if (hasName && (getCurrentScope().lookupStruct(structName) != null)) { + throw new ParseException("struct " + structName //$NON-NLS-1$ + + " already defined."); //$NON-NLS-1$ + } + + /* Create the declaration */ + structDeclaration = new StructDeclaration(structAlign); + + /* Parse the body */ + parseStructBody(structBody, structDeclaration); + + /* If struct has name, add it to the current scope. */ + if (hasName) { + getCurrentScope().registerStruct(structName, structDeclaration); + } + } else /* !hasBody */{ + if (hasName) { + /* Name and !body */ + + /* Lookup the name in the current scope. */ + structDeclaration = getCurrentScope().rlookupStruct(structName); + + /* + * If not found, it means that a struct with such name has not + * been defined + */ + if (structDeclaration == null) { + throw new ParseException("struct " + structName //$NON-NLS-1$ + + " is not defined"); //$NON-NLS-1$ + } + } else { + /* !Name and !body */ + + /* We can't do anything with that. */ + throw new ParseException("struct with no name and no body"); //$NON-NLS-1$ + } + } + + assert (structDeclaration != null); + return structDeclaration; + } + + /** + * Parses a struct body, adding the fields to specified structure + * declaration. + * + * @param structBody + * A STRUCT_BODY node. + * @param structDeclaration + * The struct declaration. + * @throws ParseException + */ + private void parseStructBody(CommonTree structBody, + StructDeclaration structDeclaration) throws ParseException { + assert (structBody.getType() == CTFParser.STRUCT_BODY); + + List structDeclarations = structBody.getChildren(); + + /* + * If structDeclaration is null, structBody has no children and the + * struct body is empty. + */ + if (structDeclarations != null) { + pushScope(); + + for (CommonTree declarationNode : structDeclarations) { + switch (declarationNode.getType()) { + case CTFParser.TYPEALIAS: + parseTypealias(declarationNode); + break; + case CTFParser.TYPEDEF: + parseTypedef(declarationNode); + break; + case CTFParser.SV_DECLARATION: + parseStructDeclaration(declarationNode, structDeclaration); + break; + default: + childTypeError(declarationNode); + break; + } + } + popScope(); + } + } + + /** + * Parses a declaration found in a struct. + * + * @param declaration + * A SV_DECLARATION node. + * @param struct + * A struct declaration. (I know, little name clash here...) + * @throws ParseException + */ + private void parseStructDeclaration(CommonTree declaration, + StructDeclaration struct) throws ParseException { + assert (declaration.getType() == CTFParser.SV_DECLARATION); + + List children = declaration.getChildren(); + assert (children != null); + + /* Get the type specifier list node */ + CommonTree typeSpecifierListNode = (CommonTree) declaration + .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST); + assert (typeSpecifierListNode != null); + + /* Get the type declarator list node */ + CommonTree typeDeclaratorListNode = (CommonTree) declaration + .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST); + assert (typeDeclaratorListNode != null); + + /* Get the type declarator list */ + List typeDeclaratorList = typeDeclaratorListNode + .getChildren(); + assert (typeDeclaratorList != null); + + /* + * 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(); + if (identifierSB.charAt(0) == '_') { + fieldName = identifierSB.substring(1); + } + + if (struct.hasField(fieldName)) { + throw new ParseException("struct: duplicate field " //$NON-NLS-1$ + + fieldName); + } + + struct.addField(fieldName, decl); + + } + } + + /** + * Parses an enum declaration and returns the corresponding declaration. + * + * @param _enum + * An ENUM node. + * @return The corresponding enum declaration. + * @throws ParseException + */ + private EnumDeclaration parseEnum(CommonTree _enum) throws ParseException { + assert (_enum.getType() == CTFParser.ENUM); + + List children = _enum.getChildren(); + assert (children != null); + + /* The return value */ + EnumDeclaration enumDeclaration = null; + + /* Name */ + String enumName = null; + + /* Body */ + CommonTree enumBody = null; + + /* Container type */ + IntegerDeclaration containerTypeDeclaration = null; + + /* Loop on all children and identify what we have to work with. */ + 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: + childTypeError(child); + break; + } + } + + /* + * If the container type has not been defined explicitly, we assume it + * is "int". + */ + if (containerTypeDeclaration == null) { + IDeclaration decl = getCurrentScope().rlookupType("int"); //$NON-NLS-1$ + + if (decl == null) { + 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$ + } + + containerTypeDeclaration = (IntegerDeclaration) decl; + } + + /* + * If it has a body, it's a new declaration, otherwise it's a reference + * to an existing declaration. Same logic as struct. + */ + if (enumBody != null) { + /* + * If enum has a name, check if already defined in the current + * scope. + */ + if ((enumName != null) + && (getCurrentScope().lookupEnum(enumName) != null)) { + throw new ParseException("enum " + enumName //$NON-NLS-1$ + + " already defined"); //$NON-NLS-1$ + } + + /* Create the declaration */ + enumDeclaration = new EnumDeclaration(containerTypeDeclaration); + + /* Parse the body */ + parseEnumBody(enumBody, enumDeclaration); + + /* If the enum has name, add it to the current scope. */ + if (enumName != null) { + getCurrentScope().registerEnum(enumName, enumDeclaration); + } + } else { + if (enumName != null) { + /* Name and !body */ + + /* Lookup the name in the current scope. */ + enumDeclaration = getCurrentScope().rlookupEnum(enumName); + + /* + * If not found, it means that an enum with such name has not + * been defined + */ + if (enumDeclaration == null) { + throw new ParseException("enum " + enumName //$NON-NLS-1$ + + " is not defined"); //$NON-NLS-1$ + } + } else { + /* !Name and !body */ + throw new ParseException("enum with no name and no body"); //$NON-NLS-1$ + } + } + + return enumDeclaration; + + } + + /** + * Parses an enum body, adding the enumerators to the specified enum + * declaration. + * + * @param enumBody + * An ENUM_BODY node. + * @param enumDeclaration + * The enum declaration. + * @throws ParseException + */ + private void parseEnumBody(CommonTree enumBody, + EnumDeclaration enumDeclaration) throws ParseException { + assert (enumBody.getType() == CTFParser.ENUM_BODY); + + List enumerators = enumBody.getChildren(); + /* enum body can't be empty (unlike struct). */ + assert (enumerators != null); + + pushScope(); + + /* + * Start at -1, so that if the first enumrator has no explicit value, it + * will choose 0 + */ + long lastHigh = -1; + + for (CommonTree enumerator : enumerators) { + lastHigh = parseEnumEnumerator(enumerator, enumDeclaration, + lastHigh); + } + + popScope(); + + } + + /** + * Parses an enumerator node and adds an enumerator declaration to an + * enumeration declaration. + * + * The high value of the range of the last enumerator is needed in case the + * current enumerator does not specify its value. + * + * @param enumerator + * An ENUM_ENUMERATOR node. + * @param enumDeclaration + * en enumeration declaration to which will be added the + * enumerator. + * @param lastHigh + * The high value of the range of the last enumerator + * @return The high value of the value range of the current enumerator. + * @throws ParseException + */ + private static long parseEnumEnumerator(CommonTree enumerator, + EnumDeclaration enumDeclaration, long lastHigh) + throws ParseException { + assert (enumerator.getType() == CTFParser.ENUM_ENUMERATOR); + + List children = enumerator.getChildren(); + assert (children != null); + + long low = 0, high = 0; + boolean valueSpecified = false; + String label = null; + + for (CommonTree child : children) { + if (isUnaryString(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; + + low = parseUnaryInteger((CommonTree) child.getChild(0)); + high = parseUnaryInteger((CommonTree) child.getChild(1)); + } else { + childTypeError(child); + } + } + + assert (label != null); + + if (!valueSpecified) { + low = lastHigh + 1; + high = low; + } + + if (low > high) { + throw new ParseException("enum low value greater than high value"); //$NON-NLS-1$ + } + + if (!enumDeclaration.add(low, high, label)) { + throw new ParseException("enum declarator values overlap."); //$NON-NLS-1$ + } + + return high; + } + + /** + * Parses an enum container type node and returns the corresponding integer + * type. + * + * @param enumContainerType + * An ENUM_CONTAINER_TYPE node. + * @return An integer declaration corresponding to the container type. + * @throws ParseException + * If the type does not parse correctly or if it is not an + * integer type. + */ + 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); + + /* Parse it and get the corresponding declaration */ + IDeclaration decl = parseTypeSpecifierList(typeSpecifierList, null); + + /* If is is an integer, return it, else throw an error */ + if (decl instanceof IntegerDeclaration) { + return (IntegerDeclaration) decl; + } + throw new ParseException("enum container type must be an integer"); //$NON-NLS-1$ + } + + private VariantDeclaration parseVariant(CommonTree variant) + throws ParseException { + assert (variant.getType() == CTFParser.VARIANT); + + List children = variant.getChildren(); + VariantDeclaration variantDeclaration = null; + + boolean hasName = false; + String variantName = null; + + boolean hasBody = false; + CommonTree variantBody = null; + + boolean hasTag = false; + String variantTag = null; + + 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); + + 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); + + assert (variantTagIdentifier.getType() == CTFParser.IDENTIFIER); + variantTag = variantTagIdentifier.getText(); + + break; + case CTFParser.VARIANT_BODY: + assert (variantBody == null); + + hasBody = true; + + variantBody = child; + + break; + default: + childTypeError(child); + break; + } + } + + if (hasBody) { + /* + * If variant has a name, check if already defined in the current + * scope. + */ + if (hasName + && (getCurrentScope().lookupVariant(variantName) != null)) { + throw new ParseException("variant " + variantName //$NON-NLS-1$ + + " already defined."); //$NON-NLS-1$ + } + + /* Create the declaration */ + variantDeclaration = new VariantDeclaration(); + + /* Parse the body */ + parseVariantBody(variantBody, variantDeclaration); + + /* If variant has name, add it to the current scope. */ + if (hasName) { + getCurrentScope().registerVariant(variantName, + variantDeclaration); + } + } else /* !hasBody */{ + if (hasName) { + /* Name and !body */ + + /* Lookup the name in the current scope. */ + variantDeclaration = getCurrentScope().rlookupVariant( + variantName); + + /* + * If not found, it means that a struct with such name has not + * been defined + */ + if (variantDeclaration == null) { + throw new ParseException("variant " + variantName //$NON-NLS-1$ + + " is not defined"); //$NON-NLS-1$ + } + } else { + /* !Name and !body */ + + /* We can't do anything with that. */ + throw new ParseException("variant with no name and no body"); //$NON-NLS-1$ + } + } + + if (hasTag) { + variantDeclaration.setTag(variantTag); + } + + assert (variantDeclaration != null); + return variantDeclaration; + } + + private void parseVariantBody(CommonTree variantBody, + VariantDeclaration variantDeclaration) throws ParseException { + assert (variantBody.getType() == CTFParser.VARIANT_BODY); + + List variantDeclarations = variantBody.getChildren(); + assert (variantDeclarations != null); + + pushScope(); + + for (CommonTree declarationNode : variantDeclarations) { + switch (declarationNode.getType()) { + case CTFParser.TYPEALIAS: + parseTypealias(declarationNode); + break; + case CTFParser.TYPEDEF: + parseTypedef(declarationNode); + break; + case CTFParser.SV_DECLARATION: + parseVariantDeclaration(declarationNode, variantDeclaration); + break; + default: + childTypeError(declarationNode); + break; + } + } + + popScope(); + } + + private void parseVariantDeclaration(CommonTree declaration, + VariantDeclaration variant) throws ParseException { + assert (declaration.getType() == CTFParser.SV_DECLARATION); + + List children = declaration.getChildren(); + assert (children != null); + + /* Get the type specifier list node */ + CommonTree typeSpecifierListNode = (CommonTree) declaration + .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST); + assert (typeSpecifierListNode != null); + + /* Get the type declarator list node */ + CommonTree typeDeclaratorListNode = (CommonTree) declaration + .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST); + assert (typeDeclaratorListNode != null); + + /* Get the type declarator list */ + List typeDeclaratorList = typeDeclaratorListNode + .getChildren(); + assert (typeDeclaratorList != null); + + /* + * 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())) { + throw new ParseException("variant: duplicate field " //$NON-NLS-1$ + + identifierSB.toString()); + } + + variant.addField(identifierSB.toString(), decl); + } + } + + /** + * Creates the string representation of a type declaration (type specifier + * list + pointers). + * + * @param typeSpecifierList + * A TYPE_SPECIFIER_LIST node. + * @param pointers + * A list of POINTER nodes. + * @return The string representation. + * @throws ParseException + */ + private static String createTypeDeclarationString( + CommonTree typeSpecifierList, List pointers) + throws ParseException { + StringBuilder sb = new StringBuilder(); + + createTypeSpecifierListString(typeSpecifierList, sb); + createPointerListString(pointers, sb); + + return sb.toString(); + } + + /** + * Creates the string representation of a list of type specifiers. + * + * @param typeSpecifierList + * A TYPE_SPECIFIER_LIST node. + * @param sb + * A StringBuilder to which will be appended the string. + * @throws ParseException + */ + private static void createTypeSpecifierListString( + CommonTree typeSpecifierList, StringBuilder sb) + throws ParseException { + assert (typeSpecifierList.getType() == CTFParser.TYPE_SPECIFIER_LIST); + + List children = typeSpecifierList.getChildren(); + assert (children != null); + + boolean firstItem = true; + + for (CommonTree child : children) { + if (!firstItem) { + sb.append(' '); + + } + + firstItem = false; + + /* Append the string that represents this type specifier. */ + createTypeSpecifierString(child, sb); + } + } + + /** + * Creates the string representation of a type specifier. + * + * @param typeSpecifier + * A TYPE_SPECIFIER node. + * @param sb + * A StringBuilder to which will be appended the string. + * @throws ParseException + */ + private static void createTypeSpecifierString(CommonTree typeSpecifier, + StringBuilder sb) throws ParseException { + switch (typeSpecifier.getType()) { + case CTFParser.FLOATTOK: + case CTFParser.INTTOK: + case CTFParser.LONGTOK: + case CTFParser.SHORTTOK: + case CTFParser.SIGNEDTOK: + case CTFParser.UNSIGNEDTOK: + case CTFParser.CHARTOK: + case CTFParser.DOUBLETOK: + case CTFParser.VOIDTOK: + case CTFParser.BOOLTOK: + case CTFParser.COMPLEXTOK: + case CTFParser.IMAGINARYTOK: + case CTFParser.CONSTTOK: + case CTFParser.IDENTIFIER: + sb.append(typeSpecifier.getText()); + break; + case CTFParser.STRUCT: { + CommonTree structName = (CommonTree) typeSpecifier + .getFirstChildWithType(CTFParser.STRUCT_NAME); + if (structName == null) { + 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); + + sb.append(structNameIdentifier.getText()); + break; + } + case CTFParser.VARIANT: { + CommonTree variantName = (CommonTree) typeSpecifier + .getFirstChildWithType(CTFParser.VARIANT_NAME); + if (variantName == null) { + 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); + + sb.append(variantNameIdentifier.getText()); + break; + } + case CTFParser.ENUM: { + CommonTree enumName = (CommonTree) typeSpecifier + .getFirstChildWithType(CTFParser.ENUM_NAME); + if (enumName == null) { + 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; + } + case CTFParser.FLOATING_POINT: + case CTFParser.INTEGER: + case CTFParser.STRING: + throw new ParseException( + "CTF type found in createTypeSpecifierString"); //$NON-NLS-1$ + /* break; */ + default: + childTypeError(typeSpecifier); + break; + } + } + + /** + * Creates the string representation of a list of pointers. + * + * @param pointerList + * A list of pointer nodes. If pointerList is null, this function + * does nothing. + * @param sb + * A stringbuilder to which will be appended the string. + */ + private static void createPointerListString(List pointerList, + StringBuilder sb) { + if (pointerList == null) { + return; + } + + 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$ + } + } + } + + /** + * @param node + * The node to check. + * @return True if the given node is an unary string or unary integer. + */ + private static boolean isUnaryExpression(CommonTree node) { + return isUnaryInteger(node) || isUnaryString(node); + } + + /** + * @param node + * The node to check. + * @return True if the given node is an unary string. + */ + private static boolean isUnaryString(CommonTree node) { + return ((node.getType() == CTFParser.UNARY_EXPRESSION_STRING) || (node + .getType() == CTFParser.UNARY_EXPRESSION_STRING_QUOTES)); + } + + /** + * @param node + * The node to check. + * @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)); + } + + /** + * Parses a unary string node and return the string value. + * + * @param unaryString + * The unary string node to parse (type UNARY_EXPRESSION_STRING + * or UNARY_EXPRESSION_STRING_QUOTES). + * @return The string value. + */ + /* + * It would be really nice to remove the quotes earlier, such as in the + * 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 */ + if (unaryString.getType() == CTFParser.UNARY_EXPRESSION_STRING_QUOTES) { + strval = strval.substring(1, strval.length() - 1); + } + + return strval; + } + + /** + * Parses an unary integer (dec, hex or oct). + * + * @param unaryInteger + * An unary integer node. + * @return The integer value. + */ + private static long parseUnaryInteger(CommonTree unaryInteger) { + assert (isUnaryInteger(unaryInteger)); + + assert (unaryInteger.getChildCount() >= 1); + + List 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 + } + + /* The rest of children are sign */ + if ((children.size() % 2) == 0) { + return -intval; + } + return intval; + } + + private static long getMajorOrMinor(CommonTree rightNode) + throws ParseException { + assert (rightNode.getType() == CTFParser.CTF_RIGHT); + assert (rightNode.getChildCount() > 0); + + CommonTree firstChild = (CommonTree) rightNode.getChild(0); + + if (isUnaryInteger(firstChild)) { + if (rightNode.getChildCount() > 1) { + throw new ParseException("Invalid value for major/minor"); //$NON-NLS-1$ + } + + long m = parseUnaryInteger(firstChild); + + if (m < 0) { + throw new ParseException("Invalid value for major/minor"); //$NON-NLS-1$ + } + + return m; + } + throw new ParseException("Invalid value for major/minor"); //$NON-NLS-1$ + } + + 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 (rightNode.getChildCount() > 1) { + throw new ParseException("Invalid value for UUID"); //$NON-NLS-1$ + } + + String uuidstr = parseUnaryString(firstChild); + + try { + UUID uuid = UUID.fromString(uuidstr); + return uuid; + } catch (IllegalArgumentException e) { + throw new ParseException("Invalid format for UUID"); //$NON-NLS-1$ + } + } + throw new ParseException("Invalid value for UUID"); //$NON-NLS-1$ + } + + /** + * Gets the value of a "signed" integer attribute. + * + * @param rightNode + * A CTF_RIGHT node. + * @return The "signed" value as a boolean. + * @throws ParseException + */ + 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); + + if (isUnaryString(firstChild)) { + String strval = concatenateUnaryStrings(rightNode.getChildren()); + + if (strval.equals("true") || strval.equals("TRUE")) { //$NON-NLS-1$ //$NON-NLS-2$ + ret = true; + } else if (strval.equals("false") || strval.equals("FALSE")) { //$NON-NLS-1$ //$NON-NLS-2$ + ret = false; + } else { + throw new ParseException("Invalid boolean value " //$NON-NLS-1$ + + firstChild.getChild(0).getText()); + } + } else if (isUnaryInteger(firstChild)) { + /* Happens if the value is something like "1234.hello" */ + if (rightNode.getChildCount() > 1) { + throw new ParseException("Invalid boolean value"); //$NON-NLS-1$ + } + + long intval = parseUnaryInteger(firstChild); + + if (intval == 1) { + ret = true; + } else if (intval == 0) { + ret = false; + } else { + throw new ParseException("Invalid boolean value " //$NON-NLS-1$ + + firstChild.getChild(0).getText()); + } + } else { + throw new ParseException(); + } + + return ret; + } + + /** + * Gets the value of a "byte_order" integer attribute. + * + * @param rightNode + * A CTF_RIGHT node. + * @return The "byte_order" value. + * @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("le")) { //$NON-NLS-1$ + return ByteOrder.LITTLE_ENDIAN; + } else if (strval.equals("be") || strval.equals("network")) { //$NON-NLS-1$ //$NON-NLS-2$ + return ByteOrder.BIG_ENDIAN; + } else if (strval.equals("native")) { //$NON-NLS-1$ + return trace.getByteOrder(); + } else { + throw new ParseException("Invalid value for byte order"); //$NON-NLS-1$ + } + } + throw new ParseException("Invalid value for byte order"); //$NON-NLS-1$ + } + + /** + * Determines if the given value is a valid alignment value. + * + * @param alignment + * The value to check. + * @return True if it is valid. + */ + private static boolean isValidAlignment(long alignment) { + return !((alignment <= 0) || ((alignment & (alignment - 1)) != 0)); + } + + /** + * Gets the value of a "size" integer attribute. + * + * @param rightNode + * A CTF_RIGHT node. + * @return The "size" value. + * @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); + + if (isUnaryInteger(firstChild)) { + if (rightNode.getChildCount() > 1) { + throw new ParseException("Invalid value for size"); //$NON-NLS-1$ + } + + long size = parseUnaryInteger(firstChild); + + if (size < 1) { + throw new ParseException("Invalid value for size"); //$NON-NLS-1$ + } + + return size; + } + throw new ParseException("Invalid value for size"); //$NON-NLS-1$ + } + + /** + * Gets the value of a "align" integer or struct attribute. + * + * @param node + * A CTF_RIGHT node or directly an unary integer. + * @return The align value. + * @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 + * child + */ + if (node.getType() == CTFParser.CTF_RIGHT) { + if (node.getChildCount() > 1) { + throw new ParseException("Invalid alignment value"); //$NON-NLS-1$ + } + + return getAlignment((CommonTree) node.getChild(0)); + } else if (isUnaryInteger(node)) { + long alignment = parseUnaryInteger(node); + + if (!isValidAlignment(alignment)) { + throw new ParseException("Invalid value for alignment : " //$NON-NLS-1$ + + alignment); + } + + return alignment; + } + throw new ParseException("Invalid value for alignment"); //$NON-NLS-1$ + } + + /** + * Gets the value of a "base" integer attribute. + * + * @param rightNode + * An CTF_RIGHT node. + * @return The "base" value. + * @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); + + if (isUnaryInteger(firstChild)) { + if (rightNode.getChildCount() > 1) { + throw new ParseException("invalid base value"); //$NON-NLS-1$ + } + + long intval = parseUnaryInteger(firstChild); + if ((intval == 2) || (intval == 8) || (intval == 10) + || (intval == 16)) { + return (int) intval; + } + throw new ParseException("Invalid value for base"); //$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$ + 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$ + return 16; + } else if (strval.equals("octal") || strval.equals("oct") //$NON-NLS-1$ //$NON-NLS-2$ + || strval.equals("o")) { //$NON-NLS-1$ + return 8; + } else if (strval.equals("binary") || strval.equals("b")) { //$NON-NLS-1$ //$NON-NLS-2$ + return 2; + } else { + throw new ParseException("Invalid value for base"); //$NON-NLS-1$ + } + } else { + throw new ParseException("invalid value for base"); //$NON-NLS-1$ + } + } + + /** + * Gets the value of an "encoding" integer attribute. + * + * @param rightNode + * A CTF_RIGHT node. + * @return The "encoding" value. + * @throws ParseException + */ + 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("UTF8")) { //$NON-NLS-1$ + return Encoding.UTF8; + } else if (strval.equals("ASCII")) { //$NON-NLS-1$ + return Encoding.ASCII; + } else if (strval.equals("none")) { //$NON-NLS-1$ + return Encoding.NONE; + } else { + throw new ParseException("Invalid value for encoding"); //$NON-NLS-1$ + } + } + throw new ParseException("Invalid value for encoding"); //$NON-NLS-1$ + } + + private static long getStreamID(CommonTree rightNode) throws ParseException { + assert (rightNode.getType() == CTFParser.CTF_RIGHT); + assert (rightNode.getChildCount() > 0); + + CommonTree firstChild = (CommonTree) rightNode.getChild(0); + + if (isUnaryInteger(firstChild)) { + if (rightNode.getChildCount() > 1) { + throw new ParseException("invalid value for stream id"); //$NON-NLS-1$ + } + + long intval = parseUnaryInteger(firstChild); + + return intval; + } + throw new ParseException("invalid value for stream id"); //$NON-NLS-1$ + } + + 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)) { + String str = concatenateUnaryStrings(rightNode.getChildren()); + + return str; + } + throw new ParseException("invalid value for event name"); //$NON-NLS-1$ + } + + private static long getEventID(CommonTree rightNode) throws ParseException { + assert (rightNode.getType() == CTFParser.CTF_RIGHT); + assert (rightNode.getChildCount() > 0); + + CommonTree firstChild = (CommonTree) rightNode.getChild(0); + + if (isUnaryInteger(firstChild)) { + if (rightNode.getChildCount() > 1) { + throw new ParseException("invalid value for event id"); //$NON-NLS-1$ + } + + long intval = parseUnaryInteger(firstChild); + + return intval; + } + throw new ParseException("invalid value for event id"); //$NON-NLS-1$ + } + + /** + * Concatenates a list of unary strings separated by arrows (->) or dots. + * + * @param strings + * A list, first element being an unary string, subsequent + * elements being ARROW or DOT nodes with unary strings as child. + * @return The string representation of the unary string chain. + */ + private static String concatenateUnaryStrings(List strings) { + assert ((strings != null) && (strings.size() > 0)); + + StringBuilder sb = new StringBuilder(); + + CommonTree first = strings.get(0); + sb.append(parseUnaryString(first)); + + boolean isFirst = true; + + for (CommonTree ref : strings) { + if (isFirst) { + isFirst = false; + 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) { + sb.append("->"); //$NON-NLS-1$ + } else { /* DOT */ + sb.append('.'); + } + + sb.append(parseUnaryString(id)); + } + + return sb.toString(); + } + + /** + * Throws a ParseException stating that the parent-child relation between + * the given node and its parent is not valid. It means that the shape of + * the AST is unexpected. + * + * @param child + * The invalid child node. + * @throws ParseException + */ + private static void childTypeError(CommonTree child) throws ParseException { + CommonTree parent = (CommonTree) child.getParent(); + String error = "Parent " + CTFParser.tokenNames[parent.getType()] //$NON-NLS-1$ + + " can't have a child of type " //$NON-NLS-1$ + + CTFParser.tokenNames[child.getType()] + "."; //$NON-NLS-1$ + + throw new ParseException(error); + } + + // ------------------------------------------------------------------------ + // Scope management + // ------------------------------------------------------------------------ + + /** + * Adds a new declaration scope on the top of the scope stack. + */ + private void pushScope() { + scope = new DeclarationScope(scope); + } + + /** + * Removes the top declaration scope from the scope stack. + */ + private void popScope() { + assert (scope != null); + scope = scope.getParentScope(); + } + + /** + * Returns the current declaration scope. + * + * @return The current declaration scope. + */ + private DeclarationScope getCurrentScope() { + assert (scope != null); + return scope; + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java new file mode 100644 index 0000000000..f4eb8a4502 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.metadata.exceptions; + +/** + * ParseException + */ +public class ParseException extends Exception { + + private static final long serialVersionUID = 7901917601459652080L; + + public ParseException() { + super(); + } + + /** + * Constructor + * + * @param message + */ + public ParseException(String message) { + super(message); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java new file mode 100644 index 0000000000..30730c7607 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +/** + * ArrayDeclaration + */ +public class ArrayDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final int length; + private final IDeclaration elemType; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public ArrayDeclaration(int length, IDeclaration elemType) { + this.length = length; + this.elemType = elemType; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public IDeclaration getElementType() { + return elemType; + } + + public int getLength() { + return length; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public ArrayDefinition createDefinition(IDefinitionScope definitionScope, + String fieldName) { + return new ArrayDefinition(this, definitionScope, fieldName); + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java new file mode 100644 index 0000000000..8c7e67a0f8 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * ArrayDefinition + */ +public class ArrayDefinition extends Definition { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final ArrayDeclaration declaration; + private Definition definitions[]; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public ArrayDefinition(ArrayDeclaration declaration, + IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + + this.declaration = declaration; + + definitions = new Definition[declaration.getLength()]; + + for (int i = 0; i < declaration.getLength(); i++) { + definitions[i] = declaration.getElementType().createDefinition( + definitionScope, fieldName + "[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + /** + * @return the definitions + */ + public Definition[] getDefinitions() { + return definitions; + } + + /** + * @param definitions + * the definitions to set + */ + public void setDefinitions(Definition[] definitions) { + this.definitions = definitions; + } + + public Definition getElem(int i) { + if (i > definitions.length) { + return null; + } + + return definitions[i]; + } + + public ArrayDeclaration getDeclaration() { + return declaration; + } + + /** + * Sometimes, strings are encoded as an array of 1-byte integers (each one + * being an UTF-8 byte). + * + * @return true if this array is in fact an UTF-8 string. false if it's a + * "normal" array of generic Definition's. + */ + public boolean isString() { + IntegerDeclaration elemInt; + + if (declaration.getElementType() instanceof IntegerDeclaration) { + /* + * If the first byte is a "character", we'll consider the whole + * array a character string. + */ + elemInt = (IntegerDeclaration) declaration.getElementType(); + if (elemInt.isCharacter()) { + return true; + } + } + return false; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + for (Definition definition : definitions) { + definition.read(input); + } + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + + if (this.isString()) { + for (Definition def : definitions) { + IntegerDefinition character = (IntegerDefinition) def; + + if (character.getValue() == 0) { + break; + } + + b.append(character.toString()); + } + } else if (definitions == null) { + b.append("[ ]"); //$NON-NLS-1$ + } else { + b.append('['); + for (int i = 0; i < (definitions.length - 1); i++) { + b.append(' '); + b.append(definitions[i].toString()); + b.append(','); + } + b.append(' '); + b.append(definitions[definitions.length - 1].toString()); + b.append(" ]"); //$NON-NLS-1$ + } + + return b.toString(); + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java new file mode 100644 index 0000000000..4d4d28ba3d --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * Definition + */ +public abstract class Definition { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /* The name of the field in its container */ + protected final String fieldName; + + /* The complete path of this field */ + protected final String path; + + /* + * The definition scope in which this definition is found. + * + * The complete path of a definition is thus the path of the definition + * scope DOT the name of the definition (name of the field in its container) + */ + protected final IDefinitionScope definitionScope; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public Definition(IDefinitionScope definitionScope, String fieldName) { + this.definitionScope = definitionScope; + this.fieldName = fieldName; + if (definitionScope != null) { + String parentPath = definitionScope.getPath(); + if (parentPath.length() > 0) { + path = parentPath + "." + fieldName; //$NON-NLS-1$ + } else { + path = fieldName; + } + } else { + path = fieldName; + } + + /* + * System.out.println("[definition] " + this.getClass().getSimpleName() + * + " " + path + " created"); + */ + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + public abstract void read(BitBuffer input); + + @Override + public String toString() { + return path + '[' + Integer.toHexString(hashCode()) + ']'; + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java new file mode 100644 index 0000000000..922c4ad9fe --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +/** + * Encoding + *

+ * Encoding types + */ +public enum Encoding { + UTF8, ASCII, NONE +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java new file mode 100644 index 0000000000..2ae8b29d05 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import java.util.LinkedList; +import java.util.List; + +/** + * EnumDeclaration + */ +public class EnumDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final EnumTable table = new EnumTable(); + private IntegerDeclaration containerType = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public EnumDeclaration(IntegerDeclaration containerType) { + this.containerType = containerType; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public IntegerDeclaration getContainerType() { + return containerType; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public EnumDefinition createDefinition(IDefinitionScope definitionScope, + String fieldName) { + return new EnumDefinition(this, definitionScope, fieldName); + } + + public boolean add(long low, long high, String label) { + return table.add(low, high, label); + } + + public String query(long value) { + return table.query(value); + } + + public String getLabel(long i) { + return table.getLabel(i); + } + + /* + * Maps integer range -> string. A simple list for now, but feel free to + * optimize it. Babeltrace suggests an interval tree. + */ + static private class EnumTable { + + List ranges = new LinkedList(); + + public EnumTable() { + } + + public String getLabel(long i) { + for (Range r : ranges) { + if (r.intersects(i)) { + return r.str; + } + } + return null; + } + + public boolean add(long low, long high, String label) { + Range newRange = new Range(low, high, label); + + for (Range r : ranges) { + if (r.intersects(newRange)) { + return false; + } + } + + ranges.add(newRange); + + return true; + } + + public String query(long value) { + for (Range r : ranges) { + if (r.intersects(value)) { + return r.str; + } + } + + return null; + } + + static private class Range { + + long low, high; + String str; + + public Range(long low, long high, String str) { + this.low = low; + this.high = high; + this.str = str; + } + + public boolean intersects(long i) { + return (i >= this.low) && (i <= this.high); + } + + public boolean intersects(Range other) { + return this.intersects(other.low) + || this.intersects(other.high); + } + } + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] enum[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java new file mode 100644 index 0000000000..aef0446728 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * EnumDefinition + */ +public class EnumDefinition extends Definition { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final EnumDeclaration declaration; + + private final IntegerDefinition integerValue; + + private String value; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public EnumDefinition(EnumDeclaration declaration, + IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + + this.declaration = declaration; + + integerValue = declaration.getContainerType().createDefinition( + definitionScope, fieldName); + value = ((Long) integerValue.getValue()).toString(); + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public String getValue() { + return value; + } + + public long getIntegerValue() { + return integerValue.getValue(); + } + + public void setIntegerValue(long Value) { + integerValue.setValue(Value); + value = ((Long) integerValue.getValue()).toString(); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + integerValue.read(input); + long val = integerValue.getValue(); + + // TODO: what to do if the integer value maps to no string for this + // integer ? + value = declaration.query(val); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java new file mode 100644 index 0000000000..87f86f2c47 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +/** + * IDeclaration + */ +public interface IDeclaration { + + public Definition createDefinition(IDefinitionScope definitionScope, + String fieldName); +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinitionScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinitionScope.java new file mode 100644 index 0000000000..b802251516 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinitionScope.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +/** + * IDefinitionScope + */ +public interface IDefinitionScope { + + public String getPath(); + + /** + * Looks up in this definition scope. + */ + public Definition lookupDefinition(String lookupPath); +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java new file mode 100644 index 0000000000..42b4e8eaaf --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import java.nio.ByteOrder; + +/** + * IntegerDeclaration + */ +public class IntegerDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private int length; + private boolean signed; + private int base; + private ByteOrder byteOrder; + private Encoding encoding; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public IntegerDeclaration(int len, boolean signed, int base, + ByteOrder byteOrder, Encoding encoding) { + this.length = len; + this.signed = signed; + this.base = base; + this.byteOrder = byteOrder; + this.encoding = encoding; + } + + // ------------------------------------------------------------------------ + // Gettters/Setters/Predicates + // ------------------------------------------------------------------------ + + public boolean isSigned() { + return signed; + } + + public void setSigned(boolean signed) { + this.signed = signed; + } + + public int getBase() { + return base; + } + + public void setBase(int base) { + this.base = base; + } + + public ByteOrder getByteOrder() { + return byteOrder; + } + + public void setByteOrder(ByteOrder byteOrder) { + this.byteOrder = byteOrder; + } + + public Encoding getEncoding() { + return encoding; + } + + public void setEncoding(Encoding encoding) { + this.encoding = encoding; + } + + public void setLength(int length) { + this.length = length; + } + + public boolean isCharacter() { + return (length == 8) && (encoding != Encoding.NONE); + } + + public int getLength() { + return length; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public IntegerDefinition createDefinition(IDefinitionScope definitionScope, + String fieldName) { + return new IntegerDefinition(this, definitionScope, fieldName); + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] integer[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java new file mode 100644 index 0000000000..9c594ebc15 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * IntegerDefinition + *

+ * TODO: Reading integers with an endianness different from the trace endianness + * is not supported + */ +public class IntegerDefinition extends Definition { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final IntegerDeclaration declaration; + private long value; + + // ------------------------------------------------------------------------ + // Contructors + // ------------------------------------------------------------------------ + + public IntegerDefinition(IntegerDeclaration declaration, + IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + this.declaration = declaration; + } + + // ------------------------------------------------------------------------ + // Gettters/Setters/Predicates + // ------------------------------------------------------------------------ + + public long getValue() { + return value; + } + + public void setValue(long val) { + value = val; + } + + public IntegerDeclaration getDeclaration() { + return declaration; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + boolean signed = declaration.isSigned(); + int length = declaration.getLength(); + long bits = 0; + + // TODO: use the eventual getLong from BitBuffer + + if (length == 64) { + long low = input.getInt(32, false); + low = low & 0x00000000FFFFFFFFL; + long high = input.getInt(32, false); + high = high & 0x00000000FFFFFFFFL; + + bits = (high << 32) | low; + } else { + bits = input.getInt(length, signed); + bits = bits & 0x00000000FFFFFFFFL; + } + + value = bits; + } + + @Override + public String toString() { + if (declaration.isCharacter()) { + char c = (char) value; + return Character.toString(c); + } + return String.valueOf(value); + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java new file mode 100644 index 0000000000..609ea46bed --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +/** + * SequenceDeclaration + */ +public class SequenceDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final IDeclaration elemType; + private final String lengthName; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public SequenceDeclaration(String lengthName, IDeclaration elemType) { + this.elemType = elemType; + this.lengthName = lengthName; + } + + // ------------------------------------------------------------------------ + // Gettters/Setters/Predicates + // ------------------------------------------------------------------------ + + public IDeclaration getElementType() { + return elemType; + } + + public String getLengthName() { + return lengthName; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public SequenceDefinition createDefinition( + IDefinitionScope definitionScope, String fieldName) { + return new SequenceDefinition(this, definitionScope, fieldName); + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] sequence[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java new file mode 100644 index 0000000000..3f29d1f14c --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * SequenceDefinition + */ +public class SequenceDefinition extends Definition { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final SequenceDeclaration declaration; + private IntegerDefinition lengthDefinition; + private Definition definitions[]; + private int currentLength; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public SequenceDefinition(SequenceDeclaration declaration, + IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + + this.declaration = declaration; + // this.definitionScope = definitionScope; + + if (definitionScope != null) { + Definition lenDef = definitionScope.lookupDefinition(declaration.getLengthName()); + lengthDefinition = (IntegerDefinition) lenDef; + } + /* + * if (lenDef == null) { throw new + * Exception("Sequence length field not found"); } + * + * if (!(lenDef instanceof IntegerDefinition)) { throw new + * Exception("Sequence length field not integer"); } + */ + /* + * if (this.lengthDefinition.declaration.signed) { throw new + * Exception("Sequence length must not be signed"); } + */ + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public SequenceDeclaration getDeclaration() { + return declaration; + } + + public int getLength() { + return currentLength; + } + + public Definition getElem(int i) { + if (i > definitions.length) { + return null; + } + + return definitions[i]; + } + + public boolean isString() { + IntegerDeclaration elemInt; + + if (declaration.getElementType() instanceof IntegerDeclaration) { + elemInt = (IntegerDeclaration) declaration.getElementType(); + if (elemInt.isCharacter()) { + return true; + } + } + return false; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + currentLength = (int) lengthDefinition.getValue(); + + if ((definitions == null) || (definitions.length < currentLength)) { + Definition newDefinitions[] = new Definition[currentLength]; + + int i = 0; + + if (definitions != null) { + for (; i < definitions.length; i++) { + newDefinitions[i] = definitions[i]; + } + } + + for (; i < currentLength; i++) { + newDefinitions[i] = declaration.getElementType().createDefinition( + definitionScope, fieldName + "[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + definitions = newDefinitions; + } + + for (int i = 0; i < currentLength; i++) { + definitions[i].read(input); + } + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + + if (this.isString()) { + for (int i = 0; i < currentLength; i++) { + IntegerDefinition character = (IntegerDefinition) definitions[i]; + + if (character.getValue() == 0) { + break; + } + + b.append(character.toString()); + } + } else { + b.append('['); + if (currentLength > 0) { + for (int i = 0; i < (currentLength - 1); i++) { + b.append(' '); + b.append(definitions[i].toString()); + b.append(','); + } + b.append(' '); + b.append(definitions[currentLength - 1].toString()); + } + b.append(" ]"); //$NON-NLS-1$ + + } + + return b.toString(); + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java new file mode 100644 index 0000000000..5fc519d9b2 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +/** + * StringDeclaration + */ +public class StringDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private Encoding encoding = Encoding.UTF8; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public Encoding getEncoding() { + return encoding; + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public StringDeclaration() { + } + + public StringDeclaration(Encoding encoding) { + this.encoding = encoding; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public void setEncoding(Encoding encoding) { + this.encoding = encoding; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public StringDefinition createDefinition(IDefinitionScope definitionScope, + String fieldName) { + return new StringDefinition(this, definitionScope, fieldName); + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] string[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java new file mode 100644 index 0000000000..17506a9ec6 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * StringDefinition + */ +public class StringDefinition extends Definition { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private StringDeclaration declaration; + + private StringBuilder string; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public StringDefinition(StringDeclaration declaration, + IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + + this.declaration = declaration; + + string = new StringBuilder(); + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public StringDeclaration getDeclaration() { + return declaration; + } + + public void setDeclaration(StringDeclaration declaration) { + this.declaration = declaration; + } + + public StringBuilder getString() { + return string; + } + + public void setString(StringBuilder string) { + this.string = string; + } + + public String getValue() { + return string.toString(); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + string.setLength(0); + + char c = (char) input.getInt(8, false); + while (c != 0) { + string.append(c); + c = (char) input.getInt(8, false); + } + } + + @Override + public String toString() { + return '\"' + getValue() + '\"'; + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java new file mode 100644 index 0000000000..1e43be6b24 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +/** + * StructDeclaration + */ +public class StructDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final HashMap fields = new HashMap(); + private final List fieldsList = new LinkedList(); + private long minAlign; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public StructDeclaration(long minAlign) { + this.minAlign = minAlign; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public long getMinAlign() { + return this.minAlign; + } + + public void setMinAlign(long minAlign) { + this.minAlign = minAlign; + } + + public boolean hasField(String name) { + return this.fields.containsKey(name); + } + + public HashMap getFields() { + return this.fields; + } + + public List getFieldsList() { + return this.fieldsList; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public StructDefinition createDefinition(IDefinitionScope definitionScope, + String fieldName) { + return new StructDefinition(this, definitionScope, fieldName); + } + + public void addField(String name, IDeclaration declaration) { + // TODO: update the minAlign to be the max of minAlign and the align + // value of the new field. + this.fields.put(name, declaration); + this.fieldsList.add(name); + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] struct[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java new file mode 100644 index 0000000000..13f1263a2e --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import java.util.HashMap; +import java.util.ListIterator; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * StructDefinition + */ +public class StructDefinition extends Definition implements IDefinitionScope { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private final StructDeclaration declaration; + private final HashMap definitions = new HashMap(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public StructDefinition(StructDeclaration declaration, + IDefinitionScope definitionScope, String structFieldName) { + super(definitionScope, structFieldName); + + this.declaration = declaration; + + for (String fName : declaration.getFieldsList()) { + IDeclaration fieldDecl = declaration.getFields().get(fName); + assert (fieldDecl != null); + + Definition def = fieldDecl.createDefinition(this, fName); + definitions.put(fName, def); + } + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + @Override + public String getPath() { + return path; + } + + public HashMap getDefinitions() { + return definitions; + } + + public StructDeclaration getDeclaration() { + return declaration; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + for (String fName : declaration.getFieldsList()) { + Definition def = definitions.get(fName); + assert (def != null); + + def.read(input); + } + } + + @Override + public Definition lookupDefinition(String lookupPath) { + /* + * The fields are created in order of appearance, so if a variant or + * sequence refers to a field that is after it, the field's definition + * will not be there yet in the hashmap. + */ + return definitions.get(lookupPath); + } + + public ArrayDefinition lookupArray(String name) { + Definition def = definitions.get(name); + return (ArrayDefinition) ((def instanceof ArrayDefinition) ? def : null); + } + + public EnumDefinition lookupEnum(String name) { + Definition def = definitions.get(name); + return (EnumDefinition) ((def instanceof EnumDefinition) ? def : null); + } + + public IntegerDefinition lookupInteger(String name) { + Definition def = definitions.get(name); + return (IntegerDefinition) ((def instanceof IntegerDefinition) ? def + : null); + } + + public SequenceDefinition lookupSequence(String name) { + Definition def = definitions.get(name); + return (SequenceDefinition) ((def instanceof SequenceDefinition) ? def + : null); + } + + public StringDefinition lookupString(String name) { + Definition def = definitions.get(name); + return (StringDefinition) ((def instanceof StringDefinition) ? def + : null); + } + + public StructDefinition lookupStruct(String name) { + Definition def = definitions.get(name); + return (StructDefinition) ((def instanceof StructDefinition) ? def + : null); + } + + public VariantDefinition lookupVariant(String name) { + Definition def = definitions.get(name); + return (VariantDefinition) ((def instanceof VariantDefinition) ? def + : null); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + int size = this.declaration.getFieldsList().size(); + int n = 0; + + if (size > 1) { + builder.append("{ "); //$NON-NLS-1$ + } + + ListIterator listIterator = this.declaration.getFieldsList().listIterator(); + + while (listIterator.hasNext()) { + String field = listIterator.next(); + builder.append(definitions.get(field).toString()); + n++; + if (n != size) { + builder.append(", "); //$NON-NLS-1$ + } + } + + if (size > 1) { + builder.append(" }"); //$NON-NLS-1$ + } + + return builder.toString(); + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java new file mode 100644 index 0000000000..bad6ba49a1 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import java.util.HashMap; + +/** + * VariantDeclaration + */ +public class VariantDeclaration implements IDeclaration { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private String tag = null; + private final HashMap fields = new HashMap(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public VariantDeclaration() { + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public boolean isTagged() { + return tag != null; + } + + public boolean hasField(String fieldTag) { + return fields.containsKey(fieldTag); + } + + public void setTag(String tag) { + this.tag = tag; + } + + public String getTag() { + return this.tag; + } + + public HashMap getFields() { + return this.fields; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public VariantDefinition createDefinition(IDefinitionScope definitionScope, + String fieldName) { + return new VariantDefinition(this, definitionScope, fieldName); + } + + public void addField(String fieldTag, IDeclaration declaration) { + fields.put(fieldTag, declaration); + } + + @Override + public String toString() { + /* Only used for debugging */ + return "[declaration] variant[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java new file mode 100644 index 0000000000..135ff682d0 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.types; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; + +/** + * VariantDefinition + */ +public class VariantDefinition extends Definition implements IDefinitionScope { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private VariantDeclaration declaration; + + private EnumDefinition tagDefinition; + private HashMap definitions = new HashMap(); + private String currentField; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public VariantDefinition(VariantDeclaration declaration, + IDefinitionScope definitionScope, String fieldName) { + super(definitionScope, fieldName); + + this.declaration = declaration; + + Definition tagDef = definitionScope.lookupDefinition(declaration.getTag()); + /* + * if (tagDef == null) { throw new + * Exception("Variant tag field not found"); } + * + * if (!(tagDef instanceof EnumDefinition)) { throw new + * Exception("Variant tag field not enum"); } + */ + this.tagDefinition = (EnumDefinition) tagDef; + + for (Map.Entry field : declaration.getFields().entrySet()) { + Definition fieldDef = field.getValue().createDefinition(this, + field.getKey()); + definitions.put(field.getKey(), fieldDef); + } + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public VariantDeclaration getDeclaration() { + return declaration; + } + + public void setDeclaration(VariantDeclaration declaration) { + this.declaration = declaration; + } + + public EnumDefinition getTagDefinition() { + return tagDefinition; + } + + public void setTagDefinition(EnumDefinition tagDefinition) { + this.tagDefinition = tagDefinition; + } + + public HashMap getDefinitions() { + return definitions; + } + + public void setDefinitions(HashMap definitions) { + this.definitions = definitions; + } + + public void setCurrentField(String currentField) { + this.currentField = currentField; + } + + @Override + public String getPath() { + return path; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public void read(BitBuffer input) { + currentField = tagDefinition.getValue(); + + Definition field = definitions.get(currentField); + + field.read(input); + } + + @Override + public Definition lookupDefinition(String lookupPath) { + return definitions.get(lookupPath); + } + + public String getCurrentFieldName() { + return currentField; + } + + public Definition getCurrentField() { + return definitions.get(currentField); + } + + public ArrayDefinition lookupArray(String name) { + Definition def = definitions.get(name); + return (ArrayDefinition) ((def instanceof ArrayDefinition) ? def : null); + } + + public EnumDefinition lookupEnum(String name) { + Definition def = definitions.get(name); + return (EnumDefinition) ((def instanceof EnumDefinition) ? def : null); + } + + public IntegerDefinition lookupInteger(String name) { + Definition def = definitions.get(name); + return (IntegerDefinition) ((def instanceof IntegerDefinition) ? def + : null); + } + + public SequenceDefinition lookupSequence(String name) { + Definition def = definitions.get(name); + return (SequenceDefinition) ((def instanceof SequenceDefinition) ? def + : null); + } + + public StringDefinition lookupString(String name) { + Definition def = definitions.get(name); + return (StringDefinition) ((def instanceof StringDefinition) ? def + : null); + } + + public StructDefinition lookupStruct(String name) { + Definition def = definitions.get(name); + return (StructDefinition) ((def instanceof StructDefinition) ? def + : null); + } + + public VariantDefinition lookupVariant(String name) { + Definition def = definitions.get(name); + return (VariantDefinition) ((def instanceof VariantDefinition) ? def + : null); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java new file mode 100644 index 0000000000..1a7d94975c --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 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: Alexandre Montplaisir - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +/** + * General exception that is thrown when there is a problem somewhere with the + * CTF trace reader. + * + * @author alexmont + * + */ +public class CTFReaderException extends Exception { + + private static final long serialVersionUID = 2065258365219777672L; + + /** + * Default constructor with no message. + */ + public CTFReaderException() { + super(); + } + + /** + * Constructor with an attached message. + * + * @param message + */ + public CTFReaderException(String message) { + super(message); + } + + /** + * Re-throw an exception into this type. + * + * @param e + * The previous Exception we caught. + */ + public CTFReaderException(Exception e) { + super(e); + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java new file mode 100644 index 0000000000..40d0f43af0 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java @@ -0,0 +1,635 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Alexandre Montplaisir - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.ByteOrder; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileChannel.MapMode; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.eclipse.linuxtools.ctf.core.CtfCorePlugin; +import org.eclipse.linuxtools.ctf.core.event.CTFClock; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; + +/** + * CTFTrace + *

+ * Represents a trace on the filesystem. It is responsible of parsing the + * metadata, creating declarations data structures, indexing the event packets + * (in other words, all the work that can be shared between readers), but the + * actual reading of events is left to TraceReader. + * + * @author Matthew Khouzam + * @version $Revision: 1.0 $ + */ +public class CTFTrace implements IDefinitionScope { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + /* Only for debugging, shouldn't be externalized */ + return "CTFTrace [path=" + path + ", major=" + major + ", minor=" + + minor + ", uuid=" + uuid + "]"; + } + + /** + * The trace directory on the filesystem. + */ + private final File path; + + /** + * The metadata parsing object. + */ + private final Metadata metadata; + + /** + * Major CTF version number + */ + private Long major; + + /** + * Minor CTF version number + */ + private Long minor; + + /** + * Trace UUID + */ + private UUID uuid; + + /** + * Trace byte order + */ + private ByteOrder byteOrder; + + /** + * Packet header structure declaration + */ + private StructDeclaration packetHeaderDecl; + + /** + * Packet header structure definition + * + * This is only used when opening the trace files, to read the first packet + * header and see if they are valid trace files. + */ + private StructDefinition packetHeaderDef; + + /** + * Collection of streams contained in the trace. + */ + private final HashMap streams = new HashMap(); + + /** + * Collection of environment variables set by the tracer + */ + private final HashMap environment = new HashMap(); + + /** + * Collection of all the clocks in a system. + */ + private final HashMap clocks = new HashMap(); + + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Trace constructor. + * + * @param path + * Filesystem path of the trace directory. + * @throws IOException + */ + public CTFTrace(String path) throws CTFReaderException { + this(new File(path)); + } + + /** + * Trace constructor. + * + * @param path + * Filesystem path of the trace directory. + * @throws CTFReaderException + */ + @SuppressWarnings("unqualified-field-access") + public CTFTrace(File path) throws CTFReaderException { + this.path = path; + + metadata = new Metadata(this); + + if (!this.path.isDirectory()) { + throw new CTFReaderException("Path must be a valid directory"); //$NON-NLS-1$ + } + + this.open(); + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + /** + * Method getStream gets the stream for a given id + * + * @param id + * Long the id of the stream + * @return Stream the stream that we need + */ + public Stream getStream(Long id) { + return streams.get(id); + } + + /** + * Method nbStreams gets the number of available streams + * + * @return int the number of streams + */ + public int nbStreams() { + return streams.size(); + } + + /** + * Method setMajor sets the major version of the trace (DO NOT USE) + * + * @param major + * long the major version + */ + public void setMajor(long major) { + this.major = major; + } + + /** + * Method setMinor sets the minor version of the trace (DO NOT USE) + * + * @param minor + * long the minor version + */ + public void setMinor(long minor) { + this.minor = minor; + } + + /** + * Method setUUID sets the UUID of a trace + * + * @param uuid + * UUID + */ + public void setUUID(UUID uuid) { + this.uuid = uuid; + } + + /** + * Method setByteOrder sets the byte order + * + * @param byteOrder + * ByteOrder of the trace, can be little-endian or big-endian + */ + public void setByteOrder(ByteOrder byteOrder) { + this.byteOrder = byteOrder; + } + + /** + * Method setPacketHeader sets the packet header of a trace (DO NOT USE) + * + * @param packetHeader + * StructDeclaration the header in structdeclaration form + */ + public void setPacketHeader(StructDeclaration packetHeader) { + this.packetHeaderDecl = packetHeader; + } + + /** + * Method majortIsSet is the major version number set? + * + * @return boolean is the major set? + */ + public boolean majortIsSet() { + return major != null; + } + + /** + * Method minorIsSet. is the minor version number set? + * + * @return boolean is the minor set? + */ + public boolean minorIsSet() { + return minor != null; + } + + /** + * Method UUIDIsSet is the UUID set? + * + * @return boolean is the UUID set? + */ + public boolean UUIDIsSet() { + return uuid != null; + } + + /** + * Method byteOrderIsSet is the byteorder set? + * + * @return boolean is the byteorder set? + */ + public boolean byteOrderIsSet() { + return byteOrder != null; + } + + /** + * Method packetHeaderIsSet is the packet header set? + * + * @return boolean is the packet header set? + */ + public boolean packetHeaderIsSet() { + return packetHeaderDecl != null; + } + + /** + * Method getUUID gets the trace UUID + * + * @return UUID gets the trace UUID + */ + public UUID getUUID() { + return uuid; + } + + /** + * Method getMajor gets the trace major version + * + * @return long gets the trace major version + */ + public long getMajor() { + return major; + } + + /** + * Method getMinor gets the trace minor version + * + * @return long gets the trace minor version + */ + public long getMinor() { + return minor; + } + + /** + * Method getByteOrder gets the trace byte order + * + * @return ByteOrder gets the trace byte order + */ + public ByteOrder getByteOrder() { + return byteOrder; + } + + /** + * Method getPacketHeader gets the trace packet header + * + * @return StructDeclaration gets the trace packet header + */ + public StructDeclaration getPacketHeader() { + return packetHeaderDecl; + } + + /** + * Method getTraceDirectory gets the trace directory + * + * @return File the path in "File" format. + */ + public File getTraceDirectory() { + return path; + } + + /** + * Method getStreams get all the streams in a map format. + * + * @return Map a map of all the streams. + */ + public Map getStreams() { + return streams; + } + + /** + * Method getPath gets the path of the trace directory + * + * @return String the path of the trace directory, in string format. + * @see java.io.File#getPath() + */ + @Override + public String getPath() { + return path.getPath(); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Opens the trace and creates the index. + * + * @throws CTFReaderException + */ + private void open() throws CTFReaderException { + /* Open and parse the metadata file */ + openTraceMetadata(); + + if (CtfCorePlugin.getDefault() != null) { + CtfCorePlugin.getDefault().log(metadata.toString()); + } + /* Open all the trace files */ + openStreamInputs(); + + /* Create their index */ + createStreamInputIndexes(); + } + + /** + * Parses the metadata + * + * @throws CTFReaderException + */ + private void openTraceMetadata() throws CTFReaderException { + metadata.parse(); + } + + /** + * Creates the definitions needed by the Trace class to open the trace + * files. + */ + private void createDefinitions() { + if (packetHeaderDecl != null) { + packetHeaderDef = packetHeaderDecl.createDefinition(this, + "packet.header"); //$NON-NLS-1$ + } + } + + /** + * Creates the indexes of all the trace files. + * + * @throws CTFReaderException + */ + private void createStreamInputIndexes() throws CTFReaderException { + for (Map.Entry stream : streams.entrySet()) { + Set inputs = stream.getValue().getStreamInputs(); + for (StreamInput s : inputs) { + s.createIndex(); + } + } + } + + /** + * Tries to open every file in the trace directory (except metadata). + * + * @throws CTFReaderException + */ + private void openStreamInputs() throws CTFReaderException { + /* Create the definitions needed to read things from the files */ + createDefinitions(); + + /* List files not called metadata and not hidden. */ + File[] files = path.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + + if (pathname.isDirectory()) { + return false; + } + + if (pathname.isHidden()) { + return false; + } + + if (pathname.getName().equals("metadata")) { //$NON-NLS-1$ + return false; + } + + return true; + } + }); + Arrays.sort(files, new Comparator() { + + @Override + public int compare(File o1, File o2) { + + return o1.getName().compareTo(o2.getName()); + + } + }); + + /* Try to open each file */ + for (File s : files) { + openStreamInput(s); + } + } + + /** + * Tries to open the given file, reads the first packet header of the file + * and check its validity. + * + * @param streamFile + * A trace file in the trace directory. + * @throws CTFReaderException + */ + private void openStreamInput(File streamFile) throws CTFReaderException { + FileChannel streamFileChannel; + MappedByteBuffer byteBuffer; + BitBuffer streamBitBuffer; + + if (!streamFile.canRead()) { + throw new CTFReaderException("Unreadable file : " //$NON-NLS-1$ + + streamFile.getPath()); + } + + try { + /* Open the file and get the FileChannel */ + streamFileChannel = new FileInputStream(streamFile).getChannel(); + + /* Map one memory page of 4 kiB */ + byteBuffer = streamFileChannel.map(MapMode.READ_ONLY, 0, 4096); + } catch (IOException e) { + /* Shouldn't happen at this stage if every other check passed */ + throw new CTFReaderException(); + } + + /* Create a BitBuffer with this mapping and the trace byte order */ + streamBitBuffer = new BitBuffer(byteBuffer, this.getByteOrder()); + + if (packetHeaderDef != null) { + /* Read the packet header */ + packetHeaderDef.read(streamBitBuffer); + + /* Check the magic number */ + IntegerDefinition magicDef = (IntegerDefinition) packetHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$ + int magic = (int) magicDef.getValue(); + if (magic != Utils.CTF_MAGIC) { + throw new CTFReaderException("CTF magic mismatch"); //$NON-NLS-1$ + } + + /* Check UUID */ + ArrayDefinition uuidDef = (ArrayDefinition) packetHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$ + assert ((uuidDef != null) && (uuidDef.getDeclaration().getLength() == Utils.UUID_LEN)); + if (uuidDef != null) { + byte[] uuidArray = new byte[Utils.UUID_LEN]; + + for (int i = 0; i < Utils.UUID_LEN; i++) { + IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i); + uuidArray[i] = (byte) uuidByteDef.getValue(); + } + + UUID otheruuid = Utils.makeUUID(uuidArray); + + if (!this.uuid.equals(otheruuid)) { + throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ + } + } + + /* Read stream ID */ + // TODO: it hasn't been checked that the stream_id field exists and + // is an unsigned + // integer + IntegerDefinition streamIDDef = (IntegerDefinition) packetHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$ + assert (streamIDDef != null); + + long streamID = streamIDDef.getValue(); + + /* Get the stream to which this trace file belongs to */ + Stream stream = streams.get(streamID); + + /* Create the stream input */ + StreamInput streamInput = new StreamInput(stream, + streamFileChannel, streamFile); + + /* Add a reference to the streamInput in the stream */ + stream.addInput(streamInput); + } else { + /* No packet header, we suppose there is only one stream */ + Stream stream = streams.get(null); + + /* Create the stream input */ + StreamInput streamInput = new StreamInput(stream, + streamFileChannel, streamFile); + + /* Add a reference to the streamInput in the stream */ + stream.addInput(streamInput); + } + } + + /** + * Looks up a definition from packet + * + * @param lookupPath + * String + * @return Definition + * @see org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope#lookupDefinition(String) + */ + @Override + public Definition lookupDefinition(String lookupPath) { + if (lookupPath.equals("trace.packet.header")) { //$NON-NLS-1$ + return packetHeaderDef; + } + return null; + } + + /** + * Adds a new stream to the trace. + * + * @param stream + * A stream object. + * + * @throws ParseException + */ + public void addStream(Stream stream) throws ParseException { + + /* + * If there is already a stream without id (the null key), it must be + * the only one + */ + if (streams.get(null) != null) { + throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$ + } + + /* + * If the stream we try to add has the null key, it must be the only + * one. Thus, if the streams container is not empty, it is not valid. + */ + if ((stream.getId() == null) && (streams.size() != 0)) { + throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$ + } + + /* If a stream with the same ID already exists, it is not valid. */ + if (streams.get(stream.getId()) != null) { + throw new ParseException("Stream id already exists"); //$NON-NLS-1$ + } + + /* It should be ok now. */ + streams.put(stream.getId(), stream); + } + + public HashMap getEnvironment() { + return environment; + } + + public String LookupEnvironment( String key ) + { + return environment.get(key); + } + + public void addEnvironmentVar( String varName, String varValue) + { + environment.put(varName, varValue); + } + + public void addClock(String nameValue, CTFClock ctfClock) { + clocks.put(nameValue, ctfClock); + } + + public CTFClock getClock(String name){ + return clocks.get(name); + } + + public CTFClock getClock(){ + if( clocks.size() == 1 ) + { + String key = (String) clocks.keySet().toArray()[0]; + return clocks.get(key); + } + return null; + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java new file mode 100644 index 0000000000..9117fc52b9 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Alexandre Montplaisir - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.util.Collection; +import java.util.PriorityQueue; +import java.util.Set; +import java.util.Vector; + +import org.eclipse.linuxtools.ctf.core.CtfCorePlugin; +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +/** + * Reads the events of a trace. + */ + +public class CTFTraceReader { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * The trace to read from. + */ + private final CTFTrace trace; + + /** + * Vector of all the trace file readers. + */ + private final Vector streamInputReaders = new Vector(); + + /** + * Priority queue to order the trace file readers by timestamp. + */ + protected PriorityQueue prio; + + /** + * Array to count the number of event per trace file. + */ + private int[] eventCountPerTraceFile; + + /** + * Timestamp of the first event in the trace + */ + private long startTime; + + /** + * Timestamp of the last event read so far + */ + private long endTime; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs a TraceReader to read a trace. + * + * @param trace + * The trace to read from. + * @throws CTFReaderException + */ + public CTFTraceReader(CTFTrace trace) { + this.trace = trace; + + /** + * Create the trace file readers. + */ + createStreamInputReaders(); + + /** + * Populate the timestamp-based priority queue. + */ + populateStreamInputReaderHeap(); + + /** + * Get the start Time of this trace + */ + this.startTime = prio.peek().getCurrentEvent().timestamp; + this.endTime = this.startTime; + } + + /** + * Copy constructor + * + * @return + */ + public CTFTraceReader copyFrom() { + CTFTraceReader newReader = null; + + newReader = new CTFTraceReader(this.trace); + newReader.startTime = this.startTime; + newReader.endTime = this.endTime; + return newReader; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + /** + * Return the start time of this trace (== timestamp of the first event) + * + * @return + */ + public long getStartTime() { + return this.startTime; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Creates one trace file reader per trace file contained in the trace. + */ + private void createStreamInputReaders() { + Collection streams = this.trace.getStreams().values(); + + /* + * For each stream. + */ + for (Stream stream : streams) { + Set streamInputs = stream.getStreamInputs(); + + /* + * For each trace file of the stream. + */ + for (StreamInput streamInput : streamInputs) { + /* + * Create a reader. + */ + StreamInputReader streamInputReader = new StreamInputReader( + streamInput); + + /* + * Add it to the group. + */ + this.streamInputReaders.add(streamInputReader); + } + } + + /* + * Create the array to count the number of event per trace file. + */ + this.eventCountPerTraceFile = new int[this.streamInputReaders.size()]; + } + + /** + * Initializes the priority queue used to choose the trace file with the + * lower next event timestamp. + */ + private void populateStreamInputReaderHeap() { + /* + * Create the priority queue with a size twice as bigger as the number + * of reader in order to avoid constant resizing. + */ + this.prio = new PriorityQueue( + this.streamInputReaders.size() * 2, + new StreamInputReaderTimestampComparator()); + + int pos = 0; + + for (StreamInputReader reader : this.streamInputReaders) { + /* + * Add each trace file reader in the priority queue, if we are able + * to read an event from it. + */ + if (reader.readNextEvent()) { + this.prio.add(reader); + + this.eventCountPerTraceFile[pos] = 0; + reader.setName(pos); + + pos++; + } + } + } + + /** + * Get the current event, which is the current event of the trace file + * reader with the lowest timestamp. + * + * @return An event definition, or null of the trace reader reached the end + * of the trace. + */ + public EventDefinition getCurrentEventDef() { + StreamInputReader top = this.prio.peek(); + + return (top != null) ? top.getCurrentEvent() : null; + } + + /** + * Go to the next event. + * + * @return True if an event was read. + */ + public boolean advance() { + /* + * Remove the reader from the top of the priority queue. + */ + StreamInputReader top = this.prio.poll(); + + /* + * If the queue was empty. + */ + if (top == null) { + return false; + } + + /* + * Read the next event of this reader. + */ + if (top.readNextEvent()) { + /* + * Add it back in the queue. + */ + this.prio.add(top); + final long topEnd = top.getCurrentEvent().timestamp; + this.endTime = Math.max(topEnd, this.endTime); + this.eventCountPerTraceFile[top.getName()]++; + } + + /* + * If there is no reader in the queue, it means the trace reader reached + * the end of the trace. + */ + return hasMoreEvents(); + } + + /** + * Go to the last event in the trace. + * + * @throws CTFReaderException + */ + public void goToLastEvent() throws CTFReaderException { + + this.seek(0); + for (StreamInputReader streamInputReader : this.streamInputReaders) { + /* + * Seek the trace reader. + */ + streamInputReader.goToLastEvent(); + } + int count = prio.size(); + for (int i = 0; i < (count); i++) { + advance(); + } + } + + /** + * Seeks to a given timestamp It will go to the event just after the + * timestamp or the timestamp itself. if a if a trace is 10 20 30 40 and + * you're looking for 19, it'll give you 20, it you want 20, you'll get 20, + * if you want 21, you'll get 30. You want -inf, you'll get the first + * element, you want +inf, you'll get the end of the file with no events. + * + * @param timestamp + * the timestamp to seek to + * @return + */ + public boolean seek(long timestamp) { + /* + * Remove all the trace readers from the priority queue + */ + this.prio.clear(); + + for (StreamInputReader streamInputReader : this.streamInputReaders) { + /* + * Seek the trace reader. + */ + streamInputReader.seek(timestamp); + + /* + * Add it to the priority queue if there is a current event. + */ + if (streamInputReader.getCurrentEvent() != null) { + this.prio.add(streamInputReader); + } + } + + return hasMoreEvents(); + } + + /** + * Does the trace have more events? + * + * @return true if yes. + */ + public boolean hasMoreEvents() { + return this.prio.size() > 0; + } + + /** + * Prints the event count stats. + */ + public void printStats() { + printStats(60); + } + + /** + * Prints the event count stats. + * + * @param width + * Width of the display. + */ + public void printStats(int width) { + int numEvents = 0; + if (width == 0) { + return; + } + + for (int i : this.eventCountPerTraceFile) { + numEvents += i; + } + + for (int j = 0; j < this.eventCountPerTraceFile.length; j++) { + StreamInputReader se = this.streamInputReaders.get(j); + + int len = (width * this.eventCountPerTraceFile[se.getName()]) + / numEvents; + + StringBuilder sb = new StringBuilder( + se.getStreamInput().getFilename() + "\t["); //$NON-NLS-1$ + + for (int i = 0; i < len; i++) { + sb.append('+'); + } + + for (int i = len; i < width; i++) { + sb.append(' '); + } + + sb.append("]\t" + this.eventCountPerTraceFile[se.getName()] + " Events"); //$NON-NLS-1$//$NON-NLS-2$ + CtfCorePlugin.getDefault().log(sb.toString()); + } + } + + public long getEndTime() { + return this.endTime; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + (int) (endTime ^ (endTime >>> 32)); + result = (prime * result) + (int) (startTime ^ (startTime >>> 32)); + result = (prime * result) + + ((streamInputReaders == null) ? 0 + : streamInputReaders.hashCode()); + result = (prime * result) + ((trace == null) ? 0 : trace.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + CTFTraceReader other = (CTFTraceReader) obj; + if (endTime != other.endTime) { + return false; + } + if (startTime != other.startTime) { + return false; + } + if (streamInputReaders == null) { + if (other.streamInputReaders != null) { + return false; + } + } else if (!streamInputReaders.equals(other.streamInputReaders)) { + return false; + } + if (trace == null) { + if (other.trace != null) { + return false; + } + } else if (!trace.equals(other.trace)) { + return false; + } + return true; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + /* Only for debugging, shouldn't be externalized */ + return "CTFTraceReader [trace=" + trace + ']'; //$NON-NLS-1$ + } + + public CTFTrace getTrace() { + return trace; + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java new file mode 100644 index 0000000000..092b24091d --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java @@ -0,0 +1,373 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; +import java.util.Arrays; +import java.util.UUID; + +import org.antlr.runtime.ANTLRReaderStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.tree.CommonTree; +import org.eclipse.linuxtools.ctf.core.event.metadata.IOStructGen; +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.ctf.parser.CTFLexer; +import org.eclipse.linuxtools.ctf.parser.CTFParser; +import org.eclipse.linuxtools.ctf.parser.CTFParser.parse_return; + +/** + * Metadata + *

+ * Represents a metadata file + */ +public class Metadata { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * Name of the metadata file in the trace directory + */ + final 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; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * Reference to the metadata file + */ + private File metadataFile = null; + + /** + * Byte order as detected when reading the TSDL magic number. + */ + private ByteOrder detectedByteOrder = null; + + /** + * The trace file to which belongs this metadata file. + */ + private CTFTrace trace = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs a Metadata object. + * + * @param trace + * The trace to which belongs this metadata file. + */ + public Metadata(CTFTrace trace) { + this.trace = trace; + + /* Path of metadata file = trace directory path + metadata filename */ + String metadataPath = trace.getTraceDirectory().getPath() + + Utils.SEPARATOR + METADATA_FILENAME; + + /* Create a file reference to the metadata file */ + metadataFile = new File(metadataPath); + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + /** + * Returns the ByteOrder that was detected while parsing the metadata. + * + * @return The byte order. + */ + public ByteOrder getDetectedByteOrder() { + return detectedByteOrder; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Parse the metadata file. + * + * @throws CTFReaderException + */ + public void parse() throws CTFReaderException { + /* Open the file and get the FileChannel */ + FileChannel metadataFileChannel; + try { + metadataFileChannel = new FileInputStream(metadataFile).getChannel(); + } catch (FileNotFoundException e) { + throw new CTFReaderException("Cannot find metadata file!"); //$NON-NLS-1$ + } + + /* + * Reader. It will contain a StringReader if we are using packet-based + * metadata and it will contain a FileReader if we have text-based + * metadata. + */ + Reader metadataTextInput = null; + + /* Check if metadata is packet-based */ + if (isPacketBased(metadataFileChannel)) { + /* Create StringBuffer to receive metadata text */ + StringBuffer metadataText = new StringBuffer(); + + /* + * Read metadata packet one by one, appending the text to the + * StringBuffer + */ + MetadataPacketHeader packetHeader = readMetadataPacket( + metadataFileChannel, metadataText); + while (packetHeader != null) { + packetHeader = readMetadataPacket(metadataFileChannel, + metadataText); + } + + /* Wrap the metadata string with a StringReader */ + metadataTextInput = new StringReader(metadataText.toString()); + } else { + /* Wrap the metadata file with a FileReader */ + try { + metadataTextInput = new FileReader(metadataFile); + } catch (FileNotFoundException e) { + /* + * We've already checked for this earlier. Why does StringReader + * not throw this too?? + */ + throw new CTFReaderException(e); + } + } + + /* Create an ANTLR reader */ + ANTLRReaderStream antlrStream; + try { + antlrStream = new ANTLRReaderStream(metadataTextInput); + } catch (IOException e) { + /* This would indicate a problem with the ANTLR library... */ + throw new CTFReaderException(e); + } + + /* 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; + try { + ret = ctfParser.parse(); + } catch (RecognitionException e) { + /* + * We don't want to expose this ANTLR-specific exception type to the + * outside.. + */ + throw new CTFReaderException(e); + } + CommonTree tree = (CommonTree) ret.getTree(); + + /* Generate IO structures (declarations) */ + IOStructGen gen = new IOStructGen(tree, trace); + try { + gen.generate(); + } catch (ParseException e) { + throw new CTFReaderException(e); + } + } + + /** + * 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 + * the endianness of the trace using the detectedByteOrder attribute. + * + * @param metadataFileChannel + * FileChannel of the metadata file. + * @return True if the metadata is packet-based. + * @throws CTFReaderException + */ + private boolean isPacketBased(FileChannel metadataFileChannel) + throws CTFReaderException { + /* + * Create a ByteBuffer to read the TSDL magic number (default is big + * endian) + */ + ByteBuffer magicByteBuffer = ByteBuffer.allocate(Utils.TSDL_MAGIC_LEN); + + /* Read without changing file position */ + try { + metadataFileChannel.read(magicByteBuffer, 0); + } catch (IOException e) { + throw new CTFReaderException( + "Unable to read metadata file channel."); //$NON-NLS-1$ + } + + /* Get the first int from the file */ + int magic = magicByteBuffer.getInt(0); + + /* Check if it matches */ + if (Utils.TSDL_MAGIC == magic) { + detectedByteOrder = ByteOrder.BIG_ENDIAN; + return true; + } + + /* Try the same thing, but with little endian */ + magicByteBuffer.order(ByteOrder.LITTLE_ENDIAN); + magic = magicByteBuffer.getInt(0); + + if (Utils.TSDL_MAGIC == magic) { + detectedByteOrder = ByteOrder.LITTLE_ENDIAN; + return true; + } + + return false; + } + + /** + * Reads a metadata packet from the given metadata FileChannel, do some + * basic validation and append the text to the StringBuffer. + * + * @param metadataFileChannel + * Metadata FileChannel + * @param metadataText + * StringBuffer to which the metadata text will be appended. + * @return A structure describing the header of the metadata packet, or null + * if the end of the file is reached. + * @throws CTFReaderException + */ + private MetadataPacketHeader readMetadataPacket( + FileChannel metadataFileChannel, StringBuffer metadataText) + throws CTFReaderException { + /* Allocate a ByteBuffer for the header */ + ByteBuffer headerByteBuffer = ByteBuffer.allocate(METADATA_PACKET_HEADER_SIZE); + + /* Read the header */ + int nbBytesRead; + try { + nbBytesRead = metadataFileChannel.read(headerByteBuffer); + } catch (IOException e) { + throw new CTFReaderException("Error reading the metadata header."); //$NON-NLS-1$ + } + + /* Return null if EOF */ + if (nbBytesRead < 0) { + return null; + } + + /* Set ByteBuffer's position to 0 */ + headerByteBuffer.position(0); + + /* Use byte order that was detected with the magic number */ + headerByteBuffer.order(detectedByteOrder); + + assert (nbBytesRead == METADATA_PACKET_HEADER_SIZE); + + MetadataPacketHeader header = new MetadataPacketHeader(); + + /* Read from the ByteBuffer */ + header.magic = headerByteBuffer.getInt(); + headerByteBuffer.get(header.uuid); + header.checksum = headerByteBuffer.getInt(); + header.contentSize = headerByteBuffer.getInt(); + header.packetSize = headerByteBuffer.getInt(); + header.compressionScheme = headerByteBuffer.get(); + header.encryptionScheme = headerByteBuffer.get(); + header.checksumScheme = headerByteBuffer.get(); + header.ctfMajorVersion = headerByteBuffer.get(); + header.ctfMinorVersion = headerByteBuffer.get(); + + /* Check TSDL magic number */ + if (header.magic != Utils.TSDL_MAGIC) { + throw new CTFReaderException("TSDL magic number does not match"); //$NON-NLS-1$ + } + + /* Check UUID */ + UUID uuid = Utils.makeUUID(header.uuid); + if (!trace.UUIDIsSet()) { + trace.setUUID(uuid); + } else { + if (!trace.getUUID().equals(uuid)) { + throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ + } + } + + /* Extract the text from the packet */ + int payloadSize = ((header.contentSize / 8) - METADATA_PACKET_HEADER_SIZE); + int skipSize = (header.packetSize - header.contentSize) / 8; + + /* Read the payload + the padding in a ByteBuffer */ + ByteBuffer payloadByteBuffer = ByteBuffer.allocateDirect(payloadSize + + skipSize); + try { + metadataFileChannel.read(payloadByteBuffer); + } catch (IOException e) { + throw new CTFReaderException( + "Error reading metadata packet payload."); //$NON-NLS-1$ + } + payloadByteBuffer.rewind(); + + /* Read only the payload from the ByteBuffer into a byte array */ + byte payloadByteArray[] = new byte[payloadByteBuffer.remaining()]; + payloadByteBuffer.get(payloadByteArray, 0, payloadSize); + + /* Convert the byte array to a String */ + String str = new String(payloadByteArray, 0, payloadSize); + + /* Append it to the existing metadata */ + metadataText.append(str); + + return header; + } + + static class MetadataPacketHeader { + + public int magic; + public byte uuid[] = new byte[16]; + public int checksum; + public int contentSize; + public int packetSize; + public byte compressionScheme; + public byte encryptionScheme; + public byte checksumScheme; + public byte ctfMajorVersion; + public byte ctfMinorVersion; + + @Override + public String toString() { + /* Only for debugging, shouldn't be externalized */ + return "MetadataPacketHeader [magic=0x" //$NON-NLS-1$ + + Integer.toHexString(magic) + ", uuid=" //$NON-NLS-1$ + + Arrays.toString(uuid) + ", checksum=" + checksum //$NON-NLS-1$ + + ", contentSize=" + contentSize + ", packetSize=" //$NON-NLS-1$ //$NON-NLS-2$ + + packetSize + ", compressionScheme=" + compressionScheme //$NON-NLS-1$ + + ", encryptionScheme=" + encryptionScheme //$NON-NLS-1$ + + ", checksumScheme=" + checksumScheme //$NON-NLS-1$ + + ", ctfMajorVersion=" + ctfMajorVersion //$NON-NLS-1$ + + ", ctfMinorVersion=" + ctfMinorVersion + ']'; //$NON-NLS-1$ + } + + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java new file mode 100644 index 0000000000..473eeaa044 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; + +/** + * Stream + *

+ * Represents a stream in a trace. + */ +public class Stream { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + + /** + * The numerical ID of the stream + */ + private Long id = null; + + /** + * Declarations of the stream-specific structures + */ + private StructDeclaration packetContextDecl = null; + private StructDeclaration eventHeaderDecl = null; + private StructDeclaration eventContextDecl = null; + + /** + * The trace to which the stream belongs + */ + private CTFTrace trace = null; + + /** + * Maps event ids to events + */ + private final HashMap events = new HashMap(); + + /** + * The inputs associated to this stream + */ + private final Set inputs = new HashSet(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs a Stream that belongs to a Trace + * + * @param trace + * The trace to which belongs this stream. + */ + public Stream(CTFTrace trace) { + this.trace = trace; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public void setId(long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public boolean idIsSet() { + return id != null; + } + + public boolean eventHeaderIsSet() { + return eventHeaderDecl != null; + } + + public boolean eventContextIsSet() { + return eventContextDecl != null; + } + + public boolean packetContextIsSet() { + return packetContextDecl != null; + } + + public void setEventHeader(StructDeclaration eventHeader) { + this.eventHeaderDecl = eventHeader; + } + + public void setEventContext(StructDeclaration eventContext) { + this.eventContextDecl = eventContext; + } + + public void setPacketContext(StructDeclaration packetContext) { + this.packetContextDecl = packetContext; + } + + public StructDeclaration getEventHeaderDecl() { + return eventHeaderDecl; + } + + public StructDeclaration getEventContextDecl() { + return eventContextDecl; + } + + public StructDeclaration getPacketContextDecl() { + return packetContextDecl; + } + + public Set getStreamInputs() { + return inputs; + } + + public CTFTrace getTrace() { + return trace; + } + + public HashMap getEvents() { + return events; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Adds an event to the event map. + * + * An event in a stream can omit its id if it is the only event in this + * stream. An event for which no id has been specified has a null id. It is + * thus not possible to add an event with the null key if the map is not + * empty. It is also not possible to add an event to the map if the null key + * is present in the map. + * + * @param event + * The event to add. + * @throws ParseException + */ + public void addEvent(EventDeclaration event) throws ParseException { + /* + * If there is an event without id (the null key), it must be the only + * one + */ + if (events.get(null) != null) { + throw new ParseException( + "Event without id with multiple events in a stream"); //$NON-NLS-1$ + } + + /* + * If there is an event without id (the null key), it must be the only + * one + */ + if ((event.getId() == null) && (events.size() != 0)) { + throw new ParseException( + "Event without id with multiple events in a stream"); //$NON-NLS-1$ + } + + /* Check if an event with the same ID already exists */ + if (events.get(event.getId()) != null) { + throw new ParseException("Event id already exists"); //$NON-NLS-1$ + } + + /* Put the event in the map */ + events.put(event.getId(), event); + } + + /** + * Add an input to this Stream + * + * @param input + * The StreamInput to add. + */ + public void addInput(StreamInput input) { + inputs.add(input); + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Stream [id=" + id + ", packetContextDecl=" + packetContextDecl //$NON-NLS-1$ //$NON-NLS-2$ + + ", eventHeaderDecl=" + eventHeaderDecl //$NON-NLS-1$ + + ", eventContextDecl=" + eventContextDecl + ", trace=" + trace //$NON-NLS-1$ //$NON-NLS-2$ + + ", events=" + events + ", inputs=" + inputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java new file mode 100644 index 0000000000..236b6ad312 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java @@ -0,0 +1,348 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.io.File; +import java.io.IOException; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileChannel.MapMode; +import java.util.UUID; + +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; + +/** + * StreamInput + *

+ * Represents a trace file that belongs to a certain stream. + */ +public class StreamInput implements IDefinitionScope { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * The associated Stream + */ + private final Stream stream; + + /** + * FileChannel to the trace file + */ + private final FileChannel fileChannel; + + /** + * Information on the file (used for debugging) + */ + public final File file; + + /** + * The packet index of this input + */ + private final StreamInputPacketIndex index = new StreamInputPacketIndex(); + + private long timestampEnd; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs a StreamInput. + * + * @param stream + * The stream to which this StreamInput belongs to. + * @param fileChannel + * The FileChannel to the trace file. + * @param file + * Information about the trace file (for debugging purposes). + */ + public StreamInput(Stream stream, FileChannel fileChannel, File file) { + this.stream = stream; + this.fileChannel = fileChannel; + this.file = file; + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public Stream getStream() { + return stream; + } + + public StreamInputPacketIndex getIndex() { + return index; + } + + public FileChannel getFileChannel() { + return fileChannel; + } + + public String getFilename() { + return file.getName(); + } + + public long getTimestampEnd() { + return timestampEnd; + } + + public void setTimestampEnd(long timestampEnd) { + this.timestampEnd = timestampEnd; + } + + @Override + public String getPath() { + return ""; //$NON-NLS-1$ + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public Definition lookupDefinition(String lookupPath) { + /* TODO: lookup in different dynamic scopes is not supported yet. */ + return null; + } + + /** + * Create the index for this trace file. + * + * @throws CTFReaderException + */ + public void createIndex() throws CTFReaderException { + /* + * The size of the file in bytes + */ + long fileSizeBytes = 0; + try { + fileSizeBytes = fileChannel.size(); + } catch (IOException e) { + throw new CTFReaderException(e); + } + + /* + * Offset of the current packet in bytes + */ + long packetOffsetBytes = 0; + + /* + * Initial size, it should map at least the packet header + context + * size. + * + * TODO: use a less arbitrary size. + */ + long mapSize = 4096; + + /* + * Definition of trace packet header + */ + StructDefinition tracePacketHeaderDef = null; + + /* + * Definition of trace stream packet context + */ + StructDefinition streamPacketContextDef = null; + + /* + * The BitBuffer to extract data from the StreamInput + */ + BitBuffer bitBuffer = new BitBuffer(); + bitBuffer.order(this.getStream().getTrace().getByteOrder()); + + /* + * Create the definitions we need to read the packet headers + contexts + */ + if (getStream().getTrace().getPacketHeader() != null) { + tracePacketHeaderDef = getStream().getTrace().getPacketHeader().createDefinition( + this, "trace.packet.header"); //$NON-NLS-1$ + } + + if (getStream().getPacketContextDecl() != null) { + streamPacketContextDef = getStream().getPacketContextDecl().createDefinition( + this, "stream.packet.context"); //$NON-NLS-1$ + } + + /* + * Scan through the packets of the file. + */ + while (packetOffsetBytes < fileSizeBytes) { + /* + * If there is less data remaining than what we want to map, reduce + * the map size. + */ + if ((fileSizeBytes - packetOffsetBytes) < mapSize) { + mapSize = fileSizeBytes - packetOffsetBytes; + } + + /* + * Map the packet. + */ + MappedByteBuffer bb; + try { + bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes, + mapSize); + } catch (IOException e) { + throw new CTFReaderException(e); + } + bitBuffer.setByteBuffer(bb); + + /* + * Create the index entry + */ + StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry( + packetOffsetBytes); + + /* + * Read the trace packet header if it exists. + */ + if (tracePacketHeaderDef != null) { + tracePacketHeaderDef.read(bitBuffer); + + /* + * Check the CTF magic number + */ + IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$ + if (magicDef != null) { + int magic = (int) magicDef.getValue(); + if (magic != Utils.CTF_MAGIC) { + throw new CTFReaderException( + "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$ + } + + } + + /* + * Check the trace UUID + */ + ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$ + if (uuidDef != null) { + byte[] uuidArray = new byte[16]; + + for (int i = 0; i < 16; i++) { + IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i); + uuidArray[i] = (byte) uuidByteDef.getValue(); + } + + UUID uuid = Utils.makeUUID(uuidArray); + + if (!getStream().getTrace().getUUID().equals(uuid)) { + throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ + } + } + + /* + * Check that the stream id did not change + */ + IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$ + if (streamIDDef != null) { + long streamID = streamIDDef.getValue(); + + if (streamID != getStream().getId()) { + throw new CTFReaderException( + "Stream ID changing within a StreamInput"); //$NON-NLS-1$ + } + } + } + + /* + * Read the stream packet context if it exists. + */ + if (streamPacketContextDef != null) { + streamPacketContextDef.read(bitBuffer); + + /* + * Read the content size in bits + */ + IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("content_size"); //$NON-NLS-1$ + if (contentSizeDef != null) { + packetIndex.contentSizeBits = (int) contentSizeDef.getValue(); + } else { + packetIndex.contentSizeBits = (int) (fileSizeBytes * 8); + } + + /* + * Read the packet size in bits + */ + IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("packet_size"); //$NON-NLS-1$ + if (packetSizeDef != null) { + packetIndex.packetSizeBits = (int) packetSizeDef.getValue(); + } else { + if (packetIndex.contentSizeBits != 0) { + packetIndex.packetSizeBits = packetIndex.contentSizeBits; + } else { + packetIndex.packetSizeBits = (int) (fileSizeBytes * 8); + } + } + + /* + * Read the begin timestamp + */ + IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("timestamp_begin"); //$NON-NLS-1$ + if (timestampBeginDef != null) { + packetIndex.timestampBegin = timestampBeginDef.getValue(); + } + + /* + * Read the end timestamp + */ + IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("timestamp_end"); //$NON-NLS-1$ + if (timestampEndDef != null) { + setTimestampEnd(packetIndex.timestampEnd = timestampEndDef.getValue()); + } + } else { + /* + * If there is no packet context, infer the content and packet + * size from the file size (assume that there is only one packet + * and no padding) + */ + packetIndex.contentSizeBits = (int) (fileSizeBytes * 8); + packetIndex.packetSizeBits = (int) (fileSizeBytes * 8); + } + + /* Basic validation */ + if (packetIndex.contentSizeBits > packetIndex.packetSizeBits) { + throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$ + } + + if (packetIndex.packetSizeBits > ((fileSizeBytes - packetIndex.offsetBytes) * 8)) { + throw new CTFReaderException( + "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$ + } + + /* + * Offset in the file, in bits + */ + packetIndex.dataOffsetBits = bitBuffer.position(); + + /* + * Add the packet index entry to the index + */ + index.addEntry(packetIndex); + + /* + * Update the counting packet offset + */ + packetOffsetBytes += (packetIndex.packetSizeBits + 7) / 8; + + } + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java new file mode 100644 index 0000000000..eae9dc4776 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.util.Collection; +import java.util.ListIterator; +import java.util.Vector; + +/** + * StreamInputPacketIndex + *

+ * TODO Implement me. Please. + */ +public class StreamInputPacketIndex { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * Entries of the index. They are sorted by increasing begin timestamp. + * index builder. + */ + private final Vector entries = new Vector(); + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public Collection getEntries() { + return this.entries; + } + + public ListIterator listIterator() { + return this.entries.listIterator(); + } + + public ListIterator listIterator(int n) { + return this.entries.listIterator(n); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Adds an entry to the index. + * + * @param entry + * The entry to add + * @throws CTFReaderException + */ + public void addEntry(StreamInputPacketIndexEntry entry) + throws CTFReaderException { + assert (entry.packetSizeBits != 0); + assert (entry.contentSizeBits != 0); + + if (entry.timestampBegin > entry.timestampEnd) { + throw new CTFReaderException( + "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$ + } + + if (!this.entries.isEmpty()) { + if (entry.timestampBegin < this.entries.lastElement().timestampBegin) { + throw new CTFReaderException( + "Packets begin timestamp decreasing"); //$NON-NLS-1$ + } + } + + this.entries.add(entry); + } + + /** + * Given a timestamp, this methods returns the first PacketIndexEntry that + * could include the timestamp, that is the last packet with a begin + * timestamp smaller than the given timestamp. + * + * @param timestamp + * The timestamp to look for. + * @return The StreamInputPacketEntry that corresponds to the packet that + * includes the given timestamp. + */ + public ListIterator search(final long timestamp) { + /* + * Start with min and max covering all the elements. + */ + int max = this.entries.size() - 1; + int min = 0; + + int guessI; + StreamInputPacketIndexEntry guessEntry = null; + + if (timestamp < 0) { + throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$ + } + + for (;;) { + /* + * Guess in the middle of min and max. The +1 is so that in case + * (min + 1 == max), we choose the packet at the subscript "max" + * instead of the one at "min". Otherwise, it would give an infinite + * loop. + */ + guessI = (max + min + 1) / 2; + guessEntry = this.entries.get(guessI); + + /* + * If we reached the point where we focus on a single packet, our + * search is done. + */ + if (min == max) { + break; + } + + if (timestamp < guessEntry.timestampBegin) { + /* + * If the timestamp if before the begin timestamp, we know that + * the packet to return is before the guess. + */ + max = guessI - 1; + } else if (timestamp >= guessEntry.timestampBegin) { + /* + * If the timestamp is after the begin timestamp, we know that + * the packet to return is after the guess or is the guess. + */ + min = guessI; + } + } + + return this.entries.listIterator(guessI); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java new file mode 100644 index 0000000000..167d8ffe15 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +/** + * StreamInputPacketIndexEntry + *

+ * Represents an entry in the index of event packets. + */ +public class StreamInputPacketIndexEntry { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * Offset of the packet in the file, in bytes + */ + public long offsetBytes; + + /** + * Offset of the data in the packet, in bits + */ + public int dataOffsetBits = 0; + + /** + * Packet size, in bits + */ + public int packetSizeBits = 0; + + /** + * Content size, in bits + */ + public int contentSizeBits = 0; + + /** + * Begin timestamp + */ + public long timestampBegin = 0; + + /** + * End timestamp + */ + public long timestampEnd = 0; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs an index entry. + * + * @param offset + * The offset of the packet in the file, in bytes. + */ + + public StreamInputPacketIndexEntry(long offset) { + this.offsetBytes = offset; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Returns whether the packet includes (inclusively) the given timestamp in + * the begin-end timestamp range. + * + * @param ts + * The timestamp to check. + * @return True if the packet includes the timestamp. + */ + boolean includes(long ts) { + return (ts >= timestampBegin) && (ts <= timestampEnd); + } + + @Override + public String toString() { + /* Only for debugging, shouldn't be externalized */ + return "PacketIndexEntry [offset=" + offsetBytes + ", timestampBegin=" //$NON-NLS-1$ //$NON-NLS-2$ + + Long.toHexString(timestampBegin) + ',' + " timestampEnd=" //$NON-NLS-1$ + + Long.toHexString(timestampEnd) + ", dataOffset=" //$NON-NLS-1$ + + dataOffsetBits + ", packetSize=" + packetSizeBits //$NON-NLS-1$ + + ", contentSize=" + contentSizeBits + ']'; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java new file mode 100644 index 0000000000..210b4827be --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java @@ -0,0 +1,465 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.ctf.core.trace; + +import java.io.IOException; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel.MapMode; +import java.util.Collection; +import java.util.HashMap; + +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.types.Definition; +import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; +import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; + +/** + * StreamInputPacketReader + *

+ * Reads the events of a packet of a trace file. + */ +public class StreamInputPacketReader implements IDefinitionScope { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * Reference to the index entry of the current packet. + */ + private StreamInputPacketIndexEntry currentPacket = null; + + /** + * BitBuffer used to read the trace file. + */ + private final BitBuffer bitBuffer = new BitBuffer(); + + /** + * StreamInputReader that uses this StreamInputPacketReader. + */ + private final StreamInputReader streamInputReader; + + /** + * Last timestamp recorded. + * + * Needed to calculate the complete timestamp values for the events with + * compact headers. + */ + private long lastTimestamp = 0; + + /** + * Trace packet header. + */ + private StructDefinition tracePacketHeaderDef = null; + + /** + * Stream packet context definition. + */ + private StructDefinition streamPacketContextDef = null; + + /** + * Stream event header definition. + */ + private StructDefinition streamEventHeaderDef = null; + + /** + * Stream event context definition. + */ + private StructDefinition streamEventContextDef = null; + + /** + * Maps event ID to event definitions. + */ + private final HashMap events = new HashMap(); + + /** + * CPU id of current packet. + */ + private int currentCpu = 0; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * Constructs a StreamInputPacketReader. + * + * @param streamInputReader + * The StreamInputReader to which this packet reader belongs to. + */ + public StreamInputPacketReader(StreamInputReader streamInputReader) { + this.streamInputReader = streamInputReader; + + /* + * Set the BitBuffer's byte order. + */ + getBitBuffer().setByteOrder(streamInputReader.getStreamInput().getStream().getTrace().getByteOrder()); + + /* + * Create definitions needed to read the events. + */ + createDefinitions(); + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + /* Getters, setters and stuff. */ + + public StreamInputPacketIndexEntry getCurrentPacket() { + return this.currentPacket; + } + + public StructDefinition getStreamPacketContextDef() { + return this.streamPacketContextDef; + } + + public int getCPU() { + return this.currentCpu; + } + + @Override + public String getPath() { + return ""; //$NON-NLS-1$ + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Creates definitions needed to read events (stream-defined and + * event-defined). + */ + private void createDefinitions() { + /* + * Create trace packet header definition. + */ + final Stream currentStream = getStreamInputReader().getStreamInput().getStream(); + StructDeclaration tracePacketHeaderDecl = currentStream.getTrace().getPacketHeader(); + if (tracePacketHeaderDecl != null) { + setTracePacketHeaderDef(tracePacketHeaderDecl.createDefinition(this, + "trace.packet.header")); //$NON-NLS-1$ + } + + /* + * Create stream packet context definition. + */ + StructDeclaration streamPacketContextDecl = currentStream.getPacketContextDecl(); + if (streamPacketContextDecl != null) { + setStreamPacketContextDef(streamPacketContextDecl.createDefinition( + this, "stream.packet.context")); //$NON-NLS-1$ + } + + /* + * Create stream event header definition. + */ + StructDeclaration streamEventHeaderDecl = currentStream.getEventHeaderDecl(); + if (streamEventHeaderDecl != null) { + setStreamEventHeaderDef(streamEventHeaderDecl.createDefinition(this, + "stream.event.header")); //$NON-NLS-1$ + } + + /* + * Create stream event context definition. + */ + StructDeclaration streamEventContextDecl = currentStream.getEventContextDecl(); + if (streamEventContextDecl != null) { + setStreamEventContextDef(streamEventContextDecl.createDefinition( + this, "stream.event.context")); //$NON-NLS-1$ + } + + createEventDefinitions(); + } + + /** + * Creates definitions needed to read the event. (event-defined). + */ + private void createEventDefinitions() { + Collection eventDecls = getStreamInputReader().getStreamInput().getStream().getEvents().values(); + + /* + * Create definitions for each event. + */ + for (EventDeclaration event : eventDecls) { + EventDefinition eventDef = event.createDefinition(getStreamInputReader()); + + events.put(event.getId(), eventDef); + } + } + + /** + * Changes the current packet to the given one. + * + * @param currentPacket + * The index entry of the packet to switch to. + */ + public void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) { + this.currentPacket = currentPacket; + + if (this.currentPacket != null) { + /* + * Change the map of the BitBuffer. + */ + MappedByteBuffer bb = null; + try { + bb = getStreamInputReader().getStreamInput().getFileChannel().map( + MapMode.READ_ONLY, this.currentPacket.offsetBytes, + (this.currentPacket.packetSizeBits + 7) / 8); + } catch (IOException e) { + /* + * The streamInputReader object is already allocated, so this + * shouldn't fail bar some very bad kernel or RAM errors... + */ + e.printStackTrace(); + } + + getBitBuffer().setByteBuffer(bb); + + /* + * Read trace packet header. + */ + if (getTracePacketHeaderDef() != null) { + getTracePacketHeaderDef().read(getBitBuffer()); + } + + /* + * Read stream packet context. + */ + if (getStreamPacketContextDef() != null) { + getStreamPacketContextDef().read(getBitBuffer()); + Definition cpuiddef = getStreamPacketContextDef().lookupDefinition("cpu_id"); //$NON-NLS-1$ + if (cpuiddef instanceof IntegerDefinition) { + currentCpu = (int) ((IntegerDefinition) cpuiddef).getValue(); + } + } + + /* + * Use the timestamp begin of the packet as the reference for the + * timestamp reconstitution. + */ + lastTimestamp = currentPacket.timestampBegin; + } else { + getBitBuffer().setByteBuffer(null); + + lastTimestamp = 0; + } + } + + /** + * Returns whether it is possible to read any more events from this packet. + * + * @return True if it is possible to read any more events from this packet. + */ + public boolean hasMoreEvents() { + if (currentPacket != null) { + return getBitBuffer().position() < currentPacket.contentSizeBits; + } + return false; + } + + /** + * Reads the next event of the packet into the right event definition. + * + * @return The event definition containing the event data that was just + * read. + * @throws CTFReaderException + */ + public EventDefinition readNextEvent() throws CTFReaderException { + /* WARNING: This is very LTTng-specific. */ + + Long eventID = null; + long timestamp = 0; + + /* + * Read thestream event header. + */ + if (getStreamEventHeaderDef() != null) { + getStreamEventHeaderDef().read(getBitBuffer()); + + /* + * Check for an event id. + */ + EnumDefinition idEnumDef = (EnumDefinition) getStreamEventHeaderDef().lookupDefinition("id"); //$NON-NLS-1$ + assert (idEnumDef != null); + + eventID = idEnumDef.getIntegerValue(); + + /* + * Check for the variant v. + */ + VariantDefinition variantDef = (VariantDefinition) getStreamEventHeaderDef().lookupDefinition("v"); //$NON-NLS-1$ + assert (variantDef != null); + + /* + * Get the variant current field + */ + StructDefinition variantCurrentField = (StructDefinition) variantDef.getCurrentField(); + assert (variantCurrentField != null); + + /* + * Try to get the id field in the current field of the variant. If + * it is present, it overrides the previously read event id. + */ + IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$ + if (idIntegerDef != null) { + eventID = idIntegerDef.getValue(); + + } + + /* + * Get the timestamp. + */ + IntegerDefinition timestampDef = (IntegerDefinition) variantCurrentField.lookupDefinition("timestamp"); //$NON-NLS-1$ + assert (timestampDef != null); + + /* + * Calculate the event timestamp. + */ + timestamp = calculateTimestamp(timestampDef); + } + + /* + * Read the stream event context. + */ + if (getStreamEventContextDef() != null) { + getStreamEventContextDef().read(getBitBuffer()); + } + + /* + * Get the right event definition using the event id. + */ + EventDefinition eventDef = events.get(eventID); + if (eventDef == null) { + throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$ + } + + /* + * Read the event context. + */ + if (eventDef.context != null) { + eventDef.context.read(getBitBuffer()); + } + + /* + * Read the event fields. + */ + if (eventDef.fields != null) { + eventDef.fields.read(getBitBuffer()); + } + + /* + * Set the event timestamp using the timestamp calculated by + * updateTimestamp. + */ + eventDef.timestamp = timestamp; + + return eventDef; + } + + /** + * Calculates the timestamp value of the event, possibly using the timestamp + * from the last event. + * + * @param timestampDef + * Integer definition of the timestamp. + * @return The calculated timestamp value. + */ + private long calculateTimestamp(IntegerDefinition timestampDef) { + long newval; + long majorasbitmask; + int len = timestampDef.getDeclaration().getLength(); + + /* + * If the timestamp length is 64 bits, it is a full timestamp. + */ + if (timestampDef.getDeclaration().getLength() == 64) { + lastTimestamp = timestampDef.getValue(); + return lastTimestamp; + } + + /* + * Bit mask to keep / remove all old / new bits. + */ + majorasbitmask = (1L << len) - 1; + + /* + * If the new value is smaller than the corresponding bits of the last + * timestamp, we assume an overflow of the compact representation. + */ + newval = timestampDef.getValue(); + if (newval < (lastTimestamp & majorasbitmask)) { + newval = newval + (1L << len); + } + + /* Keep only the high bits of the old value */ + lastTimestamp = lastTimestamp & ~majorasbitmask; + + /* Then add the low bits of the new value */ + lastTimestamp = lastTimestamp + newval; + + return lastTimestamp; + } + + @Override + public Definition lookupDefinition(String lookupPath) { + // TODO Auto-generated method stub + return null; + } + + public StructDefinition getStreamEventContextDef() { + return this.streamEventContextDef; + } + + public void setStreamEventContextDef(StructDefinition streamEventContextDef) { + this.streamEventContextDef = streamEventContextDef; + } + + public StructDefinition getStreamEventHeaderDef() { + return this.streamEventHeaderDef; + } + + public void setStreamEventHeaderDef(StructDefinition streamEventHeaderDef) { + this.streamEventHeaderDef = streamEventHeaderDef; + } + + public void setStreamPacketContextDef(StructDefinition streamPacketContextDef) { + this.streamPacketContextDef = streamPacketContextDef; + } + + public StructDefinition getTracePacketHeaderDef() { + return this.tracePacketHeaderDef; + } + + public void setTracePacketHeaderDef(StructDefinition tracePacketHeaderDef) { + this.tracePacketHeaderDef = tracePacketHeaderDef; + } + + public StreamInputReader getStreamInputReader() { + return this.streamInputReader; + } + + public BitBuffer getBitBuffer() { + return bitBuffer; + } +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java new file mode 100644 index 0000000000..25a3b2b2d6 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.util.ListIterator; + +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; + +/** + * StreamInputReader + *

+ * Reads the events of a trace file. + */ +public class StreamInputReader { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * The StreamInput we are reading. + */ + private final StreamInput streamInput; + + /** + * The packet reader used to read packets from this trace file. + */ + private final StreamInputPacketReader packetReader; + + /** + * Iterator on the packet index + */ + private ListIterator packetIndexIt; + + /** + * Reference to the current event of this trace file (iow, the last on that + * was read, the next one to be returned) + */ + private EventDefinition currentEvent = null; + + private int name; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructs a StreamInputReader that reads a StreamInput. + * + * @param streamInput + * The StreamInput to read. + */ + public StreamInputReader(StreamInput streamInput) { + this.streamInput = streamInput; + this.packetReader = new StreamInputPacketReader(this); + + /* + * Get the iterator on the packet index. + */ + this.packetIndexIt = streamInput.getIndex().listIterator(); + + /* + * Make first packet the current one. + */ + goToNextPacket(); + } + + // ------------------------------------------------------------------------ + // Getters/Setters/Predicates + // ------------------------------------------------------------------------ + + public EventDefinition getCurrentEvent() { + return this.currentEvent; + } + + public StructDefinition getCurrentPacketContext() { + return this.packetReader.getStreamPacketContextDef(); + } + + public StreamInput getStreamInput() { + return this.streamInput; + } + + public int getName() { + return this.name; + } + + public void setName(int name) { + this.name = name; + } + + public int getCPU() { + return this.packetReader.getCPU(); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Reads the next event in the current event variable. + * + * @return If an event has been successfully read. + */ + public boolean readNextEvent() { + /* + * Change packet if needed + */ + if (!this.packetReader.hasMoreEvents()) { + goToNextPacket(); + } + + /* + * If an event is available, read it. + */ + if (this.packetReader.hasMoreEvents()) { + try { + this.setCurrentEvent(this.packetReader.readNextEvent()); + } catch (CTFReaderException e) { + /* Some problem happened, we'll assume there is no more events */ + return false; + } + return true; + } + this.setCurrentEvent(null); + return false; + } + + /** + * Change the current packet of the packet reader to the next one. + */ + private void goToNextPacket() { + if (this.packetIndexIt.hasNext()) { + this.packetReader.setCurrentPacket(this.packetIndexIt.next()); + } else { + this.packetReader.setCurrentPacket(null); + } + } + + /** + * Changes the location of the trace file reader so that the current event + * is the first event with a timestamp greater than the given timestamp. + * + * @param timestamp + * The timestamp to seek to. + */ + public void seek(long timestamp) { + /* + * Search in the index for the packet to search in. + */ + this.packetIndexIt = this.streamInput.getIndex().search(timestamp); + + /* + * Switch to this packet. + */ + goToNextPacket(); + + /* + * Advance until A. we reached the end of the trace file (which means + * the given timestamp is after the last event), or B. we found the + * first event with a timestamp greater than the given timestamp. + */ + readNextEvent(); + boolean done = (this.getCurrentEvent() == null); + while (!done && (this.getCurrentEvent().timestamp < timestamp)) { + readNextEvent(); + done = (this.getCurrentEvent() == null); + } + } + + public void goToLastEvent() throws CTFReaderException { + /* + * Search in the index for the packet to search in. + */ + this.packetIndexIt = this.streamInput.getIndex().search(Long.MAX_VALUE); + /* + * Go until the end of that packet + */ + while (this.packetReader.hasMoreEvents()) { + this.packetReader.readNextEvent(); + } + } + + public void setCurrentEvent(EventDefinition currentEvent) { + this.currentEvent = currentEvent; + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java new file mode 100644 index 0000000000..1b81e0d402 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderComparator.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.io.Serializable; +import java.util.Comparator; + +/** + * StreamInputReaderComparator + *

+ * TODO Implement me. Please. + */ +public class StreamInputReaderComparator implements + Comparator, Serializable { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + private static final long serialVersionUID = 7477206132343139753L; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public int compare(StreamInputReader a, StreamInputReader b) { + // TODO: use unsigned comparison to avoid sign errors if needed + long ta = a.getCurrentEvent().timestamp; + long tb = b.getCurrentEvent().timestamp; + + if (ta < tb) { + return -1; + } else if (ta > tb) { + return 1; + } else { + return 0; + } + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java new file mode 100644 index 0000000000..0971758fdc --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.io.Serializable; +import java.util.Comparator; + +/** + * StreamInputReaderTimestampComparator + *

+ * Compares two StreamInputReader by their timestamp (smaller comes before). + */ +public class StreamInputReaderTimestampComparator implements + Comparator, Serializable { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + private static final long serialVersionUID = 1066434959451875045L; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + @Override + public int compare(StreamInputReader a, StreamInputReader b) { + // TODO: use unsigned comparison to avoid sign errors if needed + if (a.getCurrentEvent() == null) { + return 0; + } + if (b.getCurrentEvent() == null) { + return 0; + } + long ta = a.getCurrentEvent().timestamp; + long tb = b.getCurrentEvent().timestamp; + + if (ta < tb) { + return -1; + } else if (ta > tb) { + return 1; + } else { + return 0; + } + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java new file mode 100644 index 0000000000..171db4827b --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: Simon Marchi - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.trace; + +import java.util.UUID; + +/** + * Utils + *

+ * Various utilities. + */ +public class Utils { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * CTF magic number. + */ + public final static int CTF_MAGIC = 0xC1FC1FC1; + + /** + * TSDL magic number. + */ + public final static int TSDL_MAGIC = 0x75D11D57; + + /** + * TSDL magic number length in bytes. + */ + public final static int TSDL_MAGIC_LEN = 4; + + /** + * Directory separator on the current platform. + */ + public final static String SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ + + /** + * Length in bytes of a UUID value. + */ + public final static int UUID_LEN = 16; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Unsigned long comparison. + * + * @param a + * First operand. + * @param b + * Second operand. + * @return -1 if a < b, 1 if a > b, 0 if a == b. + */ + public static int unsignedCompare(long a, long b) { + boolean aLeftBit = (a & (1 << (Long.SIZE - 1))) != 0; + boolean bLeftBit = (b & (1 << (Long.SIZE - 1))) != 0; + + if (aLeftBit && !bLeftBit) { + return 1; + } else if (!aLeftBit && bLeftBit) { + return -1; + } else { + if (a < b) { + return -1; + } else if (a > b) { + return 1; + } else { + return 0; + } + } + } + + /** + * Creates a UUID object from an array of 16 bytes. + * + * @param bytes + * Array of 16 bytes. + * @return A UUID object. + */ + public static UUID makeUUID(byte bytes[]) { + long high = 0; + long low = 0; + + assert (bytes.length == Utils.UUID_LEN); + + for (int i = 0; i < 8; i++) { + low = (low << 8) | (bytes[i + 8] & 0xFF); + high = (high << 8) | (bytes[i] & 0xFF); + } + + UUID uuid = new UUID(high, low); + + return uuid; + } + +} diff --git a/org.eclipse.linuxtools.ctf.parser/.classpath b/org.eclipse.linuxtools.ctf.parser/.classpath new file mode 100644 index 0000000000..121e527a93 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.ctf.parser/.gitignore b/org.eclipse.linuxtools.ctf.parser/.gitignore new file mode 100644 index 0000000000..8d94ef8deb --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/.gitignore @@ -0,0 +1,5 @@ +bin +@dot +javaCompiler...args +build.xml +target diff --git a/org.eclipse.linuxtools.ctf.parser/.project b/org.eclipse.linuxtools.ctf.parser/.project new file mode 100644 index 0000000000..126a7777b3 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/.project @@ -0,0 +1,34 @@ + + + org.eclipse.linuxtools.ctf.parser + + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + org.deved.antlride.core.nature + + diff --git a/org.eclipse.linuxtools.ctf.parser/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.ctf.parser/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..625a8b0fdf --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Mon Dec 05 10:48:35 EST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.linuxtools.ctf.parser/Grammar/CTFLexer.g b/org.eclipse.linuxtools.ctf.parser/Grammar/CTFLexer.g new file mode 100644 index 0000000000..22acde6727 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/Grammar/CTFLexer.g @@ -0,0 +1,187 @@ +lexer grammar CTFLexer; + +options { + language = Java; +} + +@lexer::header { + package org.eclipse.linuxtools.ctf.parser; +} + +/* + * Lexer grammers + */ + +/* + * Keywords + */ +ALIGNTOK : 'align' ; +CONSTTOK : 'const' ; +CHARTOK : 'char' ; +DOUBLETOK : 'double' ; +ENUMTOK : 'enum' ; +EVENTTOK : 'event' ; +FLOATINGPOINTTOK : 'floating_point' ; +FLOATTOK : 'float' ; +INTEGERTOK : 'integer' ; +INTTOK : 'int' ; +LONGTOK : 'long' ; +SHORTTOK : 'short' ; +SIGNEDTOK : 'signed' ; +STREAMTOK : 'stream' ; +STRINGTOK : 'string' ; +STRUCTTOK : 'struct' ; +TRACETOK : 'trace' ; +TYPEALIASTOK : 'typealias' ; +TYPEDEFTOK : 'typedef' ; +UNSIGNEDTOK : 'unsigned' ; +VARIANTTOK : 'variant' ; +VOIDTOK : 'void' ; +BOOLTOK : '_Bool' ; +COMPLEXTOK : '_Complex' ; +IMAGINARYTOK : '_Imaginary' ; +ENVTOK : 'env' ; +CLOCKTOK : 'clock' ; + +/* + * Spec still to come. + */ +NANNUMBERTOK : 'NaN' ; +INFINITYTOK : '+inf' ; +NINFINITYTOK : '-inf' ; + +/* + * Symbols + */ +SEPARATOR : ',' ; +COLON : ':' ; +ELIPSES : '...' ; +ASSIGNMENT : '=' ; +TYPE_ASSIGNMENT : ':=' ; +LT : '<' ; +GT : '>' ; +OPENBRAC : '[' ; +CLOSEBRAC : ']' ; +LPAREN : '(' ; +RPAREN : ')' ; +LCURL : '{' ; +RCURL : '}' ; +TERM : ';' ; +POINTER : '*' ; +SIGN : '+' | '-' ; +ARROW : '->' ; +DOT : '.' ; +fragment BACKSLASH : '\\' ; + +/* + * Boolean literals + * - We better leave them as identifiers and numbers... + */ +/*TRUE : 'true' | 'TRUE' ; +FALSE : 'false' | 'FALSE' ; +ZERO : '0' ; +ONE : '1' ;*/ + + +/* + * Integer literals + */ +OCTAL_LITERAL : '0' ('0'..'7')+ INTEGER_TYPES_SUFFIX? ; + +DECIMAL_LITERAL : DIGIT+ INTEGER_TYPES_SUFFIX? ; + +HEX_LITERAL : HEX_PREFIX HEX_DIGIT+ INTEGER_TYPES_SUFFIX? ; +fragment HEX_DIGIT : DIGIT | ('a'..'f') | ('A'..'F') ; +fragment HEX_PREFIX : '0' ('x' | 'X') ; + +/* Helpers for integer literals */ +fragment DIGIT : '0'..'9' ; +fragment NONZERO_DIGIT : '1'..'9' ; + + +/** + * Integer suffix for long, long long and unsigned. + * + * Matches all possible combination of L, LL and U. + */ +fragment INTEGER_TYPES_SUFFIX : + ('l' ('l')? | 'L' ('L')?) // l, ll + | ('u' | 'U') // u + | ('u' | 'U') ('l' ('l')? | 'L' ('L')?) // ul, ull + | ('l' ('l')? | 'L' ('L')?) ('u'| 'U') // lu, llu + ; + +/** + * Escape sequences + */ +fragment ESCAPE_SEQUENCE : + BACKSLASH ('\'' | '"' | '?' | BACKSLASH | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' ) + | OCTAL_ESCAPE + | UNICODE_ESCAPE + | HEXADECIMAL_ESCAPE + ; + +/** + * Octal escape sequence + */ +fragment OCTAL_ESCAPE : + BACKSLASH ('0'..'3') ('0'..'7') ('0'..'7') + | BACKSLASH ('0'..'7') ('0'..'7') + | BACKSLASH ('0'..'7') + ; + +/** + * Hexadecimal escape sequence + */ +fragment HEXADECIMAL_ESCAPE : BACKSLASH 'x' HEX_DIGIT+ ; + +/** + * Unicode escape sequence + */ +fragment UNICODE_ESCAPE : + BACKSLASH 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + | BACKSLASH 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + ; + + +/* Used in both character and string literal */ +fragment STRINGPREFIX : 'L'; + +/* + * Character literal + */ +CHARACTER_LITERAL : STRINGPREFIX? SINGLEQUOTE CHAR_CONTENT+ SINGLEQUOTE ; +fragment CHAR_CONTENT : (ESCAPE_SEQUENCE | ~(BACKSLASH | SINGLEQUOTE)) ; +fragment SINGLEQUOTE : '\''; + +/* + * String literal + */ +STRING_LITERAL : STRINGPREFIX? DOUBLEQUOTE STRING_CONTENT* DOUBLEQUOTE ; +fragment STRING_CONTENT : (ESCAPE_SEQUENCE | ~(BACKSLASH | DOUBLEQUOTE)) ; +fragment DOUBLEQUOTE : '"' ; + +/** + * Whitespaces + */ +WS : (' ' | '\r' | '\t' | '\u000C' | '\n') { $channel=HIDDEN; } ; + +/** + * Multiline comment + */ +// About the greedy option: see page 100-101 of The Definitive ANTLR reference +// COMMENT : '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;} ; +COMMENT : COMMENT_OPEN .* COMMENT_CLOSE { $channel = HIDDEN; } ; +fragment COMMENT_OPEN : '/*'; +fragment COMMENT_CLOSE : '*/'; + +/** + * Single line comment + */ +LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ; + +/** + * Identifiers + */ +IDENTIFIER : NONDIGIT (NONDIGIT | DIGIT)* ; +fragment NONDIGIT : ('_') | ('A'..'Z') | ('a'..'z') ; diff --git a/org.eclipse.linuxtools.ctf.parser/Grammar/CTFParser.g b/org.eclipse.linuxtools.ctf.parser/Grammar/CTFParser.g new file mode 100644 index 0000000000..9906e80f65 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/Grammar/CTFParser.g @@ -0,0 +1,1003 @@ +parser grammar CTFParser; + +options { + language = Java; + output = AST; + ASTLabelType = CommonTree; + tokenVocab = CTFLexer; +} + +tokens { + ROOT; + + EVENT; + STREAM; + TRACE; + ENV; + CLOCK; + + DECLARATION; + SV_DECLARATION; + TYPE_SPECIFIER_LIST; + TYPE_DECLARATOR_LIST; + TYPE_DECLARATOR; + + STRUCT; + STRUCT_NAME; + STRUCT_BODY; + ALIGN; + + CTF_EXPRESSION_TYPE; + CTF_EXPRESSION_VAL; + CTF_LEFT; + CTF_RIGHT; + + UNARY_EXPRESSION_STRING; + UNARY_EXPRESSION_STRING_QUOTES; + UNARY_EXPRESSION_DEC; + UNARY_EXPRESSION_HEX; + UNARY_EXPRESSION_OCT; + LENGTH; + + TYPEDEF; + + TYPEALIAS; + TYPEALIAS_TARGET; + TYPEALIAS_ALIAS; + + INTEGER; + STRING; + FLOATING_POINT; + + ENUM; + ENUM_CONTAINER_TYPE; + ENUM_ENUMERATOR; + ENUM_NAME; + ENUM_VALUE; + ENUM_VALUE_RANGE; + ENUM_BODY; + + VARIANT; + VARIANT_NAME; + VARIANT_TAG; + VARIANT_BODY; + + DECLARATOR; + LENGTH; +} + +/* + * Scope for the tracking of types. + * For now we just track the names (it's a simple Set), but + * later we will have to track the info about the target type. + */ +scope Symbols { + Set types; +} + +@header { +package org.eclipse.linuxtools.ctf.parser; +import java.util.Set; +import java.util.HashSet; +} + +@members { + public CTFParser(TokenStream input, boolean verbose) { + this(input); + this.verbose = verbose; + } + + /* To disable automatic error recovery. When we have a mismatched token, simply throw an exception. */ + @Override + protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException + { + throw new MismatchedTokenException(ttype, input); + } + + /** + * Checks if a given name has been defined has a type. + * From: http://www.antlr.org/grammar/1153358328744/C.g + * + * @param name The name to check. + * @return True if is is a type, false otherwise. + */ + boolean isTypeName(String name) { + for (int i = Symbols_stack.size() - 1; i >= 0; i--) { + Symbols_scope scope = (Symbols_scope)Symbols_stack.get(i); + if (scope.types.contains(name)) { + return true; + } + } + return false; + } + + void addTypeName(String name) { + $Symbols::types.add(name); + if (verbose) { + debug_print("New type: " + name); + } + } + + boolean _inTypedef = false; + + void typedefOn() { + debug_print("typedefOn"); + _inTypedef = true; + } + + void typedefOff() { + debug_print("typedefOff"); + _inTypedef = false; + } + + boolean inTypedef() { + return _inTypedef; + } + + boolean _inTypealiasAlias = false; + + void typealiasAliasOn() { + debug_print("typealiasAliasOn"); + _inTypealiasAlias = true; + } + + void typealiasAliasOff() { + debug_print("typealiasAliasOff"); + _inTypealiasAlias = false; + } + + boolean inTypealiasAlias() { + return _inTypealiasAlias; + } + + void print_tabs(int n) { + for (int i = 0; i < n; i++) { + System.out.print(" "); + } + } + + void enter(String name) { + if (verbose) { + if (state.backtracking == 0) { + print_tabs(depth); + debug_print("+ " + name); + depth++; + } + } + } + + void exit(String name) { + if (verbose) { + depth--; + print_tabs(depth); + debug_print("- " + name); + } + } + + void debug_print(String str) { + if (verbose) { + System.out.println(str); + } + } + + int depth = 0; + + /* Prints rule entry and exit while parsing */ + boolean verbose = false; +} + +/* To disable automatic error recovery. By default, the catch block of every rule simple rethrows the error. */ +@rulecatch { + catch (RecognitionException e) + { + throw e; + } +} + +/* The top-level rule. */ +parse +scope Symbols; +@init { + enter("parse"); + debug_print("Scope push " + Symbols_stack.size()); + $Symbols::types = new HashSet(); +} +@after { + debug_print("Scope pop " + Symbols_stack.size()); + exit("parse"); + + debug_print("Final depth, should be 0: " + depth); +} +: + declaration+ EOF -> ^(ROOT declaration+) + ; + +numberLiteral +@init { + enter("numberLiteral"); +} +@after { + debug_print($numberLiteral.text); + exit("numberLiteral"); +} +: + SIGN* (HEX_LITERAL -> ^(UNARY_EXPRESSION_HEX HEX_LITERAL SIGN*) + | DECIMAL_LITERAL -> ^(UNARY_EXPRESSION_DEC DECIMAL_LITERAL SIGN*) + | OCTAL_LITERAL -> ^(UNARY_EXPRESSION_OCT OCTAL_LITERAL SIGN*)) + ; + +constant +@init { + enter("constant"); +} +@after { + exit("constant"); +} +: + numberLiteral + | enumConstant + | CHARACTER_LITERAL + ; + +primaryExpression +@init { + enter("primaryExpression"); +} +@after { + exit("primaryExpression"); +} +: + (IDENTIFIER) => IDENTIFIER { debug_print("IDENTIFIER: " + $IDENTIFIER.text);} -> ^(UNARY_EXPRESSION_STRING IDENTIFIER) + | (ctfKeyword) => ctfKeyword -> ^(UNARY_EXPRESSION_STRING ctfKeyword) + | (STRING_LITERAL) => STRING_LITERAL { debug_print("STRING_LITERAL: " + $STRING_LITERAL.text);} -> ^(UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL) + /*| (LPAREN unaryExpression RPAREN)*/ // Not supported yet + | constant + ; + +reference +@init { + enter("reference"); +} +@after { + debug_print($reference.text); + exit("reference"); +} +: + (ref=DOT | ref=ARROW) IDENTIFIER -> ^($ref ^(UNARY_EXPRESSION_STRING IDENTIFIER)) + ; + +postfixExpressionSuffix +@init { + enter("postfixExpressionSuffix"); +} +@after { + exit("postfixExpressionSuffix"); +} +: + (OPENBRAC unaryExpression CLOSEBRAC!) + | reference + ; + +postfixExpression +@init { + enter("postfixExpression"); +} +@after { + exit("postfixExpression"); +} +: + (primaryExpression) (postfixExpressionSuffix)*| + ((ctfSpecifierHead) (postfixExpressionSuffix)+)// added for ctfV1.8 + ; + +unaryExpression +@init { + enter("unaryExpression"); +} +@after { + exit("unaryExpression"); +} +: + /*((SIGN postfixExpression[true]) + | postfixExpression[false])*/ + postfixExpression + ; + +enumConstant +@init { + enter("enumConstant"); +} +@after { + debug_print($enumConstant.text); + exit("enumConstant"); +} +: + STRING_LITERAL -> ^(UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL) + | IDENTIFIER -> ^(UNARY_EXPRESSION_STRING IDENTIFIER) + | ctfKeyword -> ^(UNARY_EXPRESSION_STRING ctfKeyword) + ; +// 2.2 + +declaration +@init { + enter("declaration"); +} +@after { + exit("declaration"); + if (inTypedef()) + typedefOff(); +} +: + (declarationSpecifiers declaratorList? TERM) + + // When the declaration is completely parsed and was a typedef, we add the declarators to the symbol table. + -> {inTypedef()}? ^(DECLARATION ^(TYPEDEF declaratorList declarationSpecifiers)) + -> ^(DECLARATION declarationSpecifiers declaratorList?) + + | (ctfSpecifier TERM!) + ; + +declarationSpecifiers +@init { + enter("declarationSpecifiers"); +} +@after { + debug_print($declarationSpecifiers.text); + exit("declarationSpecifiers"); +} +: + ( + // We don't want to keep the typedef keyword in the specifier list. + // Instead, we keep track that we encountered a typedef in the declaration. + storageClassSpecifier + | typeQualifier + | typeSpecifier + )+ -> ^(TYPE_SPECIFIER_LIST typeQualifier* typeSpecifier*) + ; + +declaratorList +@init { + enter("declaratorList"); +} +@after { + exit("declaratorList"); +} +: + declarator (SEPARATOR declarator)* -> ^(TYPE_DECLARATOR_LIST declarator+) + ; + +abstractDeclaratorList +@init { + enter("abstractDeclaratorList"); +} +@after { + exit("abstractDeclaratorList"); +} +: + abstractDeclarator (SEPARATOR abstractDeclarator)* -> ^(TYPE_DECLARATOR_LIST abstractDeclarator+) + ; + +storageClassSpecifier : + TYPEDEFTOK {typedefOn();} + ; + +typeSpecifier +@init { + enter("typeSpecifier"); +} +@after { + debug_print($typeSpecifier.text); + exit("typeSpecifier"); +} +: + FLOATTOK + | INTTOK + | LONGTOK + | SHORTTOK + | SIGNEDTOK + | UNSIGNEDTOK + | CHARTOK + | DOUBLETOK + | VOIDTOK + | BOOLTOK + | COMPLEXTOK + | IMAGINARYTOK + | structSpecifier + | variantSpecifier + | enumSpecifier + | ctfTypeSpecifier + | {inTypealiasAlias() || isTypeName(input.LT(1).getText())}? => typedefName + ; + +typeQualifier +@init { + enter("typeQualifier"); +} +@after { + debug_print($typeQualifier.text); + exit("typeQualifier"); +} +: + CONSTTOK + ; + +alignAttribute : + ALIGNTOK LPAREN unaryExpression RPAREN -> ^(ALIGN unaryExpression) + ; + + // you can have an empty struct but not an empty variant +structBody +scope Symbols; +@init { + enter("structBody"); + debug_print("Scope push " + Symbols_stack.size()); + $Symbols::types = new HashSet(); +} +@after { + debug_print("Scope pop " + Symbols_stack.size()); + exit("structBody"); +} +: + LCURL structOrVariantDeclarationList? RCURL -> ^(STRUCT_BODY structOrVariantDeclarationList?) + ; + + + +structSpecifier +@init { + enter("structSpecifier"); +} +@after { + exit("structSpecifier"); +} +: + STRUCTTOK + ( + // We have an IDENTIFIER after 'struct' + ( + structName + ( + alignAttribute + | + ( + structBody + ( /* structBody can return an empty tree, so we need those ? */ + alignAttribute + | + /* empty */ + ) + ) + | + /* empty */ + ) + ) + | + // We have a body after 'struct' + ( + structBody + ( + alignAttribute + | + /* empty */ + ) + ) + ) -> ^(STRUCT structName? structBody? alignAttribute?) + ; + +structName +@init { + enter("structName"); +} +@after { + debug_print($structName.text); + exit("structName"); +} +: + IDENTIFIER -> ^(STRUCT_NAME IDENTIFIER) + ; + +structOrVariantDeclarationList +@init { + enter("structOrVariantDeclarationList"); +} +@after { + exit("structOrVariantDeclarationList"); +} +: + structOrVariantDeclaration+ + ; + +structOrVariantDeclaration +@init { + enter("structOrVariantDeclaration"); +} +@after { + exit("structOrVariantDeclaration"); +} +: + ( + ( + declarationSpecifiers + ( + /* If we met a "typedef" */ + {inTypedef()}? => declaratorList {typedefOff();} + -> ^(TYPEDEF declaratorList declarationSpecifiers) + | structOrVariantDeclaratorList + -> ^(SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList) + ) + ) + | + // Lines 3 and 4 + typealiasDecl -> typealiasDecl + ) + TERM + ; + +specifierQualifierList +@init { + enter("specifierQualifierList"); +} +@after { + exit("specifierQualifierList"); +} +: + (typeQualifier | typeSpecifier)+ -> ^(TYPE_SPECIFIER_LIST typeQualifier* typeSpecifier*) + ; + +structOrVariantDeclaratorList +@init { + enter("structOrVariantDeclaratorList"); +} +@after { + exit("structOrVariantDeclaratorList"); +} +: + structOrVariantDeclarator (SEPARATOR structOrVariantDeclarator)* -> ^(TYPE_DECLARATOR_LIST structOrVariantDeclarator+) + ; + +structOrVariantDeclarator +@init { + enter("structOrVariantDeclarator"); +} +@after { + exit("structOrVariantDeclarator"); +} +: + /* Bitfields not supported yet */ + (declarator (COLON numberLiteral)?) -> declarator + /*| (COLON numberLiteral)*/ + ; + +variantSpecifier +@init { + enter("variantSpecifier"); +} +@after { + exit("variantSpecifier"); +} +: + VARIANTTOK + ( + ( + variantName + ( + ( + variantTag + ( + variantBody + | + /* empty */ + ) + ) + | + variantBody + ) + ) + | + (variantTag variantBody) + | + variantBody + ) -> ^(VARIANT variantName? variantTag? variantBody?) + ; + +variantName +@init { + enter("variantName"); +} +@after { + debug_print($variantName.text); + exit("variantName"); +} +: + IDENTIFIER -> ^(VARIANT_NAME IDENTIFIER) + ; + +variantBody +scope Symbols; +@init { + enter("variantBody"); + debug_print("Scope push " + Symbols_stack.size()); + $Symbols::types = new HashSet(); +} +@after { + debug_print("Scope pop " + Symbols_stack.size()); + exit("variantBody"); +} +: + LCURL structOrVariantDeclarationList RCURL -> ^(VARIANT_BODY structOrVariantDeclarationList) + ; + +variantTag +@init { + enter("variantTag"); +} +@after { + debug_print($variantTag.text); + exit("variantTag"); +} +: + LT IDENTIFIER GT -> ^(VARIANT_TAG IDENTIFIER) + ; + +enumSpecifier +@init { + enter("enumSpecifier"); +} +@after { + exit("enumSpecifier"); +} +: + ENUMTOK + ( + // Lines 1 to 5, when we have "ENUMTOK IDENTIFIER". + ( + enumName + ( + enumContainerType enumBody + | + enumBody + | + // no enumDeclarator or enumBodym + ) + ) + | + // Lines 1, 2, 4, 5, when we have no IDENTIFIER. + ( + enumContainerType enumBody + | + enumBody + ) + ) -> ^(ENUM enumName? enumContainerType? enumBody?) + ; + +enumName +@init { + enter("enumName"); +} +@after { + debug_print($enumName.text); + exit("enumName"); +} +: + IDENTIFIER -> ^(ENUM_NAME IDENTIFIER) + ; + +enumBody +@init { + enter("enumBody"); +} +@after { + exit("enumBody"); +} +: + LCURL enumeratorList (SEPARATOR RCURL | RCURL) -> ^(ENUM_BODY enumeratorList) + ; + +enumContainerType +@init { + enter("enumContainerType"); +} +@after { + exit("enumContainerType"); +} +: + COLON declarationSpecifiers -> ^(ENUM_CONTAINER_TYPE declarationSpecifiers) + ; + +enumeratorList +@init { + enter("enumeratorList"); +} +@after { + exit("enumeratorList"); +} +: + enumerator (SEPARATOR enumerator)* -> (^(ENUM_ENUMERATOR enumerator))+ + ; + +enumerator +@init { + enter("enumerator"); +} +@after { + exit("enumerator"); +} +: + enumConstant enumeratorValue? + ; + +enumeratorValue +@init { + enter("enumeratorValue"); +} +@after { + exit("enumeratorValue"); +} +: + ASSIGNMENT e1=unaryExpression + ( + -> ^(ENUM_VALUE $e1) + | ELIPSES e2=unaryExpression -> ^(ENUM_VALUE_RANGE $e1 $e2) + ) + ; + + +declarator +@init { + enter("declarator"); +} +@after { + exit("declarator"); +} +: + pointer* directDeclarator -> ^(TYPE_DECLARATOR pointer* directDeclarator) + ; + +directDeclarator +@init { + enter("directDeclarator"); +} +@after { + exit("directDeclarator"); +} +: + ( + IDENTIFIER { if (inTypedef()) addTypeName($IDENTIFIER.text); } {debug_print($IDENTIFIER.text);} + /*| LPAREN declarator RPAREN*/ /* Not supported yet */ + ) + directDeclaratorSuffix* + ; + +directDeclaratorSuffix: + OPENBRAC directDeclaratorLength CLOSEBRAC -> ^(LENGTH directDeclaratorLength) + ; + +directDeclaratorLength : + unaryExpression + ; + + +abstractDeclarator +@init { + enter("abstractDeclarator"); +} +@after { + exit("abstractDeclarator"); +} +: + (pointer+ directAbstractDeclarator?) -> ^(TYPE_DECLARATOR pointer+ directAbstractDeclarator?) + | directAbstractDeclarator -> ^(TYPE_DECLARATOR directAbstractDeclarator) + ; + +/* + In the CTF grammar, direct-abstract-declarator can be empty (because of identifier-opt). + We take care of that by appending a '?' to each use of "abstractDeclaratorList". +*/ +directAbstractDeclarator +@init { + enter("directAbstractDeclarator"); +} +@after { + debug_print($directAbstractDeclarator.text); + exit("directAbstractDeclarator"); +} +: + ( + IDENTIFIER + | (LPAREN abstractDeclarator RPAREN) + ) + ( + OPENBRAC unaryExpression? CLOSEBRAC + )? + ; + +pointer +@init { + enter("pointer"); +} +@after { + debug_print($pointer.text); + exit("pointer"); +} +: + POINTER typeQualifierList? -> ^(POINTER typeQualifierList?) + ; + +typeQualifierList : + typeQualifier+ + ; + +typedefName +@init { + enter("typedefName"); +} +@after { + debug_print("typedefName: " + $typedefName.text); + exit("typedefName"); +} +: + {inTypealiasAlias() || isTypeName(input.LT(1).getText())}? IDENTIFIER { if ((inTypedef() || inTypealiasAlias()) && !isTypeName($IDENTIFIER.text)) { addTypeName($IDENTIFIER.text); } } + ; + +/** + * What goes in the target part of a typealias. + * + * For example, the integer part in: + * typealias integer {...} := my_new_integer; + */ +typealiasTarget +@init { + enter("typealiasTarget"); +} +@after { + exit("typealiasTarget"); +} +: + declarationSpecifiers abstractDeclaratorList? + ; + +/** + * What goes in the alias part of a typealias. + * + * For example, the my_new_integer part in: + * typealias integer {...} := my_new_integer; + */ +typealiasAlias +@init { + enter("typealiasAlias"); + typealiasAliasOn(); +} +@after { + exit("typealiasAlias"); + typealiasAliasOff(); +} +: + ( + abstractDeclaratorList + | + (declarationSpecifiers abstractDeclaratorList?) + ) + ; + +typealiasDecl +@init { + enter("typealiasDecl"); +} +@after { + exit("typealiasDecl"); +} +: + TYPEALIASTOK typealiasTarget TYPE_ASSIGNMENT typealiasAlias + -> ^(TYPEALIAS ^(TYPEALIAS_TARGET typealiasTarget) ^(TYPEALIAS_ALIAS typealiasAlias)) + ; + +// 2.3 CTF stuff + +// TODO: Ajouter ceux qui manquent +ctfKeyword +@init { + enter("ctfKeyword"); +} +@after { + debug_print($ctfKeyword.text); + exit("ctfKeyword"); +} +: + ALIGNTOK + | EVENTTOK + | SIGNEDTOK + | STRINGTOK + ; + +ctfSpecifier +@init { + enter("ctfSpecifier"); +} +@after { + exit("ctfSpecifier"); +} + : + // event {...}, stream {...}, trace {...} + ctfSpecifierHead ctfBody -> ^(ctfSpecifierHead ctfBody) + | + // typealias + typealiasDecl -> ^(DECLARATION typealiasDecl) + ; + +ctfSpecifierHead +@init { + enter("ctfSpecifierHead"); +} +@after { + debug_print($ctfSpecifierHead.text); + exit("ctfSpecifierHead"); +} +: + EVENTTOK -> EVENT + | STREAMTOK -> STREAM + | TRACETOK -> TRACE + | ENVTOK -> ENV + | CLOCKTOK -> CLOCK + ; + +ctfTypeSpecifier +@init { + enter("ctfTypeSpecifier"); +} +@after { + exit("ctfTypeSpecifier"); +} +: + /* ctfBody can return an empty tree if the body is empty */ + FLOATINGPOINTTOK ctfBody -> ^(FLOATING_POINT ctfBody?) + | INTEGERTOK ctfBody -> ^(INTEGER ctfBody?) + | STRINGTOK ctfBody? -> ^(STRING ctfBody?) + ; + +ctfBody +scope Symbols; +@init { + enter("ctfBody"); + debug_print("Scope push " + + Symbols_stack.size()); + $Symbols::types = new HashSet(); +} +@after { + debug_print("Scope pop " + + Symbols_stack.size()); + exit("ctfBody"); +} +: + LCURL ctfAssignmentExpressionList? RCURL -> ctfAssignmentExpressionList? + ; + +ctfAssignmentExpressionList : + (ctfAssignmentExpression TERM!)+ + ; + + +ctfAssignmentExpression +@init { + enter("ctfAssignmentExpression"); +} +@after { + if (inTypedef()) { + typedefOff(); + } + exit("ctfAssignmentExpression"); +} +: + ( + left=unaryExpression + ( + (assignment=ASSIGNMENT right1=unaryExpression) -> ^(CTF_EXPRESSION_VAL ^(CTF_LEFT $left) ^(CTF_RIGHT $right1)) + | (type_assignment=TYPE_ASSIGNMENT right2=typeSpecifier) -> ^(CTF_EXPRESSION_TYPE ^(CTF_LEFT $left) ^(CTF_RIGHT ^(TYPE_SPECIFIER_LIST $right2))) + ) + ) + + | + + (declarationSpecifiers {inTypedef()}? declaratorList) + -> ^(TYPEDEF declaratorList declarationSpecifiers) + | + + typealiasDecl + ; diff --git a/org.eclipse.linuxtools.ctf.parser/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.parser/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..a2de039c30 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.linuxtools.ctf.parser +Bundle-Version: 0.1.0.qualifier +Export-Package: org.eclipse.linuxtools.ctf.parser +Bundle-Vendor: %Bundle-Vendor +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: org.antlr.runtime;bundle-version="3.0.0" diff --git a/org.eclipse.linuxtools.ctf.parser/about.html b/org.eclipse.linuxtools.ctf.parser/about.html new file mode 100644 index 0000000000..c258ef55d8 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf.parser/build.properties b/org.eclipse.linuxtools.ctf.parser/build.properties new file mode 100644 index 0000000000..6fdb7efc72 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + plugin.properties,\ + about.html,\ + . +jars.compile.order = . +source.. = src/ diff --git a/org.eclipse.linuxtools.ctf.parser/plugin.properties b/org.eclipse.linuxtools.ctf.parser/plugin.properties new file mode 100644 index 0000000000..2b69b9c900 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.linuxtools.tmf +Bundle-Vendor = Eclipse Linux Tools +Bundle-Name = CTF Parser diff --git a/org.eclipse.linuxtools.ctf.parser/pom.xml b/org.eclipse.linuxtools.ctf.parser/pom.xml new file mode 100644 index 0000000000..2e5feb2229 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + + linuxtools-lttng-parent + org.eclipse.linuxtools.lttng + 0.10.0-SNAPSHOT + + + Linux Tools LTTng CTF Parser Plug-in + org.eclipse.linuxtools.ctf + org.eclipse.linuxtools.ctf.parser + 0.1.0-SNAPSHOT + eclipse-plugin + + + + + + src + + **/*.java + + + + + + org.eclipse.tycho + tycho-source-plugin + + + + + diff --git a/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/.gitignore b/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/.gitignore new file mode 100644 index 0000000000..d4840a1533 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/.gitignore @@ -0,0 +1,2 @@ +/CTFParser.tokens +/CTFLexer.tokens diff --git a/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFLexer.java b/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFLexer.java new file mode 100644 index 0000000000..7653cb01ab --- /dev/null +++ b/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFLexer.java @@ -0,0 +1,3556 @@ +// $ANTLR !Unknown version! Grammar/CTFLexer.g 2012-03-09 14:59:17 + + package org.eclipse.linuxtools.ctf.parser; + + +import org.antlr.runtime.BaseRecognizer; +import org.antlr.runtime.CharStream; +import org.antlr.runtime.DFA; +import org.antlr.runtime.EarlyExitException; +import org.antlr.runtime.Lexer; +import org.antlr.runtime.MismatchedSetException; +import org.antlr.runtime.NoViableAltException; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.RecognizerSharedState; + +@SuppressWarnings("nls") +public class CTFLexer extends Lexer { + public static final int SIGN=49; + public static final int TERM=47; + public static final int BOOLTOK=26; + public static final int LT=39; + public static final int TYPEDEFTOK=22; + public static final int STRING_CONTENT=70; + public static final int INTEGER_TYPES_SUFFIX=53; + public static final int POINTER=48; + public static final int HEX_PREFIX=57; + public static final int INTTOK=13; + public static final int SEPARATOR=34; + public static final int TYPE_ASSIGNMENT=38; + public static final int ENUMTOK=8; + public static final int COMPLEXTOK=27; + public static final int IMAGINARYTOK=28; + public static final int DOUBLEQUOTE=69; + public static final int STREAMTOK=17; + public static final int EOF=-1; + public static final int INFINITYTOK=32; + public static final int LPAREN=43; + public static final int STRINGPREFIX=65; + public static final int UNSIGNEDTOK=23; + public static final int ESCAPE_SEQUENCE=64; + public static final int CHAR_CONTENT=67; + public static final int RPAREN=44; + public static final int UNICODE_ESCAPE=62; + public static final int STRING_LITERAL=71; + public static final int SINGLEQUOTE=66; + public static final int IDENTIFIER=78; + public static final int ALIGNTOK=4; + public static final int FLOATTOK=11; + public static final int COMMENT_CLOSE=74; + public static final int STRINGTOK=18; + public static final int HEX_LITERAL=59; + public static final int DIGIT=55; + public static final int COMMENT=75; + public static final int DOT=51; + public static final int STRUCTTOK=19; + public static final int ENVTOK=29; + public static final int TYPEALIASTOK=21; + public static final int OPENBRAC=41; + public static final int FLOATINGPOINTTOK=10; + public static final int EVENTTOK=9; + public static final int LINE_COMMENT=76; + public static final int NINFINITYTOK=33; + public static final int VOIDTOK=25; + public static final int DOUBLETOK=7; + public static final int CHARACTER_LITERAL=68; + public static final int OCTAL_LITERAL=54; + public static final int COMMENT_OPEN=73; + public static final int HEX_DIGIT=58; + public static final int OCTAL_ESCAPE=61; + public static final int NANNUMBERTOK=31; + public static final int LONGTOK=14; + public static final int CLOCKTOK=30; + public static final int SIGNEDTOK=16; + public static final int TRACETOK=20; + public static final int COLON=35; + public static final int HEXADECIMAL_ESCAPE=63; + public static final int CHARTOK=6; + public static final int LCURL=45; + public static final int WS=72; + public static final int INTEGERTOK=12; + public static final int VARIANTTOK=24; + public static final int ELIPSES=36; + public static final int NONDIGIT=77; + public static final int RCURL=46; + public static final int ARROW=50; + public static final int GT=40; + public static final int ASSIGNMENT=37; + public static final int SHORTTOK=15; + public static final int NONZERO_DIGIT=60; + public static final int DECIMAL_LITERAL=56; + public static final int CONSTTOK=5; + public static final int BACKSLASH=52; + public static final int CLOSEBRAC=42; + + // delegates + // delegators + + public CTFLexer() {;} + public CTFLexer(CharStream input) { + this(input, new RecognizerSharedState()); + } + public CTFLexer(CharStream input, RecognizerSharedState state) { + super(input,state); + + } + + @Override + public String getGrammarFileName() { return "Grammar/CTFLexer.g"; } + + // $ANTLR start "ALIGNTOK" + public final void mALIGNTOK() throws RecognitionException { + try { + int _type = ALIGNTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:18:18: ( 'align' ) + // Grammar/CTFLexer.g:18:20: 'align' + { + match("align"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "ALIGNTOK" + + // $ANTLR start "CONSTTOK" + public final void mCONSTTOK() throws RecognitionException { + try { + int _type = CONSTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:19:18: ( 'const' ) + // Grammar/CTFLexer.g:19:20: 'const' + { + match("const"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "CONSTTOK" + + // $ANTLR start "CHARTOK" + public final void mCHARTOK() throws RecognitionException { + try { + int _type = CHARTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:20:18: ( 'char' ) + // Grammar/CTFLexer.g:20:20: 'char' + { + match("char"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "CHARTOK" + + // $ANTLR start "DOUBLETOK" + public final void mDOUBLETOK() throws RecognitionException { + try { + int _type = DOUBLETOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:21:18: ( 'double' ) + // Grammar/CTFLexer.g:21:20: 'double' + { + match("double"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "DOUBLETOK" + + // $ANTLR start "ENUMTOK" + public final void mENUMTOK() throws RecognitionException { + try { + int _type = ENUMTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:22:18: ( 'enum' ) + // Grammar/CTFLexer.g:22:20: 'enum' + { + match("enum"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "ENUMTOK" + + // $ANTLR start "EVENTTOK" + public final void mEVENTTOK() throws RecognitionException { + try { + int _type = EVENTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:23:18: ( 'event' ) + // Grammar/CTFLexer.g:23:20: 'event' + { + match("event"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "EVENTTOK" + + // $ANTLR start "FLOATINGPOINTTOK" + public final void mFLOATINGPOINTTOK() throws RecognitionException { + try { + int _type = FLOATINGPOINTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:24:18: ( 'floating_point' ) + // Grammar/CTFLexer.g:24:20: 'floating_point' + { + match("floating_point"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "FLOATINGPOINTTOK" + + // $ANTLR start "FLOATTOK" + public final void mFLOATTOK() throws RecognitionException { + try { + int _type = FLOATTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:25:18: ( 'float' ) + // Grammar/CTFLexer.g:25:20: 'float' + { + match("float"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "FLOATTOK" + + // $ANTLR start "INTEGERTOK" + public final void mINTEGERTOK() throws RecognitionException { + try { + int _type = INTEGERTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:26:18: ( 'integer' ) + // Grammar/CTFLexer.g:26:20: 'integer' + { + match("integer"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "INTEGERTOK" + + // $ANTLR start "INTTOK" + public final void mINTTOK() throws RecognitionException { + try { + int _type = INTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:27:18: ( 'int' ) + // Grammar/CTFLexer.g:27:20: 'int' + { + match("int"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "INTTOK" + + // $ANTLR start "LONGTOK" + public final void mLONGTOK() throws RecognitionException { + try { + int _type = LONGTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:28:18: ( 'long' ) + // Grammar/CTFLexer.g:28:20: 'long' + { + match("long"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "LONGTOK" + + // $ANTLR start "SHORTTOK" + public final void mSHORTTOK() throws RecognitionException { + try { + int _type = SHORTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:29:18: ( 'short' ) + // Grammar/CTFLexer.g:29:20: 'short' + { + match("short"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "SHORTTOK" + + // $ANTLR start "SIGNEDTOK" + public final void mSIGNEDTOK() throws RecognitionException { + try { + int _type = SIGNEDTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:30:18: ( 'signed' ) + // Grammar/CTFLexer.g:30:20: 'signed' + { + match("signed"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "SIGNEDTOK" + + // $ANTLR start "STREAMTOK" + public final void mSTREAMTOK() throws RecognitionException { + try { + int _type = STREAMTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:31:18: ( 'stream' ) + // Grammar/CTFLexer.g:31:20: 'stream' + { + match("stream"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "STREAMTOK" + + // $ANTLR start "STRINGTOK" + public final void mSTRINGTOK() throws RecognitionException { + try { + int _type = STRINGTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:32:18: ( 'string' ) + // Grammar/CTFLexer.g:32:20: 'string' + { + match("string"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "STRINGTOK" + + // $ANTLR start "STRUCTTOK" + public final void mSTRUCTTOK() throws RecognitionException { + try { + int _type = STRUCTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:33:18: ( 'struct' ) + // Grammar/CTFLexer.g:33:20: 'struct' + { + match("struct"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "STRUCTTOK" + + // $ANTLR start "TRACETOK" + public final void mTRACETOK() throws RecognitionException { + try { + int _type = TRACETOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:34:18: ( 'trace' ) + // Grammar/CTFLexer.g:34:20: 'trace' + { + match("trace"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "TRACETOK" + + // $ANTLR start "TYPEALIASTOK" + public final void mTYPEALIASTOK() throws RecognitionException { + try { + int _type = TYPEALIASTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:35:18: ( 'typealias' ) + // Grammar/CTFLexer.g:35:20: 'typealias' + { + match("typealias"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "TYPEALIASTOK" + + // $ANTLR start "TYPEDEFTOK" + public final void mTYPEDEFTOK() throws RecognitionException { + try { + int _type = TYPEDEFTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:36:18: ( 'typedef' ) + // Grammar/CTFLexer.g:36:20: 'typedef' + { + match("typedef"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "TYPEDEFTOK" + + // $ANTLR start "UNSIGNEDTOK" + public final void mUNSIGNEDTOK() throws RecognitionException { + try { + int _type = UNSIGNEDTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:37:18: ( 'unsigned' ) + // Grammar/CTFLexer.g:37:20: 'unsigned' + { + match("unsigned"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "UNSIGNEDTOK" + + // $ANTLR start "VARIANTTOK" + public final void mVARIANTTOK() throws RecognitionException { + try { + int _type = VARIANTTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:38:18: ( 'variant' ) + // Grammar/CTFLexer.g:38:20: 'variant' + { + match("variant"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "VARIANTTOK" + + // $ANTLR start "VOIDTOK" + public final void mVOIDTOK() throws RecognitionException { + try { + int _type = VOIDTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:39:18: ( 'void' ) + // Grammar/CTFLexer.g:39:20: 'void' + { + match("void"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "VOIDTOK" + + // $ANTLR start "BOOLTOK" + public final void mBOOLTOK() throws RecognitionException { + try { + int _type = BOOLTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:40:18: ( '_Bool' ) + // Grammar/CTFLexer.g:40:20: '_Bool' + { + match("_Bool"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "BOOLTOK" + + // $ANTLR start "COMPLEXTOK" + public final void mCOMPLEXTOK() throws RecognitionException { + try { + int _type = COMPLEXTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:41:18: ( '_Complex' ) + // Grammar/CTFLexer.g:41:20: '_Complex' + { + match("_Complex"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "COMPLEXTOK" + + // $ANTLR start "IMAGINARYTOK" + public final void mIMAGINARYTOK() throws RecognitionException { + try { + int _type = IMAGINARYTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:42:18: ( '_Imaginary' ) + // Grammar/CTFLexer.g:42:20: '_Imaginary' + { + match("_Imaginary"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "IMAGINARYTOK" + + // $ANTLR start "ENVTOK" + public final void mENVTOK() throws RecognitionException { + try { + int _type = ENVTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:43:18: ( 'env' ) + // Grammar/CTFLexer.g:43:20: 'env' + { + match("env"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "ENVTOK" + + // $ANTLR start "CLOCKTOK" + public final void mCLOCKTOK() throws RecognitionException { + try { + int _type = CLOCKTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:44:18: ( 'clock' ) + // Grammar/CTFLexer.g:44:20: 'clock' + { + match("clock"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "CLOCKTOK" + + // $ANTLR start "NANNUMBERTOK" + public final void mNANNUMBERTOK() throws RecognitionException { + try { + int _type = NANNUMBERTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:49:15: ( 'NaN' ) + // Grammar/CTFLexer.g:49:17: 'NaN' + { + match("NaN"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "NANNUMBERTOK" + + // $ANTLR start "INFINITYTOK" + public final void mINFINITYTOK() throws RecognitionException { + try { + int _type = INFINITYTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:50:15: ( '+inf' ) + // Grammar/CTFLexer.g:50:17: '+inf' + { + match("+inf"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "INFINITYTOK" + + // $ANTLR start "NINFINITYTOK" + public final void mNINFINITYTOK() throws RecognitionException { + try { + int _type = NINFINITYTOK; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:51:15: ( '-inf' ) + // Grammar/CTFLexer.g:51:17: '-inf' + { + match("-inf"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "NINFINITYTOK" + + // $ANTLR start "SEPARATOR" + public final void mSEPARATOR() throws RecognitionException { + try { + int _type = SEPARATOR; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:56:20: ( ',' ) + // Grammar/CTFLexer.g:56:22: ',' + { + match(','); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "SEPARATOR" + + // $ANTLR start "COLON" + public final void mCOLON() throws RecognitionException { + try { + int _type = COLON; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:57:20: ( ':' ) + // Grammar/CTFLexer.g:57:22: ':' + { + match(':'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "COLON" + + // $ANTLR start "ELIPSES" + public final void mELIPSES() throws RecognitionException { + try { + int _type = ELIPSES; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:58:20: ( '...' ) + // Grammar/CTFLexer.g:58:22: '...' + { + match("..."); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "ELIPSES" + + // $ANTLR start "ASSIGNMENT" + public final void mASSIGNMENT() throws RecognitionException { + try { + int _type = ASSIGNMENT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:59:20: ( '=' ) + // Grammar/CTFLexer.g:59:22: '=' + { + match('='); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "ASSIGNMENT" + + // $ANTLR start "TYPE_ASSIGNMENT" + public final void mTYPE_ASSIGNMENT() throws RecognitionException { + try { + int _type = TYPE_ASSIGNMENT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:60:20: ( ':=' ) + // Grammar/CTFLexer.g:60:22: ':=' + { + match(":="); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "TYPE_ASSIGNMENT" + + // $ANTLR start "LT" + public final void mLT() throws RecognitionException { + try { + int _type = LT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:61:20: ( '<' ) + // Grammar/CTFLexer.g:61:22: '<' + { + match('<'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "LT" + + // $ANTLR start "GT" + public final void mGT() throws RecognitionException { + try { + int _type = GT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:62:20: ( '>' ) + // Grammar/CTFLexer.g:62:22: '>' + { + match('>'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "GT" + + // $ANTLR start "OPENBRAC" + public final void mOPENBRAC() throws RecognitionException { + try { + int _type = OPENBRAC; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:63:20: ( '[' ) + // Grammar/CTFLexer.g:63:22: '[' + { + match('['); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "OPENBRAC" + + // $ANTLR start "CLOSEBRAC" + public final void mCLOSEBRAC() throws RecognitionException { + try { + int _type = CLOSEBRAC; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:64:20: ( ']' ) + // Grammar/CTFLexer.g:64:22: ']' + { + match(']'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "CLOSEBRAC" + + // $ANTLR start "LPAREN" + public final void mLPAREN() throws RecognitionException { + try { + int _type = LPAREN; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:65:20: ( '(' ) + // Grammar/CTFLexer.g:65:22: '(' + { + match('('); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "LPAREN" + + // $ANTLR start "RPAREN" + public final void mRPAREN() throws RecognitionException { + try { + int _type = RPAREN; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:66:20: ( ')' ) + // Grammar/CTFLexer.g:66:22: ')' + { + match(')'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "RPAREN" + + // $ANTLR start "LCURL" + public final void mLCURL() throws RecognitionException { + try { + int _type = LCURL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:67:20: ( '{' ) + // Grammar/CTFLexer.g:67:22: '{' + { + match('{'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "LCURL" + + // $ANTLR start "RCURL" + public final void mRCURL() throws RecognitionException { + try { + int _type = RCURL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:68:20: ( '}' ) + // Grammar/CTFLexer.g:68:22: '}' + { + match('}'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "RCURL" + + // $ANTLR start "TERM" + public final void mTERM() throws RecognitionException { + try { + int _type = TERM; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:69:20: ( ';' ) + // Grammar/CTFLexer.g:69:22: ';' + { + match(';'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "TERM" + + // $ANTLR start "POINTER" + public final void mPOINTER() throws RecognitionException { + try { + int _type = POINTER; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:70:20: ( '*' ) + // Grammar/CTFLexer.g:70:22: '*' + { + match('*'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "POINTER" + + // $ANTLR start "SIGN" + public final void mSIGN() throws RecognitionException { + try { + int _type = SIGN; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:71:20: ( '+' | '-' ) + // Grammar/CTFLexer.g: + { + if ( input.LA(1)=='+'||input.LA(1)=='-' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "SIGN" + + // $ANTLR start "ARROW" + public final void mARROW() throws RecognitionException { + try { + int _type = ARROW; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:72:20: ( '->' ) + // Grammar/CTFLexer.g:72:22: '->' + { + match("->"); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "ARROW" + + // $ANTLR start "DOT" + public final void mDOT() throws RecognitionException { + try { + int _type = DOT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:73:20: ( '.' ) + // Grammar/CTFLexer.g:73:22: '.' + { + match('.'); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "DOT" + + // $ANTLR start "BACKSLASH" + public final void mBACKSLASH() throws RecognitionException { + try { + // Grammar/CTFLexer.g:74:20: ( '\\\\' ) + // Grammar/CTFLexer.g:74:22: '\\\\' + { + match('\\'); + + } + + } + finally { + } + } + // $ANTLR end "BACKSLASH" + + // $ANTLR start "OCTAL_LITERAL" + public final void mOCTAL_LITERAL() throws RecognitionException { + try { + int _type = OCTAL_LITERAL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:89:15: ( '0' ( '0' .. '7' )+ ( INTEGER_TYPES_SUFFIX )? ) + // Grammar/CTFLexer.g:89:17: '0' ( '0' .. '7' )+ ( INTEGER_TYPES_SUFFIX )? + { + match('0'); + // Grammar/CTFLexer.g:89:21: ( '0' .. '7' )+ + int cnt1=0; + loop1: + do { + int alt1=2; + int LA1_0 = input.LA(1); + + if ( ((LA1_0>='0' && LA1_0<='7')) ) { + alt1=1; + } + + + switch (alt1) { + case 1 : + // Grammar/CTFLexer.g:89:22: '0' .. '7' + { + matchRange('0','7'); + + } + break; + + default : + if ( cnt1 >= 1 ) break loop1; + EarlyExitException eee = + new EarlyExitException(1, input); + throw eee; + } + cnt1++; + } while (true); + + // Grammar/CTFLexer.g:89:33: ( INTEGER_TYPES_SUFFIX )? + int alt2=2; + int LA2_0 = input.LA(1); + + if ( (LA2_0=='L'||LA2_0=='U'||LA2_0=='l'||LA2_0=='u') ) { + alt2=1; + } + switch (alt2) { + case 1 : + // Grammar/CTFLexer.g:89:33: INTEGER_TYPES_SUFFIX + { + mINTEGER_TYPES_SUFFIX(); + + } + break; + + } + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "OCTAL_LITERAL" + + // $ANTLR start "DECIMAL_LITERAL" + public final void mDECIMAL_LITERAL() throws RecognitionException { + try { + int _type = DECIMAL_LITERAL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:91:17: ( ( DIGIT )+ ( INTEGER_TYPES_SUFFIX )? ) + // Grammar/CTFLexer.g:91:19: ( DIGIT )+ ( INTEGER_TYPES_SUFFIX )? + { + // Grammar/CTFLexer.g:91:19: ( DIGIT )+ + int cnt3=0; + loop3: + do { + int alt3=2; + int LA3_0 = input.LA(1); + + if ( ((LA3_0>='0' && LA3_0<='9')) ) { + alt3=1; + } + + + switch (alt3) { + case 1 : + // Grammar/CTFLexer.g:91:19: DIGIT + { + mDIGIT(); + + } + break; + + default : + if ( cnt3 >= 1 ) break loop3; + EarlyExitException eee = + new EarlyExitException(3, input); + throw eee; + } + cnt3++; + } while (true); + + // Grammar/CTFLexer.g:91:26: ( INTEGER_TYPES_SUFFIX )? + int alt4=2; + int LA4_0 = input.LA(1); + + if ( (LA4_0=='L'||LA4_0=='U'||LA4_0=='l'||LA4_0=='u') ) { + alt4=1; + } + switch (alt4) { + case 1 : + // Grammar/CTFLexer.g:91:26: INTEGER_TYPES_SUFFIX + { + mINTEGER_TYPES_SUFFIX(); + + } + break; + + } + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "DECIMAL_LITERAL" + + // $ANTLR start "HEX_LITERAL" + public final void mHEX_LITERAL() throws RecognitionException { + try { + int _type = HEX_LITERAL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:93:13: ( HEX_PREFIX ( HEX_DIGIT )+ ( INTEGER_TYPES_SUFFIX )? ) + // Grammar/CTFLexer.g:93:15: HEX_PREFIX ( HEX_DIGIT )+ ( INTEGER_TYPES_SUFFIX )? + { + mHEX_PREFIX(); + // Grammar/CTFLexer.g:93:26: ( HEX_DIGIT )+ + int cnt5=0; + loop5: + do { + int alt5=2; + int LA5_0 = input.LA(1); + + if ( ((LA5_0>='0' && LA5_0<='9')||(LA5_0>='A' && LA5_0<='F')||(LA5_0>='a' && LA5_0<='f')) ) { + alt5=1; + } + + + switch (alt5) { + case 1 : + // Grammar/CTFLexer.g:93:26: HEX_DIGIT + { + mHEX_DIGIT(); + + } + break; + + default : + if ( cnt5 >= 1 ) break loop5; + EarlyExitException eee = + new EarlyExitException(5, input); + throw eee; + } + cnt5++; + } while (true); + + // Grammar/CTFLexer.g:93:37: ( INTEGER_TYPES_SUFFIX )? + int alt6=2; + int LA6_0 = input.LA(1); + + if ( (LA6_0=='L'||LA6_0=='U'||LA6_0=='l'||LA6_0=='u') ) { + alt6=1; + } + switch (alt6) { + case 1 : + // Grammar/CTFLexer.g:93:37: INTEGER_TYPES_SUFFIX + { + mINTEGER_TYPES_SUFFIX(); + + } + break; + + } + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "HEX_LITERAL" + + // $ANTLR start "HEX_DIGIT" + public final void mHEX_DIGIT() throws RecognitionException { + try { + // Grammar/CTFLexer.g:94:20: ( DIGIT | ( 'a' .. 'f' ) | ( 'A' .. 'F' ) ) + int alt7=3; + switch ( input.LA(1) ) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + alt7=1; + } + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + { + alt7=2; + } + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + { + alt7=3; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 7, 0, input); + + throw nvae; + } + + switch (alt7) { + case 1 : + // Grammar/CTFLexer.g:94:22: DIGIT + { + mDIGIT(); + + } + break; + case 2 : + // Grammar/CTFLexer.g:94:30: ( 'a' .. 'f' ) + { + // Grammar/CTFLexer.g:94:30: ( 'a' .. 'f' ) + // Grammar/CTFLexer.g:94:31: 'a' .. 'f' + { + matchRange('a','f'); + + } + + + } + break; + case 3 : + // Grammar/CTFLexer.g:94:43: ( 'A' .. 'F' ) + { + // Grammar/CTFLexer.g:94:43: ( 'A' .. 'F' ) + // Grammar/CTFLexer.g:94:44: 'A' .. 'F' + { + matchRange('A','F'); + + } + + + } + break; + + } + } + finally { + } + } + // $ANTLR end "HEX_DIGIT" + + // $ANTLR start "HEX_PREFIX" + public final void mHEX_PREFIX() throws RecognitionException { + try { + // Grammar/CTFLexer.g:95:21: ( '0' ( 'x' | 'X' ) ) + // Grammar/CTFLexer.g:95:23: '0' ( 'x' | 'X' ) + { + match('0'); + if ( input.LA(1)=='X'||input.LA(1)=='x' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + + } + finally { + } + } + // $ANTLR end "HEX_PREFIX" + + // $ANTLR start "DIGIT" + public final void mDIGIT() throws RecognitionException { + try { + // Grammar/CTFLexer.g:98:16: ( '0' .. '9' ) + // Grammar/CTFLexer.g:98:18: '0' .. '9' + { + matchRange('0','9'); + + } + + } + finally { + } + } + // $ANTLR end "DIGIT" + + // $ANTLR start "NONZERO_DIGIT" + public final void mNONZERO_DIGIT() throws RecognitionException { + try { + // Grammar/CTFLexer.g:99:24: ( '1' .. '9' ) + // Grammar/CTFLexer.g:99:26: '1' .. '9' + { + matchRange('1','9'); + + } + + } + finally { + } + } + // $ANTLR end "NONZERO_DIGIT" + + // $ANTLR start "INTEGER_TYPES_SUFFIX" + public final void mINTEGER_TYPES_SUFFIX() throws RecognitionException { + try { + // Grammar/CTFLexer.g:107:31: ( ( 'l' ( 'l' )? | 'L' ( 'L' )? ) | ( 'u' | 'U' ) | ( 'u' | 'U' ) ( 'l' ( 'l' )? | 'L' ( 'L' )? ) | ( 'l' ( 'l' )? | 'L' ( 'L' )? ) ( 'u' | 'U' ) ) + int alt17=4; + alt17 = dfa17.predict(input); + switch (alt17) { + case 1 : + // Grammar/CTFLexer.g:108:4: ( 'l' ( 'l' )? | 'L' ( 'L' )? ) + { + // Grammar/CTFLexer.g:108:4: ( 'l' ( 'l' )? | 'L' ( 'L' )? ) + int alt10=2; + int LA10_0 = input.LA(1); + + if ( (LA10_0=='l') ) { + alt10=1; + } + else if ( (LA10_0=='L') ) { + alt10=2; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 10, 0, input); + + throw nvae; + } + switch (alt10) { + case 1 : + // Grammar/CTFLexer.g:108:5: 'l' ( 'l' )? + { + match('l'); + // Grammar/CTFLexer.g:108:9: ( 'l' )? + int alt8=2; + int LA8_0 = input.LA(1); + + if ( (LA8_0=='l') ) { + alt8=1; + } + switch (alt8) { + case 1 : + // Grammar/CTFLexer.g:108:10: 'l' + { + match('l'); + + } + break; + + } + + + } + break; + case 2 : + // Grammar/CTFLexer.g:108:18: 'L' ( 'L' )? + { + match('L'); + // Grammar/CTFLexer.g:108:22: ( 'L' )? + int alt9=2; + int LA9_0 = input.LA(1); + + if ( (LA9_0=='L') ) { + alt9=1; + } + switch (alt9) { + case 1 : + // Grammar/CTFLexer.g:108:23: 'L' + { + match('L'); + + } + break; + + } + + + } + break; + + } + + + } + break; + case 2 : + // Grammar/CTFLexer.g:109:4: ( 'u' | 'U' ) + { + if ( input.LA(1)=='U'||input.LA(1)=='u' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + break; + case 3 : + // Grammar/CTFLexer.g:110:4: ( 'u' | 'U' ) ( 'l' ( 'l' )? | 'L' ( 'L' )? ) + { + if ( input.LA(1)=='U'||input.LA(1)=='u' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + // Grammar/CTFLexer.g:110:16: ( 'l' ( 'l' )? | 'L' ( 'L' )? ) + int alt13=2; + int LA13_0 = input.LA(1); + + if ( (LA13_0=='l') ) { + alt13=1; + } + else if ( (LA13_0=='L') ) { + alt13=2; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 13, 0, input); + + throw nvae; + } + switch (alt13) { + case 1 : + // Grammar/CTFLexer.g:110:17: 'l' ( 'l' )? + { + match('l'); + // Grammar/CTFLexer.g:110:21: ( 'l' )? + int alt11=2; + int LA11_0 = input.LA(1); + + if ( (LA11_0=='l') ) { + alt11=1; + } + switch (alt11) { + case 1 : + // Grammar/CTFLexer.g:110:22: 'l' + { + match('l'); + + } + break; + + } + + + } + break; + case 2 : + // Grammar/CTFLexer.g:110:30: 'L' ( 'L' )? + { + match('L'); + // Grammar/CTFLexer.g:110:34: ( 'L' )? + int alt12=2; + int LA12_0 = input.LA(1); + + if ( (LA12_0=='L') ) { + alt12=1; + } + switch (alt12) { + case 1 : + // Grammar/CTFLexer.g:110:35: 'L' + { + match('L'); + + } + break; + + } + + + } + break; + + } + + + } + break; + case 4 : + // Grammar/CTFLexer.g:111:4: ( 'l' ( 'l' )? | 'L' ( 'L' )? ) ( 'u' | 'U' ) + { + // Grammar/CTFLexer.g:111:4: ( 'l' ( 'l' )? | 'L' ( 'L' )? ) + int alt16=2; + int LA16_0 = input.LA(1); + + if ( (LA16_0=='l') ) { + alt16=1; + } + else if ( (LA16_0=='L') ) { + alt16=2; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 16, 0, input); + + throw nvae; + } + switch (alt16) { + case 1 : + // Grammar/CTFLexer.g:111:5: 'l' ( 'l' )? + { + match('l'); + // Grammar/CTFLexer.g:111:9: ( 'l' )? + int alt14=2; + int LA14_0 = input.LA(1); + + if ( (LA14_0=='l') ) { + alt14=1; + } + switch (alt14) { + case 1 : + // Grammar/CTFLexer.g:111:10: 'l' + { + match('l'); + + } + break; + + } + + + } + break; + case 2 : + // Grammar/CTFLexer.g:111:18: 'L' ( 'L' )? + { + match('L'); + // Grammar/CTFLexer.g:111:22: ( 'L' )? + int alt15=2; + int LA15_0 = input.LA(1); + + if ( (LA15_0=='L') ) { + alt15=1; + } + switch (alt15) { + case 1 : + // Grammar/CTFLexer.g:111:23: 'L' + { + match('L'); + + } + break; + + } + + + } + break; + + } + + if ( input.LA(1)=='U'||input.LA(1)=='u' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + break; + + } + } + finally { + } + } + // $ANTLR end "INTEGER_TYPES_SUFFIX" + + // $ANTLR start "ESCAPE_SEQUENCE" + public final void mESCAPE_SEQUENCE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:117:26: ( BACKSLASH ( '\\'' | '\"' | '?' | BACKSLASH | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' ) | OCTAL_ESCAPE | UNICODE_ESCAPE | HEXADECIMAL_ESCAPE ) + int alt18=4; + int LA18_0 = input.LA(1); + + if ( (LA18_0=='\\') ) { + switch ( input.LA(2) ) { + case 'U': + case 'u': + { + alt18=3; + } + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + { + alt18=2; + } + break; + case 'x': + { + alt18=4; + } + break; + case '\"': + case '\'': + case '?': + case '\\': + case 'a': + case 'b': + case 'f': + case 'n': + case 'r': + case 't': + case 'v': + { + alt18=1; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 18, 1, input); + + throw nvae; + } + + } + else { + NoViableAltException nvae = + new NoViableAltException("", 18, 0, input); + + throw nvae; + } + switch (alt18) { + case 1 : + // Grammar/CTFLexer.g:118:4: BACKSLASH ( '\\'' | '\"' | '?' | BACKSLASH | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' ) + { + mBACKSLASH(); + if ( input.LA(1)=='\"'||input.LA(1)=='\''||input.LA(1)=='?'||input.LA(1)=='\\'||(input.LA(1)>='a' && input.LA(1)<='b')||input.LA(1)=='f'||input.LA(1)=='n'||input.LA(1)=='r'||input.LA(1)=='t'||input.LA(1)=='v' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + break; + case 2 : + // Grammar/CTFLexer.g:119:4: OCTAL_ESCAPE + { + mOCTAL_ESCAPE(); + + } + break; + case 3 : + // Grammar/CTFLexer.g:120:4: UNICODE_ESCAPE + { + mUNICODE_ESCAPE(); + + } + break; + case 4 : + // Grammar/CTFLexer.g:121:4: HEXADECIMAL_ESCAPE + { + mHEXADECIMAL_ESCAPE(); + + } + break; + + } + } + finally { + } + } + // $ANTLR end "ESCAPE_SEQUENCE" + + // $ANTLR start "OCTAL_ESCAPE" + public final void mOCTAL_ESCAPE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:127:23: ( BACKSLASH ( '0' .. '3' ) ( '0' .. '7' ) ( '0' .. '7' ) | BACKSLASH ( '0' .. '7' ) ( '0' .. '7' ) | BACKSLASH ( '0' .. '7' ) ) + int alt19=3; + int LA19_0 = input.LA(1); + + if ( (LA19_0=='\\') ) { + int LA19_1 = input.LA(2); + + if ( ((LA19_1>='0' && LA19_1<='3')) ) { + int LA19_2 = input.LA(3); + + if ( ((LA19_2>='0' && LA19_2<='7')) ) { + int LA19_5 = input.LA(4); + + if ( ((LA19_5>='0' && LA19_5<='7')) ) { + alt19=1; + } + else { + alt19=2;} + } + else { + alt19=3;} + } + else if ( ((LA19_1>='4' && LA19_1<='7')) ) { + int LA19_3 = input.LA(3); + + if ( ((LA19_3>='0' && LA19_3<='7')) ) { + alt19=2; + } + else { + alt19=3;} + } + else { + NoViableAltException nvae = + new NoViableAltException("", 19, 1, input); + + throw nvae; + } + } + else { + NoViableAltException nvae = + new NoViableAltException("", 19, 0, input); + + throw nvae; + } + switch (alt19) { + case 1 : + // Grammar/CTFLexer.g:128:5: BACKSLASH ( '0' .. '3' ) ( '0' .. '7' ) ( '0' .. '7' ) + { + mBACKSLASH(); + // Grammar/CTFLexer.g:128:15: ( '0' .. '3' ) + // Grammar/CTFLexer.g:128:16: '0' .. '3' + { + matchRange('0','3'); + + } + + // Grammar/CTFLexer.g:128:26: ( '0' .. '7' ) + // Grammar/CTFLexer.g:128:27: '0' .. '7' + { + matchRange('0','7'); + + } + + // Grammar/CTFLexer.g:128:37: ( '0' .. '7' ) + // Grammar/CTFLexer.g:128:38: '0' .. '7' + { + matchRange('0','7'); + + } + + + } + break; + case 2 : + // Grammar/CTFLexer.g:129:5: BACKSLASH ( '0' .. '7' ) ( '0' .. '7' ) + { + mBACKSLASH(); + // Grammar/CTFLexer.g:129:15: ( '0' .. '7' ) + // Grammar/CTFLexer.g:129:16: '0' .. '7' + { + matchRange('0','7'); + + } + + // Grammar/CTFLexer.g:129:26: ( '0' .. '7' ) + // Grammar/CTFLexer.g:129:27: '0' .. '7' + { + matchRange('0','7'); + + } + + + } + break; + case 3 : + // Grammar/CTFLexer.g:130:5: BACKSLASH ( '0' .. '7' ) + { + mBACKSLASH(); + // Grammar/CTFLexer.g:130:15: ( '0' .. '7' ) + // Grammar/CTFLexer.g:130:16: '0' .. '7' + { + matchRange('0','7'); + + } + + + } + break; + + } + } + finally { + } + } + // $ANTLR end "OCTAL_ESCAPE" + + // $ANTLR start "HEXADECIMAL_ESCAPE" + public final void mHEXADECIMAL_ESCAPE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:136:29: ( BACKSLASH 'x' ( HEX_DIGIT )+ ) + // Grammar/CTFLexer.g:136:31: BACKSLASH 'x' ( HEX_DIGIT )+ + { + mBACKSLASH(); + match('x'); + // Grammar/CTFLexer.g:136:45: ( HEX_DIGIT )+ + int cnt20=0; + loop20: + do { + int alt20=2; + int LA20_0 = input.LA(1); + + if ( ((LA20_0>='0' && LA20_0<='9')||(LA20_0>='A' && LA20_0<='F')||(LA20_0>='a' && LA20_0<='f')) ) { + alt20=1; + } + + + switch (alt20) { + case 1 : + // Grammar/CTFLexer.g:136:45: HEX_DIGIT + { + mHEX_DIGIT(); + + } + break; + + default : + if ( cnt20 >= 1 ) break loop20; + EarlyExitException eee = + new EarlyExitException(20, input); + throw eee; + } + cnt20++; + } while (true); + + + } + + } + finally { + } + } + // $ANTLR end "HEXADECIMAL_ESCAPE" + + // $ANTLR start "UNICODE_ESCAPE" + public final void mUNICODE_ESCAPE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:141:25: ( BACKSLASH 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT | BACKSLASH 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ) + int alt21=2; + int LA21_0 = input.LA(1); + + if ( (LA21_0=='\\') ) { + int LA21_1 = input.LA(2); + + if ( (LA21_1=='u') ) { + alt21=1; + } + else if ( (LA21_1=='U') ) { + alt21=2; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 21, 1, input); + + throw nvae; + } + } + else { + NoViableAltException nvae = + new NoViableAltException("", 21, 0, input); + + throw nvae; + } + switch (alt21) { + case 1 : + // Grammar/CTFLexer.g:142:5: BACKSLASH 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + { + mBACKSLASH(); + match('u'); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + + } + break; + case 2 : + // Grammar/CTFLexer.g:143:5: BACKSLASH 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + { + mBACKSLASH(); + match('U'); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + mHEX_DIGIT(); + + } + break; + + } + } + finally { + } + } + // $ANTLR end "UNICODE_ESCAPE" + + // $ANTLR start "STRINGPREFIX" + public final void mSTRINGPREFIX() throws RecognitionException { + try { + // Grammar/CTFLexer.g:148:23: ( 'L' ) + // Grammar/CTFLexer.g:148:25: 'L' + { + match('L'); + + } + + } + finally { + } + } + // $ANTLR end "STRINGPREFIX" + + // $ANTLR start "CHARACTER_LITERAL" + public final void mCHARACTER_LITERAL() throws RecognitionException { + try { + int _type = CHARACTER_LITERAL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:153:19: ( ( STRINGPREFIX )? SINGLEQUOTE ( CHAR_CONTENT )+ SINGLEQUOTE ) + // Grammar/CTFLexer.g:153:21: ( STRINGPREFIX )? SINGLEQUOTE ( CHAR_CONTENT )+ SINGLEQUOTE + { + // Grammar/CTFLexer.g:153:21: ( STRINGPREFIX )? + int alt22=2; + int LA22_0 = input.LA(1); + + if ( (LA22_0=='L') ) { + alt22=1; + } + switch (alt22) { + case 1 : + // Grammar/CTFLexer.g:153:21: STRINGPREFIX + { + mSTRINGPREFIX(); + + } + break; + + } + + mSINGLEQUOTE(); + // Grammar/CTFLexer.g:153:47: ( CHAR_CONTENT )+ + int cnt23=0; + loop23: + do { + int alt23=2; + int LA23_0 = input.LA(1); + + if ( ((LA23_0>='\u0000' && LA23_0<='&')||(LA23_0>='(' && LA23_0<='\uFFFF')) ) { + alt23=1; + } + + + switch (alt23) { + case 1 : + // Grammar/CTFLexer.g:153:47: CHAR_CONTENT + { + mCHAR_CONTENT(); + + } + break; + + default : + if ( cnt23 >= 1 ) break loop23; + EarlyExitException eee = + new EarlyExitException(23, input); + throw eee; + } + cnt23++; + } while (true); + + mSINGLEQUOTE(); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "CHARACTER_LITERAL" + + // $ANTLR start "CHAR_CONTENT" + public final void mCHAR_CONTENT() throws RecognitionException { + try { + // Grammar/CTFLexer.g:154:23: ( ( ESCAPE_SEQUENCE | ~ ( BACKSLASH | SINGLEQUOTE ) ) ) + // Grammar/CTFLexer.g:154:25: ( ESCAPE_SEQUENCE | ~ ( BACKSLASH | SINGLEQUOTE ) ) + { + // Grammar/CTFLexer.g:154:25: ( ESCAPE_SEQUENCE | ~ ( BACKSLASH | SINGLEQUOTE ) ) + int alt24=2; + int LA24_0 = input.LA(1); + + if ( (LA24_0=='\\') ) { + alt24=1; + } + else if ( ((LA24_0>='\u0000' && LA24_0<='&')||(LA24_0>='(' && LA24_0<='[')||(LA24_0>=']' && LA24_0<='\uFFFF')) ) { + alt24=2; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 24, 0, input); + + throw nvae; + } + switch (alt24) { + case 1 : + // Grammar/CTFLexer.g:154:26: ESCAPE_SEQUENCE + { + mESCAPE_SEQUENCE(); + + } + break; + case 2 : + // Grammar/CTFLexer.g:154:44: ~ ( BACKSLASH | SINGLEQUOTE ) + { + if ( (input.LA(1)>='\u0000' && input.LA(1)<='&')||(input.LA(1)>='(' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + break; + + } + + + } + + } + finally { + } + } + // $ANTLR end "CHAR_CONTENT" + + // $ANTLR start "SINGLEQUOTE" + public final void mSINGLEQUOTE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:155:22: ( '\\'' ) + // Grammar/CTFLexer.g:155:24: '\\'' + { + match('\''); + + } + + } + finally { + } + } + // $ANTLR end "SINGLEQUOTE" + + // $ANTLR start "STRING_LITERAL" + public final void mSTRING_LITERAL() throws RecognitionException { + try { + int _type = STRING_LITERAL; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:160:16: ( ( STRINGPREFIX )? DOUBLEQUOTE ( STRING_CONTENT )* DOUBLEQUOTE ) + // Grammar/CTFLexer.g:160:18: ( STRINGPREFIX )? DOUBLEQUOTE ( STRING_CONTENT )* DOUBLEQUOTE + { + // Grammar/CTFLexer.g:160:18: ( STRINGPREFIX )? + int alt25=2; + int LA25_0 = input.LA(1); + + if ( (LA25_0=='L') ) { + alt25=1; + } + switch (alt25) { + case 1 : + // Grammar/CTFLexer.g:160:18: STRINGPREFIX + { + mSTRINGPREFIX(); + + } + break; + + } + + mDOUBLEQUOTE(); + // Grammar/CTFLexer.g:160:44: ( STRING_CONTENT )* + loop26: + do { + int alt26=2; + int LA26_0 = input.LA(1); + + if ( ((LA26_0>='\u0000' && LA26_0<='!')||(LA26_0>='#' && LA26_0<='\uFFFF')) ) { + alt26=1; + } + + + switch (alt26) { + case 1 : + // Grammar/CTFLexer.g:160:44: STRING_CONTENT + { + mSTRING_CONTENT(); + + } + break; + + default : + break loop26; + } + } while (true); + + mDOUBLEQUOTE(); + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "STRING_LITERAL" + + // $ANTLR start "STRING_CONTENT" + public final void mSTRING_CONTENT() throws RecognitionException { + try { + // Grammar/CTFLexer.g:161:25: ( ( ESCAPE_SEQUENCE | ~ ( BACKSLASH | DOUBLEQUOTE ) ) ) + // Grammar/CTFLexer.g:161:27: ( ESCAPE_SEQUENCE | ~ ( BACKSLASH | DOUBLEQUOTE ) ) + { + // Grammar/CTFLexer.g:161:27: ( ESCAPE_SEQUENCE | ~ ( BACKSLASH | DOUBLEQUOTE ) ) + int alt27=2; + int LA27_0 = input.LA(1); + + if ( (LA27_0=='\\') ) { + alt27=1; + } + else if ( ((LA27_0>='\u0000' && LA27_0<='!')||(LA27_0>='#' && LA27_0<='[')||(LA27_0>=']' && LA27_0<='\uFFFF')) ) { + alt27=2; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 27, 0, input); + + throw nvae; + } + switch (alt27) { + case 1 : + // Grammar/CTFLexer.g:161:28: ESCAPE_SEQUENCE + { + mESCAPE_SEQUENCE(); + + } + break; + case 2 : + // Grammar/CTFLexer.g:161:46: ~ ( BACKSLASH | DOUBLEQUOTE ) + { + if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + break; + + } + + + } + + } + finally { + } + } + // $ANTLR end "STRING_CONTENT" + + // $ANTLR start "DOUBLEQUOTE" + public final void mDOUBLEQUOTE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:162:22: ( '\"' ) + // Grammar/CTFLexer.g:162:24: '\"' + { + match('\"'); + + } + + } + finally { + } + } + // $ANTLR end "DOUBLEQUOTE" + + // $ANTLR start "WS" + public final void mWS() throws RecognitionException { + try { + int _type = WS; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:167:4: ( ( ' ' | '\\r' | '\\t' | '\\u000C' | '\\n' ) ) + // Grammar/CTFLexer.g:167:6: ( ' ' | '\\r' | '\\t' | '\\u000C' | '\\n' ) + { + if ( (input.LA(1)>='\t' && input.LA(1)<='\n')||(input.LA(1)>='\f' && input.LA(1)<='\r')||input.LA(1)==' ' ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + _channel=HIDDEN; + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "WS" + + // $ANTLR start "COMMENT" + public final void mCOMMENT() throws RecognitionException { + try { + int _type = COMMENT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:174:9: ( COMMENT_OPEN ( . )* COMMENT_CLOSE ) + // Grammar/CTFLexer.g:174:11: COMMENT_OPEN ( . )* COMMENT_CLOSE + { + mCOMMENT_OPEN(); + // Grammar/CTFLexer.g:174:24: ( . )* + loop28: + do { + int alt28=2; + int LA28_0 = input.LA(1); + + if ( (LA28_0=='*') ) { + int LA28_1 = input.LA(2); + + if ( (LA28_1=='/') ) { + alt28=2; + } + else if ( ((LA28_1>='\u0000' && LA28_1<='.')||(LA28_1>='0' && LA28_1<='\uFFFF')) ) { + alt28=1; + } + + + } + else if ( ((LA28_0>='\u0000' && LA28_0<=')')||(LA28_0>='+' && LA28_0<='\uFFFF')) ) { + alt28=1; + } + + + switch (alt28) { + case 1 : + // Grammar/CTFLexer.g:174:24: . + { + matchAny(); + + } + break; + + default : + break loop28; + } + } while (true); + + mCOMMENT_CLOSE(); + _channel = HIDDEN; + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "COMMENT" + + // $ANTLR start "COMMENT_OPEN" + public final void mCOMMENT_OPEN() throws RecognitionException { + try { + // Grammar/CTFLexer.g:175:23: ( '/*' ) + // Grammar/CTFLexer.g:175:25: '/*' + { + match("/*"); + + + } + + } + finally { + } + } + // $ANTLR end "COMMENT_OPEN" + + // $ANTLR start "COMMENT_CLOSE" + public final void mCOMMENT_CLOSE() throws RecognitionException { + try { + // Grammar/CTFLexer.g:176:24: ( '*/' ) + // Grammar/CTFLexer.g:176:26: '*/' + { + match("*/"); + + + } + + } + finally { + } + } + // $ANTLR end "COMMENT_CLOSE" + + // $ANTLR start "LINE_COMMENT" + public final void mLINE_COMMENT() throws RecognitionException { + try { + int _type = LINE_COMMENT; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:181:14: ( '//' (~ ( '\\n' | '\\r' ) )* ( '\\r' )? '\\n' ) + // Grammar/CTFLexer.g:181:16: '//' (~ ( '\\n' | '\\r' ) )* ( '\\r' )? '\\n' + { + match("//"); + + // Grammar/CTFLexer.g:181:21: (~ ( '\\n' | '\\r' ) )* + loop29: + do { + int alt29=2; + int LA29_0 = input.LA(1); + + if ( ((LA29_0>='\u0000' && LA29_0<='\t')||(LA29_0>='\u000B' && LA29_0<='\f')||(LA29_0>='\u000E' && LA29_0<='\uFFFF')) ) { + alt29=1; + } + + + switch (alt29) { + case 1 : + // Grammar/CTFLexer.g:181:21: ~ ( '\\n' | '\\r' ) + { + if ( (input.LA(1)>='\u0000' && input.LA(1)<='\t')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='\uFFFF') ) { + input.consume(); + + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + recover(mse); + throw mse;} + + + } + break; + + default : + break loop29; + } + } while (true); + + // Grammar/CTFLexer.g:181:35: ( '\\r' )? + int alt30=2; + int LA30_0 = input.LA(1); + + if ( (LA30_0=='\r') ) { + alt30=1; + } + switch (alt30) { + case 1 : + // Grammar/CTFLexer.g:181:35: '\\r' + { + match('\r'); + + } + break; + + } + + match('\n'); + _channel=HIDDEN; + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "LINE_COMMENT" + + // $ANTLR start "IDENTIFIER" + public final void mIDENTIFIER() throws RecognitionException { + try { + int _type = IDENTIFIER; + int _channel = DEFAULT_TOKEN_CHANNEL; + // Grammar/CTFLexer.g:186:12: ( NONDIGIT ( NONDIGIT | DIGIT )* ) + // Grammar/CTFLexer.g:186:14: NONDIGIT ( NONDIGIT | DIGIT )* + { + mNONDIGIT(); + // Grammar/CTFLexer.g:186:23: ( NONDIGIT | DIGIT )* + loop31: + do { + int alt31=3; + int LA31_0 = input.LA(1); + + if ( ((LA31_0>='A' && LA31_0<='Z')||LA31_0=='_'||(LA31_0>='a' && LA31_0<='z')) ) { + alt31=1; + } + else if ( ((LA31_0>='0' && LA31_0<='9')) ) { + alt31=2; + } + + + switch (alt31) { + case 1 : + // Grammar/CTFLexer.g:186:24: NONDIGIT + { + mNONDIGIT(); + + } + break; + case 2 : + // Grammar/CTFLexer.g:186:35: DIGIT + { + mDIGIT(); + + } + break; + + default : + break loop31; + } + } while (true); + + + } + + state.type = _type; + state.channel = _channel; + } + finally { + } + } + // $ANTLR end "IDENTIFIER" + + // $ANTLR start "NONDIGIT" + public final void mNONDIGIT() throws RecognitionException { + try { + // Grammar/CTFLexer.g:187:19: ( ( '_' ) | ( 'A' .. 'Z' ) | ( 'a' .. 'z' ) ) + int alt32=3; + switch ( input.LA(1) ) { + case '_': + { + alt32=1; + } + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + { + alt32=2; + } + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + { + alt32=3; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 32, 0, input); + + throw nvae; + } + + switch (alt32) { + case 1 : + // Grammar/CTFLexer.g:187:21: ( '_' ) + { + // Grammar/CTFLexer.g:187:21: ( '_' ) + // Grammar/CTFLexer.g:187:22: '_' + { + match('_'); + + } + + + } + break; + case 2 : + // Grammar/CTFLexer.g:187:29: ( 'A' .. 'Z' ) + { + // Grammar/CTFLexer.g:187:29: ( 'A' .. 'Z' ) + // Grammar/CTFLexer.g:187:30: 'A' .. 'Z' + { + matchRange('A','Z'); + + } + + + } + break; + case 3 : + // Grammar/CTFLexer.g:187:42: ( 'a' .. 'z' ) + { + // Grammar/CTFLexer.g:187:42: ( 'a' .. 'z' ) + // Grammar/CTFLexer.g:187:43: 'a' .. 'z' + { + matchRange('a','z'); + + } + + + } + break; + + } + } + finally { + } + } + // $ANTLR end "NONDIGIT" + + @Override + public void mTokens() throws RecognitionException { + // Grammar/CTFLexer.g:1:8: ( ALIGNTOK | CONSTTOK | CHARTOK | DOUBLETOK | ENUMTOK | EVENTTOK | FLOATINGPOINTTOK | FLOATTOK | INTEGERTOK | INTTOK | LONGTOK | SHORTTOK | SIGNEDTOK | STREAMTOK | STRINGTOK | STRUCTTOK | TRACETOK | TYPEALIASTOK | TYPEDEFTOK | UNSIGNEDTOK | VARIANTTOK | VOIDTOK | BOOLTOK | COMPLEXTOK | IMAGINARYTOK | ENVTOK | CLOCKTOK | NANNUMBERTOK | INFINITYTOK | NINFINITYTOK | SEPARATOR | COLON | ELIPSES | ASSIGNMENT | TYPE_ASSIGNMENT | LT | GT | OPENBRAC | CLOSEBRAC | LPAREN | RPAREN | LCURL | RCURL | TERM | POINTER | SIGN | ARROW | DOT | OCTAL_LITERAL | DECIMAL_LITERAL | HEX_LITERAL | CHARACTER_LITERAL | STRING_LITERAL | WS | COMMENT | LINE_COMMENT | IDENTIFIER ) + int alt33=57; + alt33 = dfa33.predict(input); + switch (alt33) { + case 1 : + // Grammar/CTFLexer.g:1:10: ALIGNTOK + { + mALIGNTOK(); + + } + break; + case 2 : + // Grammar/CTFLexer.g:1:19: CONSTTOK + { + mCONSTTOK(); + + } + break; + case 3 : + // Grammar/CTFLexer.g:1:28: CHARTOK + { + mCHARTOK(); + + } + break; + case 4 : + // Grammar/CTFLexer.g:1:36: DOUBLETOK + { + mDOUBLETOK(); + + } + break; + case 5 : + // Grammar/CTFLexer.g:1:46: ENUMTOK + { + mENUMTOK(); + + } + break; + case 6 : + // Grammar/CTFLexer.g:1:54: EVENTTOK + { + mEVENTTOK(); + + } + break; + case 7 : + // Grammar/CTFLexer.g:1:63: FLOATINGPOINTTOK + { + mFLOATINGPOINTTOK(); + + } + break; + case 8 : + // Grammar/CTFLexer.g:1:80: FLOATTOK + { + mFLOATTOK(); + + } + break; + case 9 : + // Grammar/CTFLexer.g:1:89: INTEGERTOK + { + mINTEGERTOK(); + + } + break; + case 10 : + // Grammar/CTFLexer.g:1:100: INTTOK + { + mINTTOK(); + + } + break; + case 11 : + // Grammar/CTFLexer.g:1:107: LONGTOK + { + mLONGTOK(); + + } + break; + case 12 : + // Grammar/CTFLexer.g:1:115: SHORTTOK + { + mSHORTTOK(); + + } + break; + case 13 : + // Grammar/CTFLexer.g:1:124: SIGNEDTOK + { + mSIGNEDTOK(); + + } + break; + case 14 : + // Grammar/CTFLexer.g:1:134: STREAMTOK + { + mSTREAMTOK(); + + } + break; + case 15 : + // Grammar/CTFLexer.g:1:144: STRINGTOK + { + mSTRINGTOK(); + + } + break; + case 16 : + // Grammar/CTFLexer.g:1:154: STRUCTTOK + { + mSTRUCTTOK(); + + } + break; + case 17 : + // Grammar/CTFLexer.g:1:164: TRACETOK + { + mTRACETOK(); + + } + break; + case 18 : + // Grammar/CTFLexer.g:1:173: TYPEALIASTOK + { + mTYPEALIASTOK(); + + } + break; + case 19 : + // Grammar/CTFLexer.g:1:186: TYPEDEFTOK + { + mTYPEDEFTOK(); + + } + break; + case 20 : + // Grammar/CTFLexer.g:1:197: UNSIGNEDTOK + { + mUNSIGNEDTOK(); + + } + break; + case 21 : + // Grammar/CTFLexer.g:1:209: VARIANTTOK + { + mVARIANTTOK(); + + } + break; + case 22 : + // Grammar/CTFLexer.g:1:220: VOIDTOK + { + mVOIDTOK(); + + } + break; + case 23 : + // Grammar/CTFLexer.g:1:228: BOOLTOK + { + mBOOLTOK(); + + } + break; + case 24 : + // Grammar/CTFLexer.g:1:236: COMPLEXTOK + { + mCOMPLEXTOK(); + + } + break; + case 25 : + // Grammar/CTFLexer.g:1:247: IMAGINARYTOK + { + mIMAGINARYTOK(); + + } + break; + case 26 : + // Grammar/CTFLexer.g:1:260: ENVTOK + { + mENVTOK(); + + } + break; + case 27 : + // Grammar/CTFLexer.g:1:267: CLOCKTOK + { + mCLOCKTOK(); + + } + break; + case 28 : + // Grammar/CTFLexer.g:1:276: NANNUMBERTOK + { + mNANNUMBERTOK(); + + } + break; + case 29 : + // Grammar/CTFLexer.g:1:289: INFINITYTOK + { + mINFINITYTOK(); + + } + break; + case 30 : + // Grammar/CTFLexer.g:1:301: NINFINITYTOK + { + mNINFINITYTOK(); + + } + break; + case 31 : + // Grammar/CTFLexer.g:1:314: SEPARATOR + { + mSEPARATOR(); + + } + break; + case 32 : + // Grammar/CTFLexer.g:1:324: COLON + { + mCOLON(); + + } + break; + case 33 : + // Grammar/CTFLexer.g:1:330: ELIPSES + { + mELIPSES(); + + } + break; + case 34 : + // Grammar/CTFLexer.g:1:338: ASSIGNMENT + { + mASSIGNMENT(); + + } + break; + case 35 : + // Grammar/CTFLexer.g:1:349: TYPE_ASSIGNMENT + { + mTYPE_ASSIGNMENT(); + + } + break; + case 36 : + // Grammar/CTFLexer.g:1:365: LT + { + mLT(); + + } + break; + case 37 : + // Grammar/CTFLexer.g:1:368: GT + { + mGT(); + + } + break; + case 38 : + // Grammar/CTFLexer.g:1:371: OPENBRAC + { + mOPENBRAC(); + + } + break; + case 39 : + // Grammar/CTFLexer.g:1:380: CLOSEBRAC + { + mCLOSEBRAC(); + + } + break; + case 40 : + // Grammar/CTFLexer.g:1:390: LPAREN + { + mLPAREN(); + + } + break; + case 41 : + // Grammar/CTFLexer.g:1:397: RPAREN + { + mRPAREN(); + + } + break; + case 42 : + // Grammar/CTFLexer.g:1:404: LCURL + { + mLCURL(); + + } + break; + case 43 : + // Grammar/CTFLexer.g:1:410: RCURL + { + mRCURL(); + + } + break; + case 44 : + // Grammar/CTFLexer.g:1:416: TERM + { + mTERM(); + + } + break; + case 45 : + // Grammar/CTFLexer.g:1:421: POINTER + { + mPOINTER(); + + } + break; + case 46 : + // Grammar/CTFLexer.g:1:429: SIGN + { + mSIGN(); + + } + break; + case 47 : + // Grammar/CTFLexer.g:1:434: ARROW + { + mARROW(); + + } + break; + case 48 : + // Grammar/CTFLexer.g:1:440: DOT + { + mDOT(); + + } + break; + case 49 : + // Grammar/CTFLexer.g:1:444: OCTAL_LITERAL + { + mOCTAL_LITERAL(); + + } + break; + case 50 : + // Grammar/CTFLexer.g:1:458: DECIMAL_LITERAL + { + mDECIMAL_LITERAL(); + + } + break; + case 51 : + // Grammar/CTFLexer.g:1:474: HEX_LITERAL + { + mHEX_LITERAL(); + + } + break; + case 52 : + // Grammar/CTFLexer.g:1:486: CHARACTER_LITERAL + { + mCHARACTER_LITERAL(); + + } + break; + case 53 : + // Grammar/CTFLexer.g:1:504: STRING_LITERAL + { + mSTRING_LITERAL(); + + } + break; + case 54 : + // Grammar/CTFLexer.g:1:519: WS + { + mWS(); + + } + break; + case 55 : + // Grammar/CTFLexer.g:1:522: COMMENT + { + mCOMMENT(); + + } + break; + case 56 : + // Grammar/CTFLexer.g:1:530: LINE_COMMENT + { + mLINE_COMMENT(); + + } + break; + case 57 : + // Grammar/CTFLexer.g:1:543: IDENTIFIER + { + mIDENTIFIER(); + + } + break; + + } + + } + + + protected DFA17 dfa17 = new DFA17(this); + protected DFA33 dfa33 = new DFA33(this); + static final String DFA17_eotS = + "\1\uffff\2\5\1\11\1\5\2\uffff\1\5\2\uffff"; + static final String DFA17_eofS = + "\12\uffff"; + static final String DFA17_minS = + "\1\114\1\125\2\114\1\125\2\uffff\1\125\2\uffff"; + static final String DFA17_maxS = + "\3\165\1\154\1\165\2\uffff\1\165\2\uffff"; + static final String DFA17_acceptS = + "\5\uffff\1\1\1\4\1\uffff\1\3\1\2"; + static final String DFA17_specialS = + "\12\uffff}>"; + static final String[] DFA17_transitionS = { + "\1\2\10\uffff\1\3\26\uffff\1\1\10\uffff\1\3", + "\1\6\26\uffff\1\4\10\uffff\1\6", + "\1\7\10\uffff\1\6\37\uffff\1\6", + "\1\10\37\uffff\1\10", + "\1\6\37\uffff\1\6", + "", + "", + "\1\6\37\uffff\1\6", + "", + "" + }; + + static final short[] DFA17_eot = DFA.unpackEncodedString(DFA17_eotS); + static final short[] DFA17_eof = DFA.unpackEncodedString(DFA17_eofS); + static final char[] DFA17_min = DFA.unpackEncodedStringToUnsignedChars(DFA17_minS); + static final char[] DFA17_max = DFA.unpackEncodedStringToUnsignedChars(DFA17_maxS); + static final short[] DFA17_accept = DFA.unpackEncodedString(DFA17_acceptS); + static final short[] DFA17_special = DFA.unpackEncodedString(DFA17_specialS); + static final short[][] DFA17_transition; + + static { + int numStates = DFA17_transitionS.length; + DFA17_transition = new short[numStates][]; + for (int i=0; i"; + static final String[] DFA33_transitionS = { + "\2\43\1\uffff\2\43\22\uffff\1\43\1\uffff\1\42\4\uffff\1\41\1"+ + "\30\1\31\1\35\1\16\1\20\1\17\1\22\1\44\1\36\11\37\1\21\1\34"+ + "\1\24\1\23\1\25\2\uffff\13\45\1\40\1\45\1\15\14\45\1\26\1\uffff"+ + "\1\27\1\uffff\1\14\1\uffff\1\1\1\45\1\2\1\3\1\4\1\5\2\45\1\6"+ + "\2\45\1\7\6\45\1\10\1\11\1\12\1\13\4\45\1\32\1\uffff\1\33", + "\1\46", + "\1\50\3\uffff\1\51\2\uffff\1\47", + "\1\52", + "\1\53\7\uffff\1\54", + "\1\55", + "\1\56", + "\1\57", + "\1\60\1\61\12\uffff\1\62", + "\1\63\6\uffff\1\64", + "\1\65", + "\1\66\15\uffff\1\67", + "\1\70\1\71\5\uffff\1\72", + "\1\73", + "\1\74", + "\1\77\52\uffff\1\76", + "", + "\1\100", + "\1\102", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "\10\105\40\uffff\1\104\37\uffff\1\104", + "", + "\1\42\4\uffff\1\41", + "", + "", + "", + "\1\106\4\uffff\1\107", + "", + "\1\110", + "\1\111", + "\1\112", + "\1\113", + "\1\114", + "\1\115\1\116", + "\1\117", + "\1\120", + "\1\121", + "\1\122", + "\1\123", + "\1\124", + "\1\125", + "\1\126", + "\1\127", + "\1\130", + "\1\131", + "\1\132", + "\1\133", + "\1\134", + "\1\135", + "\1\136", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "\10\105\2\37\22\uffff\1\141\10\uffff\1\142\26\uffff\1\140\10"+ + "\uffff\1\142", + "", + "", + "\1\143", + "\1\144", + "\1\145", + "\1\146", + "\1\147", + "\1\150", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\152", + "\1\153", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\4\45\1\154\25\45", + "\1\156", + "\1\157", + "\1\160", + "\1\161\3\uffff\1\162\13\uffff\1\163", + "\1\164", + "\1\165", + "\1\166", + "\1\167", + "\1\170", + "\1\171", + "\1\172", + "\1\173", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "\1\176\26\uffff\1\175\10\uffff\1\176", + "\1\177\10\uffff\1\176\37\uffff\1\176", + "\1\u0081\37\uffff\1\u0080", + "\1\u0082", + "\1\u0083", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u0085", + "\1\u0086", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "\1\u0088", + "\1\u0089", + "\1\u008a", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u008c", + "\1\u008d", + "\1\u008e", + "\1\u008f", + "\1\u0090", + "\1\u0091", + "\1\u0092\2\uffff\1\u0093", + "\1\u0094", + "\1\u0095", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u0097", + "\1\u0098", + "\1\u0099", + "", + "\1\176\37\uffff\1\176", + "", + "\1\176\37\uffff\1\176", + "\1\u009a", + "\1\u009b", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u009f", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\10\45\1\u00a1\21"+ + "\45", + "\1\u00a3", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00a5", + "\1\u00a6", + "\1\u00a7", + "\1\u00a8", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00aa", + "\1\u00ab", + "\1\u00ac", + "\1\u00ad", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00af", + "\1\u00b0", + "", + "", + "", + "", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "\1\u00b2", + "", + "\1\u00b3", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "\1\u00b8", + "\1\u00b9", + "\1\u00ba", + "\1\u00bb", + "", + "\1\u00bc", + "\1\u00bd", + "", + "\1\u00be", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "", + "", + "", + "\1\u00c0", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00c2", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00c4", + "\1\u00c5", + "\1\u00c6", + "", + "\1\u00c7", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00ca", + "\1\u00cb", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "", + "", + "\1\u00cd", + "\1\u00ce", + "", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "\1\u00d0", + "", + "\1\u00d1", + "\1\u00d2", + "\12\45\7\uffff\32\45\4\uffff\1\45\1\uffff\32\45", + "" + }; + + static final short[] DFA33_eot = DFA.unpackEncodedString(DFA33_eotS); + static final short[] DFA33_eof = DFA.unpackEncodedString(DFA33_eofS); + static final char[] DFA33_min = DFA.unpackEncodedStringToUnsignedChars(DFA33_minS); + static final char[] DFA33_max = DFA.unpackEncodedStringToUnsignedChars(DFA33_maxS); + static final short[] DFA33_accept = DFA.unpackEncodedString(DFA33_acceptS); + static final short[] DFA33_special = DFA.unpackEncodedString(DFA33_specialS); + static final short[][] DFA33_transition; + + static { + int numStates = DFA33_transitionS.length; + DFA33_transition = new short[numStates][]; + for (int i=0; i", "", "", "", "ALIGNTOK", "CONSTTOK", "CHARTOK", "DOUBLETOK", "ENUMTOK", "EVENTTOK", "FLOATINGPOINTTOK", "FLOATTOK", "INTEGERTOK", "INTTOK", "LONGTOK", "SHORTTOK", "SIGNEDTOK", "STREAMTOK", "STRINGTOK", "STRUCTTOK", "TRACETOK", "TYPEALIASTOK", "TYPEDEFTOK", "UNSIGNEDTOK", "VARIANTTOK", "VOIDTOK", "BOOLTOK", "COMPLEXTOK", "IMAGINARYTOK", "ENVTOK", "CLOCKTOK", "NANNUMBERTOK", "INFINITYTOK", "NINFINITYTOK", "SEPARATOR", "COLON", "ELIPSES", "ASSIGNMENT", "TYPE_ASSIGNMENT", "LT", "GT", "OPENBRAC", "CLOSEBRAC", "LPAREN", "RPAREN", "LCURL", "RCURL", "TERM", "POINTER", "SIGN", "ARROW", "DOT", "BACKSLASH", "INTEGER_TYPES_SUFFIX", "OCTAL_LITERAL", "DIGIT", "DECIMAL_LITERAL", "HEX_PREFIX", "HEX_DIGIT", "HEX_LITERAL", "NONZERO_DIGIT", "OCTAL_ESCAPE", "UNICODE_ESCAPE", "HEXADECIMAL_ESCAPE", "ESCAPE_SEQUENCE", "STRINGPREFIX", "SINGLEQUOTE", "CHAR_CONTENT", "CHARACTER_LITERAL", "DOUBLEQUOTE", "STRING_CONTENT", "STRING_LITERAL", "WS", "COMMENT_OPEN", "COMMENT_CLOSE", "COMMENT", "LINE_COMMENT", "NONDIGIT", "IDENTIFIER", "ROOT", "EVENT", "STREAM", "TRACE", "ENV", "CLOCK", "DECLARATION", "SV_DECLARATION", "TYPE_SPECIFIER_LIST", "TYPE_DECLARATOR_LIST", "TYPE_DECLARATOR", "STRUCT", "STRUCT_NAME", "STRUCT_BODY", "ALIGN", "CTF_EXPRESSION_TYPE", "CTF_EXPRESSION_VAL", "CTF_LEFT", "CTF_RIGHT", "UNARY_EXPRESSION_STRING", "UNARY_EXPRESSION_STRING_QUOTES", "UNARY_EXPRESSION_DEC", "UNARY_EXPRESSION_HEX", "UNARY_EXPRESSION_OCT", "LENGTH", "TYPEDEF", "TYPEALIAS", "TYPEALIAS_TARGET", "TYPEALIAS_ALIAS", "INTEGER", "STRING", "FLOATING_POINT", "ENUM", "ENUM_CONTAINER_TYPE", "ENUM_ENUMERATOR", "ENUM_NAME", "ENUM_VALUE", "ENUM_VALUE_RANGE", "ENUM_BODY", "VARIANT", "VARIANT_NAME", "VARIANT_TAG", "VARIANT_BODY", "DECLARATOR" + }; + public static final int SIGN=49; + public static final int LT=39; + public static final int TYPEDEFTOK=22; + public static final int VARIANT_NAME=119; + public static final int ENV=83; + public static final int INTEGER_TYPES_SUFFIX=53; + public static final int POINTER=48; + public static final int TRACE=82; + public static final int HEX_PREFIX=57; + public static final int INTTOK=13; + public static final int SEPARATOR=34; + public static final int ENUMTOK=8; + public static final int COMPLEXTOK=27; + public static final int IMAGINARYTOK=28; + public static final int STREAMTOK=17; + public static final int EOF=-1; + public static final int UNARY_EXPRESSION_OCT=102; + public static final int ENUM_VALUE=115; + public static final int UNSIGNEDTOK=23; + public static final int ENUM_NAME=114; + public static final int RPAREN=44; + public static final int CHAR_CONTENT=67; + public static final int STRING_LITERAL=71; + public static final int UNARY_EXPRESSION_STRING_QUOTES=99; + public static final int ALIGNTOK=4; + public static final int FLOATTOK=11; + public static final int STRUCT_BODY=92; + public static final int ENUM_BODY=117; + public static final int COMMENT_CLOSE=74; + public static final int STRINGTOK=18; + public static final int COMMENT=75; + public static final int STREAM=81; + public static final int UNARY_EXPRESSION_HEX=101; + public static final int UNARY_EXPRESSION_DEC=100; + public static final int FLOATINGPOINTTOK=10; + public static final int LINE_COMMENT=76; + public static final int CTF_EXPRESSION_TYPE=94; + public static final int DOUBLETOK=7; + public static final int TYPE_DECLARATOR=89; + public static final int CHARACTER_LITERAL=68; + public static final int OCTAL_ESCAPE=61; + public static final int STRUCT_NAME=91; + public static final int VARIANT=118; + public static final int NANNUMBERTOK=31; + public static final int ENUM_ENUMERATOR=113; + public static final int FLOATING_POINT=110; + public static final int DECLARATOR=122; + public static final int SIGNEDTOK=16; + public static final int CHARTOK=6; + public static final int WS=72; + public static final int INTEGERTOK=12; + public static final int VARIANT_BODY=121; + public static final int NONDIGIT=77; + public static final int GT=40; + public static final int TYPEALIAS_TARGET=106; + public static final int DECIMAL_LITERAL=56; + public static final int BACKSLASH=52; + public static final int CLOSEBRAC=42; + public static final int TERM=47; + public static final int BOOLTOK=26; + public static final int CTF_RIGHT=97; + public static final int TYPE_DECLARATOR_LIST=88; + public static final int STRING_CONTENT=70; + public static final int TYPE_ASSIGNMENT=38; + public static final int ENUM_CONTAINER_TYPE=112; + public static final int DOUBLEQUOTE=69; + public static final int ENUM_VALUE_RANGE=116; + public static final int DECLARATION=85; + public static final int LENGTH=103; + public static final int LPAREN=43; + public static final int INFINITYTOK=32; + public static final int STRINGPREFIX=65; + public static final int CTF_EXPRESSION_VAL=95; + public static final int ESCAPE_SEQUENCE=64; + public static final int UNICODE_ESCAPE=62; + public static final int SINGLEQUOTE=66; + public static final int IDENTIFIER=78; + public static final int HEX_LITERAL=59; + public static final int ALIGN=93; + public static final int DIGIT=55; + public static final int DOT=51; + public static final int ENVTOK=29; + public static final int STRUCTTOK=19; + public static final int OPENBRAC=41; + public static final int TYPEALIASTOK=21; + public static final int CLOCK=84; + public static final int INTEGER=108; + public static final int TYPEALIAS=105; + public static final int EVENTTOK=9; + public static final int NINFINITYTOK=33; + public static final int TYPEDEF=104; + public static final int VOIDTOK=25; + public static final int TYPE_SPECIFIER_LIST=87; + public static final int OCTAL_LITERAL=54; + public static final int COMMENT_OPEN=73; + public static final int HEX_DIGIT=58; + public static final int STRUCT=90; + public static final int EVENT=80; + public static final int LONGTOK=14; + public static final int ROOT=79; + public static final int CTF_LEFT=96; + public static final int CLOCKTOK=30; + public static final int TRACETOK=20; + public static final int COLON=35; + public static final int HEXADECIMAL_ESCAPE=63; + public static final int LCURL=45; + public static final int VARIANTTOK=24; + public static final int VARIANT_TAG=120; + public static final int ENUM=111; + public static final int ELIPSES=36; + public static final int RCURL=46; + public static final int TYPEALIAS_ALIAS=107; + public static final int UNARY_EXPRESSION_STRING=98; + public static final int ARROW=50; + public static final int ASSIGNMENT=37; + public static final int SHORTTOK=15; + public static final int SV_DECLARATION=86; + public static final int NONZERO_DIGIT=60; + public static final int CONSTTOK=5; + public static final int STRING=109; + + // delegates + // delegators + + protected static class Symbols_scope { + Set types; + } + protected Stack Symbols_stack = new Stack(); + + + public CTFParser(TokenStream input) { + this(input, new RecognizerSharedState()); + } + public CTFParser(TokenStream input, RecognizerSharedState state) { + super(input, state); + + } + + protected TreeAdaptor adaptor = new CommonTreeAdaptor(); + + public void setTreeAdaptor(TreeAdaptor adaptor) { + this.adaptor = adaptor; + } + public TreeAdaptor getTreeAdaptor() { + return adaptor; + } + + @Override + public String[] getTokenNames() { return CTFParser.tokenNames; } + @Override + public String getGrammarFileName() { return "Grammar/CTFParser.g"; } + + + public CTFParser(TokenStream input, boolean verbose) { + this(input); + this.verbose = verbose; + } + + /* To disable automatic error recovery. When we have a mismatched token, simply throw an exception. */ + @Override + protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException + { + throw new MismatchedTokenException(ttype, input); + } + + /** + * Checks if a given name has been defined has a type. + * From: http://www.antlr.org/grammar/1153358328744/C.g + * + * @param name The name to check. + * @return True if is is a type, false otherwise. + */ + boolean isTypeName(String name) { + for (int i = Symbols_stack.size() - 1; i >= 0; i--) { + Symbols_scope scope = (Symbols_scope)Symbols_stack.get(i); + if (scope.types.contains(name)) { + return true; + } + } + return false; + } + + void addTypeName(String name) { + ((Symbols_scope)Symbols_stack.peek()).types.add(name); + if (verbose) { + debug_print("New type: " + name); + } + } + + boolean _inTypedef = false; + + void typedefOn() { + debug_print("typedefOn"); + _inTypedef = true; + } + + void typedefOff() { + debug_print("typedefOff"); + _inTypedef = false; + } + + boolean inTypedef() { + return _inTypedef; + } + + boolean _inTypealiasAlias = false; + + void typealiasAliasOn() { + debug_print("typealiasAliasOn"); + _inTypealiasAlias = true; + } + + void typealiasAliasOff() { + debug_print("typealiasAliasOff"); + _inTypealiasAlias = false; + } + + boolean inTypealiasAlias() { + return _inTypealiasAlias; + } + + void print_tabs(int n) { + for (int i = 0; i < n; i++) { + System.out.print(" "); + } + } + + void enter(String name) { + if (verbose) { + if (state.backtracking == 0) { + print_tabs(depth); + debug_print("+ " + name); + depth++; + } + } + } + + void exit(String name) { + if (verbose) { + depth--; + print_tabs(depth); + debug_print("- " + name); + } + } + + void debug_print(String str) { + if (verbose) { + System.out.println(str); + } + } + + int depth = 0; + + /* Prints rule entry and exit while parsing */ + boolean verbose = false; + + + public static class parse_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "parse" + // Grammar/CTFParser.g:198:1: parse : ( declaration )+ EOF -> ^( ROOT ( declaration )+ ) ; + public final CTFParser.parse_return parse() throws RecognitionException { + Symbols_stack.push(new Symbols_scope()); + + CTFParser.parse_return retval = new CTFParser.parse_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token EOF2=null; + CTFParser.declaration_return declaration1 = null; + + + CommonTree EOF2_tree=null; + RewriteRuleTokenStream stream_EOF=new RewriteRuleTokenStream(adaptor,"token EOF"); + RewriteRuleSubtreeStream stream_declaration=new RewriteRuleSubtreeStream(adaptor,"rule declaration"); + + enter("parse"); + debug_print("Scope push " + Symbols_stack.size()); + ((Symbols_scope)Symbols_stack.peek()).types = new HashSet(); + + try { + // Grammar/CTFParser.g:211:1: ( ( declaration )+ EOF -> ^( ROOT ( declaration )+ ) ) + // Grammar/CTFParser.g:212:3: ( declaration )+ EOF + { + // Grammar/CTFParser.g:212:3: ( declaration )+ + int cnt1=0; + loop1: + do { + int alt1=2; + int LA1_0 = input.LA(1); + + if ( ((LA1_0>=CONSTTOK && LA1_0<=ENUMTOK)||(LA1_0>=FLOATINGPOINTTOK && LA1_0<=SIGNEDTOK)||(LA1_0>=STRINGTOK && LA1_0<=STRUCTTOK)||(LA1_0>=TYPEDEFTOK && LA1_0<=IMAGINARYTOK)) ) { + alt1=1; + } + else if ( (LA1_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt1=1; + } + else if ( (LA1_0==EVENTTOK||LA1_0==STREAMTOK||(LA1_0>=TRACETOK && LA1_0<=TYPEALIASTOK)||(LA1_0>=ENVTOK && LA1_0<=CLOCKTOK)) ) { + alt1=1; + } + + + switch (alt1) { + case 1 : + // Grammar/CTFParser.g:212:3: declaration + { + pushFollow(FOLLOW_declaration_in_parse321); + declaration1=declaration(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declaration.add(declaration1.getTree()); + + } + break; + + default : + if ( cnt1 >= 1 ) break loop1; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(1, input); + throw eee; + } + cnt1++; + } while (true); + + EOF2=(Token)match(input,EOF,FOLLOW_EOF_in_parse324); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_EOF.add(EOF2); + + + + // AST REWRITE + // elements: declaration + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 212:20: -> ^( ROOT ( declaration )+ ) + { + // Grammar/CTFParser.g:212:23: ^( ROOT ( declaration )+ ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ROOT, "ROOT"), root_1); + + if ( !(stream_declaration.hasNext()) ) { + throw new RewriteEarlyExitException(); + } + while ( stream_declaration.hasNext() ) { + adaptor.addChild(root_1, stream_declaration.nextTree()); + + } + stream_declaration.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print("Scope pop " + Symbols_stack.size()); + exit("parse"); + + debug_print("Final depth, should be 0: " + depth); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + Symbols_stack.pop(); + + } + return retval; + } + // $ANTLR end "parse" + + public static class numberLiteral_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "numberLiteral" + // Grammar/CTFParser.g:215:1: numberLiteral : ( SIGN )* ( HEX_LITERAL -> ^( UNARY_EXPRESSION_HEX HEX_LITERAL ( SIGN )* ) | DECIMAL_LITERAL -> ^( UNARY_EXPRESSION_DEC DECIMAL_LITERAL ( SIGN )* ) | OCTAL_LITERAL -> ^( UNARY_EXPRESSION_OCT OCTAL_LITERAL ( SIGN )* ) ) ; + public final CTFParser.numberLiteral_return numberLiteral() throws RecognitionException { + CTFParser.numberLiteral_return retval = new CTFParser.numberLiteral_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token SIGN3=null; + Token HEX_LITERAL4=null; + Token DECIMAL_LITERAL5=null; + Token OCTAL_LITERAL6=null; + + CommonTree SIGN3_tree=null; + CommonTree HEX_LITERAL4_tree=null; + CommonTree DECIMAL_LITERAL5_tree=null; + CommonTree OCTAL_LITERAL6_tree=null; + RewriteRuleTokenStream stream_SIGN=new RewriteRuleTokenStream(adaptor,"token SIGN"); + RewriteRuleTokenStream stream_OCTAL_LITERAL=new RewriteRuleTokenStream(adaptor,"token OCTAL_LITERAL"); + RewriteRuleTokenStream stream_HEX_LITERAL=new RewriteRuleTokenStream(adaptor,"token HEX_LITERAL"); + RewriteRuleTokenStream stream_DECIMAL_LITERAL=new RewriteRuleTokenStream(adaptor,"token DECIMAL_LITERAL"); + + + enter("numberLiteral"); + + try { + // Grammar/CTFParser.g:223:1: ( ( SIGN )* ( HEX_LITERAL -> ^( UNARY_EXPRESSION_HEX HEX_LITERAL ( SIGN )* ) | DECIMAL_LITERAL -> ^( UNARY_EXPRESSION_DEC DECIMAL_LITERAL ( SIGN )* ) | OCTAL_LITERAL -> ^( UNARY_EXPRESSION_OCT OCTAL_LITERAL ( SIGN )* ) ) ) + // Grammar/CTFParser.g:224:3: ( SIGN )* ( HEX_LITERAL -> ^( UNARY_EXPRESSION_HEX HEX_LITERAL ( SIGN )* ) | DECIMAL_LITERAL -> ^( UNARY_EXPRESSION_DEC DECIMAL_LITERAL ( SIGN )* ) | OCTAL_LITERAL -> ^( UNARY_EXPRESSION_OCT OCTAL_LITERAL ( SIGN )* ) ) + { + // Grammar/CTFParser.g:224:3: ( SIGN )* + loop2: + do { + int alt2=2; + int LA2_0 = input.LA(1); + + if ( (LA2_0==SIGN) ) { + alt2=1; + } + + + switch (alt2) { + case 1 : + // Grammar/CTFParser.g:224:3: SIGN + { + SIGN3=(Token)match(input,SIGN,FOLLOW_SIGN_in_numberLiteral357); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_SIGN.add(SIGN3); + + + } + break; + + default : + break loop2; + } + } while (true); + + // Grammar/CTFParser.g:224:10: ( HEX_LITERAL -> ^( UNARY_EXPRESSION_HEX HEX_LITERAL ( SIGN )* ) | DECIMAL_LITERAL -> ^( UNARY_EXPRESSION_DEC DECIMAL_LITERAL ( SIGN )* ) | OCTAL_LITERAL -> ^( UNARY_EXPRESSION_OCT OCTAL_LITERAL ( SIGN )* ) ) + int alt3=3; + switch ( input.LA(1) ) { + case HEX_LITERAL: + { + alt3=1; + } + break; + case DECIMAL_LITERAL: + { + alt3=2; + } + break; + case OCTAL_LITERAL: + { + alt3=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 3, 0, input); + + throw nvae; + } + + switch (alt3) { + case 1 : + // Grammar/CTFParser.g:224:11: HEX_LITERAL + { + HEX_LITERAL4=(Token)match(input,HEX_LITERAL,FOLLOW_HEX_LITERAL_in_numberLiteral362); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_HEX_LITERAL.add(HEX_LITERAL4); + + + + // AST REWRITE + // elements: SIGN, HEX_LITERAL + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 224:23: -> ^( UNARY_EXPRESSION_HEX HEX_LITERAL ( SIGN )* ) + { + // Grammar/CTFParser.g:224:26: ^( UNARY_EXPRESSION_HEX HEX_LITERAL ( SIGN )* ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_HEX, "UNARY_EXPRESSION_HEX"), root_1); + + adaptor.addChild(root_1, stream_HEX_LITERAL.nextNode()); + // Grammar/CTFParser.g:224:61: ( SIGN )* + while ( stream_SIGN.hasNext() ) { + adaptor.addChild(root_1, stream_SIGN.nextNode()); + + } + stream_SIGN.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:225:5: DECIMAL_LITERAL + { + DECIMAL_LITERAL5=(Token)match(input,DECIMAL_LITERAL,FOLLOW_DECIMAL_LITERAL_in_numberLiteral379); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_DECIMAL_LITERAL.add(DECIMAL_LITERAL5); + + + + // AST REWRITE + // elements: DECIMAL_LITERAL, SIGN + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 225:21: -> ^( UNARY_EXPRESSION_DEC DECIMAL_LITERAL ( SIGN )* ) + { + // Grammar/CTFParser.g:225:24: ^( UNARY_EXPRESSION_DEC DECIMAL_LITERAL ( SIGN )* ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_DEC, "UNARY_EXPRESSION_DEC"), root_1); + + adaptor.addChild(root_1, stream_DECIMAL_LITERAL.nextNode()); + // Grammar/CTFParser.g:225:63: ( SIGN )* + while ( stream_SIGN.hasNext() ) { + adaptor.addChild(root_1, stream_SIGN.nextNode()); + + } + stream_SIGN.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 3 : + // Grammar/CTFParser.g:226:5: OCTAL_LITERAL + { + OCTAL_LITERAL6=(Token)match(input,OCTAL_LITERAL,FOLLOW_OCTAL_LITERAL_in_numberLiteral396); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_OCTAL_LITERAL.add(OCTAL_LITERAL6); + + + + // AST REWRITE + // elements: SIGN, OCTAL_LITERAL + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 226:19: -> ^( UNARY_EXPRESSION_OCT OCTAL_LITERAL ( SIGN )* ) + { + // Grammar/CTFParser.g:226:22: ^( UNARY_EXPRESSION_OCT OCTAL_LITERAL ( SIGN )* ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_OCT, "UNARY_EXPRESSION_OCT"), root_1); + + adaptor.addChild(root_1, stream_OCTAL_LITERAL.nextNode()); + // Grammar/CTFParser.g:226:59: ( SIGN )* + while ( stream_SIGN.hasNext() ) { + adaptor.addChild(root_1, stream_SIGN.nextNode()); + + } + stream_SIGN.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("numberLiteral"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "numberLiteral" + + public static class constant_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "constant" + // Grammar/CTFParser.g:229:1: constant : ( numberLiteral | enumConstant | CHARACTER_LITERAL ); + public final CTFParser.constant_return constant() throws RecognitionException { + CTFParser.constant_return retval = new CTFParser.constant_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token CHARACTER_LITERAL9=null; + CTFParser.numberLiteral_return numberLiteral7 = null; + + CTFParser.enumConstant_return enumConstant8 = null; + + + CommonTree CHARACTER_LITERAL9_tree=null; + + + enter("constant"); + + try { + // Grammar/CTFParser.g:236:1: ( numberLiteral | enumConstant | CHARACTER_LITERAL ) + int alt4=3; + switch ( input.LA(1) ) { + case SIGN: + case OCTAL_LITERAL: + case DECIMAL_LITERAL: + case HEX_LITERAL: + { + alt4=1; + } + break; + case ALIGNTOK: + case EVENTTOK: + case SIGNEDTOK: + case STRINGTOK: + case STRING_LITERAL: + case IDENTIFIER: + { + alt4=2; + } + break; + case CHARACTER_LITERAL: + { + alt4=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 4, 0, input); + + throw nvae; + } + + switch (alt4) { + case 1 : + // Grammar/CTFParser.g:237:4: numberLiteral + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_numberLiteral_in_constant432); + numberLiteral7=numberLiteral(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, numberLiteral7.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:238:5: enumConstant + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_enumConstant_in_constant438); + enumConstant8=enumConstant(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, enumConstant8.getTree()); + + } + break; + case 3 : + // Grammar/CTFParser.g:239:5: CHARACTER_LITERAL + { + root_0 = (CommonTree)adaptor.nil(); + + CHARACTER_LITERAL9=(Token)match(input,CHARACTER_LITERAL,FOLLOW_CHARACTER_LITERAL_in_constant444); if (state.failed) return retval; + if ( state.backtracking==0 ) { + CHARACTER_LITERAL9_tree = (CommonTree)adaptor.create(CHARACTER_LITERAL9); + adaptor.addChild(root_0, CHARACTER_LITERAL9_tree); + } + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("constant"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "constant" + + public static class primaryExpression_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "primaryExpression" + // Grammar/CTFParser.g:242:1: primaryExpression : ( ( IDENTIFIER )=> IDENTIFIER -> ^( UNARY_EXPRESSION_STRING IDENTIFIER ) | ( ctfKeyword )=> ctfKeyword -> ^( UNARY_EXPRESSION_STRING ctfKeyword ) | ( STRING_LITERAL )=> STRING_LITERAL -> ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) | constant ); + public final CTFParser.primaryExpression_return primaryExpression() throws RecognitionException { + CTFParser.primaryExpression_return retval = new CTFParser.primaryExpression_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER10=null; + Token STRING_LITERAL12=null; + CTFParser.ctfKeyword_return ctfKeyword11 = null; + + CTFParser.constant_return constant13 = null; + + + CommonTree IDENTIFIER10_tree=null; + CommonTree STRING_LITERAL12_tree=null; + RewriteRuleTokenStream stream_STRING_LITERAL=new RewriteRuleTokenStream(adaptor,"token STRING_LITERAL"); + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + RewriteRuleSubtreeStream stream_ctfKeyword=new RewriteRuleSubtreeStream(adaptor,"rule ctfKeyword"); + + enter("primaryExpression"); + + try { + // Grammar/CTFParser.g:249:1: ( ( IDENTIFIER )=> IDENTIFIER -> ^( UNARY_EXPRESSION_STRING IDENTIFIER ) | ( ctfKeyword )=> ctfKeyword -> ^( UNARY_EXPRESSION_STRING ctfKeyword ) | ( STRING_LITERAL )=> STRING_LITERAL -> ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) | constant ) + int alt5=4; + switch ( input.LA(1) ) { + case IDENTIFIER: + { + int LA5_1 = input.LA(2); + + if ( (synpred1_CTFParser()) ) { + alt5=1; + } + else if ( (true) ) { + alt5=4; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 5, 1, input); + + throw nvae; + } + } + break; + case ALIGNTOK: + case EVENTTOK: + case SIGNEDTOK: + case STRINGTOK: + { + int LA5_2 = input.LA(2); + + if ( (synpred2_CTFParser()) ) { + alt5=2; + } + else if ( (true) ) { + alt5=4; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 5, 2, input); + + throw nvae; + } + } + break; + case STRING_LITERAL: + { + int LA5_3 = input.LA(2); + + if ( (synpred3_CTFParser()) ) { + alt5=3; + } + else if ( (true) ) { + alt5=4; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 5, 3, input); + + throw nvae; + } + } + break; + case SIGN: + case OCTAL_LITERAL: + case DECIMAL_LITERAL: + case HEX_LITERAL: + case CHARACTER_LITERAL: + { + alt5=4; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 5, 0, input); + + throw nvae; + } + + switch (alt5) { + case 1 : + // Grammar/CTFParser.g:250:5: ( IDENTIFIER )=> IDENTIFIER + { + IDENTIFIER10=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_primaryExpression475); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER10); + + if ( state.backtracking==0 ) { + debug_print("IDENTIFIER: " + (IDENTIFIER10!=null?IDENTIFIER10.getText():null)); + } + + + // AST REWRITE + // elements: IDENTIFIER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 250:83: -> ^( UNARY_EXPRESSION_STRING IDENTIFIER ) + { + // Grammar/CTFParser.g:250:86: ^( UNARY_EXPRESSION_STRING IDENTIFIER ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING, "UNARY_EXPRESSION_STRING"), root_1); + + adaptor.addChild(root_1, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:251:5: ( ctfKeyword )=> ctfKeyword + { + pushFollow(FOLLOW_ctfKeyword_in_primaryExpression497); + ctfKeyword11=ctfKeyword(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfKeyword.add(ctfKeyword11.getTree()); + + + // AST REWRITE + // elements: ctfKeyword + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 251:32: -> ^( UNARY_EXPRESSION_STRING ctfKeyword ) + { + // Grammar/CTFParser.g:251:35: ^( UNARY_EXPRESSION_STRING ctfKeyword ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING, "UNARY_EXPRESSION_STRING"), root_1); + + adaptor.addChild(root_1, stream_ctfKeyword.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 3 : + // Grammar/CTFParser.g:252:5: ( STRING_LITERAL )=> STRING_LITERAL + { + STRING_LITERAL12=(Token)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_primaryExpression517); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_STRING_LITERAL.add(STRING_LITERAL12); + + if ( state.backtracking==0 ) { + debug_print("STRING_LITERAL: " + (STRING_LITERAL12!=null?STRING_LITERAL12.getText():null)); + } + + + // AST REWRITE + // elements: STRING_LITERAL + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 252:99: -> ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) + { + // Grammar/CTFParser.g:252:102: ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING_QUOTES, "UNARY_EXPRESSION_STRING_QUOTES"), root_1); + + adaptor.addChild(root_1, stream_STRING_LITERAL.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 4 : + // Grammar/CTFParser.g:254:5: constant + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_constant_in_primaryExpression538); + constant13=constant(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, constant13.getTree()); + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("primaryExpression"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "primaryExpression" + + public static class reference_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "reference" + // Grammar/CTFParser.g:257:1: reference : (ref= DOT | ref= ARROW ) IDENTIFIER -> ^( $ref ^( UNARY_EXPRESSION_STRING IDENTIFIER ) ) ; + public final CTFParser.reference_return reference() throws RecognitionException { + CTFParser.reference_return retval = new CTFParser.reference_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token ref=null; + Token IDENTIFIER14=null; + + CommonTree ref_tree=null; + CommonTree IDENTIFIER14_tree=null; + RewriteRuleTokenStream stream_ARROW=new RewriteRuleTokenStream(adaptor,"token ARROW"); + RewriteRuleTokenStream stream_DOT=new RewriteRuleTokenStream(adaptor,"token DOT"); + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + + + enter("reference"); + + try { + // Grammar/CTFParser.g:265:1: ( (ref= DOT | ref= ARROW ) IDENTIFIER -> ^( $ref ^( UNARY_EXPRESSION_STRING IDENTIFIER ) ) ) + // Grammar/CTFParser.g:266:3: (ref= DOT | ref= ARROW ) IDENTIFIER + { + // Grammar/CTFParser.g:266:3: (ref= DOT | ref= ARROW ) + int alt6=2; + int LA6_0 = input.LA(1); + + if ( (LA6_0==DOT) ) { + alt6=1; + } + else if ( (LA6_0==ARROW) ) { + alt6=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 6, 0, input); + + throw nvae; + } + switch (alt6) { + case 1 : + // Grammar/CTFParser.g:266:4: ref= DOT + { + ref=(Token)match(input,DOT,FOLLOW_DOT_in_reference564); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_DOT.add(ref); + + + } + break; + case 2 : + // Grammar/CTFParser.g:266:14: ref= ARROW + { + ref=(Token)match(input,ARROW,FOLLOW_ARROW_in_reference570); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ARROW.add(ref); + + + } + break; + + } + + IDENTIFIER14=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_reference573); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER14); + + + + // AST REWRITE + // elements: IDENTIFIER, ref + // token labels: ref + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleTokenStream stream_ref=new RewriteRuleTokenStream(adaptor,"token ref",ref); + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 266:36: -> ^( $ref ^( UNARY_EXPRESSION_STRING IDENTIFIER ) ) + { + // Grammar/CTFParser.g:266:39: ^( $ref ^( UNARY_EXPRESSION_STRING IDENTIFIER ) ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot(stream_ref.nextNode(), root_1); + + // Grammar/CTFParser.g:266:46: ^( UNARY_EXPRESSION_STRING IDENTIFIER ) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING, "UNARY_EXPRESSION_STRING"), root_2); + + adaptor.addChild(root_2, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_1, root_2); + } + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("reference"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "reference" + + public static class postfixExpressionSuffix_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "postfixExpressionSuffix" + // Grammar/CTFParser.g:269:1: postfixExpressionSuffix : ( ( OPENBRAC unaryExpression CLOSEBRAC ) | reference ); + public final CTFParser.postfixExpressionSuffix_return postfixExpressionSuffix() throws RecognitionException { + CTFParser.postfixExpressionSuffix_return retval = new CTFParser.postfixExpressionSuffix_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token OPENBRAC15=null; + Token CLOSEBRAC17=null; + CTFParser.unaryExpression_return unaryExpression16 = null; + + CTFParser.reference_return reference18 = null; + + + CommonTree OPENBRAC15_tree=null; + CommonTree CLOSEBRAC17_tree=null; + + + enter("postfixExpressionSuffix"); + + try { + // Grammar/CTFParser.g:276:1: ( ( OPENBRAC unaryExpression CLOSEBRAC ) | reference ) + int alt7=2; + int LA7_0 = input.LA(1); + + if ( (LA7_0==OPENBRAC) ) { + alt7=1; + } + else if ( ((LA7_0>=ARROW && LA7_0<=DOT)) ) { + alt7=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 7, 0, input); + + throw nvae; + } + switch (alt7) { + case 1 : + // Grammar/CTFParser.g:277:5: ( OPENBRAC unaryExpression CLOSEBRAC ) + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:277:5: ( OPENBRAC unaryExpression CLOSEBRAC ) + // Grammar/CTFParser.g:277:6: OPENBRAC unaryExpression CLOSEBRAC + { + OPENBRAC15=(Token)match(input,OPENBRAC,FOLLOW_OPENBRAC_in_postfixExpressionSuffix612); if (state.failed) return retval; + if ( state.backtracking==0 ) { + OPENBRAC15_tree = (CommonTree)adaptor.create(OPENBRAC15); + adaptor.addChild(root_0, OPENBRAC15_tree); + } + pushFollow(FOLLOW_unaryExpression_in_postfixExpressionSuffix614); + unaryExpression16=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, unaryExpression16.getTree()); + CLOSEBRAC17=(Token)match(input,CLOSEBRAC,FOLLOW_CLOSEBRAC_in_postfixExpressionSuffix616); if (state.failed) return retval; + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:278:5: reference + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_reference_in_postfixExpressionSuffix624); + reference18=reference(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, reference18.getTree()); + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("postfixExpressionSuffix"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "postfixExpressionSuffix" + + public static class postfixExpression_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "postfixExpression" + // Grammar/CTFParser.g:281:1: postfixExpression : ( ( primaryExpression ) ( postfixExpressionSuffix )* | ( ( ctfSpecifierHead ) ( postfixExpressionSuffix )+ ) ); + public final CTFParser.postfixExpression_return postfixExpression() throws RecognitionException { + CTFParser.postfixExpression_return retval = new CTFParser.postfixExpression_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.primaryExpression_return primaryExpression19 = null; + + CTFParser.postfixExpressionSuffix_return postfixExpressionSuffix20 = null; + + CTFParser.ctfSpecifierHead_return ctfSpecifierHead21 = null; + + CTFParser.postfixExpressionSuffix_return postfixExpressionSuffix22 = null; + + + + + enter("postfixExpression"); + + try { + // Grammar/CTFParser.g:288:1: ( ( primaryExpression ) ( postfixExpressionSuffix )* | ( ( ctfSpecifierHead ) ( postfixExpressionSuffix )+ ) ) + int alt10=2; + alt10 = dfa10.predict(input); + switch (alt10) { + case 1 : + // Grammar/CTFParser.g:289:3: ( primaryExpression ) ( postfixExpressionSuffix )* + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:289:3: ( primaryExpression ) + // Grammar/CTFParser.g:289:4: primaryExpression + { + pushFollow(FOLLOW_primaryExpression_in_postfixExpression648); + primaryExpression19=primaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, primaryExpression19.getTree()); + + } + + // Grammar/CTFParser.g:289:23: ( postfixExpressionSuffix )* + loop8: + do { + int alt8=2; + int LA8_0 = input.LA(1); + + if ( (LA8_0==OPENBRAC||(LA8_0>=ARROW && LA8_0<=DOT)) ) { + alt8=1; + } + + + switch (alt8) { + case 1 : + // Grammar/CTFParser.g:289:24: postfixExpressionSuffix + { + pushFollow(FOLLOW_postfixExpressionSuffix_in_postfixExpression652); + postfixExpressionSuffix20=postfixExpressionSuffix(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, postfixExpressionSuffix20.getTree()); + + } + break; + + default : + break loop8; + } + } while (true); + + + } + break; + case 2 : + // Grammar/CTFParser.g:290:3: ( ( ctfSpecifierHead ) ( postfixExpressionSuffix )+ ) + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:290:3: ( ( ctfSpecifierHead ) ( postfixExpressionSuffix )+ ) + // Grammar/CTFParser.g:290:4: ( ctfSpecifierHead ) ( postfixExpressionSuffix )+ + { + // Grammar/CTFParser.g:290:4: ( ctfSpecifierHead ) + // Grammar/CTFParser.g:290:5: ctfSpecifierHead + { + pushFollow(FOLLOW_ctfSpecifierHead_in_postfixExpression661); + ctfSpecifierHead21=ctfSpecifierHead(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, ctfSpecifierHead21.getTree()); + + } + + // Grammar/CTFParser.g:290:24: ( postfixExpressionSuffix )+ + int cnt9=0; + loop9: + do { + int alt9=2; + int LA9_0 = input.LA(1); + + if ( (LA9_0==OPENBRAC||(LA9_0>=ARROW && LA9_0<=DOT)) ) { + alt9=1; + } + + + switch (alt9) { + case 1 : + // Grammar/CTFParser.g:290:25: postfixExpressionSuffix + { + pushFollow(FOLLOW_postfixExpressionSuffix_in_postfixExpression666); + postfixExpressionSuffix22=postfixExpressionSuffix(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, postfixExpressionSuffix22.getTree()); + + } + break; + + default : + if ( cnt9 >= 1 ) break loop9; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(9, input); + throw eee; + } + cnt9++; + } while (true); + + + } + + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("postfixExpression"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "postfixExpression" + + public static class unaryExpression_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "unaryExpression" + // Grammar/CTFParser.g:293:1: unaryExpression : postfixExpression ; + public final CTFParser.unaryExpression_return unaryExpression() throws RecognitionException { + CTFParser.unaryExpression_return retval = new CTFParser.unaryExpression_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.postfixExpression_return postfixExpression23 = null; + + + + + enter("unaryExpression"); + + try { + // Grammar/CTFParser.g:300:1: ( postfixExpression ) + // Grammar/CTFParser.g:303:5: postfixExpression + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_postfixExpression_in_unaryExpression700); + postfixExpression23=postfixExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, postfixExpression23.getTree()); + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("unaryExpression"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "unaryExpression" + + public static class enumConstant_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumConstant" + // Grammar/CTFParser.g:306:1: enumConstant : ( STRING_LITERAL -> ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) | IDENTIFIER -> ^( UNARY_EXPRESSION_STRING IDENTIFIER ) | ctfKeyword -> ^( UNARY_EXPRESSION_STRING ctfKeyword ) ); + public final CTFParser.enumConstant_return enumConstant() throws RecognitionException { + CTFParser.enumConstant_return retval = new CTFParser.enumConstant_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token STRING_LITERAL24=null; + Token IDENTIFIER25=null; + CTFParser.ctfKeyword_return ctfKeyword26 = null; + + + CommonTree STRING_LITERAL24_tree=null; + CommonTree IDENTIFIER25_tree=null; + RewriteRuleTokenStream stream_STRING_LITERAL=new RewriteRuleTokenStream(adaptor,"token STRING_LITERAL"); + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + RewriteRuleSubtreeStream stream_ctfKeyword=new RewriteRuleSubtreeStream(adaptor,"rule ctfKeyword"); + + enter("enumConstant"); + + try { + // Grammar/CTFParser.g:314:1: ( STRING_LITERAL -> ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) | IDENTIFIER -> ^( UNARY_EXPRESSION_STRING IDENTIFIER ) | ctfKeyword -> ^( UNARY_EXPRESSION_STRING ctfKeyword ) ) + int alt11=3; + switch ( input.LA(1) ) { + case STRING_LITERAL: + { + alt11=1; + } + break; + case IDENTIFIER: + { + alt11=2; + } + break; + case ALIGNTOK: + case EVENTTOK: + case SIGNEDTOK: + case STRINGTOK: + { + alt11=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 11, 0, input); + + throw nvae; + } + + switch (alt11) { + case 1 : + // Grammar/CTFParser.g:315:5: STRING_LITERAL + { + STRING_LITERAL24=(Token)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_enumConstant725); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_STRING_LITERAL.add(STRING_LITERAL24); + + + + // AST REWRITE + // elements: STRING_LITERAL + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 315:20: -> ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) + { + // Grammar/CTFParser.g:315:23: ^( UNARY_EXPRESSION_STRING_QUOTES STRING_LITERAL ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING_QUOTES, "UNARY_EXPRESSION_STRING_QUOTES"), root_1); + + adaptor.addChild(root_1, stream_STRING_LITERAL.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:316:7: IDENTIFIER + { + IDENTIFIER25=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_enumConstant741); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER25); + + + + // AST REWRITE + // elements: IDENTIFIER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 316:18: -> ^( UNARY_EXPRESSION_STRING IDENTIFIER ) + { + // Grammar/CTFParser.g:316:21: ^( UNARY_EXPRESSION_STRING IDENTIFIER ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING, "UNARY_EXPRESSION_STRING"), root_1); + + adaptor.addChild(root_1, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 3 : + // Grammar/CTFParser.g:317:7: ctfKeyword + { + pushFollow(FOLLOW_ctfKeyword_in_enumConstant757); + ctfKeyword26=ctfKeyword(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfKeyword.add(ctfKeyword26.getTree()); + + + // AST REWRITE + // elements: ctfKeyword + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 317:18: -> ^( UNARY_EXPRESSION_STRING ctfKeyword ) + { + // Grammar/CTFParser.g:317:21: ^( UNARY_EXPRESSION_STRING ctfKeyword ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(UNARY_EXPRESSION_STRING, "UNARY_EXPRESSION_STRING"), root_1); + + adaptor.addChild(root_1, stream_ctfKeyword.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("enumConstant"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumConstant" + + public static class declaration_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "declaration" + // Grammar/CTFParser.g:321:1: declaration : ( ( declarationSpecifiers ( declaratorList )? TERM ) -> {inTypedef()}? ^( DECLARATION ^( TYPEDEF declaratorList declarationSpecifiers ) ) -> ^( DECLARATION declarationSpecifiers ( declaratorList )? ) | ( ctfSpecifier TERM ) ); + public final CTFParser.declaration_return declaration() throws RecognitionException { + CTFParser.declaration_return retval = new CTFParser.declaration_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token TERM29=null; + Token TERM31=null; + CTFParser.declarationSpecifiers_return declarationSpecifiers27 = null; + + CTFParser.declaratorList_return declaratorList28 = null; + + CTFParser.ctfSpecifier_return ctfSpecifier30 = null; + + + CommonTree TERM29_tree=null; + CommonTree TERM31_tree=null; + RewriteRuleTokenStream stream_TERM=new RewriteRuleTokenStream(adaptor,"token TERM"); + RewriteRuleSubtreeStream stream_declaratorList=new RewriteRuleSubtreeStream(adaptor,"rule declaratorList"); + RewriteRuleSubtreeStream stream_declarationSpecifiers=new RewriteRuleSubtreeStream(adaptor,"rule declarationSpecifiers"); + + enter("declaration"); + + try { + // Grammar/CTFParser.g:330:1: ( ( declarationSpecifiers ( declaratorList )? TERM ) -> {inTypedef()}? ^( DECLARATION ^( TYPEDEF declaratorList declarationSpecifiers ) ) -> ^( DECLARATION declarationSpecifiers ( declaratorList )? ) | ( ctfSpecifier TERM ) ) + int alt13=2; + int LA13_0 = input.LA(1); + + if ( ((LA13_0>=CONSTTOK && LA13_0<=ENUMTOK)||(LA13_0>=FLOATINGPOINTTOK && LA13_0<=SIGNEDTOK)||(LA13_0>=STRINGTOK && LA13_0<=STRUCTTOK)||(LA13_0>=TYPEDEFTOK && LA13_0<=IMAGINARYTOK)) ) { + alt13=1; + } + else if ( (LA13_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt13=1; + } + else if ( (LA13_0==EVENTTOK||LA13_0==STREAMTOK||(LA13_0>=TRACETOK && LA13_0<=TYPEALIASTOK)||(LA13_0>=ENVTOK && LA13_0<=CLOCKTOK)) ) { + alt13=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 13, 0, input); + + throw nvae; + } + switch (alt13) { + case 1 : + // Grammar/CTFParser.g:331:3: ( declarationSpecifiers ( declaratorList )? TERM ) + { + // Grammar/CTFParser.g:331:3: ( declarationSpecifiers ( declaratorList )? TERM ) + // Grammar/CTFParser.g:331:4: declarationSpecifiers ( declaratorList )? TERM + { + pushFollow(FOLLOW_declarationSpecifiers_in_declaration790); + declarationSpecifiers27=declarationSpecifiers(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarationSpecifiers.add(declarationSpecifiers27.getTree()); + // Grammar/CTFParser.g:331:26: ( declaratorList )? + int alt12=2; + int LA12_0 = input.LA(1); + + if ( (LA12_0==POINTER||LA12_0==IDENTIFIER) ) { + alt12=1; + } + switch (alt12) { + case 1 : + // Grammar/CTFParser.g:331:26: declaratorList + { + pushFollow(FOLLOW_declaratorList_in_declaration792); + declaratorList28=declaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declaratorList.add(declaratorList28.getTree()); + + } + break; + + } + + TERM29=(Token)match(input,TERM,FOLLOW_TERM_in_declaration795); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_TERM.add(TERM29); + + + } + + + + // AST REWRITE + // elements: declaratorList, declaratorList, declarationSpecifiers, declarationSpecifiers + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 334:3: -> {inTypedef()}? ^( DECLARATION ^( TYPEDEF declaratorList declarationSpecifiers ) ) + if (inTypedef()) { + // Grammar/CTFParser.g:334:21: ^( DECLARATION ^( TYPEDEF declaratorList declarationSpecifiers ) ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(DECLARATION, "DECLARATION"), root_1); + + // Grammar/CTFParser.g:334:35: ^( TYPEDEF declaratorList declarationSpecifiers ) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPEDEF, "TYPEDEF"), root_2); + + adaptor.addChild(root_2, stream_declaratorList.nextTree()); + adaptor.addChild(root_2, stream_declarationSpecifiers.nextTree()); + + adaptor.addChild(root_1, root_2); + } + + adaptor.addChild(root_0, root_1); + } + + } + else // 335:3: -> ^( DECLARATION declarationSpecifiers ( declaratorList )? ) + { + // Grammar/CTFParser.g:335:6: ^( DECLARATION declarationSpecifiers ( declaratorList )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(DECLARATION, "DECLARATION"), root_1); + + adaptor.addChild(root_1, stream_declarationSpecifiers.nextTree()); + // Grammar/CTFParser.g:335:42: ( declaratorList )? + if ( stream_declaratorList.hasNext() ) { + adaptor.addChild(root_1, stream_declaratorList.nextTree()); + + } + stream_declaratorList.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:337:5: ( ctfSpecifier TERM ) + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:337:5: ( ctfSpecifier TERM ) + // Grammar/CTFParser.g:337:6: ctfSpecifier TERM + { + pushFollow(FOLLOW_ctfSpecifier_in_declaration844); + ctfSpecifier30=ctfSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, ctfSpecifier30.getTree()); + TERM31=(Token)match(input,TERM,FOLLOW_TERM_in_declaration846); if (state.failed) return retval; + + } + + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("declaration"); + if (inTypedef()) + typedefOff(); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "declaration" + + public static class declarationSpecifiers_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "declarationSpecifiers" + // Grammar/CTFParser.g:340:1: declarationSpecifiers : ( storageClassSpecifier | typeQualifier | typeSpecifier )+ -> ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) ; + public final CTFParser.declarationSpecifiers_return declarationSpecifiers() throws RecognitionException { + CTFParser.declarationSpecifiers_return retval = new CTFParser.declarationSpecifiers_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.storageClassSpecifier_return storageClassSpecifier32 = null; + + CTFParser.typeQualifier_return typeQualifier33 = null; + + CTFParser.typeSpecifier_return typeSpecifier34 = null; + + + RewriteRuleSubtreeStream stream_typeSpecifier=new RewriteRuleSubtreeStream(adaptor,"rule typeSpecifier"); + RewriteRuleSubtreeStream stream_typeQualifier=new RewriteRuleSubtreeStream(adaptor,"rule typeQualifier"); + RewriteRuleSubtreeStream stream_storageClassSpecifier=new RewriteRuleSubtreeStream(adaptor,"rule storageClassSpecifier"); + + enter("declarationSpecifiers"); + + try { + // Grammar/CTFParser.g:348:1: ( ( storageClassSpecifier | typeQualifier | typeSpecifier )+ -> ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) ) + // Grammar/CTFParser.g:349:3: ( storageClassSpecifier | typeQualifier | typeSpecifier )+ + { + // Grammar/CTFParser.g:349:3: ( storageClassSpecifier | typeQualifier | typeSpecifier )+ + int cnt14=0; + loop14: + do { + int alt14=4; + switch ( input.LA(1) ) { + case IDENTIFIER: + { + int LA14_2 = input.LA(2); + + if ( ((inTypealiasAlias() || isTypeName(input.LT(1).getText()))) ) { + alt14=3; + } + + + } + break; + case TYPEDEFTOK: + { + alt14=1; + } + break; + case CONSTTOK: + { + alt14=2; + } + break; + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case SIGNEDTOK: + case STRINGTOK: + case STRUCTTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + { + alt14=3; + } + break; + + } + + switch (alt14) { + case 1 : + // Grammar/CTFParser.g:352:6: storageClassSpecifier + { + pushFollow(FOLLOW_storageClassSpecifier_in_declarationSpecifiers891); + storageClassSpecifier32=storageClassSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_storageClassSpecifier.add(storageClassSpecifier32.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:353:6: typeQualifier + { + pushFollow(FOLLOW_typeQualifier_in_declarationSpecifiers898); + typeQualifier33=typeQualifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typeQualifier.add(typeQualifier33.getTree()); + + } + break; + case 3 : + // Grammar/CTFParser.g:354:6: typeSpecifier + { + pushFollow(FOLLOW_typeSpecifier_in_declarationSpecifiers905); + typeSpecifier34=typeSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typeSpecifier.add(typeSpecifier34.getTree()); + + } + break; + + default : + if ( cnt14 >= 1 ) break loop14; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(14, input); + throw eee; + } + cnt14++; + } while (true); + + + + // AST REWRITE + // elements: typeQualifier, typeSpecifier + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 355:6: -> ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) + { + // Grammar/CTFParser.g:355:9: ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_SPECIFIER_LIST, "TYPE_SPECIFIER_LIST"), root_1); + + // Grammar/CTFParser.g:355:31: ( typeQualifier )* + while ( stream_typeQualifier.hasNext() ) { + adaptor.addChild(root_1, stream_typeQualifier.nextTree()); + + } + stream_typeQualifier.reset(); + // Grammar/CTFParser.g:355:46: ( typeSpecifier )* + while ( stream_typeSpecifier.hasNext() ) { + adaptor.addChild(root_1, stream_typeSpecifier.nextTree()); + + } + stream_typeSpecifier.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("declarationSpecifiers"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "declarationSpecifiers" + + public static class declaratorList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "declaratorList" + // Grammar/CTFParser.g:358:1: declaratorList : declarator ( SEPARATOR declarator )* -> ^( TYPE_DECLARATOR_LIST ( declarator )+ ) ; + public final CTFParser.declaratorList_return declaratorList() throws RecognitionException { + CTFParser.declaratorList_return retval = new CTFParser.declaratorList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token SEPARATOR36=null; + CTFParser.declarator_return declarator35 = null; + + CTFParser.declarator_return declarator37 = null; + + + CommonTree SEPARATOR36_tree=null; + RewriteRuleTokenStream stream_SEPARATOR=new RewriteRuleTokenStream(adaptor,"token SEPARATOR"); + RewriteRuleSubtreeStream stream_declarator=new RewriteRuleSubtreeStream(adaptor,"rule declarator"); + + enter("declaratorList"); + + try { + // Grammar/CTFParser.g:365:1: ( declarator ( SEPARATOR declarator )* -> ^( TYPE_DECLARATOR_LIST ( declarator )+ ) ) + // Grammar/CTFParser.g:366:3: declarator ( SEPARATOR declarator )* + { + pushFollow(FOLLOW_declarator_in_declaratorList946); + declarator35=declarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarator.add(declarator35.getTree()); + // Grammar/CTFParser.g:366:14: ( SEPARATOR declarator )* + loop15: + do { + int alt15=2; + int LA15_0 = input.LA(1); + + if ( (LA15_0==SEPARATOR) ) { + alt15=1; + } + + + switch (alt15) { + case 1 : + // Grammar/CTFParser.g:366:15: SEPARATOR declarator + { + SEPARATOR36=(Token)match(input,SEPARATOR,FOLLOW_SEPARATOR_in_declaratorList949); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_SEPARATOR.add(SEPARATOR36); + + pushFollow(FOLLOW_declarator_in_declaratorList951); + declarator37=declarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarator.add(declarator37.getTree()); + + } + break; + + default : + break loop15; + } + } while (true); + + + + // AST REWRITE + // elements: declarator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 366:38: -> ^( TYPE_DECLARATOR_LIST ( declarator )+ ) + { + // Grammar/CTFParser.g:366:41: ^( TYPE_DECLARATOR_LIST ( declarator )+ ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_DECLARATOR_LIST, "TYPE_DECLARATOR_LIST"), root_1); + + if ( !(stream_declarator.hasNext()) ) { + throw new RewriteEarlyExitException(); + } + while ( stream_declarator.hasNext() ) { + adaptor.addChild(root_1, stream_declarator.nextTree()); + + } + stream_declarator.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("declaratorList"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "declaratorList" + + public static class abstractDeclaratorList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "abstractDeclaratorList" + // Grammar/CTFParser.g:369:1: abstractDeclaratorList : abstractDeclarator ( SEPARATOR abstractDeclarator )* -> ^( TYPE_DECLARATOR_LIST ( abstractDeclarator )+ ) ; + public final CTFParser.abstractDeclaratorList_return abstractDeclaratorList() throws RecognitionException { + CTFParser.abstractDeclaratorList_return retval = new CTFParser.abstractDeclaratorList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token SEPARATOR39=null; + CTFParser.abstractDeclarator_return abstractDeclarator38 = null; + + CTFParser.abstractDeclarator_return abstractDeclarator40 = null; + + + CommonTree SEPARATOR39_tree=null; + RewriteRuleTokenStream stream_SEPARATOR=new RewriteRuleTokenStream(adaptor,"token SEPARATOR"); + RewriteRuleSubtreeStream stream_abstractDeclarator=new RewriteRuleSubtreeStream(adaptor,"rule abstractDeclarator"); + + enter("abstractDeclaratorList"); + + try { + // Grammar/CTFParser.g:376:1: ( abstractDeclarator ( SEPARATOR abstractDeclarator )* -> ^( TYPE_DECLARATOR_LIST ( abstractDeclarator )+ ) ) + // Grammar/CTFParser.g:377:3: abstractDeclarator ( SEPARATOR abstractDeclarator )* + { + pushFollow(FOLLOW_abstractDeclarator_in_abstractDeclaratorList985); + abstractDeclarator38=abstractDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_abstractDeclarator.add(abstractDeclarator38.getTree()); + // Grammar/CTFParser.g:377:22: ( SEPARATOR abstractDeclarator )* + loop16: + do { + int alt16=2; + int LA16_0 = input.LA(1); + + if ( (LA16_0==SEPARATOR) ) { + alt16=1; + } + + + switch (alt16) { + case 1 : + // Grammar/CTFParser.g:377:23: SEPARATOR abstractDeclarator + { + SEPARATOR39=(Token)match(input,SEPARATOR,FOLLOW_SEPARATOR_in_abstractDeclaratorList988); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_SEPARATOR.add(SEPARATOR39); + + pushFollow(FOLLOW_abstractDeclarator_in_abstractDeclaratorList990); + abstractDeclarator40=abstractDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_abstractDeclarator.add(abstractDeclarator40.getTree()); + + } + break; + + default : + break loop16; + } + } while (true); + + + + // AST REWRITE + // elements: abstractDeclarator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 377:54: -> ^( TYPE_DECLARATOR_LIST ( abstractDeclarator )+ ) + { + // Grammar/CTFParser.g:377:57: ^( TYPE_DECLARATOR_LIST ( abstractDeclarator )+ ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_DECLARATOR_LIST, "TYPE_DECLARATOR_LIST"), root_1); + + if ( !(stream_abstractDeclarator.hasNext()) ) { + throw new RewriteEarlyExitException(); + } + while ( stream_abstractDeclarator.hasNext() ) { + adaptor.addChild(root_1, stream_abstractDeclarator.nextTree()); + + } + stream_abstractDeclarator.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("abstractDeclaratorList"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "abstractDeclaratorList" + + public static class storageClassSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "storageClassSpecifier" + // Grammar/CTFParser.g:380:1: storageClassSpecifier : TYPEDEFTOK ; + public final CTFParser.storageClassSpecifier_return storageClassSpecifier() throws RecognitionException { + CTFParser.storageClassSpecifier_return retval = new CTFParser.storageClassSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token TYPEDEFTOK41=null; + + CommonTree TYPEDEFTOK41_tree=null; + + try { + // Grammar/CTFParser.g:380:23: ( TYPEDEFTOK ) + // Grammar/CTFParser.g:381:3: TYPEDEFTOK + { + root_0 = (CommonTree)adaptor.nil(); + + TYPEDEFTOK41=(Token)match(input,TYPEDEFTOK,FOLLOW_TYPEDEFTOK_in_storageClassSpecifier1014); if (state.failed) return retval; + if ( state.backtracking==0 ) { + TYPEDEFTOK41_tree = (CommonTree)adaptor.create(TYPEDEFTOK41); + adaptor.addChild(root_0, TYPEDEFTOK41_tree); + } + if ( state.backtracking==0 ) { + typedefOn(); + } + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "storageClassSpecifier" + + public static class typeSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typeSpecifier" + // Grammar/CTFParser.g:384:1: typeSpecifier : ( FLOATTOK | INTTOK | LONGTOK | SHORTTOK | SIGNEDTOK | UNSIGNEDTOK | CHARTOK | DOUBLETOK | VOIDTOK | BOOLTOK | COMPLEXTOK | IMAGINARYTOK | structSpecifier | variantSpecifier | enumSpecifier | ctfTypeSpecifier | {...}? => typedefName ); + public final CTFParser.typeSpecifier_return typeSpecifier() throws RecognitionException { + CTFParser.typeSpecifier_return retval = new CTFParser.typeSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token FLOATTOK42=null; + Token INTTOK43=null; + Token LONGTOK44=null; + Token SHORTTOK45=null; + Token SIGNEDTOK46=null; + Token UNSIGNEDTOK47=null; + Token CHARTOK48=null; + Token DOUBLETOK49=null; + Token VOIDTOK50=null; + Token BOOLTOK51=null; + Token COMPLEXTOK52=null; + Token IMAGINARYTOK53=null; + CTFParser.structSpecifier_return structSpecifier54 = null; + + CTFParser.variantSpecifier_return variantSpecifier55 = null; + + CTFParser.enumSpecifier_return enumSpecifier56 = null; + + CTFParser.ctfTypeSpecifier_return ctfTypeSpecifier57 = null; + + CTFParser.typedefName_return typedefName58 = null; + + + CommonTree FLOATTOK42_tree=null; + CommonTree INTTOK43_tree=null; + CommonTree LONGTOK44_tree=null; + CommonTree SHORTTOK45_tree=null; + CommonTree SIGNEDTOK46_tree=null; + CommonTree UNSIGNEDTOK47_tree=null; + CommonTree CHARTOK48_tree=null; + CommonTree DOUBLETOK49_tree=null; + CommonTree VOIDTOK50_tree=null; + CommonTree BOOLTOK51_tree=null; + CommonTree COMPLEXTOK52_tree=null; + CommonTree IMAGINARYTOK53_tree=null; + + + enter("typeSpecifier"); + + try { + // Grammar/CTFParser.g:392:1: ( FLOATTOK | INTTOK | LONGTOK | SHORTTOK | SIGNEDTOK | UNSIGNEDTOK | CHARTOK | DOUBLETOK | VOIDTOK | BOOLTOK | COMPLEXTOK | IMAGINARYTOK | structSpecifier | variantSpecifier | enumSpecifier | ctfTypeSpecifier | {...}? => typedefName ) + int alt17=17; + alt17 = dfa17.predict(input); + switch (alt17) { + case 1 : + // Grammar/CTFParser.g:393:3: FLOATTOK + { + root_0 = (CommonTree)adaptor.nil(); + + FLOATTOK42=(Token)match(input,FLOATTOK,FOLLOW_FLOATTOK_in_typeSpecifier1040); if (state.failed) return retval; + if ( state.backtracking==0 ) { + FLOATTOK42_tree = (CommonTree)adaptor.create(FLOATTOK42); + adaptor.addChild(root_0, FLOATTOK42_tree); + } + + } + break; + case 2 : + // Grammar/CTFParser.g:394:5: INTTOK + { + root_0 = (CommonTree)adaptor.nil(); + + INTTOK43=(Token)match(input,INTTOK,FOLLOW_INTTOK_in_typeSpecifier1046); if (state.failed) return retval; + if ( state.backtracking==0 ) { + INTTOK43_tree = (CommonTree)adaptor.create(INTTOK43); + adaptor.addChild(root_0, INTTOK43_tree); + } + + } + break; + case 3 : + // Grammar/CTFParser.g:395:5: LONGTOK + { + root_0 = (CommonTree)adaptor.nil(); + + LONGTOK44=(Token)match(input,LONGTOK,FOLLOW_LONGTOK_in_typeSpecifier1052); if (state.failed) return retval; + if ( state.backtracking==0 ) { + LONGTOK44_tree = (CommonTree)adaptor.create(LONGTOK44); + adaptor.addChild(root_0, LONGTOK44_tree); + } + + } + break; + case 4 : + // Grammar/CTFParser.g:396:5: SHORTTOK + { + root_0 = (CommonTree)adaptor.nil(); + + SHORTTOK45=(Token)match(input,SHORTTOK,FOLLOW_SHORTTOK_in_typeSpecifier1058); if (state.failed) return retval; + if ( state.backtracking==0 ) { + SHORTTOK45_tree = (CommonTree)adaptor.create(SHORTTOK45); + adaptor.addChild(root_0, SHORTTOK45_tree); + } + + } + break; + case 5 : + // Grammar/CTFParser.g:397:5: SIGNEDTOK + { + root_0 = (CommonTree)adaptor.nil(); + + SIGNEDTOK46=(Token)match(input,SIGNEDTOK,FOLLOW_SIGNEDTOK_in_typeSpecifier1064); if (state.failed) return retval; + if ( state.backtracking==0 ) { + SIGNEDTOK46_tree = (CommonTree)adaptor.create(SIGNEDTOK46); + adaptor.addChild(root_0, SIGNEDTOK46_tree); + } + + } + break; + case 6 : + // Grammar/CTFParser.g:398:5: UNSIGNEDTOK + { + root_0 = (CommonTree)adaptor.nil(); + + UNSIGNEDTOK47=(Token)match(input,UNSIGNEDTOK,FOLLOW_UNSIGNEDTOK_in_typeSpecifier1070); if (state.failed) return retval; + if ( state.backtracking==0 ) { + UNSIGNEDTOK47_tree = (CommonTree)adaptor.create(UNSIGNEDTOK47); + adaptor.addChild(root_0, UNSIGNEDTOK47_tree); + } + + } + break; + case 7 : + // Grammar/CTFParser.g:399:5: CHARTOK + { + root_0 = (CommonTree)adaptor.nil(); + + CHARTOK48=(Token)match(input,CHARTOK,FOLLOW_CHARTOK_in_typeSpecifier1076); if (state.failed) return retval; + if ( state.backtracking==0 ) { + CHARTOK48_tree = (CommonTree)adaptor.create(CHARTOK48); + adaptor.addChild(root_0, CHARTOK48_tree); + } + + } + break; + case 8 : + // Grammar/CTFParser.g:400:5: DOUBLETOK + { + root_0 = (CommonTree)adaptor.nil(); + + DOUBLETOK49=(Token)match(input,DOUBLETOK,FOLLOW_DOUBLETOK_in_typeSpecifier1082); if (state.failed) return retval; + if ( state.backtracking==0 ) { + DOUBLETOK49_tree = (CommonTree)adaptor.create(DOUBLETOK49); + adaptor.addChild(root_0, DOUBLETOK49_tree); + } + + } + break; + case 9 : + // Grammar/CTFParser.g:401:5: VOIDTOK + { + root_0 = (CommonTree)adaptor.nil(); + + VOIDTOK50=(Token)match(input,VOIDTOK,FOLLOW_VOIDTOK_in_typeSpecifier1088); if (state.failed) return retval; + if ( state.backtracking==0 ) { + VOIDTOK50_tree = (CommonTree)adaptor.create(VOIDTOK50); + adaptor.addChild(root_0, VOIDTOK50_tree); + } + + } + break; + case 10 : + // Grammar/CTFParser.g:402:5: BOOLTOK + { + root_0 = (CommonTree)adaptor.nil(); + + BOOLTOK51=(Token)match(input,BOOLTOK,FOLLOW_BOOLTOK_in_typeSpecifier1094); if (state.failed) return retval; + if ( state.backtracking==0 ) { + BOOLTOK51_tree = (CommonTree)adaptor.create(BOOLTOK51); + adaptor.addChild(root_0, BOOLTOK51_tree); + } + + } + break; + case 11 : + // Grammar/CTFParser.g:403:5: COMPLEXTOK + { + root_0 = (CommonTree)adaptor.nil(); + + COMPLEXTOK52=(Token)match(input,COMPLEXTOK,FOLLOW_COMPLEXTOK_in_typeSpecifier1100); if (state.failed) return retval; + if ( state.backtracking==0 ) { + COMPLEXTOK52_tree = (CommonTree)adaptor.create(COMPLEXTOK52); + adaptor.addChild(root_0, COMPLEXTOK52_tree); + } + + } + break; + case 12 : + // Grammar/CTFParser.g:404:5: IMAGINARYTOK + { + root_0 = (CommonTree)adaptor.nil(); + + IMAGINARYTOK53=(Token)match(input,IMAGINARYTOK,FOLLOW_IMAGINARYTOK_in_typeSpecifier1106); if (state.failed) return retval; + if ( state.backtracking==0 ) { + IMAGINARYTOK53_tree = (CommonTree)adaptor.create(IMAGINARYTOK53); + adaptor.addChild(root_0, IMAGINARYTOK53_tree); + } + + } + break; + case 13 : + // Grammar/CTFParser.g:405:5: structSpecifier + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_structSpecifier_in_typeSpecifier1112); + structSpecifier54=structSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, structSpecifier54.getTree()); + + } + break; + case 14 : + // Grammar/CTFParser.g:406:5: variantSpecifier + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_variantSpecifier_in_typeSpecifier1118); + variantSpecifier55=variantSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, variantSpecifier55.getTree()); + + } + break; + case 15 : + // Grammar/CTFParser.g:407:5: enumSpecifier + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_enumSpecifier_in_typeSpecifier1124); + enumSpecifier56=enumSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, enumSpecifier56.getTree()); + + } + break; + case 16 : + // Grammar/CTFParser.g:408:5: ctfTypeSpecifier + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_ctfTypeSpecifier_in_typeSpecifier1130); + ctfTypeSpecifier57=ctfTypeSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, ctfTypeSpecifier57.getTree()); + + } + break; + case 17 : + // Grammar/CTFParser.g:409:5: {...}? => typedefName + { + root_0 = (CommonTree)adaptor.nil(); + + if ( !((inTypealiasAlias() || isTypeName(input.LT(1).getText()))) ) { + if (state.backtracking>0) {state.failed=true; return retval;} + throw new FailedPredicateException(input, "typeSpecifier", "inTypealiasAlias() || isTypeName(input.LT(1).getText())"); + } + pushFollow(FOLLOW_typedefName_in_typeSpecifier1140); + typedefName58=typedefName(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, typedefName58.getTree()); + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("typeSpecifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typeSpecifier" + + public static class typeQualifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typeQualifier" + // Grammar/CTFParser.g:412:1: typeQualifier : CONSTTOK ; + public final CTFParser.typeQualifier_return typeQualifier() throws RecognitionException { + CTFParser.typeQualifier_return retval = new CTFParser.typeQualifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token CONSTTOK59=null; + + CommonTree CONSTTOK59_tree=null; + + + enter("typeQualifier"); + + try { + // Grammar/CTFParser.g:420:1: ( CONSTTOK ) + // Grammar/CTFParser.g:421:3: CONSTTOK + { + root_0 = (CommonTree)adaptor.nil(); + + CONSTTOK59=(Token)match(input,CONSTTOK,FOLLOW_CONSTTOK_in_typeQualifier1163); if (state.failed) return retval; + if ( state.backtracking==0 ) { + CONSTTOK59_tree = (CommonTree)adaptor.create(CONSTTOK59); + adaptor.addChild(root_0, CONSTTOK59_tree); + } + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("typeQualifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typeQualifier" + + public static class alignAttribute_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "alignAttribute" + // Grammar/CTFParser.g:424:1: alignAttribute : ALIGNTOK LPAREN unaryExpression RPAREN -> ^( ALIGN unaryExpression ) ; + public final CTFParser.alignAttribute_return alignAttribute() throws RecognitionException { + CTFParser.alignAttribute_return retval = new CTFParser.alignAttribute_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token ALIGNTOK60=null; + Token LPAREN61=null; + Token RPAREN63=null; + CTFParser.unaryExpression_return unaryExpression62 = null; + + + CommonTree ALIGNTOK60_tree=null; + CommonTree LPAREN61_tree=null; + CommonTree RPAREN63_tree=null; + RewriteRuleTokenStream stream_RPAREN=new RewriteRuleTokenStream(adaptor,"token RPAREN"); + RewriteRuleTokenStream stream_ALIGNTOK=new RewriteRuleTokenStream(adaptor,"token ALIGNTOK"); + RewriteRuleTokenStream stream_LPAREN=new RewriteRuleTokenStream(adaptor,"token LPAREN"); + RewriteRuleSubtreeStream stream_unaryExpression=new RewriteRuleSubtreeStream(adaptor,"rule unaryExpression"); + try { + // Grammar/CTFParser.g:424:16: ( ALIGNTOK LPAREN unaryExpression RPAREN -> ^( ALIGN unaryExpression ) ) + // Grammar/CTFParser.g:425:3: ALIGNTOK LPAREN unaryExpression RPAREN + { + ALIGNTOK60=(Token)match(input,ALIGNTOK,FOLLOW_ALIGNTOK_in_alignAttribute1176); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ALIGNTOK.add(ALIGNTOK60); + + LPAREN61=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_alignAttribute1178); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_LPAREN.add(LPAREN61); + + pushFollow(FOLLOW_unaryExpression_in_alignAttribute1180); + unaryExpression62=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_unaryExpression.add(unaryExpression62.getTree()); + RPAREN63=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_alignAttribute1182); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_RPAREN.add(RPAREN63); + + + + // AST REWRITE + // elements: unaryExpression + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 425:42: -> ^( ALIGN unaryExpression ) + { + // Grammar/CTFParser.g:425:45: ^( ALIGN unaryExpression ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ALIGN, "ALIGN"), root_1); + + adaptor.addChild(root_1, stream_unaryExpression.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "alignAttribute" + + public static class structBody_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structBody" + // Grammar/CTFParser.g:429:1: structBody : LCURL ( structOrVariantDeclarationList )? RCURL -> ^( STRUCT_BODY ( structOrVariantDeclarationList )? ) ; + public final CTFParser.structBody_return structBody() throws RecognitionException { + Symbols_stack.push(new Symbols_scope()); + + CTFParser.structBody_return retval = new CTFParser.structBody_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token LCURL64=null; + Token RCURL66=null; + CTFParser.structOrVariantDeclarationList_return structOrVariantDeclarationList65 = null; + + + CommonTree LCURL64_tree=null; + CommonTree RCURL66_tree=null; + RewriteRuleTokenStream stream_LCURL=new RewriteRuleTokenStream(adaptor,"token LCURL"); + RewriteRuleTokenStream stream_RCURL=new RewriteRuleTokenStream(adaptor,"token RCURL"); + RewriteRuleSubtreeStream stream_structOrVariantDeclarationList=new RewriteRuleSubtreeStream(adaptor,"rule structOrVariantDeclarationList"); + + enter("structBody"); + debug_print("Scope push " + Symbols_stack.size()); + ((Symbols_scope)Symbols_stack.peek()).types = new HashSet(); + + try { + // Grammar/CTFParser.g:440:1: ( LCURL ( structOrVariantDeclarationList )? RCURL -> ^( STRUCT_BODY ( structOrVariantDeclarationList )? ) ) + // Grammar/CTFParser.g:441:3: LCURL ( structOrVariantDeclarationList )? RCURL + { + LCURL64=(Token)match(input,LCURL,FOLLOW_LCURL_in_structBody1223); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_LCURL.add(LCURL64); + + // Grammar/CTFParser.g:441:9: ( structOrVariantDeclarationList )? + int alt18=2; + int LA18_0 = input.LA(1); + + if ( ((LA18_0>=CONSTTOK && LA18_0<=ENUMTOK)||(LA18_0>=FLOATINGPOINTTOK && LA18_0<=SIGNEDTOK)||(LA18_0>=STRINGTOK && LA18_0<=STRUCTTOK)||(LA18_0>=TYPEDEFTOK && LA18_0<=IMAGINARYTOK)) ) { + alt18=1; + } + else if ( (LA18_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt18=1; + } + else if ( (LA18_0==TYPEALIASTOK) ) { + alt18=1; + } + switch (alt18) { + case 1 : + // Grammar/CTFParser.g:441:9: structOrVariantDeclarationList + { + pushFollow(FOLLOW_structOrVariantDeclarationList_in_structBody1225); + structOrVariantDeclarationList65=structOrVariantDeclarationList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structOrVariantDeclarationList.add(structOrVariantDeclarationList65.getTree()); + + } + break; + + } + + RCURL66=(Token)match(input,RCURL,FOLLOW_RCURL_in_structBody1228); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_RCURL.add(RCURL66); + + + + // AST REWRITE + // elements: structOrVariantDeclarationList + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 441:47: -> ^( STRUCT_BODY ( structOrVariantDeclarationList )? ) + { + // Grammar/CTFParser.g:441:50: ^( STRUCT_BODY ( structOrVariantDeclarationList )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(STRUCT_BODY, "STRUCT_BODY"), root_1); + + // Grammar/CTFParser.g:441:64: ( structOrVariantDeclarationList )? + if ( stream_structOrVariantDeclarationList.hasNext() ) { + adaptor.addChild(root_1, stream_structOrVariantDeclarationList.nextTree()); + + } + stream_structOrVariantDeclarationList.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print("Scope pop " + Symbols_stack.size()); + exit("structBody"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + Symbols_stack.pop(); + + } + return retval; + } + // $ANTLR end "structBody" + + public static class structSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structSpecifier" + // Grammar/CTFParser.g:446:1: structSpecifier : STRUCTTOK ( ( structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) ) | ( structBody ( alignAttribute | ) ) ) -> ^( STRUCT ( structName )? ( structBody )? ( alignAttribute )? ) ; + public final CTFParser.structSpecifier_return structSpecifier() throws RecognitionException { + CTFParser.structSpecifier_return retval = new CTFParser.structSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token STRUCTTOK67=null; + CTFParser.structName_return structName68 = null; + + CTFParser.alignAttribute_return alignAttribute69 = null; + + CTFParser.structBody_return structBody70 = null; + + CTFParser.alignAttribute_return alignAttribute71 = null; + + CTFParser.structBody_return structBody72 = null; + + CTFParser.alignAttribute_return alignAttribute73 = null; + + + CommonTree STRUCTTOK67_tree=null; + RewriteRuleTokenStream stream_STRUCTTOK=new RewriteRuleTokenStream(adaptor,"token STRUCTTOK"); + RewriteRuleSubtreeStream stream_structName=new RewriteRuleSubtreeStream(adaptor,"rule structName"); + RewriteRuleSubtreeStream stream_structBody=new RewriteRuleSubtreeStream(adaptor,"rule structBody"); + RewriteRuleSubtreeStream stream_alignAttribute=new RewriteRuleSubtreeStream(adaptor,"rule alignAttribute"); + + enter("structSpecifier"); + + try { + // Grammar/CTFParser.g:453:1: ( STRUCTTOK ( ( structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) ) | ( structBody ( alignAttribute | ) ) ) -> ^( STRUCT ( structName )? ( structBody )? ( alignAttribute )? ) ) + // Grammar/CTFParser.g:454:3: STRUCTTOK ( ( structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) ) | ( structBody ( alignAttribute | ) ) ) + { + STRUCTTOK67=(Token)match(input,STRUCTTOK,FOLLOW_STRUCTTOK_in_structSpecifier1266); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_STRUCTTOK.add(STRUCTTOK67); + + // Grammar/CTFParser.g:455:3: ( ( structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) ) | ( structBody ( alignAttribute | ) ) ) + int alt22=2; + int LA22_0 = input.LA(1); + + if ( (LA22_0==IDENTIFIER) ) { + alt22=1; + } + else if ( (LA22_0==LCURL) ) { + alt22=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 22, 0, input); + + throw nvae; + } + switch (alt22) { + case 1 : + // Grammar/CTFParser.g:457:5: ( structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) ) + { + // Grammar/CTFParser.g:457:5: ( structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) ) + // Grammar/CTFParser.g:458:6: structName ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) + { + pushFollow(FOLLOW_structName_in_structSpecifier1288); + structName68=structName(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structName.add(structName68.getTree()); + // Grammar/CTFParser.g:459:6: ( alignAttribute | ( structBody ( alignAttribute | ) ) | ) + int alt20=3; + switch ( input.LA(1) ) { + case ALIGNTOK: + { + alt20=1; + } + break; + case LCURL: + { + switch ( input.LA(2) ) { + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case STRUCTTOK: + case TYPEALIASTOK: + case TYPEDEFTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + case RCURL: + { + alt20=2; + } + break; + case SIGNEDTOK: + { + int LA20_5 = input.LA(3); + + if ( ((LA20_5>=CONSTTOK && LA20_5<=ENUMTOK)||(LA20_5>=FLOATINGPOINTTOK && LA20_5<=SIGNEDTOK)||(LA20_5>=STRINGTOK && LA20_5<=STRUCTTOK)||(LA20_5>=TYPEDEFTOK && LA20_5<=IMAGINARYTOK)||LA20_5==POINTER||LA20_5==IDENTIFIER) ) { + alt20=2; + } + else if ( (LA20_5==SEPARATOR||LA20_5==ASSIGNMENT||LA20_5==RCURL) ) { + alt20=3; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 20, 5, input); + + throw nvae; + } + } + break; + case STRINGTOK: + { + int LA20_6 = input.LA(3); + + if ( ((LA20_6>=CONSTTOK && LA20_6<=ENUMTOK)||(LA20_6>=FLOATINGPOINTTOK && LA20_6<=SIGNEDTOK)||(LA20_6>=STRINGTOK && LA20_6<=STRUCTTOK)||(LA20_6>=TYPEDEFTOK && LA20_6<=IMAGINARYTOK)||LA20_6==LCURL||LA20_6==POINTER||LA20_6==IDENTIFIER) ) { + alt20=2; + } + else if ( (LA20_6==SEPARATOR||LA20_6==ASSIGNMENT||LA20_6==RCURL) ) { + alt20=3; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 20, 6, input); + + throw nvae; + } + } + break; + case IDENTIFIER: + { + int LA20_7 = input.LA(3); + + if ( (LA20_7==SEPARATOR||LA20_7==ASSIGNMENT||LA20_7==RCURL) ) { + alt20=3; + } + else if ( ((LA20_7>=CONSTTOK && LA20_7<=ENUMTOK)||(LA20_7>=FLOATINGPOINTTOK && LA20_7<=SIGNEDTOK)||(LA20_7>=STRINGTOK && LA20_7<=STRUCTTOK)||(LA20_7>=TYPEDEFTOK && LA20_7<=IMAGINARYTOK)||LA20_7==POINTER||LA20_7==IDENTIFIER) ) { + alt20=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 20, 7, input); + + throw nvae; + } + } + break; + case ALIGNTOK: + case EVENTTOK: + case STRING_LITERAL: + { + alt20=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 20, 2, input); + + throw nvae; + } + + } + break; + case EOF: + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case SIGNEDTOK: + case STRINGTOK: + case STRUCTTOK: + case TYPEDEFTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + case TYPE_ASSIGNMENT: + case LPAREN: + case TERM: + case POINTER: + case IDENTIFIER: + { + alt20=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 20, 0, input); + + throw nvae; + } + + switch (alt20) { + case 1 : + // Grammar/CTFParser.g:460:8: alignAttribute + { + pushFollow(FOLLOW_alignAttribute_in_structSpecifier1304); + alignAttribute69=alignAttribute(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_alignAttribute.add(alignAttribute69.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:462:8: ( structBody ( alignAttribute | ) ) + { + // Grammar/CTFParser.g:462:8: ( structBody ( alignAttribute | ) ) + // Grammar/CTFParser.g:463:10: structBody ( alignAttribute | ) + { + pushFollow(FOLLOW_structBody_in_structSpecifier1333); + structBody70=structBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structBody.add(structBody70.getTree()); + // Grammar/CTFParser.g:464:10: ( alignAttribute | ) + int alt19=2; + int LA19_0 = input.LA(1); + + if ( (LA19_0==ALIGNTOK) ) { + alt19=1; + } + else if ( (LA19_0==EOF||(LA19_0>=CONSTTOK && LA19_0<=ENUMTOK)||(LA19_0>=FLOATINGPOINTTOK && LA19_0<=SIGNEDTOK)||(LA19_0>=STRINGTOK && LA19_0<=STRUCTTOK)||(LA19_0>=TYPEDEFTOK && LA19_0<=IMAGINARYTOK)||LA19_0==TYPE_ASSIGNMENT||LA19_0==LPAREN||LA19_0==LCURL||(LA19_0>=TERM && LA19_0<=POINTER)||LA19_0==IDENTIFIER) ) { + alt19=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 19, 0, input); + + throw nvae; + } + switch (alt19) { + case 1 : + // Grammar/CTFParser.g:465:11: alignAttribute + { + pushFollow(FOLLOW_alignAttribute_in_structSpecifier1358); + alignAttribute71=alignAttribute(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_alignAttribute.add(alignAttribute71.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:468:10: + { + } + break; + + } + + + } + + + } + break; + case 3 : + // Grammar/CTFParser.g:472:6: + { + } + break; + + } + + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:476:5: ( structBody ( alignAttribute | ) ) + { + // Grammar/CTFParser.g:476:5: ( structBody ( alignAttribute | ) ) + // Grammar/CTFParser.g:477:7: structBody ( alignAttribute | ) + { + pushFollow(FOLLOW_structBody_in_structSpecifier1456); + structBody72=structBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structBody.add(structBody72.getTree()); + // Grammar/CTFParser.g:478:7: ( alignAttribute | ) + int alt21=2; + int LA21_0 = input.LA(1); + + if ( (LA21_0==ALIGNTOK) ) { + alt21=1; + } + else if ( (LA21_0==EOF||(LA21_0>=CONSTTOK && LA21_0<=ENUMTOK)||(LA21_0>=FLOATINGPOINTTOK && LA21_0<=SIGNEDTOK)||(LA21_0>=STRINGTOK && LA21_0<=STRUCTTOK)||(LA21_0>=TYPEDEFTOK && LA21_0<=IMAGINARYTOK)||LA21_0==TYPE_ASSIGNMENT||LA21_0==LPAREN||LA21_0==LCURL||(LA21_0>=TERM && LA21_0<=POINTER)||LA21_0==IDENTIFIER) ) { + alt21=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 21, 0, input); + + throw nvae; + } + switch (alt21) { + case 1 : + // Grammar/CTFParser.g:479:9: alignAttribute + { + pushFollow(FOLLOW_alignAttribute_in_structSpecifier1474); + alignAttribute73=alignAttribute(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_alignAttribute.add(alignAttribute73.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:482:7: + { + } + break; + + } + + + } + + + } + break; + + } + + + + // AST REWRITE + // elements: alignAttribute, structName, structBody + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 484:5: -> ^( STRUCT ( structName )? ( structBody )? ( alignAttribute )? ) + { + // Grammar/CTFParser.g:484:8: ^( STRUCT ( structName )? ( structBody )? ( alignAttribute )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(STRUCT, "STRUCT"), root_1); + + // Grammar/CTFParser.g:484:17: ( structName )? + if ( stream_structName.hasNext() ) { + adaptor.addChild(root_1, stream_structName.nextTree()); + + } + stream_structName.reset(); + // Grammar/CTFParser.g:484:29: ( structBody )? + if ( stream_structBody.hasNext() ) { + adaptor.addChild(root_1, stream_structBody.nextTree()); + + } + stream_structBody.reset(); + // Grammar/CTFParser.g:484:41: ( alignAttribute )? + if ( stream_alignAttribute.hasNext() ) { + adaptor.addChild(root_1, stream_alignAttribute.nextTree()); + + } + stream_alignAttribute.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("structSpecifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "structSpecifier" + + public static class structName_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structName" + // Grammar/CTFParser.g:487:1: structName : IDENTIFIER -> ^( STRUCT_NAME IDENTIFIER ) ; + public final CTFParser.structName_return structName() throws RecognitionException { + CTFParser.structName_return retval = new CTFParser.structName_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER74=null; + + CommonTree IDENTIFIER74_tree=null; + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + + + enter("structName"); + + try { + // Grammar/CTFParser.g:495:1: ( IDENTIFIER -> ^( STRUCT_NAME IDENTIFIER ) ) + // Grammar/CTFParser.g:496:3: IDENTIFIER + { + IDENTIFIER74=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_structName1550); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER74); + + + + // AST REWRITE + // elements: IDENTIFIER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 496:14: -> ^( STRUCT_NAME IDENTIFIER ) + { + // Grammar/CTFParser.g:496:17: ^( STRUCT_NAME IDENTIFIER ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(STRUCT_NAME, "STRUCT_NAME"), root_1); + + adaptor.addChild(root_1, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("structName"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "structName" + + public static class structOrVariantDeclarationList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structOrVariantDeclarationList" + // Grammar/CTFParser.g:499:1: structOrVariantDeclarationList : ( structOrVariantDeclaration )+ ; + public final CTFParser.structOrVariantDeclarationList_return structOrVariantDeclarationList() throws RecognitionException { + CTFParser.structOrVariantDeclarationList_return retval = new CTFParser.structOrVariantDeclarationList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.structOrVariantDeclaration_return structOrVariantDeclaration75 = null; + + + + + enter("structOrVariantDeclarationList"); + + try { + // Grammar/CTFParser.g:506:1: ( ( structOrVariantDeclaration )+ ) + // Grammar/CTFParser.g:507:3: ( structOrVariantDeclaration )+ + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:507:3: ( structOrVariantDeclaration )+ + int cnt23=0; + loop23: + do { + int alt23=2; + int LA23_0 = input.LA(1); + + if ( ((LA23_0>=CONSTTOK && LA23_0<=ENUMTOK)||(LA23_0>=FLOATINGPOINTTOK && LA23_0<=SIGNEDTOK)||(LA23_0>=STRINGTOK && LA23_0<=STRUCTTOK)||(LA23_0>=TYPEDEFTOK && LA23_0<=IMAGINARYTOK)) ) { + alt23=1; + } + else if ( (LA23_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt23=1; + } + else if ( (LA23_0==TYPEALIASTOK) ) { + alt23=1; + } + + + switch (alt23) { + case 1 : + // Grammar/CTFParser.g:507:3: structOrVariantDeclaration + { + pushFollow(FOLLOW_structOrVariantDeclaration_in_structOrVariantDeclarationList1581); + structOrVariantDeclaration75=structOrVariantDeclaration(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, structOrVariantDeclaration75.getTree()); + + } + break; + + default : + if ( cnt23 >= 1 ) break loop23; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(23, input); + throw eee; + } + cnt23++; + } while (true); + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("structOrVariantDeclarationList"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "structOrVariantDeclarationList" + + public static class structOrVariantDeclaration_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structOrVariantDeclaration" + // Grammar/CTFParser.g:510:1: structOrVariantDeclaration : ( ( declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) ) | typealiasDecl -> typealiasDecl ) TERM ; + public final CTFParser.structOrVariantDeclaration_return structOrVariantDeclaration() throws RecognitionException { + CTFParser.structOrVariantDeclaration_return retval = new CTFParser.structOrVariantDeclaration_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token TERM80=null; + CTFParser.declarationSpecifiers_return declarationSpecifiers76 = null; + + CTFParser.declaratorList_return declaratorList77 = null; + + CTFParser.structOrVariantDeclaratorList_return structOrVariantDeclaratorList78 = null; + + CTFParser.typealiasDecl_return typealiasDecl79 = null; + + + CommonTree TERM80_tree=null; + RewriteRuleTokenStream stream_TERM=new RewriteRuleTokenStream(adaptor,"token TERM"); + RewriteRuleSubtreeStream stream_declaratorList=new RewriteRuleSubtreeStream(adaptor,"rule declaratorList"); + RewriteRuleSubtreeStream stream_typealiasDecl=new RewriteRuleSubtreeStream(adaptor,"rule typealiasDecl"); + RewriteRuleSubtreeStream stream_declarationSpecifiers=new RewriteRuleSubtreeStream(adaptor,"rule declarationSpecifiers"); + RewriteRuleSubtreeStream stream_structOrVariantDeclaratorList=new RewriteRuleSubtreeStream(adaptor,"rule structOrVariantDeclaratorList"); + + enter("structOrVariantDeclaration"); + + try { + // Grammar/CTFParser.g:517:1: ( ( ( declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) ) | typealiasDecl -> typealiasDecl ) TERM ) + // Grammar/CTFParser.g:518:3: ( ( declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) ) | typealiasDecl -> typealiasDecl ) TERM + { + // Grammar/CTFParser.g:518:3: ( ( declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) ) | typealiasDecl -> typealiasDecl ) + int alt25=2; + int LA25_0 = input.LA(1); + + if ( ((LA25_0>=CONSTTOK && LA25_0<=ENUMTOK)||(LA25_0>=FLOATINGPOINTTOK && LA25_0<=SIGNEDTOK)||(LA25_0>=STRINGTOK && LA25_0<=STRUCTTOK)||(LA25_0>=TYPEDEFTOK && LA25_0<=IMAGINARYTOK)) ) { + alt25=1; + } + else if ( (LA25_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt25=1; + } + else if ( (LA25_0==TYPEALIASTOK) ) { + alt25=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 25, 0, input); + + throw nvae; + } + switch (alt25) { + case 1 : + // Grammar/CTFParser.g:519:4: ( declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) ) + { + // Grammar/CTFParser.g:519:4: ( declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) ) + // Grammar/CTFParser.g:520:5: declarationSpecifiers ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) + { + pushFollow(FOLLOW_declarationSpecifiers_in_structOrVariantDeclaration1619); + declarationSpecifiers76=declarationSpecifiers(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarationSpecifiers.add(declarationSpecifiers76.getTree()); + // Grammar/CTFParser.g:521:7: ({...}? => declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) ) + int alt24=2; + alt24 = dfa24.predict(input); + switch (alt24) { + case 1 : + // Grammar/CTFParser.g:523:9: {...}? => declaratorList + { + if ( !((inTypedef())) ) { + if (state.backtracking>0) {state.failed=true; return retval;} + throw new FailedPredicateException(input, "structOrVariantDeclaration", "inTypedef()"); + } + pushFollow(FOLLOW_declaratorList_in_structOrVariantDeclaration1651); + declaratorList77=declaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declaratorList.add(declaratorList77.getTree()); + if ( state.backtracking==0 ) { + typedefOff(); + } + + + // AST REWRITE + // elements: declarationSpecifiers, declaratorList + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 524:11: -> ^( TYPEDEF declaratorList declarationSpecifiers ) + { + // Grammar/CTFParser.g:524:14: ^( TYPEDEF declaratorList declarationSpecifiers ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPEDEF, "TYPEDEF"), root_1); + + adaptor.addChild(root_1, stream_declaratorList.nextTree()); + adaptor.addChild(root_1, stream_declarationSpecifiers.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:525:11: structOrVariantDeclaratorList + { + pushFollow(FOLLOW_structOrVariantDeclaratorList_in_structOrVariantDeclaration1685); + structOrVariantDeclaratorList78=structOrVariantDeclaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structOrVariantDeclaratorList.add(structOrVariantDeclaratorList78.getTree()); + + + // AST REWRITE + // elements: structOrVariantDeclaratorList, declarationSpecifiers + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 526:11: -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) + { + // Grammar/CTFParser.g:526:14: ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(SV_DECLARATION, "SV_DECLARATION"), root_1); + + adaptor.addChild(root_1, stream_declarationSpecifiers.nextTree()); + adaptor.addChild(root_1, stream_structOrVariantDeclaratorList.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:531:5: typealiasDecl + { + pushFollow(FOLLOW_typealiasDecl_in_structOrVariantDeclaration1735); + typealiasDecl79=typealiasDecl(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typealiasDecl.add(typealiasDecl79.getTree()); + + + // AST REWRITE + // elements: typealiasDecl + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 531:19: -> typealiasDecl + { + adaptor.addChild(root_0, stream_typealiasDecl.nextTree()); + + } + + retval.tree = root_0;} + } + break; + + } + + TERM80=(Token)match(input,TERM,FOLLOW_TERM_in_structOrVariantDeclaration1747); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_TERM.add(TERM80); + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("structOrVariantDeclaration"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "structOrVariantDeclaration" + + public static class specifierQualifierList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "specifierQualifierList" + // Grammar/CTFParser.g:536:1: specifierQualifierList : ( typeQualifier | typeSpecifier )+ -> ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) ; + public final CTFParser.specifierQualifierList_return specifierQualifierList() throws RecognitionException { + CTFParser.specifierQualifierList_return retval = new CTFParser.specifierQualifierList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.typeQualifier_return typeQualifier81 = null; + + CTFParser.typeSpecifier_return typeSpecifier82 = null; + + + RewriteRuleSubtreeStream stream_typeSpecifier=new RewriteRuleSubtreeStream(adaptor,"rule typeSpecifier"); + RewriteRuleSubtreeStream stream_typeQualifier=new RewriteRuleSubtreeStream(adaptor,"rule typeQualifier"); + + enter("specifierQualifierList"); + + try { + // Grammar/CTFParser.g:543:1: ( ( typeQualifier | typeSpecifier )+ -> ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) ) + // Grammar/CTFParser.g:544:3: ( typeQualifier | typeSpecifier )+ + { + // Grammar/CTFParser.g:544:3: ( typeQualifier | typeSpecifier )+ + int cnt26=0; + loop26: + do { + int alt26=3; + int LA26_0 = input.LA(1); + + if ( (LA26_0==CONSTTOK) ) { + alt26=1; + } + else if ( ((LA26_0>=CHARTOK && LA26_0<=ENUMTOK)||(LA26_0>=FLOATINGPOINTTOK && LA26_0<=SIGNEDTOK)||(LA26_0>=STRINGTOK && LA26_0<=STRUCTTOK)||(LA26_0>=UNSIGNEDTOK && LA26_0<=IMAGINARYTOK)) ) { + alt26=2; + } + else if ( (LA26_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt26=2; + } + + + switch (alt26) { + case 1 : + // Grammar/CTFParser.g:544:4: typeQualifier + { + pushFollow(FOLLOW_typeQualifier_in_specifierQualifierList1771); + typeQualifier81=typeQualifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typeQualifier.add(typeQualifier81.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:544:20: typeSpecifier + { + pushFollow(FOLLOW_typeSpecifier_in_specifierQualifierList1775); + typeSpecifier82=typeSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typeSpecifier.add(typeSpecifier82.getTree()); + + } + break; + + default : + if ( cnt26 >= 1 ) break loop26; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(26, input); + throw eee; + } + cnt26++; + } while (true); + + + + // AST REWRITE + // elements: typeSpecifier, typeQualifier + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 544:36: -> ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) + { + // Grammar/CTFParser.g:544:39: ^( TYPE_SPECIFIER_LIST ( typeQualifier )* ( typeSpecifier )* ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_SPECIFIER_LIST, "TYPE_SPECIFIER_LIST"), root_1); + + // Grammar/CTFParser.g:544:61: ( typeQualifier )* + while ( stream_typeQualifier.hasNext() ) { + adaptor.addChild(root_1, stream_typeQualifier.nextTree()); + + } + stream_typeQualifier.reset(); + // Grammar/CTFParser.g:544:76: ( typeSpecifier )* + while ( stream_typeSpecifier.hasNext() ) { + adaptor.addChild(root_1, stream_typeSpecifier.nextTree()); + + } + stream_typeSpecifier.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("specifierQualifierList"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "specifierQualifierList" + + public static class structOrVariantDeclaratorList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structOrVariantDeclaratorList" + // Grammar/CTFParser.g:547:1: structOrVariantDeclaratorList : structOrVariantDeclarator ( SEPARATOR structOrVariantDeclarator )* -> ^( TYPE_DECLARATOR_LIST ( structOrVariantDeclarator )+ ) ; + public final CTFParser.structOrVariantDeclaratorList_return structOrVariantDeclaratorList() throws RecognitionException { + CTFParser.structOrVariantDeclaratorList_return retval = new CTFParser.structOrVariantDeclaratorList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token SEPARATOR84=null; + CTFParser.structOrVariantDeclarator_return structOrVariantDeclarator83 = null; + + CTFParser.structOrVariantDeclarator_return structOrVariantDeclarator85 = null; + + + CommonTree SEPARATOR84_tree=null; + RewriteRuleTokenStream stream_SEPARATOR=new RewriteRuleTokenStream(adaptor,"token SEPARATOR"); + RewriteRuleSubtreeStream stream_structOrVariantDeclarator=new RewriteRuleSubtreeStream(adaptor,"rule structOrVariantDeclarator"); + + enter("structOrVariantDeclaratorList"); + + try { + // Grammar/CTFParser.g:554:1: ( structOrVariantDeclarator ( SEPARATOR structOrVariantDeclarator )* -> ^( TYPE_DECLARATOR_LIST ( structOrVariantDeclarator )+ ) ) + // Grammar/CTFParser.g:555:3: structOrVariantDeclarator ( SEPARATOR structOrVariantDeclarator )* + { + pushFollow(FOLLOW_structOrVariantDeclarator_in_structOrVariantDeclaratorList1812); + structOrVariantDeclarator83=structOrVariantDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structOrVariantDeclarator.add(structOrVariantDeclarator83.getTree()); + // Grammar/CTFParser.g:555:29: ( SEPARATOR structOrVariantDeclarator )* + loop27: + do { + int alt27=2; + int LA27_0 = input.LA(1); + + if ( (LA27_0==SEPARATOR) ) { + alt27=1; + } + + + switch (alt27) { + case 1 : + // Grammar/CTFParser.g:555:30: SEPARATOR structOrVariantDeclarator + { + SEPARATOR84=(Token)match(input,SEPARATOR,FOLLOW_SEPARATOR_in_structOrVariantDeclaratorList1815); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_SEPARATOR.add(SEPARATOR84); + + pushFollow(FOLLOW_structOrVariantDeclarator_in_structOrVariantDeclaratorList1817); + structOrVariantDeclarator85=structOrVariantDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structOrVariantDeclarator.add(structOrVariantDeclarator85.getTree()); + + } + break; + + default : + break loop27; + } + } while (true); + + + + // AST REWRITE + // elements: structOrVariantDeclarator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 555:68: -> ^( TYPE_DECLARATOR_LIST ( structOrVariantDeclarator )+ ) + { + // Grammar/CTFParser.g:555:71: ^( TYPE_DECLARATOR_LIST ( structOrVariantDeclarator )+ ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_DECLARATOR_LIST, "TYPE_DECLARATOR_LIST"), root_1); + + if ( !(stream_structOrVariantDeclarator.hasNext()) ) { + throw new RewriteEarlyExitException(); + } + while ( stream_structOrVariantDeclarator.hasNext() ) { + adaptor.addChild(root_1, stream_structOrVariantDeclarator.nextTree()); + + } + stream_structOrVariantDeclarator.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("structOrVariantDeclaratorList"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "structOrVariantDeclaratorList" + + public static class structOrVariantDeclarator_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "structOrVariantDeclarator" + // Grammar/CTFParser.g:558:1: structOrVariantDeclarator : ( declarator ( COLON numberLiteral )? ) -> declarator ; + public final CTFParser.structOrVariantDeclarator_return structOrVariantDeclarator() throws RecognitionException { + CTFParser.structOrVariantDeclarator_return retval = new CTFParser.structOrVariantDeclarator_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token COLON87=null; + CTFParser.declarator_return declarator86 = null; + + CTFParser.numberLiteral_return numberLiteral88 = null; + + + CommonTree COLON87_tree=null; + RewriteRuleTokenStream stream_COLON=new RewriteRuleTokenStream(adaptor,"token COLON"); + RewriteRuleSubtreeStream stream_declarator=new RewriteRuleSubtreeStream(adaptor,"rule declarator"); + RewriteRuleSubtreeStream stream_numberLiteral=new RewriteRuleSubtreeStream(adaptor,"rule numberLiteral"); + + enter("structOrVariantDeclarator"); + + try { + // Grammar/CTFParser.g:565:1: ( ( declarator ( COLON numberLiteral )? ) -> declarator ) + // Grammar/CTFParser.g:567:5: ( declarator ( COLON numberLiteral )? ) + { + // Grammar/CTFParser.g:567:5: ( declarator ( COLON numberLiteral )? ) + // Grammar/CTFParser.g:567:6: declarator ( COLON numberLiteral )? + { + pushFollow(FOLLOW_declarator_in_structOrVariantDeclarator1858); + declarator86=declarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarator.add(declarator86.getTree()); + // Grammar/CTFParser.g:567:17: ( COLON numberLiteral )? + int alt28=2; + int LA28_0 = input.LA(1); + + if ( (LA28_0==COLON) ) { + alt28=1; + } + switch (alt28) { + case 1 : + // Grammar/CTFParser.g:567:18: COLON numberLiteral + { + COLON87=(Token)match(input,COLON,FOLLOW_COLON_in_structOrVariantDeclarator1861); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_COLON.add(COLON87); + + pushFollow(FOLLOW_numberLiteral_in_structOrVariantDeclarator1863); + numberLiteral88=numberLiteral(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_numberLiteral.add(numberLiteral88.getTree()); + + } + break; + + } + + + } + + + + // AST REWRITE + // elements: declarator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 567:41: -> declarator + { + adaptor.addChild(root_0, stream_declarator.nextTree()); + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("structOrVariantDeclarator"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "structOrVariantDeclarator" + + public static class variantSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "variantSpecifier" + // Grammar/CTFParser.g:571:1: variantSpecifier : VARIANTTOK ( ( variantName ( ( variantTag ( variantBody | ) ) | variantBody ) ) | ( variantTag variantBody ) | variantBody ) -> ^( VARIANT ( variantName )? ( variantTag )? ( variantBody )? ) ; + public final CTFParser.variantSpecifier_return variantSpecifier() throws RecognitionException { + CTFParser.variantSpecifier_return retval = new CTFParser.variantSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token VARIANTTOK89=null; + CTFParser.variantName_return variantName90 = null; + + CTFParser.variantTag_return variantTag91 = null; + + CTFParser.variantBody_return variantBody92 = null; + + CTFParser.variantBody_return variantBody93 = null; + + CTFParser.variantTag_return variantTag94 = null; + + CTFParser.variantBody_return variantBody95 = null; + + CTFParser.variantBody_return variantBody96 = null; + + + CommonTree VARIANTTOK89_tree=null; + RewriteRuleTokenStream stream_VARIANTTOK=new RewriteRuleTokenStream(adaptor,"token VARIANTTOK"); + RewriteRuleSubtreeStream stream_variantName=new RewriteRuleSubtreeStream(adaptor,"rule variantName"); + RewriteRuleSubtreeStream stream_variantTag=new RewriteRuleSubtreeStream(adaptor,"rule variantTag"); + RewriteRuleSubtreeStream stream_variantBody=new RewriteRuleSubtreeStream(adaptor,"rule variantBody"); + + enter("variantSpecifier"); + + try { + // Grammar/CTFParser.g:578:1: ( VARIANTTOK ( ( variantName ( ( variantTag ( variantBody | ) ) | variantBody ) ) | ( variantTag variantBody ) | variantBody ) -> ^( VARIANT ( variantName )? ( variantTag )? ( variantBody )? ) ) + // Grammar/CTFParser.g:579:3: VARIANTTOK ( ( variantName ( ( variantTag ( variantBody | ) ) | variantBody ) ) | ( variantTag variantBody ) | variantBody ) + { + VARIANTTOK89=(Token)match(input,VARIANTTOK,FOLLOW_VARIANTTOK_in_variantSpecifier1897); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_VARIANTTOK.add(VARIANTTOK89); + + // Grammar/CTFParser.g:580:3: ( ( variantName ( ( variantTag ( variantBody | ) ) | variantBody ) ) | ( variantTag variantBody ) | variantBody ) + int alt31=3; + switch ( input.LA(1) ) { + case IDENTIFIER: + { + alt31=1; + } + break; + case LT: + { + alt31=2; + } + break; + case LCURL: + { + alt31=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 31, 0, input); + + throw nvae; + } + + switch (alt31) { + case 1 : + // Grammar/CTFParser.g:581:5: ( variantName ( ( variantTag ( variantBody | ) ) | variantBody ) ) + { + // Grammar/CTFParser.g:581:5: ( variantName ( ( variantTag ( variantBody | ) ) | variantBody ) ) + // Grammar/CTFParser.g:582:7: variantName ( ( variantTag ( variantBody | ) ) | variantBody ) + { + pushFollow(FOLLOW_variantName_in_variantSpecifier1915); + variantName90=variantName(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantName.add(variantName90.getTree()); + // Grammar/CTFParser.g:583:7: ( ( variantTag ( variantBody | ) ) | variantBody ) + int alt30=2; + int LA30_0 = input.LA(1); + + if ( (LA30_0==LT) ) { + alt30=1; + } + else if ( (LA30_0==LCURL) ) { + alt30=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 30, 0, input); + + throw nvae; + } + switch (alt30) { + case 1 : + // Grammar/CTFParser.g:584:9: ( variantTag ( variantBody | ) ) + { + // Grammar/CTFParser.g:584:9: ( variantTag ( variantBody | ) ) + // Grammar/CTFParser.g:585:11: variantTag ( variantBody | ) + { + pushFollow(FOLLOW_variantTag_in_variantSpecifier1946); + variantTag91=variantTag(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantTag.add(variantTag91.getTree()); + // Grammar/CTFParser.g:586:11: ( variantBody | ) + int alt29=2; + int LA29_0 = input.LA(1); + + if ( (LA29_0==LCURL) ) { + switch ( input.LA(2) ) { + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case STRUCTTOK: + case TYPEALIASTOK: + case TYPEDEFTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + { + alt29=1; + } + break; + case SIGNEDTOK: + { + int LA29_4 = input.LA(3); + + if ( ((LA29_4>=CONSTTOK && LA29_4<=ENUMTOK)||(LA29_4>=FLOATINGPOINTTOK && LA29_4<=SIGNEDTOK)||(LA29_4>=STRINGTOK && LA29_4<=STRUCTTOK)||(LA29_4>=TYPEDEFTOK && LA29_4<=IMAGINARYTOK)||LA29_4==POINTER||LA29_4==IDENTIFIER) ) { + alt29=1; + } + else if ( (LA29_4==SEPARATOR||LA29_4==ASSIGNMENT||LA29_4==RCURL) ) { + alt29=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 29, 4, input); + + throw nvae; + } + } + break; + case STRINGTOK: + { + int LA29_5 = input.LA(3); + + if ( (LA29_5==SEPARATOR||LA29_5==ASSIGNMENT||LA29_5==RCURL) ) { + alt29=2; + } + else if ( ((LA29_5>=CONSTTOK && LA29_5<=ENUMTOK)||(LA29_5>=FLOATINGPOINTTOK && LA29_5<=SIGNEDTOK)||(LA29_5>=STRINGTOK && LA29_5<=STRUCTTOK)||(LA29_5>=TYPEDEFTOK && LA29_5<=IMAGINARYTOK)||LA29_5==LCURL||LA29_5==POINTER||LA29_5==IDENTIFIER) ) { + alt29=1; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 29, 5, input); + + throw nvae; + } + } + break; + case IDENTIFIER: + { + int LA29_6 = input.LA(3); + + if ( (LA29_6==SEPARATOR||LA29_6==ASSIGNMENT||LA29_6==RCURL) ) { + alt29=2; + } + else if ( ((LA29_6>=CONSTTOK && LA29_6<=ENUMTOK)||(LA29_6>=FLOATINGPOINTTOK && LA29_6<=SIGNEDTOK)||(LA29_6>=STRINGTOK && LA29_6<=STRUCTTOK)||(LA29_6>=TYPEDEFTOK && LA29_6<=IMAGINARYTOK)||LA29_6==POINTER||LA29_6==IDENTIFIER) ) { + alt29=1; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 29, 6, input); + + throw nvae; + } + } + break; + case ALIGNTOK: + case EVENTTOK: + case STRING_LITERAL: + { + alt29=2; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 29, 1, input); + + throw nvae; + } + + } + else if ( (LA29_0==EOF||(LA29_0>=CONSTTOK && LA29_0<=ENUMTOK)||(LA29_0>=FLOATINGPOINTTOK && LA29_0<=SIGNEDTOK)||(LA29_0>=STRINGTOK && LA29_0<=STRUCTTOK)||(LA29_0>=TYPEDEFTOK && LA29_0<=IMAGINARYTOK)||LA29_0==TYPE_ASSIGNMENT||LA29_0==LPAREN||(LA29_0>=TERM && LA29_0<=POINTER)||LA29_0==IDENTIFIER) ) { + alt29=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 29, 0, input); + + throw nvae; + } + switch (alt29) { + case 1 : + // Grammar/CTFParser.g:587:13: variantBody + { + pushFollow(FOLLOW_variantBody_in_variantSpecifier1972); + variantBody92=variantBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantBody.add(variantBody92.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:590:11: + { + } + break; + + } + + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:593:9: variantBody + { + pushFollow(FOLLOW_variantBody_in_variantSpecifier2040); + variantBody93=variantBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantBody.add(variantBody93.getTree()); + + } + break; + + } + + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:597:5: ( variantTag variantBody ) + { + // Grammar/CTFParser.g:597:5: ( variantTag variantBody ) + // Grammar/CTFParser.g:597:6: variantTag variantBody + { + pushFollow(FOLLOW_variantTag_in_variantSpecifier2065); + variantTag94=variantTag(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantTag.add(variantTag94.getTree()); + pushFollow(FOLLOW_variantBody_in_variantSpecifier2067); + variantBody95=variantBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantBody.add(variantBody95.getTree()); + + } + + + } + break; + case 3 : + // Grammar/CTFParser.g:599:5: variantBody + { + pushFollow(FOLLOW_variantBody_in_variantSpecifier2078); + variantBody96=variantBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_variantBody.add(variantBody96.getTree()); + + } + break; + + } + + + + // AST REWRITE + // elements: variantBody, variantTag, variantName + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 600:5: -> ^( VARIANT ( variantName )? ( variantTag )? ( variantBody )? ) + { + // Grammar/CTFParser.g:600:8: ^( VARIANT ( variantName )? ( variantTag )? ( variantBody )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(VARIANT, "VARIANT"), root_1); + + // Grammar/CTFParser.g:600:18: ( variantName )? + if ( stream_variantName.hasNext() ) { + adaptor.addChild(root_1, stream_variantName.nextTree()); + + } + stream_variantName.reset(); + // Grammar/CTFParser.g:600:31: ( variantTag )? + if ( stream_variantTag.hasNext() ) { + adaptor.addChild(root_1, stream_variantTag.nextTree()); + + } + stream_variantTag.reset(); + // Grammar/CTFParser.g:600:43: ( variantBody )? + if ( stream_variantBody.hasNext() ) { + adaptor.addChild(root_1, stream_variantBody.nextTree()); + + } + stream_variantBody.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("variantSpecifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "variantSpecifier" + + public static class variantName_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "variantName" + // Grammar/CTFParser.g:603:1: variantName : IDENTIFIER -> ^( VARIANT_NAME IDENTIFIER ) ; + public final CTFParser.variantName_return variantName() throws RecognitionException { + CTFParser.variantName_return retval = new CTFParser.variantName_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER97=null; + + CommonTree IDENTIFIER97_tree=null; + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + + + enter("variantName"); + + try { + // Grammar/CTFParser.g:611:1: ( IDENTIFIER -> ^( VARIANT_NAME IDENTIFIER ) ) + // Grammar/CTFParser.g:612:3: IDENTIFIER + { + IDENTIFIER97=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_variantName2120); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER97); + + + + // AST REWRITE + // elements: IDENTIFIER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 612:14: -> ^( VARIANT_NAME IDENTIFIER ) + { + // Grammar/CTFParser.g:612:17: ^( VARIANT_NAME IDENTIFIER ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(VARIANT_NAME, "VARIANT_NAME"), root_1); + + adaptor.addChild(root_1, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("variantName"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "variantName" + + public static class variantBody_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "variantBody" + // Grammar/CTFParser.g:615:1: variantBody : LCURL structOrVariantDeclarationList RCURL -> ^( VARIANT_BODY structOrVariantDeclarationList ) ; + public final CTFParser.variantBody_return variantBody() throws RecognitionException { + Symbols_stack.push(new Symbols_scope()); + + CTFParser.variantBody_return retval = new CTFParser.variantBody_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token LCURL98=null; + Token RCURL100=null; + CTFParser.structOrVariantDeclarationList_return structOrVariantDeclarationList99 = null; + + + CommonTree LCURL98_tree=null; + CommonTree RCURL100_tree=null; + RewriteRuleTokenStream stream_LCURL=new RewriteRuleTokenStream(adaptor,"token LCURL"); + RewriteRuleTokenStream stream_RCURL=new RewriteRuleTokenStream(adaptor,"token RCURL"); + RewriteRuleSubtreeStream stream_structOrVariantDeclarationList=new RewriteRuleSubtreeStream(adaptor,"rule structOrVariantDeclarationList"); + + enter("variantBody"); + debug_print("Scope push " + Symbols_stack.size()); + ((Symbols_scope)Symbols_stack.peek()).types = new HashSet(); + + try { + // Grammar/CTFParser.g:626:1: ( LCURL structOrVariantDeclarationList RCURL -> ^( VARIANT_BODY structOrVariantDeclarationList ) ) + // Grammar/CTFParser.g:627:3: LCURL structOrVariantDeclarationList RCURL + { + LCURL98=(Token)match(input,LCURL,FOLLOW_LCURL_in_variantBody2156); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_LCURL.add(LCURL98); + + pushFollow(FOLLOW_structOrVariantDeclarationList_in_variantBody2158); + structOrVariantDeclarationList99=structOrVariantDeclarationList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_structOrVariantDeclarationList.add(structOrVariantDeclarationList99.getTree()); + RCURL100=(Token)match(input,RCURL,FOLLOW_RCURL_in_variantBody2160); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_RCURL.add(RCURL100); + + + + // AST REWRITE + // elements: structOrVariantDeclarationList + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 627:46: -> ^( VARIANT_BODY structOrVariantDeclarationList ) + { + // Grammar/CTFParser.g:627:49: ^( VARIANT_BODY structOrVariantDeclarationList ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(VARIANT_BODY, "VARIANT_BODY"), root_1); + + adaptor.addChild(root_1, stream_structOrVariantDeclarationList.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print("Scope pop " + Symbols_stack.size()); + exit("variantBody"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + Symbols_stack.pop(); + + } + return retval; + } + // $ANTLR end "variantBody" + + public static class variantTag_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "variantTag" + // Grammar/CTFParser.g:630:1: variantTag : LT IDENTIFIER GT -> ^( VARIANT_TAG IDENTIFIER ) ; + public final CTFParser.variantTag_return variantTag() throws RecognitionException { + CTFParser.variantTag_return retval = new CTFParser.variantTag_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token LT101=null; + Token IDENTIFIER102=null; + Token GT103=null; + + CommonTree LT101_tree=null; + CommonTree IDENTIFIER102_tree=null; + CommonTree GT103_tree=null; + RewriteRuleTokenStream stream_GT=new RewriteRuleTokenStream(adaptor,"token GT"); + RewriteRuleTokenStream stream_LT=new RewriteRuleTokenStream(adaptor,"token LT"); + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + + + enter("variantTag"); + + try { + // Grammar/CTFParser.g:638:1: ( LT IDENTIFIER GT -> ^( VARIANT_TAG IDENTIFIER ) ) + // Grammar/CTFParser.g:639:3: LT IDENTIFIER GT + { + LT101=(Token)match(input,LT,FOLLOW_LT_in_variantTag2191); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_LT.add(LT101); + + IDENTIFIER102=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_variantTag2193); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER102); + + GT103=(Token)match(input,GT,FOLLOW_GT_in_variantTag2195); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_GT.add(GT103); + + + + // AST REWRITE + // elements: IDENTIFIER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 639:20: -> ^( VARIANT_TAG IDENTIFIER ) + { + // Grammar/CTFParser.g:639:23: ^( VARIANT_TAG IDENTIFIER ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(VARIANT_TAG, "VARIANT_TAG"), root_1); + + adaptor.addChild(root_1, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("variantTag"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "variantTag" + + public static class enumSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumSpecifier" + // Grammar/CTFParser.g:642:1: enumSpecifier : ENUMTOK ( ( enumName ( enumContainerType enumBody | enumBody | ) ) | ( enumContainerType enumBody | enumBody ) ) -> ^( ENUM ( enumName )? ( enumContainerType )? ( enumBody )? ) ; + public final CTFParser.enumSpecifier_return enumSpecifier() throws RecognitionException { + CTFParser.enumSpecifier_return retval = new CTFParser.enumSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token ENUMTOK104=null; + CTFParser.enumName_return enumName105 = null; + + CTFParser.enumContainerType_return enumContainerType106 = null; + + CTFParser.enumBody_return enumBody107 = null; + + CTFParser.enumBody_return enumBody108 = null; + + CTFParser.enumContainerType_return enumContainerType109 = null; + + CTFParser.enumBody_return enumBody110 = null; + + CTFParser.enumBody_return enumBody111 = null; + + + CommonTree ENUMTOK104_tree=null; + RewriteRuleTokenStream stream_ENUMTOK=new RewriteRuleTokenStream(adaptor,"token ENUMTOK"); + RewriteRuleSubtreeStream stream_enumName=new RewriteRuleSubtreeStream(adaptor,"rule enumName"); + RewriteRuleSubtreeStream stream_enumContainerType=new RewriteRuleSubtreeStream(adaptor,"rule enumContainerType"); + RewriteRuleSubtreeStream stream_enumBody=new RewriteRuleSubtreeStream(adaptor,"rule enumBody"); + + enter("enumSpecifier"); + + try { + // Grammar/CTFParser.g:649:1: ( ENUMTOK ( ( enumName ( enumContainerType enumBody | enumBody | ) ) | ( enumContainerType enumBody | enumBody ) ) -> ^( ENUM ( enumName )? ( enumContainerType )? ( enumBody )? ) ) + // Grammar/CTFParser.g:650:2: ENUMTOK ( ( enumName ( enumContainerType enumBody | enumBody | ) ) | ( enumContainerType enumBody | enumBody ) ) + { + ENUMTOK104=(Token)match(input,ENUMTOK,FOLLOW_ENUMTOK_in_enumSpecifier2225); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ENUMTOK.add(ENUMTOK104); + + // Grammar/CTFParser.g:651:2: ( ( enumName ( enumContainerType enumBody | enumBody | ) ) | ( enumContainerType enumBody | enumBody ) ) + int alt34=2; + int LA34_0 = input.LA(1); + + if ( (LA34_0==IDENTIFIER) ) { + alt34=1; + } + else if ( (LA34_0==COLON||LA34_0==LCURL) ) { + alt34=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 34, 0, input); + + throw nvae; + } + switch (alt34) { + case 1 : + // Grammar/CTFParser.g:653:3: ( enumName ( enumContainerType enumBody | enumBody | ) ) + { + // Grammar/CTFParser.g:653:3: ( enumName ( enumContainerType enumBody | enumBody | ) ) + // Grammar/CTFParser.g:654:4: enumName ( enumContainerType enumBody | enumBody | ) + { + pushFollow(FOLLOW_enumName_in_enumSpecifier2240); + enumName105=enumName(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumName.add(enumName105.getTree()); + // Grammar/CTFParser.g:655:4: ( enumContainerType enumBody | enumBody | ) + int alt32=3; + alt32 = dfa32.predict(input); + switch (alt32) { + case 1 : + // Grammar/CTFParser.g:656:5: enumContainerType enumBody + { + pushFollow(FOLLOW_enumContainerType_in_enumSpecifier2251); + enumContainerType106=enumContainerType(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumContainerType.add(enumContainerType106.getTree()); + pushFollow(FOLLOW_enumBody_in_enumSpecifier2253); + enumBody107=enumBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumBody.add(enumBody107.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:658:5: enumBody + { + pushFollow(FOLLOW_enumBody_in_enumSpecifier2265); + enumBody108=enumBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumBody.add(enumBody108.getTree()); + + } + break; + case 3 : + // Grammar/CTFParser.g:661:4: + { + } + break; + + } + + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:665:3: ( enumContainerType enumBody | enumBody ) + { + // Grammar/CTFParser.g:665:3: ( enumContainerType enumBody | enumBody ) + int alt33=2; + int LA33_0 = input.LA(1); + + if ( (LA33_0==COLON) ) { + alt33=1; + } + else if ( (LA33_0==LCURL) ) { + alt33=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 33, 0, input); + + throw nvae; + } + switch (alt33) { + case 1 : + // Grammar/CTFParser.g:666:4: enumContainerType enumBody + { + pushFollow(FOLLOW_enumContainerType_in_enumSpecifier2300); + enumContainerType109=enumContainerType(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumContainerType.add(enumContainerType109.getTree()); + pushFollow(FOLLOW_enumBody_in_enumSpecifier2302); + enumBody110=enumBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumBody.add(enumBody110.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:668:4: enumBody + { + pushFollow(FOLLOW_enumBody_in_enumSpecifier2311); + enumBody111=enumBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumBody.add(enumBody111.getTree()); + + } + break; + + } + + + } + break; + + } + + + + // AST REWRITE + // elements: enumContainerType, enumName, enumBody + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 670:4: -> ^( ENUM ( enumName )? ( enumContainerType )? ( enumBody )? ) + { + // Grammar/CTFParser.g:670:7: ^( ENUM ( enumName )? ( enumContainerType )? ( enumBody )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM, "ENUM"), root_1); + + // Grammar/CTFParser.g:670:14: ( enumName )? + if ( stream_enumName.hasNext() ) { + adaptor.addChild(root_1, stream_enumName.nextTree()); + + } + stream_enumName.reset(); + // Grammar/CTFParser.g:670:24: ( enumContainerType )? + if ( stream_enumContainerType.hasNext() ) { + adaptor.addChild(root_1, stream_enumContainerType.nextTree()); + + } + stream_enumContainerType.reset(); + // Grammar/CTFParser.g:670:43: ( enumBody )? + if ( stream_enumBody.hasNext() ) { + adaptor.addChild(root_1, stream_enumBody.nextTree()); + + } + stream_enumBody.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("enumSpecifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumSpecifier" + + public static class enumName_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumName" + // Grammar/CTFParser.g:673:1: enumName : IDENTIFIER -> ^( ENUM_NAME IDENTIFIER ) ; + public final CTFParser.enumName_return enumName() throws RecognitionException { + CTFParser.enumName_return retval = new CTFParser.enumName_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER112=null; + + CommonTree IDENTIFIER112_tree=null; + RewriteRuleTokenStream stream_IDENTIFIER=new RewriteRuleTokenStream(adaptor,"token IDENTIFIER"); + + + enter("enumName"); + + try { + // Grammar/CTFParser.g:681:1: ( IDENTIFIER -> ^( ENUM_NAME IDENTIFIER ) ) + // Grammar/CTFParser.g:682:3: IDENTIFIER + { + IDENTIFIER112=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_enumName2356); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_IDENTIFIER.add(IDENTIFIER112); + + + + // AST REWRITE + // elements: IDENTIFIER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 682:14: -> ^( ENUM_NAME IDENTIFIER ) + { + // Grammar/CTFParser.g:682:17: ^( ENUM_NAME IDENTIFIER ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM_NAME, "ENUM_NAME"), root_1); + + adaptor.addChild(root_1, stream_IDENTIFIER.nextNode()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("enumName"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumName" + + public static class enumBody_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumBody" + // Grammar/CTFParser.g:685:1: enumBody : LCURL enumeratorList ( SEPARATOR RCURL | RCURL ) -> ^( ENUM_BODY enumeratorList ) ; + public final CTFParser.enumBody_return enumBody() throws RecognitionException { + CTFParser.enumBody_return retval = new CTFParser.enumBody_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token LCURL113=null; + Token SEPARATOR115=null; + Token RCURL116=null; + Token RCURL117=null; + CTFParser.enumeratorList_return enumeratorList114 = null; + + + CommonTree LCURL113_tree=null; + CommonTree SEPARATOR115_tree=null; + CommonTree RCURL116_tree=null; + CommonTree RCURL117_tree=null; + RewriteRuleTokenStream stream_LCURL=new RewriteRuleTokenStream(adaptor,"token LCURL"); + RewriteRuleTokenStream stream_SEPARATOR=new RewriteRuleTokenStream(adaptor,"token SEPARATOR"); + RewriteRuleTokenStream stream_RCURL=new RewriteRuleTokenStream(adaptor,"token RCURL"); + RewriteRuleSubtreeStream stream_enumeratorList=new RewriteRuleSubtreeStream(adaptor,"rule enumeratorList"); + + enter("enumBody"); + + try { + // Grammar/CTFParser.g:692:1: ( LCURL enumeratorList ( SEPARATOR RCURL | RCURL ) -> ^( ENUM_BODY enumeratorList ) ) + // Grammar/CTFParser.g:693:3: LCURL enumeratorList ( SEPARATOR RCURL | RCURL ) + { + LCURL113=(Token)match(input,LCURL,FOLLOW_LCURL_in_enumBody2389); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_LCURL.add(LCURL113); + + pushFollow(FOLLOW_enumeratorList_in_enumBody2391); + enumeratorList114=enumeratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumeratorList.add(enumeratorList114.getTree()); + // Grammar/CTFParser.g:693:24: ( SEPARATOR RCURL | RCURL ) + int alt35=2; + int LA35_0 = input.LA(1); + + if ( (LA35_0==SEPARATOR) ) { + alt35=1; + } + else if ( (LA35_0==RCURL) ) { + alt35=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 35, 0, input); + + throw nvae; + } + switch (alt35) { + case 1 : + // Grammar/CTFParser.g:693:25: SEPARATOR RCURL + { + SEPARATOR115=(Token)match(input,SEPARATOR,FOLLOW_SEPARATOR_in_enumBody2394); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_SEPARATOR.add(SEPARATOR115); + + RCURL116=(Token)match(input,RCURL,FOLLOW_RCURL_in_enumBody2396); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_RCURL.add(RCURL116); + + + } + break; + case 2 : + // Grammar/CTFParser.g:693:43: RCURL + { + RCURL117=(Token)match(input,RCURL,FOLLOW_RCURL_in_enumBody2400); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_RCURL.add(RCURL117); + + + } + break; + + } + + + + // AST REWRITE + // elements: enumeratorList + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 693:50: -> ^( ENUM_BODY enumeratorList ) + { + // Grammar/CTFParser.g:693:53: ^( ENUM_BODY enumeratorList ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM_BODY, "ENUM_BODY"), root_1); + + adaptor.addChild(root_1, stream_enumeratorList.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("enumBody"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumBody" + + public static class enumContainerType_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumContainerType" + // Grammar/CTFParser.g:696:1: enumContainerType : COLON declarationSpecifiers -> ^( ENUM_CONTAINER_TYPE declarationSpecifiers ) ; + public final CTFParser.enumContainerType_return enumContainerType() throws RecognitionException { + CTFParser.enumContainerType_return retval = new CTFParser.enumContainerType_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token COLON118=null; + CTFParser.declarationSpecifiers_return declarationSpecifiers119 = null; + + + CommonTree COLON118_tree=null; + RewriteRuleTokenStream stream_COLON=new RewriteRuleTokenStream(adaptor,"token COLON"); + RewriteRuleSubtreeStream stream_declarationSpecifiers=new RewriteRuleSubtreeStream(adaptor,"rule declarationSpecifiers"); + + enter("enumContainerType"); + + try { + // Grammar/CTFParser.g:703:1: ( COLON declarationSpecifiers -> ^( ENUM_CONTAINER_TYPE declarationSpecifiers ) ) + // Grammar/CTFParser.g:704:3: COLON declarationSpecifiers + { + COLON118=(Token)match(input,COLON,FOLLOW_COLON_in_enumContainerType2432); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_COLON.add(COLON118); + + pushFollow(FOLLOW_declarationSpecifiers_in_enumContainerType2434); + declarationSpecifiers119=declarationSpecifiers(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarationSpecifiers.add(declarationSpecifiers119.getTree()); + + + // AST REWRITE + // elements: declarationSpecifiers + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 704:31: -> ^( ENUM_CONTAINER_TYPE declarationSpecifiers ) + { + // Grammar/CTFParser.g:704:34: ^( ENUM_CONTAINER_TYPE declarationSpecifiers ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM_CONTAINER_TYPE, "ENUM_CONTAINER_TYPE"), root_1); + + adaptor.addChild(root_1, stream_declarationSpecifiers.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("enumContainerType"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumContainerType" + + public static class enumeratorList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumeratorList" + // Grammar/CTFParser.g:707:1: enumeratorList : enumerator ( SEPARATOR enumerator )* -> ( ^( ENUM_ENUMERATOR enumerator ) )+ ; + public final CTFParser.enumeratorList_return enumeratorList() throws RecognitionException { + CTFParser.enumeratorList_return retval = new CTFParser.enumeratorList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token SEPARATOR121=null; + CTFParser.enumerator_return enumerator120 = null; + + CTFParser.enumerator_return enumerator122 = null; + + + CommonTree SEPARATOR121_tree=null; + RewriteRuleTokenStream stream_SEPARATOR=new RewriteRuleTokenStream(adaptor,"token SEPARATOR"); + RewriteRuleSubtreeStream stream_enumerator=new RewriteRuleSubtreeStream(adaptor,"rule enumerator"); + + enter("enumeratorList"); + + try { + // Grammar/CTFParser.g:714:1: ( enumerator ( SEPARATOR enumerator )* -> ( ^( ENUM_ENUMERATOR enumerator ) )+ ) + // Grammar/CTFParser.g:715:3: enumerator ( SEPARATOR enumerator )* + { + pushFollow(FOLLOW_enumerator_in_enumeratorList2465); + enumerator120=enumerator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumerator.add(enumerator120.getTree()); + // Grammar/CTFParser.g:715:14: ( SEPARATOR enumerator )* + loop36: + do { + int alt36=2; + int LA36_0 = input.LA(1); + + if ( (LA36_0==SEPARATOR) ) { + int LA36_1 = input.LA(2); + + if ( (LA36_1==ALIGNTOK||LA36_1==EVENTTOK||LA36_1==SIGNEDTOK||LA36_1==STRINGTOK||LA36_1==STRING_LITERAL||LA36_1==IDENTIFIER) ) { + alt36=1; + } + + + } + + + switch (alt36) { + case 1 : + // Grammar/CTFParser.g:715:15: SEPARATOR enumerator + { + SEPARATOR121=(Token)match(input,SEPARATOR,FOLLOW_SEPARATOR_in_enumeratorList2468); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_SEPARATOR.add(SEPARATOR121); + + pushFollow(FOLLOW_enumerator_in_enumeratorList2470); + enumerator122=enumerator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_enumerator.add(enumerator122.getTree()); + + } + break; + + default : + break loop36; + } + } while (true); + + + + // AST REWRITE + // elements: enumerator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 715:38: -> ( ^( ENUM_ENUMERATOR enumerator ) )+ + { + if ( !(stream_enumerator.hasNext()) ) { + throw new RewriteEarlyExitException(); + } + while ( stream_enumerator.hasNext() ) { + // Grammar/CTFParser.g:715:42: ^( ENUM_ENUMERATOR enumerator ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM_ENUMERATOR, "ENUM_ENUMERATOR"), root_1); + + adaptor.addChild(root_1, stream_enumerator.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + stream_enumerator.reset(); + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("enumeratorList"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumeratorList" + + public static class enumerator_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumerator" + // Grammar/CTFParser.g:718:1: enumerator : enumConstant ( enumeratorValue )? ; + public final CTFParser.enumerator_return enumerator() throws RecognitionException { + CTFParser.enumerator_return retval = new CTFParser.enumerator_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.enumConstant_return enumConstant123 = null; + + CTFParser.enumeratorValue_return enumeratorValue124 = null; + + + + + enter("enumerator"); + + try { + // Grammar/CTFParser.g:725:1: ( enumConstant ( enumeratorValue )? ) + // Grammar/CTFParser.g:726:3: enumConstant ( enumeratorValue )? + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_enumConstant_in_enumerator2506); + enumConstant123=enumConstant(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, enumConstant123.getTree()); + // Grammar/CTFParser.g:726:16: ( enumeratorValue )? + int alt37=2; + int LA37_0 = input.LA(1); + + if ( (LA37_0==ASSIGNMENT) ) { + alt37=1; + } + switch (alt37) { + case 1 : + // Grammar/CTFParser.g:726:16: enumeratorValue + { + pushFollow(FOLLOW_enumeratorValue_in_enumerator2508); + enumeratorValue124=enumeratorValue(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, enumeratorValue124.getTree()); + + } + break; + + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("enumerator"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumerator" + + public static class enumeratorValue_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "enumeratorValue" + // Grammar/CTFParser.g:729:1: enumeratorValue : ASSIGNMENT e1= unaryExpression ( -> ^( ENUM_VALUE $e1) | ELIPSES e2= unaryExpression -> ^( ENUM_VALUE_RANGE $e1 $e2) ) ; + public final CTFParser.enumeratorValue_return enumeratorValue() throws RecognitionException { + CTFParser.enumeratorValue_return retval = new CTFParser.enumeratorValue_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token ASSIGNMENT125=null; + Token ELIPSES126=null; + CTFParser.unaryExpression_return e1 = null; + + CTFParser.unaryExpression_return e2 = null; + + + CommonTree ASSIGNMENT125_tree=null; + CommonTree ELIPSES126_tree=null; + RewriteRuleTokenStream stream_ASSIGNMENT=new RewriteRuleTokenStream(adaptor,"token ASSIGNMENT"); + RewriteRuleTokenStream stream_ELIPSES=new RewriteRuleTokenStream(adaptor,"token ELIPSES"); + RewriteRuleSubtreeStream stream_unaryExpression=new RewriteRuleSubtreeStream(adaptor,"rule unaryExpression"); + + enter("enumeratorValue"); + + try { + // Grammar/CTFParser.g:736:1: ( ASSIGNMENT e1= unaryExpression ( -> ^( ENUM_VALUE $e1) | ELIPSES e2= unaryExpression -> ^( ENUM_VALUE_RANGE $e1 $e2) ) ) + // Grammar/CTFParser.g:737:3: ASSIGNMENT e1= unaryExpression ( -> ^( ENUM_VALUE $e1) | ELIPSES e2= unaryExpression -> ^( ENUM_VALUE_RANGE $e1 $e2) ) + { + ASSIGNMENT125=(Token)match(input,ASSIGNMENT,FOLLOW_ASSIGNMENT_in_enumeratorValue2532); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ASSIGNMENT.add(ASSIGNMENT125); + + pushFollow(FOLLOW_unaryExpression_in_enumeratorValue2536); + e1=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_unaryExpression.add(e1.getTree()); + // Grammar/CTFParser.g:738:3: ( -> ^( ENUM_VALUE $e1) | ELIPSES e2= unaryExpression -> ^( ENUM_VALUE_RANGE $e1 $e2) ) + int alt38=2; + int LA38_0 = input.LA(1); + + if ( (LA38_0==SEPARATOR||LA38_0==RCURL) ) { + alt38=1; + } + else if ( (LA38_0==ELIPSES) ) { + alt38=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 38, 0, input); + + throw nvae; + } + switch (alt38) { + case 1 : + // Grammar/CTFParser.g:739:5: + { + + // AST REWRITE + // elements: e1 + // token labels: + // rule labels: retval, e1 + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + RewriteRuleSubtreeStream stream_e1=new RewriteRuleSubtreeStream(adaptor,"rule e1",e1!=null?e1.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 739:5: -> ^( ENUM_VALUE $e1) + { + // Grammar/CTFParser.g:739:8: ^( ENUM_VALUE $e1) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM_VALUE, "ENUM_VALUE"), root_1); + + adaptor.addChild(root_1, stream_e1.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:740:7: ELIPSES e2= unaryExpression + { + ELIPSES126=(Token)match(input,ELIPSES,FOLLOW_ELIPSES_in_enumeratorValue2562); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ELIPSES.add(ELIPSES126); + + pushFollow(FOLLOW_unaryExpression_in_enumeratorValue2566); + e2=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_unaryExpression.add(e2.getTree()); + + + // AST REWRITE + // elements: e2, e1 + // token labels: + // rule labels: retval, e1, e2 + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + RewriteRuleSubtreeStream stream_e1=new RewriteRuleSubtreeStream(adaptor,"rule e1",e1!=null?e1.tree:null); + RewriteRuleSubtreeStream stream_e2=new RewriteRuleSubtreeStream(adaptor,"rule e2",e2!=null?e2.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 740:34: -> ^( ENUM_VALUE_RANGE $e1 $e2) + { + // Grammar/CTFParser.g:740:37: ^( ENUM_VALUE_RANGE $e1 $e2) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(ENUM_VALUE_RANGE, "ENUM_VALUE_RANGE"), root_1); + + adaptor.addChild(root_1, stream_e1.nextTree()); + adaptor.addChild(root_1, stream_e2.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("enumeratorValue"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "enumeratorValue" + + public static class declarator_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "declarator" + // Grammar/CTFParser.g:745:1: declarator : ( pointer )* directDeclarator -> ^( TYPE_DECLARATOR ( pointer )* directDeclarator ) ; + public final CTFParser.declarator_return declarator() throws RecognitionException { + CTFParser.declarator_return retval = new CTFParser.declarator_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.pointer_return pointer127 = null; + + CTFParser.directDeclarator_return directDeclarator128 = null; + + + RewriteRuleSubtreeStream stream_directDeclarator=new RewriteRuleSubtreeStream(adaptor,"rule directDeclarator"); + RewriteRuleSubtreeStream stream_pointer=new RewriteRuleSubtreeStream(adaptor,"rule pointer"); + + enter("declarator"); + + try { + // Grammar/CTFParser.g:752:1: ( ( pointer )* directDeclarator -> ^( TYPE_DECLARATOR ( pointer )* directDeclarator ) ) + // Grammar/CTFParser.g:753:3: ( pointer )* directDeclarator + { + // Grammar/CTFParser.g:753:3: ( pointer )* + loop39: + do { + int alt39=2; + int LA39_0 = input.LA(1); + + if ( (LA39_0==POINTER) ) { + alt39=1; + } + + + switch (alt39) { + case 1 : + // Grammar/CTFParser.g:753:3: pointer + { + pushFollow(FOLLOW_pointer_in_declarator2608); + pointer127=pointer(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_pointer.add(pointer127.getTree()); + + } + break; + + default : + break loop39; + } + } while (true); + + pushFollow(FOLLOW_directDeclarator_in_declarator2611); + directDeclarator128=directDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_directDeclarator.add(directDeclarator128.getTree()); + + + // AST REWRITE + // elements: directDeclarator, pointer + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 753:29: -> ^( TYPE_DECLARATOR ( pointer )* directDeclarator ) + { + // Grammar/CTFParser.g:753:32: ^( TYPE_DECLARATOR ( pointer )* directDeclarator ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_DECLARATOR, "TYPE_DECLARATOR"), root_1); + + // Grammar/CTFParser.g:753:50: ( pointer )* + while ( stream_pointer.hasNext() ) { + adaptor.addChild(root_1, stream_pointer.nextTree()); + + } + stream_pointer.reset(); + adaptor.addChild(root_1, stream_directDeclarator.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("declarator"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "declarator" + + public static class directDeclarator_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "directDeclarator" + // Grammar/CTFParser.g:756:1: directDeclarator : ( IDENTIFIER ) ( directDeclaratorSuffix )* ; + public final CTFParser.directDeclarator_return directDeclarator() throws RecognitionException { + CTFParser.directDeclarator_return retval = new CTFParser.directDeclarator_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER129=null; + CTFParser.directDeclaratorSuffix_return directDeclaratorSuffix130 = null; + + + CommonTree IDENTIFIER129_tree=null; + + + enter("directDeclarator"); + + try { + // Grammar/CTFParser.g:763:1: ( ( IDENTIFIER ) ( directDeclaratorSuffix )* ) + // Grammar/CTFParser.g:764:3: ( IDENTIFIER ) ( directDeclaratorSuffix )* + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:764:3: ( IDENTIFIER ) + // Grammar/CTFParser.g:765:6: IDENTIFIER + { + IDENTIFIER129=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_directDeclarator2655); if (state.failed) return retval; + if ( state.backtracking==0 ) { + IDENTIFIER129_tree = (CommonTree)adaptor.create(IDENTIFIER129); + adaptor.addChild(root_0, IDENTIFIER129_tree); + } + if ( state.backtracking==0 ) { + if (inTypedef()) addTypeName((IDENTIFIER129!=null?IDENTIFIER129.getText():null)); + } + if ( state.backtracking==0 ) { + debug_print((IDENTIFIER129!=null?IDENTIFIER129.getText():null)); + } + + } + + // Grammar/CTFParser.g:768:2: ( directDeclaratorSuffix )* + loop40: + do { + int alt40=2; + int LA40_0 = input.LA(1); + + if ( (LA40_0==OPENBRAC) ) { + alt40=1; + } + + + switch (alt40) { + case 1 : + // Grammar/CTFParser.g:768:2: directDeclaratorSuffix + { + pushFollow(FOLLOW_directDeclaratorSuffix_in_directDeclarator2673); + directDeclaratorSuffix130=directDeclaratorSuffix(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, directDeclaratorSuffix130.getTree()); + + } + break; + + default : + break loop40; + } + } while (true); + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("directDeclarator"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "directDeclarator" + + public static class directDeclaratorSuffix_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "directDeclaratorSuffix" + // Grammar/CTFParser.g:771:1: directDeclaratorSuffix : OPENBRAC directDeclaratorLength CLOSEBRAC -> ^( LENGTH directDeclaratorLength ) ; + public final CTFParser.directDeclaratorSuffix_return directDeclaratorSuffix() throws RecognitionException { + CTFParser.directDeclaratorSuffix_return retval = new CTFParser.directDeclaratorSuffix_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token OPENBRAC131=null; + Token CLOSEBRAC133=null; + CTFParser.directDeclaratorLength_return directDeclaratorLength132 = null; + + + CommonTree OPENBRAC131_tree=null; + CommonTree CLOSEBRAC133_tree=null; + RewriteRuleTokenStream stream_OPENBRAC=new RewriteRuleTokenStream(adaptor,"token OPENBRAC"); + RewriteRuleTokenStream stream_CLOSEBRAC=new RewriteRuleTokenStream(adaptor,"token CLOSEBRAC"); + RewriteRuleSubtreeStream stream_directDeclaratorLength=new RewriteRuleSubtreeStream(adaptor,"rule directDeclaratorLength"); + try { + // Grammar/CTFParser.g:771:23: ( OPENBRAC directDeclaratorLength CLOSEBRAC -> ^( LENGTH directDeclaratorLength ) ) + // Grammar/CTFParser.g:772:3: OPENBRAC directDeclaratorLength CLOSEBRAC + { + OPENBRAC131=(Token)match(input,OPENBRAC,FOLLOW_OPENBRAC_in_directDeclaratorSuffix2686); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_OPENBRAC.add(OPENBRAC131); + + pushFollow(FOLLOW_directDeclaratorLength_in_directDeclaratorSuffix2688); + directDeclaratorLength132=directDeclaratorLength(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_directDeclaratorLength.add(directDeclaratorLength132.getTree()); + CLOSEBRAC133=(Token)match(input,CLOSEBRAC,FOLLOW_CLOSEBRAC_in_directDeclaratorSuffix2690); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_CLOSEBRAC.add(CLOSEBRAC133); + + + + // AST REWRITE + // elements: directDeclaratorLength + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 772:45: -> ^( LENGTH directDeclaratorLength ) + { + // Grammar/CTFParser.g:772:48: ^( LENGTH directDeclaratorLength ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(LENGTH, "LENGTH"), root_1); + + adaptor.addChild(root_1, stream_directDeclaratorLength.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "directDeclaratorSuffix" + + public static class directDeclaratorLength_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "directDeclaratorLength" + // Grammar/CTFParser.g:775:1: directDeclaratorLength : unaryExpression ; + public final CTFParser.directDeclaratorLength_return directDeclaratorLength() throws RecognitionException { + CTFParser.directDeclaratorLength_return retval = new CTFParser.directDeclaratorLength_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.unaryExpression_return unaryExpression134 = null; + + + + try { + // Grammar/CTFParser.g:775:24: ( unaryExpression ) + // Grammar/CTFParser.g:776:3: unaryExpression + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_unaryExpression_in_directDeclaratorLength2711); + unaryExpression134=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, unaryExpression134.getTree()); + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "directDeclaratorLength" + + public static class abstractDeclarator_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "abstractDeclarator" + // Grammar/CTFParser.g:780:1: abstractDeclarator : ( ( ( pointer )+ ( directAbstractDeclarator )? ) -> ^( TYPE_DECLARATOR ( pointer )+ ( directAbstractDeclarator )? ) | directAbstractDeclarator -> ^( TYPE_DECLARATOR directAbstractDeclarator ) ); + public final CTFParser.abstractDeclarator_return abstractDeclarator() throws RecognitionException { + CTFParser.abstractDeclarator_return retval = new CTFParser.abstractDeclarator_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.pointer_return pointer135 = null; + + CTFParser.directAbstractDeclarator_return directAbstractDeclarator136 = null; + + CTFParser.directAbstractDeclarator_return directAbstractDeclarator137 = null; + + + RewriteRuleSubtreeStream stream_pointer=new RewriteRuleSubtreeStream(adaptor,"rule pointer"); + RewriteRuleSubtreeStream stream_directAbstractDeclarator=new RewriteRuleSubtreeStream(adaptor,"rule directAbstractDeclarator"); + + enter("abstractDeclarator"); + + try { + // Grammar/CTFParser.g:787:1: ( ( ( pointer )+ ( directAbstractDeclarator )? ) -> ^( TYPE_DECLARATOR ( pointer )+ ( directAbstractDeclarator )? ) | directAbstractDeclarator -> ^( TYPE_DECLARATOR directAbstractDeclarator ) ) + int alt43=2; + int LA43_0 = input.LA(1); + + if ( (LA43_0==POINTER) ) { + alt43=1; + } + else if ( (LA43_0==LPAREN||LA43_0==IDENTIFIER) ) { + alt43=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 43, 0, input); + + throw nvae; + } + switch (alt43) { + case 1 : + // Grammar/CTFParser.g:788:5: ( ( pointer )+ ( directAbstractDeclarator )? ) + { + // Grammar/CTFParser.g:788:5: ( ( pointer )+ ( directAbstractDeclarator )? ) + // Grammar/CTFParser.g:788:6: ( pointer )+ ( directAbstractDeclarator )? + { + // Grammar/CTFParser.g:788:6: ( pointer )+ + int cnt41=0; + loop41: + do { + int alt41=2; + int LA41_0 = input.LA(1); + + if ( (LA41_0==POINTER) ) { + alt41=1; + } + + + switch (alt41) { + case 1 : + // Grammar/CTFParser.g:788:6: pointer + { + pushFollow(FOLLOW_pointer_in_abstractDeclarator2742); + pointer135=pointer(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_pointer.add(pointer135.getTree()); + + } + break; + + default : + if ( cnt41 >= 1 ) break loop41; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(41, input); + throw eee; + } + cnt41++; + } while (true); + + // Grammar/CTFParser.g:788:15: ( directAbstractDeclarator )? + int alt42=2; + int LA42_0 = input.LA(1); + + if ( (LA42_0==LPAREN||LA42_0==IDENTIFIER) ) { + alt42=1; + } + switch (alt42) { + case 1 : + // Grammar/CTFParser.g:788:15: directAbstractDeclarator + { + pushFollow(FOLLOW_directAbstractDeclarator_in_abstractDeclarator2745); + directAbstractDeclarator136=directAbstractDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_directAbstractDeclarator.add(directAbstractDeclarator136.getTree()); + + } + break; + + } + + + } + + + + // AST REWRITE + // elements: pointer, directAbstractDeclarator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 788:42: -> ^( TYPE_DECLARATOR ( pointer )+ ( directAbstractDeclarator )? ) + { + // Grammar/CTFParser.g:788:45: ^( TYPE_DECLARATOR ( pointer )+ ( directAbstractDeclarator )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_DECLARATOR, "TYPE_DECLARATOR"), root_1); + + if ( !(stream_pointer.hasNext()) ) { + throw new RewriteEarlyExitException(); + } + while ( stream_pointer.hasNext() ) { + adaptor.addChild(root_1, stream_pointer.nextTree()); + + } + stream_pointer.reset(); + // Grammar/CTFParser.g:788:72: ( directAbstractDeclarator )? + if ( stream_directAbstractDeclarator.hasNext() ) { + adaptor.addChild(root_1, stream_directAbstractDeclarator.nextTree()); + + } + stream_directAbstractDeclarator.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:789:5: directAbstractDeclarator + { + pushFollow(FOLLOW_directAbstractDeclarator_in_abstractDeclarator2765); + directAbstractDeclarator137=directAbstractDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_directAbstractDeclarator.add(directAbstractDeclarator137.getTree()); + + + // AST REWRITE + // elements: directAbstractDeclarator + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 789:30: -> ^( TYPE_DECLARATOR directAbstractDeclarator ) + { + // Grammar/CTFParser.g:789:33: ^( TYPE_DECLARATOR directAbstractDeclarator ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_DECLARATOR, "TYPE_DECLARATOR"), root_1); + + adaptor.addChild(root_1, stream_directAbstractDeclarator.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("abstractDeclarator"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "abstractDeclarator" + + public static class directAbstractDeclarator_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "directAbstractDeclarator" + // Grammar/CTFParser.g:796:1: directAbstractDeclarator : ( IDENTIFIER | ( LPAREN abstractDeclarator RPAREN ) ) ( OPENBRAC ( unaryExpression )? CLOSEBRAC )? ; + public final CTFParser.directAbstractDeclarator_return directAbstractDeclarator() throws RecognitionException { + CTFParser.directAbstractDeclarator_return retval = new CTFParser.directAbstractDeclarator_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER138=null; + Token LPAREN139=null; + Token RPAREN141=null; + Token OPENBRAC142=null; + Token CLOSEBRAC144=null; + CTFParser.abstractDeclarator_return abstractDeclarator140 = null; + + CTFParser.unaryExpression_return unaryExpression143 = null; + + + CommonTree IDENTIFIER138_tree=null; + CommonTree LPAREN139_tree=null; + CommonTree RPAREN141_tree=null; + CommonTree OPENBRAC142_tree=null; + CommonTree CLOSEBRAC144_tree=null; + + + enter("directAbstractDeclarator"); + + try { + // Grammar/CTFParser.g:804:1: ( ( IDENTIFIER | ( LPAREN abstractDeclarator RPAREN ) ) ( OPENBRAC ( unaryExpression )? CLOSEBRAC )? ) + // Grammar/CTFParser.g:805:3: ( IDENTIFIER | ( LPAREN abstractDeclarator RPAREN ) ) ( OPENBRAC ( unaryExpression )? CLOSEBRAC )? + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:805:3: ( IDENTIFIER | ( LPAREN abstractDeclarator RPAREN ) ) + int alt44=2; + int LA44_0 = input.LA(1); + + if ( (LA44_0==IDENTIFIER) ) { + alt44=1; + } + else if ( (LA44_0==LPAREN) ) { + alt44=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 44, 0, input); + + throw nvae; + } + switch (alt44) { + case 1 : + // Grammar/CTFParser.g:806:6: IDENTIFIER + { + IDENTIFIER138=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_directAbstractDeclarator2805); if (state.failed) return retval; + if ( state.backtracking==0 ) { + IDENTIFIER138_tree = (CommonTree)adaptor.create(IDENTIFIER138); + adaptor.addChild(root_0, IDENTIFIER138_tree); + } + + } + break; + case 2 : + // Grammar/CTFParser.g:807:7: ( LPAREN abstractDeclarator RPAREN ) + { + // Grammar/CTFParser.g:807:7: ( LPAREN abstractDeclarator RPAREN ) + // Grammar/CTFParser.g:807:8: LPAREN abstractDeclarator RPAREN + { + LPAREN139=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_directAbstractDeclarator2814); if (state.failed) return retval; + if ( state.backtracking==0 ) { + LPAREN139_tree = (CommonTree)adaptor.create(LPAREN139); + adaptor.addChild(root_0, LPAREN139_tree); + } + pushFollow(FOLLOW_abstractDeclarator_in_directAbstractDeclarator2816); + abstractDeclarator140=abstractDeclarator(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, abstractDeclarator140.getTree()); + RPAREN141=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_directAbstractDeclarator2818); if (state.failed) return retval; + if ( state.backtracking==0 ) { + RPAREN141_tree = (CommonTree)adaptor.create(RPAREN141); + adaptor.addChild(root_0, RPAREN141_tree); + } + + } + + + } + break; + + } + + // Grammar/CTFParser.g:809:3: ( OPENBRAC ( unaryExpression )? CLOSEBRAC )? + int alt46=2; + int LA46_0 = input.LA(1); + + if ( (LA46_0==OPENBRAC) ) { + alt46=1; + } + switch (alt46) { + case 1 : + // Grammar/CTFParser.g:810:5: OPENBRAC ( unaryExpression )? CLOSEBRAC + { + OPENBRAC142=(Token)match(input,OPENBRAC,FOLLOW_OPENBRAC_in_directAbstractDeclarator2833); if (state.failed) return retval; + if ( state.backtracking==0 ) { + OPENBRAC142_tree = (CommonTree)adaptor.create(OPENBRAC142); + adaptor.addChild(root_0, OPENBRAC142_tree); + } + // Grammar/CTFParser.g:810:14: ( unaryExpression )? + int alt45=2; + int LA45_0 = input.LA(1); + + if ( (LA45_0==ALIGNTOK||LA45_0==EVENTTOK||(LA45_0>=SIGNEDTOK && LA45_0<=STRINGTOK)||LA45_0==TRACETOK||(LA45_0>=ENVTOK && LA45_0<=CLOCKTOK)||LA45_0==SIGN||LA45_0==OCTAL_LITERAL||LA45_0==DECIMAL_LITERAL||LA45_0==HEX_LITERAL||LA45_0==CHARACTER_LITERAL||LA45_0==STRING_LITERAL||LA45_0==IDENTIFIER) ) { + alt45=1; + } + switch (alt45) { + case 1 : + // Grammar/CTFParser.g:810:14: unaryExpression + { + pushFollow(FOLLOW_unaryExpression_in_directAbstractDeclarator2835); + unaryExpression143=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, unaryExpression143.getTree()); + + } + break; + + } + + CLOSEBRAC144=(Token)match(input,CLOSEBRAC,FOLLOW_CLOSEBRAC_in_directAbstractDeclarator2838); if (state.failed) return retval; + if ( state.backtracking==0 ) { + CLOSEBRAC144_tree = (CommonTree)adaptor.create(CLOSEBRAC144); + adaptor.addChild(root_0, CLOSEBRAC144_tree); + } + + } + break; + + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("directAbstractDeclarator"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "directAbstractDeclarator" + + public static class pointer_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "pointer" + // Grammar/CTFParser.g:814:1: pointer : POINTER ( typeQualifierList )? -> ^( POINTER ( typeQualifierList )? ) ; + public final CTFParser.pointer_return pointer() throws RecognitionException { + CTFParser.pointer_return retval = new CTFParser.pointer_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token POINTER145=null; + CTFParser.typeQualifierList_return typeQualifierList146 = null; + + + CommonTree POINTER145_tree=null; + RewriteRuleTokenStream stream_POINTER=new RewriteRuleTokenStream(adaptor,"token POINTER"); + RewriteRuleSubtreeStream stream_typeQualifierList=new RewriteRuleSubtreeStream(adaptor,"rule typeQualifierList"); + + enter("pointer"); + + try { + // Grammar/CTFParser.g:822:1: ( POINTER ( typeQualifierList )? -> ^( POINTER ( typeQualifierList )? ) ) + // Grammar/CTFParser.g:823:3: POINTER ( typeQualifierList )? + { + POINTER145=(Token)match(input,POINTER,FOLLOW_POINTER_in_pointer2866); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_POINTER.add(POINTER145); + + // Grammar/CTFParser.g:823:11: ( typeQualifierList )? + int alt47=2; + int LA47_0 = input.LA(1); + + if ( (LA47_0==CONSTTOK) ) { + alt47=1; + } + switch (alt47) { + case 1 : + // Grammar/CTFParser.g:823:11: typeQualifierList + { + pushFollow(FOLLOW_typeQualifierList_in_pointer2868); + typeQualifierList146=typeQualifierList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typeQualifierList.add(typeQualifierList146.getTree()); + + } + break; + + } + + + + // AST REWRITE + // elements: typeQualifierList, POINTER + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 823:30: -> ^( POINTER ( typeQualifierList )? ) + { + // Grammar/CTFParser.g:823:33: ^( POINTER ( typeQualifierList )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot(stream_POINTER.nextNode(), root_1); + + // Grammar/CTFParser.g:823:43: ( typeQualifierList )? + if ( stream_typeQualifierList.hasNext() ) { + adaptor.addChild(root_1, stream_typeQualifierList.nextTree()); + + } + stream_typeQualifierList.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("pointer"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "pointer" + + public static class typeQualifierList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typeQualifierList" + // Grammar/CTFParser.g:826:1: typeQualifierList : ( typeQualifier )+ ; + public final CTFParser.typeQualifierList_return typeQualifierList() throws RecognitionException { + CTFParser.typeQualifierList_return retval = new CTFParser.typeQualifierList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.typeQualifier_return typeQualifier147 = null; + + + + try { + // Grammar/CTFParser.g:826:19: ( ( typeQualifier )+ ) + // Grammar/CTFParser.g:827:3: ( typeQualifier )+ + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:827:3: ( typeQualifier )+ + int cnt48=0; + loop48: + do { + int alt48=2; + int LA48_0 = input.LA(1); + + if ( (LA48_0==CONSTTOK) ) { + alt48=1; + } + + + switch (alt48) { + case 1 : + // Grammar/CTFParser.g:827:3: typeQualifier + { + pushFollow(FOLLOW_typeQualifier_in_typeQualifierList2891); + typeQualifier147=typeQualifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, typeQualifier147.getTree()); + + } + break; + + default : + if ( cnt48 >= 1 ) break loop48; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(48, input); + throw eee; + } + cnt48++; + } while (true); + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typeQualifierList" + + public static class typedefName_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typedefName" + // Grammar/CTFParser.g:830:1: typedefName : {...}? IDENTIFIER ; + public final CTFParser.typedefName_return typedefName() throws RecognitionException { + CTFParser.typedefName_return retval = new CTFParser.typedefName_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token IDENTIFIER148=null; + + CommonTree IDENTIFIER148_tree=null; + + + enter("typedefName"); + + try { + // Grammar/CTFParser.g:838:1: ({...}? IDENTIFIER ) + // Grammar/CTFParser.g:839:3: {...}? IDENTIFIER + { + root_0 = (CommonTree)adaptor.nil(); + + if ( !((inTypealiasAlias() || isTypeName(input.LT(1).getText()))) ) { + if (state.backtracking>0) {state.failed=true; return retval;} + throw new FailedPredicateException(input, "typedefName", "inTypealiasAlias() || isTypeName(input.LT(1).getText())"); + } + IDENTIFIER148=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_typedefName2917); if (state.failed) return retval; + if ( state.backtracking==0 ) { + IDENTIFIER148_tree = (CommonTree)adaptor.create(IDENTIFIER148); + adaptor.addChild(root_0, IDENTIFIER148_tree); + } + if ( state.backtracking==0 ) { + if ((inTypedef() || inTypealiasAlias()) && !isTypeName((IDENTIFIER148!=null?IDENTIFIER148.getText():null))) { addTypeName((IDENTIFIER148!=null?IDENTIFIER148.getText():null)); } + } + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print("typedefName: " + input.toString(retval.start,input.LT(-1))); + exit("typedefName"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typedefName" + + public static class typealiasTarget_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typealiasTarget" + // Grammar/CTFParser.g:842:1: typealiasTarget : declarationSpecifiers ( abstractDeclaratorList )? ; + public final CTFParser.typealiasTarget_return typealiasTarget() throws RecognitionException { + CTFParser.typealiasTarget_return retval = new CTFParser.typealiasTarget_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.declarationSpecifiers_return declarationSpecifiers149 = null; + + CTFParser.abstractDeclaratorList_return abstractDeclaratorList150 = null; + + + + + enter("typealiasTarget"); + + try { + // Grammar/CTFParser.g:855:1: ( declarationSpecifiers ( abstractDeclaratorList )? ) + // Grammar/CTFParser.g:856:3: declarationSpecifiers ( abstractDeclaratorList )? + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_declarationSpecifiers_in_typealiasTarget2945); + declarationSpecifiers149=declarationSpecifiers(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, declarationSpecifiers149.getTree()); + // Grammar/CTFParser.g:856:25: ( abstractDeclaratorList )? + int alt49=2; + int LA49_0 = input.LA(1); + + if ( (LA49_0==LPAREN||LA49_0==POINTER||LA49_0==IDENTIFIER) ) { + alt49=1; + } + switch (alt49) { + case 1 : + // Grammar/CTFParser.g:856:25: abstractDeclaratorList + { + pushFollow(FOLLOW_abstractDeclaratorList_in_typealiasTarget2947); + abstractDeclaratorList150=abstractDeclaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, abstractDeclaratorList150.getTree()); + + } + break; + + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("typealiasTarget"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typealiasTarget" + + public static class typealiasAlias_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typealiasAlias" + // Grammar/CTFParser.g:859:1: typealiasAlias : ( abstractDeclaratorList | ( declarationSpecifiers ( abstractDeclaratorList )? ) ) ; + public final CTFParser.typealiasAlias_return typealiasAlias() throws RecognitionException { + CTFParser.typealiasAlias_return retval = new CTFParser.typealiasAlias_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.abstractDeclaratorList_return abstractDeclaratorList151 = null; + + CTFParser.declarationSpecifiers_return declarationSpecifiers152 = null; + + CTFParser.abstractDeclaratorList_return abstractDeclaratorList153 = null; + + + + + enter("typealiasAlias"); + typealiasAliasOn(); + + try { + // Grammar/CTFParser.g:874:1: ( ( abstractDeclaratorList | ( declarationSpecifiers ( abstractDeclaratorList )? ) ) ) + // Grammar/CTFParser.g:875:3: ( abstractDeclaratorList | ( declarationSpecifiers ( abstractDeclaratorList )? ) ) + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:875:3: ( abstractDeclaratorList | ( declarationSpecifiers ( abstractDeclaratorList )? ) ) + int alt51=2; + switch ( input.LA(1) ) { + case LPAREN: + case POINTER: + { + alt51=1; + } + break; + case IDENTIFIER: + { + int LA51_2 = input.LA(2); + + if ( (!(((inTypealiasAlias() || isTypeName(input.LT(1).getText()))))) ) { + alt51=1; + } + else if ( ((inTypealiasAlias() || isTypeName(input.LT(1).getText()))) ) { + alt51=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 51, 2, input); + + throw nvae; + } + } + break; + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case SIGNEDTOK: + case STRINGTOK: + case STRUCTTOK: + case TYPEDEFTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + { + alt51=2; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 51, 0, input); + + throw nvae; + } + + switch (alt51) { + case 1 : + // Grammar/CTFParser.g:876:3: abstractDeclaratorList + { + pushFollow(FOLLOW_abstractDeclaratorList_in_typealiasAlias2980); + abstractDeclaratorList151=abstractDeclaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, abstractDeclaratorList151.getTree()); + + } + break; + case 2 : + // Grammar/CTFParser.g:878:3: ( declarationSpecifiers ( abstractDeclaratorList )? ) + { + // Grammar/CTFParser.g:878:3: ( declarationSpecifiers ( abstractDeclaratorList )? ) + // Grammar/CTFParser.g:878:4: declarationSpecifiers ( abstractDeclaratorList )? + { + pushFollow(FOLLOW_declarationSpecifiers_in_typealiasAlias2989); + declarationSpecifiers152=declarationSpecifiers(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, declarationSpecifiers152.getTree()); + // Grammar/CTFParser.g:878:26: ( abstractDeclaratorList )? + int alt50=2; + int LA50_0 = input.LA(1); + + if ( (LA50_0==LPAREN||LA50_0==POINTER||LA50_0==IDENTIFIER) ) { + alt50=1; + } + switch (alt50) { + case 1 : + // Grammar/CTFParser.g:878:26: abstractDeclaratorList + { + pushFollow(FOLLOW_abstractDeclaratorList_in_typealiasAlias2991); + abstractDeclaratorList153=abstractDeclaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, abstractDeclaratorList153.getTree()); + + } + break; + + } + + + } + + + } + break; + + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("typealiasAlias"); + typealiasAliasOff(); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typealiasAlias" + + public static class typealiasDecl_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "typealiasDecl" + // Grammar/CTFParser.g:882:1: typealiasDecl : TYPEALIASTOK typealiasTarget TYPE_ASSIGNMENT typealiasAlias -> ^( TYPEALIAS ^( TYPEALIAS_TARGET typealiasTarget ) ^( TYPEALIAS_ALIAS typealiasAlias ) ) ; + public final CTFParser.typealiasDecl_return typealiasDecl() throws RecognitionException { + CTFParser.typealiasDecl_return retval = new CTFParser.typealiasDecl_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token TYPEALIASTOK154=null; + Token TYPE_ASSIGNMENT156=null; + CTFParser.typealiasTarget_return typealiasTarget155 = null; + + CTFParser.typealiasAlias_return typealiasAlias157 = null; + + + CommonTree TYPEALIASTOK154_tree=null; + CommonTree TYPE_ASSIGNMENT156_tree=null; + RewriteRuleTokenStream stream_TYPE_ASSIGNMENT=new RewriteRuleTokenStream(adaptor,"token TYPE_ASSIGNMENT"); + RewriteRuleTokenStream stream_TYPEALIASTOK=new RewriteRuleTokenStream(adaptor,"token TYPEALIASTOK"); + RewriteRuleSubtreeStream stream_typealiasAlias=new RewriteRuleSubtreeStream(adaptor,"rule typealiasAlias"); + RewriteRuleSubtreeStream stream_typealiasTarget=new RewriteRuleSubtreeStream(adaptor,"rule typealiasTarget"); + + enter("typealiasDecl"); + + try { + // Grammar/CTFParser.g:889:1: ( TYPEALIASTOK typealiasTarget TYPE_ASSIGNMENT typealiasAlias -> ^( TYPEALIAS ^( TYPEALIAS_TARGET typealiasTarget ) ^( TYPEALIAS_ALIAS typealiasAlias ) ) ) + // Grammar/CTFParser.g:890:3: TYPEALIASTOK typealiasTarget TYPE_ASSIGNMENT typealiasAlias + { + TYPEALIASTOK154=(Token)match(input,TYPEALIASTOK,FOLLOW_TYPEALIASTOK_in_typealiasDecl3023); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_TYPEALIASTOK.add(TYPEALIASTOK154); + + pushFollow(FOLLOW_typealiasTarget_in_typealiasDecl3025); + typealiasTarget155=typealiasTarget(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typealiasTarget.add(typealiasTarget155.getTree()); + TYPE_ASSIGNMENT156=(Token)match(input,TYPE_ASSIGNMENT,FOLLOW_TYPE_ASSIGNMENT_in_typealiasDecl3027); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_TYPE_ASSIGNMENT.add(TYPE_ASSIGNMENT156); + + pushFollow(FOLLOW_typealiasAlias_in_typealiasDecl3029); + typealiasAlias157=typealiasAlias(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typealiasAlias.add(typealiasAlias157.getTree()); + + + // AST REWRITE + // elements: typealiasTarget, typealiasAlias + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 891:3: -> ^( TYPEALIAS ^( TYPEALIAS_TARGET typealiasTarget ) ^( TYPEALIAS_ALIAS typealiasAlias ) ) + { + // Grammar/CTFParser.g:891:6: ^( TYPEALIAS ^( TYPEALIAS_TARGET typealiasTarget ) ^( TYPEALIAS_ALIAS typealiasAlias ) ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPEALIAS, "TYPEALIAS"), root_1); + + // Grammar/CTFParser.g:891:18: ^( TYPEALIAS_TARGET typealiasTarget ) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPEALIAS_TARGET, "TYPEALIAS_TARGET"), root_2); + + adaptor.addChild(root_2, stream_typealiasTarget.nextTree()); + + adaptor.addChild(root_1, root_2); + } + // Grammar/CTFParser.g:891:54: ^( TYPEALIAS_ALIAS typealiasAlias ) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPEALIAS_ALIAS, "TYPEALIAS_ALIAS"), root_2); + + adaptor.addChild(root_2, stream_typealiasAlias.nextTree()); + + adaptor.addChild(root_1, root_2); + } + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("typealiasDecl"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "typealiasDecl" + + public static class ctfKeyword_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfKeyword" + // Grammar/CTFParser.g:897:1: ctfKeyword : ( ALIGNTOK | EVENTTOK | SIGNEDTOK | STRINGTOK ); + public final CTFParser.ctfKeyword_return ctfKeyword() throws RecognitionException { + CTFParser.ctfKeyword_return retval = new CTFParser.ctfKeyword_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token set158=null; + + CommonTree set158_tree=null; + + + enter("ctfKeyword"); + + try { + // Grammar/CTFParser.g:905:1: ( ALIGNTOK | EVENTTOK | SIGNEDTOK | STRINGTOK ) + // Grammar/CTFParser.g: + { + root_0 = (CommonTree)adaptor.nil(); + + set158=(Token)input.LT(1); + if ( input.LA(1)==ALIGNTOK||input.LA(1)==EVENTTOK||input.LA(1)==SIGNEDTOK||input.LA(1)==STRINGTOK ) { + input.consume(); + if ( state.backtracking==0 ) adaptor.addChild(root_0, (CommonTree)adaptor.create(set158)); + state.errorRecovery=false;state.failed=false; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + MismatchedSetException mse = new MismatchedSetException(null,input); + throw mse; + } + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("ctfKeyword"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "ctfKeyword" + + public static class ctfSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfSpecifier" + // Grammar/CTFParser.g:912:1: ctfSpecifier : ( ctfSpecifierHead ctfBody -> ^( ctfSpecifierHead ctfBody ) | typealiasDecl -> ^( DECLARATION typealiasDecl ) ); + public final CTFParser.ctfSpecifier_return ctfSpecifier() throws RecognitionException { + CTFParser.ctfSpecifier_return retval = new CTFParser.ctfSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + CTFParser.ctfSpecifierHead_return ctfSpecifierHead159 = null; + + CTFParser.ctfBody_return ctfBody160 = null; + + CTFParser.typealiasDecl_return typealiasDecl161 = null; + + + RewriteRuleSubtreeStream stream_ctfSpecifierHead=new RewriteRuleSubtreeStream(adaptor,"rule ctfSpecifierHead"); + RewriteRuleSubtreeStream stream_typealiasDecl=new RewriteRuleSubtreeStream(adaptor,"rule typealiasDecl"); + RewriteRuleSubtreeStream stream_ctfBody=new RewriteRuleSubtreeStream(adaptor,"rule ctfBody"); + + enter("ctfSpecifier"); + + try { + // Grammar/CTFParser.g:919:3: ( ctfSpecifierHead ctfBody -> ^( ctfSpecifierHead ctfBody ) | typealiasDecl -> ^( DECLARATION typealiasDecl ) ) + int alt52=2; + int LA52_0 = input.LA(1); + + if ( (LA52_0==EVENTTOK||LA52_0==STREAMTOK||LA52_0==TRACETOK||(LA52_0>=ENVTOK && LA52_0<=CLOCKTOK)) ) { + alt52=1; + } + else if ( (LA52_0==TYPEALIASTOK) ) { + alt52=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 52, 0, input); + + throw nvae; + } + switch (alt52) { + case 1 : + // Grammar/CTFParser.g:921:3: ctfSpecifierHead ctfBody + { + pushFollow(FOLLOW_ctfSpecifierHead_in_ctfSpecifier3123); + ctfSpecifierHead159=ctfSpecifierHead(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfSpecifierHead.add(ctfSpecifierHead159.getTree()); + pushFollow(FOLLOW_ctfBody_in_ctfSpecifier3125); + ctfBody160=ctfBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfBody.add(ctfBody160.getTree()); + + + // AST REWRITE + // elements: ctfBody, ctfSpecifierHead + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 921:28: -> ^( ctfSpecifierHead ctfBody ) + { + // Grammar/CTFParser.g:921:31: ^( ctfSpecifierHead ctfBody ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot(stream_ctfSpecifierHead.nextNode(), root_1); + + adaptor.addChild(root_1, stream_ctfBody.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:924:3: typealiasDecl + { + pushFollow(FOLLOW_typealiasDecl_in_ctfSpecifier3144); + typealiasDecl161=typealiasDecl(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typealiasDecl.add(typealiasDecl161.getTree()); + + + // AST REWRITE + // elements: typealiasDecl + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 924:17: -> ^( DECLARATION typealiasDecl ) + { + // Grammar/CTFParser.g:924:20: ^( DECLARATION typealiasDecl ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(DECLARATION, "DECLARATION"), root_1); + + adaptor.addChild(root_1, stream_typealiasDecl.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("ctfSpecifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "ctfSpecifier" + + public static class ctfSpecifierHead_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfSpecifierHead" + // Grammar/CTFParser.g:927:1: ctfSpecifierHead : ( EVENTTOK -> EVENT | STREAMTOK -> STREAM | TRACETOK -> TRACE | ENVTOK -> ENV | CLOCKTOK -> CLOCK ); + public final CTFParser.ctfSpecifierHead_return ctfSpecifierHead() throws RecognitionException { + CTFParser.ctfSpecifierHead_return retval = new CTFParser.ctfSpecifierHead_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token EVENTTOK162=null; + Token STREAMTOK163=null; + Token TRACETOK164=null; + Token ENVTOK165=null; + Token CLOCKTOK166=null; + + CommonTree EVENTTOK162_tree=null; + CommonTree STREAMTOK163_tree=null; + CommonTree TRACETOK164_tree=null; + CommonTree ENVTOK165_tree=null; + CommonTree CLOCKTOK166_tree=null; + RewriteRuleTokenStream stream_EVENTTOK=new RewriteRuleTokenStream(adaptor,"token EVENTTOK"); + RewriteRuleTokenStream stream_STREAMTOK=new RewriteRuleTokenStream(adaptor,"token STREAMTOK"); + RewriteRuleTokenStream stream_ENVTOK=new RewriteRuleTokenStream(adaptor,"token ENVTOK"); + RewriteRuleTokenStream stream_CLOCKTOK=new RewriteRuleTokenStream(adaptor,"token CLOCKTOK"); + RewriteRuleTokenStream stream_TRACETOK=new RewriteRuleTokenStream(adaptor,"token TRACETOK"); + + + enter("ctfSpecifierHead"); + + try { + // Grammar/CTFParser.g:935:1: ( EVENTTOK -> EVENT | STREAMTOK -> STREAM | TRACETOK -> TRACE | ENVTOK -> ENV | CLOCKTOK -> CLOCK ) + int alt53=5; + switch ( input.LA(1) ) { + case EVENTTOK: + { + alt53=1; + } + break; + case STREAMTOK: + { + alt53=2; + } + break; + case TRACETOK: + { + alt53=3; + } + break; + case ENVTOK: + { + alt53=4; + } + break; + case CLOCKTOK: + { + alt53=5; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 53, 0, input); + + throw nvae; + } + + switch (alt53) { + case 1 : + // Grammar/CTFParser.g:936:4: EVENTTOK + { + EVENTTOK162=(Token)match(input,EVENTTOK,FOLLOW_EVENTTOK_in_ctfSpecifierHead3176); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_EVENTTOK.add(EVENTTOK162); + + + + // AST REWRITE + // elements: + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 936:13: -> EVENT + { + adaptor.addChild(root_0, (CommonTree)adaptor.create(EVENT, "EVENT")); + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:937:4: STREAMTOK + { + STREAMTOK163=(Token)match(input,STREAMTOK,FOLLOW_STREAMTOK_in_ctfSpecifierHead3185); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_STREAMTOK.add(STREAMTOK163); + + + + // AST REWRITE + // elements: + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 937:14: -> STREAM + { + adaptor.addChild(root_0, (CommonTree)adaptor.create(STREAM, "STREAM")); + + } + + retval.tree = root_0;} + } + break; + case 3 : + // Grammar/CTFParser.g:938:4: TRACETOK + { + TRACETOK164=(Token)match(input,TRACETOK,FOLLOW_TRACETOK_in_ctfSpecifierHead3194); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_TRACETOK.add(TRACETOK164); + + + + // AST REWRITE + // elements: + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 938:13: -> TRACE + { + adaptor.addChild(root_0, (CommonTree)adaptor.create(TRACE, "TRACE")); + + } + + retval.tree = root_0;} + } + break; + case 4 : + // Grammar/CTFParser.g:939:4: ENVTOK + { + ENVTOK165=(Token)match(input,ENVTOK,FOLLOW_ENVTOK_in_ctfSpecifierHead3203); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ENVTOK.add(ENVTOK165); + + + + // AST REWRITE + // elements: + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 939:11: -> ENV + { + adaptor.addChild(root_0, (CommonTree)adaptor.create(ENV, "ENV")); + + } + + retval.tree = root_0;} + } + break; + case 5 : + // Grammar/CTFParser.g:940:4: CLOCKTOK + { + CLOCKTOK166=(Token)match(input,CLOCKTOK,FOLLOW_CLOCKTOK_in_ctfSpecifierHead3212); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_CLOCKTOK.add(CLOCKTOK166); + + + + // AST REWRITE + // elements: + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 940:13: -> CLOCK + { + adaptor.addChild(root_0, (CommonTree)adaptor.create(CLOCK, "CLOCK")); + + } + + retval.tree = root_0;} + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print(input.toString(retval.start,input.LT(-1))); + exit("ctfSpecifierHead"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "ctfSpecifierHead" + + public static class ctfTypeSpecifier_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfTypeSpecifier" + // Grammar/CTFParser.g:943:1: ctfTypeSpecifier : ( FLOATINGPOINTTOK ctfBody -> ^( FLOATING_POINT ( ctfBody )? ) | INTEGERTOK ctfBody -> ^( INTEGER ( ctfBody )? ) | STRINGTOK ( ctfBody )? -> ^( STRING ( ctfBody )? ) ); + public final CTFParser.ctfTypeSpecifier_return ctfTypeSpecifier() throws RecognitionException { + CTFParser.ctfTypeSpecifier_return retval = new CTFParser.ctfTypeSpecifier_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token FLOATINGPOINTTOK167=null; + Token INTEGERTOK169=null; + Token STRINGTOK171=null; + CTFParser.ctfBody_return ctfBody168 = null; + + CTFParser.ctfBody_return ctfBody170 = null; + + CTFParser.ctfBody_return ctfBody172 = null; + + + CommonTree FLOATINGPOINTTOK167_tree=null; + CommonTree INTEGERTOK169_tree=null; + CommonTree STRINGTOK171_tree=null; + RewriteRuleTokenStream stream_FLOATINGPOINTTOK=new RewriteRuleTokenStream(adaptor,"token FLOATINGPOINTTOK"); + RewriteRuleTokenStream stream_STRINGTOK=new RewriteRuleTokenStream(adaptor,"token STRINGTOK"); + RewriteRuleTokenStream stream_INTEGERTOK=new RewriteRuleTokenStream(adaptor,"token INTEGERTOK"); + RewriteRuleSubtreeStream stream_ctfBody=new RewriteRuleSubtreeStream(adaptor,"rule ctfBody"); + + enter("ctfTypeSpecifier"); + + try { + // Grammar/CTFParser.g:950:1: ( FLOATINGPOINTTOK ctfBody -> ^( FLOATING_POINT ( ctfBody )? ) | INTEGERTOK ctfBody -> ^( INTEGER ( ctfBody )? ) | STRINGTOK ( ctfBody )? -> ^( STRING ( ctfBody )? ) ) + int alt55=3; + switch ( input.LA(1) ) { + case FLOATINGPOINTTOK: + { + alt55=1; + } + break; + case INTEGERTOK: + { + alt55=2; + } + break; + case STRINGTOK: + { + alt55=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 55, 0, input); + + throw nvae; + } + + switch (alt55) { + case 1 : + // Grammar/CTFParser.g:952:5: FLOATINGPOINTTOK ctfBody + { + FLOATINGPOINTTOK167=(Token)match(input,FLOATINGPOINTTOK,FOLLOW_FLOATINGPOINTTOK_in_ctfTypeSpecifier3246); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_FLOATINGPOINTTOK.add(FLOATINGPOINTTOK167); + + pushFollow(FOLLOW_ctfBody_in_ctfTypeSpecifier3248); + ctfBody168=ctfBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfBody.add(ctfBody168.getTree()); + + + // AST REWRITE + // elements: ctfBody + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 952:30: -> ^( FLOATING_POINT ( ctfBody )? ) + { + // Grammar/CTFParser.g:952:33: ^( FLOATING_POINT ( ctfBody )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(FLOATING_POINT, "FLOATING_POINT"), root_1); + + // Grammar/CTFParser.g:952:50: ( ctfBody )? + if ( stream_ctfBody.hasNext() ) { + adaptor.addChild(root_1, stream_ctfBody.nextTree()); + + } + stream_ctfBody.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:953:5: INTEGERTOK ctfBody + { + INTEGERTOK169=(Token)match(input,INTEGERTOK,FOLLOW_INTEGERTOK_in_ctfTypeSpecifier3263); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_INTEGERTOK.add(INTEGERTOK169); + + pushFollow(FOLLOW_ctfBody_in_ctfTypeSpecifier3265); + ctfBody170=ctfBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfBody.add(ctfBody170.getTree()); + + + // AST REWRITE + // elements: ctfBody + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 953:24: -> ^( INTEGER ( ctfBody )? ) + { + // Grammar/CTFParser.g:953:27: ^( INTEGER ( ctfBody )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(INTEGER, "INTEGER"), root_1); + + // Grammar/CTFParser.g:953:37: ( ctfBody )? + if ( stream_ctfBody.hasNext() ) { + adaptor.addChild(root_1, stream_ctfBody.nextTree()); + + } + stream_ctfBody.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 3 : + // Grammar/CTFParser.g:954:5: STRINGTOK ( ctfBody )? + { + STRINGTOK171=(Token)match(input,STRINGTOK,FOLLOW_STRINGTOK_in_ctfTypeSpecifier3280); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_STRINGTOK.add(STRINGTOK171); + + // Grammar/CTFParser.g:954:15: ( ctfBody )? + int alt54=2; + alt54 = dfa54.predict(input); + switch (alt54) { + case 1 : + // Grammar/CTFParser.g:954:15: ctfBody + { + pushFollow(FOLLOW_ctfBody_in_ctfTypeSpecifier3282); + ctfBody172=ctfBody(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfBody.add(ctfBody172.getTree()); + + } + break; + + } + + + + // AST REWRITE + // elements: ctfBody + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 954:24: -> ^( STRING ( ctfBody )? ) + { + // Grammar/CTFParser.g:954:27: ^( STRING ( ctfBody )? ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(STRING, "STRING"), root_1); + + // Grammar/CTFParser.g:954:36: ( ctfBody )? + if ( stream_ctfBody.hasNext() ) { + adaptor.addChild(root_1, stream_ctfBody.nextTree()); + + } + stream_ctfBody.reset(); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + exit("ctfTypeSpecifier"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "ctfTypeSpecifier" + + public static class ctfBody_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfBody" + // Grammar/CTFParser.g:957:1: ctfBody : LCURL ( ctfAssignmentExpressionList )? RCURL -> ( ctfAssignmentExpressionList )? ; + public final CTFParser.ctfBody_return ctfBody() throws RecognitionException { + Symbols_stack.push(new Symbols_scope()); + + CTFParser.ctfBody_return retval = new CTFParser.ctfBody_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token LCURL173=null; + Token RCURL175=null; + CTFParser.ctfAssignmentExpressionList_return ctfAssignmentExpressionList174 = null; + + + CommonTree LCURL173_tree=null; + CommonTree RCURL175_tree=null; + RewriteRuleTokenStream stream_LCURL=new RewriteRuleTokenStream(adaptor,"token LCURL"); + RewriteRuleTokenStream stream_RCURL=new RewriteRuleTokenStream(adaptor,"token RCURL"); + RewriteRuleSubtreeStream stream_ctfAssignmentExpressionList=new RewriteRuleSubtreeStream(adaptor,"rule ctfAssignmentExpressionList"); + + enter("ctfBody"); + debug_print("Scope push " + + Symbols_stack.size()); + ((Symbols_scope)Symbols_stack.peek()).types = new HashSet(); + + try { + // Grammar/CTFParser.g:968:1: ( LCURL ( ctfAssignmentExpressionList )? RCURL -> ( ctfAssignmentExpressionList )? ) + // Grammar/CTFParser.g:969:3: LCURL ( ctfAssignmentExpressionList )? RCURL + { + LCURL173=(Token)match(input,LCURL,FOLLOW_LCURL_in_ctfBody3320); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_LCURL.add(LCURL173); + + // Grammar/CTFParser.g:969:9: ( ctfAssignmentExpressionList )? + int alt56=2; + int LA56_0 = input.LA(1); + + if ( ((LA56_0>=ALIGNTOK && LA56_0<=CLOCKTOK)||LA56_0==SIGN||LA56_0==OCTAL_LITERAL||LA56_0==DECIMAL_LITERAL||LA56_0==HEX_LITERAL||LA56_0==CHARACTER_LITERAL||LA56_0==STRING_LITERAL||LA56_0==IDENTIFIER) ) { + alt56=1; + } + switch (alt56) { + case 1 : + // Grammar/CTFParser.g:969:9: ctfAssignmentExpressionList + { + pushFollow(FOLLOW_ctfAssignmentExpressionList_in_ctfBody3322); + ctfAssignmentExpressionList174=ctfAssignmentExpressionList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ctfAssignmentExpressionList.add(ctfAssignmentExpressionList174.getTree()); + + } + break; + + } + + RCURL175=(Token)match(input,RCURL,FOLLOW_RCURL_in_ctfBody3325); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_RCURL.add(RCURL175); + + + + // AST REWRITE + // elements: ctfAssignmentExpressionList + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 969:44: -> ( ctfAssignmentExpressionList )? + { + // Grammar/CTFParser.g:969:47: ( ctfAssignmentExpressionList )? + if ( stream_ctfAssignmentExpressionList.hasNext() ) { + adaptor.addChild(root_0, stream_ctfAssignmentExpressionList.nextTree()); + + } + stream_ctfAssignmentExpressionList.reset(); + + } + + retval.tree = root_0;} + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + debug_print("Scope pop " + + Symbols_stack.size()); + exit("ctfBody"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + Symbols_stack.pop(); + + } + return retval; + } + // $ANTLR end "ctfBody" + + public static class ctfAssignmentExpressionList_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfAssignmentExpressionList" + // Grammar/CTFParser.g:972:1: ctfAssignmentExpressionList : ( ctfAssignmentExpression TERM )+ ; + public final CTFParser.ctfAssignmentExpressionList_return ctfAssignmentExpressionList() throws RecognitionException { + CTFParser.ctfAssignmentExpressionList_return retval = new CTFParser.ctfAssignmentExpressionList_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token TERM177=null; + CTFParser.ctfAssignmentExpression_return ctfAssignmentExpression176 = null; + + + CommonTree TERM177_tree=null; + + try { + // Grammar/CTFParser.g:972:29: ( ( ctfAssignmentExpression TERM )+ ) + // Grammar/CTFParser.g:973:3: ( ctfAssignmentExpression TERM )+ + { + root_0 = (CommonTree)adaptor.nil(); + + // Grammar/CTFParser.g:973:3: ( ctfAssignmentExpression TERM )+ + int cnt57=0; + loop57: + do { + int alt57=2; + int LA57_0 = input.LA(1); + + if ( ((LA57_0>=ALIGNTOK && LA57_0<=CLOCKTOK)||LA57_0==SIGN||LA57_0==OCTAL_LITERAL||LA57_0==DECIMAL_LITERAL||LA57_0==HEX_LITERAL||LA57_0==CHARACTER_LITERAL||LA57_0==STRING_LITERAL||LA57_0==IDENTIFIER) ) { + alt57=1; + } + + + switch (alt57) { + case 1 : + // Grammar/CTFParser.g:973:4: ctfAssignmentExpression TERM + { + pushFollow(FOLLOW_ctfAssignmentExpression_in_ctfAssignmentExpressionList3344); + ctfAssignmentExpression176=ctfAssignmentExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, ctfAssignmentExpression176.getTree()); + TERM177=(Token)match(input,TERM,FOLLOW_TERM_in_ctfAssignmentExpressionList3346); if (state.failed) return retval; + + } + break; + + default : + if ( cnt57 >= 1 ) break loop57; + if (state.backtracking>0) {state.failed=true; return retval;} + EarlyExitException eee = + new EarlyExitException(57, input); + throw eee; + } + cnt57++; + } while (true); + + + } + + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "ctfAssignmentExpressionList" + + public static class ctfAssignmentExpression_return extends ParserRuleReturnScope { + CommonTree tree; + @Override + public Object getTree() { return tree; } + }; + + // $ANTLR start "ctfAssignmentExpression" + // Grammar/CTFParser.g:977:1: ctfAssignmentExpression : ( (left= unaryExpression ( (assignment= ASSIGNMENT right1= unaryExpression ) -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) | (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) ) ) | ( declarationSpecifiers {...}? declaratorList ) -> ^( TYPEDEF declaratorList declarationSpecifiers ) | typealiasDecl ); + public final CTFParser.ctfAssignmentExpression_return ctfAssignmentExpression() throws RecognitionException { + CTFParser.ctfAssignmentExpression_return retval = new CTFParser.ctfAssignmentExpression_return(); + retval.start = input.LT(1); + + CommonTree root_0 = null; + + Token assignment=null; + Token type_assignment=null; + CTFParser.unaryExpression_return left = null; + + CTFParser.unaryExpression_return right1 = null; + + CTFParser.typeSpecifier_return right2 = null; + + CTFParser.declarationSpecifiers_return declarationSpecifiers178 = null; + + CTFParser.declaratorList_return declaratorList179 = null; + + CTFParser.typealiasDecl_return typealiasDecl180 = null; + + + CommonTree assignment_tree=null; + CommonTree type_assignment_tree=null; + RewriteRuleTokenStream stream_ASSIGNMENT=new RewriteRuleTokenStream(adaptor,"token ASSIGNMENT"); + RewriteRuleTokenStream stream_TYPE_ASSIGNMENT=new RewriteRuleTokenStream(adaptor,"token TYPE_ASSIGNMENT"); + RewriteRuleSubtreeStream stream_declaratorList=new RewriteRuleSubtreeStream(adaptor,"rule declaratorList"); + RewriteRuleSubtreeStream stream_unaryExpression=new RewriteRuleSubtreeStream(adaptor,"rule unaryExpression"); + RewriteRuleSubtreeStream stream_declarationSpecifiers=new RewriteRuleSubtreeStream(adaptor,"rule declarationSpecifiers"); + RewriteRuleSubtreeStream stream_typeSpecifier=new RewriteRuleSubtreeStream(adaptor,"rule typeSpecifier"); + + enter("ctfAssignmentExpression"); + + try { + // Grammar/CTFParser.g:987:1: ( (left= unaryExpression ( (assignment= ASSIGNMENT right1= unaryExpression ) -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) | (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) ) ) | ( declarationSpecifiers {...}? declaratorList ) -> ^( TYPEDEF declaratorList declarationSpecifiers ) | typealiasDecl ) + int alt59=3; + switch ( input.LA(1) ) { + case IDENTIFIER: + { + int LA59_1 = input.LA(2); + + if ( ((LA59_1>=CONSTTOK && LA59_1<=ENUMTOK)||(LA59_1>=FLOATINGPOINTTOK && LA59_1<=SIGNEDTOK)||(LA59_1>=STRINGTOK && LA59_1<=STRUCTTOK)||(LA59_1>=TYPEDEFTOK && LA59_1<=IMAGINARYTOK)||LA59_1==POINTER||LA59_1==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) { + alt59=2; + } + else if ( ((LA59_1>=ASSIGNMENT && LA59_1<=TYPE_ASSIGNMENT)||LA59_1==OPENBRAC||(LA59_1>=ARROW && LA59_1<=DOT)) ) { + alt59=1; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 59, 1, input); + + throw nvae; + } + } + break; + case ALIGNTOK: + case EVENTTOK: + case STREAMTOK: + case TRACETOK: + case ENVTOK: + case CLOCKTOK: + case SIGN: + case OCTAL_LITERAL: + case DECIMAL_LITERAL: + case HEX_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + { + alt59=1; + } + break; + case SIGNEDTOK: + { + switch ( input.LA(2) ) { + case ASSIGNMENT: + case TYPE_ASSIGNMENT: + case OPENBRAC: + case ARROW: + case DOT: + { + alt59=1; + } + break; + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case SIGNEDTOK: + case STRINGTOK: + case STRUCTTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + case POINTER: + case IDENTIFIER: + { + alt59=2; + } + break; + case TYPEDEFTOK: + { + alt59=2; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 59, 3, input); + + throw nvae; + } + + } + break; + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case STRUCTTOK: + case TYPEDEFTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + { + alt59=2; + } + break; + case STRINGTOK: + { + switch ( input.LA(2) ) { + case ASSIGNMENT: + case TYPE_ASSIGNMENT: + case OPENBRAC: + case ARROW: + case DOT: + { + alt59=1; + } + break; + case CONSTTOK: + case CHARTOK: + case DOUBLETOK: + case ENUMTOK: + case FLOATINGPOINTTOK: + case FLOATTOK: + case INTEGERTOK: + case INTTOK: + case LONGTOK: + case SHORTTOK: + case SIGNEDTOK: + case STRINGTOK: + case STRUCTTOK: + case UNSIGNEDTOK: + case VARIANTTOK: + case VOIDTOK: + case BOOLTOK: + case COMPLEXTOK: + case IMAGINARYTOK: + case LCURL: + case POINTER: + case IDENTIFIER: + { + alt59=2; + } + break; + case TYPEDEFTOK: + { + alt59=2; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 59, 5, input); + + throw nvae; + } + + } + break; + case TYPEALIASTOK: + { + alt59=3; + } + break; + default: + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 59, 0, input); + + throw nvae; + } + + switch (alt59) { + case 1 : + // Grammar/CTFParser.g:988:3: (left= unaryExpression ( (assignment= ASSIGNMENT right1= unaryExpression ) -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) | (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) ) ) + { + // Grammar/CTFParser.g:988:3: (left= unaryExpression ( (assignment= ASSIGNMENT right1= unaryExpression ) -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) | (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) ) ) + // Grammar/CTFParser.g:989:5: left= unaryExpression ( (assignment= ASSIGNMENT right1= unaryExpression ) -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) | (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) ) + { + pushFollow(FOLLOW_unaryExpression_in_ctfAssignmentExpression3381); + left=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_unaryExpression.add(left.getTree()); + // Grammar/CTFParser.g:990:5: ( (assignment= ASSIGNMENT right1= unaryExpression ) -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) | (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) ) + int alt58=2; + int LA58_0 = input.LA(1); + + if ( (LA58_0==ASSIGNMENT) ) { + alt58=1; + } + else if ( (LA58_0==TYPE_ASSIGNMENT) ) { + alt58=2; + } + else { + if (state.backtracking>0) {state.failed=true; return retval;} + NoViableAltException nvae = + new NoViableAltException("", 58, 0, input); + + throw nvae; + } + switch (alt58) { + case 1 : + // Grammar/CTFParser.g:991:9: (assignment= ASSIGNMENT right1= unaryExpression ) + { + // Grammar/CTFParser.g:991:9: (assignment= ASSIGNMENT right1= unaryExpression ) + // Grammar/CTFParser.g:991:10: assignment= ASSIGNMENT right1= unaryExpression + { + assignment=(Token)match(input,ASSIGNMENT,FOLLOW_ASSIGNMENT_in_ctfAssignmentExpression3400); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_ASSIGNMENT.add(assignment); + + pushFollow(FOLLOW_unaryExpression_in_ctfAssignmentExpression3404); + right1=unaryExpression(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_unaryExpression.add(right1.getTree()); + + } + + + + // AST REWRITE + // elements: right1, left + // token labels: + // rule labels: retval, left, right1 + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + RewriteRuleSubtreeStream stream_left=new RewriteRuleSubtreeStream(adaptor,"rule left",left!=null?left.tree:null); + RewriteRuleSubtreeStream stream_right1=new RewriteRuleSubtreeStream(adaptor,"rule right1",right1!=null?right1.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 991:56: -> ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) + { + // Grammar/CTFParser.g:991:59: ^( CTF_EXPRESSION_VAL ^( CTF_LEFT $left) ^( CTF_RIGHT $right1) ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(CTF_EXPRESSION_VAL, "CTF_EXPRESSION_VAL"), root_1); + + // Grammar/CTFParser.g:991:80: ^( CTF_LEFT $left) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(CTF_LEFT, "CTF_LEFT"), root_2); + + adaptor.addChild(root_2, stream_left.nextTree()); + + adaptor.addChild(root_1, root_2); + } + // Grammar/CTFParser.g:991:98: ^( CTF_RIGHT $right1) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(CTF_RIGHT, "CTF_RIGHT"), root_2); + + adaptor.addChild(root_2, stream_right1.nextTree()); + + adaptor.addChild(root_1, root_2); + } + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 2 : + // Grammar/CTFParser.g:992:9: (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) + { + // Grammar/CTFParser.g:992:9: (type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier ) + // Grammar/CTFParser.g:992:10: type_assignment= TYPE_ASSIGNMENT right2= typeSpecifier + { + type_assignment=(Token)match(input,TYPE_ASSIGNMENT,FOLLOW_TYPE_ASSIGNMENT_in_ctfAssignmentExpression3438); if (state.failed) return retval; + if ( state.backtracking==0 ) stream_TYPE_ASSIGNMENT.add(type_assignment); + + pushFollow(FOLLOW_typeSpecifier_in_ctfAssignmentExpression3443); + right2=typeSpecifier(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_typeSpecifier.add(right2.getTree()); + + } + + + + // AST REWRITE + // elements: left, right2 + // token labels: + // rule labels: retval, left, right2 + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + RewriteRuleSubtreeStream stream_left=new RewriteRuleSubtreeStream(adaptor,"rule left",left!=null?left.tree:null); + RewriteRuleSubtreeStream stream_right2=new RewriteRuleSubtreeStream(adaptor,"rule right2",right2!=null?right2.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 992:65: -> ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) + { + // Grammar/CTFParser.g:992:68: ^( CTF_EXPRESSION_TYPE ^( CTF_LEFT $left) ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(CTF_EXPRESSION_TYPE, "CTF_EXPRESSION_TYPE"), root_1); + + // Grammar/CTFParser.g:992:90: ^( CTF_LEFT $left) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(CTF_LEFT, "CTF_LEFT"), root_2); + + adaptor.addChild(root_2, stream_left.nextTree()); + + adaptor.addChild(root_1, root_2); + } + // Grammar/CTFParser.g:992:108: ^( CTF_RIGHT ^( TYPE_SPECIFIER_LIST $right2) ) + { + CommonTree root_2 = (CommonTree)adaptor.nil(); + root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(CTF_RIGHT, "CTF_RIGHT"), root_2); + + // Grammar/CTFParser.g:992:120: ^( TYPE_SPECIFIER_LIST $right2) + { + CommonTree root_3 = (CommonTree)adaptor.nil(); + root_3 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPE_SPECIFIER_LIST, "TYPE_SPECIFIER_LIST"), root_3); + + adaptor.addChild(root_3, stream_right2.nextTree()); + + adaptor.addChild(root_2, root_3); + } + + adaptor.addChild(root_1, root_2); + } + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + + } + + + } + + + } + break; + case 2 : + // Grammar/CTFParser.g:998:5: ( declarationSpecifiers {...}? declaratorList ) + { + // Grammar/CTFParser.g:998:5: ( declarationSpecifiers {...}? declaratorList ) + // Grammar/CTFParser.g:998:6: declarationSpecifiers {...}? declaratorList + { + pushFollow(FOLLOW_declarationSpecifiers_in_ctfAssignmentExpression3493); + declarationSpecifiers178=declarationSpecifiers(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declarationSpecifiers.add(declarationSpecifiers178.getTree()); + if ( !((inTypedef())) ) { + if (state.backtracking>0) {state.failed=true; return retval;} + throw new FailedPredicateException(input, "ctfAssignmentExpression", "inTypedef()"); + } + pushFollow(FOLLOW_declaratorList_in_ctfAssignmentExpression3497); + declaratorList179=declaratorList(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) stream_declaratorList.add(declaratorList179.getTree()); + + } + + + + // AST REWRITE + // elements: declaratorList, declarationSpecifiers + // token labels: + // rule labels: retval + // token list labels: + // rule list labels: + // wildcard labels: + if ( state.backtracking==0 ) { + retval.tree = root_0; + RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null); + + root_0 = (CommonTree)adaptor.nil(); + // 999:5: -> ^( TYPEDEF declaratorList declarationSpecifiers ) + { + // Grammar/CTFParser.g:999:8: ^( TYPEDEF declaratorList declarationSpecifiers ) + { + CommonTree root_1 = (CommonTree)adaptor.nil(); + root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TYPEDEF, "TYPEDEF"), root_1); + + adaptor.addChild(root_1, stream_declaratorList.nextTree()); + adaptor.addChild(root_1, stream_declarationSpecifiers.nextTree()); + + adaptor.addChild(root_0, root_1); + } + + } + + retval.tree = root_0;} + } + break; + case 3 : + // Grammar/CTFParser.g:1002:5: typealiasDecl + { + root_0 = (CommonTree)adaptor.nil(); + + pushFollow(FOLLOW_typealiasDecl_in_ctfAssignmentExpression3525); + typealiasDecl180=typealiasDecl(); + + state._fsp--; + if (state.failed) return retval; + if ( state.backtracking==0 ) adaptor.addChild(root_0, typealiasDecl180.getTree()); + + } + break; + + } + retval.stop = input.LT(-1); + + if ( state.backtracking==0 ) { + + retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0); + adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); + } + if ( state.backtracking==0 ) { + + if (inTypedef()) { + typedefOff(); + } + exit("ctfAssignmentExpression"); + + } + } + + catch (RecognitionException e) + { + throw e; + } + finally { + } + return retval; + } + // $ANTLR end "ctfAssignmentExpression" + + // $ANTLR start synpred1_CTFParser + public final void synpred1_CTFParser_fragment() throws RecognitionException { + // Grammar/CTFParser.g:250:5: ( IDENTIFIER ) + // Grammar/CTFParser.g:250:6: IDENTIFIER + { + match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_synpred1_CTFParser470); if (state.failed) return ; + + } + } + // $ANTLR end synpred1_CTFParser + + // $ANTLR start synpred2_CTFParser + public final void synpred2_CTFParser_fragment() throws RecognitionException { + // Grammar/CTFParser.g:251:5: ( ctfKeyword ) + // Grammar/CTFParser.g:251:6: ctfKeyword + { + pushFollow(FOLLOW_ctfKeyword_in_synpred2_CTFParser492); + ctfKeyword(); + + state._fsp--; + if (state.failed) return ; + + } + } + // $ANTLR end synpred2_CTFParser + + // $ANTLR start synpred3_CTFParser + public final void synpred3_CTFParser_fragment() throws RecognitionException { + // Grammar/CTFParser.g:252:5: ( STRING_LITERAL ) + // Grammar/CTFParser.g:252:6: STRING_LITERAL + { + match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_synpred3_CTFParser512); if (state.failed) return ; + + } + } + // $ANTLR end synpred3_CTFParser + + // Delegated rules + + public final boolean synpred2_CTFParser() { + state.backtracking++; + int start = input.mark(); + try { + synpred2_CTFParser_fragment(); // can never throw exception + } catch (RecognitionException re) { + System.err.println("impossible: "+re); + } + boolean success = !state.failed; + input.rewind(start); + state.backtracking--; + state.failed=false; + return success; + } + public final boolean synpred1_CTFParser() { + state.backtracking++; + int start = input.mark(); + try { + synpred1_CTFParser_fragment(); // can never throw exception + } catch (RecognitionException re) { + System.err.println("impossible: "+re); + } + boolean success = !state.failed; + input.rewind(start); + state.backtracking--; + state.failed=false; + return success; + } + public final boolean synpred3_CTFParser() { + state.backtracking++; + int start = input.mark(); + try { + synpred3_CTFParser_fragment(); // can never throw exception + } catch (RecognitionException re) { + System.err.println("impossible: "+re); + } + boolean success = !state.failed; + input.rewind(start); + state.backtracking--; + state.failed=false; + return success; + } + + + protected DFA10 dfa10 = new DFA10(this); + protected DFA17 dfa17 = new DFA17(this); + protected DFA24 dfa24 = new DFA24(this); + protected DFA32 dfa32 = new DFA32(this); + protected DFA54 dfa54 = new DFA54(this); + static final String DFA10_eotS = + "\16\uffff"; + static final String DFA10_eofS = + "\16\uffff"; + static final String DFA10_minS = + "\1\4\15\uffff"; + static final String DFA10_maxS = + "\1\116\15\uffff"; + static final String DFA10_acceptS = + "\1\uffff\2\1\7\uffff\1\2\3\uffff"; + static final String DFA10_specialS = + "\16\uffff}>"; + static final String[] DFA10_transitionS = { + "\1\1\4\uffff\1\2\6\uffff\1\1\1\12\1\1\1\uffff\1\12\10\uffff"+ + "\2\12\22\uffff\1\1\4\uffff\1\1\1\uffff\1\1\2\uffff\1\1\10\uffff"+ + "\1\1\2\uffff\1\1\6\uffff\1\1", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + }; + + static final short[] DFA10_eot = DFA.unpackEncodedString(DFA10_eotS); + static final short[] DFA10_eof = DFA.unpackEncodedString(DFA10_eofS); + static final char[] DFA10_min = DFA.unpackEncodedStringToUnsignedChars(DFA10_minS); + static final char[] DFA10_max = DFA.unpackEncodedStringToUnsignedChars(DFA10_maxS); + static final short[] DFA10_accept = DFA.unpackEncodedString(DFA10_acceptS); + static final short[] DFA10_special = DFA.unpackEncodedString(DFA10_specialS); + static final short[][] DFA10_transition; + + static { + int numStates = DFA10_transitionS.length; + DFA10_transition = new short[numStates][]; + for (int i=0; i"; + static final String[] DFA17_transitionS = { + "\1\7\1\10\1\17\1\uffff\1\20\1\1\1\20\1\2\1\3\1\4\1\5\1\uffff"+ + "\1\20\1\15\3\uffff\1\6\1\16\1\11\1\12\1\13\1\14\61\uffff\1\21", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + }; + + static final short[] DFA17_eot = DFA.unpackEncodedString(DFA17_eotS); + static final short[] DFA17_eof = DFA.unpackEncodedString(DFA17_eofS); + static final char[] DFA17_min = DFA.unpackEncodedStringToUnsignedChars(DFA17_minS); + static final char[] DFA17_max = DFA.unpackEncodedStringToUnsignedChars(DFA17_maxS); + static final short[] DFA17_accept = DFA.unpackEncodedString(DFA17_acceptS); + static final short[] DFA17_special = DFA.unpackEncodedString(DFA17_specialS); + static final short[][] DFA17_transition; + + static { + int numStates = DFA17_transitionS.length; + DFA17_transition = new short[numStates][]; + for (int i=0; i typedefName );"; + } + @Override + public int specialStateTransition(int s, IntStream _input) throws NoViableAltException { + TokenStream input = (TokenStream)_input; + int _s = s; + switch ( s ) { + case 0 : + int LA17_0 = input.LA(1); + + + int index17_0 = input.index(); + input.rewind(); + s = -1; + if ( (LA17_0==FLOATTOK) ) {s = 1;} + + else if ( (LA17_0==INTTOK) ) {s = 2;} + + else if ( (LA17_0==LONGTOK) ) {s = 3;} + + else if ( (LA17_0==SHORTTOK) ) {s = 4;} + + else if ( (LA17_0==SIGNEDTOK) ) {s = 5;} + + else if ( (LA17_0==UNSIGNEDTOK) ) {s = 6;} + + else if ( (LA17_0==CHARTOK) ) {s = 7;} + + else if ( (LA17_0==DOUBLETOK) ) {s = 8;} + + else if ( (LA17_0==VOIDTOK) ) {s = 9;} + + else if ( (LA17_0==BOOLTOK) ) {s = 10;} + + else if ( (LA17_0==COMPLEXTOK) ) {s = 11;} + + else if ( (LA17_0==IMAGINARYTOK) ) {s = 12;} + + else if ( (LA17_0==STRUCTTOK) ) {s = 13;} + + else if ( (LA17_0==VARIANTTOK) ) {s = 14;} + + else if ( (LA17_0==ENUMTOK) ) {s = 15;} + + else if ( (LA17_0==FLOATINGPOINTTOK||LA17_0==INTEGERTOK||LA17_0==STRINGTOK) ) {s = 16;} + + else if ( (LA17_0==IDENTIFIER) && ((inTypealiasAlias() || isTypeName(input.LT(1).getText())))) {s = 17;} + + + input.seek(index17_0); + if ( s>=0 ) return s; + break; + } + if (state.backtracking>0) {state.failed=true; return -1;} + NoViableAltException nvae = + new NoViableAltException(getDescription(), 17, _s, input); + error(nvae); + throw nvae; + } + } + static final String DFA24_eotS = + "\6\uffff"; + static final String DFA24_eofS = + "\6\uffff"; + static final String DFA24_minS = + "\1\60\1\5\1\0\1\5\2\uffff"; + static final String DFA24_maxS = + "\2\116\1\0\1\116\2\uffff"; + static final String DFA24_acceptS = + "\4\uffff\1\1\1\2"; + static final String DFA24_specialS = + "\2\uffff\1\0\3\uffff}>"; + static final String[] DFA24_transitionS = { + "\1\1\35\uffff\1\2", + "\1\3\52\uffff\1\1\35\uffff\1\2", + "\1\uffff", + "\1\3\52\uffff\1\1\35\uffff\1\2", + "", + "" + }; + + static final short[] DFA24_eot = DFA.unpackEncodedString(DFA24_eotS); + static final short[] DFA24_eof = DFA.unpackEncodedString(DFA24_eofS); + static final char[] DFA24_min = DFA.unpackEncodedStringToUnsignedChars(DFA24_minS); + static final char[] DFA24_max = DFA.unpackEncodedStringToUnsignedChars(DFA24_maxS); + static final short[] DFA24_accept = DFA.unpackEncodedString(DFA24_acceptS); + static final short[] DFA24_special = DFA.unpackEncodedString(DFA24_specialS); + static final short[][] DFA24_transition; + + static { + int numStates = DFA24_transitionS.length; + DFA24_transition = new short[numStates][]; + for (int i=0; i declaratorList -> ^( TYPEDEF declaratorList declarationSpecifiers ) | structOrVariantDeclaratorList -> ^( SV_DECLARATION declarationSpecifiers structOrVariantDeclaratorList ) )"; + } + @Override + public int specialStateTransition(int s, IntStream _input) throws NoViableAltException { + TokenStream input = (TokenStream)_input; + int _s = s; + switch ( s ) { + case 0 : + int LA24_2 = input.LA(1); + + + int index24_2 = input.index(); + input.rewind(); + s = -1; + if ( ((inTypedef())) ) {s = 4;} + + else if ( (true) ) {s = 5;} + + + input.seek(index24_2); + if ( s>=0 ) return s; + break; + } + if (state.backtracking>0) {state.failed=true; return -1;} + NoViableAltException nvae = + new NoViableAltException(getDescription(), 24, _s, input); + error(nvae); + throw nvae; + } + } + static final String DFA32_eotS = + "\35\uffff"; + static final String DFA32_eofS = + "\1\3\34\uffff"; + static final String DFA32_minS = + "\1\5\34\uffff"; + static final String DFA32_maxS = + "\1\116\34\uffff"; + static final String DFA32_acceptS = + "\1\uffff\1\1\1\2\1\3\31\uffff"; + static final String DFA32_specialS = + "\35\uffff}>"; + static final String[] DFA32_transitionS = { + "\4\3\1\uffff\7\3\1\uffff\2\3\2\uffff\7\3\6\uffff\1\1\2\uffff"+ + "\1\3\4\uffff\1\3\1\uffff\1\2\1\uffff\2\3\35\uffff\1\3", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + }; + + static final short[] DFA32_eot = DFA.unpackEncodedString(DFA32_eotS); + static final short[] DFA32_eof = DFA.unpackEncodedString(DFA32_eofS); + static final char[] DFA32_min = DFA.unpackEncodedStringToUnsignedChars(DFA32_minS); + static final char[] DFA32_max = DFA.unpackEncodedStringToUnsignedChars(DFA32_maxS); + static final short[] DFA32_accept = DFA.unpackEncodedString(DFA32_acceptS); + static final short[] DFA32_special = DFA.unpackEncodedString(DFA32_specialS); + static final short[][] DFA32_transition; + + static { + int numStates = DFA32_transitionS.length; + DFA32_transition = new short[numStates][]; + for (int i=0; i"; + static final String[] DFA54_transitionS = { + "\4\2\1\uffff\7\2\1\uffff\2\2\2\uffff\7\2\11\uffff\1\2\4\uffff"+ + "\1\2\1\uffff\1\1\1\uffff\2\2\35\uffff\1\2", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + }; + + static final short[] DFA54_eot = DFA.unpackEncodedString(DFA54_eotS); + static final short[] DFA54_eof = DFA.unpackEncodedString(DFA54_eofS); + static final char[] DFA54_min = DFA.unpackEncodedStringToUnsignedChars(DFA54_minS); + static final char[] DFA54_max = DFA.unpackEncodedStringToUnsignedChars(DFA54_maxS); + static final short[] DFA54_accept = DFA.unpackEncodedString(DFA54_acceptS); + static final short[] DFA54_special = DFA.unpackEncodedString(DFA54_specialS); + static final short[][] DFA54_transition; + + static { + int numStates = DFA54_transitionS.length; + DFA54_transition = new short[numStates][]; + for (int i=0; i + + org.eclipse.linuxtools.ctf + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/org.eclipse.linuxtools.ctf/build.properties b/org.eclipse.linuxtools.ctf/build.properties new file mode 100644 index 0000000000..39b0777e50 --- /dev/null +++ b/org.eclipse.linuxtools.ctf/build.properties @@ -0,0 +1,4 @@ +bin.includes = feature.xml,\ + epl-v10.html,\ + feature.properties,\ + license.html diff --git a/org.eclipse.linuxtools.ctf/epl-v10.html b/org.eclipse.linuxtools.ctf/epl-v10.html new file mode 100644 index 0000000000..9321f4082e --- /dev/null +++ b/org.eclipse.linuxtools.ctf/epl-v10.html @@ -0,0 +1,256 @@ + + + + + + +Eclipse Public License - Version 1.0 + + + +

Eclipse Public License - v 1.0

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS +AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) in the case of the initial Contributor, the initial +code and documentation distributed under this Agreement, and

+

b) in the case of each subsequent Contributor:

+

i) changes to the Program, and

+

ii) additions to the Program;

+

where such changes and/or additions to the Program +originate from and are distributed by that particular Contributor. A +Contribution 'originates' from a Contributor if it was added to the +Program by such Contributor itself or anyone acting on such +Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) +are not derivative works of the Program.

+ +

"Contributor" means any person or entity that distributes +the Program.

+ +

"Licensed Patents" mean patent claims licensable by a +Contributor which are necessarily infringed by the use or sale of its +Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions distributed in accordance +with this Agreement.

+ +

"Recipient" means anyone who receives the Program under +this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free copyright license to reproduce, prepare derivative works +of, publicly display, publicly perform, distribute and sublicense the +Contribution of such Contributor, if any, and such derivative works, in +source code and object code form.

+ +

b) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free patent license under Licensed Patents to make, use, sell, +offer to sell, import and otherwise transfer the Contribution of such +Contributor, if any, in source code and object code form. This patent +license shall apply to the combination of the Contribution and the +Program if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to be covered +by the Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) Recipient understands that although each Contributor +grants the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility to +secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow Recipient +to distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program.

+ +

d) Each Contributor represents that to its knowledge it +has sufficient copyright rights in its Contribution, if any, to grant +the copyright license set forth in this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the Program in object code +form under its own license agreement, provided that:

+ +

a) it complies with the terms and conditions of this +Agreement; and

+ +

b) its license agreement:

+ +

i) effectively disclaims on behalf of all Contributors +all warranties and conditions, express and implied, including warranties +or conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose;

+ +

ii) effectively excludes on behalf of all Contributors +all liability for damages, including direct, indirect, special, +incidental and consequential damages, such as lost profits;

+ +

iii) states that any provisions which differ from this +Agreement are offered by that Contributor alone and not by any other +party; and

+ +

iv) states that source code for the Program is available +from such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for software +exchange.

+ +

When the Program is made available in source code form:

+ +

a) it must be made available under this Agreement; and

+ +

b) a copy of this Agreement must be included with each +copy of the Program.

+ +

Contributors may not remove or alter any copyright notices contained +within the Program.

+ +

Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and +indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") +arising from claims, lawsuits and other legal actions brought by a third +party against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In +order to qualify, an Indemnified Contributor must: a) promptly notify +the Commercial Contributor in writing of such claim, and b) allow the +Commercial Contributor to control, and cooperate with the Commercial +Contributor in, the defense and any related settlement negotiations. The +Indemnified Contributor may participate in any such claim at its own +expense.

+ +

For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable laws, +damage to or loss of data, programs or equipment, and unavailability or +interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further action +by the parties hereto, such provision shall be reformed to the minimum +extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the +date such litigation is filed.

+ +

All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of time +after becoming aware of such noncompliance. If all Recipient's rights +under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute copies of this +Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The +Agreement Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other than the +Agreement Steward has the right to modify this Agreement. The Eclipse +Foundation is the initial Agreement Steward. The Eclipse Foundation may +assign the responsibility to serve as the Agreement Steward to a +suitable separate entity. Each new version of the Agreement will be +given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version +of the Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives no +rights or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved.

+ +

This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No party +to this Agreement will bring a legal action under this Agreement more +than one year after the cause of action arose. Each party waives its +rights to a jury trial in any resulting litigation.

+ + \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf/feature.properties b/org.eclipse.linuxtools.ctf/feature.properties new file mode 100644 index 0000000000..c5e5f30679 --- /dev/null +++ b/org.eclipse.linuxtools.ctf/feature.properties @@ -0,0 +1,145 @@ +#******************************************************************************* +# Copyright (c) 2008 Red Hat, Inc. +# 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: +# Ericsson - initial API and implementation +#******************************************************************************** + +featureName=CTF - Common Trace Format (Incubation) + +description=CTF plugins. + +featureProvider=Eclipse Linux Tools + +copyright=Copyright 2011 Ericsson + +licenseURL=epl-v10.html + +license=\ +Eclipse Foundation Software User Agreement\n\ +February 1, 2011\n\ +\n\ +Usage Of Content\n\ +\n\ +THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR\n\ +OTHER MATERIALS FOR OPEN SOURCE PROJECTS (COLLECTIVELY "CONTENT").\n\ +USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS\n\ +AGREEMENT AND/OR THE TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR\n\ +NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU\n\ +AGREE THAT YOUR USE OF THE CONTENT IS GOVERNED BY THIS AGREEMENT\n\ +AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS\n\ +OR NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE\n\ +TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND CONDITIONS\n\ +OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED\n\ +BELOW, THEN YOU MAY NOT USE THE CONTENT.\n\ +\n\ +Applicable Licenses\n\ +\n\ +Unless otherwise indicated, all Content made available by the\n\ +Eclipse Foundation is provided to you under the terms and conditions of\n\ +the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is\n\ +provided with this Content and is also available at http://www.eclipse.org/legal/epl-v10.html.\n\ +For purposes of the EPL, "Program" will mean the Content.\n\ +\n\ +Content includes, but is not limited to, source code, object code,\n\ +documentation and other files maintained in the Eclipse Foundation source code\n\ +repository ("Repository") in software modules ("Modules") and made available\n\ +as downloadable archives ("Downloads").\n\ +\n\ + - Content may be structured and packaged into modules to facilitate delivering,\n\ + extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"),\n\ + plug-in fragments ("Fragments"), and features ("Features").\n\ + - Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java(TM) ARchive)\n\ + in a directory named "plugins".\n\ + - A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material.\n\ + Each Feature may be packaged as a sub-directory in a directory named "features".\n\ + Within a Feature, files named "feature.xml" may contain a list of the names and version\n\ + numbers of the Plug-ins and/or Fragments associated with that Feature.\n\ + - Features may also include other Features ("Included Features"). Within a Feature, files\n\ + named "feature.xml" may contain a list of the names and version numbers of Included Features.\n\ +\n\ +The terms and conditions governing Plug-ins and Fragments should be\n\ +contained in files named "about.html" ("Abouts"). The terms and\n\ +conditions governing Features and Included Features should be contained\n\ +in files named "license.html" ("Feature Licenses"). Abouts and Feature\n\ +Licenses may be located in any directory of a Download or Module\n\ +including, but not limited to the following locations:\n\ +\n\ + - The top-level (root) directory\n\ + - Plug-in and Fragment directories\n\ + - Inside Plug-ins and Fragments packaged as JARs\n\ + - Sub-directories of the directory named "src" of certain Plug-ins\n\ + - Feature directories\n\ +\n\ +Note: if a Feature made available by the Eclipse Foundation is installed using the\n\ +Provisioning Technology (as defined below), you must agree to a license ("Feature \n\ +Update License") during the installation process. If the Feature contains\n\ +Included Features, the Feature Update License should either provide you\n\ +with the terms and conditions governing the Included Features or inform\n\ +you where you can locate them. Feature Update Licenses may be found in\n\ +the "license" property of files named "feature.properties" found within a Feature.\n\ +Such Abouts, Feature Licenses, and Feature Update Licenses contain the\n\ +terms and conditions (or references to such terms and conditions) that\n\ +govern your use of the associated Content in that directory.\n\ +\n\ +THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER\n\ +TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS.\n\ +SOME OF THESE OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):\n\ +\n\ + - Eclipse Distribution License Version 1.0 (available at http://www.eclipse.org/licenses/edl-v1.0.html)\n\ + - Common Public License Version 1.0 (available at http://www.eclipse.org/legal/cpl-v10.html)\n\ + - Apache Software License 1.1 (available at http://www.apache.org/licenses/LICENSE)\n\ + - Apache Software License 2.0 (available at http://www.apache.org/licenses/LICENSE-2.0)\n\ + - Metro Link Public License 1.00 (available at http://www.opengroup.org/openmotif/supporters/metrolink/license.html)\n\ + - Mozilla Public License Version 1.1 (available at http://www.mozilla.org/MPL/MPL-1.1.html)\n\ +\n\ +IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR\n\ +TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License\n\ +is provided, please contact the Eclipse Foundation to determine what terms and conditions\n\ +govern that particular Content.\n\ +\n\ +\n\Use of Provisioning Technology\n\ +\n\ +The Eclipse Foundation makes available provisioning software, examples of which include,\n\ +but are not limited to, p2 and the Eclipse Update Manager ("Provisioning Technology") for\n\ +the purpose of allowing users to install software, documentation, information and/or\n\ +other materials (collectively "Installable Software"). This capability is provided with\n\ +the intent of allowing such users to install, extend and update Eclipse-based products.\n\ +Information about packaging Installable Software is available at\n\ +http://eclipse.org/equinox/p2/repository_packaging.html ("Specification").\n\ +\n\ +You may use Provisioning Technology to allow other parties to install Installable Software.\n\ +You shall be responsible for enabling the applicable license agreements relating to the\n\ +Installable Software to be presented to, and accepted by, the users of the Provisioning Technology\n\ +in accordance with the Specification. By using Provisioning Technology in such a manner and\n\ +making it available in accordance with the Specification, you further acknowledge your\n\ +agreement to, and the acquisition of all necessary rights to permit the following:\n\ +\n\ + 1. A series of actions may occur ("Provisioning Process") in which a user may execute\n\ + the Provisioning Technology on a machine ("Target Machine") with the intent of installing,\n\ + extending or updating the functionality of an Eclipse-based product.\n\ + 2. During the Provisioning Process, the Provisioning Technology may cause third party\n\ + Installable Software or a portion thereof to be accessed and copied to the Target Machine.\n\ + 3. Pursuant to the Specification, you will provide to the user the terms and conditions that\n\ + govern the use of the Installable Software ("Installable Software Agreement") and such\n\ + Installable Software Agreement shall be accessed from the Target Machine in accordance\n\ + with the Specification. Such Installable Software Agreement must inform the user of the\n\ + terms and conditions that govern the Installable Software and must solicit acceptance by\n\ + the end user in the manner prescribed in such Installable Software Agreement. Upon such\n\ + indication of agreement by the user, the provisioning Technology will complete installation\n\ + of the Installable Software.\n\ +\n\ +Cryptography\n\ +\n\ +Content may contain encryption software. The country in which you are\n\ +currently may have restrictions on the import, possession, and use,\n\ +and/or re-export to another country, of encryption software. BEFORE\n\ +using any encryption software, please check the country's laws,\n\ +regulations and policies concerning the import, possession, or use, and\n\ +re-export of encryption software, to see if this is permitted.\n\ +\n\ +Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.\n \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf/feature.xml b/org.eclipse.linuxtools.ctf/feature.xml new file mode 100644 index 0000000000..3516ed7c1c --- /dev/null +++ b/org.eclipse.linuxtools.ctf/feature.xml @@ -0,0 +1,44 @@ + + + + + %description + + + + %copyright + + + + %license + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.ctf/license.html b/org.eclipse.linuxtools.ctf/license.html new file mode 100644 index 0000000000..6e579a585b --- /dev/null +++ b/org.eclipse.linuxtools.ctf/license.html @@ -0,0 +1,164 @@ + + + + +Eclipse Foundation Software User Agreement + + + +

Eclipse Foundation Software User Agreement

+

February 1, 2011

+ +

Usage Of Content

+ +

THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS + (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND + CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE + OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR + NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND + CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.

+ +

Applicable Licenses

+ +

Unless otherwise indicated, all Content made available by the Eclipse + Foundation is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 + ("EPL"). A copy of the EPL is provided with this Content and is also + available at http://www.eclipse.org/legal/epl-v10.html. + For purposes of the EPL, "Program" will mean the Content.

+ +

Content includes, but is not limited to, source code, object code, +documentation and other files maintained in the Eclipse Foundation +source code + repository ("Repository") in software modules ("Modules") and made +available as downloadable archives ("Downloads").

+ +
    +
  • Content may be structured and packaged into modules to +facilitate delivering, extending, and upgrading the Content. Typical +modules may include plug-ins ("Plug-ins"), plug-in fragments +("Fragments"), and features ("Features").
  • +
  • Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".
  • +
  • A Feature is a bundle of one or more Plug-ins and/or +Fragments and associated material. Each Feature may be packaged as a +sub-directory in a directory named "features". Within a Feature, files +named "feature.xml" may contain a list of the names and version numbers +of the Plug-ins + and/or Fragments associated with that Feature.
  • +
  • Features may also include other Features ("Included +Features"). Within a Feature, files named "feature.xml" may contain a +list of the names and version numbers of Included Features.
  • +
+ +

The terms and conditions governing Plug-ins and Fragments should be +contained in files named "about.html" ("Abouts"). The terms and +conditions governing Features and +Included Features should be contained in files named "license.html" +("Feature Licenses"). Abouts and Feature Licenses may be located in any + directory of a Download or Module +including, but not limited to the following locations:

+ +
    +
  • The top-level (root) directory
  • +
  • Plug-in and Fragment directories
  • +
  • Inside Plug-ins and Fragments packaged as JARs
  • +
  • Sub-directories of the directory named "src" of certain Plug-ins
  • +
  • Feature directories
  • +
+ +

Note: if a Feature made available by the Eclipse Foundation is +installed using the Provisioning Technology (as defined below), you must + agree to a license ("Feature Update License") during the +installation process. If the Feature contains Included Features, the +Feature Update License should either provide you with the terms and +conditions governing the Included Features or +inform you where you can locate them. Feature Update Licenses may be +found in the "license" property of files named "feature.properties" +found within a Feature. +Such Abouts, Feature Licenses, and Feature Update Licenses contain the +terms and conditions (or references to such terms and conditions) that +govern your use of the associated Content in +that directory.

+ +

THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER +TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. + SOME OF THESE +OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):

+ + + +

IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND +CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, +or Feature Update License is provided, please +contact the Eclipse Foundation to determine what terms and conditions +govern that particular Content.

+ + +

Use of Provisioning Technology

+ +

The Eclipse Foundation makes available provisioning software, +examples of which include, but are not limited to, p2 and the Eclipse + Update Manager ("Provisioning Technology") for the purpose of +allowing users to install software, documentation, information and/or + other materials (collectively "Installable Software"). This +capability is provided with the intent of allowing such users to + install, extend and update Eclipse-based products. Information about +packaging Installable Software is available at http://eclipse.org/equinox/p2/repository_packaging.html + ("Specification").

+ +

You may use Provisioning Technology to allow other parties to install + Installable Software. You shall be responsible for enabling the + applicable license agreements relating to the Installable Software to + be presented to, and accepted by, the users of the Provisioning +Technology + in accordance with the Specification. By using Provisioning +Technology in such a manner and making it available in accordance with +the + Specification, you further acknowledge your agreement to, and the +acquisition of all necessary rights to permit the following:

+ +
    +
  1. A series of actions may occur ("Provisioning Process") in +which a user may execute the Provisioning Technology + on a machine ("Target Machine") with the intent of installing, +extending or updating the functionality of an Eclipse-based + product.
  2. +
  3. During the Provisioning Process, the Provisioning Technology +may cause third party Installable Software or a portion thereof to be + accessed and copied to the Target Machine.
  4. +
  5. Pursuant to the Specification, you will provide to the user +the terms and conditions that govern the use of the Installable + Software ("Installable Software Agreement") and such Installable +Software Agreement shall be accessed from the Target + Machine in accordance with the Specification. Such Installable +Software Agreement must inform the user of the terms and conditions that + govern + the Installable Software and must solicit acceptance by the end +user in the manner prescribed in such Installable Software Agreement. +Upon such + indication of agreement by the user, the provisioning Technology +will complete installation of the Installable Software.
  6. +
+ +

Cryptography

+ +

Content may contain encryption software. The country in which you are + currently may have restrictions on the import, possession, and use, +and/or re-export to + another country, of encryption software. BEFORE using any encryption +software, please check the country's laws, regulations and policies +concerning the import, + possession, or use, and re-export of encryption software, to see if +this is permitted.

+ +

Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.

+ + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.ctf/pom.xml b/org.eclipse.linuxtools.ctf/pom.xml new file mode 100644 index 0000000000..993f7ba469 --- /dev/null +++ b/org.eclipse.linuxtools.ctf/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + + + linuxtools-lttng-parent + org.eclipse.linuxtools.lttng + 0.10.0-SNAPSHOT + + + Linux Tools LTTng CTF (Common Trace Format) + org.eclipse.linuxtools.ctf + org.eclipse.linuxtools.ctf + 0.1.0-SNAPSHOT + + diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF index 2551e41901..358462c019 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/META-INF/MANIFEST.MF @@ -12,4 +12,3 @@ Require-Bundle: org.junit;bundle-version="3.8.2", Bundle-Localization: plugin Bundle-Activator: org.eclipse.linuxtools.lttng2.kernel.core.tests.Activator Bundle-ActivationPolicy: lazy - diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TmfTimeStatesCtrl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TmfTimeStatesCtrl.java index 9d59cac569..11b6c17f9d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TmfTimeStatesCtrl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TmfTimeStatesCtrl.java @@ -613,7 +613,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener, KeyLi return hit; } - public Item getItem(Point pt) { + Item getItem(Point pt) { int idx = hitTest(pt.x, pt.y); return idx >= 0 ? (Item) _data._items[idx] : null; } diff --git a/pom.xml b/pom.xml index edad957791..16098fab57 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,11 @@ + org.eclipse.linuxtools.ctf + org.eclipse.linuxtools.ctf.core + + org.eclipse.linuxtools.ctf.parser + org.eclipse.linuxtools.tmf org.eclipse.linuxtools.tmf.core org.eclipse.linuxtools.tmf.core.tests @@ -122,7 +127,7 @@ org.eclipse.linuxtools.lttng org.eclipse.linuxtools.lttng.core - + org.eclipse.linuxtools.lttng.help org.eclipse.linuxtools.lttng.jni org.eclipse.linuxtools.lttng.ui -- 2.34.1