Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 1865 | |
| 1866 | // Format implements the NodeFormatter interface. |
| 1867 | func (d *DEnum) Format(ctx *FmtCtx) { |
| 1868 | if ctx.HasFlags(fmtStaticallyFormatUserDefinedTypes) { |
| 1869 | s := DBytes(d.PhysicalRep) |
| 1870 | // We use the fmtFormatByteLiterals flag here so that the bytes |
| 1871 | // get formatted as byte literals. Consider an enum of type t with physical |
| 1872 | // representation \x80. If we don't format this as a bytes literal then |
| 1873 | // it gets emitted as '\x80':::t. '\x80' is scanned as a string, and we try |
| 1874 | // to find a logical representation matching '\x80', which won't exist. |
| 1875 | // Instead, we want to emit b'\x80'::: so that '\x80' is scanned as bytes, |
| 1876 | // triggering the logic to cast the bytes \x80 to t. |
| 1877 | ctx.WithFlags(ctx.flags|fmtFormatByteLiterals, func() { |
| 1878 | s.Format(ctx) |
| 1879 | }) |
| 1880 | } else { |
| 1881 | s := DString(d.LogicalRep) |
| 1882 | s.Format(ctx) |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | func (d *DEnum) String() string { |
| 1887 | return AsString(d) |