use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class ColorPoolTest method deserializesNativeObjectTableIntoNativeColor.
@Test
public void deserializesNativeObjectTableIntoNativeColor() {
TypePool typePool = TypePool.newBuilder().addType(TypeProto.newBuilder().setObject(ObjectTypeProto.newBuilder().setUuid(StandardColors.NUMBER_OBJECT_ID.asByteString()).setDebugInfo(ObjectTypeProto.DebugInfo.newBuilder().addTypename("Number")).setIsInvalidating(true)).build()).addType(TypeProto.newBuilder().setObject(ObjectTypeProto.newBuilder().setUuid(ByteString.copyFromUtf8("Num.pro"))).build()).addDisambiguationEdges(// Number is a subtype of Number.prototype
SubtypingEdge.newBuilder().setSubtype(poolPointer(0)).setSupertype(poolPointer(1))).build();
ColorPool colorPool = ColorPool.fromOnlyShard(typePool, StringPool.empty());
ColorPool.ShardView view = colorPool.getOnlyShard();
Color numberObject = colorPool.getColor(StandardColors.NUMBER_OBJECT_ID);
assertThat(numberObject).isInvalidating();
assertThat(numberObject).hasDisambiguationSupertypesThat(colorPool.getRegistry()).containsExactly(view.getColor(poolPointer(1)));
assertThat(numberObject).isSameInstanceAs(view.getColor(poolPointer(0)));
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class ColorPoolTest method recordsDisambiguationsSupertypes_multipleSupertypesPerSubtype.
@Test
public void recordsDisambiguationsSupertypes_multipleSupertypesPerSubtype() {
TypePool typePool = TypePool.newBuilder().addType(TypeProto.newBuilder().setObject(ObjectTypeProto.newBuilder().setUuid(ByteString.copyFromUtf8("Foo")))).addType(TypeProto.newBuilder().setObject(ObjectTypeProto.newBuilder().setUuid(ByteString.copyFromUtf8("Bar")))).addType(TypeProto.newBuilder().setObject(ObjectTypeProto.newBuilder().setUuid(ByteString.copyFromUtf8("Baz")))).addDisambiguationEdges(SubtypingEdge.newBuilder().setSubtype(poolPointer(1)).setSupertype(poolPointer(0))).addDisambiguationEdges(SubtypingEdge.newBuilder().setSubtype(poolPointer(1)).setSupertype(poolPointer(2))).build();
// When
ColorPool.Builder colorPoolBuilder = ColorPool.builder();
ColorPool.ShardView shard = colorPoolBuilder.addShard(typePool, StringPool.empty());
ColorPool colorPool = colorPoolBuilder.build();
// Then
Color foo = shard.getColor(poolPointer(0));
Color bar = shard.getColor(poolPointer(1));
Color baz = shard.getColor(poolPointer(2));
assertThat(bar).hasDisambiguationSupertypesThat(colorPool.getRegistry()).containsExactly(foo, baz);
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class ColorPoolTest method deserializesTopObjectTypeFromEmptyTypePool.
@Test
public void deserializesTopObjectTypeFromEmptyTypePool() {
ColorPool.ShardView colorPool = ColorPool.fromOnlyShard(TypePool.getDefaultInstance(), StringPool.empty()).getOnlyShard();
Color object = colorPool.getColor(PrimitiveType.TOP_OBJECT.getNumber());
assertThat(object).isInvalidating();
assertThat(object.getInstanceColors()).isEmpty();
assertThat(object.getPrototypes()).isEmpty();
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class JSTypeReconserializer method seedCachesWithAxiomaticTypes.
/**
* Inserts dummy pointers corresponding to all {@link PrimitiveType}s in the type pool.
*
* <p>These types will never correspond to an actual {@link TypeProto}. Instead, all normal {@link
* Integer} offsets into the pool are offset by a number equivalent to the number of {@link
* PrimitiveType} enum elements.
*/
private void seedCachesWithAxiomaticTypes() {
checkState(this.seenTypeRecords.isEmpty());
// Load all the axiomatic records in the right order without any types.
for (Color axiomatic : TypePointers.OFFSET_TO_AXIOMATIC_COLOR) {
int index = this.seenTypeRecords.size();
SeenTypeRecord record = new SeenTypeRecord(axiomatic.getId(), index);
this.seenTypeRecords.put(axiomatic.getId(), record);
}
// Add JSTypes corresponding to axiomatic IDs.
JSTYPE_NATIVE_TO_AXIOMATIC_COLOR_MAP.forEach((jstypeNative, axiomatic) -> this.getOrCreateRecord(axiomatic.getId(), this.registry.getNativeType(jstypeNative)));
checkState(this.seenTypeRecords.size() == TypePointers.OFFSET_TO_AXIOMATIC_COLOR.size());
}
use of com.google.javascript.jscomp.colors.Color in project closure-compiler by google.
the class AstAnalyzer method isTypedAsString.
private boolean isTypedAsString(Node n) {
if (n.isStringLit()) {
return true;
}
if (compiler.getOptions().useTypesForLocalOptimization) {
Color color = n.getColor();
if (color != null) {
return color.equals(StandardColors.STRING);
}
JSType type = n.getJSType();
if (type != null) {
JSType nativeStringType = compiler.getTypeRegistry().getNativeType(JSTypeNative.STRING_TYPE);
if (type.equals(nativeStringType)) {
return true;
}
}
}
return false;
}
Aggregations