codetools: find declaration: inherited;

git-svn-id: trunk@30920 -
This commit is contained in:
mattias 2011-05-27 05:41:52 +00:00
parent a999b71d2c
commit a75a29091c
23 changed files with 153 additions and 50 deletions

View File

@ -96,6 +96,7 @@ ResourceString
'; expected after "%s" property specifier, but %s found'; '; expected after "%s" property specifier, but %s found';
ctsUnknownSectionKeyword = 'unknown section keyword %s found'; ctsUnknownSectionKeyword = 'unknown section keyword %s found';
ctsIllegalQualifier = 'illegal qualifier %s found'; ctsIllegalQualifier = 'illegal qualifier %s found';
ctsMethodSignatureSNotFoundInClass = 'Method signature %s not found in class';
ctsUnexpectedEndOfSource = 'unexpected end of source'; ctsUnexpectedEndOfSource = 'unexpected end of source';
ctsEndofSourceExpectedButAtomFound = 'expected end., but %s found'; ctsEndofSourceExpectedButAtomFound = 'expected end., but %s found';
ctsPointStartAt = '. start at '; ctsPointStartAt = '. start at ';
@ -147,6 +148,30 @@ ResourceString
ctsQualifierExpectedButAtomFound = 'qualifier expected but %s found'; ctsQualifierExpectedButAtomFound = 'qualifier expected but %s found';
ctsIncompatibleTypesGotExpected = 'incompatibles types: expected "%s" but got "%s"'; ctsIncompatibleTypesGotExpected = 'incompatibles types: expected "%s" but got "%s"';
ctsDefaultPropertyNotFound = 'default property not found'; ctsDefaultPropertyNotFound = 'default property not found';
ctsFunctionGetEnumeratorNotFoundInThisClass = 'function GetEnumerator not '
+'found in this class';
ctsFunctionGetEnumeratorNotFoundInThisClass2 = 'function GetEnumerator not '
+'found in this class';
ctsResultTypeOfFunctionGetEnumeratorNotFound = 'result type of function '
+'GetEnumerator not found';
ctsPropertyCurrentNotFound = 'property Current not found';
ctsEnumerationType = 'enumeration type';
ctsType = 'type';
ctsExpectedStatementButFound = 'expected statement, but found %s';
ctsUnexpectedKeyword2 = 'unexpected keyword %s';
ctsBeginAtWithoutEnd = 'begin at %s without end';
ctsThenExpectedButFound = 'then expected, but %s found';
ctsExpectedButFound = 'expected (, but found %s';
ctsExpectedIdentifierButFound = 'expected identifier, but found %s';
ctsExpectedButFound2 = 'expected ), but found %s';
ctsMissing = 'missing :=';
ctsExpectedButFound3 = 'expected :=, but %s found';
ctsCharacterConstantOutOfRange = 'character constant out of range';
ctsOperatorExpectedButFound = 'operator expected but %s found';
ctsOperandExpectedButFound = 'operand expected but %s found';
ctsOperandExpectedButFound2 = 'operand expected, but %s found';
ctsInvalidOperator = 'invalid operator %s';
ctsOperatorExpectedButFound2 = 'operator expected, but %s found';
// codecompletion // codecompletion
ctsPropertySpecifierAlreadyDefined = 'property specifier already defined: %s'; ctsPropertySpecifierAlreadyDefined = 'property specifier already defined: %s';
@ -269,32 +294,10 @@ ResourceString
ctsInsufficientMemory = 'insufficient memory'; ctsInsufficientMemory = 'insufficient memory';
ctsFileHasCircularSymLink = '%s has a circular symbolic link'; ctsFileHasCircularSymLink = '%s has a circular symbolic link';
ctsFileIsNotExecutable = '%s is not executable'; ctsFileIsNotExecutable = '%s is not executable';
// misc
ctsSrcPathForCompiledUnits = 'src path for compiled units'; ctsSrcPathForCompiledUnits = 'src path for compiled units';
ctsTCodeToolManagerConsistencyCheck = 'TCodeToolManager.ConsistencyCheck=%d'; ctsTCodeToolManagerConsistencyCheck = 'TCodeToolManager.ConsistencyCheck=%d';
ctsFunctionGetEnumeratorNotFoundInThisClass = 'function GetEnumerator not '
+'found in this class';
ctsFunctionGetEnumeratorNotFoundInThisClass2 = 'function GetEnumerator not '
+'found in this class';
ctsResultTypeOfFunctionGetEnumeratorNotFound = 'result type of function '
+'GetEnumerator not found';
ctsPropertyCurrentNotFound = 'property Current not found';
ctsEnumerationType = 'enumeration type';
ctsType = 'type';
ctsExpectedStatementButFound = 'expected statement, but found %s';
ctsUnexpectedKeyword2 = 'unexpected keyword %s';
ctsBeginAtWithoutEnd = 'begin at %s without end';
ctsThenExpectedButFound = 'then expected, but %s found';
ctsExpectedButFound = 'expected (, but found %s';
ctsExpectedIdentifierButFound = 'expected identifier, but found %s';
ctsExpectedButFound2 = 'expected ), but found %s';
ctsMissing = 'missing :=';
ctsExpectedButFound3 = 'expected :=, but %s found';
ctsCharacterConstantOutOfRange = 'character constant out of range';
ctsOperatorExpectedButFound = 'operator expected but %s found';
ctsOperandExpectedButFound = 'operand expected but %s found';
ctsOperandExpectedButFound2 = 'operand expected, but %s found';
ctsInvalidOperator = 'invalid operator %s';
ctsOperatorExpectedButFound2 = 'operator expected, but %s found';
implementation implementation

View File

@ -7193,14 +7193,16 @@ var
end; end;
procedure ResolveINHERITED; procedure ResolveINHERITED;
// for example: inherited A; inherited;
// inherited skips the class and begins to search in the ancestor class
var var
ProcNode: TCodeTreeNode; ProcNode: TCodeTreeNode;
ClassOfMethodContext: TFindContext; ClassNodeOfMethod: TCodeTreeNode;
HasIdentifier: Boolean; HasIdentifier: Boolean;
Context: TFindContext; Context: TFindContext;
var
DefProcNode: TCodeTreeNode;
begin begin
// for example: inherited A;
// inherited skips the class and begins to search in the ancestor class
if ExprType.Desc=xtNone then if ExprType.Desc=xtNone then
Context:=CreateFindContext(Self,StartNode) Context:=CreateFindContext(Self,StartNode)
else else
@ -7210,7 +7212,8 @@ var
MoveCursorToCleanPos(CurAtom.StartPos); MoveCursorToCleanPos(CurAtom.StartPos);
RaiseIllegalQualifierFound; RaiseIllegalQualifierFound;
end; end;
if (not NodeIsInAMethod(Context.Node)) then begin ProcNode:=GetMethodOfBody(Context.Node);
if ProcNode=nil then begin
MoveCursorToCleanPos(CurAtom.StartPos); MoveCursorToCleanPos(CurAtom.StartPos);
RaiseException(ctsInheritedKeywordOnlyAllowedInMethods); RaiseException(ctsInheritedKeywordOnlyAllowedInMethods);
end; end;
@ -7231,38 +7234,47 @@ var
' CurAtom="',copy(Src,CurAtom.StartPos,CurAtom.EndPos-CurAtom.StartPos),'"'); ' CurAtom="',copy(Src,CurAtom.StartPos,CurAtom.EndPos-CurAtom.StartPos),'"');
{$ENDIF} {$ENDIF}
// find ancestor of class of method // find class of method
ProcNode:=Context.Node.GetNodeOfType(ctnProcedure);
Params.Save(OldInput); Params.Save(OldInput);
Params.Flags:=[fdfExceptionOnNotFound] Params.Flags:=[fdfExceptionOnNotFound]
+fdfGlobals*Params.Flags; +fdfGlobals*Params.Flags;
Context.Tool.FindClassOfMethod(ProcNode,Params,true); FindClassOfMethod(ProcNode,Params,true);
ClassOfMethodContext:=CreateFindContext(Params); ClassNodeOfMethod:=Params.NewNode;
// find class ancestor // find class ancestor
Params.Flags:=[fdfSearchInParentNodes,fdfExceptionOnNotFound] Params.Flags:=[fdfSearchInParentNodes,fdfExceptionOnNotFound]
+fdfGlobals*Params.Flags; +fdfGlobals*Params.Flags;
ClassOfMethodContext.Tool.FindAncestorOfClass(ClassOfMethodContext.Node, FindAncestorOfClass(ClassNodeOfMethod,Params,true);
Params,true);
ExprType.Desc:=xtContext; ExprType.Desc:=xtContext;
if HasIdentifier then begin ExprType.Context:=CreateFindContext(Params);
// search identifier only in class ancestor if (not HasIdentifier) then begin
Params.Load(OldInput,false);
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],@CheckSrcIdentifier);
Params.ContextNode:=Params.NewNode;
Params.Flags:=Params.Flags-[fdfSearchInParentNodes]
+[fdfExceptionOnNotFound,fdfSearchInAncestors];
Params.NewCodeTool.FindIdentifierInContext(Params);
ExprType.Context:=CreateFindContext(Params);
Params.Load(OldInput,true);
ResolveBaseTypeOfIdentifier;
end else begin
// the keyword 'inherited' is the last atom // the keyword 'inherited' is the last atom
// return the ancestor class context if StartFlags*[fdfFindChilds,fdfFindVariable]=[fdfFindVariable] then begin
ExprType.Context:=CreateFindContext(Params); // for example: inherited; search the method, not the context
end; DefProcNode:=FindCorrespondingProcNode(ProcNode);
if DefProcNode=nil then begin
MoveCursorToProcName(ProcNode,true);
RaiseExceptionFmt(ctsMethodSignatureSNotFoundInClass, [GetAtom]);
end;
MoveCursorToProcName(DefProcNode,true);
end else begin
// for example: inherited |
// return the ancestor class context
exit;
end;
end else
MoveCursorToCleanPos(CurAtom.StartPos);
// search identifier only in class ancestor
Params.Load(OldInput,false);
Params.SetIdentifier(Self,@Src[CurPos.StartPos],@CheckSrcIdentifier);
Params.ContextNode:=ExprType.Context.Node;
Params.Flags:=Params.Flags-[fdfSearchInParentNodes]
+[fdfExceptionOnNotFound,fdfSearchInAncestors];
ExprType.Context.Tool.FindIdentifierInContext(Params);
ExprType.Context:=CreateFindContext(Params);
Params.Load(OldInput,true);
end; end;
begin begin

View File

@ -601,6 +601,10 @@ msgstr "Fonts del Lazarus"
msgid "method name" msgid "method name"
msgstr "nom del mètode" msgstr "nom del mètode"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "no s'ha trobat la definició del tipus del mètode" msgstr "no s'ha trobat la definició del tipus del mètode"

View File

@ -602,6 +602,10 @@ msgstr "Zdroje Lazarusu"
msgid "method name" msgid "method name"
msgstr "jméno metody" msgstr "jméno metody"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "definice typu metody nenalezena" msgstr "definice typu metody nenalezena"

View File

@ -604,6 +604,10 @@ msgstr "Lazarus-Quellen"
msgid "method name" msgid "method name"
msgstr "Methodenname" msgstr "Methodenname"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "Methodentypdefinition nicht gefunden" msgstr "Methodentypdefinition nicht gefunden"

View File

@ -601,6 +601,10 @@ msgstr "Fuentes de Lazarus"
msgid "method name" msgid "method name"
msgstr "nombre de método" msgstr "nombre de método"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "definición de tipo de método no encontrado" msgstr "definición de tipo de método no encontrado"

View File

@ -600,6 +600,10 @@ msgstr "Fuentes de Lazarus"
msgid "method name" msgid "method name"
msgstr "nombre de método" msgstr "nombre de método"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "definición de tipo de método no encontrado" msgstr "definición de tipo de método no encontrado"

View File

@ -594,6 +594,10 @@ msgstr ""
msgid "method name" msgid "method name"
msgstr "" msgstr ""
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "" msgstr ""

View File

@ -602,6 +602,10 @@ msgstr "Sources de Lazarus"
msgid "method name" msgid "method name"
msgstr "nom de méthode" msgstr "nom de méthode"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "définition de la méthode non trouvée" msgstr "définition de la méthode non trouvée"

View File

@ -601,6 +601,10 @@ msgstr "הקוד של לזארוס"
msgid "method name" msgid "method name"
msgstr "שם מתודה" msgstr "שם מתודה"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "ההגדרה של סוג המתודה לא נמצאה" msgstr "ההגדרה של סוג המתודה לא נמצאה"

View File

@ -602,6 +602,10 @@ msgstr "Sumber Lazarus"
msgid "method name" msgid "method name"
msgstr "nama method" msgstr "nama method"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "definisi tipe method tidak ditemukan" msgstr "definisi tipe method tidak ditemukan"

View File

@ -599,6 +599,10 @@ msgstr "Sorgenti di Lazarus"
msgid "method name" msgid "method name"
msgstr "nome metodo" msgstr "nome metodo"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "definizione del tipo di metodo non trovata" msgstr "definizione del tipo di metodo non trovata"

View File

@ -603,6 +603,10 @@ msgstr "Lazarus pirminis kodas"
msgid "method name" msgid "method name"
msgstr "metodo pavadinimas" msgstr "metodo pavadinimas"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "nerasta metodo tipo apibrėžtis" msgstr "nerasta metodo tipo apibrėžtis"

View File

@ -601,6 +601,10 @@ msgstr ""
msgid "method name" msgid "method name"
msgstr "" msgstr ""
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "" msgstr ""

View File

@ -605,6 +605,10 @@ msgstr "źródła lazarusa"
msgid "method name" msgid "method name"
msgstr "nazwa metody" msgstr "nazwa metody"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "nie znaleziono definicji typu metody" msgstr "nie znaleziono definicji typu metody"

View File

@ -594,6 +594,10 @@ msgstr ""
msgid "method name" msgid "method name"
msgstr "" msgstr ""
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "" msgstr ""

View File

@ -601,6 +601,10 @@ msgstr "Fontes do Lazarus"
msgid "method name" msgid "method name"
msgstr "nome de método" msgstr "nome de método"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "método tipo de definição não encontrado" msgstr "método tipo de definição não encontrado"

View File

@ -601,6 +601,10 @@ msgstr "Fontes do Lazarus"
msgid "method name" msgid "method name"
msgstr "nome de método" msgstr "nome de método"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "método tipo de definição não encontrado" msgstr "método tipo de definição não encontrado"

View File

@ -600,6 +600,10 @@ msgstr "Исходный код Lazarus"
msgid "method name" msgid "method name"
msgstr "имя метода" msgstr "имя метода"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "не найдено описание типа метода" msgstr "не найдено описание типа метода"

View File

@ -600,6 +600,10 @@ msgstr ""
msgid "method name" msgid "method name"
msgstr "" msgstr ""
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "" msgstr ""

View File

@ -599,6 +599,10 @@ msgstr "Коди lazarus"
msgid "method name" msgid "method name"
msgstr "ім'я методу" msgstr "ім'я методу"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "не знайдений опис типу методу" msgstr "не знайдений опис типу методу"

View File

@ -604,6 +604,10 @@ msgstr "Lazarus 源代码"
msgid "method name" msgid "method name"
msgstr "method 名称" msgstr "method 名称"
#: codetoolsstrconsts.ctsmethodsignaturesnotfoundinclass
msgid "Method signature %s not found in class"
msgstr ""
#: codetoolsstrconsts.ctsmethodtypedefinitionnotfound #: codetoolsstrconsts.ctsmethodtypedefinitionnotfound
msgid "method type definition not found" msgid "method type definition not found"
msgstr "未找到 methond 类型定义" msgstr "未找到 methond 类型定义"

View File

@ -129,6 +129,7 @@ type
Parse: boolean = true): TCodeTreeNode; Parse: boolean = true): TCodeTreeNode;
function NodeIsInAMethod(Node: TCodeTreeNode): boolean; function NodeIsInAMethod(Node: TCodeTreeNode): boolean;
function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean; function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean;
function GetMethodOfBody(Node: TCodeTreeNode): TCodeTreeNode;
function NodeIsFunction(ProcNode: TCodeTreeNode): boolean; function NodeIsFunction(ProcNode: TCodeTreeNode): boolean;
function NodeIsConstructor(ProcNode: TCodeTreeNode): boolean; function NodeIsConstructor(ProcNode: TCodeTreeNode): boolean;
function NodeIsDestructor(ProcNode: TCodeTreeNode): boolean; function NodeIsDestructor(ProcNode: TCodeTreeNode): boolean;
@ -1919,6 +1920,13 @@ begin
end; end;
end; end;
function TPascalReaderTool.GetMethodOfBody(Node: TCodeTreeNode): TCodeTreeNode;
begin
Result:=Node;
while (Result<>nil) and not NodeIsMethodBody(Result) do
Result:=Result.Parent;
end;
function TPascalReaderTool.NodeIsFunction(ProcNode: TCodeTreeNode): boolean; function TPascalReaderTool.NodeIsFunction(ProcNode: TCodeTreeNode): boolean;
begin begin
Result:=false; Result:=false;