示例#1
0
文件: type.go 项目: kiljacken/ark
func (v *Codegen) addNamedTypeReference(n *ast.TypeReference, gcon *ast.GenericContext) {
	outer := gcon
	gcon = ast.NewGenericContextFromTypeReference(n)
	gcon.Outer = outer

	v.addNamedType(n.BaseType.(*ast.NamedType), ast.TypeReferenceMangledName(ast.MANGLE_ARK_UNSTABLE, n, gcon), gcon)
}
示例#2
0
文件: type.go 项目: kiljacken/ark
// if outer is not nil, this function does not add the current function gcon as outer, as it assumes it is already there
func (v *Codegen) typeRefToLLVMTypeWithOuter(typ *ast.TypeReference, outer *ast.GenericContext) llvm.Type {
	var gcon *ast.GenericContext
	if len(typ.GenericArguments) > 0 {
		gcon = ast.NewGenericContextFromTypeReference(typ)
	} else {
		gcon = ast.NewGenericContext(nil, nil)
	}

	if outer != nil {
		gcon.Outer = outer
	} else if v.inFunction() {
		gcon.Outer = v.currentFunction().gcon
	}

	return v.typeRefToLLVMTypeWithGenericContext(typ, gcon)
}
示例#3
0
文件: type.go 项目: kiljacken/ark
func (v *TypeCheck) CheckCompositeLiteral(s *SemanticAnalyzer, lit *ast.CompositeLiteral) {
	gcon := ast.NewGenericContext([]*ast.SubstitutionType{}, []*ast.TypeReference{})
	if len(lit.Type.GenericArguments) > 0 {
		gcon = ast.NewGenericContextFromTypeReference(lit.Type)
	}

	switch typ := lit.Type.BaseType.ActualType().(type) {
	case ast.ArrayType:
		memType := typ.MemberType
		for i, mem := range lit.Values {
			expectType(s, mem, memType, &mem)

			if lit.Fields[i] != "" {
				s.Err(mem, "Unexpected field in array literal: `%s`", lit.Fields[i])
			}
		}

	case ast.StructType:
		for i, mem := range lit.Values {
			name := lit.Fields[i]

			if name == "" {
				s.Err(mem, "Missing field in struct literal")
				continue
			}

			sMem := typ.GetMember(name)
			if sMem == nil {
				s.Err(lit, "No member named `%s` on struct of type `%s`", name, typ.String())
			}

			sMemType := gcon.Replace(sMem.Type)
			expectType(s, mem, sMemType, &mem)
		}

	default:
		panic("composite literal has neither struct nor array type")
	}
}