Skip to content

Commit f7edb90

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Add ManifestNodeIntegerLiteral.
Also adds read/writeInt64() helpers. No tests, because we don't have enough functionality, e.g. writing constant variable initializers to test it with. Change-Id: I677f988e8580cf6f290fd7c866ee8ef91821b110 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419925 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent e0dc78b commit f7edb90

File tree

3 files changed

+94
-11
lines changed

3 files changed

+94
-11
lines changed

pkg/analyzer/lib/src/fine/manifest_ast.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ sealed class ManifestNode {
2929
switch (kind) {
3030
case _ManifestNodeKind.annotation:
3131
return ManifestNodeAnnotation.read(reader);
32+
case _ManifestNodeKind.integerLiteral:
33+
return ManifestNodeIntegerLiteral.read(reader);
3234
case _ManifestNodeKind.simpleIdentifier:
3335
return ManifestNodeSimpleIdentifier.read(reader);
3436
}
@@ -81,6 +83,37 @@ class ManifestNodeAnnotation extends ManifestNode {
8183
}
8284
}
8385

86+
class ManifestNodeIntegerLiteral extends ManifestNode {
87+
final int? value;
88+
89+
ManifestNodeIntegerLiteral({
90+
required this.value,
91+
});
92+
93+
factory ManifestNodeIntegerLiteral.encode(IntegerLiteral node) {
94+
return ManifestNodeIntegerLiteral(
95+
value: node.value,
96+
);
97+
}
98+
99+
factory ManifestNodeIntegerLiteral.read(SummaryDataReader reader) {
100+
return ManifestNodeIntegerLiteral(
101+
value: reader.readOptionalInt64(),
102+
);
103+
}
104+
105+
@override
106+
bool match(MatchContext context, AstNode node) {
107+
return node is IntegerLiteral && node.value == value;
108+
}
109+
110+
@override
111+
void write(BufferedSink sink) {
112+
sink.writeEnum(_ManifestNodeKind.integerLiteral);
113+
sink.writeOptionalInt64(value);
114+
}
115+
}
116+
84117
class ManifestNodeSimpleIdentifier extends ManifestNode {
85118
final String name;
86119
final ManifestElement? element;
@@ -147,5 +180,6 @@ class ManifestNodeSimpleIdentifier extends ManifestNode {
147180

148181
enum _ManifestNodeKind {
149182
annotation,
183+
integerLiteral,
150184
simpleIdentifier,
151185
}

pkg/analyzer/lib/src/summary2/data_reader.dart

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ class SummaryDataReader {
1414

1515
late final _StringTable _stringTable;
1616

17+
final Int64List _int64Buffer = Int64List(1);
18+
late final Uint8List _int64BufferUint8 = _int64Buffer.buffer.asUint8List();
19+
1720
final Float64List _doubleBuffer = Float64List(1);
18-
Uint8List? _doubleBufferUint8;
21+
late final Uint8List _doubleBufferUint8 = _doubleBuffer.buffer.asUint8List();
1922

2023
SummaryDataReader(this.bytes);
2124

@@ -43,16 +46,14 @@ class SummaryDataReader {
4346
}
4447

4548
double readDouble() {
46-
var doubleBufferUint8 =
47-
_doubleBufferUint8 ??= _doubleBuffer.buffer.asUint8List();
48-
doubleBufferUint8[0] = readByte();
49-
doubleBufferUint8[1] = readByte();
50-
doubleBufferUint8[2] = readByte();
51-
doubleBufferUint8[3] = readByte();
52-
doubleBufferUint8[4] = readByte();
53-
doubleBufferUint8[5] = readByte();
54-
doubleBufferUint8[6] = readByte();
55-
doubleBufferUint8[7] = readByte();
49+
_doubleBufferUint8[0] = readByte();
50+
_doubleBufferUint8[1] = readByte();
51+
_doubleBufferUint8[2] = readByte();
52+
_doubleBufferUint8[3] = readByte();
53+
_doubleBufferUint8[4] = readByte();
54+
_doubleBufferUint8[5] = readByte();
55+
_doubleBufferUint8[6] = readByte();
56+
_doubleBufferUint8[7] = readByte();
5657
return _doubleBuffer[0];
5758
}
5859

@@ -61,6 +62,18 @@ class SummaryDataReader {
6162
return values[index];
6263
}
6364

65+
int readInt64() {
66+
_int64BufferUint8[0] = readByte();
67+
_int64BufferUint8[1] = readByte();
68+
_int64BufferUint8[2] = readByte();
69+
_int64BufferUint8[3] = readByte();
70+
_int64BufferUint8[4] = readByte();
71+
_int64BufferUint8[5] = readByte();
72+
_int64BufferUint8[6] = readByte();
73+
_int64BufferUint8[7] = readByte();
74+
return _int64Buffer[0];
75+
}
76+
6477
Map<K, V> readMap<K, V>({
6578
required K Function() readKey,
6679
required V Function() readValue,
@@ -75,6 +88,14 @@ class SummaryDataReader {
7588
};
7689
}
7790

91+
int? readOptionalInt64() {
92+
if (readBool()) {
93+
return readInt64();
94+
} else {
95+
return null;
96+
}
97+
}
98+
7899
T? readOptionalObject<T>(T Function() read) {
79100
if (readBool()) {
80101
return read();

pkg/analyzer/lib/src/summary2/data_writer.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class BufferedSink {
1515
Uint8List _buffer = Uint8List(_SIZE);
1616
int _length = 0;
1717

18+
final Int64List _int64Buffer = Int64List(1);
19+
late final Uint8List _int64BufferUint8 = _int64Buffer.buffer.asUint8List();
20+
1821
final Float64List _doubleBuffer = Float64List(1);
1922
late final Uint8List _doubleBufferUint8 = _doubleBuffer.buffer.asUint8List();
2023

@@ -116,6 +119,22 @@ class BufferedSink {
116119
}
117120
}
118121

122+
void writeInt64(int value) {
123+
_int64Buffer[0] = value;
124+
_addByte4(
125+
_int64BufferUint8[0],
126+
_int64BufferUint8[1],
127+
_int64BufferUint8[2],
128+
_int64BufferUint8[3],
129+
);
130+
_addByte4(
131+
_int64BufferUint8[4],
132+
_int64BufferUint8[5],
133+
_int64BufferUint8[6],
134+
_int64BufferUint8[7],
135+
);
136+
}
137+
119138
/// Writes [items], converts to [List] first.
120139
void writeIterable<T>(Iterable<T> items, void Function(T x) writeItem) {
121140
writeList(items.toList(), writeItem);
@@ -149,6 +168,15 @@ class BufferedSink {
149168
}
150169
}
151170

171+
void writeOptionalInt64(int? value) {
172+
if (value != null) {
173+
writeBool(true);
174+
writeInt64(value);
175+
} else {
176+
writeBool(false);
177+
}
178+
}
179+
152180
void writeOptionalObject<T>(T? object, void Function(T x) write) {
153181
if (object != null) {
154182
writeBool(true);

0 commit comments

Comments
 (0)