compiler: fix interface generation for unused interfaces
							parent
							
								
									00b8a5d3e4
								
							
						
					
					
						commit
						b62e28dba5
					
				|  | @ -462,25 +462,34 @@ fn (v &V) interface_table() string { | |||
| 		if t.cat != .interface_ { | ||||
| 			continue | ||||
| 		} | ||||
| 		interface_name := t.name | ||||
| 		mut methods := '' | ||||
| 		sb.writeln('// NR methods = $t.gen_types.len') | ||||
| 		for i, gen_type in t.gen_types { | ||||
| 			methods += '{' | ||||
| 			gen_concrete_type_name := gen_type.replace('*', '') | ||||
| 			methods += '{\n' | ||||
| 			for j, method in t.methods { | ||||
| 				// Cat_speak
 | ||||
| 				methods += '${gen_type}_${method.name}' | ||||
| 				methods += ' (void*)    ${gen_concrete_type_name}_${method.name}' | ||||
| 				if j < t.methods.len - 1 { | ||||
| 					methods += ', ' | ||||
| 					methods += ', \n' | ||||
| 				} | ||||
| 			} | ||||
| 			methods += '}, ' | ||||
| 			// Speaker_Cat_index = 0
 | ||||
| 			sb.writeln('int _${t.name}_${gen_type}_index = $i;') | ||||
| 			methods += '\n},\n\n' | ||||
| 			// Speaker_Cat_index = 0      
 | ||||
| 			concrete_type_name := gen_type.replace('*', '_ptr')			 | ||||
| 			sb.writeln('int _${interface_name}_${concrete_type_name}_index = $i;') | ||||
| 		} | ||||
| 		 | ||||
| 		if t.gen_types.len > 0 { | ||||
| 			// methods = '{TCCSKIP(0)}'
 | ||||
| 			// }
 | ||||
| 			sb.writeln('void* (* ${t.name}_name_table[][$t.methods.len]) = ' + '{ $methods }; ') | ||||
| 			sb.writeln('void* (* ${interface_name}_name_table[][$t.methods.len]) = ' + '{ \n $methods \n }; ') | ||||
| 		}else{ | ||||
| 			// The line below is needed so that C compilation succeeds,
 | ||||
| 			// even if no interface methods are called.
 | ||||
| 			// See https://github.com/zenith391/vgtk3/issues/7
 | ||||
| 			sb.writeln('void* (* ${interface_name}_name_table[][1]) = ' + '{ {NULL} }; ') | ||||
| 		} | ||||
| 		continue | ||||
| 	} | ||||
|  |  | |||
|  | @ -1019,18 +1019,18 @@ fn (p mut Parser) fn_call_args(f mut Fn) { | |||
| 			// if f.args[0].typ.ends_with('*') {
 | ||||
| 			// p.gen('&/*119*/')
 | ||||
| 			// }
 | ||||
| 			/* | ||||
| 			pos := p.cgen.cur_line.index('/* ? */') | ||||
| 			if pos > -1 { | ||||
| 				expr := p.cgen.cur_line[pos..] | ||||
| 				// TODO hack
 | ||||
| 				// If current expression is a func call, generate the array hack
 | ||||
| 				if expr.contains('(') { | ||||
| 					p.cgen.set_placeholder(pos, '(${arg.typ[..arg.typ.len-1]}[]){') | ||||
| 					p.gen('}[0] ') | ||||
| 				} | ||||
| 			} | ||||
| 			*/ | ||||
| 
 | ||||
| 			//pos := p.cgen.cur_line.index('/* ? */')
 | ||||
| 			//if pos > -1 {
 | ||||
| 			//	expr := p.cgen.cur_line[pos..]
 | ||||
| 			//	// TODO hack
 | ||||
| 			//	// If current expression is a func call, generate the array hack
 | ||||
| 			//	if expr.contains('(') {
 | ||||
| 			//		p.cgen.set_placeholder(pos, '(${arg.typ[..arg.typ.len-1]}[]){')
 | ||||
| 			//		p.gen('}[0] ')
 | ||||
| 			//	}
 | ||||
| 			//}
 | ||||
| 			 | ||||
| 
 | ||||
| 			continue | ||||
| 		} | ||||
|  | @ -1082,8 +1082,9 @@ fn (p mut Parser) fn_call_args(f mut Fn) { | |||
| 			if t.cat == .interface_ { | ||||
| 				// perform((Speaker) { ._object = &dog,
 | ||||
| 				// _interface_idx = _Speaker_Dog_index })
 | ||||
| 				concrete_type_name := typ.replace('*', '_ptr') | ||||
| 				p.cgen.set_placeholder(ph, '($arg.typ) { ._object = &') | ||||
| 				p.gen(', ._interface_idx = _${arg.typ}_${typ}_index} /* i. arg*/') | ||||
| 				p.gen(', ._interface_idx = _${arg.typ}_${concrete_type_name}_index} /* i. arg*/') | ||||
| 				p.table.add_gen_type(arg.typ, typ) | ||||
| 			} | ||||
| 		} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue