Add math_expression and fix ast2 tests
This commit is contained in:
parent
305d90583e
commit
d2daf22df4
3 changed files with 29 additions and 3 deletions
|
|
@ -101,7 +101,7 @@ proc processNumberLiteral*(exprParser: ExprParser, node: TSNode): PNode =
|
|||
let nodeVal = node.val
|
||||
|
||||
var match: RegexMatch
|
||||
const reg = re"(\-)?(0\d+|0[xX][0-9a-fA-F]+|0[bB][01]+|\d+\.?\d*[fFlL]?|\d*\.?\d+[fFlL]?|\d+)([ulUL]*)"
|
||||
const reg = re"(\-)?(0\d+|0[xX][0-9a-fA-F]+|0[bB][01]+|\d+|\d+\.?\d*[fFlL]?|\d*\.?\d+[fFlL]?)([ulUL]*)"
|
||||
let found = nodeVal.find(reg, match)
|
||||
if found:
|
||||
let
|
||||
|
|
@ -199,6 +199,8 @@ proc processBitwiseExpression*(exprParser: ExprParser, node: TSNode): PNode =
|
|||
nimSym = "and"
|
||||
of "^":
|
||||
nimSym = "xor"
|
||||
of "+", "-", "*", "/":
|
||||
nimSym = binarySym
|
||||
else:
|
||||
raise newException(ExprParseError, &"Unsupported binary symbol \"{binarySym}\"")
|
||||
|
||||
|
|
@ -257,7 +259,7 @@ proc processTSNode*(exprParser: ExprParser, node: TSNode): PNode =
|
|||
|
||||
of "parenthesized_expression":
|
||||
result = exprParser.processParenthesizedExpr(node)
|
||||
of "bitwise_expression":
|
||||
of "bitwise_expression", "math_expression":
|
||||
result = exprParser.processBitwiseExpression(node)
|
||||
of "shift_expression":
|
||||
result = exprParser.processShiftExpression(node)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,18 @@ extern "C" {
|
|||
#define D "hello"
|
||||
#define E 'c'
|
||||
|
||||
#define UEXPR (1234u << 1)
|
||||
#define ULEXPR (1234ul << 2)
|
||||
#define ULLEXPR (1234ull << 3)
|
||||
#define LEXPR (1234l << 4)
|
||||
#define LLEXPR (1234ll << 5)
|
||||
|
||||
#define SHL1 (1u << 1)
|
||||
#define SHL2 (1u << 2)
|
||||
#define SHL3 (1u << 3)
|
||||
|
||||
#define ALLSHL (SHL1 | SHL2 | SHL3)
|
||||
|
||||
struct A0;
|
||||
struct A1 {};
|
||||
typedef struct A2;
|
||||
|
|
|
|||
|
|
@ -105,6 +105,18 @@ assert C == 0x10
|
|||
assert D == "hello"
|
||||
assert E == 'c'
|
||||
|
||||
assert UEXPR == (1234.uint shl 1)
|
||||
assert ULEXPR == (1234.uint32 shl 2)
|
||||
assert ULLEXPR == (1234.uint64 shl 3)
|
||||
assert LEXPR == (1234.int32 shl 4)
|
||||
assert LLEXPR == (1234.int64 shl 5)
|
||||
|
||||
assert SHL1 == (1.uint shl 1)
|
||||
assert SHL2 == (1.uint shl 2)
|
||||
assert SHL3 == (1.uint shl 3)
|
||||
|
||||
assert ALLSHL == (SHL1 or SHL2 or SHL3)
|
||||
|
||||
assert A0 is object
|
||||
testFields(A0, "f1!cint")
|
||||
checkPragmas(A0, pHeaderBy, istype = false)
|
||||
|
|
@ -271,7 +283,7 @@ var a21p: A21p
|
|||
a21p = addr a20
|
||||
|
||||
assert A22 is object
|
||||
testFields(A22, "f1|f2!ptr ptr cint|array[123 + 132, ptr cint]")
|
||||
testFields(A22, "f1|f2!ptr ptr cint|array[123 + cast[typeof(123)](132), ptr cint]")
|
||||
checkPragmas(A22, pHeaderBy, istype = false)
|
||||
var a22: A22
|
||||
a22.f1 = addr a15.a2[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue