From b43f646852cc39d9aff3ad8ab170955a6eaf02b5 Mon Sep 17 00:00:00 2001 From: Samuel Gomes <47574584+a740g@users.noreply.github.com> Date: Mon, 9 Sep 2024 06:56:24 +0530 Subject: [PATCH] Relax ALIAS function name validation --- source/global/constants.bas | 27 ++++++++++--------- source/qb64pe.bas | 4 ++- tests/compile_tests/extra/declare-header.bi | 5 ++-- .../extra/header-dir/fastmath-extra.h | 6 +++++ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/source/global/constants.bas b/source/global/constants.bas index 79e37011b..c84c97e68 100644 --- a/source/global/constants.bas +++ b/source/global/constants.bas @@ -11,18 +11,21 @@ IF Debug THEN sp = CHR$(250): sp2 = CHR$(249): sp3 = CHR$(179) 'makes debug outp CONST FALSE = 0, TRUE = NOT FALSE 'ASCII codes -CONST ASC_BACKSLASH = 92 -CONST ASC_FORWARDSLASH = 47 -CONST ASC_LEFTBRACKET = 40 -CONST ASC_RIGHTBRACKET = 41 -CONST ASC_FULLSTOP = 46 -CONST ASC_COLON = 58 -CONST ASC_SEMICOLON = 59 -CONST ASC_UNDERSCORE = 95 -CONST ASC_QUOTE = 34 -CONST ASC_LEFTSQUAREBRACKET = 91 -CONST ASC_RIGHTSQUAREBRACKET = 93 -CONST ASC_QUESTIONMARK = 63 +CONST ASC_QUOTE = 34 ' " +CONST ASC_LEFTBRACKET = 40 ' ( +CONST ASC_RIGHTBRACKET = 41 ' ) +CONST ASC_MINUS = 45 ' - +CONST ASC_FULLSTOP = 46 ' . +CONST ASC_FORWARDSLASH = 47 ' / +CONST ASC_COLON = 58 ' : +CONST ASC_SEMICOLON = 59 ' ; +CONST ASC_LESSTHAN = 60 ' < +CONST ASC_GREATERTHAN = 62 ' > +CONST ASC_QUESTIONMARK = 63 ' ? +CONST ASC_LEFTSQUAREBRACKET = 91 ' [ +CONST ASC_BACKSLASH = 92 ' \ +CONST ASC_RIGHTSQUAREBRACKET = 93 ' ] +CONST ASC_UNDERSCORE = 95 ' _ '_KEYDOWN/_KEYHIT codes CONST KEY_LSHIFT = 100304 diff --git a/source/qb64pe.bas b/source/qb64pe.bas index fdf62a954..13fb412e8 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -2326,7 +2326,9 @@ DO IF LEN(e$) = 0 THEN a$ = "Expected ALIAS name-in-library": GOTO errmes FOR x = 1 TO LEN(e$) a = ASC(e$, x) - IF alphanumeric(a) = 0 AND a <> ASC_FULLSTOP AND a <> ASC_COLON THEN a$ = "Expected ALIAS name-in-library": GOTO errmes + IF _NEGATE alphanumeric(a) _ANDALSO a <> ASC_LEFTBRACKET _ANDALSO a <> ASC_RIGHTBRACKET _ANDALSO a <> ASC_MINUS _ANDALSO a <> ASC_FULLSTOP _ANDALSO a <> ASC_COLON _ANDALSO a <> ASC_LESSTHAN _ANDALSO a <> ASC_GREATERTHAN _ANDALSO a <> ASC_LEFTSQUAREBRACKET _ANDALSO a <> ASC_RIGHTSQUAREBRACKET THEN + a$ = "Expected ALIAS name-in-library": GOTO errmes + END IF NEXT aliasname$ = e$ 'remove ALIAS section from line diff --git a/tests/compile_tests/extra/declare-header.bi b/tests/compile_tests/extra/declare-header.bi index e71772a29..bdb296e61 100644 --- a/tests/compile_tests/extra/declare-header.bi +++ b/tests/compile_tests/extra/declare-header.bi @@ -1,5 +1,6 @@ DECLARE LIBRARY "./header-dir/fastmath-extra" - FUNCTION Fast_Sqrt&(BYVAL val AS LONG) + FUNCTION Fast_Sqrt& (BYVAL val AS LONG) + FUNCTION Max_Long& ALIAS "Max" (BYVAL x AS LONG, BYVAL y AS LONG) + FUNCTION Max_Single! ALIAS "Max" (BYVAL x AS SINGLE, BYVAL y AS SINGLE) END DECLARE - diff --git a/tests/compile_tests/extra/header-dir/fastmath-extra.h b/tests/compile_tests/extra/header-dir/fastmath-extra.h index b1a14d765..61f80243b 100644 --- a/tests/compile_tests/extra/header-dir/fastmath-extra.h +++ b/tests/compile_tests/extra/header-dir/fastmath-extra.h @@ -4,3 +4,9 @@ int Fast_Sqrt(int value) { return value * 2; } + +template +T Max(T a, T b) +{ + return a > b ? a : b; +}