1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
16 * A CTF array declaration
18 * Arrays are fixed-length. Their length is declared in the type declaration
19 * within the meta-data. They contain an array of "inner type" elements, which
20 * can refer to any type not containing the type of the array being declared (no
21 * circular dependency). The length is the number of elements in an array.
24 * @author Matthew Khouzam
25 * @author Simon Marchi
27 public class ArrayDeclaration
implements IDeclaration
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private final int length
;
34 private final IDeclaration elemType
;
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
44 * how many elements in the array
46 * what type of element is in the array
48 public ArrayDeclaration(int length
, IDeclaration elemType
) {
50 this.elemType
= elemType
;
53 // ------------------------------------------------------------------------
54 // Getters/Setters/Predicates
55 // ------------------------------------------------------------------------
59 * @return the type of element in the array
61 public IDeclaration
getElementType() {
67 * @return how many elements in the array
69 public int getLength() {
74 * Sometimes, strings are encoded as an array of 1-byte integers (each one
75 * being an UTF-8 byte).
77 * @return true if this array is in fact an UTF-8 string. false if it's a
78 * "normal" array of generic Definition's.
81 public boolean isString() {
82 if (elemType
instanceof IntegerDeclaration
) {
84 * If the first byte is a "character", we'll consider the whole
85 * array a character string.
87 IntegerDeclaration elemInt
= (IntegerDeclaration
) elemType
;
88 if (elemInt
.isCharacter()) {
96 public long getAlignment() {
97 return getElementType().getAlignment();
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
105 public ArrayDefinition
createDefinition(IDefinitionScope definitionScope
,
107 return new ArrayDefinition(this, definitionScope
, fieldName
);
111 public String
toString() {
112 /* Only used for debugging */
113 return "[declaration] array[" + Integer
.toHexString(hashCode()) + ']'; //$NON-NLS-1$