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

Unified Diff: runtime/vm/token_descriptor.h

Issue 1644793002: Replace intptr_t with TokenDescriptor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/token.cc ('k') | runtime/vm/token_descriptor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/token_descriptor.h
diff --git a/runtime/vm/token_descriptor.h b/runtime/vm/token_descriptor.h
new file mode 100644
index 0000000000000000000000000000000000000000..4968992964d299ef1b86e023b3c6be2c12e587d5
--- /dev/null
+++ b/runtime/vm/token_descriptor.h
@@ -0,0 +1,185 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef VM_TOKEN_DESCRIPTOR_H_
+#define VM_TOKEN_DESCRIPTOR_H_
+
+#include "platform/utils.h"
+#include "vm/allocation.h"
+
+namespace dart {
+
+// The token space is organized as follows:
+//
+// Sentinel values start at -1 and move towards negative infinity:
+// kNoSourcePos -> -1
+// ClassifyingTokenDescriptors 1 -> -1 - 1
+// ClassifyingTokenDescriptors N -> -1 - N
+//
+// Synthetically created AstNodes are given real source positions but encoded
+// as negative numbers from [kSmiMin32, -1 - N]. For example:
+//
+// A source position of 0 in a synthetic AstNode would be encoded as -2 - N.
+// A source position of 1 in a synthetic AstNode would be encoded as -3 - N.
+//
+// All other AstNodes are given real source positions encoded as positive
+// integers.
+//
+// This organization allows for ~1 billion token positions.
+//
+// NOTE: While token positions are passed around as an intptr_t they are encoded
hausner 2016/01/28 18:43:25 The intptr_t reference is not true anymore.
Cutch 2016/02/02 18:00:20 Done.
+// into the snapshot as an int32_t.
rmacnak 2016/01/28 18:21:50 encoded into the snapshot and stored on the heap
Cutch 2016/02/02 18:00:20 Acknowledged.
+
+#define SENTINEL_TOKEN_DESCRIPTORS(V) \
+ V(NoSource, -1) \
+ V(Box, -2) \
+ V(ParallelMove, -3) \
+ V(TempMove, -4) \
+ V(Constant, -5) \
+ V(PushArgument, -6) \
+ V(ControlFlow, -7) \
+ V(Context, -8) \
+ V(MethodExtractor, -9) \
+ V(Last, -10) // Always keep this at the end.
+
+// An immutable token position representing a debug safe source position,
+// a synthetic source position, or a classifying token position.
+class TokenDescriptor {
+ public:
+ TokenDescriptor()
+ : value_(kNoSource.value()) {
+ }
+
+ explicit TokenDescriptor(intptr_t value)
+ : value_(value) {
+ }
+
+ inline bool operator==(const TokenDescriptor& b) const {
+ return value() == b.value();
+ }
+
+ inline bool operator!=(const TokenDescriptor& b) const {
+ return !(*this == b);
+ }
+
+ inline bool operator<(const TokenDescriptor& b) const {
+ return value() < b.value();
+ }
+
+ inline bool operator>(const TokenDescriptor& b) const {
+ return b < *this;
+ }
+
+ inline bool operator<=(const TokenDescriptor& b) {
+ return !(*this > b);
+ }
+
+ inline bool operator>=(const TokenDescriptor& b) {
+ return !(*this < b);
+ }
+
+ static const intptr_t kMaxSentinelDescriptors = 64;
+
+#define DECLARE_VALUES(name, value) \
+ static const TokenDescriptor k##name;
+ SENTINEL_TOKEN_DESCRIPTORS(DECLARE_VALUES);
+#undef DECLARE_VALUES
+ static const TokenDescriptor kMinSource;
+ static const TokenDescriptor kMaxSource;
+
+ // Decode from a snapshot.
+ static TokenDescriptor SnapshotDecode(int32_t value);
+
+ // Encode for writing into a snapshot.
+ int32_t SnapshotEncode();
+
+ void Next() {
+ ASSERT(IsReal());
+ value_++;
+ }
+
+ // The raw value.
+ intptr_t value() const {
+ return value_;
+ }
+
+ // Token position constants.
+ static const intptr_t kNoSourcePos = -1;
+ static const intptr_t kMinSourcePos = 0;
+ static const intptr_t kMaxSourcePos = kSmiMax32 - kMaxSentinelDescriptors - 2;
+
+ // Is |this| a classifying sentinel source position?
rmacnak 2016/01/28 18:21:50 + Classifying positions are used by the profiler t
+ bool IsClassifying() const {
+ return (value_ >= kBox.value()) && (value_ <= kLast.value());
+ }
+
+ // Is |this| the no source position sentinel?
+ bool IsNoSource() const {
+ return *this == kNoSource;
+ }
+
+ // Is |this| a synthetic source position?
rmacnak 2016/01/28 18:21:50 + Synthetic source positions are used by the profi
+ bool IsSynthetic() const;
+
+ // Is |this| a real source position?
+ bool IsReal() const {
+ return value_ >= kMinSourcePos;
+ }
+
+ // Is |this| a source position?
+ bool IsSourcePosition() const {
+ return IsReal() || IsNoSource() || IsSynthetic();
+ }
+
+ // Is |this| a debug pause source position?
+ bool IsDebugPause() const {
+ // Sanity check some values here.
+ ASSERT(kNoSource.value() == kNoSourcePos);
+ ASSERT(kLast.value() < kNoSource.value());
+ ASSERT(kLast.value() > -kMaxSentinelDescriptors);
+ return IsReal();
+ }
+
+ // Encode |value| into a synthetic source position.
+ static TokenDescriptor ToSynthetic(TokenDescriptor tp) {
+ const intptr_t value = tp.value();
+ if (tp.IsClassifying() || tp.IsNoSource()) {
+ return tp;
+ }
+ if (tp.IsSynthetic()) {
+ return tp;
+ }
+ const TokenDescriptor synthetic_value =
+ TokenDescriptor((kLast.value() - 1) - value);
+ ASSERT(synthetic_value.IsSynthetic());
+ ASSERT(synthetic_value.value() < kLast.value());
+ return synthetic_value;
+ }
+
+ // Decode |synthetic_value| from a synthetic source position.
+ static TokenDescriptor FromSynthetic(TokenDescriptor tp) {
+ const intptr_t synthetic_value = tp.value();
+ if (tp.IsClassifying() || tp.IsNoSource()) {
+ return tp;
+ }
+ if (!tp.IsSynthetic()) {
+ return tp;
+ }
+ const TokenDescriptor value =
+ TokenDescriptor(-synthetic_value + (kLast.value() - 1));
+ ASSERT(!value.IsSynthetic());
+ return value;
+ }
+
+ const char* ToCString() const;
+
+ private:
+ int32_t value_;
+
+ DISALLOW_ALLOCATION();
+};
+
+} // namespace dart
+
+#endif // VM_TOKEN_DESCRIPTOR_H_
« no previous file with comments | « runtime/vm/token.cc ('k') | runtime/vm/token_descriptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698