-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuPSCompiler.pas
15789 lines (14476 loc) · 451 KB
/
uPSCompiler.pas
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit uPSCompiler;
{$I PascalScript.inc}
interface
uses
{$IFNDEF DELPHI3UP}{$IFNDEF PS_NOINTERFACES}{$IFNDEF LINUX}Windows, Ole2,{$ENDIF}
{$ENDIF}{$ENDIF}SysUtils, uPSUtils;
type
{$IFNDEF PS_NOINTERFACES}
TPSInterface = class;
{$ENDIF}
TPSParameterMode = (pmIn, pmOut, pmInOut);
TPSPascalCompiler = class;
TPSType = class;
TPSValue = class;
TPSParameters = class;
TPSSubOptType = (tMainBegin, tProcBegin, tSubBegin, tOneLiner, tifOneliner, tRepeat, tTry, tTryEnd
{$IFDEF PS_USESSUPPORT},tUnitInit, tUnitFinish {$ENDIF}); //nvds
{TPSExternalClass is used when external classes need to be called}
TPSCompileTimeClass = class;
TPSAttributes = class;
TPSAttribute = class;
EPSCompilerException = class(Exception) end;
TPSParameterDecl = class(TObject)
private
FName: tbtString;
FOrgName: tbtString;
FMode: TPSParameterMode;
FType: TPSType;
{$IFDEF PS_USESSUPPORT}
FDeclareUnit: tbtString;
{$ENDIF}
FDeclarePos: Cardinal;
FDeclareRow: Cardinal;
FDeclareCol: Cardinal;
procedure SetName(const s: tbtString);
public
property Name: tbtString read FName;
property OrgName: tbtString read FOrgName write SetName;
property aType: TPSType read FType write FType;
property Mode: TPSParameterMode read FMode write FMode;
{$IFDEF PS_USESSUPPORT}
property DeclareUnit: tbtString read FDeclareUnit write FDeclareUnit;
{$ENDIF}
property DeclarePos: Cardinal read FDeclarePos write FDeclarePos;
property DeclareRow: Cardinal read FDeclareRow write FDeclareRow;
property DeclareCol: Cardinal read FDeclareCol write FDeclareCol;
end;
TPSParametersDecl = class(TObject)
private
FParams: TPSList;
FResult: TPSType;
function GetParam(I: Longint): TPSParameterDecl;
function GetParamCount: Longint;
public
property Params[I: Longint]: TPSParameterDecl read GetParam;
property ParamCount: Longint read GetParamCount;
function AddParam: TPSParameterDecl;
procedure DeleteParam(I: Longint);
property Result : TPSType read FResult write FResult;
procedure Assign(Params: TPSParametersDecl);
function Same(d: TPSParametersDecl): boolean;
constructor Create;
destructor Destroy; override;
end;
TPSRegProc = class(TObject)
private
FNameHash: Longint;
FName: tbtString;
FDecl: TPSParametersDecl;
FExportName: Boolean;
FImportDecl: tbtString;
FOrgName: tbtString;
procedure SetName(const Value: tbtString);
public
property OrgName: tbtString read FOrgName write FOrgName;
property Name: tbtString read FName write SetName;
property NameHash: Longint read FNameHash;
property Decl: TPSParametersDecl read FDecl;
property ExportName: Boolean read FExportName write FExportName;
property ImportDecl: tbtString read FImportDecl write FImportDecl;
constructor Create;
destructor Destroy; override;
end;
PIFPSRegProc = TPSRegProc;
PIfRVariant = ^TIfRVariant;
TIfRVariant = record
FType: TPSType;
case Byte of
1: (tu8: TbtU8);
2: (tS8: TbtS8);
3: (tu16: TbtU16);
4: (ts16: TbtS16);
5: (tu32: TbtU32);
6: (ts32: TbtS32);
7: (tsingle: TbtSingle);
8: (tdouble: TbtDouble);
9: (textended: TbtExtended);
11: (tcurrency: tbtCurrency);
10: (tstring: Pointer);
{$IFNDEF PS_NOINT64}
17: (ts64: Tbts64);
{$ENDIF}
19: (tchar: tbtChar);
{$IFNDEF PS_NOWIDESTRING}
18: (twidestring: Pointer);
20: (twidechar: tbtwidechar);
{$ENDIF}
21: (ttype: TPSType);
22: (tunistring: Pointer);
end;
TPSRecordFieldTypeDef = class(TObject)
private
FFieldOrgName: tbtString;
FFieldName: tbtString;
FFieldNameHash: Longint;
FType: TPSType;
procedure SetFieldOrgName(const Value: tbtString);
public
property FieldOrgName: tbtString read FFieldOrgName write SetFieldOrgName;
property FieldName: tbtString read FFieldName;
property FieldNameHash: Longint read FFieldNameHash;
property aType: TPSType read FType write FType;
end;
PIFPSRecordFieldTypeDef = TPSRecordFieldTypeDef;
TPSType = class(TObject)
private
FNameHash: Longint;
FName: tbtString;
FBaseType: TPSBaseType;
{$IFDEF PS_USESSUPPORT}
FDeclareUnit: tbtString;
{$ENDIF}
FDeclarePos: Cardinal;
FDeclareRow: Cardinal;
FDeclareCol: Cardinal;
FUsed: Boolean;
FExportName: Boolean;
FOriginalName: tbtString;
FAttributes: TPSAttributes;
FFinalTypeNo: cardinal;
procedure SetName(const Value: tbtString);
public
constructor Create;
destructor Destroy; override;
property Attributes: TPSAttributes read FAttributes;
property FinalTypeNo: cardinal read FFinalTypeNo;
property OriginalName: tbtString read FOriginalName write FOriginalName;
property Name: tbtString read FName write SetName;
property NameHash: Longint read FNameHash;
property BaseType: TPSBaseType read FBaseType write FBaseType;
{$IFDEF PS_USESSUPPORT}
property DeclareUnit: tbtString read FDeclareUnit write FDeclareUnit;
{$ENDIF}
property DeclarePos: Cardinal read FDeclarePos write FDeclarePos;
property DeclareRow: Cardinal read FDeclareRow write FDeclareRow;
property DeclareCol: Cardinal read FDeclareCol write FDeclareCol;
property Used: Boolean read FUsed;
property ExportName: Boolean read FExportName write FExportName;
procedure Use;
end;
PIFPSType = TPSType;
TPSVariantType = class(TPSType)
private
public
function GetDynInvokeProcNo(Owner: TPSPascalCompiler; const Name: tbtString; Params: TPSParameters): Cardinal; virtual;
function GetDynIvokeSelfType(Owner: TPSPascalCompiler): TPSType; virtual;
function GetDynInvokeParamType(Owner: TPSPascalCompiler): TPSType; virtual;
function GetDynIvokeResulType(Owner: TPSPascalCompiler): TPSType; virtual;
end;
TPSRecordType = class(TPSType)
private
FRecordSubVals: TPSList;
public
constructor Create;
destructor Destroy; override;
function RecValCount: Longint;
function RecVal(I: Longint): PIFPSRecordFieldTypeDef;
function AddRecVal: PIFPSRecordFieldTypeDef;
end;
TPSClassType = class(TPSType)
private
FCL: TPSCompiletimeClass;
public
property Cl: TPSCompileTimeClass read FCL write FCL;
end;
TPSExternalClass = class;
TPSUndefinedClassType = class(TPSType)
private
FExtClass: TPSExternalClass;
public
property ExtClass: TPSExternalClass read FExtClass write FExtClass;
end;
{$IFNDEF PS_NOINTERFACES}
TPSInterfaceType = class(TPSType)
private
FIntf: TPSInterface;
public
property Intf: TPSInterface read FIntf write FIntf;
end;
{$ENDIF}
TPSProceduralType = class(TPSType)
private
FProcDef: TPSParametersDecl;
public
property ProcDef: TPSParametersDecl read FProcDef;
constructor Create;
destructor Destroy; override;
end;
TPSArrayType = class(TPSType)
private
FArrayTypeNo: TPSType;
public
property ArrayTypeNo: TPSType read FArrayTypeNo write FArrayTypeNo;
end;
TPSStaticArrayType = class(TPSArrayType)
private
FStartOffset: Longint;
FLength: Cardinal;
public
property StartOffset: Longint read FStartOffset write FStartOffset;
property Length: Cardinal read FLength write FLength;
end;
TPSSetType = class(TPSType)
private
FSetType: TPSType;
function GetByteSize: Longint;
function GetBitSize: Longint;
public
property SetType: TPSType read FSetType write FSetType;
property ByteSize: Longint read GetByteSize;
property BitSize: Longint read GetBitSize;
end;
TPSTypeLink = class(TPSType)
private
FLinkTypeNo: TPSType;
public
property LinkTypeNo: TPSType read FLinkTypeNo write FLinkTypeNo;
end;
TPSEnumType = class(TPSType)
private
FHighValue: Cardinal;
public
property HighValue: Cardinal read FHighValue write FHighValue;
end;
TPSProcedure = class(TObject)
private
FAttributes: TPSAttributes;
public
property Attributes: TPSAttributes read FAttributes;
constructor Create;
destructor Destroy; override;
end;
TPSAttributeType = class;
TPSAttributeTypeField = class(TObject)
private
FOwner: TPSAttributeType;
FFieldOrgName: tbtString;
FFieldName: tbtString;
FFieldNameHash: Longint;
FFieldType: TPSType;
FHidden: Boolean;
procedure SetFieldOrgName(const Value: tbtString);
public
constructor Create(AOwner: TPSAttributeType);
property Owner: TPSAttributeType read FOwner;
property FieldOrgName: tbtString read FFieldOrgName write SetFieldOrgName;
property FieldName: tbtString read FFieldName;
property FieldNameHash: Longint read FFieldNameHash;
property FieldType: TPSType read FFieldType write FFieldType;
property Hidden: Boolean read FHidden write FHidden;
end;
TPSApplyAttributeToType = function (Sender: TPSPascalCompiler; aType: TPSType; Attr: TPSAttribute): Boolean;
TPSApplyAttributeToProc = function (Sender: TPSPascalCompiler; aProc: TPSProcedure; Attr: TPSAttribute): Boolean;
{ An attribute type }
TPSAttributeType = class(TPSType)
private
FFields: TPSList;
FName: tbtString;
FOrgname: tbtString;
FNameHash: Longint;
FAAProc: TPSApplyAttributeToProc;
FAAType: TPSApplyAttributeToType;
function GetField(I: Longint): TPSAttributeTypeField;
function GetFieldCount: Longint;
procedure SetName(const s: tbtString);
public
property OnApplyAttributeToType: TPSApplyAttributeToType read FAAType write FAAType;
property OnApplyAttributeToProc: TPSApplyAttributeToProc read FAAProc write FAAProc;
property Fields[i: Longint]: TPSAttributeTypeField read GetField;
property FieldCount: Longint read GetFieldCount;
procedure DeleteField(I: Longint);
function AddField: TPSAttributeTypeField;
property Name: tbtString read FName;
property OrgName: tbtString read FOrgName write SetName;
property NameHash: Longint read FNameHash;
constructor Create;
destructor Destroy; override;
end;
TPSAttribute = class(TObject)
private
FAttribType: TPSAttributeType;
FValues: TPSList;
function GetValueCount: Longint;
function GetValue(I: Longint): PIfRVariant;
public
constructor Create(AttribType: TPSAttributeType);
procedure Assign(Item: TPSAttribute);
property AType: TPSAttributeType read FAttribType;
property Count: Longint read GetValueCount;
property Values[i: Longint]: PIfRVariant read GetValue; default;
procedure DeleteValue(i: Longint);
function AddValue(v: PIFRVariant): Longint;
destructor Destroy; override;
end;
TPSAttributes = class(TObject)
private
FItems: TPSList;
function GetCount: Longint;
function GetItem(I: Longint): TPSAttribute;
public
procedure Assign(attr: TPSAttributes; Move: Boolean);
property Count: Longint read GetCount;
property Items[i: Longint]: TPSAttribute read GetItem; default;
procedure Delete(i: Longint);
function Add(AttribType: TPSAttributeType): TPSAttribute;
function FindAttribute(const Name: tbtString): TPSAttribute;
constructor Create;
destructor Destroy; override;
end;
TPSProcVar = class(TObject)
private
FNameHash: Longint;
FName: tbtString;
FOrgName: tbtString;
FType: TPSType;
FUsed: Boolean;
{$IFDEF PS_USESSUPPORT}
FDeclareUnit: tbtString;
{$ENDIF}
FDeclarePos, FDeclareRow, FDeclareCol: Cardinal;
procedure SetName(const Value: tbtString);
public
property OrgName: tbtString read FOrgName write FOrgname;
property NameHash: Longint read FNameHash;
property Name: tbtString read FName write SetName;
property AType: TPSType read FType write FType;
property Used: Boolean read FUsed;
{$IFDEF PS_USESSUPPORT}
property DeclareUnit: tbtString read FDeclareUnit write FDeclareUnit;
{$ENDIF}
property DeclarePos: Cardinal read FDeclarePos write FDeclarePos;
property DeclareRow: Cardinal read FDeclareRow write FDeclareRow;
property DeclareCol: Cardinal read FDeclareCol write FDeclareCol;
procedure Use;
end;
PIFPSProcVar = TPSProcVar;
TPSExternalProcedure = class(TPSProcedure)
private
FRegProc: TPSRegProc;
public
property RegProc: TPSRegProc read FRegProc write FRegProc;
end;
TPSInternalProcedure = class(TPSProcedure)
private
FForwarded: Boolean;
FData: tbtString;
FNameHash: Longint;
FName: tbtString;
FDecl: TPSParametersDecl;
FProcVars: TPSList;
FUsed: Boolean;
FOutputDeclPosition: Cardinal;
FResultUsed: Boolean;
FLabels: TIfStringList;
FGotos: TIfStringList;
FDeclareRow: Cardinal;
{$IFDEF PS_USESSUPPORT}
FDeclareUnit: tbtString;
{$ENDIF}
FDeclarePos: Cardinal;
FDeclareCol: Cardinal;
FOriginalName: tbtString;
procedure SetName(const Value: tbtString);
public
constructor Create;
destructor Destroy; override;
{Attributes}
property Forwarded: Boolean read FForwarded write FForwarded;
property Data: tbtString read FData write FData;
property Decl: TPSParametersDecl read FDecl;
property OriginalName: tbtString read FOriginalName write FOriginalName;
property Name: tbtString read FName write SetName;
property NameHash: Longint read FNameHash;
property ProcVars: TPSList read FProcVars;
property Used: Boolean read FUsed;
{$IFDEF PS_USESSUPPORT}
property DeclareUnit: tbtString read FDeclareUnit write FDeclareUnit;
{$ENDIF}
property DeclarePos: Cardinal read FDeclarePos write FDeclarePos;
property DeclareRow: Cardinal read FDeclareRow write FDeclareRow;
property DeclareCol: Cardinal read FDeclareCol write FDeclareCol;
property OutputDeclPosition: Cardinal read FOutputDeclPosition write FOutputDeclPosition;
property ResultUsed: Boolean read FResultUsed;
property Labels: TIfStringList read FLabels;
property Gotos: TIfStringList read FGotos;
procedure Use;
procedure ResultUse;
end;
TPSVar = class(TObject)
private
FNameHash: Longint;
FOrgName: tbtString;
FName: tbtString;
FType: TPSType;
FUsed: Boolean;
FExportName: tbtString;
FDeclareRow: Cardinal;
{$IFDEF PS_USESSUPPORT}
FDeclareUnit: tbtString;
{$ENDIF}
FDeclarePos: Cardinal;
FDeclareCol: Cardinal;
FSaveAsPointer: Boolean;
procedure SetName(const Value: tbtString);
public
property SaveAsPointer: Boolean read FSaveAsPointer write FSaveAsPointer;
property ExportName: tbtString read FExportName write FExportName;
property Used: Boolean read FUsed;
property aType: TPSType read FType write FType;
property OrgName: tbtString read FOrgName write FOrgName;
property Name: tbtString read FName write SetName;
property NameHash: Longint read FNameHash;
{$IFDEF PS_USESSUPPORT}
property DeclareUnit: tbtString read FDeclareUnit write FDeclareUnit;
{$ENDIF}
property DeclarePos: Cardinal read FDeclarePos write FDeclarePos;
property DeclareRow: Cardinal read FDeclareRow write FDeclareRow;
property DeclareCol: Cardinal read FDeclareCol write FDeclareCol;
procedure Use;
end;
PIFPSVar = TPSVar;
TPSConstant = class(TObject)
private
FOrgName: tbtString;
FNameHash: Longint;
FName: tbtString;
FDeclareRow: Cardinal;
{$IFDEF PS_USESSUPPORT}
FDeclareUnit: tbtString;
{$ENDIF}
FDeclarePos: Cardinal;
FDeclareCol: Cardinal;
FValue: PIfRVariant;
procedure SetName(const Value: tbtString);
public
property OrgName: tbtString read FOrgName write FOrgName;
property Name: tbtString read FName write SetName;
property NameHash: Longint read FNameHash;
property Value: PIfRVariant read FValue write FValue;
{$IFDEF PS_USESSUPPORT}
property DeclareUnit: tbtString read FDeclareUnit write FDeclareUnit;
{$ENDIF}
property DeclarePos: Cardinal read FDeclarePos write FDeclarePos;
property DeclareRow: Cardinal read FDeclareRow write FDeclareRow;
property DeclareCol: Cardinal read FDeclareCol write FDeclareCol;
procedure SetSet(const val);
procedure SetInt(const Val: Longint);
procedure SetUInt(const Val: Cardinal);
{$IFNDEF PS_NOINT64}
procedure SetInt64(const Val: Int64);
{$ENDIF}
procedure SetString(const Val: tbtString);
procedure SetChar(c: tbtChar);
{$IFNDEF PS_NOWIDESTRING}
procedure SetWideChar(const val: WideChar);
procedure SetWideString(const val: tbtwidestring);
procedure SetUnicodeString(const val: tbtunicodestring);
{$ENDIF}
procedure SetExtended(const Val: Extended);
destructor Destroy; override;
end;
PIFPSConstant = TPSConstant;
TPSPascalCompilerErrorType = (
ecUnknownIdentifier,
ecIdentifierExpected,
ecCommentError,
ecStringError,
ecCharError,
ecSyntaxError,
ecUnexpectedEndOfFile,
ecSemicolonExpected,
ecBeginExpected,
ecPeriodExpected,
ecDuplicateIdentifier,
ecColonExpected,
ecUnknownType,
ecCloseRoundExpected,
ecTypeMismatch,
ecInternalError,
ecAssignmentExpected,
ecThenExpected,
ecDoExpected,
ecNoResult,
ecOpenRoundExpected,
ecCommaExpected,
ecToExpected,
ecIsExpected,
ecOfExpected,
ecCloseBlockExpected,
ecVariableExpected,
ecStringExpected,
ecEndExpected,
ecUnSetLabel,
ecNotInLoop,
ecInvalidJump,
ecOpenBlockExpected,
ecWriteOnlyProperty,
ecReadOnlyProperty,
ecClassTypeExpected,
ecCustomError,
ecDivideByZero,
ecMathError,
ecUnsatisfiedForward,
ecForwardParameterMismatch,
ecInvalidnumberOfParameters
{$IFDEF PS_USESSUPPORT}
, ecNotAllowed,
ecUnitNotFoundOrContainsErrors,
ecCrossReference
{$ENDIF}
);
TPSPascalCompilerHintType = (
ehVariableNotUsed,
ehFunctionNotUsed,
ehCustomHint
);
TPSPascalCompilerWarningType = (
ewCalculationAlwaysEvaluatesTo,
ewIsNotNeeded,
ewAbstractClass,
ewCustomWarning
);
TPSPascalCompilerMessage = class(TObject)
protected
FRow: Cardinal;
FCol: Cardinal;
FModuleName: tbtString;
FParam: tbtString;
FPosition: Cardinal;
procedure SetParserPos(Parser: TPSPascalParser);
public
property ModuleName: tbtString read FModuleName write FModuleName;
property Param: tbtString read FParam write FParam;
property Pos: Cardinal read FPosition write FPosition;
property Row: Cardinal read FRow write FRow;
property Col: Cardinal read FCol write FCol;
function ErrorType: tbtString; virtual; abstract;
procedure SetCustomPos(Pos, Row, Col: Cardinal);
function MessageToString: tbtString; virtual;
function ShortMessageToString: tbtString; virtual; abstract;
end;
TPSPascalCompilerError = class(TPSPascalCompilerMessage)
protected
FError: TPSPascalCompilerErrorType;
public
property Error: TPSPascalCompilerErrorType read FError;
function ErrorType: tbtString; override;
function ShortMessageToString: tbtString; override;
end;
TPSPascalCompilerHint = class(TPSPascalCompilerMessage)
protected
FHint: TPSPascalCompilerHintType;
public
property Hint: TPSPascalCompilerHintType read FHint;
function ErrorType: tbtString; override;
function ShortMessageToString: tbtString; override;
end;
TPSPascalCompilerWarning = class(TPSPascalCompilerMessage)
protected
FWarning: TPSPascalCompilerWarningType;
public
property Warning: TPSPascalCompilerWarningType read FWarning;
function ErrorType: tbtString; override;
function ShortMessageToString: tbtString; override;
end;
TPSDuplicCheck = set of (dcTypes, dcProcs, dcVars, dcConsts);
TPSBlockInfo = class(TObject)
private
FOwner: TPSBlockInfo;
FWithList: TPSList;
FProcNo: Cardinal;
FProc: TPSInternalProcedure;
FSubType: TPSSubOptType;
public
property WithList: TPSList read FWithList;
property ProcNo: Cardinal read FProcNo write FProcNo;
property Proc: TPSInternalProcedure read FProc write FProc;
property SubType: TPSSubOptType read FSubType write FSubType;
procedure Clear;
constructor Create(Owner: TPSBlockInfo);
destructor Destroy; override;
end;
TPSBinOperatorType = (otAdd, otSub, otMul, otDiv, otMod, otShl, otShr, otAnd, otOr, otXor, otAs, otIntDiv,
otGreaterEqual, otLessEqual, otGreater, otLess, otEqual,
otNotEqual, otIs, otIn);
TPSUnOperatorType = (otNot, otMinus, otCast);
TPSOnUseVariable = procedure (Sender: TPSPascalCompiler; VarType: TPSVariableType; VarNo: Longint; ProcNo, Position: Cardinal; const PropData: tbtString);
TPSOnUses = function(Sender: TPSPascalCompiler; const Name: tbtString): Boolean;
TPSOnExportCheck = function(Sender: TPSPascalCompiler; Proc: TPSInternalProcedure; const ProcDecl: tbtString): Boolean;
{$IFNDEF PS_USESSUPPORT}
TPSOnWriteLineEvent = function (Sender: TPSPascalCompiler; Position: Cardinal): Boolean;
{$ELSE}
TPSOnWriteLineEvent = function (Sender: TPSPascalCompiler; FileName: tbtString; Position: Cardinal): Boolean;
{$ENDIF}
TPSOnExternalProc = function (Sender: TPSPascalCompiler; Decl: TPSParametersDecl; const Name, FExternal: tbtString): TPSRegProc;
TPSOnTranslateLineInfoProc = procedure (Sender: TPSPascalCompiler; var Pos, Row, Col: Cardinal; var Name: tbtString);
TPSOnNotify = function (Sender: TPSPascalCompiler): Boolean;
TPSOnFunction = procedure(name: tbtString; Pos, Row, Col: Integer) of object;
TPSPascalCompiler = class
protected
FAnyString: TPSType;
FUnitName: tbtString;
FID: Pointer;
FOnExportCheck: TPSOnExportCheck;
FDefaultBoolType: TPSType;
FRegProcs: TPSList;
FConstants: TPSList;
FProcs: TPSList;
FTypes: TPSList;
FAttributeTypes: TPSList;
FVars: TPSList;
FOutput: tbtString;
FParser: TPSPascalParser;
FParserHadError: Boolean;
FMessages: TPSList;
FOnUses: TPSOnUses;
FUtf8Decode: Boolean;
FIsUnit: Boolean;
FAllowNoBegin: Boolean;
FAllowNoEnd: Boolean;
FAllowUnit: Boolean;
FAllowDuplicateRegister : Boolean;
FBooleanShortCircuit: Boolean;
FDebugOutput: tbtString;
FOnExternalProc: TPSOnExternalProc;
FOnUseVariable: TPSOnUseVariable;
FOnBeforeOutput: TPSOnNotify;
FOnBeforeCleanup: TPSOnNotify;
FOnWriteLine: TPSOnWriteLineEvent;
FContinueOffsets, FBreakOffsets: TPSList;
FOnTranslateLineInfo: TPSOnTranslateLineInfoProc;
FAutoFreeList: TPSList;
FClasses: TPSList;
FOnFunctionStart: TPSOnFunction;
FOnFunctionEnd: TPSOnFunction;
FWithCount: Integer;
FTryCount: Integer;
FExceptFinallyCount: Integer;
{$IFDEF PS_USESSUPPORT}
FUnitInits : TPSList; //nvds
FUnitFinits: TPSList; //nvds
FUses : TPSStringList;
fUnits : TPSUnitList;
fUnit : TPSUnit;
fModule : tbtString;
{$ENDIF}
fInCompile : Integer;
{$IFNDEF PS_NOINTERFACES}
FInterfaces: TPSList;
{$ENDIF}
FCurrUsedTypeNo: Cardinal;
FGlobalBlock: TPSBlockInfo;
function IsBoolean(aType: TPSType): Boolean;
{$IFNDEF PS_NOWIDESTRING}
function GetWideString(Src: PIfRVariant; var s: Boolean): tbtwidestring;
function GetUnicodeString(Src: PIfRVariant; var s: Boolean): tbtunicodestring;
{$ENDIF}
function PreCalc(FUseUsedTypes: Boolean; Var1Mod: Byte; var1: PIFRVariant; Var2Mod: Byte;
Var2: PIfRVariant; Cmd: TPSBinOperatorType; Pos, Row, Col: Cardinal): Boolean;
function FindBaseType(BaseType: TPSBaseType): TPSType;
function IsIntBoolType(aType: TPSType): Boolean;
function GetTypeCopyLink(p: TPSType): TPSType;
function at2ut(p: TPSType): TPSType;
procedure UseProc(procdecl: TPSParametersDecl);
function GetMsgCount: Longint;
function GetMsg(l: Longint): TPSPascalCompilerMessage;
function MakeExportDecl(decl: TPSParametersDecl): tbtString;
procedure DefineStandardTypes;
procedure DefineStandardProcedures;
function ReadReal(const s: tbtString): PIfRVariant;
function ReadString: PIfRVariant;
function ReadInteger(const s: tbtString): PIfRVariant;
function ReadAttributes(Dest: TPSAttributes): Boolean;
function ReadConstant(FParser: TPSPascalParser; StopOn: TPSPasToken): PIfRVariant;
function ApplyAttribsToFunction(func: TPSProcedure): boolean;
function ProcessFunction(AlwaysForward: Boolean; Att: TPSAttributes): Boolean;