From 8936771e6d92d7eae9533a847b8ccbc827a2d26b Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 22 Nov 2011 21:46:09 +0000 Subject: [PATCH] codetools: added class sections for objcprotocol: required, optional git-svn-id: trunk@33701 - --- components/codetools/codetree.pas | 13 +++-- components/codetools/identcompletiontool.pas | 5 ++ components/codetools/pascalparsertool.pas | 58 ++++++++++++-------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/components/codetools/codetree.pas b/components/codetools/codetree.pas index 0dc965023c..ee92646b94 100644 --- a/components/codetools/codetree.pas +++ b/components/codetools/codetree.pas @@ -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'; diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index bcd844fad6..ebf7c8d7d5 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -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'); diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 7b3b6137a0..5ca76085c9 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -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