implemented global property sections

git-svn-id: trunk@4968 -
This commit is contained in:
mattias 2003-12-27 01:04:29 +00:00
parent 571574438c
commit bf0d3c590f
4 changed files with 119 additions and 50 deletions

View File

@ -67,11 +67,13 @@ const
ctnConstSection = 12; ctnConstSection = 12;
ctnResStrSection = 13; ctnResStrSection = 13;
ctnLabelSection = 14; ctnLabelSection = 14;
ctnUsesSection = 15; ctnPropertySection = 15;
ctnUsesSection = 16;
ctnTypeDefinition = 20; ctnTypeDefinition = 20;
ctnVarDefinition = 21; ctnVarDefinition = 21;
ctnConstDefinition = 22; ctnConstDefinition = 22;
ctnGlobalProperty = 23;
ctnClass = 30; ctnClass = 30;
ctnClassInterface = 31; ctnClassInterface = 31;
@ -308,11 +310,13 @@ begin
ctnVarSection: Result:='Var Section'; ctnVarSection: Result:='Var Section';
ctnConstSection: Result:='Const Section'; ctnConstSection: Result:='Const Section';
ctnResStrSection: Result:='Resource String Section'; ctnResStrSection: Result:='Resource String Section';
ctnPropertySection: Result:='Property Section';
ctnUsesSection: Result:='Uses Section'; ctnUsesSection: Result:='Uses Section';
ctnTypeDefinition: Result:='Type'; ctnTypeDefinition: Result:='Type';
ctnVarDefinition: Result:='Var'; ctnVarDefinition: Result:='Var';
ctnConstDefinition: Result:='Const'; ctnConstDefinition: Result:='Const';
ctnGlobalProperty: Result:='Global Property';
ctnProperty: Result:='Property'; ctnProperty: Result:='Property';
ctnMethodMap: Result:='Method Map'; ctnMethodMap: Result:='Method Map';

View File

@ -922,8 +922,10 @@ var CleanCursorPos: integer;
procedure CheckIfCursorInPropertyNode; procedure CheckIfCursorInPropertyNode;
begin begin
if SkipChecks then exit; if SkipChecks then exit;
if CursorNode.Desc=ctnProperty then begin if (CursorNode.Desc=ctnProperty) or (CursorNode.Desc=ctnGlobalProperty) then
begin
MoveCursorToNodeStart(CursorNode); MoveCursorToNodeStart(CursorNode);
if (CursorNode.Desc=ctnProperty) then
ReadNextAtom; // read 'property' ReadNextAtom; // read 'property'
ReadNextAtom; // read property name ReadNextAtom; // read property name
if CleanCursorPos<CurPos.EndPos then begin if CleanCursorPos<CurPos.EndPos then begin
@ -1485,6 +1487,21 @@ begin
Result:=Result+NewTool.GetAtom+' '; Result:=Result+NewTool.GetAtom+' ';
IdentAdded:=true; IdentAdded:=true;
end; end;
ctnGlobalProperty:
begin
IdentNode:=NewNode;
// ToDo: ppu, ppw, dcu files
NewTool.MoveCursorToNodeStart(IdentNode);
Result:=Result+'property ';
NewTool.ReadNextAtom;
Result:=Result+NewTool.GetAtom+' ';
IdentAdded:=true;
end;
else else
writeln('ToDo: TFindDeclarationTool.FindSmartHint ',NewNode.DescAsString); writeln('ToDo: TFindDeclarationTool.FindSmartHint ',NewNode.DescAsString);
end; end;
@ -1853,7 +1870,7 @@ var
end; end;
end; end;
function SearchInTypeVarConstDefinition: boolean; function SearchInTypeVarConstPropDefinition: boolean;
// returns: true if ok to exit // returns: true if ok to exit
// false if search should continue // false if search should continue
begin begin
@ -1908,6 +1925,7 @@ var
if (fdfCollect in Params.Flags) if (fdfCollect in Params.Flags)
or (Params.Identifier[0]<>'[') then begin or (Params.Identifier[0]<>'[') then begin
MoveCursorToNodeStart(ContextNode); MoveCursorToNodeStart(ContextNode);
if (ContextNode.Desc=ctnProperty) then
ReadNextAtom; // read keyword 'property' ReadNextAtom; // read keyword 'property'
ReadNextAtom; // read name ReadNextAtom; // read name
if (fdfCollect in Params.Flags) if (fdfCollect in Params.Flags)
@ -2045,7 +2063,7 @@ var
case ContextNode.Desc of case ContextNode.Desc of
ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection, ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection,
ctnLabelSection, ctnLabelSection, ctnPropertySection,
ctnInterface, ctnImplementation, ctnInterface, ctnImplementation,
ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate, ctnClassPublished,ctnClassPublic,ctnClassProtected,ctnClassPrivate,
ctnRecordVariant, ctnRecordVariant,
@ -2149,7 +2167,7 @@ begin
case ContextNode.Desc of case ContextNode.Desc of
ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection, ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection,
ctnLabelSection, ctnLabelSection, ctnPropertySection,
ctnInterface, ctnImplementation, ctnInterface, ctnImplementation,
ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished, ctnClassPublic, ctnClassPrivate, ctnClassProtected, ctnClassPublished,
ctnClass, ctnClassInterface, ctnClass, ctnClassInterface,
@ -2160,8 +2178,9 @@ begin
// -> search in all childs // -> search in all childs
MoveContextNodeToChilds; MoveContextNodeToChilds;
ctnTypeDefinition, ctnVarDefinition, ctnConstDefinition: ctnTypeDefinition, ctnVarDefinition, ctnConstDefinition,
if SearchInTypeVarConstDefinition then exit; ctnGlobalProperty:
if SearchInTypeVarConstPropDefinition then exit;
ctnProcedure: ctnProcedure:
begin begin
@ -2542,9 +2561,11 @@ begin
Params.Load(OldInput); Params.Load(OldInput);
exit; exit;
end else end else
if (Result.Node.Desc=ctnProperty) then begin if (Result.Node.Desc=ctnProperty)
or (Result.Node.Desc=ctnGlobalProperty) then begin
// this is a property -> search the type definition of the property // this is a property -> search the type definition of the property
MoveCursorToNodeStart(Result.Node); MoveCursorToNodeStart(Result.Node);
if (Result.Node.Desc=ctnProperty) then
ReadNextAtom; // read 'property' ReadNextAtom; // read 'property'
ReadNextAtom; // read name ReadNextAtom; // read name
ReadNextAtom; ReadNextAtom;
@ -2583,7 +2604,7 @@ begin
Result:=CreateFindContext(Self,Result.Node); Result:=CreateFindContext(Self,Result.Node);
Params.Load(OldInput); Params.Load(OldInput);
exit; exit;
end else begin end else if (Result.Node.Desc=ctnProperty) then begin
// property has no type // property has no type
// -> search ancestor property // -> search ancestor property
Params.Save(OldInput); Params.Save(OldInput);
@ -3888,6 +3909,9 @@ var
// find base type // find base type
Exclude(Params.Flags,fdfFunctionResult); Exclude(Params.Flags,fdfFunctionResult);
{$IFDEF ShowExprEval}
writeln('ResolveBaseTypeOfIdentifier ExprType=',ExprTypeToString(ExprType));
{$ENDIF}
ExprType:=ExprType.Context.Tool.ConvertNodeToExpressionType( ExprType:=ExprType.Context.Tool.ConvertNodeToExpressionType(
ExprType.Context.Node,Params); ExprType.Context.Node,Params);
if (ExprType.Desc=xtContext) if (ExprType.Desc=xtContext)
@ -3987,6 +4011,9 @@ var
// search ... // search ...
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],@CheckSrcIdentifier); Params.SetIdentifier(Self,@Src[CurAtom.StartPos],@CheckSrcIdentifier);
{$IFDEF ShowExprEval}
writeln('ResolveIdentifier Ident="',GetIdentifier(Params.Identifier),'"');
{$ENDIF}
if ExprType.Context.Tool.FindIdentifierInContext(Params) then begin if ExprType.Context.Tool.FindIdentifierInContext(Params) then begin
if not Params.NewCodeTool.NodeIsConstructor(Params.NewNode) then begin if not Params.NewCodeTool.NodeIsConstructor(Params.NewNode) then begin
ExprType.Desc:=xtContext; ExprType.Desc:=xtContext;
@ -4149,7 +4176,7 @@ var
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params, ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node.FirstChild); ExprType.Context.Node.FirstChild);
ctnClass, ctnProperty: ctnClass, ctnProperty, ctnGlobalProperty:
begin begin
if ExprType.Context.Node.Desc=ctnClass then begin if ExprType.Context.Node.Desc=ctnClass then begin
// search default property of the class // search default property of the class
@ -4317,7 +4344,8 @@ begin
repeat repeat
{$IFDEF ShowExprEval} {$IFDEF ShowExprEval}
writeln(' FindExpressionTypeOfVariable CurAtomType=', writeln(' FindExpressionTypeOfVariable CurAtomType=',
VariableAtomTypeNames[CurAtomType],' CurAtom="',GetAtom(CurAtom),'"'); VariableAtomTypeNames[CurAtomType],' CurAtom="',GetAtom(CurAtom),'"',
' ExprType=',ExprTypeToString(ExprType));
{$ENDIF} {$ENDIF}
case CurAtomType of case CurAtomType of
vatIdentifier, vatPreDefIdentifier: ResolveIdentifier; vatIdentifier, vatPreDefIdentifier: ResolveIdentifier;
@ -4418,7 +4446,8 @@ begin
MoveCursorToNodeStart(Node); MoveCursorToNodeStart(Node);
ReadNextAtom; ReadNextAtom;
ConvertIdentifierAtCursor; ConvertIdentifierAtCursor;
end else if Node.Desc=ctnProperty then begin end else if (Node.Desc=ctnProperty) or (Node.Desc=ctnGlobalProperty) then
begin
// ToDo: ppu, ppw, dcu files // ToDo: ppu, ppw, dcu files
@ -6024,7 +6053,7 @@ begin
Result:=GetIdentifier( Result:=GetIdentifier(
@FindContext.Tool.Src[FindContext.Node.Parent.StartPos]); @FindContext.Tool.Src[FindContext.Node.Parent.StartPos]);
ctnProperty: ctnProperty,ctnGlobalProperty:
begin begin
FindContext.Tool.MoveCursorToPropType(FindContext.Node); FindContext.Tool.MoveCursorToPropType(FindContext.Node);
Result:=FindContext.Tool.GetAtom; Result:=FindContext.Tool.GetAtom;

View File

@ -130,7 +130,7 @@ type
function KeyWordFuncConst: boolean; function KeyWordFuncConst: boolean;
function KeyWordFuncResourceString: boolean; function KeyWordFuncResourceString: boolean;
function KeyWordFuncLabel: boolean; function KeyWordFuncLabel: boolean;
function KeyWordFuncGlobalProperty: boolean; function KeyWordFuncProperty: boolean;
// types // types
function KeyWordFuncClass: boolean; function KeyWordFuncClass: boolean;
function KeyWordFuncClassInterface: boolean; function KeyWordFuncClassInterface: boolean;
@ -327,7 +327,7 @@ begin
Add('CONST',@KeyWordFuncConst); Add('CONST',@KeyWordFuncConst);
Add('RESOURCESTRING',@KeyWordFuncResourceString); Add('RESOURCESTRING',@KeyWordFuncResourceString);
Add('LABEL',@KeyWordFuncLabel); Add('LABEL',@KeyWordFuncLabel);
Add('PROPERTY',@KeyWordFuncGlobalProperty); Add('PROPERTY',@KeyWordFuncProperty);
Add('PROCEDURE',@KeyWordFuncProc); Add('PROCEDURE',@KeyWordFuncProc);
Add('FUNCTION',@KeyWordFuncProc); Add('FUNCTION',@KeyWordFuncProc);
@ -2528,18 +2528,25 @@ begin
Result:=true; Result:=true;
end; end;
function TPascalParserTool.KeyWordFuncGlobalProperty: boolean; function TPascalParserTool.KeyWordFuncProperty: boolean;
{ {
examples: examples:
property errno : cint read fpgeterrno write fpseterrno; property
errno : cint read fpgeterrno write fpseterrno;
A2 : Integer Read GetA2 Write SetA2;
} }
begin begin
// create class method node if not (CurSection in [ctnProgram,ctnInterface,ctnImplementation]) then
RaiseUnexpectedKeyWord;
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnProperty; CurNode.Desc:=ctnPropertySection;
// read all global properties
repeat
// read property Name // read property Name
ReadNextAtom; ReadNextAtom;
AtomIsIdentifier(true); if AtomIsIdentifier(false) then begin
CreateChildNode;
CurNode.Desc:=ctnGlobalProperty;
ReadNextAtom; ReadNextAtom;
if CurPos.Flag=cafEdgedBracketOpen then begin if CurPos.Flag=cafEdgedBracketOpen then begin
// read parameter list // read parameter list
@ -2548,7 +2555,15 @@ begin
end; end;
while (CurPos.StartPos<=SrcLen) and (CurPos.Flag<>cafSemicolon) do while (CurPos.StartPos<=SrcLen) and (CurPos.Flag<>cafSemicolon) do
ReadNextAtom; ReadNextAtom;
// close property // close global property
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
end else begin
UndoReadNextAtom;
break;
end;
until CurPos.StartPos>SrcLen;
// close property section
CurNode.EndPos:=CurPos.EndPos; CurNode.EndPos:=CurPos.EndPos;
EndChildNode; EndChildNode;
Result:=true; Result:=true;

View File

@ -230,11 +230,15 @@ function TPascalReaderTool.ExtractPropType(PropNode: TCodeTreeNode;
InUpperCase, EmptyIfIndexed: boolean): string; InUpperCase, EmptyIfIndexed: boolean): string;
begin begin
Result:=''; Result:='';
if (PropNode=nil) or (PropNode.Desc<>ctnProperty) then exit; if (PropNode=nil)
or ((PropNode.Desc<>ctnProperty) and (PropNode.Desc<>ctnGlobalProperty)) then
exit;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
ReadNextAtom; ReadNextAtom;
if not UpAtomIs('PROPERTY') then exit; if (PropNode.Desc=ctnProperty) then begin
if (not UpAtomIs('PROPERTY')) then exit;
ReadNextAtom; ReadNextAtom;
end;
AtomIsIdentifier(true); AtomIsIdentifier(true);
ReadNextAtom; ReadNextAtom;
if CurPos.Flag=cafEdgedBracketOpen then begin if CurPos.Flag=cafEdgedBracketOpen then begin
@ -612,11 +616,15 @@ function TPascalReaderTool.MoveCursorToPropType(PropNode: TCodeTreeNode
): boolean; ): boolean;
begin begin
Result:=false; Result:=false;
if (PropNode=nil) or (PropNode.Desc<>ctnProperty) then exit; if (PropNode=nil)
or ((PropNode.Desc<>ctnProperty) and (PropNode.Desc<>ctnGlobalProperty)) then
exit;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
ReadNextAtom; ReadNextAtom;
if not UpAtomIs('PROPERTY') then exit; if (PropNode.Desc=ctnProperty) then begin
if (not UpAtomIs('PROPERTY')) then exit;
ReadNextAtom; ReadNextAtom;
end;
AtomIsIdentifier(true); AtomIsIdentifier(true);
ReadNextAtom; ReadNextAtom;
if CurPos.Flag=cafEdgedBracketOpen then begin if CurPos.Flag=cafEdgedBracketOpen then begin
@ -697,11 +705,15 @@ function TPascalReaderTool.ExtractPropName(PropNode: TCodeTreeNode;
InUpperCase: boolean): string; InUpperCase: boolean): string;
begin begin
Result:=''; Result:='';
if (PropNode=nil) or (PropNode.Desc<>ctnProperty) then exit; if (PropNode=nil)
or ((PropNode.Desc<>ctnProperty) and (PropNode.Desc<>ctnGlobalProperty)) then
exit;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
ReadNextAtom; ReadNextAtom;
if not UpAtomIs('PROPERTY') then exit; if (PropNode.Desc=ctnProperty) then begin
if (not UpAtomIs('PROPERTY')) then exit;
ReadNextAtom; ReadNextAtom;
end;
AtomIsIdentifier(true); AtomIsIdentifier(true);
if InUpperCase then if InUpperCase then
Result:=GetUpAtom Result:=GetUpAtom
@ -714,14 +726,17 @@ function TPascalReaderTool.ExtractProperty(PropNode: TCodeTreeNode;
begin begin
Result:=''; Result:='';
ExtractProcHeadPos:=phepNone; ExtractProcHeadPos:=phepNone;
if (PropNode=nil) or (PropNode.StartPos<1) or (PropNode.Desc<>ctnProperty) if (PropNode=nil) or (PropNode.StartPos<1)
then exit; or ((PropNode.Desc<>ctnProperty) and (PropNode.Desc<>ctnGlobalProperty)) then
exit;
// start extraction // start extraction
InitExtraction; InitExtraction;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
ExtractNextAtom(false,Attr); ExtractNextAtom(false,Attr);
if (PropNode.Desc=ctnProperty) then begin
// parse 'property' // parse 'property'
ExtractNextAtom(phpWithStart in Attr,Attr); ExtractNextAtom(phpWithStart in Attr,Attr);
end;
ExtractProcHeadPos:=phepStart; ExtractProcHeadPos:=phepStart;
// parse name // parse name
ExtractNextAtom(not (phpWithoutName in Attr),Attr); ExtractNextAtom(not (phpWithoutName in Attr),Attr);
@ -751,7 +766,9 @@ begin
Result:=nil; Result:=nil;
if PropNode=nil then exit; if PropNode=nil then exit;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
if (PropNode.Desc=ctnProperty) then begin
ReadNextAtom; // read 'propery' ReadNextAtom; // read 'propery'
end;
ReadNextAtom; // read name ReadNextAtom; // read name
Result:=@Src[CurPos.StartPos]; Result:=@Src[CurPos.StartPos];
end; end;
@ -1225,7 +1242,9 @@ begin
Result:=false; Result:=false;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
if (PropNode.Desc=ctnProperty) then begin
ReadNextAtom; // read 'property' ReadNextAtom; // read 'property'
end;
ReadNextAtom; // read name ReadNextAtom; // read name
ReadNextAtom; ReadNextAtom;
Result:=(CurPos.Flag=cafEdgedBracketOpen); Result:=(CurPos.Flag=cafEdgedBracketOpen);
@ -1239,7 +1258,9 @@ begin
Result:=false; Result:=false;
MoveCursorToNodeStart(PropNode); MoveCursorToNodeStart(PropNode);
if (PropNode.Desc=ctnProperty) then begin
ReadNextAtom; // read 'property' ReadNextAtom; // read 'property'
end;
ReadNextAtom; // read name ReadNextAtom; // read name
ReadNextAtom; ReadNextAtom;
if CurPos.Flag=cafEdgedBracketOpen then begin if CurPos.Flag=cafEdgedBracketOpen then begin