Пример #1
0
func (parser *Parser) parseMethodDecl(contract *ast.Contract) bool {
	for parser.parseAnnotation() {

	}

	token := parser.peek()

	if token.Type != lexer.TokenType('}') {

		returnVal := parser.expectTypeDecl("expect method return type")

		tokenName := parser.expectf(lexer.TokenID, "expect method name")

		name := tokenName.Value.(string)

		parser.D("parse method %s", name)

		method, ok := contract.NewMethod(name)

		if !ok {
			parser.errorf(token.Start, "duplicate contract(%s) field(%s)", contract, name)
		}

		parser.attachAnnotation(method)

		method.Return = returnVal

		parser.parseParams(method)

		parser.parseExceptions(method)

		end := parser.expectf(lexer.TokenType(';'), "expect method name").End

		_setNodePos(method, token.Start, end)

		parser.attachComment(method)

		return true
	}

	return false
}
Пример #2
0
func (codegen *_CodeGen) Contract(compiler *gslang.Compiler, contract *ast.Contract) {

	var buff bytes.Buffer

	if err := codegen.tpl.ExecuteTemplate(&buff, "contract", contract); err != nil {
		gserrors.Panicf(err, "exec template(contract) for %s error", contract)
	}

	codegen.writeJavaFile(contract.Name(), contract, buff.Bytes())

	buff.Reset()

	if err := codegen.tpl.ExecuteTemplate(&buff, "dispatcher", contract); err != nil {
		gserrors.Panicf(err, "exec template(contract) for %s error", contract)
	}

	codegen.writeJavaFile(contract.Name()+"Dispatcher", contract, buff.Bytes())

	buff.Reset()

	if err := codegen.tpl.ExecuteTemplate(&buff, "rpc", contract); err != nil {
		gserrors.Panicf(err, "exec template(contract) for %s error", contract)
	}

	codegen.writeJavaFile(contract.Name()+"RPC", contract, buff.Bytes())
}