| 168 | } |
| 169 | |
| 170 | func NewPrinter(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext) *Printer { |
| 171 | printer := &Printer{ |
| 172 | PrintHandlers: handlers, |
| 173 | Options: options, |
| 174 | emitContext: emitContext, |
| 175 | } |
| 176 | // wire up name generator |
| 177 | if printer.emitContext == nil { |
| 178 | printer.emitContext = NewEmitContext() |
| 179 | } |
| 180 | printer.nameGenerator.Context = printer.emitContext |
| 181 | printer.nameGenerator.GetTextOfNode = func(node *ast.Node) string { return printer.getTextOfNode(node, false) } |
| 182 | printer.nameGenerator.IsFileLevelUniqueNameInCurrentFile = printer.isFileLevelUniqueNameInCurrentFile |
| 183 | printer.makeFileLevelOptimisticUniqueName = func(name string) string { |
| 184 | return printer.nameGenerator.MakeFileLevelOptimisticUniqueName(name) |
| 185 | } |
| 186 | printer.containerPos = -1 |
| 187 | printer.containerEnd = -1 |
| 188 | printer.declarationListContainerEnd = -1 |
| 189 | printer.commentsDisabled = options.RemoveComments |
| 190 | return printer |
| 191 | } |
| 192 | |
| 193 | func (p *Printer) getLiteralTextOfNode(node *ast.LiteralLikeNode, sourceFile *ast.SourceFile, flags getLiteralTextFlags) string { |
| 194 | if ast.IsStringLiteral(node) { |