1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * 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
.integer
;
12 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.concatenateUnaryStrings
;
13 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.isUnaryInteger
;
14 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.isUnaryString
;
16 import org
.antlr
.runtime
.tree
.CommonTree
;
17 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ICommonTreeParser
;
18 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.MetadataStrings
;
19 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
20 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.UnaryIntegerParser
;
23 * Singed status, whether an integer is capable of accepting negative values or
26 * @author Matthew Khouzam
28 public final class SignedParser
implements ICommonTreeParser
{
32 public static final SignedParser INSTANCE
= new SignedParser();
34 private static final String INVALID_BOOLEAN_VALUE
= "Invalid boolean value "; //$NON-NLS-1$
36 private SignedParser() {
40 * Parses whether the parent is signed or not. Typical syntax would be
41 * "signed = true;" or "signed = false;"
44 * the AST node containing "signed = boolean;"
47 * @return @link {@link Boolean#TRUE} if signed, {@link Boolean#FALSE} if
49 * @throws ParseException
53 public Boolean
parse(CommonTree tree
, ICommonTreeParserParameter unused
) throws ParseException
{
55 CommonTree firstChild
= (CommonTree
) tree
.getChild(0);
57 if (isUnaryString(firstChild
)) {
58 String strval
= concatenateUnaryStrings(tree
.getChildren());
60 if (strval
.equals(MetadataStrings
.TRUE
)
61 || strval
.equals(MetadataStrings
.TRUE2
)) {
63 } else if (strval
.equals(MetadataStrings
.FALSE
)
64 || strval
.equals(MetadataStrings
.FALSE2
)) {
67 throw new ParseException(INVALID_BOOLEAN_VALUE
68 + firstChild
.getChild(0).getText());
70 } else if (isUnaryInteger(firstChild
)) {
71 /* Happens if the value is something like "1234.hello" */
72 if (tree
.getChildCount() > 1) {
73 throw new ParseException(INVALID_BOOLEAN_VALUE
);
76 long intval
= UnaryIntegerParser
.INSTANCE
.parse(firstChild
, null);
80 } else if (intval
== 0) {
83 throw new ParseException(INVALID_BOOLEAN_VALUE
84 + firstChild
.getChild(0).getText());
87 throw new ParseException(INVALID_BOOLEAN_VALUE
);