forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick e23acaa to dev Cherry-pick e6d3a45 to dev Cherry-pick a40fd6a to dev Cherry-pick 9eb1d74 to dev
- Loading branch information
Showing
63 changed files
with
584 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
library vm.metadata.obfuscation_prohibitions; | ||
|
||
import 'package:kernel/ast.dart'; | ||
|
||
class ObfuscationProhibitionsMetadata { | ||
final Set<String> protectedNames = Set<String>(); | ||
|
||
ObfuscationProhibitionsMetadata(); | ||
|
||
@override | ||
String toString() => protectedNames.toString(); | ||
} | ||
|
||
/// Repository for [ObfuscationProhibitionsMetadata]. | ||
class ObfuscationProhibitionsMetadataRepository | ||
extends MetadataRepository<ObfuscationProhibitionsMetadata> { | ||
static final repositoryTag = 'vm.obfuscation-prohibitions.metadata'; | ||
|
||
@override | ||
final String tag = repositoryTag; | ||
|
||
@override | ||
final Map<TreeNode, ObfuscationProhibitionsMetadata> mapping = | ||
<TreeNode, ObfuscationProhibitionsMetadata>{}; | ||
|
||
@override | ||
void writeToBinary( | ||
ObfuscationProhibitionsMetadata metadata, Node node, BinarySink sink) { | ||
sink.writeUInt32(metadata.protectedNames.length); | ||
for (String name in metadata.protectedNames) { | ||
sink.writeStringReference(name); | ||
} | ||
} | ||
|
||
@override | ||
ObfuscationProhibitionsMetadata readFromBinary( | ||
Node node, BinarySource source) { | ||
final metadata = ObfuscationProhibitionsMetadata(); | ||
int length = source.readUint32(); | ||
for (int i = 0; i < length; ++i) { | ||
metadata.protectedNames.add(source.readStringReference()); | ||
} | ||
return metadata; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
pkg/vm/lib/transformations/obfuscation_prohibitions_annotator.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
library vm.transformations.obfuscation_prohibitions_annotator; | ||
|
||
import 'package:kernel/ast.dart'; | ||
import 'package:kernel/core_types.dart' show CoreTypes; | ||
|
||
import '../metadata/obfuscation_prohibitions.dart'; | ||
import 'pragma.dart'; | ||
|
||
void transformComponent(Component component, CoreTypes coreTypes) { | ||
final repo = new ObfuscationProhibitionsMetadataRepository(); | ||
component.addMetadataRepository(repo); | ||
final visitor = | ||
ObfuscationProhibitionsVisitor(ConstantPragmaAnnotationParser(coreTypes)); | ||
visitor.visitComponent(component); | ||
repo.mapping[component] = visitor.metadata; | ||
} | ||
|
||
class ObfuscationProhibitionsVisitor extends RecursiveVisitor { | ||
final PragmaAnnotationParser parser; | ||
final metadata = ObfuscationProhibitionsMetadata(); | ||
|
||
ObfuscationProhibitionsVisitor(this.parser); | ||
|
||
void _addIfEntryPoint( | ||
List<Expression> annotations, String name, TreeNode node) { | ||
for (var ann in annotations) { | ||
ParsedPragma pragma = parser.parsePragma(ann); | ||
if (pragma is ParsedEntryPointPragma) { | ||
metadata.protectedNames.add(name); | ||
if (node is Field) { | ||
metadata.protectedNames.add(name + "="); | ||
} | ||
final parent = node.parent; | ||
if (parent is Class) { | ||
metadata.protectedNames.add(parent.name); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@override | ||
visitClass(Class klass) { | ||
_addIfEntryPoint(klass.annotations, klass.name, klass); | ||
klass.visitChildren(this); | ||
} | ||
|
||
@override | ||
visitProcedure(Procedure proc) { | ||
_addIfEntryPoint(proc.annotations, proc.name.name, proc); | ||
} | ||
|
||
@override | ||
visitField(Field field) { | ||
_addIfEntryPoint(field.annotations, field.name.name, field); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
library vm.transformations.pragma; | ||
|
||
import 'package:kernel/ast.dart'; | ||
import 'package:kernel/core_types.dart' show CoreTypes; | ||
|
||
const kEntryPointPragmaName = "vm:entry-point"; | ||
const kExactResultTypePragmaName = "vm:exact-result-type"; | ||
|
||
abstract class ParsedPragma {} | ||
|
||
enum PragmaEntryPointType { Always, GetterOnly, SetterOnly } | ||
|
||
class ParsedEntryPointPragma extends ParsedPragma { | ||
final PragmaEntryPointType type; | ||
ParsedEntryPointPragma(this.type); | ||
} | ||
|
||
class ParsedResultTypeByTypePragma extends ParsedPragma { | ||
final DartType type; | ||
ParsedResultTypeByTypePragma(this.type); | ||
} | ||
|
||
class ParsedResultTypeByPathPragma extends ParsedPragma { | ||
final String path; | ||
ParsedResultTypeByPathPragma(this.path); | ||
} | ||
|
||
abstract class PragmaAnnotationParser { | ||
/// May return 'null' if the annotation does not represent a recognized | ||
/// @pragma. | ||
ParsedPragma parsePragma(Expression annotation); | ||
} | ||
|
||
class ConstantPragmaAnnotationParser extends PragmaAnnotationParser { | ||
final CoreTypes coreTypes; | ||
|
||
ConstantPragmaAnnotationParser(this.coreTypes); | ||
|
||
ParsedPragma parsePragma(Expression annotation) { | ||
InstanceConstant pragmaConstant; | ||
if (annotation is ConstantExpression) { | ||
Constant constant = annotation.constant; | ||
if (constant is InstanceConstant) { | ||
if (constant.classReference.node == coreTypes.pragmaClass) { | ||
pragmaConstant = constant; | ||
} | ||
} | ||
} | ||
if (pragmaConstant == null) return null; | ||
|
||
String pragmaName; | ||
Constant name = pragmaConstant.fieldValues[coreTypes.pragmaName.reference]; | ||
if (name is StringConstant) { | ||
pragmaName = name.value; | ||
} else { | ||
return null; | ||
} | ||
|
||
Constant options = | ||
pragmaConstant.fieldValues[coreTypes.pragmaOptions.reference]; | ||
assert(options != null); | ||
|
||
switch (pragmaName) { | ||
case kEntryPointPragmaName: | ||
PragmaEntryPointType type; | ||
if (options is NullConstant) { | ||
type = PragmaEntryPointType.Always; | ||
} else if (options is BoolConstant && options.value == true) { | ||
type = PragmaEntryPointType.Always; | ||
} else if (options is StringConstant) { | ||
if (options.value == "get") { | ||
type = PragmaEntryPointType.GetterOnly; | ||
} else if (options.value == "set") { | ||
type = PragmaEntryPointType.SetterOnly; | ||
} else { | ||
throw "Error: string directive to @pragma('$kEntryPointPragmaName', ...) " | ||
"must be either 'get' or 'set'."; | ||
} | ||
} | ||
return type != null ? new ParsedEntryPointPragma(type) : null; | ||
case kExactResultTypePragmaName: | ||
if (options == null) return null; | ||
if (options is TypeLiteralConstant) { | ||
return new ParsedResultTypeByTypePragma(options.type); | ||
} else if (options is StringConstant) { | ||
return new ParsedResultTypeByPathPragma(options.value); | ||
} | ||
throw "ERROR: Unsupported option to '$kExactResultTypePragmaName' " | ||
"pragma: $options"; | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.