mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Allow concatenation of key+string and string+key producing string.
Also add corresponding test cases, making some mostly cosmetic changes to the test program while on it.
This commit is contained in:
parent
841413a2cf
commit
e03b342f78
2 changed files with 17 additions and 5 deletions
|
@ -886,6 +886,7 @@ class parser(object):
|
||||||
#or op == '-' and type2 not in ('integer', 'float',
|
#or op == '-' and type2 not in ('integer', 'float',
|
||||||
# 'vector', 'rotation'):
|
# 'vector', 'rotation'):
|
||||||
raise EParseTypeMismatch(self)
|
raise EParseTypeMismatch(self)
|
||||||
|
# Isolate the additions where the types match to make our life easier later
|
||||||
if op == '+' and (type1 == type2 or type1 == 'list' or type2 == 'list'):
|
if op == '+' and (type1 == type2 or type1 == 'list' or type2 == 'list'):
|
||||||
if type1 == type2 == 'key':
|
if type1 == type2 == 'key':
|
||||||
# key + key is the only disallowed combo of equals
|
# key + key is the only disallowed combo of equals
|
||||||
|
@ -902,6 +903,13 @@ class parser(object):
|
||||||
# list + (list)nonlist and same goes for nonlist + list, they
|
# list + (list)nonlist and same goes for nonlist + list, they
|
||||||
# don't compile to the same thing, but the optimizer should deal
|
# don't compile to the same thing, but the optimizer should deal
|
||||||
# with typecast removal anyway.
|
# with typecast removal anyway.
|
||||||
|
elif self.allowkeyconcat and op == '+' \
|
||||||
|
and type1 in ('key', 'string') and type2 in ('key', 'string'):
|
||||||
|
# Allow key addition (but add explicit cast)
|
||||||
|
if type1 == 'key':
|
||||||
|
term = [S[op], S[type2], [S['CAST'], S[type2], term], value]
|
||||||
|
else:
|
||||||
|
term = [S[op], S[type1], term, [S['CAST'], S[type1], value]]
|
||||||
elif type1 == 'key' or type2 == 'key':
|
elif type1 == 'key' or type2 == 'key':
|
||||||
# Only list + key or key + list is allowed, otherwise keys can't
|
# Only list + key or key + list is allowed, otherwise keys can't
|
||||||
# be added or subtracted with anything.
|
# be added or subtracted with anything.
|
||||||
|
@ -1663,8 +1671,8 @@ class parser(object):
|
||||||
# the correctness of the output)
|
# the correctness of the output)
|
||||||
self.explicitcast = 'explicitcast' in options
|
self.explicitcast = 'explicitcast' in options
|
||||||
|
|
||||||
# TODO: Allow string + key
|
# Allow string + key = string and key + string = string
|
||||||
#self.allowkeyconcat = 'allowkeyconcat' in options
|
self.allowkeyconcat = 'allowkeyconcat' in options
|
||||||
|
|
||||||
# Allow C style string composition of strings: "blah" "blah" = "blahblah"
|
# Allow C style string composition of strings: "blah" "blah" = "blahblah"
|
||||||
self.allowmultistrings = 'allowmultistrings' in options
|
self.allowmultistrings = 'allowmultistrings' in options
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Test02Compiler(UnitTestCase):
|
||||||
<0,0,0.>0>0>*<0,0,0==0>2,3>>3>3.>%<3,4,5>;
|
<0,0,0.>0>0>*<0,0,0==0>2,3>>3>3.>%<3,4,5>;
|
||||||
f -= TRUE-(integer)-1;
|
f -= TRUE-(integer)-1;
|
||||||
f *= !FALSE;
|
f *= !FALSE;
|
||||||
V %= ZERO_VECTOR*ZERO_ROTATION;
|
V %= (ZERO_VECTOR+-ZERO_VECTOR)*(ZERO_ROTATION+-ZERO_ROTATION);
|
||||||
1e37;1.1e22;1.;
|
1e37;1.1e22;1.;
|
||||||
print(V *= 3);
|
print(V *= 3);
|
||||||
fwd("","","");
|
fwd("","","");
|
||||||
|
@ -147,6 +147,8 @@ class Test02Compiler(UnitTestCase):
|
||||||
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){""-(key)"";}''')
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){""-(key)"";}''')
|
||||||
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){""+f();}''')
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){""+f();}''')
|
||||||
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){""+(key)"";}''')
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){""+(key)"";}''')
|
||||||
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){(key)""+"";}''')
|
||||||
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){(key)""+(key)"";}''')
|
||||||
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){key k;k+k;}''')
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){key k;k+k;}''')
|
||||||
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3/<1,2,3>;}''')
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3/<1,2,3>;}''')
|
||||||
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3/<1,2,3,4>;}''')
|
self.assertRaises(EParseTypeMismatch, self.parser.parse, '''f(){3/<1,2,3,4>;}''')
|
||||||
|
@ -193,10 +195,12 @@ class Test02Compiler(UnitTestCase):
|
||||||
integer i;
|
integer i;
|
||||||
i |= i;
|
i |= i;
|
||||||
"a" "b" "c";
|
"a" "b" "c";
|
||||||
|
"a"+(key)"b"; (key)"a" + "b";
|
||||||
i>>=i;
|
i>>=i;
|
||||||
}}''',
|
}}''',
|
||||||
set(('explicitcast','extendedtypecast','extendedassignment',
|
['explicitcast','extendedtypecast','extendedassignment',
|
||||||
'extendedglobalexpr', 'allowmultistrings'))))
|
'extendedglobalexpr', 'allowmultistrings', 'allowkeyconcat']
|
||||||
|
))
|
||||||
print self.parser.scopeindex
|
print self.parser.scopeindex
|
||||||
self.assertRaises(EParseUnexpected, self.parser.PopScope)
|
self.assertRaises(EParseUnexpected, self.parser.PopScope)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue