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

View File

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

View File

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

View File

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