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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2695633002: Annotate native methods. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import 'package:front_end/src/fasta/parser/parser.dart' show 7 import 'package:front_end/src/fasta/parser/parser.dart' show
8 FormalParameterType, 8 FormalParameterType,
9 optional; 9 optional;
10 10
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 int functionNestingLevel = 0; 139 int functionNestingLevel = 0;
140 140
141 Statement compileTimeErrorInTry; 141 Statement compileTimeErrorInTry;
142 142
143 Statement compileTimeErrorInLoopOrSwitch; 143 Statement compileTimeErrorInLoopOrSwitch;
144 144
145 Scope switchScope; 145 Scope switchScope;
146 146
147 CloneVisitor cloner; 147 CloneVisitor cloner;
148 148
149 /// Set to true each time we parse a native function body. It is reset in
150 /// [handleInvalidFunctionBody] which is called immediately after.
151 bool lastErrorWasNativeFunctionBody = false;
152
153 BodyBuilder(KernelLibraryBuilder library, this.member, Scope scope, 149 BodyBuilder(KernelLibraryBuilder library, this.member, Scope scope,
154 this.formalParameterScope, this.hierarchy, this.coreTypes, 150 this.formalParameterScope, this.hierarchy, this.coreTypes,
155 this.classBuilder, this.isInstanceMember) 151 this.classBuilder, this.isInstanceMember)
156 : enclosingScope = scope, 152 : enclosingScope = scope,
157 library = library, 153 library = library,
158 isDartLibrary = library.uri.scheme == "dart", 154 isDartLibrary = library.uri.scheme == "dart",
159 super(scope); 155 super(scope);
160 156
161 bool get inConstructor { 157 bool get inConstructor {
162 return functionNestingLevel == 0 && member is KernelConstructorBuilder; 158 return functionNestingLevel == 0 && member is KernelConstructorBuilder;
(...skipping 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 if (!hasParserError) { 2160 if (!hasParserError) {
2165 print("$uri:${recoverableErrors.last}"); 2161 print("$uri:${recoverableErrors.last}");
2166 } 2162 }
2167 hasParserError = true; 2163 hasParserError = true;
2168 } 2164 }
2169 2165
2170 @override 2166 @override
2171 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { 2167 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) {
2172 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) { 2168 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) {
2173 Token recover = skipNativeClause(token); 2169 Token recover = skipNativeClause(token);
2174 if (recover != null) { 2170 if (recover != null) return recover;
2175 buildNative(unescapeString(token.next.value));
2176 return recover;
2177 }
2178 } else if (kind == ErrorKind.UnexpectedToken) { 2171 } else if (kind == ErrorKind.UnexpectedToken) {
2179 String expected = arguments["expected"]; 2172 String expected = arguments["expected"];
2180 const List<String> trailing = const <String>[")", "}", ";", ","]; 2173 const List<String> trailing = const <String>[")", "}", ";", ","];
2181 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { 2174 if (trailing.contains(token.stringValue) && trailing.contains(expected)) {
2182 arguments.putIfAbsent("actual", () => token.value); 2175 arguments.putIfAbsent("actual", () => token.value);
2183 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments); 2176 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments);
2184 } 2177 }
2185 return token; 2178 return token;
2186 } 2179 }
2187 return super.handleUnrecoverableError(token, kind, arguments); 2180 return super.handleUnrecoverableError(token, kind, arguments);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 debugEvent("Operator"); 2230 debugEvent("Operator");
2238 push(new Operator(token.stringValue)..fileOffset = token.charOffset); 2231 push(new Operator(token.stringValue)..fileOffset = token.charOffset);
2239 } 2232 }
2240 2233
2241 dynamic addCompileTimeError(int charOffset, String message) { 2234 dynamic addCompileTimeError(int charOffset, String message) {
2242 return library.addCompileTimeError(charOffset, message, uri); 2235 return library.addCompileTimeError(charOffset, message, uri);
2243 } 2236 }
2244 2237
2245 @override 2238 @override
2246 void handleInvalidFunctionBody(Token token) { 2239 void handleInvalidFunctionBody(Token token) {
2247 if (!lastErrorWasNativeFunctionBody) { 2240 if (member.isNative) {
2241 push(NullValue.FunctionBody);
2242 } else {
2248 push(new Block(<Statement>[new InvalidStatement()])); 2243 push(new Block(<Statement>[new InvalidStatement()]));
2249 } 2244 }
2250 lastErrorWasNativeFunctionBody = false;
2251 }
2252
2253 void buildNative(String native) {
2254 lastErrorWasNativeFunctionBody = true;
2255
2256 // From dartk:
2257 //
2258 // currentMember.isExternal = true;
2259 // currentMember.addAnnotation(new ast.ConstructorInvocation(
2260 // scope.loader.getCoreClassConstructorReference('ExternalName',
2261 // library: 'dart:_internal'),
2262 // new ast.Arguments(<ast.Expression>[
2263 // new ast.StringLiteral(body.stringLiteral.stringValue)
2264 // ]),
2265 // isConst: true));
2266 push(new Block(<Statement>[new InvalidStatement()]));
2267 } 2245 }
2268 2246
2269 @override 2247 @override
2270 void debugEvent(String name) { 2248 void debugEvent(String name) {
2271 // printEvent(name); 2249 // printEvent(name);
2272 } 2250 }
2273 } 2251 }
2274 2252
2275 // TODO(ahe): Shouldn't need to be an expression. 2253 // TODO(ahe): Shouldn't need to be an expression.
2276 class UnresolvedIdentifier extends InvalidExpression { 2254 class UnresolvedIdentifier extends InvalidExpression {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 } else if (node is TypeDeclarationBuilder) { 2677 } else if (node is TypeDeclarationBuilder) {
2700 return node.name; 2678 return node.name;
2701 } else if (node is PrefixBuilder) { 2679 } else if (node is PrefixBuilder) {
2702 return node.name; 2680 return node.name;
2703 } else if (node is ThisPropertyAccessor) { 2681 } else if (node is ThisPropertyAccessor) {
2704 return node.name.name; 2682 return node.name.name;
2705 } else { 2683 } else {
2706 return internalError("Unhandled: ${node.runtimeType}"); 2684 return internalError("Unhandled: ${node.runtimeType}");
2707 } 2685 }
2708 } 2686 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698