1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.event
;
12 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.childTypeError
;
14 import java
.util
.List
;
16 import org
.antlr
.runtime
.tree
.CommonTree
;
17 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
18 import org
.eclipse
.tracecompass
.ctf
.core
.event
.metadata
.DeclarationScope
;
19 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
20 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.ICTFStream
;
21 import org
.eclipse
.tracecompass
.ctf
.parser
.CTFParser
;
22 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.EventDeclaration
;
23 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.AbstractScopedCommonTreeParser
;
24 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.MetadataStrings
;
25 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
26 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TypeAliasParser
;
27 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TypedefParser
;
28 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.trace
.CTFStream
;
33 * An event stream can be divided into contiguous event packets of variable
34 * size. An event packet can contain a certain amount of padding at the end. The
35 * stream header is repeated at the beginning of each event packet. The
36 * rationale for the event stream design choices is explained in Stream header
39 * The event stream header will therefore be referred to as the event packet
40 * header throughout the rest of this document.
42 * @author Matthew Khouzam - Initial API and implementation
43 * @author Efficios - Documentation
46 public class EventParser
extends AbstractScopedCommonTreeParser
{
49 * Parameter object with trace and scope
51 * @author Matthew Khouzam
55 public static final class Param
implements ICommonTreeParserParameter
{
57 private final DeclarationScope fCurrentScope
;
58 private final CTFTrace fTrace
;
68 public Param(CTFTrace trace
, DeclarationScope currentScope
) {
70 fCurrentScope
= currentScope
;
78 public static final EventParser INSTANCE
= new EventParser();
80 private EventParser() {
84 * Parses an enum declaration and returns the corresponding declaration.
89 * the parameter object
91 * @return The corresponding enum declaration.
92 * @throws ParseException
93 * event stream was badly defined
96 public EventDeclaration
parse(CommonTree eventNode
, ICommonTreeParserParameter param
) throws ParseException
{
97 if (!(param
instanceof Param
)) {
98 throw new IllegalArgumentException("Param must be a " + Param
.class.getCanonicalName()); //$NON-NLS-1$
100 Param parameter
= (Param
) param
;
101 CTFTrace trace
= ((Param
) param
).fTrace
;
102 List
<CommonTree
> children
= eventNode
.getChildren();
103 if (children
== null) {
104 throw new ParseException("Empty event block"); //$NON-NLS-1$
107 EventDeclaration event
= new EventDeclaration();
109 DeclarationScope scope
= new DeclarationScope(parameter
.fCurrentScope
, MetadataStrings
.EVENT
);
111 for (CommonTree child
: children
) {
112 switch (child
.getType()) {
113 case CTFParser
.TYPEALIAS
:
114 TypeAliasParser
.INSTANCE
.parse(child
, new TypeAliasParser
.Param(trace
, scope
));
116 case CTFParser
.TYPEDEF
:
117 TypedefParser
.INSTANCE
.parse(child
, new TypedefParser
.Param(trace
, scope
));
119 case CTFParser
.CTF_EXPRESSION_TYPE
:
120 case CTFParser
.CTF_EXPRESSION_VAL
:
121 EventDeclarationParser
.INSTANCE
.parse(child
, new EventDeclarationParser
.Param(trace
, event
, scope
));
124 throw childTypeError(child
);
128 if (!event
.nameIsSet()) {
129 throw new ParseException("Event name not set"); //$NON-NLS-1$
133 * If the event did not specify a stream, then the trace must be single
136 if (!event
.streamIsSet()) {
137 if (trace
.nbStreams() > 1) {
138 throw new ParseException("Event without stream_id with more than one stream"); //$NON-NLS-1$
142 * If the event did not specify a stream, the only existing stream
143 * must not have an id. Note: That behavior could be changed, it
144 * could be possible to just get the only existing stream, whatever
147 ICTFStream iStream
= trace
.getStream(null);
148 if (iStream
instanceof CTFStream
) {
149 CTFStream ctfStream
= (CTFStream
) iStream
;
150 event
.setStream(ctfStream
);
152 throw new ParseException("Event without stream_id, but there is no stream without id"); //$NON-NLS-1$
157 * Add the event to the stream.
159 event
.getStream().addEvent(event
);