styx-lang / styx

@@ -536,7 +536,7 @@
Loading
536 536
     *      a keyword otherwise the $(D TokenType) that matches to the keyword
537 537
     *      passed as argument.
538 538
     */
539 -
    static TokenType opBinaryRight(string op: "in")(const char[] word)
539 +
    static TokenType getTypeOf(const char[] word)
540 540
    {
541 541
        const ushort h = hash(word);
542 542
        TokenType result = _filled[h];
@@ -549,10 +549,10 @@
Loading
549 549
///
550 550
unittest
551 551
{
552 -
    assert(("blalba" in KeywordMatch) == TokenType.identifier);
553 -
    assert(("protection" in KeywordMatch) == TokenType.protection);
554 -
    assert(("f32" in KeywordMatch) == TokenType.f32);
555 -
    assert(("isitthere?" in KeywordMatch) == TokenType.identifier);
552 +
    assert(KeywordMatch.getTypeOf("blalba") == TokenType.identifier);
553 +
    assert(KeywordMatch.getTypeOf("protection") == TokenType.protection);
554 +
    assert(KeywordMatch.getTypeOf("f32") == TokenType.f32);
555 +
    assert(KeywordMatch.getTypeOf("isitthere?") == TokenType.identifier);
556 556
    KeywordMatch.generateFilledTable();
557 557
}
558 558
@@ -652,7 +652,7 @@
Loading
652 652
    this(const(char)[] text, uint line, uint column, TokenType type)
653 653
    {
654 654
        this.position   = Position(line, column);
655 -
        this.type       = type == TokenType.identifier ? text in KeywordMatch : type;
655 +
        this.type       = type == TokenType.identifier ? KeywordMatch.getTypeOf(text) : type;
656 656
657 657
        if (text.length > 1 && text[0] == '$')
658 658
        {

@@ -108,7 +108,7 @@
Loading
108 108
109 109
public:
110 110
111 -
    static AttributeKind opBinaryRight(string op: "in")(const char[] word)
111 +
    static AttributeKind kindOf(const char[] word)
112 112
    {
113 113
        AttributeKind result = AttributeKind.user;
114 114
        const ushort h = hash(word);
@@ -133,7 +133,7 @@
Loading
133 133
    {
134 134
        this.startPos            = p;
135 135
        this.identifierOrKeyword = id;
136 -
        this.kind                = id.text() in AttributeMatch;
136 +
        this.kind                = AttributeMatch.kindOf(id.text());
137 137
    }
138 138
    /// The attribute identifier.
139 139
    Token* identifierOrKeyword;

@@ -5,7 +5,7 @@
Loading
5 5
    styx.symbol, styx.ast.types, styx.token, styx.ast.declarations,
6 6
    styx.ast.formatter;
7 7
8 -
private enum Property : ubyte
8 +
private enum PropertyKind : ubyte
9 9
{
10 10
    none,
11 11
    length_,
@@ -18,7 +18,7 @@
Loading
18 18
19 19
unittest
20 20
{
21 -
    static foreach (i, m; __traits(allMembers, Property))
21 +
    static foreach (i, m; __traits(allMembers, PropertyKind))
22 22
        static if (i != 0)
23 23
            static assert(m[$-1] == '_', "Property members must end with an underscore");
24 24
}
@@ -51,13 +51,13 @@
Loading
51 51
52 52
    static string generateFilledTable()
53 53
    {
54 -
        string result = "static const Property[16] _filled = [";
54 +
        string result = "static const PropertyKind[16] _filled = [";
55 55
        static foreach (w; _words)
56 56
        {
57 57
            static if (w != "")
58 -
                result ~= "Property." ~ w ~ "_";
58 +
                result ~= "PropertyKind." ~ w ~ "_";
59 59
            else
60 -
                result ~= "Property.none";
60 +
                result ~= "PropertyKind.none";
61 61
            result ~= ", ";
62 62
        }
63 63
        result ~= "];";
@@ -68,12 +68,12 @@
Loading
68 68
69 69
public:
70 70
71 -
    static Property opBinaryRight(string op: "in")(const char[] word)
71 +
    static PropertyKind kindOf(const char[] word)
72 72
    {
73 -
        Property result = Property.none;
73 +
        PropertyKind result = PropertyKind.none;
74 74
        const ushort h = hash(word);
75 75
        if (_filled[h])
76 -
            result = _words[h] == word ? _filled[h] : Property.none;
76 +
            result = _words[h] == word ? _filled[h] : PropertyKind.none;
77 77
        return result;
78 78
    }
79 79
}
@@ -91,35 +91,35 @@
Loading
91 91
ExpressionAstNode tryProperties(DotExpressionAstNode node)
92 92
{
93 93
    IdentExpressionAstNode id = *cast(IdentExpressionAstNode*) &node.dotted;
94 -
    Property p = id.identifier.text() in PropertyMatch;
94 +
    const PropertyKind p = PropertyMatch.kindOf(id.identifier.text());
95 95
    final switch (p)
96 96
    {
97 -
    case Property.none:
97 +
    case PropertyKind.none:
98 98
        return null;
99 99
100 -
    case Property.min_:
101 -
    case Property.max_:
100 +
    case PropertyKind.min_:
101 +
    case PropertyKind.max_:
102 102
        if (TypeEnum te = asTypeEnum(node.expression.type))
103 -
            return (p == Property.min_) ? te.declaration.min : te.declaration.max;
103 +
            return (p == PropertyKind.min_) ? te.declaration.min : te.declaration.max;
104 104
        if (!node.expression.type.isIntegral())
105 105
            return null;
106 106
        ulong v;
107 107
        TypeAstNode t = node.expression.type.getRealType();
108 108
        with (TokenType) switch (t.kind)
109 109
        {
110 -
        case s8:    v = p == Property.min_ ? 0x80 : 0x7F; break;
111 -
        case s16:   v = p == Property.min_ ? 0x8000 : 0x7FFF; break;
112 -
        case s32:   v = p == Property.min_ ? 0x8000_0000 : 0x7FFF_FFFF; break;
113 -
        case s64:   v = p == Property.min_ ? 0x8000_0000_0000_0000L : 0x7FFF_FFFF_FFFF_FFFFL; break;
114 -
        case u8:    v = p == Property.min_ ? 0 : 0xFF; break;
115 -
        case u16:   v = p == Property.min_ ? 0 : 0xFFFF; break;
116 -
        case u32:   v = p == Property.min_ ? 0 : 0xFFFF_FFFF; break;
117 -
        case u64:   v = p == Property.min_ ? 0 : 0xFFFF_FFFF_FFFF_FFFFUL; break;
110 +
        case s8:    v = p == PropertyKind.min_ ? 0x80 : 0x7F; break;
111 +
        case s16:   v = p == PropertyKind.min_ ? 0x8000 : 0x7FFF; break;
112 +
        case s32:   v = p == PropertyKind.min_ ? 0x8000_0000 : 0x7FFF_FFFF; break;
113 +
        case s64:   v = p == PropertyKind.min_ ? 0x8000_0000_0000_0000L : 0x7FFF_FFFF_FFFF_FFFFL; break;
114 +
        case u8:    v = p == PropertyKind.min_ ? 0 : 0xFF; break;
115 +
        case u16:   v = p == PropertyKind.min_ ? 0 : 0xFFFF; break;
116 +
        case u32:   v = p == PropertyKind.min_ ? 0 : 0xFFFF_FFFF; break;
117 +
        case u64:   v = p == PropertyKind.min_ ? 0 : 0xFFFF_FFFF_FFFF_FFFFUL; break;
118 118
        default:    assert(false);
119 119
        }
120 120
        return new IntegerExpressionAstNode(node.startPos, v, t);
121 121
122 -
    case Property.length_:
122 +
    case PropertyKind.length_:
123 123
        assert(node.expression.type);
124 124
        if (node.expression.type.kind == TokenType.tkDyna)
125 125
        {
@@ -133,7 +133,7 @@
Loading
133 133
        }
134 134
        return null;
135 135
136 -
    case Property.ptr_:
136 +
    case PropertyKind.ptr_:
137 137
        assert(node.expression.type);
138 138
        TypeStaticArray tsa = node.expression.type.asTypeStaticArray();
139 139
        TypeDynamicArray tda = node.expression.type.asTypeDynamicArray();
@@ -141,14 +141,14 @@
Loading
141 141
            return PtrExpressionAstNode.createFor(node.expression, tsa ? tsa : tda, false);
142 142
        return null;
143 143
144 -
    case Property.sizeof_:
144 +
    case PropertyKind.sizeof_:
145 145
        assert(node.expression.type);
146 146
        TypeAstNode t = node.expression.type.getRealType();
147 147
        const ulong s = t is TypeBool.instance() ? 1 : t.size / 8;
148 148
        IntegerExpressionAstNode ie = new IntegerExpressionAstNode(node.startPos, s, TypeU32.instance());
149 149
        return ie;
150 150
151 -
    case Property.stringof_:
151 +
    case PropertyKind.stringof_:
152 152
        return new StringExpressionAstNode(node.dotted.startPos, identifier(format(node.expression)),
153 153
            TypeS8.instance().pointerOf());
154 154
    }
Files Coverage
src/styx 98.91%
Project Totals (38 files) 98.91%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading