Visitar URL original
Added compilation tests and support for calling Host->Flutter by gaaclarke · Pull Request #87 · flutter/packages · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ran formatter on code
  • Loading branch information
gaaclarke committed Jan 31, 2020
commit 2ef2bbe9897816ca2977d471729cfd5846e4218b
13 changes: 13 additions & 0 deletions packages/pigeon/lib/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
enum ApiLocation {
/// The API is for calling functions defined on the host.
host,

/// The API is for calling functions defined in Flutter.
flutter,
}
Expand All @@ -13,10 +14,13 @@ class Node {}
class Func extends Node {
/// Parametric constructor for [Func].
Func({this.name, this.returnType, this.argType});

/// The name of the method.
String name;

/// The data-type of the return value.
String returnType;

/// The data-type of the argument.
String argType;
}
Expand All @@ -25,10 +29,13 @@ class Func extends Node {
class Api extends Node {
/// Parametric constructor for [Api].
Api({this.name, this.location, this.functions});

/// The name of the API.
String name;

/// Where the API's implementation is located, host or Flutter.
ApiLocation location;

/// List of functions inside the API.
List<Func> functions;
}
Expand All @@ -37,8 +44,10 @@ class Api extends Node {
class Field extends Node {
/// Parametric constructor for [Field].
Field({this.name, this.dataType});

/// The name of the field.
String name;

/// The data-type of the field (ex 'String' or 'int').
String dataType;
}
Expand All @@ -47,8 +56,10 @@ class Field extends Node {
class Class extends Node {
/// Parametric constructor for [Class].
Class({this.name, this.fields});

/// The name of the class.
String name;

/// All the fields contained in the class.
List<Field> fields;
}
Expand All @@ -57,8 +68,10 @@ class Class extends Node {
class Root extends Node {
/// Parametric constructor for [Root].
Root({this.classes, this.apis});

/// All the classes contained in the AST.
List<Class> classes;

/// All the API's contained in the AST.
List<Api> apis;
}
3 changes: 2 additions & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Indent {

int _count = 0;
final StringSink _sink;
/// String used for newlines (ex "\n").

/// String used for newlines (ex "\n").
final String newline = '\n';

/// Increase the indentation level.
Expand Down
5 changes: 4 additions & 1 deletion packages/pigeon/lib/objc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import 'generator_tools.dart';
class ObjcOptions {
/// Parametric constructor for ObjcOptions.
ObjcOptions({this.header, this.prefix});

/// The path to the header that will get placed in the source filed (example:
/// "foo.h").
String header;

/// Prefix that will be appended before all generated classes and protocols.
String prefix;
}
Expand Down Expand Up @@ -132,7 +134,8 @@ String _dictValue(List<String> classnames, Field field) {
/// provided [options].
void generateObjcSource(ObjcOptions options, Root root, StringSink sink) {
final Indent indent = Indent(sink);
final List<String> classnames = root.classes.map((Class x) => x.name).toList();
final List<String> classnames =
root.classes.map((Class x) => x.name).toList();

indent.writeln('// Autogenerated from Dartle.');
indent.writeln('#import "${options.header}"');
Expand Down
12 changes: 11 additions & 1 deletion packages/pigeon/lib/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ class FlutterApi {
class Error {
/// Parametric constructor for Error.
Error({this.message, this.filename, this.lineNumber});

/// A description of the error.
String message;

/// What file caused the [Error].
String filename;

/// What line the error happened on.
int lineNumber;
}
Expand All @@ -61,12 +64,16 @@ bool _isHostApi(ClassMirror apiMirror) {
class PigeonOptions {
/// Path to the file which will be processed.
String input;

/// Path to the dart file that will be generated.
String dartOut;

/// Path to the ".h" Objective-C file will be generated.
String objcHeaderOut;

/// Path to the ".m" Objective-C file will be generated.
String objcSourceOut;

/// Options that control how Objective-C will be generated.
ObjcOptions objcOptions = ObjcOptions();
}
Expand All @@ -75,8 +82,10 @@ class PigeonOptions {
class ParseResults {
/// Parametric constructor for [ParseResults].
ParseResults({this.root, this.errors});

/// The resulting AST.
final Root root;

/// Errors generated while parsing input.
final List<Error> errors;
}
Expand Down Expand Up @@ -208,7 +217,8 @@ options:

List<Error> _validateAst(Root root) {
final List<Error> result = <Error>[];
final List<String> customClasses = root.classes.map((Class x) => x.name).toList();
final List<String> customClasses =
root.classes.map((Class x) => x.name).toList();
for (Class klass in root.classes) {
for (Field field in klass.fields) {
if (!(_validTypes.contains(field.dataType) ||
Expand Down
12 changes: 8 additions & 4 deletions packages/pigeon/test/pigeon_lib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ class Nested {

void main() {
test('parse args - input', () {
final PigeonOptions opts = Pigeon.parseArgs(<String>['--input', 'foo.dart']);
final PigeonOptions opts =
Pigeon.parseArgs(<String>['--input', 'foo.dart']);
expect(opts.input, equals('foo.dart'));
});

test('parse args - dart_out', () {
final PigeonOptions opts = Pigeon.parseArgs(<String>['--dart_out', 'foo.dart']);
final PigeonOptions opts =
Pigeon.parseArgs(<String>['--dart_out', 'foo.dart']);
expect(opts.dartOut, equals('foo.dart'));
});

test('parse args - objc_header_out', () {
final PigeonOptions opts = Pigeon.parseArgs(<String>['--objc_header_out', 'foo.h']);
final PigeonOptions opts =
Pigeon.parseArgs(<String>['--objc_header_out', 'foo.h']);
expect(opts.objcHeaderOut, equals('foo.h'));
});

test('parse args - objc_source_out', () {
final PigeonOptions opts = Pigeon.parseArgs(<String>['--objc_source_out', 'foo.m']);
final PigeonOptions opts =
Pigeon.parseArgs(<String>['--objc_source_out', 'foo.m']);
expect(opts.objcSourceOut, equals('foo.m'));
});

Expand Down