refactor: [wasm] move compile to wadapter

上级 4852578e
......@@ -68,6 +68,6 @@ coca_reporter
bug
_fixtures/tbs/tbs
_fixtures/refactor/move/b/ImportForB.java
!wasm/web
wasm/web/coca.wasm
!wasm/demo
wasm/demo/coca.wasm
coverage.txt
......@@ -2,13 +2,8 @@ package main
import (
"encoding/json"
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca_file"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/full"
"github.com/phodal/coca/core/infrastructure/ast/identifier"
"syscall/js"
"wasm/wadapter"
)
func registerCallbacks() {
......@@ -25,49 +20,10 @@ func CompileCodeCallback(value js.Value, args []js.Value) interface{} {
callback := args[len(args)-1:][0]
message := args[0].String()
results := CompileCode(message)
results := wadapter.CompileCode(message)
identModel, _ := json.Marshal(results)
callback.Invoke(js.Null(), string(identModel))
return nil
}
func CompileCode(code string) []domain.JClassNode {
classes, identMap := prepareForAnalysis(code)
parser := coca_file.ProcessString(code)
context := parser.CompilationUnit()
listener := full.NewJavaFullListener(identMap, "hello")
listener.AppendClasses(classes)
antlr.NewParseTreeWalker().Walk(listener, context)
nodes := listener.GetNodeInfo()
fmt.Println(nodes)
return nodes
}
func prepareForAnalysis(code string) ([]string, map[string]domain.JIdentifier) {
parser := coca_file.ProcessString(code)
context := parser.CompilationUnit()
listener := identifier.NewJavaIdentifierListener()
antlr.NewParseTreeWalker().Walk(listener, context)
identifiers := listener.GetNodes()
var classes []string = nil
for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName)
}
var identMap = make(map[string]domain.JIdentifier)
for _, ident := range identifiers {
identMap[ident.GetClassFullName()] = ident
}
return classes, identMap
}
package wadapter
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/core/adapter/coca_file"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/full"
"github.com/phodal/coca/core/infrastructure/ast/identifier"
)
func CompileCode(code string) []domain.JClassNode {
classes, identMap := prepareForAnalysis(code)
parser := coca_file.ProcessString(code)
context := parser.CompilationUnit()
listener := full.NewJavaFullListener(identMap, "hello")
listener.AppendClasses(classes)
antlr.NewParseTreeWalker().Walk(listener, context)
nodes := listener.GetNodeInfo()
return nodes
}
func prepareForAnalysis(code string) ([]string, map[string]domain.JIdentifier) {
parser := coca_file.ProcessString(code)
context := parser.CompilationUnit()
listener := identifier.NewJavaIdentifierListener()
antlr.NewParseTreeWalker().Walk(listener, context)
identifiers := listener.GetNodes()
var classes []string = nil
for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName)
}
var identMap = make(map[string]domain.JIdentifier)
for _, ident := range identifiers {
identMap[ident.GetClassFullName()] = ident
}
return classes, identMap
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册