[pigeon] add support for top level consts#12032
Open
tarrinneal wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds support for generating top-level constants across all supported platforms in Pigeon. Feedback on the changes suggests resolving compilation issues by avoiding the escaping of the $ character in the shared double-quote escaping helper and instead handling it specifically in Kotlin. Additionally, double constants initialized with integer literals should be explicitly parsed as doubles to prevent type mismatch errors in Java and Kotlin, and Java constants should be generated as primitive types rather than boxed types to ensure they function as true compile-time constants.
Contributor
Author
|
/gemini |
Contributor
Author
|
/gemini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Top-level Constants Support to Pigeon
This PR adds support for defining and generating top-level constants across all target languages supported by Pigeon (Dart, Kotlin, Java, Swift, Objective-C, C++, and GObject).
Resolves: flutter/flutter#188642
Summary of Changes
1. AST & Parser
Constantnode type to the AST representing top-level constants.pigeon_lib_internal.dartto parseconstdeclarations.String,int,double, andbool.2. Code Generation
Added constant generation to all target languages:
constvariables.public static finalfields inside the main generated class.const valproperties (usingvalfor double/boolean where JVMconstis not supported).public letconstants.static const/static NSString *constvariables in the header file.inline constexprvariables in the header.#definemacros in the header.3. Tests & Documentation
test/pigeon_lib_test.dart.test/*_generator_test.dart) for each language verifying the syntax of generated constants.pigeons/core_tests.dartwith constant declarations, and added corresponding unit tests verifying their correctness in each target platform project.platform_tests/shared_test_plugin_code/lib/integration_tests.dartto assert constant values at runtime.packages/pigeon/README.mdto document the new feature, using code excerpts linked toexample/app/pigeons/messages.dart.