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 *******************************************************************************/
9 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
;
11 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.childTypeError
;
13 import org
.antlr
.runtime
.tree
.CommonTree
;
14 import org
.eclipse
.tracecompass
.ctf
.parser
.CTFParser
;
15 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ICommonTreeParser
;
16 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
19 * Type specifier list name parser (is it a bool? a string... )
21 * @author Matthew Khouzam
24 public final class TypeSpecifierListNameParser
implements ICommonTreeParser
{
29 public static final TypeSpecifierListNameParser INSTANCE
= new TypeSpecifierListNameParser();
31 private TypeSpecifierListNameParser() {
35 * Creates the string representation of a type specifier.
37 * @param typeSpecifier
38 * A TYPE_SPECIFIER node.
40 * @return param unused
41 * @throws ParseException
45 public StringBuilder
parse(CommonTree typeSpecifier
, ICommonTreeParserParameter param
) throws ParseException
{
46 StringBuilder sb
= new StringBuilder();
47 switch (typeSpecifier
.getType()) {
48 case CTFParser
.FLOATTOK
:
49 case CTFParser
.INTTOK
:
50 case CTFParser
.LONGTOK
:
51 case CTFParser
.SHORTTOK
:
52 case CTFParser
.SIGNEDTOK
:
53 case CTFParser
.UNSIGNEDTOK
:
54 case CTFParser
.CHARTOK
:
55 case CTFParser
.DOUBLETOK
:
56 case CTFParser
.VOIDTOK
:
57 case CTFParser
.BOOLTOK
:
58 case CTFParser
.COMPLEXTOK
:
59 case CTFParser
.IMAGINARYTOK
:
60 case CTFParser
.CONSTTOK
:
61 case CTFParser
.IDENTIFIER
:
62 parseSimple(typeSpecifier
, sb
);
64 case CTFParser
.STRUCT
: {
65 parseStruct(typeSpecifier
, sb
);
68 case CTFParser
.VARIANT
: {
69 parseVariant(typeSpecifier
, sb
);
72 case CTFParser
.ENUM
: {
73 parseEnum(typeSpecifier
, sb
);
76 case CTFParser
.FLOATING_POINT
:
77 case CTFParser
.INTEGER
:
78 case CTFParser
.STRING
:
79 throw new ParseException("CTF type found in createTypeSpecifierString"); //$NON-NLS-1$
81 throw childTypeError(typeSpecifier
);
87 private static void parseEnum(CommonTree typeSpecifier
, StringBuilder sb
) throws ParseException
{
88 CommonTree enumName
= (CommonTree
) typeSpecifier
.getFirstChildWithType(CTFParser
.ENUM_NAME
);
89 if (enumName
== null) {
90 throw new ParseException("nameless enum found in createTypeSpecifierString"); //$NON-NLS-1$
93 CommonTree enumNameIdentifier
= (CommonTree
) enumName
.getChild(0);
95 parseSimple(enumNameIdentifier
, sb
);
98 private static void parseVariant(CommonTree typeSpecifier
, StringBuilder sb
) throws ParseException
{
99 CommonTree variantName
= (CommonTree
) typeSpecifier
.getFirstChildWithType(CTFParser
.VARIANT_NAME
);
100 if (variantName
== null) {
101 throw new ParseException("nameless variant found in createTypeSpecifierString"); //$NON-NLS-1$
104 CommonTree variantNameIdentifier
= (CommonTree
) variantName
.getChild(0);
106 parseSimple(variantNameIdentifier
, sb
);
109 private static void parseSimple(CommonTree typeSpecifier
, StringBuilder sb
) {
110 sb
.append(typeSpecifier
.getText());
113 private static void parseStruct(CommonTree typeSpecifier
, StringBuilder sb
) throws ParseException
{
114 CommonTree structName
= (CommonTree
) typeSpecifier
.getFirstChildWithType(CTFParser
.STRUCT_NAME
);
115 if (structName
== null) {
116 throw new ParseException("nameless struct found in createTypeSpecifierString"); //$NON-NLS-1$
119 CommonTree structNameIdentifier
= (CommonTree
) structName
.getChild(0);
121 parseSimple(structNameIdentifier
, sb
);