diff --git a/components/codetools/codetoolmemmanager.pas b/components/codetools/codetoolmemmanager.pas index 008a0a8b63..9bff3e4ae8 100644 --- a/components/codetools/codetoolmemmanager.pas +++ b/components/codetools/codetoolmemmanager.pas @@ -51,8 +51,10 @@ type FCount: integer; FMinFree: integer; FMaxFreeRatio: integer; + {$IFDEF DebugCTMemManager} FAllocatedCount: int64; FFreedCount: int64; + {$ENDIF} procedure DisposeItem(AnItem: PCodeToolMemManagerItem); function NewItem: PCodeToolMemManagerItem; procedure FreeFirstItem; virtual; @@ -62,8 +64,10 @@ type read FMaxFreeRatio write SetMaxFreeRatio; // in one eighth steps property Count: integer read FCount; property FreeCount: integer read FFreeCount; + {$IFDEF DebugCTMemManager} property AllocatedCount: int64 read FAllocatedCount; property FreedCount: int64 read FFreedCount; + {$ENDIF} procedure Clear; constructor Create; destructor Destroy; override; @@ -79,7 +83,9 @@ procedure TCodeToolMemManager.Clear; begin while FFirstFree<>nil do begin FreeFirstItem; + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; FFreeCount:=0; end; @@ -90,8 +96,10 @@ begin FFirstFree:=nil; FFreeCount:=0; FCount:=0; + {$IFDEF DebugCTMemManager} FAllocatedCount:=0; FFreedCount:=0; + {$ENDIF} FMinFree:=100000; FMaxFreeRatio:=8; // 1:1 end; @@ -112,7 +120,9 @@ begin end else begin // free list full -> free the ANode //FreeItem(AnItem); + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -128,7 +138,9 @@ begin end else begin // free list empty -> create new node New(Result); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; diff --git a/components/codetools/codetree.pas b/components/codetools/codetree.pas index c7353d8bbe..2346310024 100644 --- a/components/codetools/codetree.pas +++ b/components/codetools/codetree.pas @@ -684,7 +684,9 @@ begin end else begin // free list empty -> create new node Result:=TCodeTreeNode.Create; + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; @@ -701,7 +703,9 @@ begin end else begin // free list full -> free the ANode ANode.Free; + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -777,7 +781,9 @@ end; procedure InternalFinal; begin NodeExtMemManager.Free; + NodeExtMemManager:=nil; NodeMemManager.Free; + NodeMemManager:=nil; end; diff --git a/components/codetools/finddeclarationcache.pas b/components/codetools/finddeclarationcache.pas index c356c80f2e..c0bb1ad4c4 100644 --- a/components/codetools/finddeclarationcache.pas +++ b/components/codetools/finddeclarationcache.pas @@ -299,7 +299,9 @@ begin end else begin // free list full -> free the Entry Dispose(Entry); + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -315,7 +317,9 @@ begin end else begin // free list empty -> create new Entry New(Result); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; @@ -343,7 +347,9 @@ begin end else begin // free list full -> free the Entry Dispose(Entry); + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -359,7 +365,9 @@ begin end else begin // free list empty -> create new Entry New(Result); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; @@ -939,7 +947,9 @@ begin end else begin // free list full -> free the NodeCache NodeCache.Free; + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -965,7 +975,9 @@ begin end else begin // free list empty -> create new NodeCache Result:=TCodeTreeNodeCache.Create(AnOwner); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; @@ -1042,7 +1054,9 @@ begin end else begin // free list full -> free the BaseType BaseTypeCache.Free; + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -1067,7 +1081,9 @@ begin end else begin // free list empty -> create new BaseType Result:=TBaseTypeCache.Create(AnOwner); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 72825adb07..d41585b2b3 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -1838,7 +1838,8 @@ var Params.SetResult(Self,ContextNode,CurPos.StartPos); Result:=CheckResult(true,true); end; - if FindIdentifierInHiddenUsedUnits(Params) then begin + if (not (fdfIgnoreUsedUnits in Params.Flags)) + and FindIdentifierInHiddenUsedUnits(Params) then begin Result:=CheckResult(true,false); end; end; @@ -2881,7 +2882,7 @@ begin Params.Save(OldInput); Params.ContextNode:=Params.NewNode; - Exclude(Params.Flags,fdfIgnoreCurContextNode); + Params.Flags:=Params.Flags-[fdfIgnoreCurContextNode,fdfSearchInParentNodes]; Result:=Params.NewCodeTool.FindIdentifierInContext(Params); Params.Load(OldInput); end; @@ -3188,7 +3189,8 @@ begin Result:=false; // build code tree {$IFDEF ShowTriedContexts} - writeln(DebugPrefix,'TFindDeclarationTool.FindIdentifierInInterface', + writeln({$IFDEF DebugPrefix}DebugPrefix,{$ENDIF} + 'TFindDeclarationTool.FindIdentifierInInterface', ' Ident="',GetIdentifier(Params.Identifier),'"', ' IgnoreUsedUnits=',fdfIgnoreUsedUnits in Params.Flags, ' Self=',TCodeBuffer(Scanner.MainCode).Filename @@ -3311,7 +3313,7 @@ end; function TFindDeclarationTool.FindIdentifierInUsedUnit( const AnUnitName: string; Params: TFindDeclarationParams): boolean; -{ this function is internally used by FindIdentifierInUsesSection +{ this function is internally used by FindIdentifierInHiddenUsedUnits for hidden used units, like the system unit or the objpas unit } var diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index f10410bc46..33e29af5f4 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -56,7 +56,7 @@ uses {$ENDIF} Classes, SysUtils, CodeToolsStrConsts, CodeTree, CodeAtom, CustomCodeTool, SourceLog, KeywordFuncLists, BasicCodeTools, LinkScanner, CodeCache, AVL_Tree, - SourceChanger, FindDeclarationTool, PascalParserTool; + CodeToolMemManager, SourceChanger, FindDeclarationTool, PascalParserTool; type @@ -82,6 +82,7 @@ type TIdentifierListItem = class private + FNext: TIdentifierListItem; FParamList: string; FParamListValid: boolean; function GetParamList: string; @@ -109,6 +110,7 @@ type function CanBeAssigned: boolean; procedure UpdateBaseContext; function HasChilds: boolean; + procedure Clear; public property ParamList: string read GetParamList write SetParamList; end; @@ -322,6 +324,78 @@ begin Result:=AnsiCompareText(HistItem.ParamList,IdentItem.ParamList); end; +type + TIdentifierListItemMemManager = class(TCodeToolMemManager) + protected + procedure FreeFirstItem; override; + public + procedure DisposeIdentListItem(IdentListItem: TIdentifierListItem); + function NewIdentListItem(NewCompatibility: TIdentifierCompatibility; + NewHasChilds: boolean; NewHistoryIndex: integer; + NewIdentifier: PChar; NewLevel: integer; + NewNode: TCodeTreeNode; NewTool: TFindDeclarationTool; + NewDefaultDesc: TCodeTreeNodeDesc): TIdentifierListItem; + end; + +var + IdentifierListItemMemManager: TIdentifierListItemMemManager; + +{ TIdentifierListItemMemManager } + +procedure TIdentifierListItemMemManager.FreeFirstItem; +var Item: TIdentifierListItem; +begin + Item:=TIdentifierListItem(FFirstFree); + TIdentifierListItem(FFirstFree):=Item.FNext; + Item.Free; +end; + +procedure TIdentifierListItemMemManager.DisposeIdentListItem( + IdentListItem: TIdentifierListItem); +begin + if (FFreeCount free IdentListItem + IdentListItem.Free; + {$IFDEF DebugCTMemManager} + inc(FFreedCount); + {$ENDIF} + end; + dec(FCount); +end; + +function TIdentifierListItemMemManager.NewIdentListItem( + NewCompatibility: TIdentifierCompatibility; + NewHasChilds: boolean; NewHistoryIndex: integer; + NewIdentifier: PChar; NewLevel: integer; + NewNode: TCodeTreeNode; NewTool: TFindDeclarationTool; + NewDefaultDesc: TCodeTreeNodeDesc): TIdentifierListItem; +begin + if FFirstFree<>nil then begin + // take from free list + Result:=TIdentifierListItem(FFirstFree); + // ToDo: set values + TIdentifierListItem(FFirstFree):=Result.FNext; + Result.FNext:=nil; + dec(FFreeCount); + end else begin + // free list empty -> create new node + Result:=TIdentifierListItem.Create(NewCompatibility, + NewHasChilds,NewHistoryIndex,NewIdentifier,NewLevel, + NewNode,NewTool, + NewDefaultDesc); + {$IFDEF DebugCTMemManager} + inc(FAllocatedCount); + {$ENDIF} + end; + inc(FCount); +end; + { TIdentifierList } procedure TIdentifierList.SetPrefix(const AValue: string); @@ -438,6 +512,7 @@ begin Include(FFlags,ilfFilteredListNeedsUpdate); end else begin // redefined identifier -> ignore + //writeln('TIdentifierList.Add redefined: ',NewItem.AsString); NewItem.Free; end; end; @@ -552,7 +627,7 @@ begin Ident:=@FoundContext.Tool.Src[FoundContext.Node.StartPos]; end; - ctnVarDefinition,ctnConstDefinition: + ctnVarDefinition,ctnConstDefinition,ctnEnumIdentifier: Ident:=@FoundContext.Tool.Src[FoundContext.Node.StartPos]; ctnProcedure,ctnProcedureHead: @@ -979,6 +1054,21 @@ begin Result:=iliHasChilds in Flags; end; +procedure TIdentifierListItem.Clear; +begin + FParamList:=''; + FParamListValid:=false; + Compatibility:=icompUnknown; + HistoryIndex:=0; + Identifier:=nil; + Level:=0; + Node:=nil; + Tool:=nil; + DefaultDesc:=ctnNone; + Flags:=[]; + BaseExprType:=CleanExpressionType; +end; + { TIdentifierHistoryList } procedure TIdentifierHistoryList.SetCapacity(const AValue: integer); @@ -1070,7 +1160,7 @@ var begin AnAVLNode:=FindItem(AnItem); if AnAVLNode=nil then - Result:=3333333 // a very high value + Result:=33333333 // a very high value else Result:=TIdentHistListItem(AnAVLNode.Data).HistoryIndex; end; @@ -1080,5 +1170,12 @@ begin Result:=FItems.Count; end; +initialization + IdentifierListItemMemManager:=TIdentifierListItemMemManager.Create; + +finalization + IdentifierListItemMemManager.Free; + IdentifierListItemMemManager:=nil; + end. diff --git a/components/codetools/linkscanner.pas b/components/codetools/linkscanner.pas index a662d0a08f..f74b9dc7f0 100644 --- a/components/codetools/linkscanner.pas +++ b/components/codetools/linkscanner.pas @@ -2799,7 +2799,9 @@ begin end else begin // free list full -> free Link Dispose(Link); + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -2816,7 +2818,9 @@ begin // free list empty -> create new PSourceLink New(Result); FillChar(Result^,SizeOf(TSourceLink),0); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; @@ -2844,7 +2848,9 @@ begin end else begin // free list full -> free Step Dispose(Step); + {$IFDEF DebugCTMemManager} inc(FFreedCount); + {$ENDIF} end; dec(FCount); end; @@ -2861,7 +2867,9 @@ begin // free list empty -> create new PSourceChangeStep New(Result); FillChar(Result^,SizeOf(TSourceChangeStep),0); + {$IFDEF DebugCTMemManager} inc(FAllocatedCount); + {$ENDIF} end; inc(FCount); end; diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 9863eb4c50..3acf111f3e 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -3122,12 +3122,11 @@ begin if ExtractMemStream=nil then ExtractMemStream:=TMemoryStream.Create; ExtractMemStream.Position:=0; - ExtractMemStream.Size:=0; end; function TPascalParserTool.GetExtraction: string; begin - SetLength(Result,ExtractMemStream.Size); + SetLength(Result,ExtractMemStream.Position); ExtractMemStream.Position:=0; ExtractMemStream.Read(Result[1],length(Result)); end;