-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_analysis.cpp
More file actions
66 lines (61 loc) · 1.41 KB
/
types_analysis.cpp
File metadata and controls
66 lines (61 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Created by Vlad on 19-May-22.
//
#include "symbol_table.h"
#include "semantic_analysis.h"
using namespace std;
void cast(const Type & dst, const Type &src)
{
if(src.nElements > -1)
{
if(dst.nElements > -1)
{
if(src.typeBase != dst.typeBase)
{
cout << "An array cannot be converted to an array of another type!\n";
exit(0);
}
}
else
{
cout<<"An array cannot be converted to a non-array!\n";
exit(0);
}
}
else
{
if(dst.nElements > -1)
{
cout<<"A non-array cannot be converted to an array!\n";
}
}
switch(src.typeBase)
{
case TB_CHAR:
case TB_INT:
case TB_DOUBLE:
switch(dst.typeBase)
{
case TB_CHAR:
case TB_INT:
case TB_DOUBLE:
return;
}
case TB_STRUCT:
if(dst.typeBase==TB_STRUCT){
if(src.struct_type != dst.struct_type)
{
cout << "A structure cannot be converted to another one!\n";
exit(0);
}
return;
}
}
cout<<"Cast failed! Incompatible types!\n";
exit(0);
}
Type getArithType(const Type & t1, const Type & t2)
{
//for now
return t2;
}