From 7d499c32d809d7d98a697f8ad4af0117540b6450 Mon Sep 17 00:00:00 2001 From: "Walied K. Yassen" Date: Fri, 24 Nov 2023 13:06:05 +0300 Subject: [PATCH] Add support for long numeric type --- CHANGELOG.md | 1 + .../plugin/lang/lexer/_RsLexer.java | 401 +++++++++--------- .../plugin/lang/parser/RsParser.java | 20 +- .../plugin/lang/psi/RsElementTypes.java | 5 + .../lang/psi/RsLongLiteralExpression.java | 13 + .../runescript/plugin/lang/psi/RsVisitor.java | 4 + .../psi/impl/RsLongLiteralExpressionImpl.java | 36 ++ src/main/grammars/RuneScript.bnf | 2 + src/main/grammars/RuneScript.flex | 4 + .../RsInlayParameterHintsProvider.kt | 1 + .../controlFlow/RsControlFlowBuilder.kt | 4 + .../ide/highlight/RsSyntaxHighlighter.kt | 1 + .../type/inference/RsTypeInferenceVisitor.kt | 90 +++- 13 files changed, 362 insertions(+), 220 deletions(-) create mode 100644 src/main/gen/io/runescript/plugin/lang/psi/RsLongLiteralExpression.java create mode 100644 src/main/gen/io/runescript/plugin/lang/psi/impl/RsLongLiteralExpressionImpl.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df2016..b657dff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # intellij-runescript Changelog ## [Unreleased] +- Add support for long numeric type. ## [1.4.1] - 2023-10-16 diff --git a/src/main/gen/io/runescript/plugin/lang/lexer/_RsLexer.java b/src/main/gen/io/runescript/plugin/lang/lexer/_RsLexer.java index df604f7..54173c7 100644 --- a/src/main/gen/io/runescript/plugin/lang/lexer/_RsLexer.java +++ b/src/main/gen/io/runescript/plugin/lang/lexer/_RsLexer.java @@ -77,12 +77,12 @@ private static int zzUnpackcmap_top(String packed, int offset, int [] result) { "\11\0\1\1\1\2\2\0\1\3\22\0\1\1\1\4"+ "\1\5\1\0\1\6\1\7\1\10\1\11\1\12\1\13"+ "\1\14\1\15\1\16\1\17\1\20\1\21\1\22\11\23"+ - "\1\24\1\25\1\26\1\27\1\30\2\0\6\31\21\20"+ - "\1\32\2\20\1\33\1\34\1\35\1\36\1\37\1\0"+ - "\1\40\1\41\1\42\1\43\1\44\1\45\1\46\1\47"+ - "\1\50\2\20\1\51\1\52\1\53\1\54\2\20\1\55"+ - "\1\56\1\57\1\60\1\61\1\62\1\32\2\20\1\63"+ - "\1\64\1\65\1\66\u0181\0"; + "\1\24\1\25\1\26\1\27\1\30\2\0\6\31\5\20"+ + "\1\32\13\20\1\33\2\20\1\34\1\35\1\36\1\37"+ + "\1\40\1\0\1\41\1\42\1\43\1\44\1\45\1\46"+ + "\1\47\1\50\1\51\2\20\1\52\1\53\1\54\1\55"+ + "\2\20\1\56\1\57\1\60\1\61\1\62\1\63\1\33"+ + "\2\20\1\64\1\65\1\66\1\67\u0181\0"; private static int [] zzUnpackcmap_blocks() { int [] result = new int[512]; @@ -113,16 +113,16 @@ private static int zzUnpackcmap_blocks(String packed, int offset, int [] result) "\1\10\1\11\1\12\1\13\1\14\1\15\1\16\1\17"+ "\2\20\1\21\1\22\1\23\1\24\1\25\1\26\1\27"+ "\1\30\11\16\1\31\1\32\1\33\1\34\1\35\1\36"+ - "\1\37\1\1\2\40\4\20\1\41\1\0\2\16\1\42"+ - "\1\43\4\16\1\44\4\16\7\0\1\35\1\45\1\0"+ - "\1\46\2\47\1\20\12\16\7\0\1\35\1\50\1\20"+ - "\1\51\1\16\1\52\1\53\1\16\1\54\1\16\1\55"+ - "\1\16\1\56\1\16\6\0\2\16\1\57\1\16\1\60"+ - "\1\0\1\35\2\16\1\61\1\0\1\16\1\62\1\16"+ - "\1\63"; + "\1\37\1\1\2\40\4\20\1\41\1\0\1\42\2\16"+ + "\1\43\1\44\4\16\1\45\4\16\7\0\1\35\1\46"+ + "\1\42\1\0\1\47\2\50\1\20\12\16\7\0\1\35"+ + "\1\51\1\20\1\52\1\16\1\53\1\54\1\16\1\55"+ + "\1\16\1\56\1\16\1\57\1\16\6\0\2\16\1\60"+ + "\1\16\1\61\1\0\1\35\2\16\1\62\1\0\1\16"+ + "\1\63\1\16\1\64"; private static int [] zzUnpackAction() { - int [] result = new int[132]; + int [] result = new int[134]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; @@ -147,26 +147,26 @@ private static int zzUnpackAction(String packed, int offset, int [] result) { private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = - "\0\0\0\67\0\156\0\245\0\245\0\245\0\245\0\245"+ - "\0\245\0\245\0\245\0\245\0\245\0\334\0\245\0\u0113"+ - "\0\u014a\0\u0181\0\u01b8\0\u01ef\0\u014a\0\245\0\u0226\0\245"+ - "\0\u025d\0\245\0\245\0\245\0\u0294\0\u02cb\0\u0302\0\u0339"+ - "\0\u0370\0\u03a7\0\u03de\0\u0415\0\u044c\0\245\0\245\0\245"+ - "\0\245\0\u0483\0\245\0\u04ba\0\u04f1\0\245\0\u0528\0\u055f"+ - "\0\u0596\0\u05cd\0\u0604\0\u063b\0\u0672\0\u06a9\0\u06e0\0\245"+ - "\0\245\0\u0717\0\u074e\0\u0785\0\u07bc\0\u014a\0\u07f3\0\u082a"+ - "\0\u0861\0\u0898\0\u08cf\0\u0906\0\u093d\0\u0974\0\u09ab\0\u09e2"+ - "\0\u0a19\0\245\0\245\0\u0a50\0\u0a87\0\245\0\u0abe\0\u06a9"+ - "\0\u0af5\0\u0b2c\0\u0b63\0\u0b9a\0\u0bd1\0\u0c08\0\u0c3f\0\u0c76"+ - "\0\u0cad\0\u0ce4\0\u0d1b\0\u0d52\0\u0d89\0\u0dc0\0\u0df7\0\u0e2e"+ - "\0\u0e65\0\u0e9c\0\245\0\u0a50\0\245\0\u0ed3\0\u014a\0\u014a"+ - "\0\u0f0a\0\u014a\0\u0f41\0\u014a\0\u0f78\0\u014a\0\u0faf\0\u0fe6"+ - "\0\u101d\0\u1054\0\u108b\0\u10c2\0\u10f9\0\u1130\0\u1167\0\u014a"+ - "\0\u119e\0\u014a\0\u11d5\0\u120c\0\u1243\0\u127a\0\u014a\0\u12b1"+ - "\0\u12e8\0\u014a\0\u131f\0\u131f"; + "\0\0\0\70\0\160\0\250\0\250\0\250\0\250\0\250"+ + "\0\250\0\250\0\250\0\250\0\250\0\340\0\250\0\u0118"+ + "\0\u0150\0\u0188\0\u01c0\0\u01f8\0\u0150\0\250\0\u0230\0\250"+ + "\0\u0268\0\250\0\250\0\250\0\u02a0\0\u02d8\0\u0310\0\u0348"+ + "\0\u0380\0\u03b8\0\u03f0\0\u0428\0\u0460\0\250\0\250\0\250"+ + "\0\250\0\u0498\0\250\0\u04d0\0\u0508\0\250\0\u0540\0\u0578"+ + "\0\u05b0\0\u05e8\0\u0620\0\u0658\0\u0690\0\u0150\0\u06c8\0\u0700"+ + "\0\250\0\250\0\u0738\0\u0770\0\u07a8\0\u07e0\0\u0150\0\u0818"+ + "\0\u0850\0\u0888\0\u08c0\0\u08f8\0\u0930\0\u0968\0\u09a0\0\u09d8"+ + "\0\u0a10\0\u0a48\0\250\0\250\0\250\0\u0a80\0\u0ab8\0\250"+ + "\0\u0af0\0\u0b28\0\u0b60\0\u0b98\0\u0bd0\0\u0c08\0\u0c40\0\u0c78"+ + "\0\u0cb0\0\u0ce8\0\u0d20\0\u0d58\0\u0d90\0\u0dc8\0\u0e00\0\u0e38"+ + "\0\u0e70\0\u0ea8\0\u0ee0\0\u0f18\0\250\0\u0f50\0\250\0\u0f88"+ + "\0\u0150\0\u0150\0\u0fc0\0\u0150\0\u0ff8\0\u0150\0\u1030\0\u0150"+ + "\0\u1068\0\u10a0\0\u10d8\0\u1110\0\u1148\0\u1180\0\u11b8\0\u11f0"+ + "\0\u1228\0\u0150\0\u1260\0\u0150\0\u1298\0\u12d0\0\u1308\0\u1340"+ + "\0\u0150\0\u1378\0\u13b0\0\u0150\0\u13e8\0\u13e8"; private static int [] zzUnpackRowMap() { - int [] result = new int[132]; + int [] result = new int[134]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; @@ -191,103 +191,109 @@ private static int zzUnpackRowMap(String packed, int offset, int [] result) { private static final String ZZ_TRANS_PACKED_0 = "\1\4\3\5\1\6\1\7\1\10\1\11\1\12\1\4"+ "\1\13\1\14\1\15\1\16\1\17\1\20\1\21\1\22"+ - "\1\23\1\24\1\25\1\26\1\27\1\30\1\31\2\21"+ + "\1\23\1\24\1\25\1\26\1\27\1\30\1\31\3\21"+ "\1\32\1\4\1\33\1\34\3\21\1\35\1\36\1\37"+ "\1\40\2\21\1\41\2\21\1\42\1\21\1\43\1\21"+ "\1\44\2\21\1\45\1\46\1\47\1\50\1\51\2\52"+ - "\2\4\1\52\1\53\20\52\1\54\5\52\1\55\32\52"+ - "\14\56\1\57\52\56\104\0\1\21\2\0\1\21\1\0"+ - "\1\60\1\61\1\21\4\0\2\21\4\0\24\21\26\0"+ - "\1\62\1\63\60\0\1\21\2\0\1\21\1\0\3\21"+ - "\4\0\2\21\4\0\24\21\20\0\1\64\4\0\1\65"+ - "\62\0\1\21\2\0\1\21\1\0\2\24\1\21\4\0"+ - "\1\21\1\66\4\0\1\67\23\21\21\0\1\21\2\0"+ - "\1\21\1\0\2\24\1\21\4\0\2\21\4\0\1\67"+ - "\23\21\33\0\1\70\66\0\1\71\54\0\1\21\2\0"+ - "\1\21\1\0\3\21\4\0\2\21\4\0\1\21\1\72"+ - "\22\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ - "\2\21\4\0\5\21\1\73\16\21\21\0\1\21\2\0"+ - "\1\21\1\0\3\21\4\0\2\21\4\0\12\21\1\74"+ - "\11\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ - "\2\21\4\0\1\21\1\75\22\21\21\0\1\21\2\0"+ - "\1\21\1\0\3\21\4\0\2\21\4\0\6\21\1\76"+ + "\2\4\1\52\1\53\20\52\1\54\6\52\1\55\32\52"+ + "\14\56\1\57\53\56\105\0\1\21\2\0\1\21\1\0"+ + "\1\60\1\61\1\21\4\0\3\21\4\0\24\21\26\0"+ + "\1\62\1\63\61\0\1\21\2\0\1\21\1\0\3\21"+ + "\4\0\3\21\4\0\24\21\20\0\1\64\4\0\1\65"+ + "\63\0\1\21\2\0\1\21\1\0\2\24\1\21\4\0"+ + "\1\21\1\66\1\67\4\0\1\70\11\21\1\66\11\21"+ + "\21\0\1\21\2\0\1\21\1\0\2\24\1\21\4\0"+ + "\1\21\1\66\1\21\4\0\1\70\11\21\1\66\11\21"+ + "\33\0\1\71\67\0\1\72\55\0\1\21\2\0\1\21"+ + "\1\0\3\21\4\0\3\21\4\0\1\21\1\73\22\21"+ + "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\3\21"+ + "\4\0\5\21\1\74\16\21\21\0\1\21\2\0\1\21"+ + "\1\0\3\21\4\0\3\21\4\0\12\21\1\75\11\21"+ + "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\3\21"+ + "\4\0\1\21\1\76\22\21\21\0\1\21\2\0\1\21"+ + "\1\0\3\21\4\0\3\21\4\0\6\21\1\77\15\21"+ + "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\3\21"+ + "\4\0\21\21\1\100\2\21\21\0\1\21\2\0\1\21"+ + "\1\0\3\21\4\0\3\21\4\0\5\21\1\101\16\21"+ + "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\3\21"+ + "\4\0\16\21\1\102\5\21\21\0\1\21\2\0\1\21"+ + "\1\0\3\21\4\0\3\21\4\0\10\21\1\103\13\21"+ + "\4\0\2\52\2\0\1\52\1\0\20\52\1\0\6\52"+ + "\1\0\32\52\21\0\1\104\20\0\1\105\1\106\3\0"+ + "\1\107\1\0\1\110\1\107\4\0\1\111\1\0\1\112"+ + "\13\0\1\113\3\0\1\113\23\0\1\113\3\0\2\113"+ + "\3\0\1\113\5\0\1\113\1\0\1\113\1\0\1\113"+ + "\1\0\1\113\26\0\1\114\63\0\1\21\2\0\1\21"+ + "\1\0\2\61\1\21\4\0\1\21\1\66\1\67\4\0"+ + "\12\21\1\66\11\21\21\0\1\21\2\0\1\21\1\0"+ + "\2\61\1\21\4\0\1\21\1\66\1\21\4\0\12\21"+ + "\1\66\11\21\26\0\2\63\6\0\1\115\1\116\16\0"+ + "\1\115\37\0\2\63\6\0\1\115\17\0\1\115\31\0"+ + "\1\117\53\0\2\65\1\120\1\121\64\65\15\0\1\21"+ + "\2\0\1\21\1\0\2\122\1\21\4\0\1\122\2\21"+ + "\4\0\1\21\6\122\15\21\21\0\1\21\2\0\1\21"+ + "\1\0\2\123\1\21\4\0\3\21\4\0\24\21\21\0"+ + "\1\21\2\0\1\21\1\0\3\21\4\0\3\21\4\0"+ + "\12\21\1\124\4\21\1\125\4\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\6\21\1\126"+ "\15\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ - "\2\21\4\0\21\21\1\77\2\21\21\0\1\21\2\0"+ - "\1\21\1\0\3\21\4\0\2\21\4\0\5\21\1\100"+ - "\16\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ - "\2\21\4\0\16\21\1\101\5\21\21\0\1\21\2\0"+ - "\1\21\1\0\3\21\4\0\2\21\4\0\10\21\1\102"+ - "\13\21\4\0\2\52\2\0\1\52\1\0\20\52\1\0"+ - "\5\52\1\0\32\52\21\0\1\103\17\0\1\104\1\105"+ - "\3\0\1\106\1\0\1\107\1\106\4\0\1\110\1\0"+ - "\1\111\13\0\1\112\3\0\1\112\22\0\1\112\3\0"+ - "\2\112\3\0\1\112\5\0\1\112\1\0\1\112\1\0"+ - "\1\112\1\0\1\112\26\0\1\113\62\0\1\21\2\0"+ - "\1\21\1\0\2\61\1\21\4\0\1\21\1\66\4\0"+ - "\24\21\21\0\1\21\2\0\1\21\1\0\2\61\1\21"+ - "\4\0\2\21\4\0\24\21\26\0\2\63\6\0\1\114"+ - "\56\0\2\63\57\0\1\115\52\0\2\65\1\116\1\117"+ - "\63\65\15\0\1\21\2\0\1\21\1\0\2\120\1\21"+ - "\4\0\1\120\1\21\4\0\1\21\6\120\15\21\21\0"+ - "\1\21\2\0\1\21\1\0\2\121\1\21\4\0\2\21"+ - "\4\0\24\21\21\0\1\21\2\0\1\21\1\0\3\21"+ - "\4\0\2\21\4\0\12\21\1\122\4\21\1\123\4\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\6\21\1\124\15\21\21\0\1\21\2\0\1\21"+ - "\1\0\3\21\4\0\2\21\4\0\17\21\1\125\4\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\12\21\1\126\11\21\21\0\1\21\2\0\1\21"+ - "\1\0\3\21\4\0\2\21\4\0\12\21\1\127\11\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\20\21\1\130\3\21\21\0\1\21\2\0\1\21"+ - "\1\0\3\21\4\0\2\21\4\0\21\21\1\131\2\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\11\21\1\132\12\21\46\0\1\133\13\0\1\134"+ - "\1\0\1\135\63\0\1\135\65\0\1\136\71\0\1\135"+ - "\61\0\1\137\63\0\1\140\7\0\1\141\36\0\1\142"+ - "\1\143\60\0\2\144\5\0\1\144\6\0\6\144\42\0"+ - "\1\145\47\0\1\116\101\0\1\21\2\0\1\21\1\0"+ - "\2\121\1\21\4\0\2\21\4\0\1\146\23\21\21\0"+ - "\1\21\2\0\1\21\1\0\3\21\4\0\2\21\4\0"+ - "\3\21\1\147\20\21\21\0\1\21\2\0\1\21\1\0"+ - "\3\21\4\0\2\21\4\0\5\21\1\150\16\21\21\0"+ - "\1\21\2\0\1\21\1\0\3\21\4\0\2\21\4\0"+ - "\1\21\1\151\22\21\21\0\1\21\2\0\1\21\1\0"+ - "\3\21\4\0\2\21\4\0\5\21\1\152\16\21\21\0"+ - "\1\21\2\0\1\21\1\0\3\21\4\0\2\21\4\0"+ - "\17\21\1\153\4\21\21\0\1\21\2\0\1\21\1\0"+ - "\3\21\4\0\2\21\4\0\12\21\1\154\11\21\21\0"+ - "\1\21\2\0\1\21\1\0\3\21\4\0\2\21\4\0"+ - "\21\21\1\155\2\21\21\0\1\21\2\0\1\21\1\0"+ - "\3\21\4\0\2\21\4\0\5\21\1\156\16\21\21\0"+ - "\1\21\2\0\1\21\1\0\3\21\4\0\2\21\4\0"+ - "\12\21\1\157\11\21\60\0\1\160\61\0\1\161\7\0"+ - "\1\104\37\0\1\143\107\0\1\162\63\0\1\163\60\0"+ - "\1\164\103\0\1\111\33\0\2\165\5\0\1\165\6\0"+ - "\6\165\36\0\1\21\2\0\1\21\1\0\2\166\1\21"+ - "\4\0\2\21\4\0\24\21\21\0\1\21\2\0\1\21"+ - "\1\0\3\21\4\0\2\21\4\0\21\21\1\167\2\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\5\21\1\170\16\21\21\0\1\21\2\0\1\21"+ - "\1\0\3\21\4\0\2\21\4\0\16\21\1\171\5\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\5\21\1\172\16\21\55\0\1\135\55\0\1\173"+ - "\55\0\1\142\66\0\1\174\102\0\1\162\45\0\2\165"+ - "\4\0\1\143\1\165\6\0\6\165\36\0\1\21\2\0"+ - "\1\21\1\0\2\166\1\21\4\0\2\21\4\0\1\175"+ - "\23\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ - "\2\21\4\0\12\21\1\176\11\21\21\0\1\21\2\0"+ - "\1\21\1\0\3\21\4\0\2\21\4\0\14\21\1\177"+ - "\7\21\47\0\1\135\45\0\2\200\60\0\1\21\2\0"+ - "\1\21\1\0\2\201\1\21\4\0\2\21\4\0\24\21"+ - "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\2\21"+ - "\4\0\20\21\1\202\3\21\26\0\2\200\4\0\1\143"+ - "\53\0\1\21\2\0\1\21\1\0\2\201\1\21\4\0"+ - "\2\21\4\0\1\203\23\21\21\0\1\21\2\0\1\21"+ - "\1\0\2\204\1\21\4\0\2\21\4\0\24\21\4\0"; + "\3\21\4\0\17\21\1\127\4\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\12\21\1\130"+ + "\11\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ + "\3\21\4\0\12\21\1\131\11\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\20\21\1\132"+ + "\3\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ + "\3\21\4\0\21\21\1\133\2\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\11\21\1\134"+ + "\12\21\47\0\1\135\13\0\1\136\1\0\1\137\64\0"+ + "\1\137\66\0\1\140\72\0\1\137\62\0\1\141\64\0"+ + "\1\142\7\0\1\143\36\0\1\144\1\145\61\0\2\146"+ + "\5\0\1\146\7\0\6\146\42\0\1\147\50\0\1\120"+ + "\102\0\1\21\2\0\1\21\1\0\2\122\1\21\4\0"+ + "\1\122\1\66\1\21\4\0\1\21\6\122\3\21\1\66"+ + "\11\21\21\0\1\21\2\0\1\21\1\0\2\123\1\21"+ + "\4\0\3\21\4\0\1\150\23\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\3\21\1\151"+ + "\20\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ + "\3\21\4\0\5\21\1\152\16\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\1\21\1\153"+ + "\22\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ + "\3\21\4\0\5\21\1\154\16\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\17\21\1\155"+ + "\4\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ + "\3\21\4\0\12\21\1\156\11\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\21\21\1\157"+ + "\2\21\21\0\1\21\2\0\1\21\1\0\3\21\4\0"+ + "\3\21\4\0\5\21\1\160\16\21\21\0\1\21\2\0"+ + "\1\21\1\0\3\21\4\0\3\21\4\0\12\21\1\161"+ + "\11\21\61\0\1\162\62\0\1\163\7\0\1\105\37\0"+ + "\1\145\111\0\1\164\64\0\1\165\61\0\1\166\104\0"+ + "\1\112\33\0\2\167\5\0\1\167\7\0\6\167\43\0"+ + "\2\146\5\0\1\146\1\115\6\0\6\146\3\0\1\115"+ + "\32\0\1\21\2\0\1\21\1\0\2\170\1\21\4\0"+ + "\3\21\4\0\24\21\21\0\1\21\2\0\1\21\1\0"+ + "\3\21\4\0\3\21\4\0\21\21\1\171\2\21\21\0"+ + "\1\21\2\0\1\21\1\0\3\21\4\0\3\21\4\0"+ + "\5\21\1\172\16\21\21\0\1\21\2\0\1\21\1\0"+ + "\3\21\4\0\3\21\4\0\16\21\1\173\5\21\21\0"+ + "\1\21\2\0\1\21\1\0\3\21\4\0\3\21\4\0"+ + "\5\21\1\174\16\21\56\0\1\137\56\0\1\175\55\0"+ + "\1\144\67\0\1\176\104\0\1\164\45\0\2\167\4\0"+ + "\1\145\1\167\7\0\6\167\36\0\1\21\2\0\1\21"+ + "\1\0\2\170\1\21\4\0\3\21\4\0\1\177\23\21"+ + "\21\0\1\21\2\0\1\21\1\0\3\21\4\0\3\21"+ + "\4\0\12\21\1\200\11\21\21\0\1\21\2\0\1\21"+ + "\1\0\3\21\4\0\3\21\4\0\14\21\1\201\7\21"+ + "\50\0\1\137\45\0\2\202\61\0\1\21\2\0\1\21"+ + "\1\0\2\203\1\21\4\0\3\21\4\0\24\21\21\0"+ + "\1\21\2\0\1\21\1\0\3\21\4\0\3\21\4\0"+ + "\20\21\1\204\3\21\26\0\2\202\4\0\1\145\54\0"+ + "\1\21\2\0\1\21\1\0\2\203\1\21\4\0\3\21"+ + "\4\0\1\205\23\21\21\0\1\21\2\0\1\21\1\0"+ + "\2\206\1\21\4\0\3\21\4\0\24\21\4\0"; private static int [] zzUnpacktrans() { - int [] result = new int[4950]; + int [] result = new int[5152]; int offset = 0; offset = zzUnpacktrans(ZZ_TRANS_PACKED_0, offset, result); return result; @@ -327,12 +333,12 @@ private static int zzUnpacktrans(String packed, int offset, int [] result) { private static final String ZZ_ATTRIBUTE_PACKED_0 = "\3\0\12\11\1\1\1\11\6\1\1\11\1\1\1\11"+ "\1\1\3\11\11\1\4\11\1\1\1\11\2\1\1\11"+ - "\6\1\1\0\2\1\2\11\11\1\7\0\2\11\1\0"+ + "\6\1\1\0\3\1\2\11\11\1\7\0\3\11\1\0"+ "\1\1\1\11\14\1\7\0\1\1\1\11\1\1\1\11"+ "\12\1\6\0\5\1\1\0\4\1\1\0\4\1"; private static int [] zzUnpackAttribute() { - int [] result = new int[132]; + int [] result = new int[134]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; @@ -661,13 +667,13 @@ else if (zzAtEOF) { popState(); return state == DOC_COMMENT ? RsTokenTypes.DOC_COMMENT : RsTokenTypes.BLOCK_COMMENT; } // fall though - case 133: break; + case 135: break; case DOC_COMMENT: { int state = yystate(); popState(); return state == DOC_COMMENT ? RsTokenTypes.DOC_COMMENT : RsTokenTypes.BLOCK_COMMENT; } // fall though - case 134: break; + case 136: break; default: return null; } @@ -678,67 +684,67 @@ else if (zzAtEOF) { { return TokenType.BAD_CHARACTER; } // fall through - case 52: break; + case 53: break; case 2: { return TokenType.WHITE_SPACE; } // fall through - case 53: break; + case 54: break; case 3: { return EXCEL; } // fall through - case 54: break; + case 55: break; case 4: { pushState(STRING); return STRING_START; } // fall through - case 55: break; + case 56: break; case 5: { return DOLLAR; } // fall through - case 56: break; + case 57: break; case 6: { return PERCENT; } // fall through - case 57: break; + case 58: break; case 7: { return AMPERSAND; } // fall through - case 58: break; + case 59: break; case 8: { return LPAREN; } // fall through - case 59: break; + case 60: break; case 9: { return RPAREN; } // fall through - case 60: break; + case 61: break; case 10: { return STAR; } // fall through - case 61: break; + case 62: break; case 11: { return PLUS; } // fall through - case 62: break; + case 63: break; case 12: { return COMMA; } // fall through - case 63: break; + case 64: break; case 13: { return MINUS; } // fall through - case 64: break; + case 65: break; case 14: { CharSequence lexeme = yytext(); for (String typeName: getTypeNames()) { @@ -778,37 +784,37 @@ else if (zzAtEOF) { return IDENTIFIER; } // fall through - case 65: break; + case 66: break; case 15: { return SLASH; } // fall through - case 66: break; + case 67: break; case 16: { return INTEGER; } // fall through - case 67: break; + case 68: break; case 17: { return COLON; } // fall through - case 68: break; + case 69: break; case 18: { return SEMICOLON; } // fall through - case 69: break; + case 70: break; case 19: { return LT; } // fall through - case 70: break; + case 71: break; case 20: { return EQUAL; } // fall through - case 71: break; + case 72: break; case 21: { if (yystate() == STRING_INTERPOLATION) { popState(); @@ -818,159 +824,164 @@ else if (zzAtEOF) { } } // fall through - case 72: break; + case 73: break; case 22: { return LBRACKET; } // fall through - case 73: break; + case 74: break; case 23: { return RBRACKET; } // fall through - case 74: break; + case 75: break; case 24: { return CARET; } // fall through - case 75: break; + case 76: break; case 25: { return LBRACE; } // fall through - case 76: break; + case 77: break; case 26: { return BAR; } // fall through - case 77: break; + case 78: break; case 27: { return RBRACE; } // fall through - case 78: break; + case 79: break; case 28: { return TILDE; } // fall through - case 79: break; + case 80: break; case 29: { return STRING_PART; } // fall through - case 80: break; + case 81: break; case 30: { popState(); return STRING_END; } // fall through - case 81: break; + case 82: break; case 31: { pushState(STRING_INTERPOLATION); return STRING_INTERPOLATION_START; } // fall through - case 82: break; + case 83: break; case 32: { } // fall through - case 83: break; + case 84: break; case 33: { pushState(BLOCK_COMMENT); } // fall through - case 84: break; + case 85: break; case 34: - { return LTE; + { return LONG; } // fall through - case 85: break; + case 86: break; case 35: - { return GTE; + { return LTE; } // fall through - case 86: break; + case 87: break; case 36: - { return IF; + { return GTE; } // fall through - case 87: break; + case 88: break; case 37: + { return IF; + } + // fall through + case 89: break; + case 38: { int state = yystate(); popState(); return state == DOC_COMMENT ? RsTokenTypes.DOC_COMMENT : RsTokenTypes.BLOCK_COMMENT; } // fall through - case 88: break; - case 38: + case 90: break; + case 39: { pushState(DOC_COMMENT); } // fall through - case 89: break; - case 39: + case 91: break; + case 40: { return LINE_COMMENT; } // fall through - case 90: break; - case 40: + case 92: break; + case 41: { return STRING_TAG; } // fall through - case 91: break; - case 41: + case 93: break; + case 42: { return RsTokenTypes.BLOCK_COMMENT; } // fall through - case 92: break; - case 42: + case 94: break; + case 43: { return CALC; } // fall through - case 93: break; - case 43: + case 95: break; + case 44: { return CASE; } // fall through - case 94: break; - case 44: + case 96: break; + case 45: { return ELSE; } // fall through - case 95: break; - case 45: + case 97: break; + case 46: { return NULL; } // fall through - case 96: break; - case 46: + case 98: break; + case 47: { return TRUE; } // fall through - case 97: break; - case 47: + case 99: break; + case 48: { return FALSE; } // fall through - case 98: break; - case 48: + case 100: break; + case 49: { return WHILE; } // fall through - case 99: break; - case 49: + case 101: break; + case 50: { return RETURN; } // fall through - case 100: break; - case 50: + case 102: break; + case 51: { return DEFAULT; } // fall through - case 101: break; - case 51: + case 103: break; + case 52: { return COORDGRID; } // fall through - case 102: break; + case 104: break; default: zzScanError(ZZ_NO_MATCH); } diff --git a/src/main/gen/io/runescript/plugin/lang/parser/RsParser.java b/src/main/gen/io/runescript/plugin/lang/parser/RsParser.java index ad627c4..e2e168a 100644 --- a/src/main/gen/io/runescript/plugin/lang/parser/RsParser.java +++ b/src/main/gen/io/runescript/plugin/lang/parser/RsParser.java @@ -50,9 +50,9 @@ static boolean parse_root_(IElementType t, PsiBuilder b, int l) { create_token_set_(ARITHMETIC_EXPRESSION, ARITHMETIC_VALUE_EXPRESSION, ARRAY_ACCESS_EXPRESSION, BOOLEAN_LITERAL_EXPRESSION, CALC_EXPRESSION, COMMAND_EXPRESSION, CONDITION_EXPRESSION, CONSTANT_EXPRESSION, COORD_LITERAL_EXPRESSION, DYNAMIC_EXPRESSION, EXPRESSION, GOSUB_EXPRESSION, - INTEGER_LITERAL_EXPRESSION, LOCAL_VARIABLE_EXPRESSION, NULL_LITERAL_EXPRESSION, PAR_EXPRESSION, - RELATIONAL_VALUE_EXPRESSION, SCOPED_VARIABLE_EXPRESSION, STRING_INTERPOLATION_EXPRESSION, STRING_LITERAL_EXPRESSION, - SWITCH_CASE_DEFAULT_EXPRESSION), + INTEGER_LITERAL_EXPRESSION, LOCAL_VARIABLE_EXPRESSION, LONG_LITERAL_EXPRESSION, NULL_LITERAL_EXPRESSION, + PAR_EXPRESSION, RELATIONAL_VALUE_EXPRESSION, SCOPED_VARIABLE_EXPRESSION, STRING_INTERPOLATION_EXPRESSION, + STRING_LITERAL_EXPRESSION, SWITCH_CASE_DEFAULT_EXPRESSION), }; /* ********************************************************** */ @@ -776,6 +776,7 @@ public static boolean IntegerLiteralExpression(PsiBuilder b, int l) { /* ********************************************************** */ // IntegerLiteralExpression + // | LongLiteralExpression // | CoordLiteralExpression // | BooleanLiteralExpression // | NullLiteralExpression @@ -785,6 +786,7 @@ static boolean LiteralExpression(PsiBuilder b, int l) { boolean r; Marker m = enter_section_(b, l, _NONE_, null, ""); r = IntegerLiteralExpression(b, l + 1); + if (!r) r = LongLiteralExpression(b, l + 1); if (!r) r = CoordLiteralExpression(b, l + 1); if (!r) r = BooleanLiteralExpression(b, l + 1); if (!r) r = NullLiteralExpression(b, l + 1); @@ -936,6 +938,18 @@ private static boolean LogicalOrWrapper_1(PsiBuilder b, int l) { return true; } + /* ********************************************************** */ + // LONG + public static boolean LongLiteralExpression(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "LongLiteralExpression")) return false; + if (!nextTokenIs(b, "", LONG)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, LONG_LITERAL_EXPRESSION, ""); + r = consumeToken(b, LONG); + exit_section_(b, l, m, r, false, null); + return r; + } + /* ********************************************************** */ // IDENTIFIER | DEFINE_TYPE | TYPE_LITERAL | ARRAY_TYPE_LITERAL | WHILE | IF | TRUE | FALSE | NULL | SWITCH public static boolean NameLiteral(PsiBuilder b, int l) { diff --git a/src/main/gen/io/runescript/plugin/lang/psi/RsElementTypes.java b/src/main/gen/io/runescript/plugin/lang/psi/RsElementTypes.java index 70145e9..0bf874d 100644 --- a/src/main/gen/io/runescript/plugin/lang/psi/RsElementTypes.java +++ b/src/main/gen/io/runescript/plugin/lang/psi/RsElementTypes.java @@ -36,6 +36,7 @@ public interface RsElementTypes { IElementType INTEGER_LITERAL_EXPRESSION = new RsElementType("INTEGER_LITERAL_EXPRESSION"); IElementType LOCAL_VARIABLE_DECLARATION_STATEMENT = new RsElementType("LOCAL_VARIABLE_DECLARATION_STATEMENT"); IElementType LOCAL_VARIABLE_EXPRESSION = StubElementTypeFactory.create("LOCAL_VARIABLE_EXPRESSION"); + IElementType LONG_LITERAL_EXPRESSION = new RsElementType("LONG_LITERAL_EXPRESSION"); IElementType NAME_LITERAL = StubElementTypeFactory.create("NAME_LITERAL"); IElementType NULL_LITERAL_EXPRESSION = new RsElementType("NULL_LITERAL_EXPRESSION"); IElementType PARAMETER = StubElementTypeFactory.create("PARAMETER"); @@ -80,6 +81,7 @@ public interface RsElementTypes { IElementType INTEGER = new RsElementType("INTEGER"); IElementType LBRACE = new RsElementType("{"); IElementType LBRACKET = new RsElementType("["); + IElementType LONG = new RsElementType("LONG"); IElementType LPAREN = new RsElementType("("); IElementType LT = new RsElementType("<"); IElementType LTE = new RsElementType("<="); @@ -187,6 +189,9 @@ else if (type == LOCAL_VARIABLE_DECLARATION_STATEMENT) { else if (type == LOCAL_VARIABLE_EXPRESSION) { return new RsLocalVariableExpressionImpl(node); } + else if (type == LONG_LITERAL_EXPRESSION) { + return new RsLongLiteralExpressionImpl(node); + } else if (type == NAME_LITERAL) { return new RsNameLiteralImpl(node); } diff --git a/src/main/gen/io/runescript/plugin/lang/psi/RsLongLiteralExpression.java b/src/main/gen/io/runescript/plugin/lang/psi/RsLongLiteralExpression.java new file mode 100644 index 0000000..bd7e466 --- /dev/null +++ b/src/main/gen/io/runescript/plugin/lang/psi/RsLongLiteralExpression.java @@ -0,0 +1,13 @@ +// This class is automatically generated. Do not edit. +package io.runescript.plugin.lang.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface RsLongLiteralExpression extends RsExpression { + + @NotNull + PsiElement getLong(); + +} diff --git a/src/main/gen/io/runescript/plugin/lang/psi/RsVisitor.java b/src/main/gen/io/runescript/plugin/lang/psi/RsVisitor.java index 2c39a78..b631afd 100644 --- a/src/main/gen/io/runescript/plugin/lang/psi/RsVisitor.java +++ b/src/main/gen/io/runescript/plugin/lang/psi/RsVisitor.java @@ -126,6 +126,10 @@ public void visitLocalVariableExpression(@NotNull RsLocalVariableExpression o) { // visitNamedElement(o); } + public void visitLongLiteralExpression(@NotNull RsLongLiteralExpression o) { + visitExpression(o); + } + public void visitNameLiteral(@NotNull RsNameLiteral o) { visitPsiElement(o); } diff --git a/src/main/gen/io/runescript/plugin/lang/psi/impl/RsLongLiteralExpressionImpl.java b/src/main/gen/io/runescript/plugin/lang/psi/impl/RsLongLiteralExpressionImpl.java new file mode 100644 index 0000000..5d93a6d --- /dev/null +++ b/src/main/gen/io/runescript/plugin/lang/psi/impl/RsLongLiteralExpressionImpl.java @@ -0,0 +1,36 @@ +// This class is automatically generated. Do not edit. +package io.runescript.plugin.lang.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static io.runescript.plugin.lang.psi.RsElementTypes.*; +import io.runescript.plugin.lang.psi.*; + +public class RsLongLiteralExpressionImpl extends RsExpressionImpl implements RsLongLiteralExpression { + + public RsLongLiteralExpressionImpl(@NotNull ASTNode node) { + super(node); + } + + @Override + public void accept(@NotNull RsVisitor visitor) { + visitor.visitLongLiteralExpression(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof RsVisitor) accept((RsVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public PsiElement getLong() { + return notNullChild(findChildByType(LONG)); + } + +} diff --git a/src/main/grammars/RuneScript.bnf b/src/main/grammars/RuneScript.bnf index 12319be..e82dfb5 100644 --- a/src/main/grammars/RuneScript.bnf +++ b/src/main/grammars/RuneScript.bnf @@ -240,11 +240,13 @@ ScopedVariableExpression ::= '%' NameLiteral { } private LiteralExpression ::= IntegerLiteralExpression + | LongLiteralExpression | CoordLiteralExpression | BooleanLiteralExpression | NullLiteralExpression | StringLiteralExpression IntegerLiteralExpression ::= INTEGER +LongLiteralExpression ::= LONG CoordLiteralExpression ::= COORDGRID BooleanLiteralExpression ::= TRUE | FALSE NullLiteralExpression ::= NULL diff --git a/src/main/grammars/RuneScript.flex b/src/main/grammars/RuneScript.flex index 8a564d8..c6dd887 100644 --- a/src/main/grammars/RuneScript.flex +++ b/src/main/grammars/RuneScript.flex @@ -47,9 +47,12 @@ IDENTIFIER = ({IDENTIFIER_PART})+ DECIMAL_DIGIT = [0-9] HEX_DIGIT = [0-9a-fA-F] HEX_INTEGER = 0[xX]({HEX_DIGIT})+ +LONG_HEX_INTEGER = 0[xX]({HEX_DIGIT})+ [lL] DECIMAL_INTEGER = (({DECIMAL_DIGIT})+) +LONG_DECIMAL_INTEGER = (({DECIMAL_DIGIT})+) [lL] COORDGRID = {DECIMAL_INTEGER}_{DECIMAL_INTEGER}_{DECIMAL_INTEGER}_{DECIMAL_INTEGER}_{DECIMAL_INTEGER} INTEGER = ([-+]?)(({DECIMAL_INTEGER})|({HEX_INTEGER})) +LONG = ([-+]?)(({LONG_DECIMAL_INTEGER})|({LONG_HEX_INTEGER})) STRING_ESCAPE_SEQUENCE=\\([abfnrtv\'\"\\]) STRING_PART = [^\"\r\n<\\]+ @@ -99,6 +102,7 @@ INCOMPLETE_TAG = "<"(shad|col|str|u|img)"=" \" { pushState(STRING); return STRING_START; } {COORDGRID} { return COORDGRID; } +{LONG} { return LONG; } {INTEGER} { return INTEGER; } diff --git a/src/main/kotlin/io/runescript/plugin/ide/codeInsight/RsInlayParameterHintsProvider.kt b/src/main/kotlin/io/runescript/plugin/ide/codeInsight/RsInlayParameterHintsProvider.kt index 7ac899b..466eba8 100644 --- a/src/main/kotlin/io/runescript/plugin/ide/codeInsight/RsInlayParameterHintsProvider.kt +++ b/src/main/kotlin/io/runescript/plugin/ide/codeInsight/RsInlayParameterHintsProvider.kt @@ -61,6 +61,7 @@ class RsInlayParameterHintsProvider : InlayParameterHintsProvider { unwrappedExpression = unwrappedExpression.expression } return unwrappedExpression !is RsIntegerLiteralExpression + && unwrappedExpression !is RsLongLiteralExpression && unwrappedExpression !is RsBooleanLiteralExpression && unwrappedExpression !is RsStringLiteralExpression && unwrappedExpression !is RsNullLiteralExpression diff --git a/src/main/kotlin/io/runescript/plugin/ide/codeInsight/controlFlow/RsControlFlowBuilder.kt b/src/main/kotlin/io/runescript/plugin/ide/codeInsight/controlFlow/RsControlFlowBuilder.kt index 91e74d3..5745b5d 100644 --- a/src/main/kotlin/io/runescript/plugin/ide/codeInsight/controlFlow/RsControlFlowBuilder.kt +++ b/src/main/kotlin/io/runescript/plugin/ide/codeInsight/controlFlow/RsControlFlowBuilder.kt @@ -281,6 +281,10 @@ class RsControlFlowBuilder : ControlFlowBuilder() { addInstruction(o) } + override fun visitLongLiteralExpression(o: RsLongLiteralExpression) { + addInstruction(o) + } + override fun visitCoordLiteralExpression(o: RsCoordLiteralExpression) { addInstruction(o) } diff --git a/src/main/kotlin/io/runescript/plugin/ide/highlight/RsSyntaxHighlighter.kt b/src/main/kotlin/io/runescript/plugin/ide/highlight/RsSyntaxHighlighter.kt index 9670e43..d4599b4 100644 --- a/src/main/kotlin/io/runescript/plugin/ide/highlight/RsSyntaxHighlighter.kt +++ b/src/main/kotlin/io/runescript/plugin/ide/highlight/RsSyntaxHighlighter.kt @@ -33,6 +33,7 @@ class RsSyntaxHighlighter(private val lexerInfo: RsLexerInfo) : SyntaxHighlighte init { attributes[IDENTIFIER] = RsSyntaxHighlighterColors.IDENTIFIER attributes[INTEGER] = RsSyntaxHighlighterColors.NUMBER + attributes[LONG] = RsSyntaxHighlighterColors.NUMBER fillMap(attributes, KEYWORDS, RsSyntaxHighlighterColors.KEYWORD) attributes[TYPE_LITERAL] = RsSyntaxHighlighterColors.TYPE_LITERAL attributes[ARRAY_TYPE_LITERAL] = RsSyntaxHighlighterColors.ARRAY_TYPE_LITERAL diff --git a/src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/RsTypeInferenceVisitor.kt b/src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/RsTypeInferenceVisitor.kt index a62aba5..bf2e078 100644 --- a/src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/RsTypeInferenceVisitor.kt +++ b/src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/RsTypeInferenceVisitor.kt @@ -117,38 +117,51 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV return RsTupleType(flatten()) } - private fun checkTypeMismatch(context: PsiElement, actualType: RsType?, expectedType: RsType?) { + private fun checkTypeMismatchAll(context: PsiElement, actualType: RsType?, expectedTypes: List): Boolean { + return expectedTypes.all { checkTypeMismatch(context, actualType, it, false) } + } + + private fun checkTypeMismatch( + context: PsiElement, + actualType: RsType?, + expectedType: RsType?, + reportError: Boolean = true + ): Boolean { val unfoldedActualType = actualType.unfold() ?: RsErrorType val unfoldedExpectedType = expectedType.unfold() ?: RsErrorType if (unfoldedActualType is RsErrorType || unfoldedExpectedType is RsErrorType) { - return + return false } if (unfoldedActualType is RsTupleType && RsErrorType in unfoldedActualType.types) { - return + return false } if (unfoldedExpectedType is RsTupleType && RsErrorType in unfoldedExpectedType.types) { - return + return false } if (unfoldedExpectedType == RsPrimitiveType.OBJ && unfoldedActualType == RsPrimitiveType.NAMEDOBJ) { // namedobj extends obj - return + return true } if (unfoldedExpectedType == RsPrimitiveType.FONTMETRICS && unfoldedActualType == RsPrimitiveType.GRAPHIC) { // graphic extends fontmetrics - return + return true } if (unfoldedExpectedType.isHookType() && unfoldedActualType == RsPrimitiveType.STRING) { // hooks are just strings that are parsed different. - return + return true } if (unfoldedActualType != unfoldedExpectedType) { - context.error( - "Type mismatch: '%s' was given but '%s' was expected".format( - unfoldedActualType.representation, - unfoldedExpectedType.representation + if (reportError) { + context.error( + "Type mismatch: '%s' was given but '%s' was expected".format( + unfoldedActualType.representation, + unfoldedExpectedType.representation + ) ) - ) + } + return false } + return true } override fun visitGosubExpression(o: RsGosubExpression) { @@ -280,10 +293,19 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV o.left.accept(this) if (valueRequiredType != null) { - o.right.typeHint = o.right.typeHint ?: o.left.type + o.right.typeHint = o.left.type ?: o.right.typeHint o.right.accept(this) - checkTypeMismatch(o.left, valueRequiredType) - checkTypeMismatch(o.right, valueRequiredType) + if (op.isRelational()) { + var expectedType = o.left.type ?: o.right.type + if (expectedType != RsPrimitiveType.LONG) { + expectedType = valueRequiredType + } + checkTypeMismatch(o.left, expectedType) + checkTypeMismatch(o.right, expectedType) + } else { + checkTypeMismatch(o.left, valueRequiredType) + checkTypeMismatch(o.right, valueRequiredType) + } } else { o.right.typeHint = o.left.type o.right.accept(this) @@ -416,11 +438,10 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV o.statementList.accept(this) } - override fun visitCalcExpression(o: RsCalcExpression) { - o.type = RsPrimitiveType.INT + o.type = o.typeHint ?: RsPrimitiveType.INT - o.expression.typeHint = RsPrimitiveType.INT + o.expression.typeHint = o.typeHint ?: RsPrimitiveType.INT o.expression.accept(this) } @@ -485,10 +506,10 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV } override fun visitArithmeticExpression(o: RsArithmeticExpression) { - o.left.typeHint = RsPrimitiveType.INT + o.left.typeHint = o.typeHint ?: RsPrimitiveType.INT o.left.accept(this) - o.right.typeHint = RsPrimitiveType.INT + o.right.typeHint = o.typeHint ?: RsPrimitiveType.INT o.right.accept(this) } @@ -540,16 +561,31 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV val trimmedValue: String if (value.startsWith("0x")) { radix = 16 - trimmedValue = value.substring(2) + trimmedValue = value.substring(2, value.length) } else { radix = 10 - trimmedValue = value + trimmedValue = value.substring(0, value.length) } if (trimmedValue.toIntOrNull(radix) == null) { o.error("Could not convert constant value '${value}' to an integer number.") } } + RsPrimitiveType.LONG -> { + val radix: Int + val trimmedValue: String + val endIndex = if (value.endsWith('L', ignoreCase = true)) value.length - 1 else value.length + if (value.startsWith("0x")) { + radix = 16 + trimmedValue = value.substring(2, endIndex) + } else { + radix = 10 + trimmedValue = value.substring(0, endIndex) + } + if (trimmedValue.toLongOrNull(radix) == null) { + o.error("Could not convert constant value '${value}' to a long number.") + } + } else -> { val configReference = RsSymbolIndex.lookup(o.project, type, value) if (configReference == null) { @@ -578,6 +614,10 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV o.type = RsPrimitiveType.INT } + override fun visitLongLiteralExpression(o: RsLongLiteralExpression) { + o.type = RsPrimitiveType.LONG + } + override fun visitCoordLiteralExpression(o: RsCoordLiteralExpression) { o.type = RsPrimitiveType.COORD } @@ -624,6 +664,12 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV ?.toTypedArray() checkExpressionList(o, o.expressionList, expectedReturnList ?: emptyArray()) } + companion object { + private val ALLOWED_RELATIONAL_TYPES = arrayOf( + RsPrimitiveType.INT, + RsPrimitiveType.LONG + ) + } } private fun RsScript.findCommandHandler(): CommandHandler {