Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: runtime/vm/token_position.h

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/token.cc ('k') | runtime/vm/token_position.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_VM_TOKEN_POSITION_H_ 5 #ifndef RUNTIME_VM_TOKEN_POSITION_H_
6 #define RUNTIME_VM_TOKEN_POSITION_H_ 6 #define RUNTIME_VM_TOKEN_POSITION_H_
7 7
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 10
(...skipping 11 matching lines...) Expand all
22 // 22 //
23 // A source position of 0 in a synthetic AstNode would be encoded as -2 - N. 23 // A source position of 0 in a synthetic AstNode would be encoded as -2 - N.
24 // A source position of 1 in a synthetic AstNode would be encoded as -3 - N. 24 // A source position of 1 in a synthetic AstNode would be encoded as -3 - N.
25 // 25 //
26 // All other AstNodes are given real source positions encoded as positive 26 // All other AstNodes are given real source positions encoded as positive
27 // integers. 27 // integers.
28 // 28 //
29 // This organization allows for ~1 billion token positions. 29 // This organization allows for ~1 billion token positions.
30 30
31 #define SENTINEL_TOKEN_DESCRIPTORS(V) \ 31 #define SENTINEL_TOKEN_DESCRIPTORS(V) \
32 V(NoSource, -1) \ 32 V(NoSource, -1) \
33 V(Box, -2) \ 33 V(Box, -2) \
34 V(ParallelMove, -3) \ 34 V(ParallelMove, -3) \
35 V(TempMove, -4) \ 35 V(TempMove, -4) \
36 V(Constant, -5) \ 36 V(Constant, -5) \
37 V(PushArgument, -6) \ 37 V(PushArgument, -6) \
38 V(ControlFlow, -7) \ 38 V(ControlFlow, -7) \
39 V(Context, -8) \ 39 V(Context, -8) \
40 V(MethodExtractor, -9) \ 40 V(MethodExtractor, -9) \
41 V(DeferredSlowPath, -10) \ 41 V(DeferredSlowPath, -10) \
42 V(DeferredDeoptInfo, -11) \ 42 V(DeferredDeoptInfo, -11) \
43 V(DartCodePrologue, -12) \ 43 V(DartCodePrologue, -12) \
44 V(DartCodeEpilogue, -13) \ 44 V(DartCodeEpilogue, -13) \
45 V(Last, -14) // Always keep this at the end. 45 V(Last, -14) // Always keep this at the end.
46 46
47 // A token position representing a debug safe source (real) position, 47 // A token position representing a debug safe source (real) position,
48 // non-debug safe source (synthetic) positions, or a classifying value used 48 // non-debug safe source (synthetic) positions, or a classifying value used
49 // by the profiler. 49 // by the profiler.
50 class TokenPosition { 50 class TokenPosition {
51 public: 51 public:
52 TokenPosition() 52 TokenPosition() : value_(kNoSource.value()) {}
53 : value_(kNoSource.value()) {
54 }
55 53
56 explicit TokenPosition(intptr_t value) 54 explicit TokenPosition(intptr_t value) : value_(value) {}
57 : value_(value) {
58 }
59 55
60 bool operator==(const TokenPosition& b) const { 56 bool operator==(const TokenPosition& b) const { return value() == b.value(); }
61 return value() == b.value();
62 }
63 57
64 bool operator!=(const TokenPosition& b) const { 58 bool operator!=(const TokenPosition& b) const { return !(*this == b); }
65 return !(*this == b);
66 }
67 59
68 bool operator<(const TokenPosition& b) const { 60 bool operator<(const TokenPosition& b) const {
69 // TODO(johnmccutchan): Assert that this is a source position. 61 // TODO(johnmccutchan): Assert that this is a source position.
70 return value() < b.value(); 62 return value() < b.value();
71 } 63 }
72 64
73 bool operator>(const TokenPosition& b) const { 65 bool operator>(const TokenPosition& b) const {
74 // TODO(johnmccutchan): Assert that this is a source position. 66 // TODO(johnmccutchan): Assert that this is a source position.
75 return b < *this; 67 return b < *this;
76 } 68 }
77 69
78 bool operator<=(const TokenPosition& b) { 70 bool operator<=(const TokenPosition& b) {
79 // TODO(johnmccutchan): Assert that this is a source position. 71 // TODO(johnmccutchan): Assert that this is a source position.
80 return !(*this > b); 72 return !(*this > b);
81 } 73 }
82 74
83 bool operator>=(const TokenPosition& b) { 75 bool operator>=(const TokenPosition& b) {
84 // TODO(johnmccutchan): Assert that this is a source position. 76 // TODO(johnmccutchan): Assert that this is a source position.
85 return !(*this < b); 77 return !(*this < b);
86 } 78 }
87 79
88 static const intptr_t kMaxSentinelDescriptors = 64; 80 static const intptr_t kMaxSentinelDescriptors = 64;
89 81
90 #define DECLARE_VALUES(name, value) \ 82 #define DECLARE_VALUES(name, value) static const TokenPosition k##name;
91 static const TokenPosition k##name;
92 SENTINEL_TOKEN_DESCRIPTORS(DECLARE_VALUES); 83 SENTINEL_TOKEN_DESCRIPTORS(DECLARE_VALUES);
93 #undef DECLARE_VALUES 84 #undef DECLARE_VALUES
94 static const TokenPosition kMinSource; 85 static const TokenPosition kMinSource;
95 static const TokenPosition kMaxSource; 86 static const TokenPosition kMaxSource;
96 87
97 // Decode from a snapshot. 88 // Decode from a snapshot.
98 static TokenPosition SnapshotDecode(int32_t value); 89 static TokenPosition SnapshotDecode(int32_t value);
99 90
100 // Encode for writing into a snapshot. 91 // Encode for writing into a snapshot.
101 int32_t SnapshotEncode(); 92 int32_t SnapshotEncode();
102 93
103 // Increment the token position. 94 // Increment the token position.
104 TokenPosition Next() { 95 TokenPosition Next() {
105 ASSERT(IsReal()); 96 ASSERT(IsReal());
106 value_++; 97 value_++;
107 return *this; 98 return *this;
108 } 99 }
109 100
110 // The raw value. 101 // The raw value.
111 // TODO(johnmccutchan): Make this private. 102 // TODO(johnmccutchan): Make this private.
112 intptr_t value() const { 103 intptr_t value() const { return value_; }
113 return value_;
114 }
115 104
116 // Return the source position. 105 // Return the source position.
117 intptr_t Pos() const { 106 intptr_t Pos() const {
118 if (IsSynthetic()) { 107 if (IsSynthetic()) {
119 return FromSynthetic().Pos(); 108 return FromSynthetic().Pos();
120 } 109 }
121 return value_; 110 return value_;
122 } 111 }
123 112
124 // Token position constants. 113 // Token position constants.
125 static const intptr_t kNoSourcePos = -1; 114 static const intptr_t kNoSourcePos = -1;
126 static const intptr_t kMinSourcePos = 0; 115 static const intptr_t kMinSourcePos = 0;
127 static const intptr_t kMaxSourcePos = kSmiMax32 - kMaxSentinelDescriptors - 2; 116 static const intptr_t kMaxSourcePos = kSmiMax32 - kMaxSentinelDescriptors - 2;
128 117
129 // Is |this| a classifying sentinel source position? 118 // Is |this| a classifying sentinel source position?
130 // Classifying positions are used by the profiler to group instructions whose 119 // Classifying positions are used by the profiler to group instructions whose
131 // cost isn't naturally attributable to a source location. 120 // cost isn't naturally attributable to a source location.
132 bool IsClassifying() const { 121 bool IsClassifying() const {
133 return (value_ >= kBox.value()) && (value_ <= kLast.value()); 122 return (value_ >= kBox.value()) && (value_ <= kLast.value());
134 } 123 }
135 124
136 // Is |this| the no source position sentinel? 125 // Is |this| the no source position sentinel?
137 bool IsNoSource() const { 126 bool IsNoSource() const { return *this == kNoSource; }
138 return *this == kNoSource;
139 }
140 127
141 // Is |this| a synthetic source position? 128 // Is |this| a synthetic source position?
142 // Synthetic source positions are used by the profiler to attribute ticks to a 129 // Synthetic source positions are used by the profiler to attribute ticks to a
143 // pieces of source, but ignored by the debugger as potential breakpoints. 130 // pieces of source, but ignored by the debugger as potential breakpoints.
144 bool IsSynthetic() const; 131 bool IsSynthetic() const;
145 132
146 // Is |this| a real source position? 133 // Is |this| a real source position?
147 bool IsReal() const { 134 bool IsReal() const { return value_ >= kMinSourcePos; }
148 return value_ >= kMinSourcePos;
149 }
150 135
151 // Is |this| a source position? 136 // Is |this| a source position?
152 bool IsSourcePosition() const { 137 bool IsSourcePosition() const {
153 return IsReal() || IsNoSource() || IsSynthetic(); 138 return IsReal() || IsNoSource() || IsSynthetic();
154 } 139 }
155 140
156 // Is |this| a debug pause source position? 141 // Is |this| a debug pause source position?
157 bool IsDebugPause() const { 142 bool IsDebugPause() const {
158 // Sanity check some values here. 143 // Sanity check some values here.
159 ASSERT(kNoSource.value() == kNoSourcePos); 144 ASSERT(kNoSource.value() == kNoSourcePos);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 184
200 private: 185 private:
201 int32_t value_; 186 int32_t value_;
202 187
203 DISALLOW_ALLOCATION(); 188 DISALLOW_ALLOCATION();
204 }; 189 };
205 190
206 } // namespace dart 191 } // namespace dart
207 192
208 #endif // RUNTIME_VM_TOKEN_POSITION_H_ 193 #endif // RUNTIME_VM_TOKEN_POSITION_H_
OLDNEW
« no previous file with comments | « runtime/vm/token.cc ('k') | runtime/vm/token_position.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698