// File: /workspace/github_cpp_makefile_star2_O2/rfotino[P]consolite-compiler/src/syntax.cpp
// Function: GlobalVarToken::parse(Tokenizer*, std::vector<std::shared_ptr<FunctionToken>, std::allocator<std::shared_ptr<FunctionToken>>> const&, std::vector<std::shared_ptr<GlobalVarToken>, std::allocator<std::shared_ptr<GlobalVarToken>>> const&)
bool GlobalVarToken::parse(
      Tokenizer *tokenizer,
      const std::vector<std::shared_ptr<FunctionToken>>& functions,
      const std::vector<std::shared_ptr<GlobalVarToken>>& globals) {
  _lineNum = _type.line();
  // Validate the type
  if ("void" == _type.name()) {
    _error("Global var cannot be of type 'void'.", _type.line());
    return false;
  }
  // Validate the name
  if (!isValidName(_name)) {
    _error("Invalid global var name '" + _name + "'.", _type.line());
    return false;
  } else if (getFunction(_name, functions)) {
    _error("Global var '" + _name + "' conflicts with existing function name.",
           _type.line());
    return false;
  } else if (getGlobal(_name, globals)) {
    _error("Global var '" + _name + "' conflicts with existing global var name.",
           _type.line());
    return false;
  }
  // Validate the value (if set)
  AtomToken next = tokenizer->getNext();
  AtomToken last = next;
  if ("=" == next.str()) {
    if (_type.isArray()) {
      // Make sure array expression has as many values as the type
      // requires, and make sure they are all constant.
      ArrayExprToken arrayExpr;
      if (!arrayExpr.parse(tokenizer, functions, globals)) {
        return false;
      } else if (arrayExpr.size() != _type.arraySize()) {
        _error("Array size mismatch.", _type.line());
        return false;
      }
      for (size_t i = 0; i < arrayExpr.size(); i++) {
        auto expr = arrayExpr.get(i);
        if (!expr->isConst()) {
          _error("Global value must be known at compile time.", expr->line());
          return false;
        }
        _arrayValues.push_back(expr->val());
      }
    } else {
      // Not an array value, get the singleton initialization expression
      ExprToken expr;
      if (!expr.parse(tokenizer, functions, globals)) {
        return false;
      } else if (!expr.isConst()) {
        _error("Global value must be known at compile time.", expr.line());
        return false;
      }
      _value = expr.val();
    }
    // This should be a semicolon
    last = tokenizer->getNext();
  } else if (";" == next.str()) {
    // No value supplied, give default value of 0.
    if (_type.isArray()) {
      for (size_t i = 0; i < _type.arraySize(); i++) {
        _arrayValues.push_back(0);
      }
    } else {
      _value = 0;
    }
  }
  if (last.empty()) {
    _error("Unexpected EOF.", last.line());
    return false;
  } else if (";" != last.str()) {
    _error("Unexpected token '" + last.str() + "', expected ';'.", last.line());
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movl 0x40(%rdi), %eax
movl %eax, 0x8(%rdi)
leaq 0x48(%rdi), %rsi
leaq 0x60(%rsp), %r13
movq %r13, %rdi
callq 0x73e0
leaq 0x17105(%rip), %rdi     # 0x29030
movq %r13, %rsi
callq 0x97dd
movl %eax, %ebp
movq %r13, %rdi
callq 0x75c8
testb %bpl, %bpl
je 0x11f72
leaq 0x17b97(%rip), %rsi     # 0x29ae0
leaq 0x60(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x9502
movl 0x40(%rbx), %esi
leaq 0x60(%rsp), %rdi
callq 0x285f3
leaq 0x60(%rsp), %rdi
jmp 0x12036
leaq 0x70(%rbx), %r13
movq %r13, %rdi
callq 0x2804b
testb %al, %al
je 0x11fe9
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x283f4
movq (%rbp), %rbp
leaq 0x68(%rsp), %rdi
callq 0x7a34
testq %rbp, %rbp
je 0x12051
leaq 0x17b6c(%rip), %rsi     # 0x29b1f
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rdx
callq 0x9980
leaq 0x17b5f(%rip), %rdx     # 0x29b2c
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x9ad4
movl 0x40(%rbx), %esi
leaq 0x60(%rsp), %rdi
callq 0x285f3
jmp 0x12024
leaq 0x17b15(%rip), %rsi     # 0x29b05
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rdx
callq 0x9980
leaq 0x17d38(%rip), %rdx     # 0x29d42
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x9ad4
movl 0x40(%rbx), %esi
leaq 0x60(%rsp), %rdi
callq 0x285f3
leaq 0x60(%rsp), %rdi
callq 0x75c8
leaq 0xb8(%rsp), %rdi
callq 0x75c8
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x28490
movq (%rbp), %rbp
leaq 0x68(%rsp), %rdi
callq 0x7a34
testq %rbp, %rbp
je 0x120b7
leaq 0x17aa1(%rip), %rsi     # 0x29b1f
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rdx
callq 0x9980
leaq 0x17abd(%rip), %rdx     # 0x29b55
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x9ad4
movl 0x40(%rbx), %esi
leaq 0x60(%rsp), %rdi
callq 0x285f3
jmp 0x12024
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x2772c
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0x187be
leaq 0x70(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x73e0
leaq 0x17505(%rip), %rdi     # 0x295f2
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0x97dd
movl %eax, %r13d
movq %rbp, %rdi
callq 0x75c8
testb %r13b, %r13b
je 0x12254
cmpb $0x1, 0x68(%rbx)
jne 0x122c6
leaq 0x10(%rsp), %rdi
orl $-0x1, 0x8(%rdi)
leaq 0x2c328(%rip), %rax     # 0x3e450
movq %rax, (%rdi)
andq $0x0, 0x20(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
leaq 0x40(%rsp), %r8
movaps %xmm0, (%r8)
andq $0x0, 0x10(%r8)
leaq 0x90(%rsp), %r9
movaps %xmm0, (%r9)
andq $0x0, 0x10(%r9)
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x11b90
movl %eax, %ebp
leaq 0x90(%rsp), %rdi
callq 0x97bc
leaq 0x40(%rsp), %rdi
callq 0x9786
testb %bpl, %bpl
je 0x12395
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
sarq $0x4, %rax
movzwl 0x6a(%rbx), %ecx
cmpq %rcx, %rax
jne 0x12365
addq $0x98, %rbx
xorl %r12d, %r12d
leaq 0x10(%rsp), %rbp
leaq 0x40(%rsp), %r15
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
sarq $0x4, %rax
cmpq %rax, %r12
jae 0x123e4
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x187dc
movq 0x90(%rsp), %rdi
movb 0xc(%rdi), %r13b
testb %r13b, %r13b
je 0x12207
movq (%rdi), %rax
callq *(%rax)
movw %ax, 0x40(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25f1c
jmp 0x12236
movq %r15, %rdi
leaq 0x17984(%rip), %rsi     # 0x29b95
leaq 0xf(%rsp), %rdx
callq 0x9502
movq 0x90(%rsp), %rax
movl 0x8(%rax), %esi
movq %r15, %rdi
callq 0x285f3
movq %r15, %rdi
callq 0x75c8
leaq 0x98(%rsp), %rdi
callq 0x7a34
incq %r12
testb %r13b, %r13b
jne 0x121b5
jmp 0x12395
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x73e0
leaq 0x17957(%rip), %rdi     # 0x29bc1
leaq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x97dd
movl %eax, %ebp
movq %r14, %rdi
callq 0x75c8
testb %bpl, %bpl
je 0x12418
cmpb $0x1, 0x68(%rbx)
jne 0x12358
leaq 0x98(%rbx), %r14
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
movzwl 0x6a(%rbx), %eax
cmpq %rax, %r12
jae 0x12418
andw $0x0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x25f1c
incq %r12
jmp 0x122a3
leaq 0x10(%rsp), %rdi
orl $-0x1, 0x8(%rdi)
leaq 0x2bd72(%rip), %rax     # 0x3e048
movq %rax, (%rdi)
movb $0x1, 0xc(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0xe(%rdi)
movups %xmm0, 0x18(%rdi)
leaq 0x40(%rsp), %r8
movaps %xmm0, (%r8)
andq $0x0, 0x10(%r8)
leaq 0x90(%rsp), %r9
movaps %xmm0, (%r9)
andq $0x0, 0x10(%r9)
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0xe5a8
movl %eax, %ebp
leaq 0x90(%rsp), %rdi
callq 0x97bc
leaq 0x40(%rsp), %rdi
callq 0x9786
testb %bpl, %bpl
je 0x123d5
cmpb $0x0, 0x1c(%rsp)
je 0x123a4
leaq 0x10(%rsp), %rdi
movzwl 0xe(%rdi), %eax
movw %ax, 0x92(%rbx)
callq 0x1835a
jmp 0x123ee
andw $0x0, 0x92(%rbx)
jmp 0x12418
leaq 0x17814(%rip), %rsi     # 0x29b80
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x9502
movl 0x40(%rbx), %esi
leaq 0x40(%rsp), %rdi
callq 0x285f3
leaq 0x40(%rsp), %rdi
callq 0x75c8
leaq 0x10(%rsp), %rdi
callq 0x187f8
jmp 0x12504
leaq 0x177ea(%rip), %rsi     # 0x29b95
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x9502
movl 0x18(%rsp), %esi
leaq 0x40(%rsp), %rdi
callq 0x285f3
leaq 0x40(%rsp), %rdi
callq 0x75c8
leaq 0x10(%rsp), %rdi
callq 0x1835a
jmp 0x12504
leaq 0x10(%rsp), %rdi
callq 0x187f8
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2772c
leaq 0xb8(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x1880c
movq %rbx, %rdi
callq 0x7b20
cmpq $0x0, 0xd0(%rsp)
je 0x124d3
leaq 0xc8(%rsp), %r14
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x73e0
leaq 0x1777e(%rip), %rdi     # 0x29bc1
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x9976
movl %eax, %ebp
movq %rbx, %rdi
callq 0x75c8
movb $0x1, %bl
testb %bpl, %bpl
je 0x12506
leaq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0x73e0
leaq 0x1742b(%rip), %rsi     # 0x298a7
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x1832f
leaq 0x1772e(%rip), %rdx     # 0x29bc3
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x9ad4
movl 0xc0(%rsp), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
leaq 0x10(%rsp), %rdi
callq 0x75c8
leaq 0x40(%rsp), %rdi
callq 0x75c8
leaq 0x90(%rsp), %rdi
jmp 0x124ff
leaq 0x174fd(%rip), %rsi     # 0x299d7
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x9502
movl 0xc0(%rsp), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
leaq 0x10(%rsp), %rdi
callq 0x75c8
xorl %ebx, %ebx
leaq 0xb8(%rsp), %rdi
callq 0x7b20
leaq 0x60(%rsp), %rdi
callq 0x7b20
jmp 0x1203d
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x75c8
jmp 0x125b6
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x75c8
jmp 0x12603
movq %rax, %rbx
jmp 0x125b6
movq %rax, %rbx
jmp 0x12603
jmp 0x1261a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x75c8
jmp 0x1256a
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x75c8
jmp 0x12579
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
jmp 0x12590
jmp 0x1261a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x75c8
jmp 0x1261d
jmp 0x1261a
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x97bc
leaq 0x40(%rsp), %rdi
callq 0x9786
leaq 0x10(%rsp), %rdi
callq 0x1835a
jmp 0x1261d
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x97bc
leaq 0x40(%rsp), %rdi
callq 0x9786
jmp 0x12603
jmp 0x1261a
jmp 0x125f3
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x75c8
jmp 0x125f6
jmp 0x1261a
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x7a34
leaq 0x10(%rsp), %rdi
callq 0x187f8
jmp 0x1261d
jmp 0x1261a
movq %rax, %rbx
jmp 0x1262a
jmp 0x1263a
jmp 0x12649
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x7b20
leaq 0x60(%rsp), %rdi
callq 0x7b20
jmp 0x12668
jmp 0x1263a
jmp 0x12649
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x75c8
jmp 0x1264c
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x1265e
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x75c8
jmp 0x12668
movq %rax, %rbx
movq %rbx, %rdi
callq 0x7510