src/JavaMethod.st
branchjk_new_structure
changeset 912 e651488f5741
parent 877 f5a5b93e1c78
child 913 1781f130b005
equal deleted inserted replaced
911:efa922d67283 912:e651488f5741
   144     SignatureTypeCodes at:$J put:#long.
   144     SignatureTypeCodes at:$J put:#long.
   145     SignatureTypeCodes at:$S put:#'unsigned short'.
   145     SignatureTypeCodes at:$S put:#'unsigned short'.
   146     SignatureTypeCodes at:$Z put:#boolean.
   146     SignatureTypeCodes at:$Z put:#boolean.
   147     SignatureTypeCodes at:$L put:#object.
   147     SignatureTypeCodes at:$L put:#object.
   148     SignatureTypeCodes at:$[ put:#array.
   148     SignatureTypeCodes at:$[ put:#array.
       
   149     SignatureTypeCodes at:$T put:#typevar.
   149 
   150 
   150     ForceByteCodeDisplay := false.
   151     ForceByteCodeDisplay := false.
   151 
   152 
   152     "
   153     "
   153      JavaMethod initialize.
   154      JavaMethod initialize.
   154      JavaMethodWithHandler initialize.
   155      JavaMethodWithHandler initialize.
   155      ForceByteCodeDisplay := true.
   156      ForceByteCodeDisplay := true.
   156      ForceByteCodeDisplay := false.
   157      ForceByteCodeDisplay := false.
   157     "
   158     "
   158 
   159 
   159     "Modified: / 16.10.1998 / 01:29:48 / cg"
   160     "Modified: / 16-10-1998 / 01:29:48 / cg"
       
   161     "Modified: / 13-08-2011 / 01:02:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   160 !
   162 !
   161 
   163 
   162 reinitialize
   164 reinitialize
   163 
   165 
   164     self flags:(self flags bitOr:Behavior flagJavaMethod).
   166     self flags:(self flags bitOr:Behavior flagJavaMethod).
   424 !
   426 !
   425 
   427 
   426 fieldTypeFromStream:s in:aPackage
   428 fieldTypeFromStream:s in:aPackage
   427     "parse a fieldTypeSpec - see java doc"
   429     "parse a fieldTypeSpec - see java doc"
   428 
   430 
   429     |typeChar typeSym elType size className nm|
   431     |typeChar typeSym elType size className nm out nangles |
   430 
   432 
   431     typeChar := s next.
   433     typeChar := s next.
   432 
   434 
   433     typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown.
   435     typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown.
   434 
   436 
   435     typeSym == #unknown ifTrue:[
   437     typeSym == #unknown ifTrue:[
   436 	^ typeSym
   438         ^ typeSym
   437     ].
   439     ].
   438     typeSym == #object ifTrue:[
   440     (typeSym == #object or: [typeSym == #typevar]) ifTrue:[
   439 	className := s upTo:$;.
   441         "Take care about type variables"
   440 	"/ strip off default
   442         out := String new writeStream.
   441 
   443         [ s peek ~~ $; and:[ s peek ~~ $< ] ] whileTrue:[
   442 	nm := className.
   444             out nextPut: s next.
   443 	aPackage notNil ifTrue:[
   445         ].
   444 	    (nm startsWith:aPackage) ifTrue:[
   446         className := out contents.
   445 		nm := nm copyFrom:(aPackage size + 2).
   447         "Eat possible type variables"
   446 	    ].
   448         (s peek == $<) ifTrue:[
   447 	].
   449             nangles := 1. s next.
       
   450             [  nangles ~~ 0 ] whileTrue:[
       
   451                 s peek == $< ifTrue:[nangles := nangles + 1].
       
   452                 s peek == $> ifTrue:[nangles := nangles - 1].
       
   453                 s next.
       
   454             ]
       
   455         ].
       
   456         s peek ~~ $; ifTrue:[self error: 'Signature corrupted?'].
       
   457         s next. "/eat ;
       
   458 
       
   459 
       
   460         typeSym == #typevar ifTrue:[^className].
       
   461         "/ strip off default
       
   462         nm := className.
       
   463         aPackage notNil ifTrue:[
       
   464             (nm startsWith:aPackage) ifTrue:[
       
   465                 nm := nm copyFrom:(aPackage size + 2).
       
   466             ].
       
   467         ].
   448         
   468         
   449 	nm := nm copyReplaceAll:$/ with:$..
   469         nm := nm copyReplaceAll:$/ with:$..
   450 	^ nm
   470         ^ nm
   451     ].
   471     ].
   452 
   472 
   453     typeSym == #array ifTrue:[
   473     typeSym == #array ifTrue:[
   454 	s peek isDigit ifTrue:[
   474         s peek isDigit ifTrue:[
   455 	    size := Integer readFrom:s.
   475             size := Integer readFrom:s.
   456 	    elType := self fieldTypeFromStream:s in:aPackage.
   476             elType := self fieldTypeFromStream:s in:aPackage.
   457 	    ^ elType , '[' , size printString , ']'
   477             ^ elType , '[' , size printString , ']'
   458 	].
   478         ].
   459 	elType := self fieldTypeFromStream:s in:aPackage.
   479         elType := self fieldTypeFromStream:s in:aPackage.
   460 	^ elType , '[]'
   480         ^ elType , '[]'
   461     ].
   481     ].
   462 
   482 
   463     ^ typeSym
   483     ^ typeSym
   464 
   484 
   465     "Created: / 18.3.1997 / 11:07:56 / cg"
   485     "Created: / 18-03-1997 / 11:07:56 / cg"
   466     "Modified: / 18.7.1998 / 22:57:06 / cg"
   486     "Modified: / 18-07-1998 / 22:57:06 / cg"
       
   487     "Modified: / 13-08-2011 / 01:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   467 !
   488 !
   468 
   489 
   469 numArgsFromSignature:aSignature
   490 numArgsFromSignature:aSignature
   470     "given a signature, return the number of args"
   491     "given a signature, return the number of args"
   471 
   492 
   472     |s|
   493     |s|
   473 
   494 
   474     s := aSignature readStream.
   495     s := aSignature readStream.
   475     s next ~~ $( ifTrue:[self halt].
   496     (aSignature includes: $() ifFalse:[self error:'Invalid signature'].
       
   497     [s next ~~ $(] whileTrue.
   476 
   498 
   477     ^ self numArgsFromStream:s.
   499     ^ self numArgsFromStream:s.
   478 
   500 
   479     "
   501     "
   480      JavaMethod numArgsFromSignature:'(LObject;)V'
   502      JavaMethod numArgsFromSignature:'(LObject;)V'
   481      JavaMethod numArgsFromSignature:'(BB)S'      
   503      JavaMethod numArgsFromSignature:'(BB)S'      
   482      JavaMethod numArgsFromSignature:'()V'      
   504      JavaMethod numArgsFromSignature:'()V'      
   483     "
   505      JavaMethod numArgsFromSignature:'(Ljava/util/ArrayList<*>;)V'
       
   506     "
       
   507 
       
   508     "Modified (comment): / 13-08-2011 / 00:59:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   484 !
   509 !
   485 
   510 
   486 numArgsFromStream:s
   511 numArgsFromStream:s
   487     "parse an argSpec - see java doc"
   512     "parse an argSpec - see java doc"
   488 
   513 
  1287 
  1312 
  1288 setLocalVariableTable:anArray
  1313 setLocalVariableTable:anArray
  1289      localVariableTable := anArray.
  1314      localVariableTable := anArray.
  1290 !
  1315 !
  1291 
  1316 
  1292 setName:nameString signature:signatureString
  1317 setName:nameString signature:aString
  1293     selector := (nameString , signatureString) asSymbol.
  1318 
  1294     self setSignature:signatureString
  1319 
       
  1320     |numArgs tooManyArgs returnType|
       
  1321 
       
  1322     selector := (nameString , aString) asSymbol.
       
  1323     self setSignature:aString.
       
  1324 
       
  1325      numArgs := self class numArgsFromSignature:aString.
       
  1326      (tooManyArgs := (numArgs > self class maxNumberOfArguments)) ifTrue:[
       
  1327      numArgs := 0.
       
  1328      ].
       
  1329      self numberOfArgs:numArgs.
       
  1330      returnType := self class typeFromSignature:aString in:nil.
       
  1331 
       
  1332      "/ for the convenience of the VM, also mirror the return type in
       
  1333      "/ the flags ...
       
  1334 
       
  1335      returnType == #void ifTrue:[
       
  1336      accessFlags := accessFlags bitOr:R_VOID
       
  1337      ] ifFalse:[
       
  1338      returnType == #long ifTrue:[
       
  1339      accessFlags := accessFlags bitOr:R_LONG
       
  1340      ] ifFalse:[
       
  1341      returnType == #double ifTrue:[
       
  1342      accessFlags := accessFlags bitOr:R_DOUBLE
       
  1343      ]
       
  1344      ]
       
  1345      ].
       
  1346      tooManyArgs ifTrue:[
       
  1347      ^ ArgumentError
       
  1348      raiseRequestWith:self
       
  1349      errorString:'too many args in method'
       
  1350     ].
       
  1351 
       
  1352     "Modified: / 13-08-2011 / 01:21:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1295 !
  1353 !
  1296 
  1354 
  1297 setSignature:aString
  1355 setSignature:aString
  1298     |numArgs tooManyArgs returnType|
  1356     |numArgs tooManyArgs returnType|
  1299 
  1357 
  1300     signature := aString asSymbol.
  1358     signature := aString asSymbol.
  1301 
  1359 
  1302     numArgs := self class numArgsFromSignature:aString.
       
  1303     (tooManyArgs := (numArgs > self class maxNumberOfArguments)) ifTrue:[
       
  1304         numArgs := 0.
       
  1305     ].
       
  1306     self numberOfArgs:numArgs.
       
  1307     returnType := self class typeFromSignature:aString in:nil.
       
  1308 
       
  1309     "/ for the convenience of the VM, also mirror the return type in
       
  1310     "/ the flags ...
       
  1311 
       
  1312     returnType == #void ifTrue:[
       
  1313         accessFlags := accessFlags bitOr:R_VOID
       
  1314     ] ifFalse:[
       
  1315         returnType == #long ifTrue:[
       
  1316             accessFlags := accessFlags bitOr:R_LONG
       
  1317         ] ifFalse:[
       
  1318             returnType == #double ifTrue:[
       
  1319                 accessFlags := accessFlags bitOr:R_DOUBLE
       
  1320             ]
       
  1321         ]
       
  1322     ].
       
  1323     tooManyArgs ifTrue:[
       
  1324         ^ ArgumentError
       
  1325             raiseRequestWith:self
       
  1326             errorString:'too many args in method'
       
  1327     ].
       
  1328 
       
  1329     "Created: / 16-04-1996 / 11:34:29 / cg"
  1360     "Created: / 16-04-1996 / 11:34:29 / cg"
  1330     "Modified: / 16-10-1998 / 00:17:12 / cg"
  1361     "Modified: / 16-10-1998 / 00:17:12 / cg"
  1331     "Modified: / 20-10-2010 / 11:29:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1362     "Modified: / 13-08-2011 / 01:21:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1332 !
  1363 !
  1333 
  1364 
  1334 signature
  1365 signature
  1335     ^ signature 
  1366     ^ signature 
  1336 
  1367