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
.stream
;
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
.parser
.CTFParser
;
21 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.AbstractScopedCommonTreeParser
;
22 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.MetadataStrings
;
23 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
24 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TypeAliasParser
;
25 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TypedefParser
;
26 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.trace
.CTFStream
;
29 * A stream is a collection of packets with events in them. It will contain data
32 * @author Matthew Khouzam
35 public class StreamParser
extends AbstractScopedCommonTreeParser
{
38 * Parameter Object with a trace and scope
40 * @author Matthew Khouzam
44 public static final class Param
implements ICommonTreeParserParameter
{
46 private final DeclarationScope fCurrentScope
;
47 private final CTFTrace fTrace
;
57 public Param(CTFTrace trace
, DeclarationScope currentScope
) {
59 fCurrentScope
= currentScope
;
67 public static final StreamParser INSTANCE
= new StreamParser();
69 private StreamParser() {
73 * Parses an stream declaration and returns a stream type
78 * the parameter object
80 * @return The corresponding enum declaration.
81 * @throws ParseException
82 * badly defined stream
85 public CTFStream
parse(CommonTree streamNode
, ICommonTreeParserParameter param
) throws ParseException
{
86 if (!(param
instanceof Param
)) {
87 throw new IllegalArgumentException("Param must be a " + Param
.class.getCanonicalName()); //$NON-NLS-1$
89 Param parameter
= (Param
) param
;
90 CTFTrace trace
= ((Param
) param
).fTrace
;
91 CTFStream stream
= new CTFStream(trace
);
93 List
<CommonTree
> children
= streamNode
.getChildren();
94 if (children
== null) {
95 throw new ParseException("Empty stream block"); //$NON-NLS-1$
98 DeclarationScope scope
= new DeclarationScope(parameter
.fCurrentScope
, MetadataStrings
.STREAM
);
100 for (CommonTree child
: children
) {
101 switch (child
.getType()) {
102 case CTFParser
.TYPEALIAS
:
103 TypeAliasParser
.INSTANCE
.parse(child
, new TypeAliasParser
.Param(trace
, scope
));
105 case CTFParser
.TYPEDEF
:
106 TypedefParser
.INSTANCE
.parse(child
, new TypedefParser
.Param(trace
, scope
));
108 case CTFParser
.CTF_EXPRESSION_TYPE
:
109 case CTFParser
.CTF_EXPRESSION_VAL
:
110 StreamDeclarationParser
.INSTANCE
.parse(child
, new StreamDeclarationParser
.Param(trace
, stream
, scope
));
113 throw childTypeError(child
);
117 if (stream
.isIdSet() &&
118 (!trace
.packetHeaderIsSet() || !trace
.getPacketHeader().hasField(MetadataStrings
.STREAM_ID
))) {
119 throw new ParseException("Stream has an ID, but there is no stream_id field in packet header."); //$NON-NLS-1$
122 trace
.addStream(stream
);