diff --git a/src/shared/xdynrec.pas b/src/shared/xdynrec.pas
index c992997d32ce55a4f21c73b764ad62dbbaa3cc95..7d1098ee7de0710dfef124fb51c02de429561f66 100644 (file)
--- a/src/shared/xdynrec.pas
+++ b/src/shared/xdynrec.pas
uses
SysUtils, Variants, Classes,
+ {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
xparser, xstreams, utils, hashtable;
TDynEBSList = specialize TSimpleList<TDynEBS>;
// this is base type for all scalars (and arrays)
- TDynField = class
+ TDynField = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
public
type
TType = (TBool, TChar, TByte, TUByte, TShort, TUShort, TInt, TUInt, TString, TPoint, TSize, TColor, TList, TTrigData);
// record, either with actual values, or with type definitions
- TDynRecord = class
+ TDynRecord = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
private
mOwner: TDynMapDef;
mId: AnsiString;
// bitset/enum definition
- TDynEBS = class
+ TDynEBS = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
private
mOwner: TDynMapDef;
mIsEnum: Boolean;
// parsed "mapdef.txt"
- TDynMapDef = class
+ TDynMapDef = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
public
recTypes: TDynRecList; // [0] is always header
trigTypes: TDynRecList; // trigdata
procedure xdynDumpProfiles ();
{$ENDIF}
+var
+ DynWarningCB: procedure (const msg: AnsiString; line, col: Integer) = nil;
implementation
+{$IF DEFINED(D2D_DYNREC_PROFILER)}
uses
- e_log
- {$IF DEFINED(D2D_DYNREC_PROFILER)},xprofiler{$ENDIF};
+ xprofiler;
+{$ENDIF}
// ////////////////////////////////////////////////////////////////////////// //
if (mType = TType.TList) then
begin
mRVal := TDynRecList.Create();
- mRHash := hashNewStrInt();
+ mRHash := THashStrInt.Create();
end;
end;
if (mRVal <> nil) then
begin
if (result.mRVal = nil) then result.mRVal := TDynRecList.Create(mRVal.count);
- if (result.mRHash = nil) then result.mRHash := hashNewStrInt();
+ if (result.mRHash = nil) then result.mRHash := THashStrInt.Create();
for rec in mRVal do result.addListItem(rec.clone(registerIn));
end;
result.mRecRef := mRecRef;
// field name
fldname := pr.expectStrOrId();
- while (pr.tokType <> pr.TTSemi) do
+ while (not pr.isDelim(';')) do
begin
if pr.eatId('type') then
begin
lebs := TDynField.TEBS.TRec;
end;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
// create field
mName := fldname;
edim: AnsiChar;
begin
if (pr.tokType = pr.TTEOF) then raise TDynParseException.Create(pr, 'field value expected');
- if (pr.tokType = pr.TTSemi) then raise TDynParseException.Create(pr, 'extra semicolon');
+ if (pr.isDelim(';')) then raise TDynParseException.Create(pr, 'extra semicolon');
// if this field should contain struct, convert type and parse struct
case mEBS of
TEBS.TNone: begin end;
// ugly hack. sorry.
if (mType = TType.TTrigData) then
begin
- pr.expectTT(pr.TTBegin);
- if (pr.tokType = pr.TTEnd) then
+ pr.expectDelim('{');
+ if (pr.eatDelim('}')) then
begin
// '{}'
mRecRef := nil;
- pr.expectTT(pr.TTEnd);
end
else
begin
mRecRef := rc;
end;
mDefined := true;
- pr.eatTT(pr.TTSemi); // hack: allow (but don't require) semicolon after inline records
+ pr.eatDelim(';'); // hack: allow (but don't require) semicolon after inline records
exit;
end;
// other record types
pr.expectId();
end;
mDefined := true;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end
- else if (pr.tokType = pr.TTBegin) then
+ else if (pr.isDelim('{')) then
begin
//rec := mOwner.mOwner.recType[mEBSTypeName]; // find in mapdef
rec := nil;
begin
raise TDynParseException.CreateFmt(pr, 'duplicate record with id ''%s'' for field ''%s'' in record ''%s''', [rc.mId, mName, mOwner.mTypeName]);
end;
- pr.eatTT(pr.TTSemi); // hack: allow (but don't require) semicolon after inline records
+ pr.eatDelim(';'); // hack: allow (but don't require) semicolon after inline records
exit;
end;
- pr.expectTT(pr.TTBegin);
+ pr.expectDelim('{');
end;
TEBS.TEnum:
begin
mSVal := tk;
//writeln('ENUM ', mEBSName, '; element <', mSVal, '> with value ', mIVal);
mDefined := true;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TEBS.TBitSet:
pr.skipToken(); // plus or pipe
end;
mDefined := true;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
else raise TDynParseException.Create(pr, 'ketmar forgot to handle some EBS type');
else if pr.eatId('false') or pr.eatId('ona') or pr.eatId('no') then mIVal := 0
else raise TDynParseException.CreateFmt(pr, 'invalid bool value for field ''%s''', [mName]);
mDefined := true;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TChar:
if (Length(mSVal) > mMaxDim) then raise TDynParseException.CreateFmt(pr, 'invalid string size for field ''%s''', [mName]);
end;
mDefined := true;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TByte:
begin
parseInt(-128, 127);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TUByte:
begin
parseInt(0, 255);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TShort:
begin
parseInt(-32768, 32768);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TUShort:
begin
parseInt(0, 65535);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TInt:
begin
parseInt(Integer($80000000), $7fffffff);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TUInt:
begin
parseInt(0, $7fffffff); //FIXME
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TString:
begin
mSVal := pr.expectStr(true);
mDefined := true;
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TPoint,
end;
mDefined := true;
pr.expectDelim(edim);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TColor:
end;
mDefined := true;
pr.expectDelim(edim);
- pr.expectTT(pr.TTSemi);
+ pr.expectDelim(';');
exit;
end;
TType.TList:
if (fld.mRVal = nil) then
begin
fld.mRVal := TDynRecList.Create();
- fld.mRHash := hashNewStrInt();
+ fld.mRHash := THashStrInt.Create();
end;
result := fld.addListItem(rc);
end;
begin
while true do
begin
- while pr.eatTT(pr.TTComma) do begin end;
+ while (pr.eatDelim(',')) do begin end;
if pr.eatDelim(')') then break;
tdn := pr.expectId();
if isForTrig[tdn] then raise TDynParseException.CreateFmt(pr, 'duplicate trigdata ''%s'' trigtype ''%s''', [mTypeName, tdn]);
else
begin
mTypeName := pr.expectStrOrId();
- while (pr.tokType <> pr.TTBegin) do
+ while (not pr.isDelim('{')) do
begin
if pr.eatId('header') then begin mHeader := true; continue; end;
if pr.eatId('size') then
end;
end;
- pr.expectTT(pr.TTBegin);
+ pr.expectDelim('{');
// load fields
- while (pr.tokType <> pr.TTEnd) do
+ while (not pr.isDelim('}')) do
begin
fld := TDynField.Create(pr);
// append
end;
// done with field
end;
- pr.expectTT(pr.TTEnd);
+ pr.expectDelim('}');
end;
rt := findRecordByTypeId(fld.mEBSTypeName, fld.mRecRefId);
if (rt = nil) then
begin
- e_LogWritefln('record of type ''%s'' with id ''%s'' links to inexistant record of type ''%s'' with id ''%s''', [rec.mTypeName, rec.mId, fld.mEBSTypeName, fld.mRecRefId], MSG_WARNING);
+ if assigned(DynWarningCB) then
+ begin
+ DynWarningCB(formatstrf('record of type ''%s'' with id ''%s'' links to inexistant record of type ''%s'' with id ''%s''', [rec.mTypeName, rec.mId, fld.mEBSTypeName, fld.mRecRefId]), -1, -1);
+ end;
//raise TDynRecException.CreateFmt('record of type ''%s'' with id ''%s'' links to inexistant record of type ''%s'' with id ''%s''', [rec.mName, rec.mId, fld.mEBSTypeName, fld.mRecRefId]);
end;
//writeln(' ', rec.mName, '.', rec.mId, ':', fld.mName, ' -> ', rt.mName, '.', rt.mId, ' (', fld.mEBSTypeName, '.', fld.mRecRefId, ')');
procedure linkNames (rec: TDynRecord);
var
fld: TDynField;
- rt: TDynRecord;
+ rt, rvc: TDynRecord;
begin
+ if (rec = nil) then exit;
//writeln('*** rec: ', rec.mName, '.', rec.mId, ' (', rec.mFields.count, ')');
for fld in rec.mFields do
begin
+ if (fld.mType = TDynField.TType.TList) then
+ begin
+ for rvc in fld.mRVal do linkNames(rvc);
+ end;
if (fld.mType = TDynField.TType.TTrigData) then
begin
- if (fld.mRecRef <> nil) then linkNames(fld.mRecRef);
+ //if (fld.mRecRef <> nil) then linkNames(fld.mRecRef);
continue;
end;
if (Length(fld.mRecRefId) = 0) then continue;
for fld in rec.mFields do
begin
//writeln(' ', fld.mName);
- fld.fixDefaultValue(); // just in case
+ fld.fixDefaultValue();
end;
end;
begin
if (mOwner = nil) then raise TDynParseException.CreateFmt(pr, 'can''t parse record ''%s'' value without owner', [mTypeName]);
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stall := curTimeMicro();{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}stall := getTimeMicro();{$ENDIF}
// not a header?
if not mHeader then
end;
//writeln('parsing record <', mName, '>');
- if not beginEaten then pr.expectTT(pr.TTBegin);
- while (pr.tokType <> pr.TTEnd) do
+ if not beginEaten then pr.expectDelim('{');
+ while (not pr.isDelim('}')) do
begin
if (pr.tokType <> pr.TTId) then raise TDynParseException.Create(pr, 'identifier expected');
//writeln('<', mName, '.', pr.tokStr, '>');
if mHeader then
begin
// add records with this type (if any)
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := getTimeMicro();{$ENDIF}
trc := mOwner.recType[pr.tokStr];
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profFindRecType := curTimeMicro()-stt;{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}profFindRecType := getTimeMicro()-stt;{$ENDIF}
if (trc <> nil) then
begin
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := getTimeMicro();{$ENDIF}
rec := trc.clone(mHeaderRec);
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profCloneRec := curTimeMicro()-stt;{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}profCloneRec := getTimeMicro()-stt;{$ENDIF}
rec.mHeaderRec := mHeaderRec;
// on error, it will be freed by memowner
pr.skipToken();
rec.parseValue(pr);
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := getTimeMicro();{$ENDIF}
addRecordByType(rec.mTypeName, rec);
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profAddRecByType := curTimeMicro()-stt;{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}profAddRecByType := getTimeMicro()-stt;{$ENDIF}
continue;
end;
end;
// fields
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := getTimeMicro();{$ENDIF}
//writeln('0: <', mName, '.', pr.tokStr, '>');
fld := field[pr.tokStr];
//writeln('1: <', mName, '.', pr.tokStr, '>');
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profFieldSearching := curTimeMicro()-stt;{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}profFieldSearching := getTimeMicro()-stt;{$ENDIF}
if (fld <> nil) then
begin
//writeln('2: <', mName, '.', pr.tokStr, '>');
if fld.internal then raise TDynParseException.CreateFmt(pr, 'internal field ''%s'' in record ''%s''', [fld.mName, mTypeName]);
pr.skipToken(); // skip field name
//writeln('3: <', mName, '.', pr.tokStr, '>:', pr.tokType);
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := getTimeMicro();{$ENDIF}
fld.parseValue(pr);
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profFieldValParsing := curTimeMicro()-stt;{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}profFieldValParsing := getTimeMicro()-stt;{$ENDIF}
continue;
end;
// something is wrong
raise TDynParseException.CreateFmt(pr, 'unknown field ''%s'' in record ''%s''', [pr.tokStr, mTypeName]);
end;
- pr.expectTT(pr.TTEnd);
+ pr.expectDelim('}');
if mHeader then
begin
// link fields
- for fld in mFields do
- begin
- if (fld.mType <> TDynField.TType.TList) then continue;
- for rec in fld.mRVal do linkNames(rec);
- end;
+ linkNames(self);
+ for rec in mRec2Free do if (rec <> nil) then linkNames(rec);
end;
-
- // fix field defaults
- {$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
- for fld in mFields do fld.fixDefaultValue();
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profFixDefaults := curTimeMicro()-stt;{$ENDIF}
//writeln('done parsing record <', mName, '>');
- //{$IF DEFINED(D2D_DYNREC_PROFILER)}writeln('stall: ', curTimeMicro()-stall);{$ENDIF}
- {$IF DEFINED(D2D_DYNREC_PROFILER)}profRecValParse := curTimeMicro()-stall;{$ENDIF}
+ //{$IF DEFINED(D2D_DYNREC_PROFILER)}writeln('stall: ', getTimeMicro()-stall);{$ENDIF}
+ {$IF DEFINED(D2D_DYNREC_PROFILER)}profRecValParse := getTimeMicro()-stall;{$ENDIF}
end;
mTypeName := pr.expectId();
mMaxVal := Integer($80000000);
if mIsEnum then cv := 0 else cv := 1;
- while (pr.tokType <> pr.TTBegin) do
+ while (not pr.isDelim('{')) do
begin
if pr.eatId('tip') then
begin
end;
break;
end;
- pr.expectTT(pr.TTBegin);
- while (pr.tokType <> pr.TTEnd) do
+ pr.expectDelim('{');
+ while (not pr.isDelim('}')) do
begin
idname := pr.expectId();
for f := 0 to High(mIds) do
if mIsEnum then Inc(cv) else cv := cv shl 1;
end;
end;
- if (pr.tokType = pr.TTEnd) then break;
- pr.expectTT(pr.TTComma);
- while pr.eatTT(pr.TTComma) do begin end;
+ if (pr.isDelim('}')) then break;
+ pr.expectDelim(',');
+ while (pr.eatDelim(',')) do begin end;
end;
- pr.expectTT(pr.TTEnd);
+ pr.expectDelim('}');
// add max field
if (Length(mMaxName) > 0) then
begin