1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE a_modes.inc}
19 interface
21 uses
25 // ////////////////////////////////////////////////////////////////////////// //
26 type
28 private
34 public
43 // ////////////////////////////////////////////////////////////////////////// //
44 type
46 public
53 public
56 public
61 public
68 private
70 public
79 private
81 public
90 private
92 public
103 private
105 public
111 TUnExprNeg = class(TUnExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
112 TUnExprNot = class(TUnExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
115 private
118 public
127 private
129 private
131 public
137 TBinExprAdd = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
138 TBinExprSub = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
139 TBinExprMul = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
140 TBinExprDiv = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
141 TBinExprMod = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
143 TBinExprLogAnd = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
144 TBinExprLogOr = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
146 TBinExprCmpLess = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
147 TBinExprCmpGreat = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
148 TBinExprCmpLessEqu = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
149 TBinExprCmpGreatEqu = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
150 TBinExprCmpEqu = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
151 TBinExprCmpNotEqu = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
153 TBinAssign = class(TBinExpr) public function value (scope: TExprScope): Variant; override; function toString (): AnsiString; override; end;
156 // ////////////////////////////////////////////////////////////////////////// //
160 implementation
162 uses
166 // ////////////////////////////////////////////////////////////////////////// //
168 begin
205 // ////////////////////////////////////////////////////////////////////////// //
206 (*
207 procedure dumpPublishedProperties (obj: TObject);
208 var
209 pt: PTypeData;
210 pi: PTypeInfo;
211 i, j: Integer;
212 pp: PPropList;
213 begin
214 if (obj = nil) then exit;
215 //e_LogWritefln('Object of type ''%s'':', [obj.ClassName]);
216 pi := obj.ClassInfo;
217 pt := GetTypeData(pi);
218 //e_LogWritefln('property count: %s', [pt.PropCount]);
219 GetMem(pp, pt^.PropCount*sizeof(Pointer));
220 try
221 j := GetPropList(pi, [tkInteger, tkBool, tkSString, tkLString, tkAString, tkSet, tkEnumeration], pp);
222 //e_LogWritefln('ordinal property count: %s', [j]);
223 for i := 0 to j-1 do
224 begin
225 {
226 if (typinfo.PropType(obj, pp^[i].name) in [tkSString, tkLString, tkAString]) then
227 begin
228 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i+1, pp^[i].name, typeKind2Str(typinfo.PropType(obj, pp^[i].name)), GetStrProp(obj, pp^[i])]);
229 end
230 else if (typinfo.PropType(obj, pp^[i].name) = tkSet) then
231 begin
232 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i+1, pp^[i].name, typeKind2Str(typinfo.PropType(obj, pp^[i].name)), GetSetProp(obj, pp^[i], true)]);
233 end
234 else if (typinfo.PropType(obj, pp^[i].name) = tkEnumeration) then
235 begin
236 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i+1, pp^[i].name, typeKind2Str(typinfo.PropType(obj, pp^[i].name)), GetEnumProp(obj, pp^[i])]);
237 end
238 else
239 begin
240 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i+1, pp^[i].name, typeKind2Str(typinfo.PropType(obj, pp^[i].name)), GetOrdProp(obj, pp^[i])]);
241 end;
242 }
243 end;
244 finally
245 FreeMem(pp);
246 end;
247 end;
248 *)
251 // ////////////////////////////////////////////////////////////////////////// //
253 var
257 begin
263 pc := GetPropList(pi, [tkInteger, tkBool, tkSString, tkLString, tkAString, {tkSet,} tkEnumeration], pl);
268 begin
278 var
280 begin
283 begin
290 //tkFloat: result := 'Float';
291 //tkClass: result := 'Class';
292 //tkInt64: result := 'Int64';
293 //tkClassRef: result := 'ClassRef';
302 var
304 begin
307 begin
312 tkBool: if TExprBase.coerce2bool(v) then SetOrdProp(obj, pl^[idx], 1) else SetOrdProp(obj, pl^[idx], 0);
314 //tkFloat: result := 'Float';
315 //tkClass: result := 'Class';
316 //tkInt64: result := 'Int64';
317 //tkClassRef: result := 'ClassRef';
325 // ////////////////////////////////////////////////////////////////////////// //
326 function TExprScope.getObj (const aname: AnsiString): TObject; begin result := nil; TExprBase.error(); end;
327 function TExprScope.getField (obj: TObject; const afldname: AnsiString): Variant; begin result := Unassigned; TExprBase.error(); end;
328 procedure TExprScope.setField (obj: TObject; const afldname: AnsiString; var aval: Variant); begin TExprBase.error(); end;
331 // ////////////////////////////////////////////////////////////////////////// //
335 begin
343 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := (LongInt(v0) <> 0);
351 begin
365 // ////////////////////////////////////////////////////////////////////////// //
367 destructor TExprStatList.Destroy (); var f: Integer; begin for f := 0 to High(mList) do mList[f].Free(); mList := nil; end;
370 var
372 begin
377 var
379 begin
384 var
387 begin
391 try
393 except
400 // ////////////////////////////////////////////////////////////////////////// //
402 function TObjExpr.value (scope: TExprScope): Variant; begin result := UInt64(PtrUInt(Pointer(scope.getObj(mName)))); end;
407 // ////////////////////////////////////////////////////////////////////////// //
413 function TLitExpr.clone (): TExprBase; begin result := TLitExpr.Create(0); (result as TLitExpr).mValue := mValue; end;
416 // ////////////////////////////////////////////////////////////////////////// //
419 function TUnExpr.clone (): TExprBase; begin result := (self.ClassType.Create() as TUnExpr); (result as TUnExpr).mOp0 := mOp0.clone(); end;
422 begin
437 begin
445 // ////////////////////////////////////////////////////////////////////////// //
447 begin
453 begin
460 var
462 begin
473 // ////////////////////////////////////////////////////////////////////////// //
476 function TBinExpr.clone (): TExprBase; begin result := (self.ClassType.Create() as TBinExpr); (result as TBinExpr).mOp0 := mOp0.clone(); (result as TBinExpr).mOp1 := mOp1.clone(); end;
480 begin
488 begin
496 begin
501 begin
505 begin
507 begin
509 begin
520 end
522 begin
529 end
531 begin
540 end
541 else
542 begin
549 // ////////////////////////////////////////////////////////////////////////// //
551 var
553 begin
560 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := LongInt(result)+LongInt(r1);
565 function TBinExprAdd.toString (): AnsiString; begin result := '('+mOp0.toString()+'+'+mOp1.toString+')'; end;
568 var
570 begin
576 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := LongInt(result)-LongInt(r1);
581 function TBinExprSub.toString (): AnsiString; begin result := '('+mOp0.toString()+'-'+mOp1.toString+')'; end;
584 var
586 begin
592 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := LongInt(result)*LongInt(r1);
597 function TBinExprMul.toString (): AnsiString; begin result := '('+mOp0.toString()+'*'+mOp1.toString+')'; end;
600 var
602 begin
608 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := LongInt(result) div LongInt(r1);
613 function TBinExprDiv.toString (): AnsiString; begin result := '('+mOp0.toString()+'/'+mOp1.toString+')'; end;
616 var
618 begin
623 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := LongInt(result) mod LongInt(r1);
628 function TBinExprMod.toString (): AnsiString; begin result := '('+mOp0.toString()+'%'+mOp1.toString+')'; end;
631 begin
637 function TBinExprLogAnd.toString (): AnsiString; begin result := '('+mOp0.toString()+'&&'+mOp1.toString+')'; end;
640 begin
646 function TBinExprLogOr.toString (): AnsiString; begin result := '('+mOp0.toString()+'||'+mOp1.toString+')'; end;
649 var
651 begin
657 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := Boolean(LongInt(result) < LongInt(r1));
663 function TBinExprCmpLess.toString (): AnsiString; begin result := '('+mOp0.toString()+'<'+mOp1.toString+')'; end;
666 var
668 begin
674 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := Boolean(LongInt(result) > LongInt(r1));
680 function TBinExprCmpGreat.toString (): AnsiString; begin result := '('+mOp0.toString()+'>'+mOp1.toString+')'; end;
683 var
685 begin
691 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := Boolean(LongInt(result) <= LongInt(r1));
697 function TBinExprCmpLessEqu.toString (): AnsiString; begin result := '('+mOp0.toString()+'<='+mOp1.toString+')'; end;
700 var
702 begin
708 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := Boolean(LongInt(result) >= LongInt(r1));
714 function TBinExprCmpGreatEqu.toString (): AnsiString; begin result := '('+mOp0.toString()+'>='+mOp1.toString+')'; end;
717 var
719 begin
725 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := Boolean(LongInt(result) = LongInt(r1));
733 function TBinExprCmpEqu.toString (): AnsiString; begin result := '('+mOp0.toString()+'=='+mOp1.toString+')'; end;
736 var
738 begin
744 varShortInt, varSmallint, varInteger, varByte, varWord, varLongWord: result := Boolean(LongInt(result) <> LongInt(r1));
752 function TBinExprCmpNotEqu.toString (): AnsiString; begin result := '('+mOp0.toString()+'<>'+mOp1.toString+')'; end;
755 // ////////////////////////////////////////////////////////////////////////// //
757 begin
762 function TBinAssign.toString (): AnsiString; begin result := mOp0.toString()+'='+mOp1.toString(); end;
765 // ////////////////////////////////////////////////////////////////////////// //
767 var
769 begin
771 try
774 finally
780 var
784 begin
789 try
791 begin
803 finally
815 begin
817 try
819 if pr.eatDelim('!') then begin result := expr(); result := TUnExprNot.Create(result); exit; end;
820 if pr.eatDelim('-') then begin result := expr(); result := TUnExprNeg.Create(result); exit; end;
825 begin
827 if (pr.tokStr = 'false') then begin result := TLitExpr.Create(false); pr.skipToken(); exit; end;
831 begin
835 exit;
837 except
845 begin
847 try
849 begin
855 except
862 begin
864 try
866 begin
871 except
878 begin
880 try
882 begin
886 else if pr.eatTT(pr.TTGreatEqu) then result := TBinExprCmpGreatEqu.Create(result, doPlusMinus())
889 except
896 begin
898 try
900 begin
905 except
912 begin
914 try
916 begin
919 except
926 begin
928 try
930 begin
933 except
939 // funcall, [], dot
940 // !, ~
941 // *, /, %
942 // +, -
943 // <<, >>
944 // <, <=, >, >=
945 // ==, !=
946 // &
947 // ^
948 // |
949 // &&
950 // ||
953 var
955 begin
962 var
964 begin
968 try
971 try
973 except
976 finally
982 {
983 varEmpty:
984 varNull:
985 varSingle:
986 varDouble:
987 varDecimal:
988 varCurrency:
989 varDate:
990 varOleStr:
991 varStrArg:
992 varString:
993 varDispatch:
994 varBoolean:
995 varVariant:
996 varUnknown:
997 varShortInt:
998 varSmallint:
999 varInteger:
1000 varInt64:
1001 varByte:
1002 varWord:
1003 varLongWord:
1004 varQWord:
1005 varError:
1006 }