1 // unsafe.cc -- Go frontend builtin unsafe package.
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
13 // Set up the builtin unsafe package. This should probably be driven
17 Gogo::import_unsafe(const std::string
& local_name
, bool is_local_name_exported
,
20 Location bloc
= Linemap::predeclared_location();
23 Package
* package
= this->add_imported_package("unsafe", local_name
,
24 is_local_name_exported
,
30 go_assert(saw_errors());
34 package
->set_location(location
);
35 package
->set_is_imported();
37 this->imports_
.insert(std::make_pair("unsafe", package
));
39 Bindings
* bindings
= package
->bindings();
41 // The type may have already been created by an import.
42 Named_object
* no
= package
->bindings()->lookup("Pointer");
45 Type
* type
= Type::make_pointer_type(Type::make_void_type());
46 no
= bindings
->add_type("Pointer", package
, type
,
47 Linemap::unknown_location());
51 go_assert(no
->package() == package
);
52 go_assert(no
->is_type());
53 go_assert(no
->type_value()->is_unsafe_pointer_type());
54 no
->type_value()->set_is_visible();
56 Named_type
* pointer_type
= no
->type_value();
58 this->add_named_type(pointer_type
);
60 Type
* uintptr_type
= Type::lookup_integer_type("uintptr");
63 Typed_identifier_list
* results
= new Typed_identifier_list
;
64 results
->push_back(Typed_identifier("", uintptr_type
, bloc
));
65 Function_type
* fntype
= Type::make_function_type(NULL
, NULL
, results
, bloc
);
66 fntype
->set_is_builtin();
67 no
= bindings
->add_function_declaration("Sizeof", package
, fntype
, bloc
);
69 this->add_named_object(no
);
72 results
= new Typed_identifier_list
;
73 results
->push_back(Typed_identifier("", uintptr_type
, bloc
));
74 fntype
= Type::make_function_type(NULL
, NULL
, results
, bloc
);
75 fntype
->set_is_varargs();
76 fntype
->set_is_builtin();
77 no
= bindings
->add_function_declaration("Offsetof", package
, fntype
, bloc
);
79 this->add_named_object(no
);
82 results
= new Typed_identifier_list
;
83 results
->push_back(Typed_identifier("", uintptr_type
, bloc
));
84 fntype
= Type::make_function_type(NULL
, NULL
, results
, bloc
);
85 fntype
->set_is_varargs();
86 fntype
->set_is_builtin();
87 no
= bindings
->add_function_declaration("Alignof", package
, fntype
, bloc
);
89 this->add_named_object(no
);
91 if (!this->imported_unsafe_
)
94 this->imported_unsafe_
= true;