Commit | Line | Data |
---|---|---|
866e5b51 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others |
866e5b51 FC |
3 | * |
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 | * | |
9 | * Contributors: Matthew Khouzam - Initial API and implementation | |
10 | * Contributors: Simon Marchi - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.ctf.core.event.types; | |
14 | ||
15 | /** | |
d37aaa7f FC |
16 | * A CTF array declaration |
17 | * | |
18 | * Arrays are fixed-length. Their length is declared in the type | |
19 | * declaration within the meta-data. They contain an array of "inner type" | |
20 | * elements, which can refer to any type not containing the type of the | |
21 | * array being declared (no circular dependency). The length is the number | |
22 | * of elements in an array. | |
23 | * | |
24 | * @version 1.0 | |
25 | * @author Matthew Khouzam | |
26 | * @author Simon Marchi | |
866e5b51 FC |
27 | */ |
28 | public class ArrayDeclaration implements IDeclaration { | |
29 | ||
30 | // ------------------------------------------------------------------------ | |
31 | // Attributes | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
34 | private final int length; | |
35 | private final IDeclaration elemType; | |
36 | ||
37 | // ------------------------------------------------------------------------ | |
38 | // Constructors | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
9ac2eb62 MK |
41 | /** |
42 | * Constructor | |
43 | * @param length how many elements in the array | |
44 | * @param elemType what type of element is in the array | |
45 | */ | |
866e5b51 FC |
46 | public ArrayDeclaration(int length, IDeclaration elemType) { |
47 | this.length = length; | |
48 | this.elemType = elemType; | |
49 | } | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Getters/Setters/Predicates | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
9ac2eb62 MK |
55 | /** |
56 | * | |
57 | * @return the type of element in the array | |
58 | */ | |
866e5b51 FC |
59 | public IDeclaration getElementType() { |
60 | return elemType; | |
61 | } | |
62 | ||
9ac2eb62 MK |
63 | /** |
64 | * | |
65 | * @return how many elements in the array | |
66 | */ | |
866e5b51 FC |
67 | public int getLength() { |
68 | return length; | |
69 | } | |
70 | ||
fd74e6c1 MK |
71 | @Override |
72 | public long getAlignment() { | |
0594c61c | 73 | return getElementType().getAlignment(); |
fd74e6c1 | 74 | } |
866e5b51 FC |
75 | // ------------------------------------------------------------------------ |
76 | // Operations | |
77 | // ------------------------------------------------------------------------ | |
78 | ||
79 | @Override | |
80 | public ArrayDefinition createDefinition(IDefinitionScope definitionScope, | |
81 | String fieldName) { | |
82 | return new ArrayDefinition(this, definitionScope, fieldName); | |
83 | } | |
84 | ||
85 | @Override | |
86 | public String toString() { | |
87 | /* Only used for debugging */ | |
88 | return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ | |
89 | } | |
90 | ||
91 | } |