// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/check.cpp
// Function: AST_function_call::fill_and_check(symbol_table*)
void AST_function_call::fill_and_check(symbol_table* st){
    
    params->fill_and_check(st);
    
    sym = st->lookup(name);
    
    if ( !sym ){

        logger->buf << "Función '" << name << "' no definida.";
        logger->error(line, column);
        
        type = UNDEFINED;
    } else if ( !sym->is_function ){
        sym = 0;

        logger->buf << "Identificador '" << name << "' no es un nombre de función.";
        logger->error(line, column);
        
        type = UNDEFINED;
    } else {
        symbol_function* f = (symbol_function*)sym;
        
        if ( params->elem.size() != f->params.size() ){
            logger->buf << "Se esperaban " << f->params.size()
                        << " argumentos para la función '" << name
                        << "', " << params->elem.size() << " recibidos.";
            logger->error(line, column);
        } else {
            uint nsize = params->elem.size();
            
            for (uint i=0; i<nsize; i++){
                if ( params->elem[i]->type != INVALID
                     && params->elem[i]->type != f->params[i] )
                {
                    logger->buf << "Argumento " << i << " de '" << name << "' de tipo inválido '"
                                << types.types[params->elem[i]->type]->name << "'.";
                    logger->error(line, column);
                }
            }
        }
        
        type = f->getType();
    }
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x80(%rax), %rdi
movq 0x88(%rsp), %rsi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
movq 0x28(%rsp), %rsi
movq 0x88(%rsp), %rax
movq %rax, 0x30(%rsp)
addq $0x50, %rsi
leaq 0x68(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x6170
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2a040
movq %rax, 0x40(%rsp)
jmp 0xd75b
movq 0x28(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x70(%rax)
leaq 0x68(%rsp), %rdi
callq 0x6778
movq 0x28(%rsp), %rax
cmpq $0x0, 0x70(%rax)
jne 0xd809
leaq 0x60d4e(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
leaq 0x4522f(%rip), %rsi     # 0x529cb
callq 0x6370
movq 0x28(%rsp), %rsi
movq %rax, %rdi
addq $0x50, %rsi
callq 0x6340
movq %rax, %rdi
leaq 0x4521a(%rip), %rsi     # 0x529d6
callq 0x6370
movq 0x28(%rsp), %rax
leaq 0x60d0b(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2f440
movq 0x28(%rsp), %rax
movl $0x0, 0x10(%rax)
jmp 0xdb25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x6778
jmp 0xdb2d
movq 0x28(%rsp), %rax
movq 0x70(%rax), %rax
testb $0x1, 0x31(%rax)
jne 0xd88e
movq 0x28(%rsp), %rax
movq $0x0, 0x70(%rax)
leaq 0x60cac(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
leaq 0x4503a(%rip), %rsi     # 0x52878
callq 0x6370
movq 0x28(%rsp), %rsi
movq %rax, %rdi
addq $0x50, %rsi
callq 0x6340
movq %rax, %rdi
leaq 0x45187(%rip), %rsi     # 0x529e5
callq 0x6370
movq 0x28(%rsp), %rax
leaq 0x60c69(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2f440
movq 0x28(%rsp), %rax
movl $0x0, 0x10(%rax)
jmp 0xdb23
movq 0x28(%rsp), %rax
movq 0x70(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq 0x80(%rax), %rdi
addq $0x10, %rdi
callq 0x1ffd0
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
addq $0x78, %rdi
callq 0x20540
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
je 0xd995
leaq 0x60c01(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
leaq 0x4511b(%rip), %rsi     # 0x52a04
callq 0x6370
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rdi
addq $0x78, %rdi
callq 0x20540
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x60e0
movq %rax, %rdi
leaq 0x450fa(%rip), %rsi     # 0x52a12
callq 0x6370
movq 0x28(%rsp), %rsi
movq %rax, %rdi
addq $0x50, %rsi
callq 0x6340
movq %rax, %rdi
leaq 0x450f9(%rip), %rsi     # 0x52a31
callq 0x6370
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x18(%rsp)
movq 0x80(%rax), %rdi
addq $0x10, %rdi
callq 0x1ffd0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x60e0
movq %rax, %rdi
leaq 0x450c4(%rip), %rsi     # 0x52a35
callq 0x6370
movq 0x28(%rsp), %rax
leaq 0x60b56(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2f440
jmp 0xdb0f
movq 0x28(%rsp), %rax
movq 0x80(%rax), %rdi
addq $0x10, %rdi
callq 0x1ffd0
movl %eax, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jae 0xdb0d
movq 0x28(%rsp), %rax
movq 0x80(%rax), %rdi
addq $0x10, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x1fff0
movq (%rax), %rax
cmpl $0x1, 0x10(%rax)
je 0xdafb
movq 0x28(%rsp), %rax
movq 0x80(%rax), %rdi
addq $0x10, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x1fff0
movq (%rax), %rax
movl 0x10(%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x50(%rsp), %rdi
addq $0x78, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x20560
movq %rax, %rcx
movl 0xc(%rsp), %eax
cmpl (%rcx), %eax
je 0xdafb
leaq 0x60a9d(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
leaq 0x44ff4(%rip), %rsi     # 0x52a41
callq 0x6370
movq %rax, %rdi
movl 0x48(%rsp), %esi
callq 0x6540
movq %rax, %rdi
leaq 0x45073(%rip), %rsi     # 0x52adb
callq 0x6370
movq 0x28(%rsp), %rsi
movq %rax, %rdi
addq $0x50, %rsi
callq 0x6340
movq %rax, %rdi
leaq 0x44fc4(%rip), %rsi     # 0x52a4c
callq 0x6370
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rsp)
movq 0x80(%rax), %rdi
addq $0x10, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x1fff0
movq (%rax), %rax
movslq 0x10(%rax), %rsi
leaq 0x60a23(%rip), %rdi     # 0x6e4e0
callq 0x1fc90
movq (%rsp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x6340
movq %rax, %rdi
leaq 0x49bdb(%rip), %rsi     # 0x576b7
callq 0x6370
movq 0x28(%rsp), %rax
leaq 0x609eb(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2f440
jmp 0xdafd
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0xd9b6
jmp 0xdb0f
movq 0x50(%rsp), %rdi
callq 0x295f0
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
jmp 0xdb25
addq $0x98, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x66b0
nopw (%rax,%rax)