// File: /workspace/github_cpp_makefile_star2_O1/kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/check.cpp
// Function: AST_op::fill_and_check(symbol_table*)
void AST_op::fill_and_check(symbol_table* st){
    if ( left )
        left->fill_and_check(st);
    
    if ( right )
        right->fill_and_check(st);
    
    if ( !left || !right ){
        return;
    }
    
    // Ambos argumentos son invalidos
    if ( left->type == INVALID && right->type == INVALID ){
        type = INVALID;
        logger->error(line, column);
        return;
    }
    
    /* Un solo argumento invalido, tratar de validar el otro y colocar el valor
    * de la expresion segun el valor de ese argumento
    */
    else if ( left->type == INVALID || right->type == INVALID ){
        AST_expression* valido;
        char* nombre_valido;
        
        if ( left->type != INVALID ){
            valido = left;
            nombre_valido = (char*)"izquierdo";
        } else {
            valido = right;
            nombre_valido = (char*)"derecho";
        }
        
        switch( oper_type ){
            
            case MOD:
                
                type = INT;
                
                if ( valido->type != INT ){
                    logger->buf << "Operando '" << nombre_valido
                                << "' de tipo '" << types.types[valido->type]->name
                                << "', esperando int.";
                    logger->error(line, column);
                }
                break;
                
            /* Operadores aritmeticos: suma, resta, multiplicacion y division */
            case PLUS:
            case MINUS:
            case PROD:
            case DIV:
                
                if ( valido->type == INT
                     || valido->type == FLOAT
                   )
                {
                    type = valido->type;
                } else {
                    logger->buf << "Operando '" << nombre_valido
                                << "' de tipo '" << types.types[valido->type]->name
                                << "', esperando float o int.";
                    logger->error(line, column);
                }
                break;
            
            /* Operadores logicos: y, o, implica, consecuencia */
            case AND:
            case OR:
            case IMP:
            case CONSEQ:
                
                if ( valido->type == BOOLEAN ){
                    type = BOOLEAN;
                } else {
                    logger->buf << "Operando '" << nombre_valido
                                << "' de tipo '" << types.types[valido->type]->name
                                << "', esperando boolean.";
                    logger->error(line, column);
                }
                break;
            
            /* Operadores de comparación de igualdad: ==, != */
            case EQ:
            case UNEQ:
            
                type = BOOLEAN;
                break;
            
            /* Operadores de relación de orden: <, <=, >, >= */
            case LESS:
            case LESS_EQ:
            case GREAT:
            case GREAT_EQ:
            
                type = BOOLEAN;
                if (    valido->type != INT
                     && valido->type != FLOAT
                     && valido->type != CHAR
                   )
                {
                    logger->buf << "Operando '" << nombre_valido
                                << "' de tipo '" << types.types[valido->type]->name
                                << "', esperando float o int.";
                    logger->error(line, column);
                }
                break;
        }
        return;
    }
    
    /* else */
    
    // Ambos argumentos validos
    switch( oper_type ){
        
        case MOD:
            type = INT;
            
            if ( left->type != INT ){
                logger->buf << "Operando izquierdo de tipo '" << types.types[left->type]->name
                            << "', esperando int.";
                logger->error(line, column);
            } else if ( right->type != INT ) {
                logger->buf << "Operando derecho de tipo '" << types.types[right->type]->name
                            << "', esperando int.";
                logger->error(line, column);
            }
            
            break;
            
        /* Operadores aritmeticos: suma, resta, multiplicacion y division */
        case PLUS:
        case MINUS:
        case PROD:
        case DIV:
            
            if ( left->type == right->type ) {
                if ( left->type == INT || left->type == FLOAT )
                {
                    type = left->type;
                } else {
                    // Error de ambos argumentos con tipos invalidos
                    logger->buf << "Operando izquierdo de tipo '" << types.types[left->type]->name
                                << "', esperando float o int.";
                    logger->error(line, column);
                    
                    type = INVALID;
                }
                
            } else {
                // Argumento derecho con tipo invalido
                logger->buf << "Operandos de tipos incompatibles '"
                            << types.types[left->type]->name << "' y '"
                            << types.types[right->type]->name << "'";
                logger->error(line, column);
                type = INVALID;
            }
            break;
        
        /* Operadores logicos: y, o, implica, consecuencia */
        case AND:
        case OR:
        case IMP:
        case CONSEQ:
            
            if ( left->type == right->type )
            {
                type = BOOLEAN;
                if ( left->type != BOOLEAN )
                {
                    logger->buf << "Operandos de tipo '" << types.types[left->type]->name
                                << "', esperando boolean.";
                    logger->error(line, column);
                }
                
            } else {
                // Error de ambos argumentos con tipos invalidos
                logger->buf << "Operandos de tipos '"
                            << types.types[left->type]->name << "' y '"
                            << types.types[right->type]->name << "' esperados boolean.";
                logger->error(line, column);
            }
            
            break;
        
        /* Operadores de comparación de igualdad: ==, != */
        case EQ:
        case UNEQ:
            
            type = BOOLEAN;
            if ( left->type != right->type )
            {
                // Error de ambos argumentos con tipos invalidos
                logger->buf << "Operandos de tipos imcompratibles '"
                            << types.types[left->type]->name << "' y '"
                            << types.types[right->type]->name << "'";
                logger->error(line, column);
            }
            
            break;
        
        /* Operadores de relación de orden: <, <=, >, >= */
        case LESS:
        case LESS_EQ:
        case GREAT:
        case GREAT_EQ:
            
            type = BOOLEAN;
            
            if ( left->type == right->type )
            {
                if (    left->type != INT
                     && left->type != FLOAT
                     && left->type != CHAR
                   )
                {
                    // Error de ambos argumentos con tipos invalidos
                    logger->buf << "Operandos de tipos '"
                                << types.types[left->type]->name
                                << "' esperando float, int o char";
                    logger->error(line, column);
                }
                
            } else {
                // Error de ambos argumentos con tipos invalidos
                logger->buf << "Operandos de tipos imcompratibles '"
                            << types.types[left->type]->name << "' y '"
                            << types.types[right->type]->name << "'";
                logger->error(line, column);
            }
            
            break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x58(%rdi), %rdi
testq %rdi, %rdi
je 0xa05f
movq (%rdi), %rax
movq %r14, %rsi
callq *0x8(%rax)
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0xa071
movq (%rdi), %rax
movq %r14, %rsi
callq *0x8(%rax)
movq 0x58(%rbx), %r12
testq %r12, %r12
je 0xa695
movq 0x60(%rbx), %rcx
testq %rcx, %rcx
je 0xa695
movl 0x10(%r12), %eax
cmpl $0x1, %eax
jne 0xa0b6
cmpl $0x1, 0x10(%rcx)
jne 0xa0b1
movl $0x1, 0x10(%rbx)
leaq 0x34357(%rip), %rax     # 0x3e400
movq (%rax), %rdi
jmp 0xa703
cmpl $0x1, %eax
je 0xa0be
movl 0x10(%rcx), %edx
cmpl $0x1, %edx
jne 0xa109
cmpl $0x1, %eax
cmoveq %rcx, %r12
leaq 0x23e04(%rip), %rcx     # 0x2ded0
leaq 0x225f5(%rip), %r14     # 0x2c6c8
cmoveq %rcx, %r14
movl 0x68(%rbx), %ecx
cmpq $0xe, %rcx
ja 0xa695
leaq 0x22019(%rip), %rdx     # 0x2c104
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x10(%r12), %ecx
leal -0x3(%rcx), %edx
cmpl $0x1, %edx
ja 0xa15a
movl %ecx, 0x10(%rbx)
jmp 0xa695
movl 0x68(%rbx), %esi
cmpq $0xe, %rsi
ja 0xa695
leaq 0x21fab(%rip), %rdi     # 0x2c0c8
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
cmpl %edx, %eax
jne 0xa3ff
leal -0x3(%rax), %ecx
cmpl $0x1, %ecx
ja 0xa624
movl %eax, 0x10(%rbx)
jmp 0xa695
movl $0x6, 0x10(%rbx)
movl 0x10(%r12), %ecx
addl $-0x3, %ecx
cmpl $0x3, %ecx
jb 0xa695
xorl %ebp, %ebp
cmpl $0x1, %eax
setne %bpl
leaq 0x34296(%rip), %r13     # 0x3e400
movq (%r13), %r15
addq $0x48, %r15
leaq 0x22559(%rip), %rsi     # 0x2c6d2
movl $0xa, %edx
movq %r15, %rdi
callq 0x6360
leaq 0x7(,%rbp,2), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6360
leaq 0x2253d(%rip), %rsi     # 0x2c6dd
movl $0xb, %edx
movq %r15, %rdi
callq 0x6360
movslq 0x10(%r12), %rax
leaq 0x3424f(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r15, %rdi
callq 0x6360
leaq 0x22524(%rip), %rsi     # 0x2c6fb
movl $0x19, %edx
jmp 0xa5cb
cmpl $0x6, 0x10(%r12)
jne 0xa2e7
movl $0x6, 0x10(%rbx)
jmp 0xa695
cmpl %edx, %eax
jne 0xa36e
movl $0x6, 0x10(%rbx)
cmpl $0x6, 0x10(%r12)
je 0xa695
leaq 0x341e5(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x22563(%rip), %rsi     # 0x2c78c
movl $0x13, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x341c3(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x224b2(%rip), %rsi     # 0x2c715
movl $0x15, %edx
jmp 0xa6f8
movl $0x6, 0x10(%rbx)
movl 0x10(%r12), %eax
cmpl 0x10(%rcx), %eax
jne 0xa4a5
addl $-0x3, %eax
cmpl $0x3, %eax
jb 0xa695
leaq 0x3416b(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x224fd(%rip), %rsi     # 0x2c7a0
movl $0x14, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x34149(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x22511(%rip), %rsi     # 0x2c7ee
movl $0x1d, %edx
jmp 0xa6f8
xorl %ebp, %ebp
cmpl $0x1, %eax
setne %bpl
leaq 0x34109(%rip), %r13     # 0x3e400
movq (%r13), %r15
addq $0x48, %r15
leaq 0x223cc(%rip), %rsi     # 0x2c6d2
movl $0xa, %edx
movq %r15, %rdi
callq 0x6360
leaq 0x7(,%rbp,2), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6360
leaq 0x223b0(%rip), %rsi     # 0x2c6dd
movl $0xb, %edx
movq %r15, %rdi
callq 0x6360
movslq 0x10(%r12), %rax
leaq 0x340c2(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r15, %rdi
callq 0x6360
leaq 0x223b1(%rip), %rsi     # 0x2c715
movl $0x15, %edx
jmp 0xa5cb
leaq 0x3408b(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x2241d(%rip), %rsi     # 0x2c7a0
movl $0x14, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x34069(%rip), %r12     # 0x3e408
movq (%r12), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
movq %rax, %r14
leaq 0x223c5(%rip), %rsi     # 0x2c786
movl $0x5, %edx
movq %rax, %rdi
callq 0x6360
movq 0x60(%rbx), %rax
movslq 0x10(%rax), %rax
movq (%r12), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x223c0(%rip), %rsi     # 0x2c7b5
movl $0x14, %edx
jmp 0xa6f8
leaq 0x33ffa(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x2234f(%rip), %rsi     # 0x2c763
movl $0x22, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x33fd8(%rip), %r12     # 0x3e408
movq (%r12), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
movq %rax, %r14
leaq 0x22334(%rip), %rsi     # 0x2c786
movl $0x5, %edx
movq %rax, %rdi
callq 0x6360
movq 0x60(%rbx), %rax
movslq 0x10(%rax), %rax
movq (%r12), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x2281d(%rip), %rsi     # 0x2cca3
movl $0x1, %edx
jmp 0xa678
movl $0x6, 0x10(%rbx)
movl 0x10(%r12), %eax
cmpl 0x10(%rcx), %eax
je 0xa695
leaq 0x33f54(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x22310(%rip), %rsi     # 0x2c7ca
movl $0x23, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x33f32(%rip), %r12     # 0x3e408
movq (%r12), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
movq %rax, %r14
leaq 0x2228e(%rip), %rsi     # 0x2c786
movl $0x5, %edx
movq %rax, %rdi
callq 0x6360
movq 0x60(%rbx), %rax
movslq 0x10(%rax), %rax
movq (%r12), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x22777(%rip), %rsi     # 0x2cca3
movl $0x1, %edx
jmp 0xa6f8
movl $0x3, 0x10(%rbx)
cmpl $0x3, 0x10(%r12)
je 0xa695
xorl %ebp, %ebp
cmpl $0x1, %eax
setne %bpl
leaq 0x33ea7(%rip), %r13     # 0x3e400
movq (%r13), %r15
addq $0x48, %r15
leaq 0x2216a(%rip), %rsi     # 0x2c6d2
movl $0xa, %edx
movq %r15, %rdi
callq 0x6360
leaq 0x7(,%rbp,2), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6360
leaq 0x2214e(%rip), %rsi     # 0x2c6dd
movl $0xb, %edx
movq %r15, %rdi
callq 0x6360
movslq 0x10(%r12), %rax
leaq 0x33e60(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r15, %rdi
callq 0x6360
leaq 0x22123(%rip), %rsi     # 0x2c6e9
movl $0x11, %edx
movq %rax, %rdi
callq 0x6360
movq (%r13), %rdi
jmp 0xa703
movl $0x3, 0x10(%rbx)
cmpl $0x3, 0x10(%r12)
jne 0xa6a4
cmpl $0x3, 0x10(%rcx)
je 0xa695
leaq 0x33e00(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x2213a(%rip), %rsi     # 0x2c748
movl $0x1a, %edx
movq %r14, %rdi
callq 0x6360
movq 0x60(%rbx), %rax
jmp 0xa6ca
leaq 0x33dd5(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x220f2(%rip), %rsi     # 0x2c72b
movl $0x1c, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x33db3(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x22088(%rip), %rsi     # 0x2c6fb
movl $0x19, %edx
movq %rax, %rdi
callq 0x6360
movq (%r15), %rdi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x1a9e6
movl $0x1, 0x10(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x33d55(%rip), %r15     # 0x3e400
movq (%r15), %r14
addq $0x48, %r14
leaq 0x22072(%rip), %rsi     # 0x2c72b
movl $0x1c, %edx
movq %r14, %rdi
callq 0x6360
movq 0x58(%rbx), %rax
movslq 0x10(%rax), %rax
leaq 0x33d33(%rip), %rcx     # 0x3e408
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r14, %rdi
callq 0x6360
leaq 0x21ff6(%rip), %rsi     # 0x2c6e9
movl $0x11, %edx
movq %rax, %rdi
callq 0x6360
movq (%r15), %rdi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1a9e6