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

View File

@ -1655,6 +1655,11 @@ begin
Add('procedure'); Add('procedure');
Add('function'); Add('function');
Add('property'); 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 if (Node.Desc=ctnClass) or (Node.Parent.Desc=ctnClass) then begin
Add('constructor'); Add('constructor');
Add('destructor'); Add('destructor');

View File

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