1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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
;
15 import java
.util
.HashMap
;
16 import java
.util
.LinkedList
;
17 import java
.util
.List
;
20 * <b><u>StructDeclaration</u></b>
22 public class StructDeclaration
implements IDeclaration
{
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 private final HashMap
<String
, IDeclaration
> fields
= new HashMap
<String
, IDeclaration
>();
29 private final List
<String
> fieldsList
= new LinkedList
<String
>();
30 private long maxAlign
;
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 public StructDeclaration(long align
) {
37 this.maxAlign
= Math
.max(align
, 1);
40 // ------------------------------------------------------------------------
41 // Getters/Setters/Predicates
42 // ------------------------------------------------------------------------
44 public long getMaxAlign() {
48 public boolean hasField(String name
) {
49 return this.fields
.containsKey(name
);
52 public HashMap
<String
, IDeclaration
> getFields() {
56 public List
<String
> getFieldsList() {
57 return this.fieldsList
;
61 public long getAlignment() {
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 public StructDefinition
createDefinition(IDefinitionScope definitionScope
,
71 return new StructDefinition(this, definitionScope
, fieldName
);
74 public void addField(String name
, IDeclaration declaration
) {
75 this.fields
.put(name
, declaration
);
76 this.fieldsList
.add(name
);
77 maxAlign
= Math
.max(maxAlign
, declaration
.getAlignment());
85 public String
toString() {
86 /* Only used for debugging */
87 return "[declaration] struct[" + Integer
.toHexString(hashCode()) + ']'; //$NON-NLS-1$
91 * @see java.lang.Object#hashCode()
94 public int hashCode() {
97 result
= (prime
* result
)
98 + ((fieldsList
== null) ?
0 : fieldsList
.hashCode());
99 result
= (prime
* result
) + (int) (maxAlign ^
(maxAlign
>>> 32));
104 * @see java.lang.Object#equals(java.lang.Object)
107 public boolean equals(Object obj
) {
114 if (!(obj
instanceof StructDeclaration
)) {
117 StructDeclaration other
= (StructDeclaration
) obj
;
118 if (fieldsList
== null) {
119 if (other
.fieldsList
!= null) {
122 } else if (!fieldsList
.equals(other
.fieldsList
)) {
125 if (maxAlign
!= other
.maxAlign
) {