Implement metadata on classes and additional semantic checks.

R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2938793002 .
This commit is contained in:
Peter von der Ahé 2017-06-14 14:59:51 +02:00
parent d98d32b63c
commit 6302a5b31b
8 changed files with 93 additions and 84 deletions

View file

@ -28,7 +28,7 @@ class AnalyzerDietListener extends DietListener {
: super(library, null, null, null);
StackListener createListener(
MemberBuilder builder, Scope memberScope, bool isInstanceMember,
ModifierBuilder builder, Scope memberScope, bool isInstanceMember,
[Scope formalParameterScope]) {
return new AstBuilder(
null, library, builder, elementStore, memberScope, false, uri);

View file

@ -36,4 +36,10 @@ abstract class ModifierBuilder extends Builder {
bool get isNamedMixinApplication {
return (modifiers & namedMixinApplicationMask) != 0;
}
bool get isClassMember => false;
String get name;
bool get isNative => false;
}

View file

@ -78,7 +78,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
@override
final KernelLibraryBuilder library;
final MemberBuilder member;
final ModifierBuilder member;
final KernelClassBuilder classBuilder;
@ -349,20 +349,41 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) {
debugEvent("Metadata");
var arguments = pop();
pushQualifiedReference(beginToken.next, periodBeforeName);
if (arguments != null) {
endConstructorReference(beginToken, periodBeforeName, endToken);
push(arguments);
endNewExpression(beginToken);
push(popForValue());
} else {
var postfix = popIfNotNull(periodBeforeName);
if (postfix != null) {
addCompileTimeError(offsetForToken(beginToken), "Not implemented.");
String name = pop();
pop(); // Type arguments (ignored, already reported by parser).
var expression = pop();
if (expression is Identifier) {
Identifier identifier = expression;
expression = new UnresolvedAccessor(
this, new Name(identifier.name, library.library), identifier.token);
}
pop(); // Type arguments.
var e = popForValue(); // Expression.
constantExpressionRequired = pop();
push(e);
if (name?.isNotEmpty ?? false) {
Token period = periodBeforeName ?? beginToken.next;
FastaAccessor accessor = expression;
expression = accessor.buildPropertyAccess(
new IncompletePropertyAccessor(
this, period.next, new Name(name, library.library)),
period.next.offset,
false);
}
bool savedConstantExpressionRequired = pop();
if (expression is! StaticAccessor) {
push(wrapInCompileTimeError(
toValue(expression),
"This can't be used as metadata; metadata should be a reference to "
"a compile-time constant variable, or "
"a call to a constant constructor."));
} else {
push(toValue(expression));
}
constantExpressionRequired = savedConstantExpressionRequired;
}
}
@ -2023,25 +2044,43 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
void endConstructorReference(
Token start, Token periodBeforeName, Token endToken) {
debugEvent("ConstructorReference");
// A constructor reference can contain up to three identifiers:
//
// a) type <type-arguments>?
// b) type <type-arguments>? . name
// c) prefix . type <type-arguments>?
// d) prefix . type <type-arguments>? . name
//
// This isn't a legal constructor reference:
//
// type . name <type-arguments>
//
// But the parser can't tell this from type c) above.
//
// This method pops 2 (or 3 if periodBeforeName != null) values from the
// stack and pushes 3 values: a type, a list of type arguments, and a name.
//
// If the constructor reference can be resolved, type is either a
// ClassBuilder, or a ThisPropertyAccessor. Otherwise, it's an error that
// should be handled later.
pushQualifiedReference(start, periodBeforeName);
}
/// A qualfied reference is something that matches one of:
///
/// identifier
/// identifier typeArguments? '.' identifier
/// identifier '.' identifier typeArguments? '.' identifier
///
/// That is, one to three identifiers separated by periods and optionally one
/// list of type arguments.
///
/// A qualified reference can be used to represent both a reference to
/// compile-time constant variable (metadata) or a constructor reference
/// (used by metadata, new/const expression, and redirecting factories).
///
/// Note that the parser will report errors if metadata includes type
/// arguments, but will other preserve them for error recovery.
///
/// A constructor reference can contain up to three identifiers:
///
/// a) type typeArguments?
/// b) type typeArguments? '.' name
/// c) prefix '.' type typeArguments?
/// d) prefix '.' type typeArguments? '.' name
///
/// This isn't a legal constructor reference:
///
/// type '.' name typeArguments?
///
/// But the parser can't tell this from type c) above.
///
/// This method pops 2 (or 3 if `periodBeforeName != null`) values from the
/// stack and pushes 3 values: an accessor (the type in a constructor
/// reference, or an expression in metadata), a list of type arguments, and a
/// name.
void pushQualifiedReference(Token start, Token periodBeforeName) {
Identifier suffix = popIfNotNull(periodBeforeName);
Identifier identifier;
List<DartType> typeArguments = pop();

View file

@ -406,7 +406,7 @@ class DietListener extends StackListener {
}
StackListener createListener(
MemberBuilder builder, Scope memberScope, bool isInstanceMember,
ModifierBuilder builder, Scope memberScope, bool isInstanceMember,
[Scope formalParameterScope]) {
var listener = new TypeInferenceListener();
InterfaceType thisType;
@ -458,10 +458,19 @@ class DietListener extends StackListener {
void beginClassBody(Token token) {
debugEvent("beginClassBody");
String name = pop();
pop(); // Metadata.
Token metadata = pop();
assert(currentClass == null);
currentClass = lookupBuilder(token, null, name);
assert(memberScope == library.scope);
Builder classBuilder = lookupBuilder(token, null, name);
if (metadata != null) {
StackListener listener = createListener(classBuilder, memberScope, false);
Parser parser = new Parser(listener);
parser.parseMetadataStar(metadata);
List metadataConstants = listener.pop();
Class cls = classBuilder.target;
metadataConstants.forEach(cls.addAnnotation);
}
currentClass = classBuilder;
memberScope = currentClass.scope;
}

View file

@ -5,5 +5,4 @@
# Status file for the shaker_test.dart test suite. This is only testing the
# tree-shaking piece of the modular compilation in fasta.
roots4: Fail # Annotations are not implemented
include_field_type: Fail # Fasta does not create interfaceTarget on accessors.

View file

@ -141,14 +141,9 @@ Language/Metadata/before_param_t09: RuntimeError # Issue 28434: Kernel IR misse
Language/Metadata/before_typedef_t01: RuntimeError # Issue 28434: Kernel IR misses these annotations.
Language/Metadata/before_variable_t01: RuntimeError # Issue 28434: Kernel IR misses these annotations.
Language/Metadata/before_variable_t02: RuntimeError # Issue 28434: Kernel IR misses these annotations.
Language/Metadata/compilation_t01: MissingCompileTimeError
Language/Metadata/compilation_t02: MissingCompileTimeError
Language/Metadata/compilation_t03: MissingCompileTimeError
Language/Metadata/compilation_t04: MissingCompileTimeError
Language/Metadata/compilation_t08: MissingCompileTimeError
Language/Metadata/compilation_t09: MissingCompileTimeError
Language/Metadata/compilation_t10: MissingCompileTimeError
Language/Metadata/compilation_t11: MissingCompileTimeError
Language/Metadata/compilation_t08: Crash
Language/Metadata/compilation_t10: Crash
Language/Mixins/Mixin_Application/deferred_t01: MissingCompileTimeError
Language/Mixins/Mixin_Application/syntax_t16: CompileTimeError # Issue 25765
Language/Mixins/declaring_constructor_t05: MissingCompileTimeError # Issue 24767
@ -197,16 +192,7 @@ Language/Expressions/Constants/depending_on_itself_t02: MissingCompileTimeError
Language/Expressions/Instance_Creation/Const/canonicalized_t05: RuntimeError
Language/Expressions/Object_Identity/string_t01: RuntimeError
Language/Expressions/Strings/adjacent_strings_t02: RuntimeError
Language/Metadata/before_class_t01: RuntimeError
Language/Metadata/before_type_param_t01: RuntimeError
Language/Metadata/compilation_t01: MissingCompileTimeError
Language/Metadata/compilation_t02: MissingCompileTimeError
Language/Metadata/compilation_t03: MissingCompileTimeError
Language/Metadata/compilation_t04: MissingCompileTimeError
Language/Metadata/compilation_t08: MissingCompileTimeError
Language/Metadata/compilation_t09: MissingCompileTimeError
Language/Metadata/compilation_t10: MissingCompileTimeError
Language/Metadata/compilation_t11: MissingCompileTimeError
LibTest/isolate/Isolate/spawnUri_A01_t03: Pass, Timeout
# dartk: JIT failures (debug)

View file

@ -104,8 +104,6 @@ const_dynamic_type_literal_test/02: RuntimeError # KernelVM bug: Constant map du
map_literal3_test: RuntimeError # KernelVM bug: Constant map duplicated key.
map_literal6_test: RuntimeError # KernelVM bug: Constant map duplicated key.
const_evaluation_test/01: RuntimeError # KernelVM bug: Reflecting on metadata.
cyclic_type_test/00: RuntimeError # KernelVM bug: Incorrect type argument.
cyclic_type_test/01: RuntimeError # KernelVM bug: Incorrect type argument.
cyclic_type_test/03: RuntimeError # KernelVM bug: Incorrect type argument.

View file

@ -517,7 +517,6 @@ mirrors/generics_substitution_test: RuntimeError
mirrors/hot_get_field_test: RuntimeError
mirrors/hot_set_field_test: RuntimeError
mirrors/inherit_field_test: RuntimeError
mirrors/inherited_metadata_test: RuntimeError
mirrors/instance_members_easier_test: RuntimeError
mirrors/instance_members_test: RuntimeError
mirrors/instance_members_with_override_test: RuntimeError
@ -547,43 +546,16 @@ mirrors/library_metadata_test: RuntimeError
mirrors/list_constructor_test/01: Crash
mirrors/list_constructor_test/none: Crash
mirrors/load_library_test: RuntimeError
mirrors/metadata_allowed_values_test/01: MissingCompileTimeError
mirrors/metadata_allowed_values_test/01: Crash
mirrors/metadata_allowed_values_test/02: MissingCompileTimeError
mirrors/metadata_allowed_values_test/03: MissingCompileTimeError
mirrors/metadata_allowed_values_test/04: MissingCompileTimeError
mirrors/metadata_allowed_values_test/09: MissingCompileTimeError
mirrors/metadata_allowed_values_test/10: MissingCompileTimeError
mirrors/metadata_allowed_values_test/11: MissingCompileTimeError
mirrors/metadata_allowed_values_test/10: Crash
mirrors/metadata_allowed_values_test/11: Crash
mirrors/metadata_allowed_values_test/13: MissingCompileTimeError
mirrors/metadata_allowed_values_test/14: MissingCompileTimeError
mirrors/metadata_allowed_values_test/15: MissingCompileTimeError
mirrors/metadata_allowed_values_test/16: MissingCompileTimeError
mirrors/metadata_allowed_values_test/27: MissingCompileTimeError
mirrors/metadata_allowed_values_test/28: MissingCompileTimeError
mirrors/metadata_allowed_values_test/29: MissingCompileTimeError
mirrors/metadata_allowed_values_test/30: MissingCompileTimeError
mirrors/metadata_allowed_values_test/31: MissingCompileTimeError
mirrors/metadata_allowed_values_test/none: RuntimeError
mirrors/metadata_allowed_values_test/15: Crash
mirrors/metadata_allowed_values_test/27: Crash
mirrors/metadata_constructed_constant_test: Crash
mirrors/metadata_constructor_arguments_test/01: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/02: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/03: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/04: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/05: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/06: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/07: MissingCompileTimeError
mirrors/metadata_constructor_arguments_test/none: RuntimeError
mirrors/metadata_nested_constructor_call_test/01: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/02: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/03: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/04: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/05: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/06: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/07: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/08: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/09: MissingCompileTimeError
mirrors/metadata_nested_constructor_call_test/none: RuntimeError
mirrors/metadata_scope_test/01: MissingCompileTimeError
mirrors/metadata_scope_test/none: RuntimeError
mirrors/metadata_test: RuntimeError
mirrors/method_mirror_location_test: RuntimeError