Commit | Line | Data |
---|---|---|
a4fa4e36 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
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 | *******************************************************************************/ | |
11 | ||
12 | package org.eclipse.linuxtools.ctf.core.event.types; | |
13 | ||
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; | |
19 | ||
20 | /** | |
21 | * Declaration base, it helps for basic functionality that is often called, so | |
22 | * performance is often a high priority in this class | |
23 | * | |
24 | * @author Matthew Khouzam | |
25 | * @since 3.0 | |
26 | */ | |
27 | public abstract class Declaration implements IDeclaration { | |
28 | ||
29 | @Override | |
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); | |
37 | } | |
38 | return myScope; | |
39 | } | |
40 | } | |
41 | LexicalScope child = LexicalScope.ROOT.getChild(fieldName); | |
42 | if (child != null) { | |
43 | return child; | |
44 | } | |
45 | return new LexicalScope(LexicalScope.ROOT, fieldName); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Offset the buffer position wrt the current alignment. | |
50 | * | |
51 | * @param input | |
52 | * The bitbuffer that is being read | |
53 | * @throws CTFReaderException | |
54 | * Happens when there is an out of bounds exception | |
55 | * @since 3.0 | |
56 | */ | |
57 | protected final void alignRead(BitBuffer input) throws CTFReaderException { | |
58 | long mask = getAlignment() - 1; | |
59 | /* | |
60 | * The alignment is a power of 2 | |
61 | */ | |
62 | long pos = input.position(); | |
63 | if ((pos & mask) == 0) { | |
64 | return; | |
65 | } | |
66 | pos = (pos + mask) & ~mask; | |
67 | input.position(pos); | |
68 | } | |
69 | } |