10
10
interface
11
11
12
12
uses
13
- SysUtils, Classes,
13
+ SysUtils, Classes, nullable,
14
14
simba.base,
15
15
simba.containers,
16
16
simba.ide_codetools_base,
@@ -25,7 +25,8 @@ TDeclarationClass = class of TDeclaration;
25
25
TDeclarationArray = array of TDeclaration;
26
26
27
27
TDeclarationStack = specialize TSimbaStack<TDeclaration>;
28
- TDeclarationCache = specialize TCache<TDeclarationArray>;
28
+ TDeclarationCache = specialize TNullable<TDeclarationArray>;
29
+ TStringCache = specialize TNullable<String>;
29
30
30
31
TDeclarationList = class (TObject)
31
32
protected
@@ -722,7 +723,7 @@ procedure TDeclarationList.Clear(const FreeDecls: Boolean);
722
723
723
724
function TDeclaration.GetText : String;
724
725
begin
725
- if FText.Empty then
726
+ if FText.IsNull then
726
727
FText := FLexer.CopyDoc(FStartPos, FEndPos);
727
728
728
729
Result := FText;
@@ -750,7 +751,7 @@ function TDeclaration.GetTextNoComments: String;
750
751
end ;
751
752
752
753
begin
753
- if FTextNoComments.Empty then
754
+ if FTextNoComments.IsNull then
754
755
FTextNoComments := Filter(FLexer.CopyDoc(FStartPos, FEndPos));
755
756
756
757
Result := FTextNoComments;
@@ -786,18 +787,15 @@ function TDeclaration.GetTextNoCommentsSingleLine: String;
786
787
end ;
787
788
788
789
begin
789
- if FTextNoCommentsSingleLine.Empty then
790
+ if FTextNoCommentsSingleLine.IsNull then
790
791
FTextNoCommentsSingleLine := Filter(FLexer.CopyDoc(FStartPos, FEndPos));
791
792
792
793
Result := FTextNoCommentsSingleLine;
793
794
end ;
794
795
795
796
function TDeclaration.GetName : String;
796
797
begin
797
- if FName.Empty then
798
- Result := ' '
799
- else
800
- Result := FName;
798
+ Result := FName.ValueOrDefault;
801
799
end ;
802
800
803
801
function TDeclaration.GetFullName : String;
@@ -1002,31 +1000,23 @@ constructor TDeclaration_Keyword.Create(Keyword: String);
1002
1000
1003
1001
function TDeclaration_Anchor.GetHeader : String;
1004
1002
begin
1005
- if FHeader.Empty then
1006
- begin
1007
- Result := ' Anchor "' + Name + ' "' ;
1008
-
1009
- FHeader := Result;
1010
- end ;
1003
+ if FHeader.IsNull then
1004
+ FHeader := ' Anchor "' + Name + ' "' ;
1011
1005
1012
1006
Result := FHeader;
1013
1007
end ;
1014
1008
1015
1009
function TDeclaration_Type.GetHeader : String;
1016
1010
begin
1017
- if FHeader.Empty then
1018
- begin
1019
- Result := ' type ' + Name + ' = ' + TextNoCommentsSingleLine;
1020
-
1021
- FHeader := Result;
1022
- end ;
1011
+ if FHeader.IsNull then
1012
+ FHeader := ' type ' + Name + ' = ' + TextNoCommentsSingleLine;
1023
1013
1024
1014
Result := FHeader;
1025
1015
end ;
1026
1016
1027
1017
function TDeclaration_EnumElement.GetName : string;
1028
1018
begin
1029
- if FName.Empty then
1019
+ if FName.IsNull then
1030
1020
FName := Items.GetTextOfClass(TDeclaration_EnumElementName);
1031
1021
1032
1022
Result := inherited ;
@@ -1042,13 +1032,10 @@ function TDeclaration_EnumElement.GetFullName: String;
1042
1032
1043
1033
function TDeclaration_EnumElement.GetHeader : String;
1044
1034
begin
1045
- if FHeader.Empty then
1046
- begin
1047
- if (FParent is TDeclaration_TypeEnumScoped) then
1048
- Result := FParent.Name + ' .' + Name
1049
- else
1050
- Result := Name ;
1051
- end ;
1035
+ if FHeader.IsNull then
1036
+ FHeader := IfThen(FParent is TDeclaration_TypeEnumScoped, FParent.Name + ' .' + Name , Name );
1037
+
1038
+ Result := FHeader;
1052
1039
end ;
1053
1040
1054
1041
function TDeclaration_TypeAlias.Dump : String;
@@ -1098,36 +1085,24 @@ function TDeclaration_TypeArray.VarType: TDeclaration;
1098
1085
1099
1086
function TDeclaration_TypeRecord.GetFields : TDeclarationArray;
1100
1087
begin
1101
- if FFields.Empty then
1102
- begin
1103
- Result := Items.GetByClass(TDeclaration_Field);
1104
-
1105
- FFields := Result;
1106
- end ;
1088
+ if FFields.IsNull then
1089
+ FFields := Items.GetByClass(TDeclaration_Field, True);
1107
1090
1108
1091
Result := FFields;
1109
1092
end ;
1110
1093
1111
1094
function TDeclaration_TypeRecord.GetConsts : TDeclarationArray;
1112
1095
begin
1113
- if FConsts.Empty then
1114
- begin
1115
- Result := Items.GetByClass(TDeclaration_Const);
1116
-
1117
- FConsts := Result;
1118
- end ;
1096
+ if FConsts.IsNull then
1097
+ FConsts := Items.GetByClass(TDeclaration_Const, True);
1119
1098
1120
1099
Result := FConsts;
1121
1100
end ;
1122
1101
1123
1102
function TDeclaration_Var.GetHeader : String;
1124
1103
begin
1125
- if FHeader.Empty then
1126
- begin
1127
- Result := ' var ' + Name + VarTypeString + VarDefaultString;
1128
-
1129
- FHeader := Result;
1130
- end ;
1104
+ if FHeader.IsNull then
1105
+ FHeader := ' var ' + Name + VarTypeString + VarDefaultString;
1131
1106
1132
1107
Result := FHeader;
1133
1108
end ;
@@ -1139,15 +1114,15 @@ function TDeclaration_Var.GetVarType: TDeclaration;
1139
1114
1140
1115
function TDeclaration_Var.GetVarTypeString : String;
1141
1116
begin
1142
- if FVarTypeString.Empty then
1117
+ if FVarTypeString.IsNull then
1143
1118
FVarTypeString := Items.GetTextOfClassNoCommentsSingleLine(TDeclaration_VarType, ' : ' );
1144
1119
1145
1120
Result := FVarTypeString;
1146
1121
end ;
1147
1122
1148
1123
function TDeclaration_Var.GetVarDefaultString : String;
1149
1124
1150
- function ReplaceunPrintable (const Str: String): String;
1125
+ function ReplaceUnPrintable (const Str: String): String;
1151
1126
var
1152
1127
I: Integer = 1 ;
1153
1128
begin
@@ -1165,27 +1140,24 @@ function TDeclaration_Var.GetVarDefaultString: String;
1165
1140
end ;
1166
1141
1167
1142
begin
1168
- if FVarDefaultString.Empty then
1143
+ if FVarDefaultString.IsNull then
1169
1144
begin
1170
1145
case DefToken of
1171
1146
tokAssign: FVarDefaultString := Items.GetTextOfClassNoCommentsSingleLine(TDeclaration_VarDefault, ' := ' );
1172
1147
tokEqual: FVarDefaultString := Items.GetTextOfClassNoCommentsSingleLine(TDeclaration_VarDefault, ' = ' );
1148
+ else
1149
+ FVarDefaultString := ' ' ;
1173
1150
end ;
1174
-
1175
- FVarDefaultString := ReplaceunPrintable(FVarDefaultString);
1151
+ FVarDefaultString := ReplaceUnPrintable(FVarDefaultString);
1176
1152
end ;
1177
1153
1178
1154
Result := FVarDefaultString;
1179
1155
end ;
1180
1156
1181
1157
function TDeclaration_Const.GetHeader : String;
1182
1158
begin
1183
- if FHeader.Empty then
1184
- begin
1185
- Result := ' const ' + Name + VarDefaultString;
1186
-
1187
- FHeader := Result;
1188
- end ;
1159
+ if FHeader.IsNull then
1160
+ FHeader := ' const ' + Name + VarDefaultString;
1189
1161
1190
1162
Result := FHeader;
1191
1163
end ;
@@ -1199,32 +1171,24 @@ function TDeclaration_Field.Dump: String;
1199
1171
1200
1172
function TDeclaration_EnumElementName.GetName : string;
1201
1173
begin
1202
- if FName.Empty then
1174
+ if FName.IsNull then
1203
1175
FName := Text;
1204
1176
1205
1177
Result := FName;
1206
1178
end ;
1207
1179
1208
1180
function TDeclaration_TypeEnum.GetElements : TDeclarationArray;
1209
1181
begin
1210
- if FElements.Empty then
1211
- begin
1212
- Result := FItems.GetByClass(TDeclaration_EnumElement);
1213
-
1214
- FElements := Result;
1215
- end ;
1182
+ if FElements.IsNull then
1183
+ FElements := FItems.GetByClass(TDeclaration_EnumElement);
1216
1184
1217
1185
Result := FElements;
1218
1186
end ;
1219
1187
1220
1188
function TDeclaration_TypeSet.GetEnumElements : TDeclarationArray;
1221
1189
begin
1222
- if FEnumElements.Empty then
1223
- begin
1224
- Result := FItems.GetByClass(TDeclaration_EnumElement);
1225
-
1226
- FEnumElements := Result;
1227
- end ;
1190
+ if FEnumElements.IsNull then
1191
+ FEnumElements := FItems.GetByClass(TDeclaration_EnumElement);
1228
1192
1229
1193
Result := FEnumElements;
1230
1194
end ;
@@ -1301,15 +1265,15 @@ function TDeclaration_Method.GetParamVarType(Index: Integer): TDeclaration;
1301
1265
1302
1266
function TDeclaration_Method.GetParamString : String;
1303
1267
begin
1304
- if FParamString.Empty then
1268
+ if FParamString.IsNull then
1305
1269
FParamString := FItems.GetTextOfClassNoCommentsSingleLine(TDeclaration_ParamList);
1306
1270
1307
1271
Result := FParamString;
1308
1272
end ;
1309
1273
1310
1274
function TDeclaration_Method.GetResultString : String;
1311
1275
begin
1312
- if FResultString.Empty then
1276
+ if FResultString.IsNull then
1313
1277
FResultString := FItems.GetTextOfClassNoCommentsSingleLine(TDeclaration_MethodResult, ' : ' );
1314
1278
1315
1279
Result := FResultString;
@@ -1319,7 +1283,7 @@ function TDeclaration_Method.GetHeader: String;
1319
1283
var
1320
1284
Builder: TSimbaStringBuilder;
1321
1285
begin
1322
- if FHeader.Empty then
1286
+ if FHeader.IsNull then
1323
1287
begin
1324
1288
if isFunc then Builder.Append(' function' ) else
1325
1289
if isProc then Builder.Append(' procedure' ) else
@@ -1346,16 +1310,14 @@ function TDeclaration_Method.GetParams: TDeclarationArray;
1346
1310
var
1347
1311
Decl: TDeclaration;
1348
1312
begin
1349
- Result := [];
1350
-
1351
- if FParams.Empty then
1313
+ if FParams.IsNull then
1352
1314
begin
1315
+ FParams := [];
1316
+
1353
1317
Decl := Items.GetByClassFirst(TDeclaration_ParamList);
1354
1318
if (Decl <> nil ) then
1355
1319
for Decl in Decl.Items.GetByClass(TDeclaration_ParamGroup) do
1356
- Result.Add(Decl.Items.GetByClass(TDeclaration_Parameter));
1357
-
1358
- FParams := Result;
1320
+ FParams.Value .Add(Decl.Items.GetByClass(TDeclaration_Parameter));
1359
1321
end ;
1360
1322
1361
1323
Result := FParams;
@@ -1370,7 +1332,7 @@ function TDeclaration_MethodOfType.GetHeader: String;
1370
1332
var
1371
1333
Builder: TSimbaStringBuilder;
1372
1334
begin
1373
- if FHeader.Empty then
1335
+ if FHeader.IsNull then
1374
1336
begin
1375
1337
if isFunc then Builder.Append(' function' ) else
1376
1338
if isProc then Builder.Append(' procedure' ) else
@@ -1488,7 +1450,7 @@ function TCodeParser.GetHash: String;
1488
1450
Builder: TSimbaStringBuilder;
1489
1451
I: Integer;
1490
1452
begin
1491
- if FHash.Empty then
1453
+ if FHash.IsNull then
1492
1454
begin
1493
1455
with Lexer.SaveDefines() do
1494
1456
Builder.Append(Defines + IntToStr(Stack));
@@ -2037,7 +1999,7 @@ procedure TCodeParser.Reset;
2037
1999
begin
2038
2000
inherited Reset();
2039
2001
2040
- FHash.Empty := True ;
2002
+ FHash.Clear() ;
2041
2003
FManagedItems.Clear(True);
2042
2004
2043
2005
FRoot.Items.Clear();
0 commit comments