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 | ||
a4fa4e36 MK |
15 | import org.eclipse.jdt.annotation.NonNull; |
16 | import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; | |
17 | import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; | |
866e5b51 FC |
18 | |
19 | /** | |
a511da0d | 20 | * A CTF definition |
d37aaa7f | 21 | * |
abec0e9c MK |
22 | * A definition is like an object of a declaration class. It fills the |
23 | * declaration with values. <br> | |
9ac2eb62 MK |
24 | * An example: <br> |
25 | * int i = 0; <br> | |
26 | * <b>int</b> is the declaration.<br> | |
27 | * <b>i</b> is the definition.<br> | |
28 | * <b>0</b> is the value assigned to the definition, not the declaration.<br> | |
29 | * | |
d37aaa7f FC |
30 | * @version 1.0 |
31 | * @author Matthew Khouzam | |
32 | * @author Simon Marchi | |
866e5b51 FC |
33 | */ |
34 | public abstract class Definition { | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
a4fa4e36 | 40 | private final String fFieldName; |
866e5b51 | 41 | |
07002e0a | 42 | /** The complete path of this field */ |
a4fa4e36 | 43 | private final LexicalScope fPath; |
866e5b51 | 44 | |
a4fa4e36 MK |
45 | private final IDefinitionScope fDefinitionScope; |
46 | ||
47 | @NonNull | |
48 | private final IDeclaration fDeclaration; | |
866e5b51 FC |
49 | |
50 | // ------------------------------------------------------------------------ | |
51 | // Constructors | |
52 | // ------------------------------------------------------------------------ | |
53 | ||
9ac2eb62 MK |
54 | /** |
55 | * Constructor | |
56 | * | |
a4fa4e36 MK |
57 | * @param declaration |
58 | * the event declaration | |
59 | * | |
9ac2eb62 MK |
60 | * @param definitionScope |
61 | * the definition is in a scope, (normally a struct) what is it? | |
62 | * @param fieldName | |
63 | * the name of the definition. (it is a field in the parent | |
64 | * scope) | |
a4fa4e36 | 65 | * @since 3.0 |
9ac2eb62 | 66 | */ |
a4fa4e36 MK |
67 | public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) { |
68 | fDeclaration = declaration; | |
69 | fDefinitionScope = definitionScope; | |
70 | fFieldName = fieldName; | |
71 | fPath = fDeclaration.getPath(definitionScope, fieldName); | |
0594c61c | 72 | } |
866e5b51 | 73 | |
0594c61c AM |
74 | // ------------------------------------------------------------------------ |
75 | // Getters | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
78 | /** | |
79 | * Get the field name in its container. | |
80 | * | |
81 | * @return The field name | |
82 | * @since 2.0 | |
83 | */ | |
84 | protected String getFieldName() { | |
a4fa4e36 | 85 | return fFieldName; |
0594c61c AM |
86 | } |
87 | ||
88 | /** | |
89 | * Get the complete path of this field. | |
90 | * | |
91 | * @return The path | |
a4fa4e36 | 92 | * @since 3.0 |
0594c61c | 93 | */ |
a4fa4e36 MK |
94 | public LexicalScope getScopePath() { |
95 | return fPath; | |
0594c61c AM |
96 | } |
97 | ||
98 | /** | |
99 | * Get the definition scope in which this definition is found. | |
100 | * | |
101 | * The complete path of a definition is thus the path of the definition | |
102 | * scope DOT the name of the definition (name of the field in its container) | |
103 | * | |
104 | * @return The definition scope | |
a4fa4e36 | 105 | * @since 3.0 |
0594c61c AM |
106 | */ |
107 | protected IDefinitionScope getDefinitionScope() { | |
a4fa4e36 | 108 | return fDefinitionScope; |
866e5b51 FC |
109 | } |
110 | ||
111 | // ------------------------------------------------------------------------ | |
112 | // Operations | |
113 | // ------------------------------------------------------------------------ | |
114 | ||
9ac2eb62 MK |
115 | /** |
116 | * | |
117 | * @return gets the declaration of a datatype | |
118 | * | |
119 | */ | |
a4fa4e36 MK |
120 | @NonNull |
121 | public IDeclaration getDeclaration() { | |
122 | return fDeclaration; | |
d6205f97 MK |
123 | } |
124 | ||
866e5b51 FC |
125 | @Override |
126 | public String toString() { | |
a4fa4e36 | 127 | return fPath.toString() + '[' + Integer.toHexString(hashCode()) + ']'; |
866e5b51 FC |
128 | } |
129 | } |