-
Notifications
You must be signed in to change notification settings - Fork 13
/
Declaration.java
90 lines (82 loc) · 2.85 KB
/
Declaration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
* Copyright (c) 2014 Ericsson
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Matthew Khouzam - Initial API and implementation
*******************************************************************************/
package org.eclipse.tracecompass.ctf.core.event.types;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.ctf.core.CTFException;
import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope;
/**
* Declaration base, it helps for basic functionality that is often called, so
* performance is often a high priority in this class
*
* @author Matthew Khouzam
*/
public abstract class Declaration implements IDeclaration {
/**
* Public field to store the role of a declaration. This is meant to
* accomodate the CTF2 spec.
*/
private @Nullable String fRole;
/**
* @since 1.0
*/
@Override
public ILexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName) {
if (definitionScope != null) {
final ILexicalScope parentPath = definitionScope.getScopePath();
if (parentPath != null) {
ILexicalScope myScope = parentPath.getChild(fieldName);
if (myScope == null) {
myScope = new LexicalScope(parentPath, fieldName);
}
return myScope;
}
}
ILexicalScope child = ILexicalScope.ROOT.getChild(fieldName);
if (child != null) {
return child;
}
return new LexicalScope(ILexicalScope.ROOT, fieldName);
}
/**
* Offset the buffer position wrt the current alignment.
*
* @param input
* The bitbuffer that is being read
* @throws CTFException
* Happens when there is an out of bounds exception
*/
protected final void alignRead(BitBuffer input) throws CTFException {
long mask = getAlignment() - 1;
/*
* The alignment is a power of 2
*/
long pos = input.position();
if ((pos & mask) == 0) {
return;
}
pos = (pos + mask) & ~mask;
input.position(pos);
}
@Override
public String getRole() {
return fRole;
}
@Override
public void setRole(String role) {
fRole = role;
}
}