// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST.cpp
// Function: AST_function::AST_function(int, tokenId*, AST_arg_list*, AST_block*)
AST_function::AST_function(TYPE t, tokenId* id, AST_arg_list* args,
                           AST_block* code
                          )
{
    line = id->line;
    column = id->column;
    
    vector< symbol* >::iterator it;
    vector< TYPE > types;
    for (it = args->args.begin(); it != args->args.end(); ++ it){
        types.push_back( (*it)->getType() );
    }
    
    if ( t ){
        func = new symbol_function(id->ident, t, id->line, id->column,
                                   types);
    } else {
        func = new symbol_function(id->ident, id->line, id->column, types );
    }
    
    delete id;
    
    formal_parameters = args;
    instructions = code;
    
    if ( func->getType() != NONE ){
        if ( code->has_return == NO ){
            // Reportar error de tipo de argumento
            logger->buf << "Función '" << id->ident << "' sin retorno.";
            logger->error(line, column);
        } else if ( code->has_return == MAYBE ){
            logger->buf << "Función '" << id->ident << "' posiblemente sin retorno.";
            logger->warning(line, column);
        }
    }
    has_return = NO;
    
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movl %esi, 0x10c(%rsp)
movq %rdx, 0x100(%rsp)
movq %rcx, 0xf8(%rsp)
movq %r8, 0xf0(%rsp)
movq 0x110(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x21180
movq 0x50(%rsp), %rax
leaq 0x4e96c(%rip), %rcx     # 0x6d5f8
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x100(%rsp), %rcx
movl (%rcx), %ecx
movl %ecx, 0x8(%rax)
movq 0x100(%rsp), %rcx
movl 0x4(%rcx), %ecx
movl %ecx, 0xc(%rax)
leaq 0xe8(%rsp), %rdi
callq 0x1fd10
leaq 0xd0(%rsp), %rdi
callq 0x21420
movq 0xf8(%rsp), %rdi
addq $0x10, %rdi
callq 0x1fd30
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0xf8(%rsp), %rdi
addq $0x10, %rdi
callq 0x1fda0
movq %rax, 0xc0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x1fd60
testb $0x1, %al
jne 0x1ed25
jmp 0x1ed8f
leaq 0xe8(%rsp), %rdi
callq 0x1fdd0
movq (%rax), %rdi
callq 0x295f0
movl %eax, 0x4c(%rsp)
jmp 0x1ed40
movl 0x4c(%rsp), %eax
movl %eax, 0xbc(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xbc(%rsp), %rsi
callq 0x21430
jmp 0x1ed62
jmp 0x1ed64
leaq 0xe8(%rsp), %rdi
callq 0x1fde0
jmp 0x1ecf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x1f0d8
cmpl $0x0, 0x10c(%rsp)
je 0x1ee84
movl $0x90, %edi
callq 0x6390
movq %rax, 0x40(%rsp)
jmp 0x1edae
movb $0x1, 0x87(%rsp)
movq 0x100(%rsp), %rsi
addq $0x8, %rsi
leaq 0x88(%rsp), %rdi
callq 0x6170
jmp 0x1edd1
movq 0x40(%rsp), %rdi
movl 0x10c(%rsp), %edx
movq 0x100(%rsp), %rax
movl (%rax), %ecx
movl 0x4(%rax), %r8d
leaq 0x88(%rsp), %rsi
leaq 0xd0(%rsp), %r9
callq 0x297a0
jmp 0x1ee02
movq 0x50(%rsp), %rax
movq 0x40(%rsp), %rcx
movb $0x0, 0x87(%rsp)
movq %rcx, 0x98(%rax)
leaq 0x88(%rsp), %rdi
callq 0x6778
jmp 0x1ef4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x1ee64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x6778
testb $0x1, 0x87(%rsp)
jne 0x1ee70
jmp 0x1ee7f
movq 0x40(%rsp), %rdi
movl $0x90, %esi
callq 0x63a0
jmp 0x1f0d8
movl $0x90, %edi
callq 0x6390
movq %rax, 0x38(%rsp)
jmp 0x1ee95
movb $0x1, 0x5f(%rsp)
movq 0x100(%rsp), %rsi
addq $0x8, %rsi
leaq 0x60(%rsp), %rdi
callq 0x6170
jmp 0x1eeb2
movq 0x38(%rsp), %rdi
movq 0x100(%rsp), %rax
movl (%rax), %edx
movl 0x4(%rax), %ecx
leaq 0x60(%rsp), %rsi
leaq 0xd0(%rsp), %r8
callq 0x29660
jmp 0x1eed8
movq 0x50(%rsp), %rax
movq 0x38(%rsp), %rcx
movb $0x0, 0x5f(%rsp)
movq %rcx, 0x98(%rax)
leaq 0x60(%rsp), %rdi
callq 0x6778
jmp 0x1ef4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x1ef2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x6778
testb $0x1, 0x5f(%rsp)
jne 0x1ef37
jmp 0x1ef46
movq 0x38(%rsp), %rdi
movl $0x90, %esi
callq 0x63a0
jmp 0x1f0d8
movq 0x100(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0x1ef77
movq 0x30(%rsp), %rdi
callq 0x20f10
movq 0x30(%rsp), %rdi
movl $0x28, %esi
callq 0x63a0
movq 0x50(%rsp), %rax
movq 0xf8(%rsp), %rcx
movq %rcx, 0xa0(%rax)
movq 0xf0(%rsp), %rcx
movq %rcx, 0xa8(%rax)
movq 0x98(%rax), %rdi
callq 0x295f0
movl %eax, 0x2c(%rsp)
jmp 0x1efac
movl 0x2c(%rsp), %eax
cmpl $0x2, %eax
je 0x1f0b7
movq 0xf0(%rsp), %rax
cmpl $0x1, 0x78(%rax)
jne 0x1f036
leaq 0x4f50a(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x48, %rdi
leaq 0x339ef(%rip), %rsi     # 0x529cb
callq 0x6370
movq %rax, 0x20(%rsp)
jmp 0x1efe8
movq 0x20(%rsp), %rdi
movq 0x100(%rsp), %rsi
addq $0x8, %rsi
callq 0x6340
movq %rax, 0x18(%rsp)
jmp 0x1f005
movq 0x18(%rsp), %rdi
leaq 0x35123(%rip), %rsi     # 0x54134
callq 0x6370
jmp 0x1f018
movq 0x50(%rsp), %rax
leaq 0x4f4b4(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2f440
jmp 0x1f034
jmp 0x1f0b5
movq 0xf0(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jne 0x1f0b3
leaq 0x4f48d(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x48, %rdi
leaq 0x33972(%rip), %rsi     # 0x529cb
callq 0x6370
movq %rax, 0x10(%rsp)
jmp 0x1f065
movq 0x10(%rsp), %rdi
movq 0x100(%rsp), %rsi
addq $0x8, %rsi
callq 0x6340
movq %rax, 0x8(%rsp)
jmp 0x1f082
movq 0x8(%rsp), %rdi
leaq 0x350b5(%rip), %rsi     # 0x54143
callq 0x6370
jmp 0x1f095
movq 0x50(%rsp), %rax
leaq 0x4f437(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2f160
jmp 0x1f0b1
jmp 0x1f0b3
jmp 0x1f0b5
jmp 0x1f0b7
movq 0x50(%rsp), %rax
movl $0x1, 0x10(%rax)
leaq 0xd0(%rsp), %rdi
callq 0x21460
addq $0x118, %rsp            # imm = 0x118
retq
leaq 0xd0(%rsp), %rdi
callq 0x21460
movq 0x50(%rsp), %rdi
callq 0x211c0
movq 0xb0(%rsp), %rdi
callq 0x66b0
nopl (%rax)