OLD | NEW |
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 library kernel.ast_to_binary; | 4 library kernel.ast_to_binary; |
5 | 5 |
6 import '../ast.dart'; | 6 import '../ast.dart'; |
7 import '../import_table.dart'; | 7 import '../import_table.dart'; |
8 import 'tag.dart'; | 8 import 'tag.dart'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 writeStringReference(node.name ?? ''); | 337 writeStringReference(node.name ?? ''); |
338 writeNodeList(node.combinators); | 338 writeNodeList(node.combinators); |
339 } | 339 } |
340 | 340 |
341 void visitCombinator(Combinator node) { | 341 void visitCombinator(Combinator node) { |
342 writeByte(node.isShow ? 1 : 0); | 342 writeByte(node.isShow ? 1 : 0); |
343 writeStringReferenceList(node.names); | 343 writeStringReferenceList(node.names); |
344 } | 344 } |
345 | 345 |
346 void visitTypedef(Typedef node) { | 346 void visitTypedef(Typedef node) { |
347 _variableIndexer = new VariableIndexer(); | |
348 writeCanonicalNameReference(getCanonicalNameOfTypedef(node)); | 347 writeCanonicalNameReference(getCanonicalNameOfTypedef(node)); |
349 writeOffset(node.fileOffset); | 348 writeOffset(node.fileOffset); |
350 writeStringReference(node.name); | 349 writeStringReference(node.name); |
351 writeUriReference(node.fileUri ?? ''); | 350 writeUriReference(node.fileUri ?? ''); |
352 _typeParameterIndexer.enter(node.typeParameters); | 351 _typeParameterIndexer.enter(node.typeParameters); |
353 writeNodeList(node.typeParameters); | 352 writeNodeList(node.typeParameters); |
354 writeUInt30(node.requiredParameterCount); | |
355 writeVariableDeclarationList(node.positionalParameters); | |
356 writeVariableDeclarationList(node.namedParameters); | |
357 writeNode(node.type); | 353 writeNode(node.type); |
358 _typeParameterIndexer.exit(node.typeParameters); | 354 _typeParameterIndexer.exit(node.typeParameters); |
359 _variableIndexer = null; | |
360 } | 355 } |
361 | 356 |
362 void writeAnnotation(Expression annotation) { | 357 void writeAnnotation(Expression annotation) { |
363 _variableIndexer ??= new VariableIndexer(); | 358 _variableIndexer ??= new VariableIndexer(); |
364 writeNode(annotation); | 359 writeNode(annotation); |
365 } | 360 } |
366 | 361 |
367 void writeAnnotationList(List<Expression> annotations) { | 362 void writeAnnotationList(List<Expression> annotations) { |
368 writeList(annotations, writeAnnotation); | 363 writeList(annotations, writeAnnotation); |
369 } | 364 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 _variableIndexer = new VariableIndexer(); | 408 _variableIndexer = new VariableIndexer(); |
414 writeByte(Tag.Constructor); | 409 writeByte(Tag.Constructor); |
415 writeCanonicalNameReference(getCanonicalNameOfMember(node)); | 410 writeCanonicalNameReference(getCanonicalNameOfMember(node)); |
416 writeOffset(node.fileOffset); | 411 writeOffset(node.fileOffset); |
417 writeOffset(node.fileEndOffset); | 412 writeOffset(node.fileEndOffset); |
418 writeByte(node.flags); | 413 writeByte(node.flags); |
419 assert(node.parent is Class); | 414 assert(node.parent is Class); |
420 Class parent = node.parent; | 415 Class parent = node.parent; |
421 writeUInt30(parent.binaryOffset); | 416 writeUInt30(parent.binaryOffset); |
422 writeName(node.name ?? _emptyName); | 417 writeName(node.name ?? _emptyName); |
423 writeStringReference(node.documentationComment ?? ''); | |
424 writeAnnotationList(node.annotations); | 418 writeAnnotationList(node.annotations); |
425 assert(node.function.typeParameters.isEmpty); | 419 assert(node.function.typeParameters.isEmpty); |
426 writeNode(node.function); | 420 writeNode(node.function); |
427 // Parameters are in scope in the initializers. | 421 // Parameters are in scope in the initializers. |
428 _variableIndexer.restoreScope(node.function.positionalParameters.length + | 422 _variableIndexer.restoreScope(node.function.positionalParameters.length + |
429 node.function.namedParameters.length); | 423 node.function.namedParameters.length); |
430 writeNodeList(node.initializers); | 424 writeNodeList(node.initializers); |
431 _variableIndexer = null; | 425 _variableIndexer = null; |
432 } | 426 } |
433 | 427 |
434 visitProcedure(Procedure node) { | 428 visitProcedure(Procedure node) { |
435 if (node.canonicalName == null) { | 429 if (node.canonicalName == null) { |
436 throw 'Missing canonical name for $node'; | 430 throw 'Missing canonical name for $node'; |
437 } | 431 } |
438 _variableIndexer = new VariableIndexer(); | 432 _variableIndexer = new VariableIndexer(); |
439 writeByte(Tag.Procedure); | 433 writeByte(Tag.Procedure); |
440 writeCanonicalNameReference(getCanonicalNameOfMember(node)); | 434 writeCanonicalNameReference(getCanonicalNameOfMember(node)); |
441 writeOffset(node.fileOffset); | 435 writeOffset(node.fileOffset); |
442 writeOffset(node.fileEndOffset); | 436 writeOffset(node.fileEndOffset); |
443 writeByte(node.kind.index); | 437 writeByte(node.kind.index); |
444 writeByte(node.flags); | 438 writeByte(node.flags); |
445 if (node.parent is Class) { | 439 if (node.parent is Class) { |
446 Class parent = node.parent; | 440 Class parent = node.parent; |
447 writeUInt30(parent.binaryOffset); | 441 writeUInt30(parent.binaryOffset); |
448 } else { | 442 } else { |
449 writeUInt30(0); // 0 is a valid offset, but not for a class. | 443 writeUInt30(0); // 0 is a valid offset, but not for a class. |
450 } | 444 } |
451 writeName(node.name ?? ''); | 445 writeName(node.name ?? ''); |
452 writeUriReference(node.fileUri ?? ''); | 446 writeUriReference(node.fileUri ?? ''); |
453 writeStringReference(node.documentationComment ?? ''); | |
454 writeAnnotationList(node.annotations); | 447 writeAnnotationList(node.annotations); |
455 writeOptionalNode(node.function); | 448 writeOptionalNode(node.function); |
456 _variableIndexer = null; | 449 _variableIndexer = null; |
457 } | 450 } |
458 | 451 |
459 visitField(Field node) { | 452 visitField(Field node) { |
460 if (node.canonicalName == null) { | 453 if (node.canonicalName == null) { |
461 throw 'Missing canonical name for $node'; | 454 throw 'Missing canonical name for $node'; |
462 } | 455 } |
463 _variableIndexer = new VariableIndexer(); | 456 _variableIndexer = new VariableIndexer(); |
464 writeByte(Tag.Field); | 457 writeByte(Tag.Field); |
465 writeCanonicalNameReference(getCanonicalNameOfMember(node)); | 458 writeCanonicalNameReference(getCanonicalNameOfMember(node)); |
466 writeOffset(node.fileOffset); | 459 writeOffset(node.fileOffset); |
467 writeOffset(node.fileEndOffset); | 460 writeOffset(node.fileEndOffset); |
468 writeByte(node.flags); | 461 writeByte(node.flags); |
469 if (node.parent is Class) { | 462 if (node.parent is Class) { |
470 Class parent = node.parent; | 463 Class parent = node.parent; |
471 writeUInt30(parent.binaryOffset); | 464 writeUInt30(parent.binaryOffset); |
472 } else { | 465 } else { |
473 writeUInt30(0); // 0 is a valid offset, but not for a class. | 466 writeUInt30(0); // 0 is a valid offset, but not for a class. |
474 } | 467 } |
475 writeName(node.name); | 468 writeName(node.name); |
476 writeUriReference(node.fileUri ?? ''); | 469 writeUriReference(node.fileUri ?? ''); |
477 writeStringReference(node.documentationComment ?? ''); | |
478 writeAnnotationList(node.annotations); | 470 writeAnnotationList(node.annotations); |
479 writeNode(node.type); | 471 writeNode(node.type); |
480 writeOptionalNode(node.initializer); | 472 writeOptionalNode(node.initializer); |
481 _variableIndexer = null; | 473 _variableIndexer = null; |
482 } | 474 } |
483 | 475 |
484 visitInvalidInitializer(InvalidInitializer node) { | 476 visitInvalidInitializer(InvalidInitializer node) { |
485 writeByte(Tag.InvalidInitializer); | 477 writeByte(Tag.InvalidInitializer); |
486 writeByte(node.isSynthetic ? 1 : 0); | 478 writeByte(node.isSynthetic ? 1 : 0); |
487 } | 479 } |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 put(node.name); | 1363 put(node.name); |
1372 node.visitChildren(this); | 1364 node.visitChildren(this); |
1373 } | 1365 } |
1374 | 1366 |
1375 visitClass(Class node) { | 1367 visitClass(Class node) { |
1376 putOptional(node.documentationComment); | 1368 putOptional(node.documentationComment); |
1377 putOptional(node.name); | 1369 putOptional(node.name); |
1378 node.visitChildren(this); | 1370 node.visitChildren(this); |
1379 } | 1371 } |
1380 | 1372 |
1381 @override | |
1382 visitConstructor(Constructor node) { | |
1383 putOptional(node.documentationComment); | |
1384 super.visitConstructor(node); | |
1385 } | |
1386 | |
1387 @override | |
1388 visitField(Field node) { | |
1389 putOptional(node.documentationComment); | |
1390 super.visitField(node); | |
1391 } | |
1392 | |
1393 visitNamedExpression(NamedExpression node) { | 1373 visitNamedExpression(NamedExpression node) { |
1394 put(node.name); | 1374 put(node.name); |
1395 node.visitChildren(this); | 1375 node.visitChildren(this); |
1396 } | 1376 } |
1397 | 1377 |
1398 @override | |
1399 visitProcedure(Procedure node) { | |
1400 putOptional(node.documentationComment); | |
1401 super.visitProcedure(node); | |
1402 } | |
1403 | |
1404 visitStringLiteral(StringLiteral node) { | 1378 visitStringLiteral(StringLiteral node) { |
1405 put(node.value); | 1379 put(node.value); |
1406 } | 1380 } |
1407 | 1381 |
1408 visitIntLiteral(IntLiteral node) { | 1382 visitIntLiteral(IntLiteral node) { |
1409 if (node.value.abs() >> 30 != 0) { | 1383 if (node.value.abs() >> 30 != 0) { |
1410 put('${node.value}'); | 1384 put('${node.value}'); |
1411 } | 1385 } |
1412 } | 1386 } |
1413 | 1387 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 _sink.add(_buffer.sublist(0, length)); | 1515 _sink.add(_buffer.sublist(0, length)); |
1542 _buffer = new Uint8List(SIZE); | 1516 _buffer = new Uint8List(SIZE); |
1543 flushedLength += length; | 1517 flushedLength += length; |
1544 length = 0; | 1518 length = 0; |
1545 } | 1519 } |
1546 | 1520 |
1547 void flushAndDestroy() { | 1521 void flushAndDestroy() { |
1548 _sink.add(_buffer.sublist(0, length)); | 1522 _sink.add(_buffer.sublist(0, length)); |
1549 } | 1523 } |
1550 } | 1524 } |
OLD | NEW |