* give correct error locations for errors when specializing templates

* removed more germanisms
* better dumping of tokenbuf in ppudump

git-svn-id: trunk@5101 -
This commit is contained in:
florian 2006-10-30 23:28:06 +00:00
parent 0c6e1e4c44
commit bce905b106
15 changed files with 149 additions and 89 deletions

View File

@ -218,7 +218,7 @@ interface
RelocSectionSetExplicitly : boolean;
LinkTypeSetExplicitly : boolean;
akttokenpos, { position of the last token }
current_tokenpos, { position of the last token }
current_filepos : tfileposinfo; { current position }
nwscreenname : string;

View File

@ -303,7 +303,7 @@ implementation
oldtoken:=token;
oldidtoken:=idtoken;
old_block_type:=block_type;
oldtokenpos:=akttokenpos;
oldtokenpos:=current_tokenpos;
{ save cg }
oldparse_only:=parse_only;
{ save akt... state }
@ -445,7 +445,7 @@ implementation
orgpattern:=oldorgpattern;
token:=oldtoken;
idtoken:=oldidtoken;
akttokenpos:=oldtokenpos;
current_tokenpos:=oldtokenpos;
block_type:=old_block_type;
{ restore cg }
parse_only:=oldparse_only;

View File

@ -131,7 +131,7 @@ implementation
else
begin
if token=_END then
last_endtoken_filepos:=akttokenpos;
last_endtoken_filepos:=current_tokenpos;
current_scanner.readtoken(true);
end;
end;
@ -144,7 +144,7 @@ implementation
begin
try_to_consume:=true;
if token=_END then
last_endtoken_filepos:=akttokenpos;
last_endtoken_filepos:=current_tokenpos;
current_scanner.readtoken(true);
end;
end;

View File

@ -84,8 +84,8 @@ implementation
internalerror(9584582);
hp:=nil;
p:=comp_expr(true);
storetokenpos:=akttokenpos;
akttokenpos:=filepos;
storetokenpos:=current_tokenpos;
current_tokenpos:=filepos;
case p.nodetype of
ordconstn:
begin
@ -148,7 +148,7 @@ implementation
else
Message(parser_e_illegal_expression);
end;
akttokenpos:=storetokenpos;
current_tokenpos:=storetokenpos;
p.free;
readconstant:=hp;
end;
@ -170,7 +170,7 @@ implementation
block_type:=bt_const;
repeat
orgname:=orgpattern;
filepos:=akttokenpos;
filepos:=current_tokenpos;
consume(_ID);
case token of
@ -201,10 +201,10 @@ implementation
block_type:=bt_const;
skipequal:=false;
{ create symbol }
storetokenpos:=akttokenpos;
akttokenpos:=filepos;
storetokenpos:=current_tokenpos;
current_tokenpos:=filepos;
sym:=ttypedconstsym.create(orgname,hdef,(cs_typed_const_writable in current_settings.localswitches));
akttokenpos:=storetokenpos;
current_tokenpos:=storetokenpos;
symtablestack.top.insert(sym);
{ procvar can have proc directives, but not type references }
if (hdef.deftype=procvardef) and
@ -312,8 +312,8 @@ implementation
begin
{ try to resolve the forward }
{ get the correct position for it }
stpos:=akttokenpos;
akttokenpos:=tforwarddef(hpd).forwardpos;
stpos:=current_tokenpos;
current_tokenpos:=tforwarddef(hpd).forwardpos;
resolving_forward:=true;
make_ref:=false;
if not assigned(tforwarddef(hpd).tosymname) then
@ -321,7 +321,7 @@ implementation
searchsym(tforwarddef(hpd).tosymname^,srsym,srsymtable);
make_ref:=true;
resolving_forward:=false;
akttokenpos:=stpos;
current_tokenpos:=stpos;
{ we don't need the forwarddef anymore, dispose it }
hpd.free;
tabstractpointerdef(pd).pointeddef:=nil; { if error occurs }
@ -407,7 +407,7 @@ implementation
block_type:=bt_type;
typecanbeforward:=true;
repeat
defpos:=akttokenpos;
defpos:=current_tokenpos;
istyperenaming:=false;
generictypelist:=nil;
generictokenbuf:=nil;
@ -477,11 +477,11 @@ implementation
referencing the type before it's really set it
will give an error (PFV) }
hdef:=generrordef;
storetokenpos:=akttokenpos;
storetokenpos:=current_tokenpos;
newtype:=ttypesym.create(orgtypename,hdef);
symtablestack.top.insert(newtype);
akttokenpos:=defpos;
akttokenpos:=storetokenpos;
current_tokenpos:=defpos;
current_tokenpos:=storetokenpos;
{ read the type definition }
read_named_type(hdef,orgtypename,nil,generictypelist,false);
{ update the definition of the type }
@ -666,15 +666,15 @@ implementation
block_type:=bt_const;
repeat
orgname:=orgpattern;
filepos:=akttokenpos;
filepos:=current_tokenpos;
consume(_ID);
case token of
_EQUAL:
begin
consume(_EQUAL);
p:=comp_expr(true);
storetokenpos:=akttokenpos;
akttokenpos:=filepos;
storetokenpos:=current_tokenpos;
current_tokenpos:=filepos;
sym:=nil;
case p.nodetype of
ordconstn:
@ -699,7 +699,7 @@ implementation
else
Message(parser_e_illegal_expression);
end;
akttokenpos:=storetokenpos;
current_tokenpos:=storetokenpos;
{ Support hint directives }
dummysymoptions:=[];
try_consume_hintdirective(dummysymoptions);

View File

@ -96,9 +96,9 @@ implementation
not is_void(pd.returndef) and
paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
begin
storepos:=akttokenpos;
storepos:=current_tokenpos;
if pd.deftype=procdef then
akttokenpos:=tprocdef(pd).fileinfo;
current_tokenpos:=tprocdef(pd).fileinfo;
{ For left to right add it at the end to be delphi compatible }
if pd.proccalloption in (pushleftright_pocalls+[pocall_safecall]) then
@ -112,7 +112,7 @@ implementation
if pd.deftype=procdef then
tprocdef(pd).funcretsym:=vs;
akttokenpos:=storepos;
current_tokenpos:=storepos;
end;
end;
@ -124,9 +124,9 @@ implementation
begin
if pd.parast.symtablelevel>normal_function_level then
begin
storepos:=akttokenpos;
storepos:=current_tokenpos;
if pd.deftype=procdef then
akttokenpos:=tprocdef(pd).fileinfo;
current_tokenpos:=tprocdef(pd).fileinfo;
{ Generate result variable accessing function result, it
can't be put in a register since it must be accessable
@ -135,7 +135,7 @@ implementation
vs.varregable:=vr_none;
pd.parast.insert(vs);
akttokenpos:=storepos;
current_tokenpos:=storepos;
end;
end;
@ -160,8 +160,8 @@ implementation
assigned(tprocdef(pd)._class) and
(pd.parast.symtablelevel=normal_function_level) then
begin
storepos:=akttokenpos;
akttokenpos:=tprocdef(pd).fileinfo;
storepos:=current_tokenpos;
current_tokenpos:=tprocdef(pd).fileinfo;
{ Generate VMT variable for constructor/destructor }
if pd.proctypeoption in [potype_constructor,potype_destructor] then
@ -188,7 +188,7 @@ implementation
vs:=tparavarsym.create('$self',paranr_self,vsp,hdef,[vo_is_self,vo_is_hidden_para]);
pd.parast.insert(vs);
akttokenpos:=storepos;
current_tokenpos:=storepos;
end;
end;
end;
@ -205,8 +205,8 @@ implementation
if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
not is_void(pd.returndef) then
begin
storepos:=akttokenpos;
akttokenpos:=pd.fileinfo;
storepos:=current_tokenpos;
current_tokenpos:=pd.fileinfo;
{ We always need a localsymtable }
if not assigned(pd.localst) then
@ -243,7 +243,7 @@ implementation
tlocalsymtable(pd.localst).insert(aliasvs);
end;
akttokenpos:=storepos;
current_tokenpos:=storepos;
end;
end;
@ -632,7 +632,7 @@ implementation
popclass : boolean;
begin
{ Save the position where this procedure really starts }
procstartfilepos:=akttokenpos;
procstartfilepos:=current_tokenpos;
result:=false;
pd:=nil;
@ -656,8 +656,8 @@ implementation
(aclass.implementedinterfaces.count>0) and
try_to_consume(_POINT) then
begin
storepos:=akttokenpos;
akttokenpos:=procstartfilepos;
storepos:=current_tokenpos;
current_tokenpos:=procstartfilepos;
{ get interface syms}
searchsym(sp,srsym,srsymtable);
if not assigned(srsym) then
@ -665,7 +665,7 @@ implementation
identifier_not_found(orgsp);
srsym:=generrorsym;
end;
akttokenpos:=storepos;
current_tokenpos:=storepos;
{ qualifier is interface? }
if (srsym.typ=typesym) and
(ttypesym(srsym).typedef.deftype=objectdef) then
@ -693,19 +693,19 @@ implementation
try_to_consume(_POINT) then
begin
{ search for object name }
storepos:=akttokenpos;
akttokenpos:=procstartfilepos;
storepos:=current_tokenpos;
current_tokenpos:=procstartfilepos;
searchsym(sp,srsym,srsymtable);
if not assigned(srsym) then
begin
identifier_not_found(orgsp);
srsym:=generrorsym;
end;
akttokenpos:=storepos;
current_tokenpos:=storepos;
{ consume proc name }
sp:=pattern;
orgsp:=orgpattern;
procstartfilepos:=akttokenpos;
procstartfilepos:=current_tokenpos;
consume(_ID);
{ qualifier is class name ? }
if (srsym.typ=typesym) and
@ -748,7 +748,7 @@ implementation
repeat
searchagain:=false;
akttokenpos:=procstartfilepos;
current_tokenpos:=procstartfilepos;
srsymtable:=symtablestack.top;
srsym:=tsym(srsymtable.search(sp));
@ -795,7 +795,7 @@ implementation
if not assigned(aprocsym) then
begin
{ create a new procsym and set the real filepos }
akttokenpos:=procstartfilepos;
current_tokenpos:=procstartfilepos;
{ for operator we have only one procsym for each overloaded
operation }
if (potype=potype_operator) then

View File

@ -1077,7 +1077,7 @@ implementation
membercall : boolean;
callflags : tcallnodeflags;
propaccesslist : tpropaccesslist;
function getpropaccesslist(pap:tpropaccesslisttypes):boolean;
var
hpropsym : tpropertysym;
@ -1896,7 +1896,7 @@ implementation
int_to_4cc(p1)
else
ok := false;
end;
end;
if ok then
begin
p2:=comp_expr(true);
@ -2123,7 +2123,7 @@ implementation
begin
oldp1:=nil;
p1:=nil;
filepos:=akttokenpos;
filepos:=current_tokenpos;
again:=false;
if token=_ID then
begin
@ -2148,7 +2148,7 @@ implementation
if assigned(p1) then
p1.fileinfo:=filepos;
oldp1:=p1;
filepos:=akttokenpos;
filepos:=current_tokenpos;
end;
{ handle post fix operators }
postfixoperators(p1,again);
@ -2610,7 +2610,7 @@ implementation
((token<>_EQUAL) or accept_equal) then
begin
oldt:=token;
filepos:=akttokenpos;
filepos:=current_tokenpos;
consume(token);
if pred_level=highest_precedence then
p2:=factor(false)
@ -2717,7 +2717,7 @@ implementation
{ get the resultdef for this expression }
if not assigned(p1.resultdef) then
do_typecheckpass(p1);
filepos:=akttokenpos;
filepos:=current_tokenpos;
if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
afterassignment:=true;
oldp1:=p1;

View File

@ -145,7 +145,7 @@ implementation
{ function styled new is handled in factor }
{ destructors have no parameters }
destructorname:=pattern;
destructorpos:=akttokenpos;
destructorpos:=current_tokenpos;
consume(_ID);
if (p.resultdef.deftype<>pointerdef) then
@ -179,10 +179,10 @@ implementation
exit;
end;
{ search cons-/destructor, also in parent classes }
storepos:=akttokenpos;
akttokenpos:=destructorpos;
storepos:=current_tokenpos;
current_tokenpos:=destructorpos;
sym:=search_class_member(classh,destructorname);
akttokenpos:=storepos;
current_tokenpos:=storepos;
{ the second parameter of new/dispose must be a call }
{ to a cons-/destructor }

View File

@ -923,7 +923,7 @@ implementation
srsymtable : tsymtable;
s : stringid;
begin
filepos:=akttokenpos;
filepos:=current_tokenpos;
case token of
_GOTO :
begin
@ -1088,7 +1088,7 @@ implementation
begin
first:=nil;
filepos:=akttokenpos;
filepos:=current_tokenpos;
consume(starttoken);
while not(token in [_END,_FINALIZATION]) do
@ -1189,7 +1189,7 @@ implementation
{ because the END is already read we need to get the
last_endtoken_filepos here (PFV) }
last_endtoken_filepos:=akttokenpos;
last_endtoken_filepos:=current_tokenpos;
assembler_block:=p;
end;

View File

@ -1701,7 +1701,7 @@ implementation
internalerror(200512111);
oldcurrent_filepos:=current_filepos;
current_filepos:=tprocdef(tprocdef(hp).genericdef).fileinfo;
akttokenpos:=current_filepos;
current_tokenpos:=current_filepos;
current_scanner.startreplaytokens(tprocdef(tprocdef(hp).genericdef).generictokenbuf);
read_proc_body(nil,tprocdef(hp));
current_filepos:=oldcurrent_filepos;

View File

@ -168,7 +168,7 @@ implementation
begin
s:=pattern;
sorg:=orgpattern;
pos:=akttokenpos;
pos:=current_tokenpos;
{ use of current parsed object:
- classes can be used also in classes
- objects can be parameters }
@ -617,7 +617,7 @@ implementation
aktenumdef:=tenumdef.create;
repeat
s:=orgpattern;
defpos:=akttokenpos;
defpos:=current_tokenpos;
consume(_ID);
{ only allow assigning of specific numbers under fpc mode }
if not(m_tp7 in current_settings.modeswitches) and
@ -659,10 +659,10 @@ implementation
else
inc(l);
first := false;
storepos:=akttokenpos;
akttokenpos:=defpos;
storepos:=current_tokenpos;
current_tokenpos:=defpos;
tstoredsymtable(aktenumdef.owner).insert(tenumsym.create(s,aktenumdef,l));
akttokenpos:=storepos;
current_tokenpos:=storepos;
until not try_to_consume(_COMMA);
def:=aktenumdef;
consume(_RKLAMMER);

View File

@ -67,7 +67,7 @@ interface
tcompile_time_predicate = function(var valuedescr: String) : Boolean;
tspecialgenerictoken = (ST_LOADSETTINGS);
tspecialgenerictoken = (ST_LOADSETTINGS,ST_LINE,ST_COLUMN,ST_FILEINDEX);
tscannerfile = class
public
@ -91,6 +91,9 @@ interface
{ last settings we stored }
last_settings : tsettings;
{ last filepos we stored }
last_filepos : tfileposinfo;
comment_level,
yylexcount : longint;
lastasmgetchar : char;
@ -1829,6 +1832,7 @@ In case not, the value returned can be arbitrary.
internalerror(200511173);
recordtokenbuf:=buf;
fillchar(last_settings,sizeof(last_settings),0);
fillchar(last_filepos,sizeof(last_filepos),0);
end;
@ -1853,6 +1857,30 @@ In case not, the value returned can be arbitrary.
recordtokenbuf.write(current_settings,sizeof(current_settings));
last_settings:=current_settings;
end;
{ file pos changes? }
if current_tokenpos.line<>last_filepos.line then
begin
recordtokenbuf.write(_GENERICSPECIALTOKEN,1);
recordtokenbuf.write(ST_LINE,1);
recordtokenbuf.write(current_tokenpos.line,sizeof(current_tokenpos.line));
last_filepos.line:=current_tokenpos.line;
end;
if current_tokenpos.column<>last_filepos.column then
begin
recordtokenbuf.write(_GENERICSPECIALTOKEN,1);
recordtokenbuf.write(ST_COLUMN,1);
recordtokenbuf.write(current_tokenpos.column,sizeof(current_tokenpos.column));
last_filepos.column:=current_tokenpos.column;
end;
if current_tokenpos.fileindex<>last_filepos.fileindex then
begin
recordtokenbuf.write(_GENERICSPECIALTOKEN,1);
recordtokenbuf.write(ST_FILEINDEX,1);
recordtokenbuf.write(current_tokenpos.fileindex,sizeof(current_tokenpos.fileindex));
last_filepos.fileindex:=current_tokenpos.fileindex;
end;
recordtokenbuf.write(token,1);
if token=_ID then
recordtokenbuf.write(idtoken,1);
@ -1892,8 +1920,6 @@ In case not, the value returned can be arbitrary.
{ install buffer }
replaytokenbuf:=buf;
fillchar(last_settings,sizeof(last_settings),0);
{ reload next token }
replaytokenbuf.seek(0);
replaytoken;
@ -1950,9 +1976,13 @@ In case not, the value returned can be arbitrary.
replaytokenbuf.read(specialtoken,1);
case specialtoken of
ST_LOADSETTINGS:
begin
replaytokenbuf.read(current_settings,sizeof(current_settings));
end
replaytokenbuf.read(current_settings,sizeof(current_settings));
ST_LINE:
replaytokenbuf.read(current_tokenpos.line,sizeof(current_tokenpos.line));
ST_COLUMN:
replaytokenbuf.read(current_tokenpos.column,sizeof(current_tokenpos.column));
ST_FILEINDEX:
replaytokenbuf.read(current_tokenpos.fileindex,sizeof(current_tokenpos.fileindex));
else
internalerror(2006103010);
end;
@ -2082,11 +2112,11 @@ In case not, the value returned can be arbitrary.
{ load the values of tokenpos and lasttokenpos }
begin
lasttokenpos:=inputstart+(inputpointer-inputbuffer);
akttokenpos.line:=line_no;
akttokenpos.column:=lasttokenpos-lastlinepos;
akttokenpos.fileindex:=inputfile.ref_index;
akttokenpos.moduleindex:=current_module.unit_index;
current_filepos:=akttokenpos;
current_tokenpos.line:=line_no;
current_tokenpos.column:=lasttokenpos-lastlinepos;
current_tokenpos.fileindex:=inputfile.ref_index;
current_tokenpos.moduleindex:=current_module.unit_index;
current_filepos:=current_tokenpos;
end;
@ -2149,12 +2179,12 @@ In case not, the value returned can be arbitrary.
{ update for status and call the show status routine,
but don't touch current_filepos ! }
oldcurrent_filepos:=current_filepos;
oldtokenpos:=akttokenpos;
oldtokenpos:=current_tokenpos;
gettokenpos; { update for v_status }
inc(status.compiledlines);
ShowStatus;
current_filepos:=oldcurrent_filepos;
akttokenpos:=oldtokenpos;
current_tokenpos:=oldtokenpos;
end;
end;

View File

@ -2529,10 +2529,10 @@ implementation
begin
if (ado_IsBitPacked in arrayoptions) then
internalerror(2006080101);
if assigned(_elementdef) then
if assigned(_elementdef) then
result:=_elementdef.size
else
result:=0;
result:=0;
end;
@ -2540,10 +2540,10 @@ implementation
begin
if not(ado_IsBitPacked in arrayoptions) then
internalerror(2006080102);
if assigned(_elementdef) then
if assigned(_elementdef) then
result:=_elementdef.packedbitsize
else
result:=0;
result:=0;
end;
@ -3263,7 +3263,7 @@ implementation
refcount:=0;
if (cs_browser in current_settings.moduleswitches) and make_ref then
begin
defref:=tref.create(defref,@akttokenpos);
defref:=tref.create(defref,@current_tokenpos);
inc(refcount);
end;
lastref:=defref;

View File

@ -1640,7 +1640,7 @@ implementation
if (cs_browser in current_settings.moduleswitches) then
begin
newref:=tref.create(sym.lastref,@akttokenpos);
newref:=tref.create(sym.lastref,@current_tokenpos);
{ for symbols that are in tables without browser info or syssyms }
if sym.refcount=0 then
begin

View File

@ -311,10 +311,10 @@ implementation
refs:=0;
lastwritten:=nil;
refcount:=0;
fileinfo:=akttokenpos;
fileinfo:=current_tokenpos;
if (cs_browser in current_settings.moduleswitches) and make_ref then
begin
defref:=tref.create(defref,@akttokenpos);
defref:=tref.create(defref,@current_tokenpos);
inc(refcount);
end;
lastref:=defref;

View File

@ -58,6 +58,9 @@ type
);
tprocinfoflags=set of tprocinfoflag;
{ copied from scanner.pas }
tspecialgenerictoken = (ST_LOADSETTINGS,ST_LINE,ST_COLUMN,ST_FILEINDEX);
{ Copied from systems.pas }
tsystemcpu=
(
@ -873,7 +876,8 @@ begin
write(space,' Tokens: ');
while i<tokenbufsize do
begin
write(arraytokeninfo[ttoken(tokenbuf[i])].str);
if ttoken(tokenbuf[i])<>_GENERICSPECIALTOKEN then
write(arraytokeninfo[ttoken(tokenbuf[i])].str);
case ttoken(tokenbuf[i]) of
_CWCHAR,
_CWSTRING :
@ -901,6 +905,9 @@ begin
_ID :
begin
inc(i);
inc(i);
write(' ',pshortstring(@tokenbuf[i])^);
inc(i,tokenbuf[i]+1);
{
replaytokenbuf.read(orgpattern[0],1);
replaytokenbuf.read(orgpattern[1],length(orgpattern));
@ -910,9 +917,32 @@ begin
_GENERICSPECIALTOKEN:
begin
inc(i);
inc(i);
inc(i,sizeof(tsettings));
case tspecialgenerictoken(tokenbuf[i]) of
ST_LOADSETTINGS:
begin
inc(i);
write('Settings');
inc(i,sizeof(tsettings));
end;
ST_LINE:
begin
inc(i);
write('Line: ',pdword(@tokenbuf[i])^);
inc(i,4);
end;
ST_COLUMN:
begin
inc(i);
write('Col: ',pword(@tokenbuf[i])^);
inc(i,2);
end;
ST_FILEINDEX:
begin
inc(i);
write('File: ',pword(@tokenbuf[i])^);
inc(i,2);
end;
end;
{
replaytokenbuf.read(specialtoken,1);
case specialtoken of