3566 ! |
3566 ! |
3567 |
3567 |
3568 warnUnused:aNameCollection |
3568 warnUnused:aNameCollection |
3569 "report an unused method variable" |
3569 "report an unused method variable" |
3570 |
3570 |
3571 |s msg answer| |
3571 |msg answer| |
3572 |
3572 |
3573 (ignoreErrors not |
3573 (ignoreErrors not |
3574 and:[ignoreWarnings not |
3574 and:[ignoreWarnings not |
3575 and:[parserFlags warnUnusedVars]]) ifTrue:[ |
3575 and:[parserFlags warnUnusedVars]]) ifTrue:[ |
3576 s := '' writeStream. |
3576 msg := 'Unused method variable(s): '. |
3577 s nextPutAll:'Unused method variable(s): '. |
|
3578 aNameCollection asSortedCollection do:[:name| |
3577 aNameCollection asSortedCollection do:[:name| |
3579 s nextPutAll:' '; nextPutAll:name allBold. |
3578 msg := msg , (' "',name allBold,'"'). |
3580 ]. |
3579 ]. |
3581 msg := s contents. |
|
3582 |
3580 |
3583 (requestor isNil or:[requestor isStream]) ifTrue:[ |
3581 (requestor isNil or:[requestor isStream]) ifTrue:[ |
3584 self showErrorMessage:('Warning: ', msg) position:nil. |
3582 self showErrorMessage:('Warning: ', msg) position:nil. |
3585 ] ifFalse:[ |
3583 ] ifFalse:[ |
3586 answer := requestor |
3584 answer := requestor |
4008 |what| |
4006 |what| |
4009 |
4007 |
4010 (tokenType ~~ #EOF) ifTrue:[ |
4008 (tokenType ~~ #EOF) ifTrue:[ |
4011 "/ just for the nicer error message |
4009 "/ just for the nicer error message |
4012 (#(Self Nil True False Super Here) includes:tokenType) ifTrue:[ |
4010 (#(Self Nil True False Super Here) includes:tokenType) ifTrue:[ |
4013 self parseError:tokenName , ' unexpected (missing ''.'' or '':'' before ' , tokenName , ' ?)' |
4011 self parseError:'"',tokenName allBold,'" unexpected (missing ''.'' or '':'' before ' , tokenName , ' ?)' |
4014 position:tokenPosition to:(tokenPosition + tokenName size - 1) |
4012 position:tokenPosition to:(tokenPosition + tokenName size - 1) |
4015 ] ifFalse:[ |
4013 ] ifFalse:[ |
4016 tokenType isCharacter ifTrue:[ |
4014 tokenType isCharacter ifTrue:[ |
4017 what := '''' , tokenType , ''''. |
4015 what := '''' , tokenType , ''''. |
4018 ] ifFalse:[ |
4016 ] ifFalse:[ |
4270 ]. |
4268 ]. |
4271 |
4269 |
4272 (tokenType == $|) ifTrue:[ |
4270 (tokenType == $|) ifTrue:[ |
4273 "memorize position for declaration in correction" |
4271 "memorize position for declaration in correction" |
4274 |
4272 |
4275 localVarDefPosition := tokenPosition. |
4273 localVarDefPosition := Array with:tokenPosition with:nil. |
4276 self nextToken. |
4274 self nextToken. |
4277 pos := tokenPosition. |
4275 pos := tokenPosition. |
4278 [tokenType == #Identifier] whileTrue:[ |
4276 [tokenType == #Identifier] whileTrue:[ |
4279 pos2 := tokenPosition + tokenName size - 1. |
4277 pos2 := tokenPosition + tokenName size - 1. |
4280 self markLocalIdentifierFrom:tokenPosition to:pos2. |
4278 self markLocalIdentifierFrom:tokenPosition to:pos2. |
4289 "/ redefinition |
4287 "/ redefinition |
4290 self isSyntaxHighlighter ifTrue:[ |
4288 self isSyntaxHighlighter ifTrue:[ |
4291 self markBadIdentifierFrom:tokenPosition to:pos2. |
4289 self markBadIdentifierFrom:tokenPosition to:pos2. |
4292 ] ifFalse:[ |
4290 ] ifFalse:[ |
4293 self |
4291 self |
4294 parseError:'redefinition of ''' , tokenName , ''' in local variables' |
4292 parseError:'redefinition of ''' , tokenName , ''' in local variables.' |
4295 position:tokenPosition to:pos2. |
4293 position:tokenPosition to:pos2. |
4296 ] |
4294 ] |
4297 ] ifFalse:[ |
4295 ] ifFalse:[ |
4298 methodVars add:var. |
4296 methodVars add:var. |
4299 methodVarNames add:tokenName |
4297 methodVarNames add:tokenName |
4300 ] |
4298 ] |
4301 ]. |
4299 ]. |
4302 |
4300 |
4303 methodArgNames notNil ifTrue:[ |
4301 parserFlags warnHiddenVariables ifTrue:[ |
4304 (methodArgNames includes:tokenName) ifTrue:[ |
4302 methodArgNames notNil ifTrue:[ |
4305 self |
4303 (methodArgNames includes:tokenName) ifTrue:[ |
4306 warning:'local variable ''' , tokenName , ''' hides argument.' |
4304 self |
4307 position:tokenPosition to:pos2 |
4305 warning:'local variable "' , tokenName allBold , '" hides method argument.' |
4308 ] |
4306 position:tokenPosition to:pos2 |
4309 ]. |
4307 ] |
|
4308 ]. |
|
4309 classToCompileFor notNil ifTrue:[ |
|
4310 (self classesInstVarNames includes:tokenName) ifTrue:[ |
|
4311 self |
|
4312 warning:'local variable "' , tokenName allBold , '" hides instance variable.' |
|
4313 position:tokenPosition to:pos2 |
|
4314 ] |
|
4315 ]. |
|
4316 ]. |
|
4317 |
4310 self nextToken. |
4318 self nextToken. |
4311 |
4319 |
4312 classHint := nil. |
4320 classHint := nil. |
4313 lastDirective notNil ifTrue:[ |
4321 lastDirective notNil ifTrue:[ |
4314 lastDirective isClassHintDirective ifTrue:[ |
4322 lastDirective isClassHintDirective ifTrue:[ |
4332 pos := tokenPosition |
4340 pos := tokenPosition |
4333 ]. |
4341 ]. |
4334 |
4342 |
4335 (tokenType ~~ $|) ifTrue:[ |
4343 (tokenType ~~ $|) ifTrue:[ |
4336 (#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
4344 (#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
4337 msg := 'Reserved keyword in local var declaration'. |
4345 msg := 'reserved keyword "',tokenName allBold,'" in local var declaration'. |
4338 pos2 := tokenPosition + tokenName size - 1. |
4346 pos2 := tokenPosition + tokenName size - 1. |
4339 self markBadIdentifierFrom:tokenPosition to:pos2. |
4347 self markBadIdentifierFrom:tokenPosition to:pos2. |
4340 ] ifFalse:[ |
4348 ] ifFalse:[ |
4341 pos2 := source position1Based-1. |
4349 pos2 := source position1Based-1. |
4342 msg := 'Identifier or | expected in local var declaration' |
4350 msg := 'Identifier or | expected in local var declaration' |
4343 ]. |
4351 ]. |
4344 self syntaxError:msg position:tokenPosition to:pos2. |
4352 self syntaxError:msg position:tokenPosition to:pos2. |
4345 ^ #Error |
4353 ^ #Error |
4346 ]. |
4354 ]. |
4347 localVarDefPosition := Array with:localVarDefPosition with:tokenPosition. |
4355 localVarDefPosition at:2 put:tokenPosition. |
4348 self nextToken |
4356 self nextToken |
4349 ]. |
4357 ]. |
4350 |
4358 |
4351 parserFlags allowSqueakExtensions ifTrue:[ |
4359 parserFlags allowSqueakExtensions ifTrue:[ |
4352 "/ allow for primitiveSpec after local-var decl. |
4360 "/ allow for primitiveSpec after local-var decl. |
4400 (methodArgNames includes:tokenName) ifTrue:[ |
4408 (methodArgNames includes:tokenName) ifTrue:[ |
4401 self methodArgRedefined:tokenName from:tokenPosition to:pos2 |
4409 self methodArgRedefined:tokenName from:tokenPosition to:pos2 |
4402 ]. |
4410 ]. |
4403 methodArgs := methodArgs copyWith:arg. |
4411 methodArgs := methodArgs copyWith:arg. |
4404 methodArgNames := methodArgNames copyWith:tokenName |
4412 methodArgNames := methodArgNames copyWith:tokenName |
|
4413 ]. |
|
4414 parserFlags warnHiddenVariables ifTrue:[ |
|
4415 classToCompileFor notNil ifTrue:[ |
|
4416 (self classesInstVarNames includes:tokenName) ifTrue:[ |
|
4417 self |
|
4418 warning:'argument "' , tokenName allBold , '" hides instance variable.' |
|
4419 position:tokenPosition to:pos2 |
|
4420 ] |
|
4421 ]. |
4405 ]. |
4422 ]. |
4406 self nextToken. |
4423 self nextToken. |
4407 "/ ((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
4424 "/ ((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
4408 "/ self nextToken. |
4425 "/ self nextToken. |
4409 "/ arg domain:nil. |
4426 "/ arg domain:nil. |
5909 self markSelfFrom:pos to:pos+3. |
5926 self markSelfFrom:pos to:pos+3. |
5910 ^ SuperNode value:selfValue inClass:classToCompileFor here:true |
5927 ^ SuperNode value:selfValue inClass:classToCompileFor here:true |
5911 ! |
5928 ! |
5912 |
5929 |
5913 primary_identifier |
5930 primary_identifier |
5914 "parse a false primary; return a node-tree, or raise an Error." |
5931 "parse a primary; return a node-tree, or raise an Error." |
5915 |
5932 |
5916 |pos1 pos2 expr varName rawName var globlName nameSpace nameSpaceGlobal |
5933 |pos1 pos2 expr varName rawName var globlName nameSpace nameSpaceGlobal |
5917 t cls lnr node holder autoHow assignmentAllowed| |
5934 t cls lnr node holder autoHow assignmentAllowed| |
5918 |
5935 |
5919 pos1 := tokenPosition. |
5936 pos1 := tokenPosition. |