EncodeSourceFile encodes an entire source file AST into the binary format. Returns the encoded bytes and a NodeIndexTable mapping encoder indices to AST nodes.
(sourceFile *ast.SourceFile)
| 395 | // EncodeSourceFile encodes an entire source file AST into the binary format. |
| 396 | // Returns the encoded bytes and a NodeIndexTable mapping encoder indices to AST nodes. |
| 397 | func EncodeSourceFile(sourceFile *ast.SourceFile) ([]byte, *NodeIndexTable, error) { |
| 398 | data, nodeTable, err := encodeTree(sourceFile.AsNode(), sourceFile) |
| 399 | if err != nil { |
| 400 | return nil, nil, err |
| 401 | } |
| 402 | nodeTable = ast.GetOrComputeSourceFileData(sourceFile, nodeIndexTableKey, func(*ast.SourceFile) *NodeIndexTable { |
| 403 | return nodeTable |
| 404 | }) |
| 405 | return data, nodeTable, nil |
| 406 | } |
| 407 | |
| 408 | // EncodeNode encodes an arbitrary AST node and its descendants into the binary format. |
| 409 | // The sourceFile is needed to provide the source text for efficient string encoding. |