// File: /workspace/github_c_makefile_star2_O1/anuwu[P]ERPLAG-Compiler/typeChecker.c
// Function: getExpressionType
tokenID getExpressionType (moduleST *baseModule, astNode *exprNode)
{
	if (exprNode->child == NULL || exprNode->child->next == NULL)	// constant value, integer, or array[index]
	{
		if (exprNode->id != TK_ID)
		{
			if (exprNode->id == TK_NUM)
				return TK_INTEGER ;
			else if (exprNode->id == TK_RNUM)
			{
				realPresent = 1 ;
				return TK_REAL ;
			}
			else
				return TK_BOOLEAN ;
		}
		else
			return validateVar (baseModule, exprNode, NULL) ;
	}
	else
	{
		tokenID typeLeft , typeRight ;
		typeLeft = getExpressionType (baseModule, exprNode->child) ;
		typeRight = getExpressionType (baseModule, exprNode->child->next) ;

		if (typeLeft == TK_ARRAY || typeRight == TK_ARRAY)
		{
			errSemantic () ;
			#ifdef _WIN64
				printf ("In module \"%s\" at line %d, array variable(s) \"%s\" and \"%s\" cannot occur in an expression\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->child->tok->lexeme, exprNode->child->next->tok->lexeme) ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable(s) " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " and " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " cannot occur in an expression\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->child->tok->lexeme, exprNode->child->next->tok->lexeme) ;
			#endif
			return (tokenID)0 ;
		}

		if (!typeLeft || !typeRight)
			return (tokenID)0 ;
		else if (typeLeft != typeRight)
		{
			errSemantic () ;
			#ifdef _WIN64
				printf ("In module \"%s\" at line %d, the operator \"%s\" is not allowed between types \"%s\" and \"%s\" respectively\n", getParentModuleName (baseModule), exprNode->tok->lineNumber,  exprNode->tok->lexeme, typeIDToString(typeLeft), typeIDToString(typeRight)) ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", the operator " ANSI_BOLD ANSI_CYAN "%s" ANSI_RESET " is not allowed between types " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET " and " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET " respectively\n", getParentModuleName (baseModule), exprNode->tok->lineNumber,  exprNode->tok->lexeme, typeIDToString(typeLeft), typeIDToString(typeRight)) ;
			#endif
			return (tokenID)0 ;
		}
		else
		{
			if (isArithmeticType(typeLeft) && isArithmeticOp (exprNode->id))
				return typeLeft ;
			else if (isArithmeticType(typeLeft) && isRelationalOp(exprNode->id))
				return TK_BOOLEAN ;
			else if (typeLeft == TK_BOOLEAN && isLogicalOp(exprNode->id))
				return typeLeft ;
			else
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, the operator \"%s\" cannot be executed between two operands of type \"%s\"\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->tok->lexeme, typeIDToString(typeLeft)) ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", the operator " ANSI_BOLD ANSI_CYAN "%s" ANSI_RESET " cannot be executed between two operands of type " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET "\n", getParentModuleName (baseModule), exprNode->tok->lineNumber, exprNode->tok->lexeme, typeIDToString(typeLeft)) ;
				#endif
				realBase->semanticError = 1 ;
				return (tokenID)0 ;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
movq 0x30(%rsi), %rsi
testq %rsi, %rsi
je 0xecd0
cmpq $0x0, 0x38(%rsi)
je 0xecd0
movq %r15, %rdi
callq 0xebd3
movl %eax, %r12d
movq 0x30(%rbx), %rax
movq 0x38(%rax), %rsi
movq %r15, %rdi
callq 0xebd3
cmpl $0x3b, %r12d
je 0xecf9
movl %eax, %r13d
cmpl $0x3b, %eax
je 0xecf9
xorl %r14d, %r14d
testl %r12d, %r12d
je 0xedb9
testl %r13d, %r13d
je 0xedb9
cmpl %r13d, %r12d
jne 0xed68
leal -0x39(%r12), %eax
cmpl $-0x2, %eax
jae 0xedcb
cmpl $0x39, %r12d
jne 0xec76
movl (%rbx), %eax
andl $-0x2, %eax
movl $0x39, %r14d
cmpl $0x4e, %eax
je 0xedb9
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xf205
movq %r15, %rdi
callq 0xcb84
movq %rax, %r15
movq 0x8(%rbx), %rax
movl 0x10(%rax), %ebx
movq 0x8(%rax), %r13
movl %r12d, %edi
callq 0xd3bf
leaq 0x56be(%rip), %rdi      # 0x14363
movq %r15, %rsi
movl %ebx, %edx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x10b0
leaq 0x2336a(%rip), %rax     # 0x32028
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0xedb9
movl (%rbx), %eax
cmpl $0x40, %eax
je 0xed45
cmpl $0x71, %eax
je 0xed3d
cmpl $0x72, %eax
jne 0xed60
leaq 0x2333c(%rip), %rax     # 0x32024
movl $0x1, (%rax)
movl $0x38, %r14d
jmp 0xedb9
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xf205
movq %r15, %rdi
callq 0xcb84
movq 0x8(%rbx), %rcx
movq 0x30(%rbx), %rsi
movl 0x10(%rcx), %edx
movq 0x8(%rsi), %rcx
movq 0x38(%rsi), %rsi
movq 0x8(%rcx), %rcx
movq 0x8(%rsi), %rsi
movq 0x8(%rsi), %r8
leaq 0x5508(%rip), %rdi      # 0x14239
movq %rax, %rsi
xorl %eax, %eax
callq 0x10b0
jmp 0xedb9
movl $0x37, %r14d
jmp 0xedb9
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xea15
movl $0x39, %r14d
jmp 0xedb9
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xf205
movq %r15, %rdi
callq 0xcb84
movq %rax, -0x30(%rbp)
movq 0x8(%rbx), %rax
movl 0x10(%rax), %ebx
movq 0x8(%rax), %r15
movl %r12d, %edi
callq 0xd3bf
movq %rax, %r12
movl %r13d, %edi
callq 0xd3bf
leaq 0x5526(%rip), %rdi      # 0x142c9
movq -0x30(%rbp), %rsi
movl %ebx, %edx
movq %r15, %rcx
movq %r12, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x10b0
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rbx), %ecx
addl $-0x5b, %ecx
cmpl $-0x5, %ecx
ja 0xedf4
cmpl $-0x2, %eax
jb 0xec5c
movl (%rbx), %eax
addl $-0x61, %eax
movl $0x39, %r14d
cmpl $-0x7, %eax
jbe 0xec5c
jmp 0xedb9
movl %r12d, %r14d
jmp 0xedb9