codetools: support new class/generics syntax. like the next:

{ 
 TFoo = class
  const
    Value = 5;
  type
    TBar = integer;
  var
    FSomeField: Integer;
    procedure Dosomething;
  end;  
}

git-svn-id: trunk@28513 -
This commit is contained in:
paul 2010-11-27 18:25:25 +00:00
parent e2c48f0cd4
commit 188361e605
6 changed files with 100 additions and 120 deletions

View File

@ -5901,7 +5901,7 @@ begin
if ClassSectionNode.NextBrother<>nil then if ClassSectionNode.NextBrother<>nil then
Indent:=GetLineIndent(Src,ClassSectionNode.StartPos) Indent:=GetLineIndent(Src,ClassSectionNode.StartPos)
+ASourceChangeCache.BeautifyCodeOptions.Indent; +ASourceChangeCache.BeautifyCodeOptions.Indent;
end else if (ClassSectionNode.Desc in (AllClassBaseSections+AllClassTypeSections)) end else if (ClassSectionNode.Desc in (AllClassBaseSections+[ctnClassType]))
then begin then begin
// skip keyword // skip keyword
MoveCursorToCleanPos(InsertPos); MoveCursorToCleanPos(InsertPos);

View File

@ -95,20 +95,16 @@ const
ctnClassSealed = 41; ctnClassSealed = 41;
ctnClassInheritance = 42; ctnClassInheritance = 42;
ctnClassGUID = 43; ctnClassGUID = 43;
ctnClassTypePrivate = 44; ctnClassConst = 44;
ctnClassTypeProtected = 45; ctnClassType = 45;
ctnClassTypePublic = 46; ctnClassVar = 46;
ctnClassTypePublished = 47; ctnClassClassVar = 47;
ctnClassVarPrivate = 48; ctnClassPrivate = 48;
ctnClassVarProtected = 49; ctnClassProtected = 49;
ctnClassVarPublic = 50; ctnClassPublic = 50;
ctnClassVarPublished = 51; ctnClassPublished = 51;
ctnClassPrivate = 52; ctnProperty = 52;
ctnClassProtected = 53; ctnMethodMap = 53;
ctnClassPublic = 54;
ctnClassPublished = 55;
ctnProperty = 56;
ctnMethodMap = 57;
ctnProcedure = 60; // childs: ctnProcedureHead, sections, ctnBeginBlock/ctnAsmBlock ctnProcedure = 60; // childs: ctnProcedureHead, sections, ctnBeginBlock/ctnAsmBlock
ctnProcedureHead = 61; // childs: ctnParameterList, operator: ctnVarDefinition, operator/function: ctnResultType ctnProcedureHead = 61; // childs: ctnParameterList, operator: ctnVarDefinition, operator/function: ctnResultType
@ -159,14 +155,8 @@ const
+ [ctnInterface, ctnImplementation, ctnInitialization, ctnFinalization]; + [ctnInterface, ctnImplementation, ctnInitialization, ctnFinalization];
AllClassBaseSections = AllClassBaseSections =
[ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected]; [ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected];
AllClassTypeSections =
[ctnClassTypePublic,ctnClassTypePublished,ctnClassTypePrivate,
ctnClassTypeProtected];
AllClassVarSections =
[ctnClassVarPublic,ctnClassVarPublished,ctnClassVarPrivate,
ctnClassVarProtected];
AllClassSections = AllClassSections =
AllClassBaseSections+AllClassTypeSections+AllClassVarSections; AllClassBaseSections+[ctnClassConst, ctnClassType, ctnClassVar, ctnClassClassVar];
AllClasses = AllClasses =
[ctnClass,ctnClassInterface,ctnDispinterface,ctnObject, [ctnClass,ctnClassInterface,ctnDispinterface,ctnObject,
ctnObjCClass,ctnObjCCategory,ctnObjCProtocol, ctnObjCClass,ctnObjCCategory,ctnObjCProtocol,
@ -386,14 +376,10 @@ begin
ctnClassPrivate: Result:='Private'; ctnClassPrivate: Result:='Private';
ctnClassProtected: Result:='Protected'; ctnClassProtected: Result:='Protected';
ctnClassPublic: Result:='Public'; ctnClassPublic: Result:='Public';
ctnClassTypePublished: Result:='Type Published'; ctnClassConst: Result:='Const';
ctnClassTypePrivate: Result:='Type Private'; ctnClassType: Result:='Type';
ctnClassTypeProtected: Result:='Type Protected'; ctnClassVar: Result:='Var';
ctnClassTypePublic: Result:='Type Public'; ctnClassClassVar: Result:='Class Var';
ctnClassVarPublished: Result:='Var Published';
ctnClassVarPrivate: Result:='Var Private';
ctnClassVarProtected: Result:='Var Protected';
ctnClassVarPublic: Result:='Var Public';
ctnClassAbstract: Result:='abstract'; ctnClassAbstract: Result:='abstract';
ctnClassSealed: Result:='sealed'; ctnClassSealed: Result:='sealed';

View File

@ -2148,14 +2148,19 @@ begin
while ANode<>nil do begin while ANode<>nil do begin
if ANode.Desc in AllClassSections then begin if ANode.Desc in AllClassSections then begin
case ANode.Desc of case ANode.Desc of
ctnClassPrivate,ctnClassTypePrivate,ctnClassVarPrivate: ctnClassPrivate:
Result:=Result+'private '; Result:=Result+'private ';
ctnClassProtected,ctnClassTypeProtected,ctnClassVarProtected: ctnClassProtected:
Result:=Result+'protected '; Result:=Result+'protected ';
ctnClassPublic,ctnClassTypePublic,ctnClassVarPublic: ctnClassPublic:
Result:=Result+'public '; Result:=Result+'public ';
ctnClassPublished,ctnClassTypePublished,ctnClassVarPublished: ctnClassPublished:
Result:=Result+'published '; Result:=Result+'published ';
else
begin
ANode:=ANode.Parent;
Continue;
end;
end; end;
break; break;
end else if ANode.Desc in ([ctnParameterList]+AllClasses) then end else if ANode.Desc in ([ctnParameterList]+AllClasses) then
@ -2967,8 +2972,7 @@ var
ctnLabelSection, ctnPropertySection, ctnLabelSection, ctnPropertySection,
ctnInterface, ctnImplementation, ctnInterface, ctnImplementation,
ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate, ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate,
ctnClassTypePublished,ctnClassTypePublic,ctnClassTypeProtected,ctnClassTypePrivate, ctnClassConst,ctnClassType,ctnClassVar,ctnClassClassVar,
ctnClassVarPublished,ctnClassVarPublic,ctnClassVarProtected,ctnClassVarPrivate,
ctnRecordVariant, ctnRecordVariant,
ctnProcedureHead, ctnParameterList, ctnProcedureHead, ctnParameterList,
ctnClassInheritance: ctnClassInheritance:
@ -3087,8 +3091,7 @@ begin
ctnLabelSection, ctnPropertySection, ctnLabelSection, ctnPropertySection,
ctnInterface, ctnImplementation, ctnInterface, ctnImplementation,
ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished, ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished,
ctnClassTypePublished,ctnClassTypePublic,ctnClassTypeProtected,ctnClassTypePrivate, ctnClassConst, ctnClassType, ctnClassVar, ctnClassClassVar,
ctnClassVarPublished,ctnClassVarPublic,ctnClassVarProtected,ctnClassVarPrivate,
ctnClass, ctnClassInterface, ctnDispinterface, ctnObject, ctnClass, ctnClassInterface, ctnDispinterface, ctnObject,
ctnObjCClass, ctnObjCCategory, ctnObjCProtocol, ctnCPPClass, ctnObjCClass, ctnObjCCategory, ctnObjCProtocol, ctnCPPClass,
ctnRecordType, ctnRecordVariant, ctnRecordType, ctnRecordVariant,

View File

@ -1944,7 +1944,7 @@ var
Node:=CursorNode; Node:=CursorNode;
Can:=false; Can:=false;
if (Node.Parent<>nil) if (Node.Parent<>nil)
and (Node.Parent.Desc in (AllClassBaseSections+AllClassVarSections)) and (Node.Parent.Desc in [ctnClassVar,ctnClassClassVar])
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

View File

@ -138,6 +138,7 @@ type
function KeyWordFuncExports: boolean; function KeyWordFuncExports: boolean;
function KeyWordFuncLabel: boolean; function KeyWordFuncLabel: boolean;
function KeyWordFuncProperty: boolean; function KeyWordFuncProperty: boolean;
procedure ReadConst;
// types // types
procedure ReadEqualsType; procedure ReadEqualsType;
function KeyWordFuncClass: boolean; function KeyWordFuncClass: boolean;
@ -160,6 +161,7 @@ type
function KeyWordFuncBeginEnd: boolean; function KeyWordFuncBeginEnd: boolean;
// class/object elements // class/object elements
function KeyWordFuncClassSection: boolean; function KeyWordFuncClassSection: boolean;
function KeyWordFuncClassConstSection: boolean;
function KeyWordFuncClassTypeSection: boolean; function KeyWordFuncClassTypeSection: boolean;
function KeyWordFuncClassVarSection: boolean; function KeyWordFuncClassVarSection: boolean;
function KeyWordFuncClassClass: boolean; function KeyWordFuncClassClass: boolean;
@ -443,7 +445,8 @@ begin
'C': 'C':
case UpChars[p[1]] of case UpChars[p[1]] of
'L': if CompareSrcIdentifiers(p,'CLASS') then exit(KeyWordFuncClassClass); 'L': if CompareSrcIdentifiers(p,'CLASS') then exit(KeyWordFuncClassClass);
'O': if CompareSrcIdentifiers(p,'CONSTRUCTOR') then exit(KeyWordFuncClassMethod); 'O': if CompareSrcIdentifiers(p,'CONSTRUCTOR') then exit(KeyWordFuncClassMethod)
else if CompareSrcIdentifiers(p,'CONST') then exit(KeyWordFuncClassConstSection);
end; end;
'D': 'D':
if CompareSrcIdentifiers(p,'DESTRUCTOR') then exit(KeyWordFuncClassMethod); if CompareSrcIdentifiers(p,'DESTRUCTOR') then exit(KeyWordFuncClassMethod);
@ -875,7 +878,7 @@ begin
end; end;
function TPascalParserTool.KeyWordFuncClassIdentifier: boolean; function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
{ parse class variable or type { parse class variable or type or const
examples for variables: examples for variables:
Name: TypeName; Name: TypeName;
@ -902,13 +905,21 @@ function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
MyRange: 3..5; MyRange: 3..5;
} }
begin begin
if CurNode.Desc in AllClassTypeSections then begin if CurNode.Desc = ctnClassType then begin
// create type definition node // create type definition node
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnTypeDefinition; CurNode.Desc:=ctnTypeDefinition;
ReadEqualsType; ReadEqualsType;
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
EndChildNode; EndChildNode;
end else
if CurNode.Desc = ctnClassConst then begin
// create const definition node
CreateChildNode;
CurNode.Desc:=ctnConstDefinition;
ReadConst;
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
end else begin end else begin
// create variable definition node // create variable definition node
CreateChildNode; CreateChildNode;
@ -1097,6 +1108,17 @@ begin
Result:=true; Result:=true;
end; end;
function TPascalParserTool.KeyWordFuncClassConstSection: boolean;
begin
// end last section
CurNode.EndPos:=CurPos.StartPos;
EndChildNode;
// start new section
CreateChildNode;
CurNode.Desc:=ctnClassConst;
Result:=true;
end;
function TPascalParserTool.KeyWordFuncClassTypeSection: boolean; function TPascalParserTool.KeyWordFuncClassTypeSection: boolean;
begin begin
// end last section // end last section
@ -1104,39 +1126,14 @@ begin
EndChildNode; EndChildNode;
// start new section // start new section
CreateChildNode; CreateChildNode;
if UpAtomIs('CLASS') then ReadNextAtom; CurNode.Desc:=ctnClassType;
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 begin
if CurNode.PriorBrother<>nil then begin
case CurNode.PriorBrother.Desc of
ctnClassPrivate: CurNode.Desc:=ctnClassTypePrivate;
ctnClassProtected: CurNode.Desc:=ctnClassTypeProtected;
ctnClassPublic: CurNode.Desc:=ctnClassTypePublic;
ctnClassPublished: CurNode.Desc:=ctnClassTypePublished;
else
RaiseStringExpectedButAtomFound('public');
end;
end;
UndoReadNextAtom;
end;
Result:=true; Result:=true;
end; end;
function TPascalParserTool.KeyWordFuncClassVarSection: boolean; function TPascalParserTool.KeyWordFuncClassVarSection: boolean;
{ {
var private var
var protected class var
var public
var published
class var private
} }
begin begin
// end last section // end last section
@ -1144,19 +1141,13 @@ begin
EndChildNode; EndChildNode;
// start new section // start new section
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnClassVarPublic; if UpAtomIs('CLASS') then
if UpAtomIs('CLASS') then ReadNextAtom; begin
CurNode.Desc:=ctnClassClassVar;
ReadNextAtom; ReadNextAtom;
if UpAtomIs('PUBLIC') then end
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 else
RaiseStringExpectedButAtomFound('public'); CurNode.Desc:=ctnClassVar;
Result:=true; Result:=true;
end; end;
@ -1167,7 +1158,6 @@ function TPascalParserTool.KeyWordFuncClassClass: boolean;
class constructor class constructor
class destructor class destructor
class var class var
class type
} }
begin begin
ReadNextAtom; ReadNextAtom;
@ -3454,32 +3444,7 @@ begin
then begin then begin
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnConstDefinition; CurNode.Desc:=ctnConstDefinition;
ReadNextAtom; ReadConst;
if (CurPos.Flag=cafColon) then begin
// read type
ReadNextAtom;
ParseType(CurPos.StartPos,CurPos.EndPos-CurPos.StartPos);
end;
if (CurPos.Flag<>cafEqual) then
RaiseCharExpectedButAtomFound('=');
// read constant
ReadNextAtom;
CreateChildNode;
CurNode.Desc:=ctnConstant;
repeat
if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen]) then
ReadTilBracketClose(true);
if (CurPos.Flag in AllCommonAtomWords)
and (not IsKeyWordInConstAllowed.DoItCaseInsensitive(Src,
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos))
and AtomIsKeyWord then
RaiseStringExpectedButAtomFound('constant');
if (CurPos.Flag=cafSemicolon) then break;
CurNode.EndPos:=CurPos.EndPos;
ReadNextAtom;
until (CurPos.StartPos>SrcLen);
// close ctnConstant node
EndChildNode;
// close ctnConstDefinition node // close ctnConstDefinition node
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
EndChildNode; EndChildNode;
@ -3661,6 +3626,36 @@ begin
Result:=true; Result:=true;
end; end;
procedure TPascalParserTool.ReadConst;
begin
ReadNextAtom;
if (CurPos.Flag=cafColon) then begin
// read type
ReadNextAtom;
ParseType(CurPos.StartPos,CurPos.EndPos-CurPos.StartPos);
end;
if (CurPos.Flag<>cafEqual) then
RaiseCharExpectedButAtomFound('=');
// read constant
ReadNextAtom;
CreateChildNode;
CurNode.Desc:=ctnConstant;
repeat
if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen]) then
ReadTilBracketClose(true);
if (CurPos.Flag in AllCommonAtomWords)
and (not IsKeyWordInConstAllowed.DoItCaseInsensitive(Src,
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos))
and AtomIsKeyWord then
RaiseStringExpectedButAtomFound('constant');
if (CurPos.Flag=cafSemicolon) then break;
CurNode.EndPos:=CurPos.EndPos;
ReadNextAtom;
until (CurPos.StartPos>SrcLen);
// close ctnConstant node
EndChildNode;
end;
procedure TPascalParserTool.ReadEqualsType; procedure TPascalParserTool.ReadEqualsType;
// read = type; // read = type;
begin begin
@ -3826,7 +3821,7 @@ begin
SaveRaiseException(ctsEndForClassNotFound); SaveRaiseException(ctsEndForClassNotFound);
'C': 'C':
if CompareSrcIdentifiers(p,'CONST') if CompareSrcIdentifiers(p,'CONST')
and (BracketLvl=0) then and (BracketLvl>0) then
SaveRaiseException(ctsEndForClassNotFound); SaveRaiseException(ctsEndForClassNotFound);
'I': 'I':
if CompareSrcIdentifiers(p,'INTERFACE') if CompareSrcIdentifiers(p,'INTERFACE')

View File

@ -1105,7 +1105,7 @@ begin
end; end;
end; end;
ctnClassTypePrivate..ctnClassPublished: ctnClassConst..ctnClassPublished:
begin begin
if (cefcUnsortedClassVisibility in ObserverCats) if (cefcUnsortedClassVisibility in ObserverCats)
and (CodeNode.PriorBrother<>nil) and (CodeNode.PriorBrother<>nil)
@ -2222,18 +2222,14 @@ const
Result:=4; Result:=4;
// class sections // class sections
ctnClassTypePrivate, ctnClassConst,
ctnClassTypeProtected, ctnClassType,
ctnClassTypePublic, ctnClassVar,
ctnClassTypePublished, ctnClassClassVar,
ctnClassVarPrivate,
ctnClassVarProtected,
ctnClassVarPublic,
ctnClassVarPublished,
ctnClassPrivate, ctnClassPrivate,
ctnClassProtected, ctnClassProtected,
ctnClassPublic, ctnClassPublic,
ctnClassPublished : Result:=Desc-ctnClassTypePrivate; ctnClassPublished : Result:=Desc-ctnClassConst;
else Result:=10000; else Result:=10000;
end; end;