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
;
12 import static org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
.TsdlUtils
.isUnaryInteger
;
14 import org
.antlr
.runtime
.tree
.CommonTree
;
15 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ICommonTreeParser
;
16 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
19 * Type size, in bits, for integers and floats is that returned by sizeof() in C
20 * multiplied by CHAR_BIT. We require the size of char and unsigned char types
21 * (CHAR_BIT) to be fixed to 8 bits for cross-endianness compatibility.
23 * TSDL metadata representation:
26 * size = /* value is in bits * /
29 * @author Matthew Khouzam
30 * @author Efficios - javadoc preamble.
32 public final class SizeParser
implements ICommonTreeParser
{
33 private static final String INVALID_VALUE_FOR_SIZE
= "Invalid value for size"; //$NON-NLS-1$
38 public static final SizeParser INSTANCE
= new SizeParser();
40 private SizeParser() {
44 * Gets the value of a "size" integer attribute.
50 * @return The "size" value. Can be 4 bytes.
51 * @throws ParseException
52 * if the size is not an int or a negative
55 public Long
parse(CommonTree rightNode
, ICommonTreeParserParameter param
) throws ParseException
{
56 CommonTree firstChild
= (CommonTree
) rightNode
.getChild(0);
57 if (isUnaryInteger(firstChild
)) {
58 if (rightNode
.getChildCount() > 1) {
59 throw new ParseException(INVALID_VALUE_FOR_SIZE
);
61 long size
= UnaryIntegerParser
.INSTANCE
.parse(firstChild
, null);
63 throw new ParseException(INVALID_VALUE_FOR_SIZE
);
67 throw new ParseException(INVALID_VALUE_FOR_SIZE
);