Commit Graph

17 Commits

Author SHA1 Message Date
Anthony Latsis
1001c46e4c ASTDumper: Do not escape Unicode chars in quoted fields
Context: https://github.com/swiftlang/swift/pull/68438#discussion_r1449272860
2024-12-10 12:51:19 +00:00
Becca Royal-Gordon
8770c7f826 Rework ASTDumper (#68438)
This PR refactors the ASTDumper to make it more structured, less mistake-prone, and more amenable to future changes. For example:

```cpp
  // Before:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
    printCommon(E, "unresolved_dot_expr")
      << " field '" << E->getName() << "'";
    PrintWithColorRAII(OS, ExprModifierColor)
      << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind());
    if (E->getBase()) {
      OS << '\n';
      printRec(E->getBase());
    }
    PrintWithColorRAII(OS, ParenthesisColor) << ')';
  }

  // After:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E, StringRef label) {
    printCommon(E, "unresolved_dot_expr", label);

    printFieldQuoted(E->getName(), "field");
    printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor);

    if (E->getBase()) {
      printRec(E->getBase());
    }

    printFoot();
  }
```

* Values are printed through calls to base class methods, rather than direct access to the underlying `raw_ostream`.
    * These methods tend to reduce the chances of bugs like missing/extra spaces or newlines, too much/too little indentation, etc.
    * More values are quoted, and unprintable/non-ASCII characters in quoted values are escaped before printing.
* Infrastructure to label child nodes now exists.
    * Some weird breaks from the normal "style", like `PatternBindingDecl`'s original and processed initializers, have been brought into line.
* Some types that previously used ad-hoc dumping functions, like conformances and substitution maps, are now structured similarly to the dumper classes.
* I've fixed the odd dumping bug along the way. For example, distributed actors were only marked `actor`, not `distributed actor`.

This PR doesn't change the overall style of AST dumps; they're still pseudo-S-expressions. But the logic that implements this style is now isolated into a relatively small base class, making it feasible to introduce e.g. JSON dumping in the future.
2023-09-11 23:56:38 -07:00
Anthony Latsis
ff7f117025 Gardening: Migrate test suite to GH issues: Parse 2022-09-02 01:44:24 +03:00
Michael Verges
75eed47f91 Note for zero-width chars in multiline delimiter
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2020-10-24 00:49:58 -04:00
Michael Verges
d6d01aa85a Consistent comment format for test description 2020-10-23 23:51:47 -04:00
maustinstar
b72fb1c02b Test zero-width chars nested within false delimiter 2020-10-23 23:47:48 -04:00
maustinstar
fe4f7a5f48 Test cases for false multiline delimiters 2020-10-23 17:12:50 -04:00
Vinicius Vendramini
39d3963131 Fix broken tests
- Many tests got broken because of two things:
  - AST dump now outputs to stdout, but many tests expected stderr. This was a straightforward fix.
  - Many tests call swift with specific parameters; specifically, many call `swift frontend` directly. This makes them go through the compiler in unexpected ways, and specifically it makes them not have primary files, which breaks the new AST dump implementation. This commit adds the old implementation as a fallback for those cases, except it dumps to `stdout` to maintain some consistence.

Finally, the `/test/Driver/filelists.swift` failed for unknown reasons. It seems its output now had some lines out of order, and fixing the order made the test pass. However, as the reasons why it failed are unknown, this fix might not have been a good idea. Corrections are welcome.
2018-11-14 13:38:01 -02:00
Rintaro Ishizaki
50497ff5a9 [Lexer] Add a couple of test cases for extended escaping str literal 2018-09-19 18:58:54 +09:00
John Holdsworth
4da8cbe655 Implement SE-0200 (extended escaping in string literals)
Supports string literals like #"foo"\n"bar"#.
2018-09-06 15:19:52 -07:00
Brent Royal-Gordon
df22ea1bfb Revert "[Parse] Implementation for SE-200 (raw strings)" 2018-09-06 12:22:41 -07:00
John Holdsworth
dc96342368 Response to xwu's review 2018-09-02 11:37:02 +01:00
John Holdsworth
032d865fa1 Response to rintaro's 2nd review 2018-08-31 18:51:37 +01:00
John Holdsworth
6bd7cb884c Pragmatic support of multiline/delimited in attributes 2018-08-20 08:43:53 +01:00
John Holdsworth
7866093ea5 Extend token boundary to include delimiter 2018-08-17 02:12:01 +01:00
John Holdsworth
2317048f44 Alternative implementation for raw strings 2018-07-09 18:38:54 +01:00
John Holdsworth
14213b84bd Revised implementation for raw strings 2018-07-02 12:54:06 +01:00