Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 02295eb

Browse files
committed
[[ ExternalsApiV5 ]] Corrected native code import definitions.
[[ ExternalsApiV5 ]] Corrected errors in Android support functions.
1 parent b50dc7a commit 02295eb

File tree

2 files changed

+163
-36
lines changed

2 files changed

+163
-36
lines changed

lcidlc/src/InterfaceGenerate.cpp

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ static NativeType map_native_type(HandlerMapping p_mapping, NameRef p_type)
152152
class TypeMapper
153153
{
154154
public:
155+
virtual const char *GetTypedef(ParameterType mode) = 0;
156+
155157
virtual void Initialize(CoderRef coder, ParameterType mode, const char *name) = 0;
156158
virtual void Fetch(CoderRef coder, ParameterType mode, const char *name, const char *source) = 0;
157159
virtual void Default(CoderRef coder, ParameterType mode, const char *name, ValueRef value) = 0;
@@ -164,6 +166,11 @@ class TypeMapper
164166
class PrimitiveTypeMapper: public TypeMapper
165167
{
166168
public:
169+
virtual const char *GetTypedef(ParameterType mode)
170+
{
171+
return GetType();
172+
}
173+
167174
virtual void Initialize(CoderRef p_coder, ParameterType p_mode, const char *p_name)
168175
{
169176
CoderWriteStatement(p_coder, "%s %s", GetType(), p_name);
@@ -283,7 +290,7 @@ class ObjcArrayTypeMapper: public PrimitiveTypeMapper
283290
}
284291

285292
protected:
286-
virtual const char *GetType(void) const {return "NSArry*";}
293+
virtual const char *GetType(void) const {return "NSArray*";}
287294
virtual const char *GetInitializer(void) const {return "nil";}
288295
virtual const char *GetTag(void) const {return "objc_array";}
289296
};
@@ -335,6 +342,11 @@ class CTypesTypeMapper : public TypeMapper
335342
class CStringTypeMapper: public CTypesTypeMapper
336343
{
337344
public:
345+
virtual const char *GetTypedef(ParameterType mode)
346+
{
347+
return mode == kParameterTypeIn ? "const char *" : "char *";
348+
}
349+
338350
virtual void Initialize(CoderRef p_coder, ParameterType p_mode, const char *p_name)
339351
{
340352
if (p_mode == kParameterTypeInOut)
@@ -373,6 +385,11 @@ class CStringTypeMapper: public CTypesTypeMapper
373385
class CDataTypeMapper: public CTypesTypeMapper
374386
{
375387
public:
388+
virtual const char *GetTypedef(ParameterType mode)
389+
{
390+
return "LCBytes";
391+
}
392+
376393
virtual void Initialize(CoderRef p_coder, ParameterType p_mode, const char *p_name)
377394
{
378395
if (p_mode == kParameterTypeInOut)
@@ -421,6 +438,11 @@ class EnumTypeMapper: public TypeMapper
421438
m_type_default = p_default;
422439
}
423440

441+
virtual const char *GetTypedef(ParameterType mode)
442+
{
443+
return "int";
444+
}
445+
424446
virtual void Initialize(CoderRef p_coder, ParameterType p_mode, const char *p_name)
425447
{
426448
CoderWriteStatement(p_coder, "int %s", p_name);
@@ -456,6 +478,11 @@ class EnumTypeMapper: public TypeMapper
456478
class JavaStringTypeMapper: public TypeMapper
457479
{
458480
public:
481+
virtual const char *GetTypedef(ParameterType type)
482+
{
483+
return "__INTERNAL_ERROR__";
484+
}
485+
459486
virtual void Initialize(CoderRef p_coder, ParameterType p_mode, const char *p_name)
460487
{
461488
CoderWriteStatement(p_coder, "jobject %s", p_name);
@@ -486,6 +513,11 @@ class JavaStringTypeMapper: public TypeMapper
486513
class JavaDataTypeMapper: public TypeMapper
487514
{
488515
public:
516+
virtual const char *GetTypedef(ParameterType type)
517+
{
518+
return "__INTERNAL_ERROR__";
519+
}
520+
489521
virtual void Initialize(CoderRef p_coder, ParameterType p_mode, const char *p_name)
490522
{
491523
CoderWriteStatement(p_coder, "jobject %s", p_name);
@@ -559,6 +591,7 @@ static bool InterfaceGenerateImports(InterfaceRef self, CoderRef p_coder)
559591
if (self -> shutdown_hook != nil)
560592
CoderWriteLine(p_coder, "%s void %s(void);", t_extern, NameGetCString(self -> shutdown_hook));
561593

594+
#if NOT_USED
562595
for(uint32_t i = 0; i < self -> handler_count; i++)
563596
for(uint32_t j = 0; j < self -> handlers[i] . variant_count; j++)
564597
{
@@ -590,6 +623,7 @@ static bool InterfaceGenerateImports(InterfaceRef self, CoderRef p_coder)
590623

591624
CoderWriteLine(p_coder, ");");
592625
}
626+
#endif
593627

594628
return true;
595629
}
@@ -1070,6 +1104,57 @@ static bool InterfaceGenerateVariant(InterfaceRef self, CoderRef p_coder, Handle
10701104
for(uint32_t k = 0; k < t_variant -> parameter_count; k++)
10711105
map_parameter(self, p_mapping, &t_variant -> parameters[k], k, t_mapped_params[k]);
10721106

1107+
// If c++ then we can use references for indirect return values.
1108+
const char *t_ref_char;
1109+
if (self -> use_cpp_naming)
1110+
t_ref_char = "";
1111+
else
1112+
t_ref_char = "&";
1113+
1114+
// Get the type mapper for the return type.
1115+
TypeMapper *t_return_type_mapper;
1116+
if (t_variant -> return_type != nil)
1117+
t_return_type_mapper = map_parameter_type(self, p_mapping, t_variant -> return_type, nil);
1118+
else
1119+
t_return_type_mapper = nil;
1120+
1121+
// Generate the import - but not for Java
1122+
if (!t_is_java)
1123+
{
1124+
CoderBeginStatement(p_coder);
1125+
1126+
CoderWrite(p_coder, "%s %s %s(",
1127+
InterfaceGetExternPrefix(self),
1128+
t_return_type_mapper != nil && !t_variant -> return_type_indirect ? t_return_type_mapper -> GetTypedef(kParameterTypeOut) : "void",
1129+
NameGetCString(t_variant -> binding));
1130+
1131+
bool t_has_param;
1132+
t_has_param = false;
1133+
if (t_variant -> return_type_indirect)
1134+
{
1135+
CoderWrite(p_coder, "%s%s", t_return_type_mapper -> GetTypedef(kParameterTypeOut), InterfaceGetReferenceSuffix(self));
1136+
t_has_param = true;
1137+
}
1138+
1139+
if (t_variant -> parameter_count != 0)
1140+
for(uint32_t k = 0; k < t_variant -> parameter_count; k++)
1141+
{
1142+
if (t_has_param)
1143+
CoderWrite(p_coder, ", ");
1144+
CoderWrite(p_coder, "%s%s",
1145+
t_mapped_params[k] . mapper -> GetTypedef(t_mapped_params[k] . mode),
1146+
InterfaceGetReferenceSuffix(self));
1147+
t_has_param = true;
1148+
}
1149+
1150+
if (!t_has_param)
1151+
CoderWrite(p_coder, "void");
1152+
1153+
CoderWrite(p_coder, ")");
1154+
1155+
CoderEndStatement(p_coder);
1156+
}
1157+
10731158
CoderBegin(p_coder, "static bool variant__%s(MCVariableRef *argv, uint32_t argc, MCVariableRef result)", NameGetCString(t_variant -> binding));
10741159
if (self -> use_objc_objects && !t_is_java)
10751160
{
@@ -1134,20 +1219,6 @@ static bool InterfaceGenerateVariant(InterfaceRef self, CoderRef p_coder, Handle
11341219
CoderPad(p_coder);
11351220
}
11361221

1137-
// If c++ then we can use references for indirect return values.
1138-
const char *t_ref_char;
1139-
if (self -> use_cpp_naming)
1140-
t_ref_char = "";
1141-
else
1142-
t_ref_char = "&";
1143-
1144-
// Get the type mapper for the return type.
1145-
TypeMapper *t_return_type_mapper;
1146-
if (t_variant -> return_type != nil)
1147-
t_return_type_mapper = map_parameter_type(self, p_mapping, t_variant -> return_type, nil);
1148-
else
1149-
t_return_type_mapper = nil;
1150-
11511222
// If we have a return value, generate the initializer for it.
11521223
if (t_return_type_mapper != nil)
11531224
t_return_type_mapper -> Initialize(p_coder, kParameterTypeOut, "returnvalue");
@@ -1297,7 +1368,7 @@ static bool InterfaceGenerateVariant(InterfaceRef self, CoderRef p_coder, Handle
12971368

12981369
static void InterfaceGenerateUnsupportedVariant(InterfaceRef self, CoderRef p_coder, Handler *p_handler, HandlerVariant *p_variant, HandlerMapping p_mapping)
12991370
{
1300-
CoderBegin(p_coder, "static bool variant__%s(MCVariableRef *argv, uint32_t argc, MCVariableRef result)", NameGetCString(t_variant -> binding));
1371+
CoderBegin(p_coder, "static bool variant__%s(MCVariableRef *argv, uint32_t argc, MCVariableRef result)", NameGetCString(p_variant -> binding));
13011372
CoderWriteStatement(p_coder, "return error__report_not_supported(result)");
13021373
CoderEnd(p_coder, "");
13031374
}
@@ -1346,7 +1417,7 @@ static bool InterfaceGenerateHandlers(InterfaceRef self, CoderRef p_coder)
13461417
if (t_mapping != kHandlerMappingNone)
13471418
InterfaceGenerateVariant(self, p_coder, t_handler, t_variant, t_mapping);
13481419
else
1349-
InterfaceGenerateUnsupportedVariant(self, p_coder, t_handler, t_variant);
1420+
InterfaceGenerateUnsupportedVariant(self, p_coder, t_handler, t_variant, t_mapping);
13501421
CoderEndPreprocessor(p_coder, "#endif");
13511422

13521423
MCCStringFree(t_defineds);

0 commit comments

Comments
 (0)