codetools: implemented local type and var section for generics

git-svn-id: trunk@11833 -
This commit is contained in:
mattias 2007-08-17 12:48:29 +00:00
parent 2f7eaae417
commit afcbbf4db0
13 changed files with 283 additions and 193 deletions

View File

@ -1747,7 +1747,7 @@ begin
and (Node.FirstChild.Desc=ctnEnumerationType) then and (Node.FirstChild.Desc=ctnEnumerationType) then
Node:=Node.FirstChild Node:=Node.FirstChild
else else
Node:=Node.Next; Node:=Node.NextSkipChilds;
end; end;
ctnProcedure: ctnProcedure:
begin begin
@ -2040,7 +2040,7 @@ begin
and (Node.FirstChild.Desc=ctnEnumerationType) then and (Node.FirstChild.Desc=ctnEnumerationType) then
Node:=Node.FirstChild Node:=Node.FirstChild
else else
Node:=Node.Next; Node:=Node.NextSkipChilds;
end; end;
ctnProcedure: ctnProcedure:
begin begin
@ -3773,7 +3773,8 @@ var CleanCursorPos, Indent, insertPos: integer;
// due to insertions in front of the class, the cursor position could // due to insertions in front of the class, the cursor position could
// have changed // have changed
while (CursorNode<>nil) do begin 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; then break;
CursorNode:=CursorNode.Parent; CursorNode:=CursorNode.Parent;
end; end;

View File

@ -72,6 +72,7 @@ ResourceString
ctsNoPascalCodeFound = 'no pascal code found (first token is %s)'; ctsNoPascalCodeFound = 'no pascal code found (first token is %s)';
ctsStringConstant = 'string constant'; ctsStringConstant = 'string constant';
ctsAnonymDefinitionsAreNotAllowed = 'Anonymous %s definitions are not allowed'; ctsAnonymDefinitionsAreNotAllowed = 'Anonymous %s definitions are not allowed';
ctsNestedDefinitionsAreNotAllowed = 'Nested %s definitions are not allowed';
ctsEndForRecordNotFound = 'end for record not found'; ctsEndForRecordNotFound = 'end for record not found';
ctsMissingEnumList = 'missing enum list'; ctsMissingEnumList = 'missing enum list';
ctsMissingTypeIdentifier = 'missing type identifier'; ctsMissingTypeIdentifier = 'missing type identifier';

View File

@ -51,92 +51,108 @@ type
const const
// CodeTreeNodeDescriptors // CodeTreeNodeDescriptors
ctnNone = 0; ctnNone = 0;
ctnProgram = 1; ctnProgram = 1;
ctnPackage = 2; ctnPackage = 2;
ctnLibrary = 3; ctnLibrary = 3;
ctnUnit = 4; ctnUnit = 4;
ctnInterface = 5; ctnInterface = 5;
ctnImplementation = 6; ctnImplementation = 6;
ctnInitialization = 7; ctnInitialization = 7;
ctnFinalization = 8; ctnFinalization = 8;
ctnEndPoint = 9; ctnEndPoint = 9;
ctnTypeSection = 10; ctnTypeSection = 10;
ctnVarSection = 11; ctnVarSection = 11;
ctnConstSection = 12; ctnConstSection = 12;
ctnResStrSection = 13; ctnResStrSection = 13;
ctnLabelSection = 14; ctnLabelSection = 14;
ctnPropertySection = 15; ctnPropertySection = 15;
ctnUsesSection = 16; ctnUsesSection = 16;
ctnRequiresSection = 17; ctnRequiresSection = 17;
ctnContainsSection = 18; ctnContainsSection = 18;
ctnExportsSection = 19; ctnExportsSection = 19;
ctnTypeDefinition = 20; ctnTypeDefinition = 20;
ctnVarDefinition = 21; ctnVarDefinition = 21;
ctnConstDefinition = 22; ctnConstDefinition = 22;
ctnGlobalProperty = 23; ctnGlobalProperty = 23;
ctnClass = 30; ctnClass = 30;
ctnClassInterface = 31; ctnClassInterface = 31;
ctnClassPublished = 32; ctnClassTypePublic = 32;
ctnClassPrivate = 33; ctnClassTypePrivate = 33;
ctnClassProtected = 34; ctnClassTypeProtected = 34;
ctnClassPublic = 35; ctnClassTypePublished = 35;
ctnClassGUID = 36; ctnClassVarPublic = 36;
ctnClassVarPrivate = 37;
ctnClassVarProtected = 38;
ctnClassVarPublished = 39;
ctnClassPublished = 40;
ctnClassPrivate = 41;
ctnClassProtected = 42;
ctnClassPublic = 43;
ctnClassGUID = 44;
ctnProperty = 40; ctnProperty = 50;
ctnMethodMap = 41; ctnMethodMap = 51;
ctnProcedure = 50; ctnProcedure = 60;
ctnProcedureHead = 51; ctnProcedureHead = 61;
ctnParameterList = 52; ctnParameterList = 62;
ctnIdentifier = 60; ctnIdentifier = 70;
ctnRangedArrayType = 61; ctnRangedArrayType = 71;
ctnOpenArrayType = 62; ctnOpenArrayType = 72;
ctnOfConstType = 63; ctnOfConstType = 73;
ctnRecordType = 64; ctnRecordType = 74;
ctnRecordCase = 65; ctnRecordCase = 75;
ctnRecordVariant = 66; ctnRecordVariant = 76;
ctnProcedureType = 67; ctnProcedureType = 77;
ctnSetType = 68; ctnSetType = 78;
ctnRangeType = 69; ctnRangeType = 79;
ctnEnumerationType = 70; ctnEnumerationType = 80;
ctnEnumIdentifier = 71; ctnEnumIdentifier = 81;
ctnLabelType = 72; ctnLabelType = 82;
ctnTypeType = 73; ctnTypeType = 83;
ctnFileType = 74; ctnFileType = 84;
ctnPointerType = 75; ctnPointerType = 85;
ctnClassOfType = 76; ctnClassOfType = 86;
ctnVariantType = 77; ctnVariantType = 87;
ctnSpecialize = 78; ctnSpecialize = 88;
ctnSpecializeType = 79; ctnSpecializeType = 89;
ctnSpecializeParams= 80; ctnSpecializeParams = 90;
ctnGenericType = 81;// 1. child = ctnGenericName, 2. child = ctnGenericParams, 3. child = type ctnGenericType = 91;// 1. child = ctnGenericName, 2. child = ctnGenericParams, 3. child = type
ctnGenericName = 82; ctnGenericName = 92;
ctnGenericParams = 83; ctnGenericParams = 93;
ctnGenericParameter= 84; ctnGenericParameter = 94;
ctnConstant = 85; ctnConstant = 95;
ctnBeginBlock = 90; ctnBeginBlock =100;
ctnAsmBlock = 91; ctnAsmBlock =101;
ctnWithVariable =100; ctnWithVariable =110;
ctnWithStatement =101; ctnWithStatement =111;
ctnOnBlock =102; ctnOnBlock =112;
ctnOnIdentifier =103;// e.g. on E: Exception ctnOnIdentifier =113;// e.g. on E: Exception
ctnOnStatement =104; ctnOnStatement =114;
// combined values // combined values
AllCodeSections = AllCodeSections =
[ctnProgram, ctnPackage, ctnLibrary, ctnUnit, ctnInterface, [ctnProgram, ctnPackage, ctnLibrary, ctnUnit, ctnInterface,
ctnImplementation, ctnInitialization, ctnFinalization]; ctnImplementation, ctnInitialization, ctnFinalization];
AllClassSections = AllClassBaseSections =
[ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected]; [ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected];
AllClassTypeSections =
[ctnClassTypePublic,ctnClassTypePublished,ctnClassTypePrivate,
ctnClassTypeProtected];
AllClassVarSections =
[ctnClassVarPublic,ctnClassVarPublished,ctnClassVarPrivate,
ctnClassVarProtected];
AllClassSections =
AllClassBaseSections+AllClassTypeSections+AllClassVarSections;
AllClasses = AllClasses =
[ctnClass,ctnClassInterface]; [ctnClass,ctnClassInterface];
AllDefinitionSections = AllDefinitionSections =
@ -323,11 +339,19 @@ begin
ctnClass: Result:='Class'; ctnClass: Result:='Class';
ctnClassInterface: Result:='Class Interface'; ctnClassInterface: Result:='Class Interface';
ctnClassGUID: Result:='GUID';
ctnClassPublished: Result:='Published'; ctnClassPublished: Result:='Published';
ctnClassPrivate: Result:='Private'; ctnClassPrivate: Result:='Private';
ctnClassProtected: Result:='Protected'; ctnClassProtected: Result:='Protected';
ctnClassPublic: Result:='Public'; 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'; ctnProcedure: Result:='Procedure';
ctnProcedureHead: Result:='ProcedureHead'; ctnProcedureHead: Result:='ProcedureHead';

View File

@ -7,7 +7,16 @@ type
{ TMyList } { TMyList }
generic TMyList<T> = class(TObject) 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); procedure SetData(item: T);
end; end;

View File

@ -2459,35 +2459,30 @@ var
// it is not always allowed to search in every node on the same lvl: // it is not always allowed to search in every node on the same lvl:
// -> test if class visibility valid // -> test if class visibility valid
case ContextNode.Desc of if ContextNode.Desc in AllClassSections then
ctnClassPublished: break; break
ctnClassPublic: break; else if ContextNode.Desc=ctnWithVariable then begin
ctnClassProtected: break; // check if StartContextNode is covered by the ContextNode
ctnClassPrivate: break; // a WithVariable ranges from the start of its expression
ctnWithVariable: // to the end of the with statement
begin {$IFDEF ShowExprEval}
// check if StartContextNode is covered by the ContextNode DebugLn('SearchNextNode WithVar StartContextNode.StartPos=',dbgs(StartContextNode.StartPos),
// a WithVariable ranges from the start of its expression ' ContextNode=',dbgs(ContextNode.StartPos),'-',dbgs(ContextNode.EndPos),
// to the end of the with statement ' WithStart="',StringToPascalConst(copy(Src,ContextNode.StartPos,15)),'"');
{$IFDEF ShowExprEval} {$ENDIF}
DebugLn('SearchNextNode WithVar StartContextNode.StartPos=',dbgs(StartContextNode.StartPos), if (StartContextNode.StartPos>=ContextNode.StartPos)
' ContextNode=',dbgs(ContextNode.StartPos),'-',dbgs(ContextNode.EndPos), and (StartContextNode.StartPos<ContextNode.EndPos) then break;
' WithStart="',StringToPascalConst(copy(Src,ContextNode.StartPos,15)),'"'); { ELSE: this with statement does not cover the startcontext
{$ENDIF} -> skip it
if (StartContextNode.StartPos>=ContextNode.StartPos) for example:
and (StartContextNode.StartPos<ContextNode.EndPos) then break; will be skipped:
{ ELSE: this with statement does not cover the startcontext with ContextNode do ;
-> skip it with B do StartContextNode;
for example:
will be skipped:
with ContextNode do ;
with B do StartContextNode;
will be searched: will be searched:
with ContextNode, StartContextNode do ; with ContextNode, StartContextNode do ;
} }
end; end else begin
else
break; break;
end; end;
end else if (ContextNode.Parent<>nil) end else if (ContextNode.Parent<>nil)
@ -2509,6 +2504,8 @@ var
ctnLabelSection, ctnPropertySection, ctnLabelSection, ctnPropertySection,
ctnInterface, ctnImplementation, ctnInterface, ctnImplementation,
ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate, ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate,
ctnClassTypePublished,ctnClassTypePublic,ctnClassTypeProtected,ctnClassTypePrivate,
ctnClassVarPublished,ctnClassVarPublic,ctnClassVarProtected,ctnClassVarPrivate,
ctnRecordVariant, ctnRecordVariant,
ctnProcedureHead, ctnParameterList: ctnProcedureHead, ctnParameterList:
// these codetreenodes build a parent-child-relationship, but // these codetreenodes build a parent-child-relationship, but
@ -2613,6 +2610,8 @@ begin
ctnLabelSection, ctnPropertySection, ctnLabelSection, ctnPropertySection,
ctnInterface, ctnImplementation, ctnInterface, ctnImplementation,
ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished, ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished,
ctnClassTypePublished,ctnClassTypePublic,ctnClassTypeProtected,ctnClassTypePrivate,
ctnClassVarPublished,ctnClassVarPublic,ctnClassVarProtected,ctnClassVarPrivate,
ctnClass, ctnClassInterface, ctnClass, ctnClassInterface,
ctnRecordType, ctnRecordVariant, ctnRecordType, ctnRecordVariant,
ctnParameterList: ctnParameterList:
@ -4025,6 +4024,7 @@ var
ClassNameAtom: TAtomPosition; ClassNameAtom: TAtomPosition;
OldInput: TFindDeclarationInput; OldInput: TFindDeclarationInput;
ClassContext: TFindContext; ClassContext: TFindContext;
CurClassNode: TCodeTreeNode;
begin begin
{$IFDEF ShowTriedContexts} {$IFDEF ShowTriedContexts}
DebugLn('[TFindDeclarationTool.FindClassOfMethod] A '); DebugLn('[TFindDeclarationTool.FindClassOfMethod] A ');
@ -4032,15 +4032,14 @@ begin
Result:=false; Result:=false;
if ProcNode.Desc=ctnProcedureHead then if ProcNode.Desc=ctnProcedureHead then
ProcNode:=ProcNode.Parent; ProcNode:=ProcNode.Parent;
if ProcNode.Parent.Desc if ProcNode.Parent.Desc in AllClassSections then begin
in [ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate] CurClassNode:=ProcNode.Parent.Parent;
then begin
if FindClassContext then begin if FindClassContext then begin
// return the class node // return the class node
Params.SetResult(Self,ProcNode.GetNodeOfType(ctnClass)); Params.SetResult(Self,CurClassNode);
end else begin end else begin
// return the type identifier node // return the type identifier node
Params.SetResult(Self,ProcNode.GetNodeOfType(ctnClass).Parent); Params.SetResult(Self,CurClassNode.Parent);
end; end;
Result:=true; Result:=true;
exit; exit;

View File

@ -1282,7 +1282,8 @@ var
//DebugLn(['CheckProcedureDeclarationContext ',CursorNode.DescAsString]); //DebugLn(['CheckProcedureDeclarationContext ',CursorNode.DescAsString]);
Node:=CursorNode; Node:=CursorNode;
Can:=false; 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 (Node.Desc=ctnVarDefinition)
and (CurrentIdentifierList.StartAtomBehind.Flag<>cafColon) then begin and (CurrentIdentifierList.StartAtomBehind.Flag<>cafColon) then begin
{ cursor is at a class variable definition without type { cursor is at a class variable definition without type
@ -1301,7 +1302,7 @@ var
// for example: procedure DoSomething| // for example: procedure DoSomething|
Can:=true; Can:=true;
end end
else if Node.Desc in (AllClassSections+AllSourceTypes else if Node.Desc in (AllClassBaseSections+AllSourceTypes
+[ctnInterface,ctnImplementation]) +[ctnInterface,ctnImplementation])
then begin then begin
//DebugLn(['TIdentCompletionTool.CheckProcedureDeclarationContext ilcfCanProcDeclaration']); //DebugLn(['TIdentCompletionTool.CheckProcedureDeclarationContext ilcfCanProcDeclaration']);

View File

@ -136,6 +136,7 @@ type
function KeyWordFuncLabel: boolean; function KeyWordFuncLabel: boolean;
function KeyWordFuncProperty: boolean; function KeyWordFuncProperty: boolean;
// types // types
procedure ReadEqualsType;
function KeyWordFuncClass: boolean; function KeyWordFuncClass: boolean;
function KeyWordFuncClassInterface: boolean; function KeyWordFuncClassInterface: boolean;
function KeyWordFuncTypePacked: boolean; function KeyWordFuncTypePacked: boolean;
@ -156,9 +157,10 @@ type
function KeyWordFuncBeginEnd: boolean; function KeyWordFuncBeginEnd: boolean;
// class/object elements // class/object elements
function KeyWordFuncClassSection: boolean; function KeyWordFuncClassSection: boolean;
function KeyWordFuncClassTypeSection: boolean;
function KeyWordFuncClassVarSection: boolean;
function KeyWordFuncClassMethod: boolean; function KeyWordFuncClassMethod: boolean;
function KeyWordFuncClassProperty: boolean; function KeyWordFuncClassProperty: boolean;
function KeyWordFuncClassReadTilEnd: boolean;
function KeyWordFuncClassIdentifier: boolean; function KeyWordFuncClassIdentifier: boolean;
function KeyWordFuncClassVarTypeClass: boolean; function KeyWordFuncClassVarTypeClass: boolean;
function KeyWordFuncClassVarTypePacked: boolean; function KeyWordFuncClassVarTypePacked: boolean;
@ -390,6 +392,8 @@ procedure TPascalParserTool.BuildInnerClassKeyWordFunctions;
// KeyWordFunctions for parsing in a class/object // KeyWordFunctions for parsing in a class/object
begin begin
with InnerClassKeyWordFuncList do begin with InnerClassKeyWordFuncList do begin
Add('TYPE',@KeyWordFuncClassTypeSection);
Add('VAR',@KeyWordFuncClassVarSection);
Add('PUBLIC',@KeyWordFuncClassSection); Add('PUBLIC',@KeyWordFuncClassSection);
Add('PRIVATE',@KeyWordFuncClassSection); Add('PRIVATE',@KeyWordFuncClassSection);
Add('PUBLISHED',@KeyWordFuncClassSection); Add('PUBLISHED',@KeyWordFuncClassSection);
@ -605,7 +609,7 @@ begin
MoveCursorToNodeStart(ClassNode); MoveCursorToNodeStart(ClassNode);
// parse // parse
// - inheritage // - inheritage
// - class sections (public, published, private, protected) // - class sections (GUID, type, var, public, published, private, protected)
// - methods (procedures, functions, constructors, destructors) // - methods (procedures, functions, constructors, destructors)
// first parse the inheritage // first parse the inheritage
@ -722,20 +726,10 @@ begin
end; end;
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; function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
{ parse class variable { parse class variable or type
examples: examples for variables:
Name: TypeName; Name: TypeName;
Name: UnitName.TypeName; Name: UnitName.TypeName;
i, j: integer; i, j: integer;
@ -760,26 +754,35 @@ function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
MyRange: 3..5; MyRange: 3..5;
} }
begin begin
// create variable definition node if CurNode.Desc in AllClassTypeSections then begin
CreateChildNode; // create type definition node
CurNode.Desc:=ctnVarDefinition; CreateChildNode;
ReadNextAtom; CurNode.Desc:=ctnTypeDefinition;
while CurPos.Flag=cafComma do begin ReadEqualsType;
// end variable definition CurNode.EndPos:=CurPos.EndPos;
CurNode.EndPos:=CurPos.StartPos;
EndChildNode; EndChildNode;
// read next variable name end else begin
ReadNextAtom;
AtomIsIdentifier(true);
// create variable definition node // create variable definition node
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnVarDefinition; CurNode.Desc:=ctnVarDefinition;
ReadNextAtom; 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; end;
if CurPos.Flag<>cafColon then
RaiseCharExpectedButAtomFound(':');
// read type
ReadVariableType;
Result:=true; Result:=true;
end; end;
@ -944,6 +947,50 @@ begin
Result:=true; Result:=true;
end; 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; function TPascalParserTool.KeyWordFuncClassMethod: boolean;
{ parse class method { parse class method
@ -967,6 +1014,9 @@ function TPascalParserTool.KeyWordFuncClassMethod: boolean;
var IsFunction, HasForwardModifier: boolean; var IsFunction, HasForwardModifier: boolean;
ParseAttr: TParseProcHeadAttributes; ParseAttr: TParseProcHeadAttributes;
begin begin
if not (CurNode.Desc in (AllClassBaseSections+[ctnClassInterface])) then
RaiseIdentExpectedButAtomFound;
HasForwardModifier:=false; HasForwardModifier:=false;
// create class method node // create class method node
CreateChildNode; CreateChildNode;
@ -1788,6 +1838,8 @@ function TPascalParserTool.KeyWordFuncClassProperty: boolean;
end; end;
begin begin
if not (CurNode.Desc in AllClassBaseSections) then
RaiseIdentExpectedButAtomFound;
// create class method node // create class method node
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnProperty; CurNode.Desc:=ctnProperty;
@ -2491,29 +2543,25 @@ begin
RaiseCharExpectedButAtomFound(';'); RaiseCharExpectedButAtomFound(';');
ReadNextAtom; ReadNextAtom;
end; end;
if UpAtomIs('PUBLIC') or UpAtomIs('EXTERNAL') then begin if (CurNode.Parent.Desc=ctnVarSection)
if NodeHasParentOfType(CurNode,ctnClass) then and (UpAtomIs('PUBLIC') or UpAtomIs('EXTERNAL')) then begin
// class visibility keyword 'public' // for example 'var a: char; public;'
UndoReadNextAtom if UpAtomIs('EXTERNAL') then begin
else begin // read external name
// for example 'var a: char; public;' ReadNextAtom;
if UpAtomIs('EXTERNAL') then begin if (not UpAtomIs('NAME')) and AtomIsIdentifier(false) then
// 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);
ReadConstant(true,false,[]); ReadConstant(true,false,[]);
end; end else
if CurPos.Flag<>cafSemicolon then ReadNextAtom;
RaiseCharExpectedButAtomFound(';'); if UpAtomIs('NAME') then begin
// for example 'var a: char; public name 'b' ;'
ReadNextAtom;
if not AtomIsStringConstant then
RaiseStringExpectedButAtomFound(ctsStringConstant);
ReadConstant(true,false,[]);
end; end;
if CurPos.Flag<>cafSemicolon then
RaiseCharExpectedButAtomFound(';');
end else end else
UndoReadNextAtom; UndoReadNextAtom;
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
@ -2603,23 +2651,6 @@ function TPascalParserTool.KeyWordFuncType: boolean;
procedure c; procedure c;
type d=e; 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 begin
if not (CurSection in [ctnProgram,ctnLibrary,ctnInterface,ctnImplementation]) if not (CurSection in [ctnProgram,ctnLibrary,ctnInterface,ctnImplementation])
then then
@ -2677,14 +2708,14 @@ begin
// close ctnGenericParams // close ctnGenericParams
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
EndChildNode; EndChildNode;
ReadType; ReadEqualsType;
// close ctnGenericType // close ctnGenericType
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
EndChildNode; EndChildNode;
end else if AtomIsIdentifier(false) then begin end else if AtomIsIdentifier(false) then begin
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnTypeDefinition; CurNode.Desc:=ctnTypeDefinition;
ReadType; ReadEqualsType;
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
EndChildNode; EndChildNode;
end else begin end else begin
@ -2986,6 +3017,22 @@ begin
Result:=true; Result:=true;
end; 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; function TPascalParserTool.KeyWordFuncTypePacked: boolean;
begin begin
ReadNextAtom; ReadNextAtom;
@ -3081,9 +3128,10 @@ begin
ContextDesc:=CurNode.Desc; ContextDesc:=CurNode.Desc;
if not (ContextDesc in [ctnTypeDefinition,ctnGenericType, if not (ContextDesc in [ctnTypeDefinition,ctnGenericType,
ctnVarDefinition,ctnConstDefinition]) ctnVarDefinition,ctnConstDefinition])
then begin then
SaveRaiseExceptionFmt(ctsAnonymDefinitionsAreNotAllowed,['class']); SaveRaiseExceptionFmt(ctsAnonymDefinitionsAreNotAllowed,['class']);
end; if CurNode.Parent.Desc<>ctnTypeSection then
SaveRaiseExceptionFmt(ctsNestedDefinitionsAreNotAllowed,['class']);
if LastUpAtomIs(0,'PACKED') or LastUpAtomIs(0,'BITPACKED') then begin if LastUpAtomIs(0,'PACKED') or LastUpAtomIs(0,'BITPACKED') then begin
ClassAtomPos:=LastAtoms.GetValueAt(0); ClassAtomPos:=LastAtoms.GetValueAt(0);
end else begin end else begin
@ -3160,6 +3208,8 @@ var
begin begin
if not (CurNode.Desc in [ctnTypeDefinition,ctnGenericType]) then if not (CurNode.Desc in [ctnTypeDefinition,ctnGenericType]) then
SaveRaiseExceptionFmt(ctsAnonymDefinitionsAreNotAllowed,['interface']); SaveRaiseExceptionFmt(ctsAnonymDefinitionsAreNotAllowed,['interface']);
if CurNode.Parent.Desc<>ctnTypeSection then
SaveRaiseExceptionFmt(ctsNestedDefinitionsAreNotAllowed,['interface']);
IntfAtomPos:=CurPos; IntfAtomPos:=CurPos;
// class interface start found // class interface start found
ChildCreated:=true; ChildCreated:=true;

View File

@ -598,9 +598,15 @@ begin
StartNode:=FindClassNodeInUnit(ExtractClassNameOfProcNode(ProcNode),true, StartNode:=FindClassNodeInUnit(ExtractClassNameOfProcNode(ProcNode),true,
false,false,true); false,false,true);
BuildSubTreeForClass(StartNode); BuildSubTreeForClass(StartNode);
while (StartNode<>nil) if (StartNode<>nil) and (StartNode.Desc in [ctnClass,ctnClassInterface])
and (StartNode.Desc in [ctnClass,ctnClassInterface]+AllClassSections) do then begin
StartNode:=StartNode.FirstChild; 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 end else begin
//DebugLn('TPascalReaderTool.FindCorrespondingProcNode Normal'); //DebugLn('TPascalReaderTool.FindCorrespondingProcNode Normal');
// else: search on same lvl // else: search on same lvl

View File

@ -181,8 +181,7 @@ type
{ TFixAliasDefinitionsInUnit - fix section type of alias definitions { TFixAliasDefinitionsInUnit - fix section type of alias definitions
NOT COMPLETE YET
Checks all alias definitions of the form Checks all alias definitions of the form
const LeftSide = RightSide; const LeftSide = RightSide;
looks up RightSide in the unit and if RightSide is a type or var, changes 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]); DebugLn(['TFixAliasDefinitionsInUnit.Execute file is not pascal: ',aText.Filename]);
exit(mrOk);// ignore exit(mrOk);// ignore
end; end;
// ToDo: finish codetools FixAllAliasDefinitions // finish codetools FixAllAliasDefinitions
if not CodeToolBoss.FixAllAliasDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin if not CodeToolBoss.FixAllAliasDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
DebugLn(['TFixAliasDefinitionsInUnit.Execute FixAllAliasDefinitions failed ',CodeToolBoss.ErrorMessage]); DebugLn(['TFixAliasDefinitionsInUnit.Execute FixAllAliasDefinitions failed ',CodeToolBoss.ErrorMessage]);
exit; exit;
@ -3634,7 +3633,7 @@ begin
repeat repeat
Changed:=false; Changed:=false;
if not ReduceCompilerDirectives(Changed,Result) then exit; 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; if not ConvertSimpleFunctions(Changed,Result) then exit;
until Changed=false; until Changed=false;
end; end;

View File

@ -49,20 +49,20 @@
<Type Value="RunAndDesignTime"/> <Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="5"> <RequiredPkgs Count="5">
<Item1> <Item1>
<PackageName Value="LCL"/> <PackageName Value="CodeTools"/>
</Item1> </Item1>
<Item2> <Item2>
<PackageName Value="SynEdit"/> <PackageName Value="FCL"/>
<MinVersion Major="1" Valid="True"/>
</Item2> </Item2>
<Item3> <Item3>
<PackageName Value="IDEIntf"/> <PackageName Value="IDEIntf"/>
</Item3> </Item3>
<Item4> <Item4>
<PackageName Value="FCL"/> <PackageName Value="SynEdit"/>
<MinVersion Major="1" Valid="True"/>
</Item4> </Item4>
<Item5> <Item5>
<PackageName Value="CodeTools"/> <PackageName Value="LCL"/>
</Item5> </Item5>
</RequiredPkgs> </RequiredPkgs>
<UsageOptions> <UsageOptions>

View File

@ -801,7 +801,7 @@ var
begin begin
Result:=true; 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 if DestCompilerOptions<>nil then
Options:=DestCompilerOptions Options:=DestCompilerOptions
else else

View File

@ -3766,6 +3766,7 @@ begin
if Assigned(OnPopupMenu) then OnPopupMenu(@AddContextPopupMenuItem); if Assigned(OnPopupMenu) then OnPopupMenu(@AddContextPopupMenuItem);
SourceEditorMenuRoot.NotifySubSectionOnShow(Self); SourceEditorMenuRoot.NotifySubSectionOnShow(Self);
//SourceEditorMenuRoot.WriteDebugReport(' ',true);
end; end;
procedure TSourceNotebook.NotebookShowTabHint(Sender: TObject; procedure TSourceNotebook.NotebookShowTabHint(Sender: TObject;

View File

@ -1905,7 +1905,6 @@ var
PkgFile: TPkgFile; PkgFile: TPkgFile;
begin begin
PkgFile:=GetPackageOfCurrentSourceEditor; PkgFile:=GetPackageOfCurrentSourceEditor;
//debugln('TPkgManager.OnSourceEditorPopupMenu ',dbgsName(PkgFile));
if PkgFile<>nil then if PkgFile<>nil then
AddMenuItemProc('Open package '+PkgFile.LazPackage.Name,true, AddMenuItemProc('Open package '+PkgFile.LazPackage.Name,true,
@OnOpenPackageForCurrentSrcEditFile); @OnOpenPackageForCurrentSrcEditFile);