// File: /workspace/github_cpp_makefile_star2_O2/WayfireWM[P]wf-utils/wayfire/lexer/symbol.cpp
// Function: wf::symbol_t::symbol_t(std::variant<int, char, bool, float, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&)
symbol_t::symbol_t(const variant_t &v) : type(type_t::LITERAL), value(v)
{
    // String literals can also be keywords, comments or identifiers. Check for this.
    if (is_string(value))
    {
        auto literal_value = get_string(value);

        if ((literal_value.front() == '\"') && (literal_value.back() == '\"'))
        {
            value = literal_value.substr(1, literal_value.size() - 2); // Strip quotes here.
        }
        else if (contains(SIGNALS, literal_value))
        {
            type = type_t::SIGNAL;
        }
        else if (contains(KEYWORDS, literal_value))
        {
            type = type_t::KEYWORD;
        }
        else if (contains(STRUCTURES, literal_value))
        {
            type = type_t::STRUCTURAL;
        }
        else if (contains(OPERATORS, literal_value))
        {
            type = type_t::OPERATOR;
        }
        else
        {
            bool first = true;
            for (const auto &c : literal_value)
            {
                auto digit = std::isdigit(c);
                auto letter = std::isalpha(c);
                auto underscore = (c == '_');

                if (first)
                {
                    first = false;
                    if (digit)
                    {
                        std::string error = "Symbol parser error. Identifier should start with _ or letter. text:";
                        error.append(literal_value);
                        throw std::runtime_error(error);
                    }
                }

                if (!(digit | letter | underscore))
                {
                    std::string error = "Symbol parser error. Identifier contains invalid character. text:";
                    error.append(literal_value);
                    throw std::runtime_error(error);
                }
            }
            type = type_t::IDENTIFIER;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x8(%rdi), %rbx
movq %rdi, %r14
movl $0x2, (%rdi)
movq %rbx, %rdi
callq 0x6210
movq %rbx, %rdi
callq 0xad37
testb %al, %al
je 0x869f
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xad75
movq 0x18(%rsp), %rax
cmpb $0x22, (%rax)
jne 0x855b
movq 0x20(%rsp), %rcx
cmpb $0x22, -0x1(%rax,%rcx)
jne 0x855b
addq $-0x2, %rcx
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x5210
leaq 0x38(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8758
movq %r14, %rdi
callq 0x50e0
jmp 0x8695
leaq 0xbd8e(%rip), %rdi      # 0x142f0
leaq 0x18(%rsp), %rsi
callq 0x74cd
testb %al, %al
je 0x857c
movl $0x6, (%r14)
jmp 0x8695
leaq 0xbd9d(%rip), %rdi      # 0x14320
leaq 0x18(%rsp), %rsi
callq 0x74cd
testb %al, %al
je 0x859d
movl $0x4, (%r14)
jmp 0x8695
leaq 0xbddc(%rip), %rdi      # 0x14380
leaq 0x18(%rsp), %rsi
callq 0x74cd
testb %al, %al
je 0x85be
movl $0x5, (%r14)
jmp 0x8695
leaq 0xbd8b(%rip), %rdi      # 0x14350
leaq 0x18(%rsp), %rsi
callq 0x74cd
testb %al, %al
je 0x85df
movl $0x3, (%r14)
jmp 0x8695
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r12
movb $0x1, %cl
xorl %r13d, %r13d
movq %rbx, 0x10(%rsp)
cmpq %r13, %r12
je 0x868e
movb (%r15,%r13), %al
movsbl %al, %edi
leal -0x30(%rdi), %eax
cmpl $0xa, %eax
setb %dl
andb %dl, %cl
cmpb $0x1, %cl
je 0x86ae
cmpl $0xa, %eax
setb %bpl
cmpb $0x5f, %dil
sete %bl
callq 0x52f0
orb %bpl, %bl
incq %r13
xorl %ecx, %ecx
movzbl %bl, %edx
orl %eax, %edx
jne 0x85f3
leaq 0x3e0d(%rip), %rsi      # 0xc44d
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x61ca
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r15
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xb973(%rip), %rsi      # 0x13ff0
movq 0xb924(%rip), %rdx      # 0x13fa8
movq %r15, %rdi
callq 0x5320
jmp 0x8701
movl $0x1, (%r14)
leaq 0x18(%rsp), %rdi
callq 0x50e0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d53(%rip), %rsi      # 0xc408
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x61ca
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r15
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xb8fe(%rip), %rsi      # 0x13ff0
movq 0xb8af(%rip), %rdx      # 0x13fa8
movq %r15, %rdi
callq 0x5320
jmp 0x8703
movq %r15, %rdi
movq %rax, %r14
callq 0x5180
jmp 0x8717
jmp 0x8729
jmp 0x8714
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x50e0
jmp 0x8731
jmp 0x872e
jmp 0x872e
jmp 0x873d
movq %rbx, 0x10(%rsp)
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x50e0
jmp 0x8745
movq %rbx, 0x10(%rsp)
movq %rax, %r14
movq 0x10(%rsp), %rdi
callq 0x62d0
movq %r14, %rdi
callq 0x5340
nop