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 | 33 | */ |
cc98c947 | 34 | public abstract class Definition implements IDefinition { |
866e5b51 FC |
35 | |
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
a4fa4e36 | 40 | private final String fFieldName; |
866e5b51 | 41 | |
07002e0a | 42 | /** The complete path of this field */ |
cc98c947 | 43 | private final @NonNull 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 | |
9ac2eb62 MK |
59 | * @param definitionScope |
60 | * the definition is in a scope, (normally a struct) what is it? | |
61 | * @param fieldName | |
62 | * the name of the definition. (it is a field in the parent | |
63 | * scope) | |
a4fa4e36 | 64 | * @since 3.0 |
9ac2eb62 | 65 | */ |
a4fa4e36 | 66 | public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) { |
70f60307 MK |
67 | this(declaration, definitionScope, fieldName, declaration.getPath(definitionScope, fieldName)); |
68 | } | |
69 | ||
70 | /** | |
009883d7 MK |
71 | * Constructor This one takes the scope and thus speeds up definition |
72 | * creation | |
70f60307 MK |
73 | * |
74 | * | |
75 | * @param declaration | |
76 | * the event declaration | |
77 | * | |
78 | * @param definitionScope | |
79 | * the definition is in a scope, (normally a struct) what is it? | |
80 | * | |
81 | * @param fieldName | |
82 | * the name of the defintions. it is a field in the parent scope. | |
83 | * | |
84 | * @param scope | |
85 | * the scope | |
86 | * @since 3.1 | |
87 | */ | |
009883d7 | 88 | public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull LexicalScope scope) { |
a4fa4e36 MK |
89 | fDeclaration = declaration; |
90 | fDefinitionScope = definitionScope; | |
91 | fFieldName = fieldName; | |
70f60307 | 92 | fPath = scope; |
0594c61c | 93 | } |
866e5b51 | 94 | |
0594c61c AM |
95 | // ------------------------------------------------------------------------ |
96 | // Getters | |
97 | // ------------------------------------------------------------------------ | |
98 | ||
99 | /** | |
100 | * Get the field name in its container. | |
101 | * | |
102 | * @return The field name | |
103 | * @since 2.0 | |
104 | */ | |
105 | protected String getFieldName() { | |
a4fa4e36 | 106 | return fFieldName; |
0594c61c AM |
107 | } |
108 | ||
cc98c947 | 109 | @Override |
a4fa4e36 MK |
110 | public LexicalScope getScopePath() { |
111 | return fPath; | |
0594c61c AM |
112 | } |
113 | ||
114 | /** | |
115 | * Get the definition scope in which this definition is found. | |
116 | * | |
117 | * The complete path of a definition is thus the path of the definition | |
118 | * scope DOT the name of the definition (name of the field in its container) | |
119 | * | |
120 | * @return The definition scope | |
a4fa4e36 | 121 | * @since 3.0 |
0594c61c AM |
122 | */ |
123 | protected IDefinitionScope getDefinitionScope() { | |
a4fa4e36 | 124 | return fDefinitionScope; |
866e5b51 FC |
125 | } |
126 | ||
127 | // ------------------------------------------------------------------------ | |
128 | // Operations | |
129 | // ------------------------------------------------------------------------ | |
130 | ||
cc98c947 | 131 | @Override |
a4fa4e36 MK |
132 | public IDeclaration getDeclaration() { |
133 | return fDeclaration; | |
d6205f97 MK |
134 | } |
135 | ||
866e5b51 FC |
136 | @Override |
137 | public String toString() { | |
a4fa4e36 | 138 | return fPath.toString() + '[' + Integer.toHexString(hashCode()) + ']'; |
866e5b51 FC |
139 | } |
140 | } |