mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 14:49:28 +02:00
codetools: implemented local type and var section for generics
git-svn-id: trunk@11833 -
This commit is contained in:
parent
2f7eaae417
commit
afcbbf4db0
@ -1747,7 +1747,7 @@ begin
|
||||
and (Node.FirstChild.Desc=ctnEnumerationType) then
|
||||
Node:=Node.FirstChild
|
||||
else
|
||||
Node:=Node.Next;
|
||||
Node:=Node.NextSkipChilds;
|
||||
end;
|
||||
ctnProcedure:
|
||||
begin
|
||||
@ -2040,7 +2040,7 @@ begin
|
||||
and (Node.FirstChild.Desc=ctnEnumerationType) then
|
||||
Node:=Node.FirstChild
|
||||
else
|
||||
Node:=Node.Next;
|
||||
Node:=Node.NextSkipChilds;
|
||||
end;
|
||||
ctnProcedure:
|
||||
begin
|
||||
@ -3773,7 +3773,8 @@ var CleanCursorPos, Indent, insertPos: integer;
|
||||
// due to insertions in front of the class, the cursor position could
|
||||
// have changed
|
||||
while (CursorNode<>nil) do begin
|
||||
if (CursorNode.Desc in [ctnTypeSection,ctnTypeDefinition,ctnGenericType])
|
||||
if (CursorNode.Desc=ctnTypeSection)
|
||||
or ((CursorNode.Parent<>nil) and (CursorNode.Parent.Desc=ctnTypeSection))
|
||||
then break;
|
||||
CursorNode:=CursorNode.Parent;
|
||||
end;
|
||||
|
@ -72,6 +72,7 @@ ResourceString
|
||||
ctsNoPascalCodeFound = 'no pascal code found (first token is %s)';
|
||||
ctsStringConstant = 'string constant';
|
||||
ctsAnonymDefinitionsAreNotAllowed = 'Anonymous %s definitions are not allowed';
|
||||
ctsNestedDefinitionsAreNotAllowed = 'Nested %s definitions are not allowed';
|
||||
ctsEndForRecordNotFound = 'end for record not found';
|
||||
ctsMissingEnumList = 'missing enum list';
|
||||
ctsMissingTypeIdentifier = 'missing type identifier';
|
||||
|
@ -51,92 +51,108 @@ type
|
||||
|
||||
const
|
||||
// CodeTreeNodeDescriptors
|
||||
ctnNone = 0;
|
||||
ctnNone = 0;
|
||||
|
||||
ctnProgram = 1;
|
||||
ctnPackage = 2;
|
||||
ctnLibrary = 3;
|
||||
ctnUnit = 4;
|
||||
ctnInterface = 5;
|
||||
ctnImplementation = 6;
|
||||
ctnInitialization = 7;
|
||||
ctnFinalization = 8;
|
||||
ctnEndPoint = 9;
|
||||
ctnProgram = 1;
|
||||
ctnPackage = 2;
|
||||
ctnLibrary = 3;
|
||||
ctnUnit = 4;
|
||||
ctnInterface = 5;
|
||||
ctnImplementation = 6;
|
||||
ctnInitialization = 7;
|
||||
ctnFinalization = 8;
|
||||
ctnEndPoint = 9;
|
||||
|
||||
ctnTypeSection = 10;
|
||||
ctnVarSection = 11;
|
||||
ctnConstSection = 12;
|
||||
ctnResStrSection = 13;
|
||||
ctnLabelSection = 14;
|
||||
ctnPropertySection = 15;
|
||||
ctnUsesSection = 16;
|
||||
ctnRequiresSection = 17;
|
||||
ctnContainsSection = 18;
|
||||
ctnExportsSection = 19;
|
||||
ctnTypeSection = 10;
|
||||
ctnVarSection = 11;
|
||||
ctnConstSection = 12;
|
||||
ctnResStrSection = 13;
|
||||
ctnLabelSection = 14;
|
||||
ctnPropertySection = 15;
|
||||
ctnUsesSection = 16;
|
||||
ctnRequiresSection = 17;
|
||||
ctnContainsSection = 18;
|
||||
ctnExportsSection = 19;
|
||||
|
||||
ctnTypeDefinition = 20;
|
||||
ctnVarDefinition = 21;
|
||||
ctnConstDefinition = 22;
|
||||
ctnGlobalProperty = 23;
|
||||
ctnTypeDefinition = 20;
|
||||
ctnVarDefinition = 21;
|
||||
ctnConstDefinition = 22;
|
||||
ctnGlobalProperty = 23;
|
||||
|
||||
ctnClass = 30;
|
||||
ctnClassInterface = 31;
|
||||
ctnClassPublished = 32;
|
||||
ctnClassPrivate = 33;
|
||||
ctnClassProtected = 34;
|
||||
ctnClassPublic = 35;
|
||||
ctnClassGUID = 36;
|
||||
ctnClass = 30;
|
||||
ctnClassInterface = 31;
|
||||
ctnClassTypePublic = 32;
|
||||
ctnClassTypePrivate = 33;
|
||||
ctnClassTypeProtected = 34;
|
||||
ctnClassTypePublished = 35;
|
||||
ctnClassVarPublic = 36;
|
||||
ctnClassVarPrivate = 37;
|
||||
ctnClassVarProtected = 38;
|
||||
ctnClassVarPublished = 39;
|
||||
ctnClassPublished = 40;
|
||||
ctnClassPrivate = 41;
|
||||
ctnClassProtected = 42;
|
||||
ctnClassPublic = 43;
|
||||
ctnClassGUID = 44;
|
||||
|
||||
ctnProperty = 40;
|
||||
ctnMethodMap = 41;
|
||||
ctnProperty = 50;
|
||||
ctnMethodMap = 51;
|
||||
|
||||
ctnProcedure = 50;
|
||||
ctnProcedureHead = 51;
|
||||
ctnParameterList = 52;
|
||||
ctnProcedure = 60;
|
||||
ctnProcedureHead = 61;
|
||||
ctnParameterList = 62;
|
||||
|
||||
ctnIdentifier = 60;
|
||||
ctnRangedArrayType = 61;
|
||||
ctnOpenArrayType = 62;
|
||||
ctnOfConstType = 63;
|
||||
ctnRecordType = 64;
|
||||
ctnRecordCase = 65;
|
||||
ctnRecordVariant = 66;
|
||||
ctnProcedureType = 67;
|
||||
ctnSetType = 68;
|
||||
ctnRangeType = 69;
|
||||
ctnEnumerationType = 70;
|
||||
ctnEnumIdentifier = 71;
|
||||
ctnLabelType = 72;
|
||||
ctnTypeType = 73;
|
||||
ctnFileType = 74;
|
||||
ctnPointerType = 75;
|
||||
ctnClassOfType = 76;
|
||||
ctnVariantType = 77;
|
||||
ctnSpecialize = 78;
|
||||
ctnSpecializeType = 79;
|
||||
ctnSpecializeParams= 80;
|
||||
ctnGenericType = 81;// 1. child = ctnGenericName, 2. child = ctnGenericParams, 3. child = type
|
||||
ctnGenericName = 82;
|
||||
ctnGenericParams = 83;
|
||||
ctnGenericParameter= 84;
|
||||
ctnConstant = 85;
|
||||
ctnIdentifier = 70;
|
||||
ctnRangedArrayType = 71;
|
||||
ctnOpenArrayType = 72;
|
||||
ctnOfConstType = 73;
|
||||
ctnRecordType = 74;
|
||||
ctnRecordCase = 75;
|
||||
ctnRecordVariant = 76;
|
||||
ctnProcedureType = 77;
|
||||
ctnSetType = 78;
|
||||
ctnRangeType = 79;
|
||||
ctnEnumerationType = 80;
|
||||
ctnEnumIdentifier = 81;
|
||||
ctnLabelType = 82;
|
||||
ctnTypeType = 83;
|
||||
ctnFileType = 84;
|
||||
ctnPointerType = 85;
|
||||
ctnClassOfType = 86;
|
||||
ctnVariantType = 87;
|
||||
ctnSpecialize = 88;
|
||||
ctnSpecializeType = 89;
|
||||
ctnSpecializeParams = 90;
|
||||
ctnGenericType = 91;// 1. child = ctnGenericName, 2. child = ctnGenericParams, 3. child = type
|
||||
ctnGenericName = 92;
|
||||
ctnGenericParams = 93;
|
||||
ctnGenericParameter = 94;
|
||||
ctnConstant = 95;
|
||||
|
||||
ctnBeginBlock = 90;
|
||||
ctnAsmBlock = 91;
|
||||
ctnBeginBlock =100;
|
||||
ctnAsmBlock =101;
|
||||
|
||||
ctnWithVariable =100;
|
||||
ctnWithStatement =101;
|
||||
ctnOnBlock =102;
|
||||
ctnOnIdentifier =103;// e.g. on E: Exception
|
||||
ctnOnStatement =104;
|
||||
ctnWithVariable =110;
|
||||
ctnWithStatement =111;
|
||||
ctnOnBlock =112;
|
||||
ctnOnIdentifier =113;// e.g. on E: Exception
|
||||
ctnOnStatement =114;
|
||||
|
||||
|
||||
// combined values
|
||||
AllCodeSections =
|
||||
[ctnProgram, ctnPackage, ctnLibrary, ctnUnit, ctnInterface,
|
||||
ctnImplementation, ctnInitialization, ctnFinalization];
|
||||
AllClassSections =
|
||||
AllClassBaseSections =
|
||||
[ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected];
|
||||
AllClassTypeSections =
|
||||
[ctnClassTypePublic,ctnClassTypePublished,ctnClassTypePrivate,
|
||||
ctnClassTypeProtected];
|
||||
AllClassVarSections =
|
||||
[ctnClassVarPublic,ctnClassVarPublished,ctnClassVarPrivate,
|
||||
ctnClassVarProtected];
|
||||
AllClassSections =
|
||||
AllClassBaseSections+AllClassTypeSections+AllClassVarSections;
|
||||
AllClasses =
|
||||
[ctnClass,ctnClassInterface];
|
||||
AllDefinitionSections =
|
||||
@ -323,11 +339,19 @@ begin
|
||||
|
||||
ctnClass: Result:='Class';
|
||||
ctnClassInterface: Result:='Class Interface';
|
||||
ctnClassGUID: Result:='GUID';
|
||||
ctnClassPublished: Result:='Published';
|
||||
ctnClassPrivate: Result:='Private';
|
||||
ctnClassProtected: Result:='Protected';
|
||||
ctnClassPublic: Result:='Public';
|
||||
ctnClassGUID: Result:='GUID';
|
||||
ctnClassTypePublished: Result:='Type Published';
|
||||
ctnClassTypePrivate: Result:='Type Private';
|
||||
ctnClassTypeProtected: Result:='Type Protected';
|
||||
ctnClassTypePublic: Result:='Type Public';
|
||||
ctnClassVarPublished: Result:='Var Published';
|
||||
ctnClassVarPrivate: Result:='Var Private';
|
||||
ctnClassVarProtected: Result:='Var Protected';
|
||||
ctnClassVarPublic: Result:='Var Public';
|
||||
|
||||
ctnProcedure: Result:='Procedure';
|
||||
ctnProcedureHead: Result:='ProcedureHead';
|
||||
|
@ -7,7 +7,16 @@ type
|
||||
{ TMyList }
|
||||
|
||||
generic TMyList<T> = class(TObject)
|
||||
data : T;
|
||||
type public
|
||||
TItem = record
|
||||
Value: T;
|
||||
end;
|
||||
type private
|
||||
PValue = ^T;
|
||||
var public
|
||||
Data : T;
|
||||
public
|
||||
Cache: T;
|
||||
procedure SetData(item: T);
|
||||
end;
|
||||
|
||||
|
@ -2459,35 +2459,30 @@ var
|
||||
// it is not always allowed to search in every node on the same lvl:
|
||||
|
||||
// -> test if class visibility valid
|
||||
case ContextNode.Desc of
|
||||
ctnClassPublished: break;
|
||||
ctnClassPublic: break;
|
||||
ctnClassProtected: break;
|
||||
ctnClassPrivate: break;
|
||||
ctnWithVariable:
|
||||
begin
|
||||
// check if StartContextNode is covered by the ContextNode
|
||||
// a WithVariable ranges from the start of its expression
|
||||
// to the end of the with statement
|
||||
{$IFDEF ShowExprEval}
|
||||
DebugLn('SearchNextNode WithVar StartContextNode.StartPos=',dbgs(StartContextNode.StartPos),
|
||||
' ContextNode=',dbgs(ContextNode.StartPos),'-',dbgs(ContextNode.EndPos),
|
||||
' WithStart="',StringToPascalConst(copy(Src,ContextNode.StartPos,15)),'"');
|
||||
{$ENDIF}
|
||||
if (StartContextNode.StartPos>=ContextNode.StartPos)
|
||||
and (StartContextNode.StartPos<ContextNode.EndPos) then break;
|
||||
{ ELSE: this with statement does not cover the startcontext
|
||||
-> skip it
|
||||
for example:
|
||||
will be skipped:
|
||||
with ContextNode do ;
|
||||
with B do StartContextNode;
|
||||
if ContextNode.Desc in AllClassSections then
|
||||
break
|
||||
else if ContextNode.Desc=ctnWithVariable then begin
|
||||
// check if StartContextNode is covered by the ContextNode
|
||||
// a WithVariable ranges from the start of its expression
|
||||
// to the end of the with statement
|
||||
{$IFDEF ShowExprEval}
|
||||
DebugLn('SearchNextNode WithVar StartContextNode.StartPos=',dbgs(StartContextNode.StartPos),
|
||||
' ContextNode=',dbgs(ContextNode.StartPos),'-',dbgs(ContextNode.EndPos),
|
||||
' WithStart="',StringToPascalConst(copy(Src,ContextNode.StartPos,15)),'"');
|
||||
{$ENDIF}
|
||||
if (StartContextNode.StartPos>=ContextNode.StartPos)
|
||||
and (StartContextNode.StartPos<ContextNode.EndPos) then break;
|
||||
{ ELSE: this with statement does not cover the startcontext
|
||||
-> skip it
|
||||
for example:
|
||||
will be skipped:
|
||||
with ContextNode do ;
|
||||
with B do StartContextNode;
|
||||
|
||||
will be searched:
|
||||
with ContextNode, StartContextNode do ;
|
||||
}
|
||||
end;
|
||||
else
|
||||
will be searched:
|
||||
with ContextNode, StartContextNode do ;
|
||||
}
|
||||
end else begin
|
||||
break;
|
||||
end;
|
||||
end else if (ContextNode.Parent<>nil)
|
||||
@ -2509,6 +2504,8 @@ var
|
||||
ctnLabelSection, ctnPropertySection,
|
||||
ctnInterface, ctnImplementation,
|
||||
ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate,
|
||||
ctnClassTypePublished,ctnClassTypePublic,ctnClassTypeProtected,ctnClassTypePrivate,
|
||||
ctnClassVarPublished,ctnClassVarPublic,ctnClassVarProtected,ctnClassVarPrivate,
|
||||
ctnRecordVariant,
|
||||
ctnProcedureHead, ctnParameterList:
|
||||
// these codetreenodes build a parent-child-relationship, but
|
||||
@ -2613,6 +2610,8 @@ begin
|
||||
ctnLabelSection, ctnPropertySection,
|
||||
ctnInterface, ctnImplementation,
|
||||
ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished,
|
||||
ctnClassTypePublished,ctnClassTypePublic,ctnClassTypeProtected,ctnClassTypePrivate,
|
||||
ctnClassVarPublished,ctnClassVarPublic,ctnClassVarProtected,ctnClassVarPrivate,
|
||||
ctnClass, ctnClassInterface,
|
||||
ctnRecordType, ctnRecordVariant,
|
||||
ctnParameterList:
|
||||
@ -4025,6 +4024,7 @@ var
|
||||
ClassNameAtom: TAtomPosition;
|
||||
OldInput: TFindDeclarationInput;
|
||||
ClassContext: TFindContext;
|
||||
CurClassNode: TCodeTreeNode;
|
||||
begin
|
||||
{$IFDEF ShowTriedContexts}
|
||||
DebugLn('[TFindDeclarationTool.FindClassOfMethod] A ');
|
||||
@ -4032,15 +4032,14 @@ begin
|
||||
Result:=false;
|
||||
if ProcNode.Desc=ctnProcedureHead then
|
||||
ProcNode:=ProcNode.Parent;
|
||||
if ProcNode.Parent.Desc
|
||||
in [ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate]
|
||||
then begin
|
||||
if ProcNode.Parent.Desc in AllClassSections then begin
|
||||
CurClassNode:=ProcNode.Parent.Parent;
|
||||
if FindClassContext then begin
|
||||
// return the class node
|
||||
Params.SetResult(Self,ProcNode.GetNodeOfType(ctnClass));
|
||||
Params.SetResult(Self,CurClassNode);
|
||||
end else begin
|
||||
// return the type identifier node
|
||||
Params.SetResult(Self,ProcNode.GetNodeOfType(ctnClass).Parent);
|
||||
Params.SetResult(Self,CurClassNode.Parent);
|
||||
end;
|
||||
Result:=true;
|
||||
exit;
|
||||
|
@ -1282,7 +1282,8 @@ var
|
||||
//DebugLn(['CheckProcedureDeclarationContext ',CursorNode.DescAsString]);
|
||||
Node:=CursorNode;
|
||||
Can:=false;
|
||||
if (Node.Parent<>nil) and (Node.Parent.Desc in AllClassSections)
|
||||
if (Node.Parent<>nil)
|
||||
and (Node.Parent.Desc in (AllClassBaseSections+AllClassVarSections))
|
||||
and (Node.Desc=ctnVarDefinition)
|
||||
and (CurrentIdentifierList.StartAtomBehind.Flag<>cafColon) then begin
|
||||
{ cursor is at a class variable definition without type
|
||||
@ -1301,7 +1302,7 @@ var
|
||||
// for example: procedure DoSomething|
|
||||
Can:=true;
|
||||
end
|
||||
else if Node.Desc in (AllClassSections+AllSourceTypes
|
||||
else if Node.Desc in (AllClassBaseSections+AllSourceTypes
|
||||
+[ctnInterface,ctnImplementation])
|
||||
then begin
|
||||
//DebugLn(['TIdentCompletionTool.CheckProcedureDeclarationContext ilcfCanProcDeclaration']);
|
||||
|
@ -136,6 +136,7 @@ type
|
||||
function KeyWordFuncLabel: boolean;
|
||||
function KeyWordFuncProperty: boolean;
|
||||
// types
|
||||
procedure ReadEqualsType;
|
||||
function KeyWordFuncClass: boolean;
|
||||
function KeyWordFuncClassInterface: boolean;
|
||||
function KeyWordFuncTypePacked: boolean;
|
||||
@ -156,9 +157,10 @@ type
|
||||
function KeyWordFuncBeginEnd: boolean;
|
||||
// class/object elements
|
||||
function KeyWordFuncClassSection: boolean;
|
||||
function KeyWordFuncClassTypeSection: boolean;
|
||||
function KeyWordFuncClassVarSection: boolean;
|
||||
function KeyWordFuncClassMethod: boolean;
|
||||
function KeyWordFuncClassProperty: boolean;
|
||||
function KeyWordFuncClassReadTilEnd: boolean;
|
||||
function KeyWordFuncClassIdentifier: boolean;
|
||||
function KeyWordFuncClassVarTypeClass: boolean;
|
||||
function KeyWordFuncClassVarTypePacked: boolean;
|
||||
@ -390,6 +392,8 @@ procedure TPascalParserTool.BuildInnerClassKeyWordFunctions;
|
||||
// KeyWordFunctions for parsing in a class/object
|
||||
begin
|
||||
with InnerClassKeyWordFuncList do begin
|
||||
Add('TYPE',@KeyWordFuncClassTypeSection);
|
||||
Add('VAR',@KeyWordFuncClassVarSection);
|
||||
Add('PUBLIC',@KeyWordFuncClassSection);
|
||||
Add('PRIVATE',@KeyWordFuncClassSection);
|
||||
Add('PUBLISHED',@KeyWordFuncClassSection);
|
||||
@ -605,7 +609,7 @@ begin
|
||||
MoveCursorToNodeStart(ClassNode);
|
||||
// parse
|
||||
// - inheritage
|
||||
// - class sections (public, published, private, protected)
|
||||
// - class sections (GUID, type, var, public, published, private, protected)
|
||||
// - methods (procedures, functions, constructors, destructors)
|
||||
|
||||
// first parse the inheritage
|
||||
@ -722,20 +726,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPascalParserTool.KeyWordFuncClassReadTilEnd: boolean;
|
||||
// read til atom after next 'end'
|
||||
begin
|
||||
repeat
|
||||
ReadNextAtom;
|
||||
until (CurPos.StartPos>SrcLen) or (CurPos.Flag=cafEND);
|
||||
ReadNextAtom;
|
||||
Result:=(CurPos.StartPos<SrcLen);
|
||||
end;
|
||||
|
||||
function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
|
||||
{ parse class variable
|
||||
{ parse class variable or type
|
||||
|
||||
examples:
|
||||
examples for variables:
|
||||
Name: TypeName;
|
||||
Name: UnitName.TypeName;
|
||||
i, j: integer;
|
||||
@ -760,26 +754,35 @@ function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
|
||||
MyRange: 3..5;
|
||||
}
|
||||
begin
|
||||
// create variable definition node
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnVarDefinition;
|
||||
ReadNextAtom;
|
||||
while CurPos.Flag=cafComma do begin
|
||||
// end variable definition
|
||||
CurNode.EndPos:=CurPos.StartPos;
|
||||
if CurNode.Desc in AllClassTypeSections then begin
|
||||
// create type definition node
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnTypeDefinition;
|
||||
ReadEqualsType;
|
||||
CurNode.EndPos:=CurPos.EndPos;
|
||||
EndChildNode;
|
||||
// read next variable name
|
||||
ReadNextAtom;
|
||||
AtomIsIdentifier(true);
|
||||
end else begin
|
||||
// create variable definition node
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnVarDefinition;
|
||||
ReadNextAtom;
|
||||
while CurPos.Flag=cafComma do begin
|
||||
// end variable definition
|
||||
CurNode.EndPos:=CurPos.StartPos;
|
||||
EndChildNode;
|
||||
// read next variable name
|
||||
ReadNextAtom;
|
||||
AtomIsIdentifier(true);
|
||||
// create variable definition node
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnVarDefinition;
|
||||
ReadNextAtom;
|
||||
end;
|
||||
if CurPos.Flag<>cafColon then
|
||||
RaiseCharExpectedButAtomFound(':');
|
||||
// read type
|
||||
ReadVariableType;
|
||||
end;
|
||||
if CurPos.Flag<>cafColon then
|
||||
RaiseCharExpectedButAtomFound(':');
|
||||
// read type
|
||||
ReadVariableType;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
@ -944,6 +947,50 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TPascalParserTool.KeyWordFuncClassTypeSection: boolean;
|
||||
begin
|
||||
// end last section
|
||||
CurNode.EndPos:=CurPos.StartPos;
|
||||
EndChildNode;
|
||||
// start new section
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnClassTypePublic;
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('PUBLIC') then
|
||||
CurNode.Desc:=ctnClassTypePublic
|
||||
else if UpAtomIs('PRIVATE') then
|
||||
CurNode.Desc:=ctnClassTypePrivate
|
||||
else if UpAtomIs('PROTECTED') then
|
||||
CurNode.Desc:=ctnClassTypeProtected
|
||||
else if UpAtomIs('PUBLISHED') then
|
||||
CurNode.Desc:=ctnClassTypePublished
|
||||
else
|
||||
RaiseStringExpectedButAtomFound('public');
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TPascalParserTool.KeyWordFuncClassVarSection: boolean;
|
||||
begin
|
||||
// end last section
|
||||
CurNode.EndPos:=CurPos.StartPos;
|
||||
EndChildNode;
|
||||
// start new section
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnClassVarPublic;
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('PUBLIC') then
|
||||
CurNode.Desc:=ctnClassVarPublic
|
||||
else if UpAtomIs('PRIVATE') then
|
||||
CurNode.Desc:=ctnClassVarPrivate
|
||||
else if UpAtomIs('PROTECTED') then
|
||||
CurNode.Desc:=ctnClassVarProtected
|
||||
else if UpAtomIs('PUBLISHED') then
|
||||
CurNode.Desc:=ctnClassVarPublished
|
||||
else
|
||||
RaiseStringExpectedButAtomFound('public');
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TPascalParserTool.KeyWordFuncClassMethod: boolean;
|
||||
{ parse class method
|
||||
|
||||
@ -967,6 +1014,9 @@ function TPascalParserTool.KeyWordFuncClassMethod: boolean;
|
||||
var IsFunction, HasForwardModifier: boolean;
|
||||
ParseAttr: TParseProcHeadAttributes;
|
||||
begin
|
||||
if not (CurNode.Desc in (AllClassBaseSections+[ctnClassInterface])) then
|
||||
RaiseIdentExpectedButAtomFound;
|
||||
|
||||
HasForwardModifier:=false;
|
||||
// create class method node
|
||||
CreateChildNode;
|
||||
@ -1788,6 +1838,8 @@ function TPascalParserTool.KeyWordFuncClassProperty: boolean;
|
||||
end;
|
||||
|
||||
begin
|
||||
if not (CurNode.Desc in AllClassBaseSections) then
|
||||
RaiseIdentExpectedButAtomFound;
|
||||
// create class method node
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnProperty;
|
||||
@ -2491,29 +2543,25 @@ begin
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
ReadNextAtom;
|
||||
end;
|
||||
if UpAtomIs('PUBLIC') or UpAtomIs('EXTERNAL') then begin
|
||||
if NodeHasParentOfType(CurNode,ctnClass) then
|
||||
// class visibility keyword 'public'
|
||||
UndoReadNextAtom
|
||||
else begin
|
||||
// for example 'var a: char; public;'
|
||||
if UpAtomIs('EXTERNAL') then begin
|
||||
// read external name
|
||||
ReadNextAtom;
|
||||
if (not UpAtomIs('NAME')) and AtomIsIdentifier(false) then
|
||||
ReadConstant(true,false,[]);
|
||||
end else
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('NAME') then begin
|
||||
// for example 'var a: char; public name 'b' ;'
|
||||
ReadNextAtom;
|
||||
if not AtomIsStringConstant then
|
||||
RaiseStringExpectedButAtomFound(ctsStringConstant);
|
||||
if (CurNode.Parent.Desc=ctnVarSection)
|
||||
and (UpAtomIs('PUBLIC') or UpAtomIs('EXTERNAL')) then begin
|
||||
// for example 'var a: char; public;'
|
||||
if UpAtomIs('EXTERNAL') then begin
|
||||
// read external name
|
||||
ReadNextAtom;
|
||||
if (not UpAtomIs('NAME')) and AtomIsIdentifier(false) then
|
||||
ReadConstant(true,false,[]);
|
||||
end;
|
||||
if CurPos.Flag<>cafSemicolon then
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
end else
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('NAME') then begin
|
||||
// for example 'var a: char; public name 'b' ;'
|
||||
ReadNextAtom;
|
||||
if not AtomIsStringConstant then
|
||||
RaiseStringExpectedButAtomFound(ctsStringConstant);
|
||||
ReadConstant(true,false,[]);
|
||||
end;
|
||||
if CurPos.Flag<>cafSemicolon then
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
end else
|
||||
UndoReadNextAtom;
|
||||
CurNode.EndPos:=CurPos.EndPos;
|
||||
@ -2603,23 +2651,6 @@ function TPascalParserTool.KeyWordFuncType: boolean;
|
||||
procedure c;
|
||||
type d=e;
|
||||
}
|
||||
|
||||
procedure ReadType;
|
||||
// read = type;
|
||||
begin
|
||||
// read =
|
||||
ReadNextAtom;
|
||||
if (CurPos.Flag<>cafEqual) then
|
||||
RaiseCharExpectedButAtomFound('=');
|
||||
// read type
|
||||
ReadNextAtom;
|
||||
TypeKeyWordFuncList.DoItUpperCase(UpperSrc,CurPos.StartPos,
|
||||
CurPos.EndPos-CurPos.StartPos);
|
||||
// read ;
|
||||
if CurPos.Flag<>cafSemicolon then
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
end;
|
||||
|
||||
begin
|
||||
if not (CurSection in [ctnProgram,ctnLibrary,ctnInterface,ctnImplementation])
|
||||
then
|
||||
@ -2677,14 +2708,14 @@ begin
|
||||
// close ctnGenericParams
|
||||
CurNode.EndPos:=CurPos.EndPos;
|
||||
EndChildNode;
|
||||
ReadType;
|
||||
ReadEqualsType;
|
||||
// close ctnGenericType
|
||||
CurNode.EndPos:=CurPos.EndPos;
|
||||
EndChildNode;
|
||||
end else if AtomIsIdentifier(false) then begin
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnTypeDefinition;
|
||||
ReadType;
|
||||
ReadEqualsType;
|
||||
CurNode.EndPos:=CurPos.EndPos;
|
||||
EndChildNode;
|
||||
end else begin
|
||||
@ -2986,6 +3017,22 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TPascalParserTool.ReadEqualsType;
|
||||
// read = type;
|
||||
begin
|
||||
// read =
|
||||
ReadNextAtom;
|
||||
if (CurPos.Flag<>cafEqual) then
|
||||
RaiseCharExpectedButAtomFound('=');
|
||||
// read type
|
||||
ReadNextAtom;
|
||||
TypeKeyWordFuncList.DoItUpperCase(UpperSrc,CurPos.StartPos,
|
||||
CurPos.EndPos-CurPos.StartPos);
|
||||
// read ;
|
||||
if CurPos.Flag<>cafSemicolon then
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
end;
|
||||
|
||||
function TPascalParserTool.KeyWordFuncTypePacked: boolean;
|
||||
begin
|
||||
ReadNextAtom;
|
||||
@ -3081,9 +3128,10 @@ begin
|
||||
ContextDesc:=CurNode.Desc;
|
||||
if not (ContextDesc in [ctnTypeDefinition,ctnGenericType,
|
||||
ctnVarDefinition,ctnConstDefinition])
|
||||
then begin
|
||||
then
|
||||
SaveRaiseExceptionFmt(ctsAnonymDefinitionsAreNotAllowed,['class']);
|
||||
end;
|
||||
if CurNode.Parent.Desc<>ctnTypeSection then
|
||||
SaveRaiseExceptionFmt(ctsNestedDefinitionsAreNotAllowed,['class']);
|
||||
if LastUpAtomIs(0,'PACKED') or LastUpAtomIs(0,'BITPACKED') then begin
|
||||
ClassAtomPos:=LastAtoms.GetValueAt(0);
|
||||
end else begin
|
||||
@ -3160,6 +3208,8 @@ var
|
||||
begin
|
||||
if not (CurNode.Desc in [ctnTypeDefinition,ctnGenericType]) then
|
||||
SaveRaiseExceptionFmt(ctsAnonymDefinitionsAreNotAllowed,['interface']);
|
||||
if CurNode.Parent.Desc<>ctnTypeSection then
|
||||
SaveRaiseExceptionFmt(ctsNestedDefinitionsAreNotAllowed,['interface']);
|
||||
IntfAtomPos:=CurPos;
|
||||
// class interface start found
|
||||
ChildCreated:=true;
|
||||
|
@ -598,9 +598,15 @@ begin
|
||||
StartNode:=FindClassNodeInUnit(ExtractClassNameOfProcNode(ProcNode),true,
|
||||
false,false,true);
|
||||
BuildSubTreeForClass(StartNode);
|
||||
while (StartNode<>nil)
|
||||
and (StartNode.Desc in [ctnClass,ctnClassInterface]+AllClassSections) do
|
||||
if (StartNode<>nil) and (StartNode.Desc in [ctnClass,ctnClassInterface])
|
||||
then begin
|
||||
StartNode:=StartNode.FirstChild;
|
||||
while (StartNode<>nil) and (not (StartNode.Desc in AllClassBaseSections))
|
||||
do
|
||||
StartNode:=StartNode.NextBrother;
|
||||
if StartNode<>nil then
|
||||
StartNode:=StartNode.FirstChild;
|
||||
end;
|
||||
end else begin
|
||||
//DebugLn('TPascalReaderTool.FindCorrespondingProcNode Normal');
|
||||
// else: search on same lvl
|
||||
|
@ -181,8 +181,7 @@ type
|
||||
|
||||
|
||||
{ TFixAliasDefinitionsInUnit - fix section type of alias definitions
|
||||
NOT COMPLETE YET
|
||||
|
||||
|
||||
Checks all alias definitions of the form
|
||||
const LeftSide = RightSide;
|
||||
looks up RightSide in the unit and if RightSide is a type or var, changes
|
||||
@ -3269,7 +3268,7 @@ begin
|
||||
DebugLn(['TFixAliasDefinitionsInUnit.Execute file is not pascal: ',aText.Filename]);
|
||||
exit(mrOk);// ignore
|
||||
end;
|
||||
// ToDo: finish codetools FixAllAliasDefinitions
|
||||
// finish codetools FixAllAliasDefinitions
|
||||
if not CodeToolBoss.FixAllAliasDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
|
||||
DebugLn(['TFixAliasDefinitionsInUnit.Execute FixAllAliasDefinitions failed ',CodeToolBoss.ErrorMessage]);
|
||||
exit;
|
||||
@ -3634,7 +3633,7 @@ begin
|
||||
repeat
|
||||
Changed:=false;
|
||||
if not ReduceCompilerDirectives(Changed,Result) then exit;
|
||||
//if not FixAliasDefinitions(Changed,Result) then exit;
|
||||
if not FixAliasDefinitions(Changed,Result) then exit;
|
||||
if not ConvertSimpleFunctions(Changed,Result) then exit;
|
||||
until Changed=false;
|
||||
end;
|
||||
|
@ -49,20 +49,20 @@
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="5">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
<PackageName Value="CodeTools"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="SynEdit"/>
|
||||
<PackageName Value="FCL"/>
|
||||
<MinVersion Major="1" Valid="True"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="IDEIntf"/>
|
||||
</Item3>
|
||||
<Item4>
|
||||
<PackageName Value="FCL"/>
|
||||
<MinVersion Major="1" Valid="True"/>
|
||||
<PackageName Value="SynEdit"/>
|
||||
</Item4>
|
||||
<Item5>
|
||||
<PackageName Value="CodeTools"/>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item5>
|
||||
</RequiredPkgs>
|
||||
<UsageOptions>
|
||||
|
@ -801,7 +801,7 @@ var
|
||||
begin
|
||||
Result:=true;
|
||||
|
||||
{ Put the compiler options into the TCompilerOptions class to be saved }
|
||||
// Put the compiler options from the dialog into the TCompilerOptions class
|
||||
if DestCompilerOptions<>nil then
|
||||
Options:=DestCompilerOptions
|
||||
else
|
||||
|
@ -3766,6 +3766,7 @@ begin
|
||||
if Assigned(OnPopupMenu) then OnPopupMenu(@AddContextPopupMenuItem);
|
||||
|
||||
SourceEditorMenuRoot.NotifySubSectionOnShow(Self);
|
||||
//SourceEditorMenuRoot.WriteDebugReport(' ',true);
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.NotebookShowTabHint(Sender: TObject;
|
||||
|
@ -1905,7 +1905,6 @@ var
|
||||
PkgFile: TPkgFile;
|
||||
begin
|
||||
PkgFile:=GetPackageOfCurrentSourceEditor;
|
||||
//debugln('TPkgManager.OnSourceEditorPopupMenu ',dbgsName(PkgFile));
|
||||
if PkgFile<>nil then
|
||||
AddMenuItemProc('Open package '+PkgFile.LazPackage.Name,true,
|
||||
@OnOpenPackageForCurrentSrcEditFile);
|
||||
|
Loading…
Reference in New Issue
Block a user