Skip to content

Commit

Permalink
[UR] Allow else to be None
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Vesely committed Jul 11, 2023
1 parent 284a10d commit 276110e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// standard headers
#include <stddef.h>
#include <stdint.h>
#if defined(_WIN32)
#include "windows.h"
#endif

#if defined(__cplusplus)
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion scripts/core/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,5 @@ name: $x_file_descriptor_t
value:
- if: Windows
value: HANDLE
- else: ""
- else:
value: int
16 changes: 16 additions & 0 deletions scripts/parse_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ def __validate_params(d, tags):
raise Exception(prefix+"'version' must be increasing: %s"%item['version'])
max_ver = ver

def __validate_typedef_values(d):
if not isinstance(d['value'], list):
return

for cond in d['value']:
if not ('if' in cond or 'else' in cond):
raise Exception("typedef values must include an 'if' or 'else' field")

valid_platforms = ['Linux', 'Windows', 'Darwin']
if 'if' in cond and cond['if'] not in valid_platforms:
raise Exception(f"Invalid platform selected '{cond['if']}' : must be one of {valid_platforms}")

if 'else' in cond and cond['else'] is not None:
raise Exception("typedef 'else' field is required to be None")

try:
if 'type' not in d:
raise Exception("every document must have 'type'")
Expand Down Expand Up @@ -374,6 +389,7 @@ def __validate_params(d, tags):
raise Exception("'typedef' requires the following scalar fields: {`desc`, `name`, `value`}")

__validate_type(d, 'name', tags)
__validate_typedef_values(d)
__validate_details(d)
__validate_ordinal(d)
__validate_version(d)
Expand Down
10 changes: 6 additions & 4 deletions scripts/templates/api.h.mako
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ from templates import helper as th
// standard headers
#include <stdint.h>
#include <stddef.h>
#if defined(_WIN32)
#include "windows.h"
#endif
%endif

#if defined(__cplusplus)
Expand Down Expand Up @@ -75,14 +78,13 @@ extern "C" {
%if isinstance(obj['value'], list):
<% first = True%>\
%for cond in obj['value']:
%if cond.get('if') is not None:
%if 'if' in cond:
${"#if" if first else "#elif"} ${th.convert_platform_to_define(cond['if'])}
<% first = False %>\
typedef ${th.subt(n, tags, cond['value'])} ${th.make_type_name(n, tags, obj)};
%elif cond.get('else') is not None:
%elif 'else' in cond:
#else
typedef ${th.subt(n, tags, cond['value'])} ${th.make_type_name(n, tags, obj)};
%endif
typedef ${th.subt(n, tags, cond['value'])} ${th.make_type_name(n, tags, obj)};
%endfor
#endif
%else:
Expand Down
4 changes: 2 additions & 2 deletions scripts/templates/api.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ ${th.make_macro_name(n, tags, obj)} = ${th.subt(n, tags, obj['value'])}
%if isinstance(obj['value'], list):
<% first = True%>\
%for cond in obj['value']:
%if cond.get('if') is not None:
%if 'if' in cond:
${"if" if first else "elif"} platform.system() == "${cond['if']}":<% first = False %>
%elif cond.get('else') is not None:
%elif 'else' in cond:
else:
%endif
class ${th.make_type_name(n, tags, obj)}(${th.get_ctype_name(n, tags, {'type': cond['value']})}):
Expand Down

0 comments on commit 276110e

Please sign in to comment.