@@ -43,6 +43,7 @@ type FunctionDeclBits struct {
4343 u32 has_return : 1; // if it returns something, set during analysis
4444 u32 is_template : 1;
4545 u32 is_type : 1; // part of FunctionTypeDecl
46+ u32 is_member_type : 1; // if function is defined in struct as member type
4647 u32 has_body : 1; // if function is defined in C2
4748}
4849
@@ -125,16 +126,16 @@ public fn FunctionDecl* FunctionDecl.create(ast_context.Context* c,
125126}
126127
127128public fn FunctionDecl* FunctionDecl.createTemplate(ast_context.Context* c,
128- u32 name,
129- SrcLoc loc,
130- bool is_public,
131- u32 ast_idx,
132- const TypeRefHolder* rtype,
133- u32 template_name,
134- SrcLoc template_loc,
135- VarDecl** params,
136- u32 num_params,
137- bool is_variadic)
129+ u32 name,
130+ SrcLoc loc,
131+ bool is_public,
132+ u32 ast_idx,
133+ const TypeRefHolder* rtype,
134+ u32 template_name,
135+ SrcLoc template_loc,
136+ VarDecl** params,
137+ u32 num_params,
138+ bool is_variadic)
138139{
139140 u32 size = sizeof(FunctionDecl) + num_params * sizeof(VarDecl*) + rtype.getExtraSize();
140141 FunctionDecl* d = c.alloc(size);
@@ -238,6 +239,11 @@ public fn bool FunctionDecl.isInline(const FunctionDecl* d) {
238239 return true;
239240}
240241
242+ public fn bool FunctionDecl.canBeNil(const FunctionDecl* d) {
243+ // Variable with Function type (eg callback)
244+ return d.isType() || d.isMemberType() || d.hasAttrWeak();
245+ }
246+
241247public fn bool FunctionDecl.isType(const FunctionDecl* d) {
242248 return d.base.functionDeclBits.is_type;
243249}
@@ -426,6 +432,14 @@ public fn const char* FunctionDecl.getDiagKind(const FunctionDecl* d) {
426432 return "";
427433}
428434
435+ public fn void FunctionDecl.setMemberType(FunctionDecl* d) {
436+ d.base.functionDeclBits.is_member_type = 1;
437+ }
438+
439+ public fn bool FunctionDecl.isMemberType(const FunctionDecl* d) {
440+ return d.base.functionDeclBits.is_member_type;
441+ }
442+
429443fn void FunctionDecl.print(const FunctionDecl* d, string_buffer.Buf* out, u32 indent) {
430444 bool valid_type = d.base.qt.isValid();
431445 d.base.printKind(out, indent, valid_type);
@@ -441,6 +455,7 @@ fn void FunctionDecl.print(const FunctionDecl* d, string_buffer.Buf* out, u32 in
441455 out.add(callKind_names[d.getCallKind()]);
442456 d.base.printAttrs(out);
443457 if (d.base.functionDeclBits.is_type) out.add(" Type");
458+ if (d.base.functionDeclBits.is_member_type) out.add(" MemberType");
444459 out.color(col_Expr); // purple
445460 if (d.hasAttrUnusedParams()) out.add(" unused-params");
446461 if (d.hasAttrNoReturn()) out.add(" noreturn");
0 commit comments