// File: /workspace/github_cpp_makefile_star2_O1/kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/check.cpp
// Function: AST::fill_and_check(symbol_table*)
void AST::fill_and_check(symbol_table* st){
    
    // Declaracion previa de todas las funciones
    uint nsize = declarations.size();
    for ( uint i = 0; i != nsize; i++){
        if ( typeid(*declarations[i]) == typeid(AST_function) ){
            
            AST_function* f = (AST_function*)declarations[i];
            symbol_function* sf = (symbol_function*)st->lookup( f->func->getName() );
            
            if ( sf ){
                logger->buf << "Función '" << f->func->getName()
                            << "' con nombre repetido (primera declaración en "
                            << sf->getLine() << ':' << sf->getColumn() << ").";
                logger->error(f->func->getLine(), f->func->getColumn());
            } else {
                st->insert( f->func );
            }
        }
    }
    
    // Verificacion de existencia de main
    {
        symbol_function* sf = (symbol_function*)st->lookup( "main" );
        
        if ( !sf ){
            logger->buf << "Falta declaración de función main.";
            logger->error(yylineno+1, 0);
        } else if ( sf->getType() != NONE ){
            logger->buf << "main debe tener tipo de retorno none.";
            logger->error(sf->getLine(), sf->getColumn());
        } else if ( sf->params.size() ){
            logger->buf << "main no debe recibir argumentos.";
            logger->error(sf->getLine(), sf->getColumn());
        }
    }
    
    // Verificacion del programa
    vector<AST_declaration*>::iterator it;
    for ( it = declarations.begin(); it != declarations.end(); it++){
        (*it)->fill_and_check(st);
        
        if ( typeid(**it) == typeid(AST_variable_declaration) ){
            AST_variable_declaration* var = 
                (AST_variable_declaration*)*it;
            
            if (    var->value
                 && var->value->type != INVALID 
                 && var->value->has_functions()
               )
            {
                logger->buf << "Inicialización de variable '" << var->sym->getName()
                            << "' involucra llamada a función.";
                logger->error(var->line, var->column);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
movq 0x18(%rdi), %r12
subq 0x10(%rdi), %r12
shrq $0x3, %r12
testl %r12d, %r12d
je 0xc71f
xorl %r15d, %r15d
leaq 0x1fca2(%rip), %r13     # 0x2c20d
movq %r12, 0x30(%rsp)
movq 0x10(%r14), %rax
movq (%rax,%r15,8), %rbx
testq %rbx, %rbx
je 0xc94d
movq (%rbx), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rdi
cmpq %r13, %rdi
je 0xc5aa
cmpb $0x2a, (%rdi)
je 0xc713
movq %r13, %rsi
callq 0x6400
testl %eax, %eax
jne 0xc713
movq 0x98(%rbx), %rsi
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
callq 0x17fb8
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x183ae
movq %rax, %rbp
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc5ec
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x62f0
testq %rbp, %rbp
je 0xc702
movq %r14, %r12
movq %r13, %r14
leaq 0x31dfe(%rip), %rax     # 0x3e400
movq (%rax), %r13
addq $0x48, %r13
movl $0xa, %edx
movq %r13, %rdi
leaq 0x203c7(%rip), %rsi     # 0x2c9df
callq 0x6360
movq 0x98(%rbx), %rsi
leaq 0x10(%rsp), %rdi
callq 0x17fb8
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rdi
callq 0x6360
movq %rax, %r13
movl $0x2f, %edx
movq %rax, %rdi
leaq 0x204f7(%rip), %rsi     # 0x2cb49
callq 0x6360
movq %rbp, %rdi
callq 0x17fe2
movq %r13, %rdi
movl %eax, %esi
callq 0x6530
movb $0x3a, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
callq 0x6360
movq %rax, %r13
movq %rbp, %rdi
callq 0x17fe6
movq %r13, %rdi
movl %eax, %esi
callq 0x6530
movl $0x2, %edx
movq %rax, %rdi
leaq 0x2022b(%rip), %rsi     # 0x2c8cf
callq 0x6360
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xc6c5
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x62f0
leaq 0x31d34(%rip), %rax     # 0x3e400
movq (%rax), %r13
movq 0x98(%rbx), %rdi
callq 0x17fe2
movl %eax, %ebp
movq 0x98(%rbx), %rdi
callq 0x17fe6
movq %r13, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x1a9e6
movq %r14, %r13
movq %r12, %r14
movq 0x30(%rsp), %r12
jmp 0xc713
movq 0x98(%rbx), %rsi
movq 0x8(%rsp), %rdi
callq 0x184aa
incq %r15
cmpl %r15d, %r12d
jne 0xc570
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x20449(%rip), %rsi     # 0x2cb79
leaq 0x20446(%rip), %rdx     # 0x2cb7d
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x6fec
movq 0x8(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x183ae
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0xc76d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x62f0
testq %r15, %r15
movq 0x8(%rsp), %r12
je 0xc7b1
movq %r15, %rdi
callq 0x17fde
cmpl $0x2, %eax
jne 0xc7e2
movq 0x80(%r15), %rax
cmpq 0x78(%r15), %rax
je 0xc827
leaq 0x31c64(%rip), %rbx     # 0x3e400
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x2041f(%rip), %rsi     # 0x2cbc9
movl $0x20, %edx
jmp 0xc7fc
leaq 0x31c48(%rip), %rbx     # 0x3e400
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x203b8(%rip), %rsi     # 0x2cb7e
movl $0x24, %edx
callq 0x6360
movq (%rbx), %rdi
leaq 0x31b1e(%rip), %rax     # 0x3e2f8
movl (%rax), %esi
incl %esi
xorl %edx, %edx
jmp 0xc822
leaq 0x31c17(%rip), %rbx     # 0x3e400
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x203ac(%rip), %rsi     # 0x2cba3
movl $0x25, %edx
callq 0x6360
movq (%rbx), %r12
movq %r15, %rdi
callq 0x17fe2
movl %eax, %ebp
movq %r15, %rdi
callq 0x17fe6
movq %r12, %rdi
movq 0x8(%rsp), %r12
movl %ebp, %esi
movl %eax, %edx
callq 0x1a9e6
movq 0x10(%r14), %rbx
cmpq 0x18(%r14), %rbx
je 0xc93e
leaq 0x1f9f2(%rip), %r15     # 0x2c22e
leaq 0x31bbd(%rip), %r13     # 0x3e400
movq (%rbx), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x8(%rax)
movq (%rbx), %rbp
testq %rbp, %rbp
je 0xc94d
movq (%rbp), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rdi
cmpq %r15, %rdi
je 0xc885
cmpb $0x2a, (%rdi)
je 0xc930
movq %r15, %rsi
callq 0x6400
testl %eax, %eax
jne 0xc930
movq 0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0xc930
cmpl $0x1, 0x10(%rdi)
je 0xc930
movq (%rdi), %rax
callq *0x28(%rax)
testb %al, %al
je 0xc930
movq (%r13), %r12
addq $0x48, %r12
movl $0x1d, %edx
movq %r12, %rdi
leaq 0x20326(%rip), %rsi     # 0x2cbea
callq 0x6360
movq 0x98(%rbp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x17fb8
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rdi
callq 0x6360
movl $0x1f, %edx
movq %rax, %rdi
leaq 0x2030d(%rip), %rsi     # 0x2cc08
callq 0x6360
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xc91c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x62f0
movq (%r13), %rdi
movl 0x8(%rbp), %esi
movl 0xc(%rbp), %edx
callq 0x1a9e6
movq 0x8(%rsp), %r12
addq $0x8, %rbx
cmpq 0x18(%r14), %rbx
jne 0xc843
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6340
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0xc9a0
movq 0x68(%rsp), %rsi
jmp 0xc998
jmp 0xc981
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc9a0
movq 0x48(%rsp), %rsi
jmp 0xc998
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xc9a0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x62f0
movq %rbx, %rdi
callq 0x6550