Coverage Report

Created: 2026-11-13 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibSQL/AST/Token.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include "Token.h"
8
#include <AK/Assertions.h>
9
#include <AK/ByteString.h>
10
#include <stdlib.h>
11
12
namespace SQL::AST {
13
14
StringView Token::name(TokenType type)
15
8.96M
{
16
8.96M
    switch (type) {
17
0
#define __ENUMERATE_SQL_TOKEN(value, type, category) \
18
8.96M
    case TokenType::type:                            \
19
8.96M
        return #type##sv;
20
0
        ENUMERATE_SQL_TOKENS
21
0
#undef __ENUMERATE_SQL_TOKEN
22
0
    default:
23
0
        VERIFY_NOT_REACHED();
24
8.96M
    }
25
8.96M
}
26
27
TokenCategory Token::category(TokenType type)
28
0
{
29
0
    switch (type) {
30
0
#define __ENUMERATE_SQL_TOKEN(value, type, category) \
31
0
    case TokenType::type:                            \
32
0
        return TokenCategory::category;
33
0
        ENUMERATE_SQL_TOKENS
34
0
#undef __ENUMERATE_SQL_TOKEN
35
0
    default:
36
0
        VERIFY_NOT_REACHED();
37
0
    }
38
0
}
39
40
double Token::double_value() const
41
1.09M
{
42
1.09M
    VERIFY(type() == TokenType::NumericLiteral);
43
1.09M
    ByteString value(m_value);
44
45
1.09M
    if (value[0] == '0' && value.length() >= 2) {
46
117k
        if (value[1] == 'x' || value[1] == 'X')
47
2.57k
            return static_cast<double>(strtoul(value.characters() + 2, nullptr, 16));
48
117k
    }
49
50
1.08M
    return strtod(value.characters(), nullptr);
51
1.09M
}
52
53
}