[pigeon] fixed recursing into class declarations in the front end parser (#386)

This commit is contained in:
gaaclarke
2021-06-23 09:54:49 -07:00
committed by GitHub
parent 7277bd72c6
commit 8c03b5ed24
6 changed files with 59 additions and 3 deletions

View File

@ -1,3 +1,8 @@
## 0.2.4
* bugfix in front-end parser for recursively referenced datatypes.
## 0.2.3
* bugfix in iOS async handlers of functions with no arguments.

View File

@ -8,7 +8,7 @@ import 'dart:mirrors';
import 'ast.dart';
/// The current version of pigeon. This must match the version in pubspec.yaml.
const String pigeonVersion = '0.2.3';
const String pigeonVersion = '0.2.4';
/// Read all the content from [stdin] to a String.
String readStdin() {

View File

@ -399,6 +399,27 @@ class Pigeon {
}
}
}
// Recurse into class field declarations.
final List<ClassMirror> classesToRecurse = <ClassMirror>[...classes];
while (classesToRecurse.isNotEmpty) {
final ClassMirror next = classesToRecurse.removeLast();
for (final DeclarationMirror declaration in next.declarations.values) {
if (declaration is VariableMirror) {
final TypeMirror fieldType = declaration.type;
if (fieldType is ClassMirror) {
if (!classes.contains(fieldType) &&
!fieldType.isEnum &&
!_validTypes
.contains(MirrorSystem.getName(fieldType.simpleName))) {
classes.add(declaration.type as ClassMirror);
classesToRecurse.add(declaration.type as ClassMirror);
}
}
}
}
}
// Parse referenced enum types out of classes.
for (final ClassMirror klass in classes) {
for (final DeclarationMirror declaration in klass.declarations.values) {

View File

@ -2,7 +2,7 @@ name: pigeon
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
repository: https://github.com/flutter/packages/tree/master/packages/pigeon
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
version: 0.2.3 # This must match the version in lib/generator_tools.dart
version: 0.2.4 # This must match the version in lib/generator_tools.dart
environment:
sdk: '>=2.12.0 <3.0.0'

View File

@ -71,8 +71,9 @@ test_pigeon_ios() {
xcrun clang \
-arch arm64 \
-isysroot $(xcrun --sdk iphoneos --show-sdk-path) \
-F $framework_path \
-F $framework_path/Flutter.xcframework/ios-armv7_arm64 \
-F $framework_path/Flutter.xcframework/ios-armv7 \
-F $framework_path/Flutter.xcframework/ios-arm64_armv7 \
-Werror \
-fobjc-arc \
-c $temp_dir/pigeon.m \

View File

@ -86,6 +86,26 @@ abstract class InvalidReturnTypeApi {
bool doit();
}
enum NestedEnum { one, two }
class NestedEnum1 {
NestedEnum? test;
}
class NestedEnum2 {
NestedEnum1? class1;
}
class NestedEnum3 {
NestedEnum2? class1;
int? n;
}
@HostApi()
abstract class NestedEnumApi {
void method(NestedEnum3 foo);
}
void main() {
test('parse args - input', () {
final PigeonOptions opts =
@ -312,4 +332,13 @@ void main() {
objcSourceGenerator.generate(buffer, options, root);
expect(buffer.toString(), startsWith('// Copyright 2013'));
});
test('nested enum', () {
final Pigeon dartle = Pigeon.setup();
final ParseResults parseResult = dartle.parse(<Type>[NestedEnumApi]);
expect(parseResult.errors.length, equals(0));
expect(parseResult.root.apis.length, 1);
expect(parseResult.root.classes.length, 3);
expect(parseResult.root.enums.length, 1);
});
}