-
Notifications
You must be signed in to change notification settings - Fork 64
[code_builder] Add control-flow support #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
one23four56
wants to merge
19
commits into
dart-lang:main
Choose a base branch
from
one23four56:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
16e8e34
[code_builder] add control-flow expressions via `ControlExpression`
one23four56 cbbb7ee
[code_builder] fix typos in `expression_test` and changelog
one23four56 1754964
[code_builder] feat: add control-flow loops
one23four56 ec35a89
[code_builder] chore: rebuild generated files with newer `built_value…
one23four56 6d152c4
[code_builder] style: follow commonmark
one23four56 993ca06
[code_builder] feat: support if/else trees
one23four56 415bc29
[code_builder] feat: support try/catch blocks
one23four56 32797a0
[code_builder] refactor: split up control.dart
one23four56 b39e415
[code_builder] feat: support switch statements
one23four56 8b9dbfc
[code_builder] feat: support `switch` expressions
one23four56 4ef3b88
[code_builder] feat: support collection control-flow expressions
one23four56 da9b254
update readme and delete temp files
one23four56 76e4560
update readme and delete temp files
one23four56 25f0368
allow `catch` omission and update defaults
one23four56 7f0b0d1
Merge branch 'main' into main
one23four56 4c02606
refactor branches
one23four56 ac79fa1
Merge branch 'main' of https://github.com/one23four56/tools
one23four56 3435a07
- drop ignores
one23four56 eecb6d5
Merge branch 'main' into main
one23four56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
.packages | ||
.pub | ||
pubspec.lock | ||
doc/api | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,58 @@ | ||
## 4.10.2-wip | ||
## 4.11.0-wip | ||
|
||
* Upgrade `dart_style` and `source_gen` to remove `package:macros` dependency. | ||
|
||
* Require Dart `^3.6.0` due to the upgrades. | ||
* Support `Expression.newInstanceNamed` with empty name | ||
* Fixed bug: Fields declared with `static` and `external` now produce code with correct order | ||
|
||
* Support `Expression.newInstanceNamed` with empty name. | ||
|
||
* Fixed bug: Fields declared with `static` and `external` now produce code with correct order. | ||
|
||
* Add `ControlFlow` extension on `Expression` to support control-flow helper functions. | ||
* Add `Expression.yielded` (via ext.) | ||
* Add `Expression.yieldStarred` (via ext.) | ||
* Add `Expression.ifThen` (via ext.) | ||
* Add `Expression.ifThenReturn` (via ext.) | ||
* Add `Expression.loopWhile` (via ext.) | ||
* Add `Expression.loopDoWhile` (via ext.) | ||
* Add `Expression.loopForIn` (via ext.) | ||
|
||
* Add static keyword helper functions to `ControlFlow`. | ||
* Add `ControlFlow.breakVoid` | ||
* Add `ControlFlow.breakLabel` | ||
* Add `ControlFlow.continueVoid` | ||
* Add `ControlFlow.continueLabel` | ||
* Add `ControlFlow.returnVoid` | ||
* Add `ControlFlow.rethrowVoid` | ||
|
||
* Support emitting collection control-flow expressions via static methods on `ControlFlow`. | ||
* Add `ControlFlow.collectionIf` | ||
* Add `ControlFlow.collectionElse` | ||
* Add `ControlFlow.collectionFor` | ||
* Add `ControlFlow.collectionForIn` | ||
* Add `ControlFlow.ifCase` | ||
* Update literal collection visitors to support chaining. | ||
|
||
* Support emitting control-flow loops. | ||
* Add `ForLoop` and `ForLoopBuilder` for traditional `for` loops. | ||
* Add `ForInLoop` and `ForInLoopBuilder` for `for-in` and `await-for` loops. | ||
* Add `WhileLoop` and `WhileLoopBuilder` for `while` and `do-while` loops. | ||
|
||
* Support emitting `if` statements and `if`/`else if`/`else` trees. | ||
* Add `Conditional` and `ConditionalBuilder` for conditional trees. | ||
* Add `BranchBuilder` for builder `Conditional` branches. | ||
|
||
* Support emitting `try`/`catch`/`finally` blocks. | ||
* Add `CatchBlock` and `CatchBlockBuilder` for catch clauses. | ||
* Add `TryCatch` and `TryCatchBuilder` for try/catch blocks. | ||
|
||
* Support emitting `switch` statements and expressions. | ||
* Add `Case` and `CaseBuilder` for creating `switch` cases. | ||
* Add `SwitchExpression` and `SwitchExpressionBuilder` for `switch` expressions. | ||
* Add `SwitchStatement` and `SwitchStatementBuilder` for `switch` statements. | ||
* Add `Expression.wildcard` static constant for wildcard (`_`) expressions. | ||
|
||
* Simplify usage examples on the README. | ||
|
||
## 4.10.1 | ||
|
||
|
@@ -156,7 +205,7 @@ void main() { | |
## 3.4.1 | ||
|
||
* Fix confusing mismatch description from `equalsDart`. | ||
https://github.com/dart-lang/code_builder/issues/293 | ||
<https://github.com/dart-lang/code_builder/issues/293> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid other changes to this file. it makes it hard to review! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apologies, that was my formatter as i inadvertently left format on save enabled |
||
## 3.4.0 | ||
|
||
|
@@ -209,7 +258,6 @@ void main() { | |
* `Expression.asA` is now wrapped with parenthesis so that further calls may be | ||
made on it as an expression. | ||
|
||
|
||
## 3.1.0 | ||
|
||
* Added `Expression.asA` for creating explicit casts: | ||
|
@@ -256,7 +304,7 @@ void main() { | |
|
||
## 2.4.0 | ||
|
||
* Add `equalTo`, `notEqualTo`, `greaterThan`, `lessThan`, `greateOrEqualTo`, and | ||
* Add `equalTo`, `notEqualTo`, `greaterThan`, `lessThan`, `greaterOrEqualTo`, and | ||
`lessOrEqualTo` to `Expression`. | ||
|
||
## 2.3.0 | ||
|
@@ -346,7 +394,7 @@ void main() { | |
``` | ||
|
||
* Added `nullSafeProperty` to `Expression` to access properties with `?.` | ||
* Added `conditional` to `Expression` to use the ternary operator `? : ` | ||
* Added `conditional` to `Expression` to use the ternary operator `? :` | ||
* Methods taking `positionalArguments` accept `Iterable<Expression>` | ||
* **BUG FIX**: Parameters can take a `FunctionType` as a `type`. | ||
`Reference.type` now returns a `Reference`. Note that this change is | ||
|
@@ -572,7 +620,7 @@ final animal = new Class((b) => b | |
## 2.0.0-alpha | ||
|
||
* Complete re-write to not use `package:analyzer`. | ||
* Code generation now properly uses the _builder_ pattern (via `built_value`). | ||
* Code generation now properly uses the *builder* pattern (via `built_value`). | ||
* See examples and tests for details. | ||
|
||
## 1.0.4 | ||
|
@@ -606,38 +654,38 @@ that the entire Dart language is buildable with our API, though. | |
|
||
**Contributions are welcome.** | ||
|
||
- Exposed `uri` in `ImportBuilder`, `ExportBuilder`, and `Part[Of]Builder`. | ||
* Exposed `uri` in `ImportBuilder`, `ExportBuilder`, and `Part[Of]Builder`. | ||
|
||
## 1.0.0-beta+7 | ||
|
||
- Added `ExpressionBuilder#ternary`. | ||
* Added `ExpressionBuilder#ternary`. | ||
|
||
## 1.0.0-beta+6 | ||
|
||
- Added `TypeDefBuilder`. | ||
- Added `FunctionParameterBuilder`. | ||
- Added `asAbstract` to various `MethodBuilder` constructors. | ||
* Added `TypeDefBuilder`. | ||
* Added `FunctionParameterBuilder`. | ||
* Added `asAbstract` to various `MethodBuilder` constructors. | ||
|
||
## 1.0.0-beta+5 | ||
|
||
- Re-published the package without merge conflicts. | ||
* Re-published the package without merge conflicts. | ||
|
||
## 1.0.0-beta+4 | ||
|
||
- Renamed `PartBuilder` to `PartOfBuilder`. | ||
- Added a new class, `PartBuilder`, to represent `part '...dart'` directives. | ||
- Added the `HasAnnotations` interface to all library/part/directive builders. | ||
- Added `asFactory` and `asConst` to `ConstructorBuilder`. | ||
- Added `ConstructorBuilder.redirectTo` for a redirecting factory constructor. | ||
- Added a `name` getter to `ReferenceBuilder`. | ||
- Supplying an empty constructor name (`''`) is equivalent to `null` (default). | ||
- Automatically encodes string literals with multiple lines as `'''`. | ||
- Added `asThrow` to `ExpressionBuilder`. | ||
- Fixed a bug that prevented `FieldBuilder` from being used at the top-level. | ||
* Renamed `PartBuilder` to `PartOfBuilder`. | ||
* Added a new class, `PartBuilder`, to represent `part '...dart'` directives. | ||
* Added the `HasAnnotations` interface to all library/part/directive builders. | ||
* Added `asFactory` and `asConst` to `ConstructorBuilder`. | ||
* Added `ConstructorBuilder.redirectTo` for a redirecting factory constructor. | ||
* Added a `name` getter to `ReferenceBuilder`. | ||
* Supplying an empty constructor name (`''`) is equivalent to `null` (default). | ||
* Automatically encodes string literals with multiple lines as `'''`. | ||
* Added `asThrow` to `ExpressionBuilder`. | ||
* Fixed a bug that prevented `FieldBuilder` from being used at the top-level. | ||
|
||
## 1.0.0-beta+3 | ||
|
||
- Added support for `genericTypes` parameter for `ExpressionBuilder#invoke`: | ||
* Added support for `genericTypes` parameter for `ExpressionBuilder#invoke`: | ||
|
||
```dart | ||
expect( | ||
|
@@ -650,7 +698,7 @@ expect( | |
); | ||
``` | ||
|
||
- Added a `castAs` method to `ExpressionBuilder`: | ||
* Added a `castAs` method to `ExpressionBuilder`: | ||
|
||
```dart | ||
expect( | ||
|
@@ -663,7 +711,7 @@ expect( | |
|
||
### BREAKING CHANGES | ||
|
||
- Removed `namedNewInstance` and `namedConstInstance`, replaced with `constructor: `: | ||
* Removed `namedNewInstance` and `namedConstInstance`, replaced with `constructor:`: | ||
|
||
```dart | ||
expect( | ||
|
@@ -674,7 +722,7 @@ expect( | |
); | ||
``` | ||
|
||
- Renamed `named` parameter to `namedArguments`: | ||
* Renamed `named` parameter to `namedArguments`: | ||
|
||
```dart | ||
expect( | ||
|
@@ -696,25 +744,25 @@ expect( | |
|
||
Avoid creating symbols that can collide with the Dart language: | ||
|
||
- `MethodModifier.async` -> `MethodModifier.asAsync` | ||
- `MethodModifier.asyncStar` -> `MethodModifier.asAsyncStar` | ||
- `MethodModifier.syncStar` -> `MethodModifier.asSyncStar` | ||
* `MethodModifier.async` -> `MethodModifier.asAsync` | ||
* `MethodModifier.asyncStar` -> `MethodModifier.asAsyncStar` | ||
* `MethodModifier.syncStar` -> `MethodModifier.asSyncStar` | ||
|
||
## 1.0.0-beta+1 | ||
|
||
- Add support for `switch` statements | ||
- Add support for a raw expression and statement | ||
- `new ExpressionBuilder.raw(...)` | ||
- `new StatemnetBuilder.raw(...)` | ||
* Add support for `switch` statements | ||
* Add support for a raw expression and statement | ||
* `new ExpressionBuilder.raw(...)` | ||
* `new StatementBuilder.raw(...)` | ||
|
||
This should help cover any cases not covered with builders today. | ||
|
||
- Allow referring to a `ClassBuilder` and `TypeBuilder` as an expression | ||
- Add support for accessing the index `[]` operator on an expression | ||
* Allow referring to a `ClassBuilder` and `TypeBuilder` as an expression | ||
* Add support for accessing the index `[]` operator on an expression | ||
|
||
### BREAKING CHANGES | ||
|
||
- Changed `ExpressionBuilder.asAssign` to always take an `ExpressionBuilder` as | ||
* Changed `ExpressionBuilder.asAssign` to always take an `ExpressionBuilder` as | ||
target and removed the `value` property. Most changes are pretty simple, and | ||
involve just using `reference(...)`. For example: | ||
|
||
|
@@ -726,34 +774,34 @@ literal(true).asAssign(reference('flag')) | |
|
||
## 1.0.0-beta | ||
|
||
- Add support for `async`, `sync`, `sync*` functions | ||
- Add support for expression `asAwait`, `asYield`, `asYieldStar` | ||
- Add `toExportBuilder` and `toImportBuilder` to types and references | ||
- Fix an import scoping bug in `return` statements and named constructor invocations. | ||
- Added constructor initializer support | ||
- Add `while` and `do {} while` loop support | ||
- Add `for` and `for-in` support | ||
- Added a `name` getter for `ParameterBuilder` | ||
* Add support for `async`, `sync`, `sync*` functions | ||
* Add support for expression `asAwait`, `asYield`, `asYieldStar` | ||
* Add `toExportBuilder` and `toImportBuilder` to types and references | ||
* Fix an import scoping bug in `return` statements and named constructor invocations. | ||
* Added constructor initializer support | ||
* Add `while` and `do {} while` loop support | ||
* Add `for` and `for-in` support | ||
* Added a `name` getter for `ParameterBuilder` | ||
|
||
## 1.0.0-alpha+7 | ||
|
||
- Make use of the new analyzer APIs in preparation for analyzer version 0.30. | ||
* Make use of the new analyzer APIs in preparation for analyzer version 0.30. | ||
|
||
## 1.0.0-alpha+6 | ||
|
||
- `MethodBuilder.closure` emits properly as a top-level function | ||
* `MethodBuilder.closure` emits properly as a top-level function | ||
|
||
## 1.0.0-alpha+5 | ||
|
||
- MethodBuilder with no statements will create an empty block instead of | ||
* MethodBuilder with no statements will create an empty block instead of | ||
a semicolon. | ||
|
||
```dart | ||
// main() {} | ||
method('main') | ||
``` | ||
|
||
- Fix lambdas and closures to not include a trailing semicolon when used | ||
* Fix lambdas and closures to not include a trailing semicolon when used | ||
as an expression. | ||
|
||
```dart | ||
|
@@ -763,29 +811,29 @@ method('main') | |
|
||
## 1.0.0-alpha+4 | ||
|
||
- Add support for the latest `pkg/analyzer`. | ||
* Add support for the latest `pkg/analyzer`. | ||
|
||
## 1.0.0-alpha+3 | ||
|
||
- BREAKING CHANGE: Added generics support to `TypeBuilder`: | ||
* BREAKING CHANGE: Added generics support to `TypeBuilder`: | ||
|
||
`importFrom` becomes a _named_, not a positional argument, and the named | ||
`importFrom` becomes a *named*, not a positional argument, and the named | ||
argument `genericTypes` is added (`Iterable<TypeBuilder>`). | ||
|
||
```dart | ||
// List<String> | ||
new TypeBuilder('List', genericTypes: [reference('String')]) | ||
``` | ||
|
||
- Added generic support to `ReferenceBuilder`: | ||
* Added generic support to `ReferenceBuilder`: | ||
|
||
```dart | ||
// List<String> | ||
reference('List').toTyped([reference('String')]) | ||
``` | ||
|
||
- Fixed a bug where `ReferenceBuilder.buildAst` was not implemented | ||
- Added `and` and `or` methods to `ExpressionBuilder`: | ||
* Fixed a bug where `ReferenceBuilder.buildAst` was not implemented | ||
* Added `and` and `or` methods to `ExpressionBuilder`: | ||
|
||
```dart | ||
// true || false | ||
|
@@ -795,7 +843,7 @@ literal(true).or(literal(false)); | |
literal(true).and(literal(false)); | ||
``` | ||
|
||
- Added support for creating closures - `MethodBuilder.closure`: | ||
* Added support for creating closures - `MethodBuilder.closure`: | ||
|
||
```dart | ||
// () => true | ||
|
@@ -807,21 +855,21 @@ new MethodBuilder.closure( | |
|
||
## 1.0.0-alpha+2 | ||
|
||
- Added `returnVoid` to well, `return;` | ||
- Added support for top-level field assignments: | ||
* Added `returnVoid` to well, `return;` | ||
* Added support for top-level field assignments: | ||
|
||
```dart | ||
new LibraryBuilder()..addMember(literal(false).asConst('foo')) | ||
``` | ||
|
||
- Added support for specifying a `target` when using `asAssign`: | ||
* Added support for specifying a `target` when using `asAssign`: | ||
|
||
```dart | ||
// Outputs bank.bar = goldBar | ||
reference('goldBar').asAssign('bar', target: reference('bank')) | ||
``` | ||
|
||
- Added support for the cascade operator: | ||
* Added support for the cascade operator: | ||
|
||
```dart | ||
// Outputs foo..doThis()..doThat() | ||
|
@@ -831,7 +879,7 @@ reference('foo').cascade((c) => <ExpressionBuilder> [ | |
]); | ||
``` | ||
|
||
- Added support for accessing a property | ||
* Added support for accessing a property | ||
|
||
```dart | ||
// foo.bar | ||
|
@@ -840,25 +888,25 @@ reference('foo').property('bar'); | |
|
||
## 1.0.0-alpha+1 | ||
|
||
- Slight updates to confusing documentation. | ||
- Added support for null-aware assignments. | ||
- Added `show` and `hide` support to `ImportBuilder` | ||
- Added `deferred` support to `ImportBuilder` | ||
- Added `ExportBuilder` | ||
- Added `list` and `map` literals that support generic types | ||
* Slight updates to confusing documentation. | ||
* Added support for null-aware assignments. | ||
* Added `show` and `hide` support to `ImportBuilder` | ||
* Added `deferred` support to `ImportBuilder` | ||
* Added `ExportBuilder` | ||
* Added `list` and `map` literals that support generic types | ||
|
||
## 1.0.0-alpha | ||
|
||
- Large refactor that makes the library more feature complete. | ||
* Large refactor that makes the library more feature complete. | ||
|
||
## 0.1.1 | ||
|
||
- Add the concept of `Scope` and change `toAst` to support it | ||
* Add the concept of `Scope` and change `toAst` to support it | ||
|
||
Now your entire AST tree can be scoped and import directives | ||
automatically added to a `LibraryBuilder` for you if you use | ||
`LibraryBuilder.scope`. | ||
|
||
## 0.1.0 | ||
|
||
- Initial version | ||
* Initial version |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.