From bf72d2c3bf7057c881362edcc4a86e0416ef130c Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 17 Oct 2021 20:07:33 +0200 Subject: [PATCH] Allow //pragma inline or /*pragma inline*/ for inlining a function They are transformed by the scanner to the identifier `inline`, which is how the parser identifies it. This solves the comment problem, but it results in a funny side effect. Now, in inline mode, /*pragma inline*/ will always be the identifier `inline`, therefore this is valid: integer /*pragma inline*/ = 5; llOwnerSay((string)inline); // will say 5 Not overly elegant, but better than making up a specific token or declaring comments as tokens or the like. --- lslopt/lslparse.py | 16 ++++++++++++++++ unit_tests/coverage.suite/inline-1.lsl | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index 0a9422f..2c6c2be 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -525,6 +525,18 @@ class parser(object): if c == '/': if self.script[self.pos:self.pos+1] == '/': self.pos += 1 + if self.enable_inline and self.script.startswith( + 'pragma inline', self.pos + ) and not isalphanum_(self.script[self.pos + 13: + self.pos + 14] + ): + self.pos += 12 # len('pragma inline') - 1 + while self.script[self.pos] != '\n': + self.pos += 1 + # Check for normal EOF. Note: 'inline' is not + # inserted if the file ends before a newline. + self.ceof() + return ('IDENT', 'inline') self.ceof() while self.script[self.pos] != '\n': self.pos += 1 @@ -537,6 +549,10 @@ class parser(object): elif self.script[self.pos:self.pos+1] == '*': self.pos += 2 + if self.enable_inline and self.script.startswith( + 'pragma inline*/', self.pos-1): + self.pos += 14 # len('pragma inline*/') - 1 + return ('IDENT', 'inline') while self.script[self.pos-1:self.pos+1] != '*/': self.pos += 1 self.ueof() # An unterminated multiline comment *is* unexpected EOF. diff --git a/unit_tests/coverage.suite/inline-1.lsl b/unit_tests/coverage.suite/inline-1.lsl index c4f8977..947cc8a 100644 --- a/unit_tests/coverage.suite/inline-1.lsl +++ b/unit_tests/coverage.suite/inline-1.lsl @@ -5,12 +5,12 @@ f1() inline llOwnerSay("f1"); } -f2(integer f2param) inline +f2(integer f2param) /*pragma inline*/ { llOwnerSay("f2:" + (string)f2param); } -vector f3(integer f3p1, string f3p2) inline +vector f3(integer f3p1, string f3p2) //pragma inline { f2(f3p1); integer f3p1; // test shading the parameter