1 /*******************************************************************************
2 * Copyright (c) 2014 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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
14 import org
.eclipse
.jdt
.annotation
.NonNull
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.IDefinitionScope
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.LexicalScope
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
21 * Declaration base, it helps for basic functionality that is often called, so
22 * performance is often a high priority in this class
24 * @author Matthew Khouzam
27 public abstract class Declaration
implements IDeclaration
{
30 public LexicalScope
getPath(IDefinitionScope definitionScope
, @NonNull String fieldName
) {
31 if (definitionScope
!= null) {
32 final LexicalScope parentPath
= definitionScope
.getScopePath();
33 if (parentPath
!= null) {
34 LexicalScope myScope
= parentPath
.getChild(fieldName
);
35 if (myScope
== null) {
36 myScope
= new LexicalScope(parentPath
, fieldName
);
41 LexicalScope child
= LexicalScope
.ROOT
.getChild(fieldName
);
45 return new LexicalScope(LexicalScope
.ROOT
, fieldName
);
49 * Offset the buffer position wrt the current alignment.
52 * The bitbuffer that is being read
53 * @throws CTFReaderException
54 * Happens when there is an out of bounds exception
57 protected final void alignRead(BitBuffer input
) throws CTFReaderException
{
58 long mask
= getAlignment() - 1;
60 * The alignment is a power of 2
62 long pos
= input
.position();
63 if ((pos
& mask
) == 0) {
66 pos
= (pos
+ mask
) & ~mask
;