Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
df851d5
Rename generator class to Adapter
tarrinneal Dec 21, 2022
e40d679
create new generator class and dart subclass
tarrinneal Dec 21, 2022
8c4e2a0
cpp and dart test gen
tarrinneal Dec 21, 2022
bcdbdbc
added files
tarrinneal Dec 21, 2022
31bb701
Adds Generator class to all generators
tarrinneal Dec 21, 2022
06315ce
adds swift
tarrinneal Dec 21, 2022
5675c64
Updates tests to use new Adapter naming scheme
tarrinneal Dec 21, 2022
a319b48
Dart generate methods
tarrinneal Dec 21, 2022
6d7405d
convert all generate functions to use new method
tarrinneal Dec 21, 2022
72a380c
Merge branch 'main' of github.com:flutter/packages into skeleton2
tarrinneal Dec 21, 2022
1e59fef
chagngelog
tarrinneal Dec 21, 2022
0964cd3
remove Generator class fields
tarrinneal Dec 21, 2022
f589da4
move paths to options
tarrinneal Dec 22, 2022
637679d
remove dartTestOptions
tarrinneal Dec 22, 2022
af5e0e6
Moves write header to generator class method
tarrinneal Dec 22, 2022
ae817ad
Updates tests to use new generator class
tarrinneal Dec 22, 2022
5cecc21
source -> header
tarrinneal Dec 22, 2022
99f25b5
correct options
tarrinneal Dec 22, 2022
16df207
header -> source
tarrinneal Dec 22, 2022
049c6be
header -> prefix, source -> header
tarrinneal Dec 22, 2022
a2dcb1c
remove headers from generateTestDart
tarrinneal Dec 22, 2022
e4c78f5
changelog
tarrinneal Dec 22, 2022
4f36bf4
Merge branch 'main' of github.com:flutter/packages into skelington3
tarrinneal Dec 22, 2022
68a23e2
Nits and combines source and header generators
tarrinneal Dec 27, 2022
67282cf
renames Adapter to GeneratorAdapter
tarrinneal Dec 27, 2022
d08606c
Update version number for breaking changes
tarrinneal Dec 27, 2022
90fcb67
nits
tarrinneal Dec 27, 2022
ea0ec6c
more personal nits
tarrinneal Dec 27, 2022
e99526d
Merge branch 'skeleton2' into skelington3
tarrinneal Dec 27, 2022
d5c5f1f
update tests to match new merged generators
tarrinneal Dec 27, 2022
6856812
cleaner header methods
tarrinneal Dec 27, 2022
6206bad
Fixes dart header bug
tarrinneal Dec 27, 2022
f17c0a3
Merge branch 'skeleton2' into skelington3
tarrinneal Dec 27, 2022
7c3d35c
add gen files for clarity
tarrinneal Dec 27, 2022
ef0b71a
Merge branch 'main' of github.com:flutter/packages into skeleton2
tarrinneal Dec 27, 2022
8bf2dfb
better field naming
tarrinneal Dec 28, 2022
8c6abf2
better field naming
tarrinneal Dec 28, 2022
93a5d1b
removed unneeded dart test generator
tarrinneal Dec 28, 2022
710d1a1
Add filetype to generator
tarrinneal Dec 28, 2022
d189d11
Adds filetype as field to generatorAdapters
tarrinneal Dec 29, 2022
8e068fa
Merge branch 'skeleton2' into skelington3
tarrinneal Dec 29, 2022
859c6cb
merge
tarrinneal Dec 29, 2022
daae569
Merge branch 'main' of github.com:flutter/packages into skeleton2
tarrinneal Dec 29, 2022
f23b5b6
Merge branch 'main' of github.com:flutter/packages into skelington3
tarrinneal Dec 29, 2022
6dff8cb
analyze
tarrinneal Dec 29, 2022
c17c1e4
add import method
tarrinneal Dec 29, 2022
d9f116f
re-remove DartTestGenerator
tarrinneal Dec 29, 2022
1094eeb
Merge branch 'skelington3' into imports-skeleton
tarrinneal Dec 29, 2022
e57de98
Moves imports to new method
tarrinneal Dec 29, 2022
fc63d50
adds writeEnum method to generator class
tarrinneal Dec 30, 2022
88905e3
Merge branch 'main' of github.com:flutter/packages into skeleton2
tarrinneal Dec 30, 2022
29decb9
nits
tarrinneal Dec 30, 2022
b7abbe4
assert
tarrinneal Jan 3, 2023
00ea54b
Merge branch 'skeleton2' into skelington3
tarrinneal Jan 3, 2023
bd3d2a3
Merge branch 'skelington3' into imports-skeleton
tarrinneal Jan 3, 2023
6b0faf0
Merge branch 'imports-skeleton' into writeEnum
tarrinneal Jan 3, 2023
2508a81
objc enum
tarrinneal Jan 3, 2023
e4ac916
fix code order issues
tarrinneal Jan 3, 2023
6e51c03
remove writeMainClass from java
tarrinneal Jan 4, 2023
b0b55a4
remove dead code
tarrinneal Jan 4, 2023
9664a06
Creates writeHeader method on Generator classes
tarrinneal Jan 6, 2023
ec289bc
Merge branch 'writeHeaders' into imports-skeleton
tarrinneal Jan 6, 2023
5636c81
Merge branch 'imports-skeleton' into writeEnum
tarrinneal Jan 6, 2023
3a01ade
changelog
tarrinneal Jan 7, 2023
db0f586
Merge branch 'imports-skeleton' into writeEnum
tarrinneal Jan 7, 2023
91ffeb4
changelog
tarrinneal Jan 7, 2023
02fd734
prologue
tarrinneal Jan 7, 2023
31189c8
Merge branch 'writeHeaders' into imports-skeleton
tarrinneal Jan 7, 2023
7f013f9
Merge branch 'imports-skeleton' into writeEnum
tarrinneal Jan 7, 2023
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
12 changes: 12 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 5.0.3

* Adds writeEnum method to Generator classes.

## 5.0.2

* Adds writeImports method to Generator classes.

## 5.0.1

* Adds writeHeaders method to Generator classes and updates tests to use new Generators.

## 5.0.0

* Creates new Generator classes for each language.
Expand Down
144 changes: 106 additions & 38 deletions packages/pigeon/lib/cpp_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,63 @@ class CppGenerator extends Generator<OutputFileOptions<CppOptions>> {
/// Instantiates a Cpp Generator.
CppGenerator();

/// Generates Cpp files with specified [OutputFileOptions<CppOptions>]
/// Generates Cpp header files with specified [CppOptions]
@override
void generate(OutputFileOptions<CppOptions> languageOptions, Root root,
void generate(OutputFileOptions<CppOptions> generatorOptions, Root root,
StringSink sink) {
final FileType fileType = languageOptions.fileType;
final FileType fileType = generatorOptions.fileType;
assert(fileType == FileType.header || fileType == FileType.source);

final Indent indent = Indent(sink);
writeFilePrologue(generatorOptions, root, sink, indent);
writeFileImports(generatorOptions, root, sink, indent);

for (final Enum anEnum in root.enums) {
writeEnum(generatorOptions, root, sink, indent, anEnum);
}

indent.addln('');

if (fileType == FileType.header) {
generateCppHeader(generatorOptions.languageOptions, root, sink, indent);
} else {
generateCppSource(generatorOptions.languageOptions, root, sink, indent);
}
}

@override
void writeFilePrologue(OutputFileOptions<CppOptions> generatorOptions,
Root root, StringSink sink, Indent indent) {
final FileType fileType = generatorOptions.fileType;
if (fileType == FileType.header) {
writeCppHeaderPrologue(
generatorOptions.languageOptions, root, sink, indent);
} else {
writeCppSourcePrologue(
generatorOptions.languageOptions, root, sink, indent);
}
}

@override
void writeFileImports(OutputFileOptions<CppOptions> generatorOptions,
Root root, StringSink sink, Indent indent) {
final FileType fileType = generatorOptions.fileType;
if (fileType == FileType.header) {
generateCppHeader(languageOptions.languageOptions, root, sink);
writeCppHeaderImports(
generatorOptions.languageOptions, root, sink, indent);
} else {
generateCppSource(languageOptions.languageOptions, root, sink);
writeCppSourceImports(
generatorOptions.languageOptions, root, sink, indent);
}
}

@override
void writeEnum(OutputFileOptions<CppOptions> generatorOptions, Root root,
StringSink sink, Indent indent, Enum anEnum) {
final FileType fileType = generatorOptions.fileType;
if (fileType == FileType.header) {
writeCppHeaderEnum(
generatorOptions.languageOptions, root, sink, indent, anEnum);
}
}
}
Expand Down Expand Up @@ -1049,18 +1096,22 @@ void _writeSystemHeaderIncludeBlock(Indent indent, List<String> headers) {
}
}

/// Generates the ".h" file for the AST represented by [root] to [sink] with the
/// provided [options] and [headerFileName].
void generateCppHeader(CppOptions options, Root root, StringSink sink) {
final String? headerFileName = options.headerOutPath;
final Indent indent = Indent(sink);
/// Writes Cpp header file header to sink.
void writeCppHeaderPrologue(
CppOptions options, Root root, StringSink sink, Indent indent) {
if (options.copyrightHeader != null) {
addLines(indent, options.copyrightHeader!, linePrefix: '// ');
}
indent.writeln('$_commentPrefix $generatedCodeWarning');
indent.writeln('$_commentPrefix $seeAlsoWarning');
indent.addln('');
final String guardName = _getGuardName(headerFileName, options.namespace);
}

/// Writes Cpp header file imports to sink.
void writeCppHeaderImports(
CppOptions options, Root root, StringSink sink, Indent indent) {
final String guardName =
_getGuardName(options.headerIncludePath, options.namespace);
indent.writeln('#ifndef $guardName');
indent.writeln('#define $guardName');

Expand All @@ -1077,40 +1128,48 @@ void generateCppHeader(CppOptions options, Root root, StringSink sink) {
'optional',
]);
indent.addln('');

if (options.namespace != null) {
indent.writeln('namespace ${options.namespace} {');
}

// When generating for a Pigeon unit test, add a test fixture friend class to
// allow unit testing private methods, since testing serialization via public
// methods is essentially an end-to-end test.
String? testFixtureClass;
indent.addln('');
if (options.namespace?.endsWith('_pigeontest') ?? false) {
testFixtureClass =
final String testFixtureClass =
'${_pascalCaseFromSnakeCase(options.namespace!.replaceAll('_pigeontest', ''))}Test';
indent.writeln('class $testFixtureClass;');
}

indent.addln('');
indent.writeln('$_commentPrefix Generated class from Pigeon.');
}

for (final Enum anEnum in root.enums) {
indent.writeln('');
addDocumentationComments(
indent, anEnum.documentationComments, _docCommentSpec);
indent.write('enum class ${anEnum.name} ');
indent.scoped('{', '};', () {
enumerate(anEnum.members, (int index, final EnumMember member) {
addDocumentationComments(
indent, member.documentationComments, _docCommentSpec);
indent.writeln(
'${member.name} = $index${index == anEnum.members.length - 1 ? '' : ','}');
});
/// Writes Cpp header enum to sink.
void writeCppHeaderEnum(CppOptions options, Root root, StringSink sink,
Indent indent, Enum anEnum) {
indent.writeln('');
addDocumentationComments(
indent, anEnum.documentationComments, _docCommentSpec);
indent.write('enum class ${anEnum.name} ');
indent.scoped('{', '};', () {
enumerate(anEnum.members, (int index, final EnumMember member) {
addDocumentationComments(
indent, member.documentationComments, _docCommentSpec);
indent.writeln(
'${member.name} = $index${index == anEnum.members.length - 1 ? '' : ','}');
});
}
});
}

indent.addln('');
/// Generates the ".h" file for the AST represented by [root] to [sink] with the
/// provided [options] and [headerFileName].
void generateCppHeader(
CppOptions options, Root root, StringSink sink, Indent indent) {
// When generating for a Pigeon unit test, add a test fixture friend class to
// allow unit testing private methods, since testing serialization via public
// methods is essentially an end-to-end test.
String? testFixtureClass;
if (options.namespace?.endsWith('_pigeontest') ?? false) {
testFixtureClass =
'${_pascalCaseFromSnakeCase(options.namespace!.replaceAll('_pigeontest', ''))}Test';
}

_writeErrorOr(indent, friends: root.apis.map((Api api) => api.name));

Expand All @@ -1136,14 +1195,14 @@ void generateCppHeader(CppOptions options, Root root, StringSink sink) {
if (options.namespace != null) {
indent.writeln('} // namespace ${options.namespace}');
}

final String guardName =
_getGuardName(options.headerIncludePath, options.namespace);
indent.writeln('#endif // $guardName');
}

/// Generates the ".cpp" file for the AST represented by [root] to [sink] with the
/// provided [options].
void generateCppSource(CppOptions options, Root root, StringSink sink) {
final Indent indent = Indent(sink);
/// Writes Cpp source file header to sink.
void writeCppSourcePrologue(
CppOptions options, Root root, StringSink sink, Indent indent) {
if (options.copyrightHeader != null) {
addLines(indent, options.copyrightHeader!, linePrefix: '// ');
}
Expand All @@ -1152,7 +1211,11 @@ void generateCppSource(CppOptions options, Root root, StringSink sink) {
indent.addln('');
indent.addln('#undef _HAS_EXCEPTIONS');
indent.addln('');
}

/// Writes Cpp source file imports to sink.
void writeCppSourceImports(
CppOptions options, Root root, StringSink sink, Indent indent) {
indent.writeln('#include "${options.headerIncludePath}"');
indent.addln('');
_writeSystemHeaderIncludeBlock(indent, <String>[
Expand All @@ -1172,7 +1235,12 @@ void generateCppSource(CppOptions options, Root root, StringSink sink) {
if (options.namespace != null) {
indent.writeln('namespace ${options.namespace} {');
}
}

/// Generates the ".cpp" file for the AST represented by [root] to [sink] with the
/// provided [options].
void generateCppSource(
CppOptions options, Root root, StringSink sink, Indent indent) {
for (final Class klass in root.classes) {
_writeDataClassImplementation(indent, klass, root);
}
Expand Down
Loading