-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDataType.pas
More file actions
75 lines (65 loc) · 1.72 KB
/
DataType.pas
File metadata and controls
75 lines (65 loc) · 1.72 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
67
68
69
70
71
72
73
74
75
unit DataType;
interface
uses
Classes, Types, Generics.Collections, CodeElement;
type
TRawType = (rtUInteger, rtBoolean, rtPointer, rtArray, rtRecord, rtString, rtNilType);
TDataType = class(TCodeElement)
private
FRawType: TRawType;
FSize: Integer;
FBaseType: TDataType;
FDimensions: TList<Integer>;
function GetIsStaticArray: Boolean;
public
constructor Create(AName: string; ASize: Integer = 2; APrimitive: TRawType = rtUInteger;
ABaseType: TDataType = nil);
function GetRamWordSize(): Integer;
property Size: Integer read FSize;
property RawType: TRawType read FRawType;
property BaseType: TDataType read FBaseType;
property Dimensions: TList<Integer> read FDimensions;
property IsStaticArray: Boolean read GetIsStaticArray;
end;
implementation
{ TDataType }
constructor TDataType.Create(AName: string; ASize: Integer = 2;
APrimitive: TRawType = rtUInteger; ABaseType: TDataType = nil);
begin
inherited Create(AName);
FDimensions := TList<Integer>.Create();
FSize := ASize;
FRawType := APrimitive;
if Assigned(ABaseType) then
begin
FBaseType := ABaseType;
end
else
begin
FBaseType := Self;
end;
end;
function TDataType.GetIsStaticArray: Boolean;
begin
Result := (RawType = rtArray) and (FDimensions.Count > 0);
end;
function TDataType.GetRamWordSize: Integer;
var
LArSize: Integer;
LDimSize: Integer;
begin
if RawType = rtArray then
begin
LArSize := 1;
for LDimSize in FDimensions do
begin
LArSize := LArSize * LDimSize;
end;
Result := LArSize * BaseType.GetRamWordSize();
end
else
begin
Result := FSize div 2;
end;
end;
end.