mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 04:39:28 +02:00
Added a check similar to the "allowed" one to be able to remove the "current_syssym" variable again.
* nld.pas: - added "helperallowed" boolean field to ttypenode which is set to false by default - check that field in ttypenode.pass_1 and generate an error if it's false * ncal.pas: check the "helperallowed" field if the methodpointer node is a typenode and contains a helper; this is needed, because pass_1 of ttypenode is never called in case of "TSomeHelper.SomeMethod" * pexpr.pas: - allow helpers in "sizeof" and "typeinfo" - remove the check against "TSomeHelper.SomeMethod", but leave an explaining comment there git-svn-id: branches/svenbarth/classhelpers@17308 -
This commit is contained in:
parent
798cc01ffe
commit
24243f87e8
@ -3238,6 +3238,14 @@ implementation
|
||||
begin
|
||||
result:=nil;
|
||||
|
||||
{ as pass_1 is never called on the methodpointer node, we must check
|
||||
here that it's not a helper type }
|
||||
if assigned(methodpointer) and
|
||||
(methodpointer.nodetype=typen) and
|
||||
is_objectpascal_helper(ttypenode(methodpointer).typedef) and
|
||||
not ttypenode(methodpointer).helperallowed then
|
||||
Message(parser_e_no_category_as_types);
|
||||
|
||||
{ convert Objective-C calls into a message call }
|
||||
if (procdefinition.typ=procdef) and
|
||||
(po_objc in tprocdef(procdefinition).procoptions) then
|
||||
|
@ -101,6 +101,7 @@ interface
|
||||
|
||||
ttypenode = class(tnode)
|
||||
allowed : boolean;
|
||||
helperallowed : boolean;
|
||||
typedef : tdef;
|
||||
typedefderef : tderef;
|
||||
constructor create(def:tdef);virtual;
|
||||
@ -1034,6 +1035,7 @@ implementation
|
||||
inherited create(typen);
|
||||
typedef:=def;
|
||||
allowed:=false;
|
||||
helperallowed:=false;
|
||||
end;
|
||||
|
||||
|
||||
@ -1042,6 +1044,7 @@ implementation
|
||||
inherited ppuload(t,ppufile);
|
||||
ppufile.getderef(typedefderef);
|
||||
allowed:=boolean(ppufile.getbyte);
|
||||
helperallowed:=boolean(ppufile.getbyte);
|
||||
end;
|
||||
|
||||
|
||||
@ -1050,6 +1053,7 @@ implementation
|
||||
inherited ppuwrite(ppufile);
|
||||
ppufile.putderef(typedefderef);
|
||||
ppufile.putbyte(byte(allowed));
|
||||
ppufile.putbyte(byte(helperallowed));
|
||||
end;
|
||||
|
||||
|
||||
@ -1087,6 +1091,8 @@ implementation
|
||||
an error }
|
||||
if not allowed then
|
||||
Message(parser_e_no_type_not_allowed_here);
|
||||
if not helperallowed then
|
||||
Message(parser_e_no_category_as_types);
|
||||
end;
|
||||
|
||||
|
||||
@ -1097,6 +1103,7 @@ implementation
|
||||
n:=ttypenode(inherited dogetcopy);
|
||||
n.allowed:=allowed;
|
||||
n.typedef:=typedef;
|
||||
n.helperallowed:=helperallowed;
|
||||
result:=n;
|
||||
end;
|
||||
|
||||
|
@ -407,6 +407,9 @@ implementation
|
||||
end
|
||||
else
|
||||
begin
|
||||
{ allow helpers for SizeOf and BitSizeOf }
|
||||
if p1.nodetype=typen then
|
||||
ttypenode(p1).helperallowed:=true;
|
||||
if (p1.resultdef.typ=forwarddef) then
|
||||
Message1(type_e_type_is_not_completly_defined,tforwarddef(p1.resultdef).tosymname^);
|
||||
if (l = in_sizeof_x) or
|
||||
@ -445,7 +448,12 @@ implementation
|
||||
p1:=p2;
|
||||
end;
|
||||
if p1.nodetype=typen then
|
||||
begin
|
||||
ttypenode(p1).allowed:=true;
|
||||
{ allow helpers for TypeInfo }
|
||||
if l=in_typeinfo_x then
|
||||
ttypenode(p1).helperallowed:=true;
|
||||
end;
|
||||
{ else
|
||||
begin
|
||||
p1.destroy;
|
||||
@ -1539,15 +1547,12 @@ implementation
|
||||
end
|
||||
else
|
||||
begin
|
||||
{ TClassHelper.Something is not allowed, but
|
||||
TypeInfo(TClassHelper) and SizeOf(TClassHelper) is }
|
||||
if is_objectpascal_helper(hdef) and
|
||||
not (current_syssym in [in_typeinfo_x,in_sizeof_x,in_bitsizeof_x]) then
|
||||
begin
|
||||
Message(parser_e_no_category_as_types);
|
||||
{ for recovery we use the extended class }
|
||||
hdef:=tobjectdef(hdef).extendeddef;
|
||||
end;
|
||||
{ Normally here would be the check against the usage
|
||||
of "TClassHelper.Something", but as that might be
|
||||
used inside of system symbols like sizeof and
|
||||
typeinfo this check is put into ttypenode.pass_1
|
||||
(for "TClassHelper" alone) and tcallnode.pass_1
|
||||
(for "TClassHelper.Something") }
|
||||
{ class reference ? }
|
||||
if is_class(hdef) or
|
||||
is_objcclass(hdef) then
|
||||
|
Loading…
Reference in New Issue
Block a user