codetools: added class sections for objcprotocol: required, optional

git-svn-id: trunk@33701 -
This commit is contained in:
mattias 2011-11-22 21:46:09 +00:00
parent 0380dd7344
commit 8936771e6d
3 changed files with 49 additions and 27 deletions

View File

@ -102,8 +102,10 @@ const
ctnClassProtected = 47;
ctnClassPublic = 48;
ctnClassPublished = 49;
ctnProperty = 50; // child of visibility section or AllClassInterfaces
ctnMethodMap = 51; // child of visibility section or AllClassInterfaces
ctnClassRequired = 50;
ctnClassOptional = 51;
ctnProperty = 52; // child of visibility section or AllClassInterfaces
ctnMethodMap = 53; // child of visibility section or AllClassInterfaces
ctnProcedure = 60; // children: ctnProcedureHead, sections, ctnBeginBlock/ctnAsmBlock
ctnProcedureHead = 61; // children: ctnParameterList, operator: ctnVarDefinition, operator/function: ctnIdentifier
@ -154,7 +156,8 @@ const
AllCodeSections = AllSourceTypes
+ [ctnInterface, ctnImplementation, ctnInitialization, ctnFinalization];
AllClassBaseSections =
[ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected];
[ctnClassPublic,ctnClassPublished,ctnClassPrivate,ctnClassProtected,
ctnClassRequired,ctnClassOptional];
AllClassSubSections =
[ctnConstSection, ctnTypeSection, ctnVarSection, ctnClassClassVar];
AllClassSections =
@ -348,10 +351,12 @@ begin
ctnClassInheritance: Result:='Class inheritance';
ctnClassGUID: Result:='GUID';
ctnClassPublished: Result:='Published';
ctnClassPrivate: Result:='Private';
ctnClassProtected: Result:='Protected';
ctnClassPublic: Result:='Public';
ctnClassPublished: Result:='Published';
ctnClassRequired: Result:='Required section';
ctnClassOptional: Result:='Optional section';
ctnClassClassVar: Result:='Class Var';
ctnClassAbstract: Result:='abstract';
ctnClassSealed: Result:='sealed';

View File

@ -1655,6 +1655,11 @@ begin
Add('procedure');
Add('function');
Add('property');
if [cmsObjectiveC1,cmsObjectiveC2]*Scanner.CompilerModeSwitches<>[] then
begin
Add('required');
Add('optional');
end;
if (Node.Desc=ctnClass) or (Node.Parent.Desc=ctnClass) then begin
Add('constructor');
Add('destructor');

View File

@ -461,11 +461,15 @@ begin
'S': if CompareSrcIdentifiers(p,'PUBLISHED') then exit(KeyWordFuncClassSection);
end;
end;
'R':
if CompareSrcIdentifiers(p,'REQUIRED') then exit(KeyWordFuncClassSection);
'S':
if CompareSrcIdentifiers(p,'STATIC') then exit(KeyWordFuncClassMethod)
else if CompareSrcIdentifiers(p,'STRICT') then exit(KeyWordFuncClassSection);
'T':
if CompareSrcIdentifiers(p,'TYPE') then exit(KeyWordFuncClassTypeSection);
'O':
if CompareSrcIdentifiers(p,'OPTIONAL') then exit(KeyWordFuncClassSection);
'V':
if CompareSrcIdentifiers(p,'VAR') then exit(KeyWordFuncClassVarSection);
'(','[':
@ -947,33 +951,46 @@ begin
end;
function TPascalParserTool.KeyWordFuncClassSection: boolean;
// change section in a class (public, private, protected, published)
// change section in a class (public, private, protected, published, optional, required)
var
OldSubSection: TCodeTreeNodeDesc;
NewSubSection: TCodeTreeNodeDesc;
SectionStart: Integer;
begin
SectionStart:=CurPos.StartPos;
NewSubSection:=ctnNone;
if UpAtomIs('STRICT') then ReadNextAtom;
if UpAtomIs('PUBLIC') then
NewSubSection:=ctnClassPublic
else if UpAtomIs('PRIVATE') then
NewSubSection:=ctnClassPrivate
else if UpAtomIs('PROTECTED') then
NewSubSection:=ctnClassProtected
else if UpAtomIs('PUBLISHED') then
NewSubSection:=ctnClassPublished
else if UpAtomIs('REQUIRED') then begin
if [cmsObjectiveC1,cmsObjectiveC2]*Scanner.CompilerModeSwitches=[] then
exit(false);
NewSubSection:=ctnClassRequired;
end else if UpAtomIs('OPTIONAL') then begin
if [cmsObjectiveC1,cmsObjectiveC2]*Scanner.CompilerModeSwitches=[] then
exit(false);
NewSubSection:=ctnClassOptional;
end else
RaiseStringExpectedButAtomFound('public');
OldSubSection:=ctnNone;
if CurNode.Desc in AllClassSubSections then begin
// end sub section
OldSubSection:=CurNode.Desc;
CurNode.EndPos:=CurPos.StartPos;
CurNode.EndPos:=SectionStart;
EndChildNode;
end;
// end last visibility section
CurNode.EndPos:=CurPos.StartPos;
CurNode.EndPos:=SectionStart;
EndChildNode;
// start new section
CreateChildNode;
if UpAtomIs('STRICT') then ReadNextAtom;
if UpAtomIs('PUBLIC') then
CurNode.Desc:=ctnClassPublic
else if UpAtomIs('PRIVATE') then
CurNode.Desc:=ctnClassPrivate
else if UpAtomIs('PROTECTED') then
CurNode.Desc:=ctnClassProtected
else if UpAtomIs('PUBLISHED') then
CurNode.Desc:=ctnClassPublished
else
RaiseStringExpectedButAtomFound('public');
CurNode.Desc:=NewSubSection;
if (OldSubSection<>ctnNone)
and (Scanner.CompilerMode=cmOBJFPC)
and (Scanner.Values.IsDefined('VER2_4')) then begin
@ -3877,10 +3894,12 @@ begin
end;
end;
end else begin
// start the first class section (always published/public)
// start the first class section (the one without a keyword)
CreateChildNode;
if ClassDesc = ctnClass then
if ClassDesc=ctnClass then
CurNode.Desc:=ctnClassPublished
else if ClassDesc=ctnObjCProtocol then
CurNode.Desc:=ctnClassRequired
else
CurNode.Desc:=ctnClassPublic;
CurNode.StartPos:=LastAtoms.GetValueAt(0).EndPos;
@ -3985,13 +4004,6 @@ begin
// parse till "end" of interface
repeat
// ObjCProtocol can have 'OPTIONAL' and 'REQUIRED' sections
if (IntfDesc=ctnObjCProtocol) and (CurPos.Flag=cafWord) then begin
if UpAtomIs('OPTIONAL') then
ReadNextAtom
else
if UpAtomIs('REQUIRED') then
ReadNextAtom;
end;
if not ParseInnerClass(CurPos.StartPos,CurPos.EndPos-CurPos.StartPos) then
begin
if CurPos.Flag<>cafEnd then