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

Commit f509a64

Browse files
committed
[[ ExternalsApiV5 ]] Initial changes to lcidl syntax to better support cross-platform externals.
1 parent 498ec28 commit f509a64

File tree

8 files changed

+588
-344
lines changed

8 files changed

+588
-344
lines changed

lcidlc/src/Interface.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ enum InterfaceError
5151
kInterfaceErrorJavaImpliesInParam,
5252
kInterfaceErrorMethodsCannotHaveVariants,
5353
kInterfaceErrorMethodsMustBeJava,
54-
kInterfaceErrorMethodsAreAlwaysTail
54+
kInterfaceErrorMethodsAreAlwaysTail,
55+
kInterfaceErrorUnknownHandlerMapping,
56+
kInterfaceErrorUnknownPlatform,
57+
kInterfaceErrorObjCNotSupported,
58+
kInterfaceErrorJavaNotSupported,
5559
};
5660

5761
////////////////////////////////////////////////////////////////////////////////
@@ -140,6 +144,18 @@ static bool InterfaceReport(InterfaceRef self, Position p_where, InterfaceError
140144
case kInterfaceErrorUnknownType:
141145
fprintf(stderr, "Unknown type '%s'\n", StringGetCStringPtr(NameGetString((NameRef)p_hint)));
142146
break;
147+
case kInterfaceErrorUnknownHandlerMapping:
148+
fprintf(stderr, "Unknown handler mapping type '%s'\n", StringGetCStringPtr(NameGetString((NameRef)p_hint)));
149+
break;
150+
case kInterfaceErrorUnknownPlatform:
151+
fprintf(stderr, "Unknown platform '%s'\n", StringGetCStringPtr(NameGetString((NameRef)p_hint)));
152+
break;
153+
case kInterfaceErrorObjCNotSupported:
154+
fprintf(stderr, "Objective-C mapping not supported on platform '%s'\n", StringGetCStringPtr(NameGetString((NameRef)p_hint)));
155+
break;
156+
case kInterfaceErrorJavaNotSupported:
157+
fprintf(stderr, "Java mapping not supported on platform '%s'\n", StringGetCStringPtr(NameGetString((NameRef)p_hint)));
158+
break;
143159
}
144160

145161
self -> invalid = true;
@@ -245,6 +261,47 @@ bool InterfaceDefineUse(InterfaceRef self, Position p_where, NameRef p_use)
245261
return true;
246262
}
247263

264+
bool InterfaceDefineUseOnPlatform(InterfaceRef self, Position p_where, NameRef p_use, NameRef p_platform)
265+
{
266+
MCLog("%s - use %s on %s", PositionDescribe(p_where), StringGetCStringPtr(NameGetString(p_use)), StringGetCStringPtr(NameGetString(p_platform)));
267+
268+
HandlerMapping t_mapping;
269+
if (NameEqualToCString(p_use, "none"))
270+
t_mapping = kHandlerMappingNone;
271+
else if (NameEqualToCString(p_use, "c"))
272+
t_mapping = kHandlerMappingC;
273+
else if (NameEqualToCString(p_use, "objc"))
274+
t_mapping = kHandlerMappingObjC;
275+
else if (NameEqualToCString(p_use, "java"))
276+
t_mapping = kHandlerMappingJava;
277+
else
278+
return InterfaceReport(self, p_where, kInterfaceErrorUnknownHandlerMapping, p_use);
279+
280+
Platform t_platform;
281+
if (NameEqualToCString(p_platform, "mac"))
282+
t_platform = kPlatformMac;
283+
else if (NameEqualToCString(p_platform, "windows"))
284+
t_platform = kPlatformWindows;
285+
else if (NameEqualToCString(p_platform, "linux"))
286+
t_platform = kPlatformLinux;
287+
else if (NameEqualToCString(p_platform, "ios"))
288+
t_platform = kPlatformIOS;
289+
else if (NameEqualToCString(p_platform, "android"))
290+
t_platform = kPlatformAndroid;
291+
else
292+
return InterfaceReport(self, p_where, kInterfaceErrorUnknownPlatform, p_platform);
293+
294+
if (t_mapping == kHandlerMappingObjC && !(t_platform == kPlatformMac || t_platform == kPlatformIOS))
295+
return InterfaceReport(self, p_where, kInterfaceErrorObjCNotSupported, p_platform);
296+
297+
if (t_mapping == kHandlerMappingJava && !(t_platform == kPlatformAndroid))
298+
return InterfaceReport(self, p_where, kInterfaceErrorJavaNotSupported, p_platform);
299+
300+
self -> use_mappings[t_platform] = t_mapping;
301+
302+
return true;
303+
}
304+
248305
bool InterfaceDefineHook(InterfaceRef self, Position p_where, NameRef p_handler, NameRef p_target)
249306
{
250307
MCLog("%s - hook %s with %s", PositionDescribe(p_where), StringGetCStringPtr(NameGetString(p_handler)), StringGetCStringPtr(NameGetString(p_target)));
@@ -376,9 +433,11 @@ bool InterfaceBeginHandler(InterfaceRef self, Position p_where, HandlerType p_ty
376433

377434
if (!MCMemoryResizeArray(t_handler -> variant_count + 1, t_handler -> variants, t_handler -> variant_count))
378435
return false;
379-
436+
380437
t_handler -> variants[t_handler -> variant_count - 1] . where = p_where;
381438

439+
memcpy(t_handler -> variants[t_handler -> variant_count - 1] . mappings, self -> use_mappings, sizeof(self -> use_mappings));
440+
382441
self -> current_handler = t_handler;
383442

384443
return true;

lcidlc/src/Interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void InterfaceDestroy(InterfaceRef interface);
5757

5858
bool InterfaceBegin(InterfaceRef interface, Position where, NameRef name);
5959
bool InterfaceDefineUse(InterfaceRef interface, Position where, NameRef use);
60+
bool InterfaceDefineUseOnPlatform(InterfaceRef interface, Position where, NameRef type, NameRef platform);
6061
bool InterfaceDefineHook(InterfaceRef interface, Position where, NameRef handler, NameRef target);
6162

6263
bool InterfaceBeginEnum(InterfaceRef interface, Position where, NameRef name);

0 commit comments

Comments
 (0)