]> git.tdb.fi Git - libs/gl.git/commitdiff
Rearrange operator metadata
authorMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 19:08:28 +0000 (21:08 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 19:12:33 +0000 (21:12 +0200)
A secondary token can now be stored for the operators that need one.

The member access operator is categorized as postfix because it only has
one actual operand (the right-hand side is just an identifier).

source/glsl/debug.cpp
source/glsl/output.cpp
source/glsl/parser.cpp
source/glsl/syntax.cpp
source/glsl/syntax.h

index 700acbf9cd50a66c8db4e98c54343d8696a332ce..ddf1013dda2b5a70b00619c821652ae7d50f9e15 100644 (file)
@@ -196,7 +196,7 @@ void DumpTree::visit(UnaryExpression &unary)
 
 void DumpTree::visit(BinaryExpression &binary)
 {
-       append(format("Binary: %s -> %s", (binary.oper->token[0]=='[' ? "[]" : binary.oper->token), format_type(binary.type)));
+       append(format("Binary: %s%s -> %s", binary.oper->token, binary.oper->token2, format_type(binary.type)));
        begin_sub();
        binary.left->visit(*this);
        last_branch();
@@ -242,7 +242,7 @@ void DumpTree::visit(Assignment &assign)
 
 void DumpTree::visit(TernaryExpression &ternary)
 {
-       append(format("Ternary: %s -> %s", (ternary.oper->token[0]=='?' ? "?:" : ternary.oper->token), format_type(ternary.type)));
+       append(format("Ternary: %s%s -> %s", ternary.oper->token, ternary.oper->token2, format_type(ternary.type)));
        begin_sub();
        ternary.condition->visit(*this);
        ternary.true_expr->visit(*this);
index 364e5e4b23c02356a2c72743103ba212a32abd91..35c52fec51fc109ada7ad10f7e73b48836955cd2 100644 (file)
@@ -156,8 +156,8 @@ void Formatter::visit(BinaryExpression &binary)
        binary.left->visit(*this);
        append(binary.oper->token);
        binary.right->visit(*this);
-       if(binary.oper->token[0]=='[')
-               append(']');
+       if(binary.oper->token2[0])
+               append(binary.oper->token2);
 }
 
 void Formatter::visit(Assignment &assign)
@@ -172,8 +172,8 @@ void Formatter::visit(TernaryExpression &ternary)
        ternary.condition->visit(*this);
        append(ternary.oper->token);
        ternary.true_expr->visit(*this);
-       if(ternary.oper->token[0]=='?')
-               append(':');
+       if(ternary.oper->token2)
+               append(ternary.oper->token2);
        ternary.false_expr->visit(*this);
 }
 
index 31f9fcb65cc7ffe4da48cacd8cc41e0c7787dba5..7b034a4c671f1d854a06cfabcaad83d94859aa88 100644 (file)
@@ -551,10 +551,10 @@ RefPtr<BinaryExpression> Parser::parse_binary(const RefPtr<Expression> &left, co
        binary->left = left;
        binary->oper = &oper;
        tokenizer.expect(oper.token);
-       if(oper.token[0]=='[')
+       if(oper.token2[0])
        {
                binary->right = parse_expression();
-               tokenizer.expect("]");
+               tokenizer.expect(oper.token2);
        }
        else
                binary->right = parse_expression(&oper);
index 025af2710bb55da807fb686b6876eaef41d4ce22..bbd364c0730d7cca157376ad34bbdbd028ec1581 100644 (file)
@@ -10,51 +10,50 @@ namespace SL {
 
 const Operator Operator::operators[] =
 {
-       { "[", 2, BINARY, LEFT_TO_RIGHT },
-       { "(", 2, POSTFIX, LEFT_TO_RIGHT },
-       { ".", 2, BINARY, LEFT_TO_RIGHT },
-       { "++", 2, POSTFIX, LEFT_TO_RIGHT },
-       { "--", 2, POSTFIX, LEFT_TO_RIGHT },
-       { "++", 3, PREFIX, RIGHT_TO_LEFT },
-       { "--", 3, PREFIX, RIGHT_TO_LEFT },
-       { "+", 3, PREFIX, RIGHT_TO_LEFT },
-       { "-", 3, PREFIX, RIGHT_TO_LEFT },
-       { "~", 3, PREFIX, RIGHT_TO_LEFT },
-       { "!", 3, PREFIX, RIGHT_TO_LEFT },
-       { "*", 4, BINARY, ASSOCIATIVE },
-       { "/", 4, BINARY, LEFT_TO_RIGHT },
-       { "%", 4, BINARY, LEFT_TO_RIGHT },
-       { "+", 5, BINARY, ASSOCIATIVE },
-       { "-", 5, BINARY, LEFT_TO_RIGHT },
-       { "<<", 6, BINARY, LEFT_TO_RIGHT },
-       { ">>", 6, BINARY, LEFT_TO_RIGHT },
-       { "<", 7, BINARY, LEFT_TO_RIGHT },
-       { ">", 7, BINARY, LEFT_TO_RIGHT },
-       { "<=", 7, BINARY, LEFT_TO_RIGHT },
-       { ">=", 7, BINARY, LEFT_TO_RIGHT },
-       { "==", 8, BINARY, LEFT_TO_RIGHT },
-       { "!=", 8, BINARY, LEFT_TO_RIGHT },
-       { "&", 9, BINARY, ASSOCIATIVE },
-       { "^", 10, BINARY, ASSOCIATIVE },
-       { "|", 11, BINARY, ASSOCIATIVE },
-       { "&&", 12, BINARY, ASSOCIATIVE },
-       { "^^", 13, BINARY, ASSOCIATIVE },
-       { "||", 14, BINARY, ASSOCIATIVE },
-       { "?", 15, TERNARY, RIGHT_TO_LEFT },
-       { ":", 15, TERNARY, RIGHT_TO_LEFT },
-       { "=", 16, BINARY, RIGHT_TO_LEFT },
-       { "+=", 16, BINARY, RIGHT_TO_LEFT },
-       { "-=", 16, BINARY, RIGHT_TO_LEFT },
-       { "*=", 16, BINARY, RIGHT_TO_LEFT },
-       { "/=", 16, BINARY, RIGHT_TO_LEFT },
-       { "%=", 16, BINARY, RIGHT_TO_LEFT },
-       { "<<=", 16, BINARY, RIGHT_TO_LEFT },
-       { ">>=", 16, BINARY, RIGHT_TO_LEFT },
-       { "&=", 16, BINARY, RIGHT_TO_LEFT },
-       { "^=", 16, BINARY, RIGHT_TO_LEFT },
-       { "|=", 16, BINARY, RIGHT_TO_LEFT },
-       { ",", 17, BINARY, LEFT_TO_RIGHT },
-       { { 0 }, 18, NO_OPERATOR, LEFT_TO_RIGHT }
+       { "[", "]", 2, BINARY, LEFT_TO_RIGHT },
+       { "(", ")", 2, POSTFIX, LEFT_TO_RIGHT },
+       { ".", { }, 2, POSTFIX, LEFT_TO_RIGHT },
+       { "++", { }, 2, POSTFIX, LEFT_TO_RIGHT },
+       { "--", { }, 2, POSTFIX, LEFT_TO_RIGHT },
+       { "++", { }, 3, PREFIX, RIGHT_TO_LEFT },
+       { "--", { }, 3, PREFIX, RIGHT_TO_LEFT },
+       { "+", { }, 3, PREFIX, RIGHT_TO_LEFT },
+       { "-", { }, 3, PREFIX, RIGHT_TO_LEFT },
+       { "~", { }, 3, PREFIX, RIGHT_TO_LEFT },
+       { "!", { }, 3, PREFIX, RIGHT_TO_LEFT },
+       { "*", { }, 4, BINARY, ASSOCIATIVE },
+       { "/", { }, 4, BINARY, LEFT_TO_RIGHT },
+       { "%", { }, 4, BINARY, LEFT_TO_RIGHT },
+       { "+", { }, 5, BINARY, ASSOCIATIVE },
+       { "-", { }, 5, BINARY, LEFT_TO_RIGHT },
+       { "<<", { }, 6, BINARY, LEFT_TO_RIGHT },
+       { ">>", { }, 6, BINARY, LEFT_TO_RIGHT },
+       { "<", { }, 7, BINARY, LEFT_TO_RIGHT },
+       { ">", { }, 7, BINARY, LEFT_TO_RIGHT },
+       { "<=", { }, 7, BINARY, LEFT_TO_RIGHT },
+       { ">=", { }, 7, BINARY, LEFT_TO_RIGHT },
+       { "==", { }, 8, BINARY, LEFT_TO_RIGHT },
+       { "!=", { }, 8, BINARY, LEFT_TO_RIGHT },
+       { "&", { }, 9, BINARY, ASSOCIATIVE },
+       { "^", { }, 10, BINARY, ASSOCIATIVE },
+       { "|", { }, 11, BINARY, ASSOCIATIVE },
+       { "&&", { }, 12, BINARY, ASSOCIATIVE },
+       { "^^", { }, 13, BINARY, ASSOCIATIVE },
+       { "||", { }, 14, BINARY, ASSOCIATIVE },
+       { "?", ":", 15, TERNARY, RIGHT_TO_LEFT },
+       { "=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "+=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "-=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "*=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "/=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "%=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "<<=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { ">>=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "&=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "^=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { "|=", { }, 16, BINARY, RIGHT_TO_LEFT },
+       { ",", { }, 17, BINARY, LEFT_TO_RIGHT },
+       { { 0 }, { }, 18, NO_OPERATOR, LEFT_TO_RIGHT }
 };
 
 const Operator &Operator::get_operator(const string &token, Type type)
index 81fd6b4f6390050e0312aee3b2d04983e55217e4..b8d9c1a6e98ab8325569a78a1242a6a4a44cff00 100644 (file)
@@ -39,7 +39,8 @@ struct Operator
        };
 
        char token[4];
-       unsigned precedence;
+       char token2[2];
+       UInt8 precedence;
        Type type;
        Associativity assoc;