// File: /workspace/github_cpp_makefile_star2_O3/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 0xc6f9
xorl %r15d, %r15d
leaq 0x20cc8(%rip), %r13     # 0x2d20d
movq %r12, 0x30(%rsp)
movq 0x10(%r14), %rax
movq (%rax,%r15,8), %rbx
testq %rbx, %rbx
je 0xc927
movq (%rbx), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rdi
cmpq %r13, %rdi
je 0xc584
cmpb $0x2a, (%rdi)
je 0xc6ed
movq %r13, %rsi
callq 0x6410
testl %eax, %eax
jne 0xc6ed
movq 0x98(%rbx), %rsi
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
callq 0x17ff4
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x183ea
movq %rax, %rbp
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc5c6
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x6300
testq %rbp, %rbp
je 0xc6dc
movq %r14, %r12
movq %r13, %r14
leaq 0x32e2c(%rip), %rax     # 0x3f408
movq (%rax), %r13
addq $0x48, %r13
movl $0xa, %edx
movq %r13, %rdi
leaq 0x213ed(%rip), %rsi     # 0x2d9df
callq 0x6370
movq 0x98(%rbx), %rsi
leaq 0x10(%rsp), %rdi
callq 0x17ff4
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rdi
callq 0x6370
movq %rax, %r13
movl $0x2f, %edx
movq %rax, %rdi
leaq 0x2151d(%rip), %rsi     # 0x2db49
callq 0x6370
movq %rbp, %rdi
callq 0x1801e
movq %r13, %rdi
movl %eax, %esi
callq 0x6540
movb $0x3a, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
callq 0x6370
movq %rax, %r13
movq %rbp, %rdi
callq 0x18022
movq %r13, %rdi
movl %eax, %esi
callq 0x6540
movl $0x2, %edx
movq %rax, %rdi
leaq 0x21251(%rip), %rsi     # 0x2d8cf
callq 0x6370
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xc69f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6300
leaq 0x32d62(%rip), %rax     # 0x3f408
movq (%rax), %r13
movq 0x98(%rbx), %rdi
callq 0x1801e
movl %eax, %ebp
movq 0x98(%rbx), %rdi
callq 0x18022
movq %r13, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x1aa40
movq %r14, %r13
movq %r12, %r14
movq 0x30(%rsp), %r12
jmp 0xc6ed
movq 0x98(%rbx), %rsi
movq 0x8(%rsp), %rdi
callq 0x184e6
incq %r15
cmpl %r15d, %r12d
jne 0xc54a
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2146f(%rip), %rsi     # 0x2db79
leaq 0x2146c(%rip), %rdx     # 0x2db7d
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x7008
movq 0x8(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x183ea
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0xc747
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x6300
testq %r15, %r15
movq 0x8(%rsp), %r12
je 0xc78b
movq %r15, %rdi
callq 0x1801a
cmpl $0x2, %eax
jne 0xc7bc
movq 0x80(%r15), %rax
cmpq 0x78(%r15), %rax
je 0xc801
leaq 0x32c92(%rip), %rbx     # 0x3f408
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x21445(%rip), %rsi     # 0x2dbc9
movl $0x20, %edx
jmp 0xc7d6
leaq 0x32c76(%rip), %rbx     # 0x3f408
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x213de(%rip), %rsi     # 0x2db7e
movl $0x24, %edx
callq 0x6370
movq (%rbx), %rdi
leaq 0x32b4c(%rip), %rax     # 0x3f300
movl (%rax), %esi
incl %esi
xorl %edx, %edx
jmp 0xc7fc
leaq 0x32c45(%rip), %rbx     # 0x3f408
movq (%rbx), %rdi
addq $0x48, %rdi
leaq 0x213d2(%rip), %rsi     # 0x2dba3
movl $0x25, %edx
callq 0x6370
movq (%rbx), %r12
movq %r15, %rdi
callq 0x1801e
movl %eax, %ebp
movq %r15, %rdi
callq 0x18022
movq %r12, %rdi
movq 0x8(%rsp), %r12
movl %ebp, %esi
movl %eax, %edx
callq 0x1aa40
movq 0x10(%r14), %rbx
cmpq 0x18(%r14), %rbx
je 0xc918
leaq 0x20a18(%rip), %r15     # 0x2d22e
leaq 0x32beb(%rip), %r13     # 0x3f408
movq (%rbx), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x8(%rax)
movq (%rbx), %rbp
testq %rbp, %rbp
je 0xc927
movq (%rbp), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rdi
cmpq %r15, %rdi
je 0xc85f
cmpb $0x2a, (%rdi)
je 0xc90a
movq %r15, %rsi
callq 0x6410
testl %eax, %eax
jne 0xc90a
movq 0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0xc90a
cmpl $0x1, 0x10(%rdi)
je 0xc90a
movq (%rdi), %rax
callq *0x28(%rax)
testb %al, %al
je 0xc90a
movq (%r13), %r12
addq $0x48, %r12
movl $0x1d, %edx
movq %r12, %rdi
leaq 0x2134c(%rip), %rsi     # 0x2dbea
callq 0x6370
movq 0x98(%rbp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x17ff4
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rdi
callq 0x6370
movl $0x1f, %edx
movq %rax, %rdi
leaq 0x21333(%rip), %rsi     # 0x2dc08
callq 0x6370
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xc8f6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6300
movq (%r13), %rdi
movl 0x8(%rbp), %esi
movl 0xc(%rbp), %edx
callq 0x1aa40
movq 0x8(%rsp), %r12
addq $0x8, %rbx
cmpq 0x18(%r14), %rbx
jne 0xc81d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6350
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0xc97a
movq 0x68(%rsp), %rsi
jmp 0xc972
jmp 0xc95b
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc97a
movq 0x48(%rsp), %rsi
jmp 0xc972
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xc97a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6300
movq %rbx, %rdi
callq 0x6560