Improved macro argument type checking,
and change some formals to convey type expectations.
This commit is contained in:
parent
3bf19bb1f1
commit
f5a323e8c3
7 changed files with 33 additions and 27 deletions
|
@ -148,28 +148,28 @@
|
|||
[/store_unit]
|
||||
#enddef
|
||||
|
||||
#define HEROMACRO X
|
||||
#define HEROMACRO DESCRIPTION
|
||||
[store_unit]
|
||||
[filter]
|
||||
description={X}
|
||||
description={DESCRIPTION}
|
||||
[/filter]
|
||||
variable=temp{X}
|
||||
variable=temp{DESCRIPTION}
|
||||
kill=yes
|
||||
[/store_unit]
|
||||
#enddef
|
||||
|
||||
#define RECALLMACRO X
|
||||
#define RECALLMACRO THING
|
||||
[unstore_unit]
|
||||
variable=temp{X}
|
||||
variable=temp{THING}
|
||||
[/unstore_unit]
|
||||
[recall]
|
||||
role=temp{X}
|
||||
role=temp{THING}
|
||||
[/recall]
|
||||
[recall]
|
||||
description={X}
|
||||
description={THING}
|
||||
[/recall]
|
||||
[clear_variable]
|
||||
name=temp{X}
|
||||
name=temp{THING}
|
||||
[/clear_variable]
|
||||
#enddef
|
||||
|
||||
|
|
|
@ -926,11 +926,11 @@
|
|||
[/event]
|
||||
#enddef
|
||||
|
||||
#define DEFINE_MAIN_GROUP X Y
|
||||
#define DEFINE_MAIN_GROUP XX YY
|
||||
{VARIABLE spawn_id 0}
|
||||
{VARIABLE_OP main_group add 1}
|
||||
{VARIABLE main_spawns[$main_group].x {X}}
|
||||
{VARIABLE main_spawns[$main_group].y {Y}}
|
||||
{VARIABLE main_spawns[$main_group].x {XX}}
|
||||
{VARIABLE main_spawns[$main_group].y {YY}}
|
||||
#enddef
|
||||
|
||||
#define ADD_MAIN_SPAWN TYPE UP1 UP2 UP3
|
||||
|
|
|
@ -152,11 +152,11 @@
|
|||
convert_to=Aa
|
||||
[/road_cost]
|
||||
|
||||
#define MIN_COST_ROAD X
|
||||
#define MIN_COST_ROAD TERRAIN
|
||||
[road_cost]
|
||||
terrain={X}
|
||||
terrain={TERRAIN}
|
||||
cost=2
|
||||
convert_to={X}
|
||||
convert_to={TERRAIN}
|
||||
[/road_cost]
|
||||
#enddef
|
||||
|
||||
|
|
|
@ -109,11 +109,11 @@
|
|||
convert_to=Rd
|
||||
[/road_cost]
|
||||
|
||||
#define MIN_COST_ROAD X
|
||||
#define MIN_COST_ROAD TERRAIN
|
||||
[road_cost]
|
||||
terrain={X}
|
||||
terrain={TERRAIN}
|
||||
cost=2
|
||||
convert_to={X}
|
||||
convert_to={TERRAIN}
|
||||
[/road_cost]
|
||||
#enddef
|
||||
|
||||
|
|
|
@ -123,11 +123,11 @@
|
|||
convert_to=Re
|
||||
[/road_cost]
|
||||
|
||||
#define MIN_COST_ROAD X
|
||||
#define MIN_COST_ROAD TERRAIN
|
||||
[road_cost]
|
||||
terrain={X}
|
||||
terrain={TERRAIN}
|
||||
cost=2
|
||||
convert_to={X}
|
||||
convert_to={TERRAIN}
|
||||
[/road_cost]
|
||||
#enddef
|
||||
|
||||
|
|
|
@ -144,11 +144,11 @@
|
|||
convert_to=Re
|
||||
[/road_cost]
|
||||
|
||||
#define MIN_COST_ROAD X
|
||||
#define MIN_COST_ROAD TERRAIN
|
||||
[road_cost]
|
||||
terrain={X}
|
||||
terrain={TERRAIN}
|
||||
cost=2
|
||||
convert_to={X}
|
||||
convert_to={TERRAIN}
|
||||
[/road_cost]
|
||||
#enddef
|
||||
|
||||
|
|
|
@ -65,21 +65,27 @@ def argmatch(formals, actuals):
|
|||
return False
|
||||
for (f, a) in zip(formals, actuals):
|
||||
# Deduce the expected type of the formal
|
||||
if f in ("X", "Y", "SIDE"):
|
||||
if f in ("SIDE",):
|
||||
ftype = "numeric"
|
||||
elif f in ("TYPE", "DESCRIPTION", "USER_DESCRIPTION"):
|
||||
elif f in ("X", "Y"):
|
||||
ftype = "range"
|
||||
elif f in ("TYPE", "DESCRIPTION", "USER_DESCRIPTION", "TERRAIN"):
|
||||
ftype = "string"
|
||||
else:
|
||||
ftype = None
|
||||
# Deduce the type of the actual
|
||||
if a.isdigit():
|
||||
if a.isdigit() or a.startswith("-") and a[1:].isdigit():
|
||||
atype = "numeric"
|
||||
elif re.search(r"[0-9]+\-[0-9]+", a):
|
||||
atype = "range"
|
||||
elif a.startswith("{") and a.endswith("}") or a.startswith("$"):
|
||||
atype = None # Can't tell -- it's a macro expansion
|
||||
else:
|
||||
atype = "string"
|
||||
# Here's the compatibility rule
|
||||
if atype != ftype and ftype is not None and atype is not None:
|
||||
if atype == "numeric" and ftype == "range":
|
||||
pass
|
||||
elif atype != ftype and ftype is not None and atype is not None:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue