// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %r15
movq 0x30(%rsi), %rsi
testq %rsi, %rsi
je 0xe409
cmpq $0x0, 0x38(%rsi)
je 0xe409
movq %r15, %rdi
callq 0xe366
movl %eax, %r12d
movq 0x30(%r14), %rax
movq 0x38(%rax), %rsi
movq %r15, %rdi
callq 0xe366
cmpl $0x3b, %r12d
je 0xe436
movl %eax, %r13d
cmpl $0x3b, %eax
je 0xe436
xorl %ebx, %ebx
testl %r12d, %r12d
je 0xe572
testl %r13d, %r13d
je 0xe572
cmpl %r13d, %r12d
jne 0xe4ab
leal -0x39(%r12), %eax
cmpl $-0x2, %eax
jae 0xe4ff
cmpl $0x39, %r12d
jne 0xe517
movl (%r14), %eax
andl $-0x2, %eax
movl $0x39, %ebx
cmpl $0x4e, %eax
jne 0xe517
jmp 0xe572
movl (%r14), %eax
cmpl $0x40, %eax
je 0xe486
cmpl $0x71, %eax
je 0xe47c
cmpl $0x72, %eax
jne 0xe4a1
leaq 0x22bfe(%rip), %rax     # 0x31024
movl $0x1, (%rax)
movl $0x38, %ebx
jmp 0xe572
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xe989
movq %r15, %rdi
callq 0xc0ec
movq 0x8(%r14), %rcx
movq 0x30(%r14), %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 0x4ddc(%rip), %rdi      # 0x13249
movq %rax, %rsi
xorl %eax, %eax
callq 0x10b0
jmp 0xe572
movl $0x37, %ebx
jmp 0xe572
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe1a5
movl $0x39, %ebx
jmp 0xe572
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xe989
movq %r15, %rdi
callq 0xc0ec
movq %rax, -0x30(%rbp)
movq 0x8(%r14), %rax
movl 0x10(%rax), %r14d
movq 0x8(%rax), %r15
movl %r12d, %edi
callq 0xc9b3
movq %rax, %r12
movl %r13d, %edi
callq 0xc9b3
leaq 0x4df3(%rip), %rdi      # 0x132d9
movq -0x30(%rbp), %rsi
movl %r14d, %edx
movq %r15, %rcx
movq %r12, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x10b0
jmp 0xe572
movl (%r14), %eax
leal -0x5b(%rax), %ecx
cmpl $-0x5, %ecx
ja 0xe56f
addl $-0x61, %eax
movl $0x39, %ebx
cmpl $-0x6, %eax
jae 0xe572
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xe989
movq %r15, %rdi
callq 0xc0ec
movq %rax, %r15
movq 0x8(%r14), %rax
movl 0x10(%rax), %r14d
movq 0x8(%rax), %r13
movl %r12d, %edi
callq 0xc9b3
leaq 0x4e2d(%rip), %rdi      # 0x13373
movq %r15, %rsi
movl %r14d, %edx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x10b0
leaq 0x22ac8(%rip), %rax     # 0x31028
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0xe572
movl %r12d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq