Class SourceEmitter

    • Constructor Detail

      • SourceEmitter

        public SourceEmitter​(IndentingWriter writer)
        Creates an emitter with the default configuration.
        Parameters:
        writer - the output writer
      • SourceEmitter

        public SourceEmitter​(IndentingWriter writer,
                             SourceEmitterConfig config)
        Creates an emitter with the given configuration.
        Parameters:
        writer - the output writer
        config - emission options
    • Method Detail

      • getUsedTypes

        public Set<String> getUsedTypes()
        Returns:
        the used types
      • clearUsedTypes

        public void clearUsedTypes()
        Clears the record of types referenced during emission.
      • setCurrentClassName

        public void setCurrentClassName​(String className)
        Sets the name of the class currently being emitted.
        Parameters:
        className - the class name
      • setLineMapSink

        public void setLineMapSink​(String baseMethodKey,
                                   SourceEmitter.LineMapSink sink)
        Registers a sink for the 1-based output line each provenance-carrying statement starts on.
        Parameters:
        baseMethodKey - key of the method being emitted.
        sink - receives each statement and its start line, skipping offsets whose owning method cannot be identified
      • emit

        public static String emit​(Statement stmt)
        Emits a statement to source text with the default configuration.
        Parameters:
        stmt - the statement to emit
        Returns:
        the emitted source text
      • emit

        public static String emit​(Statement stmt,
                                  SourceEmitterConfig config)
        Emits a statement to source text.
        Parameters:
        stmt - the statement to emit
        config - emission options
        Returns:
        the emitted source text
      • emit

        public static String emit​(Expression expr)
        Emits an expression to source text with the default configuration.
        Parameters:
        expr - the expression to emit
        Returns:
        the emitted source text
      • emit

        public static String emit​(CompilationUnit cu)
        Emits a compilation unit to source text with the default configuration.
        Parameters:
        cu - the compilation unit to emit
        Returns:
        the emitted source text
      • emit

        public static String emit​(CompilationUnit cu,
                                  SourceEmitterConfig config)
        Emits a compilation unit to source text.
        Parameters:
        cu - the compilation unit to emit
        config - emission options
        Returns:
        the emitted source text
      • visitImportDecl

        public Void visitImportDecl​(ImportDecl decl)
        Description copied from interface: SourceVisitor
        Visits an import declaration.
        Specified by:
        visitImportDecl in interface SourceVisitor<Void>
        Parameters:
        decl - the declaration node
        Returns:
        the visitor's result, null unless overridden
      • visitClassDecl

        public Void visitClassDecl​(ClassDecl decl)
        Description copied from interface: SourceVisitor
        Visits a class declaration.
        Specified by:
        visitClassDecl in interface SourceVisitor<Void>
        Parameters:
        decl - the declaration node
        Returns:
        the visitor's result, null unless overridden
      • visitEnumDecl

        public Void visitEnumDecl​(EnumDecl decl)
        Description copied from interface: SourceVisitor
        Visits an enum declaration.
        Specified by:
        visitEnumDecl in interface SourceVisitor<Void>
        Parameters:
        decl - the declaration node
        Returns:
        the visitor's result, null unless overridden
      • visitMethodDecl

        public Void visitMethodDecl​(MethodDecl decl)
        Description copied from interface: SourceVisitor
        Visits a method declaration.
        Specified by:
        visitMethodDecl in interface SourceVisitor<Void>
        Parameters:
        decl - the declaration node
        Returns:
        the visitor's result, null unless overridden
      • visitFieldDecl

        public Void visitFieldDecl​(FieldDecl decl)
        Description copied from interface: SourceVisitor
        Visits a field declaration.
        Specified by:
        visitFieldDecl in interface SourceVisitor<Void>
        Parameters:
        decl - the declaration node
        Returns:
        the visitor's result, null unless overridden
      • visitParameterDecl

        public Void visitParameterDecl​(ParameterDecl decl)
        Description copied from interface: SourceVisitor
        Visits a method or constructor parameter.
        Specified by:
        visitParameterDecl in interface SourceVisitor<Void>
        Parameters:
        decl - the declaration node
        Returns:
        the visitor's result, null unless overridden
      • visitIf

        public Void visitIf​(IfStmt stmt)
        Description copied from interface: SourceVisitor
        Visits an if statement.
        Specified by:
        visitIf in interface SourceVisitor<Void>
        Parameters:
        stmt - the statement node
        Returns:
        the visitor's result
      • visitFor

        public Void visitFor​(ForStmt stmt)
        Description copied from interface: SourceVisitor
        Visits a counted for loop.
        Specified by:
        visitFor in interface SourceVisitor<Void>
        Parameters:
        stmt - the statement node
        Returns:
        the visitor's result
      • visitTryCatch

        public Void visitTryCatch​(TryCatchStmt stmt)
        Description copied from interface: SourceVisitor
        Visits a try statement, with its catch clauses and finally block.
        Specified by:
        visitTryCatch in interface SourceVisitor<Void>
        Parameters:
        stmt - the statement node
        Returns:
        the visitor's result
      • setParameterNames

        public void setParameterNames​(Collection<String> names)
        Seeds the shadow scope with the emitting method's parameter names (block-emission path).
        Parameters:
        names - the names to treat as already in scope, replacing any previous set
      • visitExprStmt

        public Void visitExprStmt​(ExprStmt stmt)
        Description copied from interface: SourceVisitor
        Visits an expression used as a statement.
        Specified by:
        visitExprStmt in interface SourceVisitor<Void>
        Parameters:
        stmt - the statement node
        Returns:
        the visitor's result
      • visitIRRegion

        public Void visitIRRegion​(IRRegionStmt stmt)
        Description copied from interface: SourceVisitor
        Visits a region of control flow that stayed in IR form because it could not be structured.
        Specified by:
        visitIRRegion in interface SourceVisitor<Void>
        Parameters:
        stmt - the statement node
        Returns:
        the visitor's result
      • visitNew

        public Void visitNew​(NewExpr expr)
        Description copied from interface: SourceVisitor
        Visits an object allocation.
        Specified by:
        visitNew in interface SourceVisitor<Void>
        Parameters:
        expr - the expression node
        Returns:
        the visitor's result
      • visitSwitchExpr

        public Void visitSwitchExpr​(SwitchExpr expr)
        Description copied from interface: SourceVisitor
        Default so existing visitors need no change; only the source emitter overrides it.
        Specified by:
        visitSwitchExpr in interface SourceVisitor<Void>
        Parameters:
        expr - the switch expression to visit
        Returns:
        the visitor result, null unless overridden
      • visitThis

        public Void visitThis​(ThisExpr expr)
        Description copied from interface: SourceVisitor
        Visits a this reference.
        Specified by:
        visitThis in interface SourceVisitor<Void>
        Parameters:
        expr - the expression node
        Returns:
        the visitor's result