// File: /workspace/github_cpp_makefile_star2_O2/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 0x18(%rdi), %r14
movq %rdi, 0x10(%rsp)
subq 0x10(%rdi), %r14
shrq $0x3, %r14
xorl %r12d, %r12d
leaq 0x2c54a(%rip), %rbp     # 0x36f38
leaq 0x58(%rsp), %r15
cmpl %r12d, %r14d
je 0xab5b
movl %r12d, %ebx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbx,8), %rax
testq %rax, %rax
je 0xad2d
movq (%rax), %rax
movq -0x8(%rax), %rdi
movq %rbp, %rsi
callq 0x1227e
testb %al, %al
je 0xab53
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbx,8), %rbx
movq 0x98(%rbx), %rsi
movq %r15, %rdi
callq 0x13efa
movq 0x8(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x1422e
movq %rax, %r13
movq %r15, %rdi
callq 0x65c8
testq %r13, %r13
je 0xab42
leaq 0x2d98e(%rip), %rax     # 0x38400
movq (%rax), %rdi
addq $0x48, %rdi
leaq 0x18f5f(%rip), %rsi     # 0x239df
callq 0x62b0
movq %rax, %rbp
movq 0x98(%rbx), %rsi
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x13efa
movq %rbp, %rdi
movq %r15, %rsi
callq 0x62a0
movq %rax, %rdi
leaq 0x19098(%rip), %rsi     # 0x23b49
callq 0x62b0
movq %rax, %rbp
movq %r13, %rdi
callq 0x13f10
movq %rbp, %rdi
movl %eax, %esi
callq 0x6510
movq %rax, %rdi
pushq $0x3a
popq %rsi
callq 0x6350
movq %rax, %rbp
movq %r13, %rdi
callq 0x13f14
movq %rbp, %rdi
movl %eax, %esi
callq 0x6510
movq %rax, %rdi
leaq 0x18dda(%rip), %rsi     # 0x238cf
callq 0x62b0
leaq 0x18(%rsp), %rdi
callq 0x65c8
leaq 0x2d8f5(%rip), %rax     # 0x38400
movq (%rax), %r13
movq 0x98(%rbx), %rdi
callq 0x13f10
movl %eax, %ebp
movq 0x98(%rbx), %rdi
callq 0x13f14
movq %r13, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x16112
leaq 0x2c3fd(%rip), %rbp     # 0x36f38
leaq 0x58(%rsp), %r15
jmp 0xab53
movq 0x98(%rbx), %rsi
movq 0x8(%rsp), %rdi
callq 0x142e6
incl %r12d
jmp 0xa9f3
leaq 0x19017(%rip), %rsi     # 0x23b79
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x6d6c
leaq 0x38(%rsp), %rsi
movq 0x8(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x1422e
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x65c8
testq %r15, %r15
je 0xabcc
movq %r15, %rdi
callq 0x13f0c
cmpl $0x2, %eax
jne 0xabf8
movq 0x80(%r15), %rax
cmpq 0x78(%r15), %rax
je 0xac38
leaq 0x2d844(%rip), %rbx     # 0x38400
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x18fff(%rip), %rsi     # 0x23bc9
jmp 0xac0d
leaq 0x2d82d(%rip), %rbx     # 0x38400
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x18f9d(%rip), %rsi     # 0x23b7e
callq 0x62b0
movq (%rbx), %rdi
leaq 0x2d708(%rip), %rax     # 0x382f8
movl (%rax), %esi
incl %esi
xorl %edx, %edx
jmp 0xac33
leaq 0x2d801(%rip), %rbx     # 0x38400
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x18f96(%rip), %rsi     # 0x23ba3
callq 0x62b0
movq (%rbx), %r12
movq %r15, %rdi
callq 0x13f10
movl %eax, %ebp
movq %r15, %rdi
callq 0x13f14
movq %r12, %rdi
movq 0x8(%rsp), %r12
movl %ebp, %esi
movl %eax, %edx
callq 0x16112
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rbx
leaq 0x2c308(%rip), %r15     # 0x36f50
leaq 0x18f9b(%rip), %r14     # 0x23bea
leaq 0x18(%rsp), %r13
movq 0x10(%rsp), %rax
cmpq 0x18(%rax), %rbx
je 0xad1e
movq (%rbx), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x8(%rax)
movq (%rbx), %rax
testq %rax, %rax
je 0xad2d
movq (%rax), %rax
movq -0x8(%rax), %rdi
movq %r15, %rsi
callq 0x1227e
testb %al, %al
je 0xad15
movq (%rbx), %rbp
movq 0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0xad15
cmpl $0x1, 0x10(%rdi)
je 0xad15
movq (%rdi), %rax
callq *0x28(%rax)
testb %al, %al
je 0xad15
leaq 0x2d748(%rip), %rax     # 0x38400
movq (%rax), %rdi
addq $0x48, %rdi
movq %r14, %rsi
callq 0x62b0
movq %rax, %r12
movq 0x98(%rbp), %rsi
movq %r13, %rdi
callq 0x13efa
movq %r12, %rdi
movq %r13, %rsi
callq 0x62a0
movq %rax, %rdi
leaq 0x18f1a(%rip), %rsi     # 0x23c08
callq 0x62b0
movq %r13, %rdi
callq 0x65c8
leaq 0x2d6fe(%rip), %rax     # 0x38400
movq (%rax), %rdi
movl 0x8(%rbp), %esi
movl 0xc(%rbp), %edx
callq 0x16112
movq 0x8(%rsp), %r12
addq $0x8, %rbx
jmp 0xac54
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6320
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0xad55
movq %rax, %rbx
jmp 0xad5a
jmp 0xad4d
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0xad55
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x65c8
movq %rbx, %rdi
callq 0x6530