Beispiel #1
0
func (codegen *_CodeGen) enumWrite(typeDecl ast.Type) string {
	_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

	if ok {
		return fmt.Sprintf("[%s:(UInt32) val]", writeMapping[lexer.KeyUInt32])
	}

	return fmt.Sprintf("[%s:(UInt8) val]", writeMapping[lexer.KeyByte])
}
Beispiel #2
0
func (codegen *_CodeGen) enumRead(typeDecl ast.Type) string {
	_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

	if ok {
		return fmt.Sprintf("[%s]", readMapping[lexer.KeyUInt32])
	}

	return fmt.Sprintf("[%s]", readMapping[lexer.KeyByte])
}
Beispiel #3
0
func enumType(typeDecl ast.Type) string {
	_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

	if !ok {
		return builtin[lexer.KeyUInt32]
	}

	return builtin[lexer.KeyByte]
}
Beispiel #4
0
func (codegen *_CodeGen) enumSize(typeDecl ast.Type) int {
	_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

	if ok {
		return 4
	}

	return 1
}
Beispiel #5
0
func (codegen *_CodeGen) tagValue(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		switch builtinType.Type {
		case lexer.KeySByte, lexer.KeyByte, lexer.KeyBool:
			return "GSTagI8"
		case lexer.KeyInt16, lexer.KeyUInt16:
			return "GSTagI16"
		case lexer.KeyInt32, lexer.KeyUInt32, lexer.KeyFloat32:
			return "GSTagI32"
		case lexer.KeyInt64, lexer.KeyUInt64, lexer.KeyFloat64:
			return "GSTagI64"
		case lexer.KeyString:
			return "GSTagString"
		}

	case *ast.TypeRef:
		return codegen.tagValue(typeDecl.(*ast.TypeRef).Ref)
	case *ast.Enum:

		_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

		if !ok {
			return "GSTagI32"
		}

		return "GSTagI8"

	case *ast.Table:
		return "GSTagTable"
	case *ast.Seq:

		seq := typeDecl.(*ast.Seq)

		component := codegen.tagValue(seq.Component)

		if component == "GSTagList" {
			start, _ := gslang.Pos(typeDecl)
			gserrors.Panicf(nil, "list component %v can't be a list :%v", seq.Component, start)
		}

		return fmt.Sprintf("((%s << 4)|GSTagList)", component)
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return ""
}
Beispiel #6
0
func (codegen *_CodeGen) Using(compiler *gslang.Compiler, using *ast.Using) {

	nodes := strings.Split(using.Name(), ".")

	_, ok := gslang.FindAnnotation(using.Ref, "gslang.Exception")

	name := using.Name()

	if ok {
		name = strings.Join(nodes[:len(nodes)-1], ".") + "." + exception(nodes[len(nodes)-1])
	}

	codegen.imports[nodes[len(nodes)-1]] = "import " + name
}