Example #1
0
func (v *AttributeCheck) CheckStructType(s *SemanticAnalyzer, n ast.StructType) {
	for _, attr := range n.Attrs() {
		switch attr.Key {
		case "packed":
			if attr.Value != "" {
				s.Err(attr, "Struct attribute `%s` doesn't expect value", attr.Key)
			}
		case "deprecated":
			// value is optional, nothing to check
		default:
			s.Err(attr, "Invalid struct attribute key `%s`", attr.Key)
		}
	}
}
Example #2
0
func (v *Codegen) addStructType(typ ast.StructType, name string, gcon *ast.GenericContext) {
	if _, ok := v.namedTypeLookup[name]; ok {
		return
	}

	structure := v.curFile.LlvmModule.Context().StructCreateNamed(name)

	v.namedTypeLookup[name] = structure

	for _, field := range typ.Members {
		if _, ok := field.Type.BaseType.(*ast.NamedType); ok {
			v.addNamedTypeReference(field.Type, gcon)
		}
	}

	structure.StructSetBody(v.structTypeToLLVMTypeFields(typ, gcon), typ.Attrs().Contains("packed"))
}
Example #3
0
func (v *Codegen) structTypeToLLVMType(typ ast.StructType, gcon *ast.GenericContext) llvm.Type {
	return llvm.StructType(v.structTypeToLLVMTypeFields(typ, gcon), typ.Attrs().Contains("packed"))
}