WriteType appends the string representation of n to the Printer's buffer.
(n semantic.Type)
| 286 | |
| 287 | // WriteType appends the string representation of n to the Printer's buffer. |
| 288 | func (p *Printer) WriteType(n semantic.Type) *Printer { |
| 289 | switch n := n.(type) { |
| 290 | case *semantic.Builtin: |
| 291 | p.WriteString(n.Name()) |
| 292 | case *semantic.Class: |
| 293 | p.WriteString(n.Name()) |
| 294 | case *semantic.Enum: |
| 295 | p.WriteString(n.Name()) |
| 296 | case *semantic.Pointer: |
| 297 | if n.Const { |
| 298 | p.WriteString("const ") |
| 299 | } |
| 300 | p.WriteType(n.To) |
| 301 | p.WriteRune('*') |
| 302 | case *semantic.Pseudonym: |
| 303 | p.WriteString(n.Name()) |
| 304 | case *semantic.Slice: |
| 305 | p.WriteType(n.To) |
| 306 | p.WriteString("[]") |
| 307 | case *semantic.Signature: |
| 308 | p.WriteType(n.Return) |
| 309 | p.WriteRune(' ') |
| 310 | p.WriteString(n.Name()) |
| 311 | p.WriteRune('(') |
| 312 | p.list(n.Arguments, func(ty semantic.Type) { |
| 313 | p.WriteType(ty) |
| 314 | }) |
| 315 | p.WriteString(")") |
| 316 | case *semantic.StaticArray: |
| 317 | p.WriteType(n.ValueType) |
| 318 | p.WriteRune('[') |
| 319 | p.WriteString(strconv.Itoa(int(n.Size))) |
| 320 | p.WriteRune(']') |
| 321 | case *semantic.Map: |
| 322 | p.WriteString("map!(") |
| 323 | p.WriteType(n.KeyType) |
| 324 | p.WriteString(", ") |
| 325 | p.WriteType(n.ValueType) |
| 326 | p.WriteRune(')') |
| 327 | case *semantic.Reference: |
| 328 | p.WriteString("ref!") |
| 329 | p.WriteType(n.To) |
| 330 | default: |
| 331 | panic(fmt.Sprintf("Unknown type: %T", n)) |
| 332 | } |
| 333 | return p |
| 334 | } |
| 335 | |
| 336 | func (p *Printer) function(f *semantic.Function) { |
| 337 | p.WriteString(f.Name()) |
no test coverage detected