Explainer.st
changeset 4435 10a6786b7d87
parent 4434 d04631202a76
child 4448 e0dbd918bc2e
equal deleted inserted replaced
4434:d04631202a76 4435:10a6786b7d87
   862                     stringText := stringText , ': a class instVar in ' , clsName
   862                     stringText := stringText , ': a class instVar in ' , clsName
   863                 ] ifFalse:[
   863                 ] ifFalse:[
   864                     stringText := stringText, ': a class instance variable inherited from ' , clsName
   864                     stringText := stringText, ': a class instance variable inherited from ' , clsName
   865                 ].
   865                 ].
   866                 val := aClassOrNil theNonMetaclass instVarNamed:string.
   866                 val := aClassOrNil theNonMetaclass instVarNamed:string.
   867                 valString := self valueStringFor:val.
   867                 valString := self safeValueStringFor:val.
   868                 ^ stringText , ' (' , valString , ').'
   868                 ^ stringText , ' (' , valString , ').'
   869             ].
   869             ].
   870             ^ self explainInstanceVariable:string inClass:c short:shortText.
   870             ^ self explainInstanceVariable:string inClass:c short:shortText.
   871         ].
   871         ].
   872     ].
   872     ].
   875         aClassOrNil notNil ifTrue:[
   875         aClassOrNil notNil ifTrue:[
   876             "classvars"
   876             "classvars"
   877             c := explainer inWhichClassIsClassVar:string.
   877             c := explainer inWhichClassIsClassVar:string.
   878             c notNil ifTrue:[
   878             c notNil ifTrue:[
   879                 val := c theNonMetaclass classVarAt:string. "/ Smalltalk at:(clsName , ':' , string) asSymbol.
   879                 val := c theNonMetaclass classVarAt:string. "/ Smalltalk at:(clsName , ':' , string) asSymbol.
   880                 valString := self valueStringFor:val.
   880                 valString := self safeValueStringFor:val.
   881 
   881 
   882                 val == true ifTrue:[
   882                 val == true ifTrue:[
   883                     color := Color darkGreen.
   883                     color := Color darkGreen.
   884                 ] ifFalse:[
   884                 ] ifFalse:[
   885                     val == false ifTrue:[
   885                     val == false ifTrue:[
   937                         (sharedPool includesKey:sharedPoolSym) ifTrue:[
   937                         (sharedPool includesKey:sharedPoolSym) ifTrue:[
   938                             poolName := sharedPool name.
   938                             poolName := sharedPool name.
   939                             poolName := self asClassLink:eachPoolName.
   939                             poolName := self asClassLink:eachPoolName.
   940                             stringText := stringText , ': a pool variable in ',poolName.
   940                             stringText := stringText , ': a pool variable in ',poolName.
   941                             val := sharedPool at:sharedPoolSym.
   941                             val := sharedPool at:sharedPoolSym.
   942                             valString := self valueStringFor:val.
   942                             valString := self safeValueStringFor:val.
   943                             ^ stringText , ' (' , valString , ').'
   943                             ^ stringText , ' (' , valString , ').'
   944                         ].
   944                         ].
   945                     ].
   945                     ].
   946                 ].
   946                 ].
   947             ].
   947             ].
  1036 Please try again with an individual token selected.'
  1036 Please try again with an individual token selected.'
  1037 
  1037 
  1038     "Created: / 03-12-1995 / 12:47:37 / cg"
  1038     "Created: / 03-12-1995 / 12:47:37 / cg"
  1039     "Modified: / 16-04-1997 / 12:46:11 / stefan"
  1039     "Modified: / 16-04-1997 / 12:46:11 / stefan"
  1040     "Modified: / 23-08-2017 / 12:44:12 / cg"
  1040     "Modified: / 23-08-2017 / 12:44:12 / cg"
  1041     "Modified: / 13-03-2019 / 21:17:09 / Claus Gittinger"
  1041     "Modified: / 08-06-2019 / 14:04:00 / Claus Gittinger"
  1042 !
  1042 !
  1043 
  1043 
  1044 explainGlobal:string inClass:aClassOrNil short:shortText
  1044 explainGlobal:string inClass:aClassOrNil short:shortText
  1045     "return an explanation or nil"
  1045     "return an explanation or nil"
  1046 
  1046 
  1148 ' , varName , ' is bound to the class ' , val name ,
  1148 ' , varName , ' is bound to the class ' , val name ,
  1149 ' in the "' , val category , '" category.'.
  1149 ' in the "' , val category , '" category.'.
  1150         ^ explanation.
  1150         ^ explanation.
  1151     ].
  1151     ].
  1152 
  1152 
  1153     valText := self valueStringFor:val.
  1153     valText := self safeValueStringFor:val.
  1154 
  1154 
  1155     shortText ifTrue:[
  1155     shortText ifTrue:[
  1156         ^ (shortTemplate ? '%1: a global (%2)') 
  1156         ^ (shortTemplate ? '%1: a global (%2)') 
  1157             bindWith:varName 
  1157             bindWith:varName 
  1158             with:(self asLink:valText to:(self actionToBrowseClass:val class selector:nil))
  1158             with:(self asLink:valText to:(self actionToBrowseClass:val class selector:nil))
  1163 Its current value is "%1".' bindWith:valText.
  1163 Its current value is "%1".' bindWith:valText.
  1164     ^ explanation.
  1164     ^ explanation.
  1165 
  1165 
  1166     "Created: / 14-10-2010 / 11:33:04 / cg"
  1166     "Created: / 14-10-2010 / 11:33:04 / cg"
  1167     "Modified: / 16-11-2016 / 13:08:07 / cg"
  1167     "Modified: / 16-11-2016 / 13:08:07 / cg"
  1168     "Modified: / 22-02-2019 / 11:17:20 / Claus Gittinger"
  1168     "Modified: / 08-06-2019 / 14:03:42 / Claus Gittinger"
  1169     "Modified (format): / 04-03-2019 / 10:10:10 / Claus Gittinger"
       
  1170 !
  1169 !
  1171 
  1170 
  1172 explainHereIn:aClassOrNil short:shortText
  1171 explainHereIn:aClassOrNil short:shortText
  1173     "return an explanation"
  1172     "return an explanation"
  1174 
  1173 
  2025 
  2024 
  2026     "Modified: / 28-07-2017 / 10:32:11 / cg"
  2025     "Modified: / 28-07-2017 / 10:32:11 / cg"
  2027     "Modified: / 13-03-2019 / 10:25:48 / Claus Gittinger"
  2026     "Modified: / 13-03-2019 / 10:25:48 / Claus Gittinger"
  2028 !
  2027 !
  2029 
  2028 
       
  2029 safeValueStringFor:aValue
       
  2030     Error handle:[:ex |
       
  2031         ^ 'Error in storeString: ',ex description
       
  2032     ] do:[
       
  2033         ^ self valueStringFor:aValue
       
  2034     ]
       
  2035 
       
  2036     "Created: / 08-06-2019 / 14:03:38 / Claus Gittinger"
       
  2037 !
       
  2038 
  2030 typeDescriptionFor:setOfTypes andSelector:selectorOrNil
  2039 typeDescriptionFor:setOfTypes andSelector:selectorOrNil
  2031     "up to 3 types are shown by name; more are simply counted"
  2040     "up to 3 types are shown by name; more are simply counted"
  2032     
  2041     
  2033     ^ self typeDescriptionFor:setOfTypes andSelector:selectorOrNil wordBetween:'or'
  2042     ^ self typeDescriptionFor:setOfTypes andSelector:selectorOrNil wordBetween:'or'
  2034 !
  2043 !
  2097         or:[aValue isString
  2106         or:[aValue isString
  2098         or:[aValue isNumber
  2107         or:[aValue isNumber
  2099         or:[aValue isPoint
  2108         or:[aValue isPoint
  2100         or:[aValue isCharacter
  2109         or:[aValue isCharacter
  2101     ]]]]]) ifTrue:[
  2110     ]]]]]) ifTrue:[
  2102         Error handle:[:ex |
  2111         ^ aValue storeString.
  2103             ^ 'Error in storeString: ',ex description
       
  2104         ] do:[
       
  2105             ^ aValue storeString.
       
  2106         ].
       
  2107     ].
  2112     ].
  2108 
  2113 
  2109     (aValue isColor) ifTrue:[
  2114     (aValue isColor) ifTrue:[
  2110         ^ 'Color: ',('   ' emphasizeAllWith:(#backgroundColor->aValue)).
  2115         ^ 'Color: ',('   ' emphasizeAllWith:(#backgroundColor->aValue)).
  2111     ].
  2116     ].
  2122     ].
  2127     ].
  2123 
  2128 
  2124     ^ valString
  2129     ^ valString
  2125 
  2130 
  2126     "Modified: / 14-10-2010 / 11:57:52 / cg"
  2131     "Modified: / 14-10-2010 / 11:57:52 / cg"
  2127     "Modified: / 08-06-2019 / 14:01:55 / Claus Gittinger"
  2132     "Modified: / 08-06-2019 / 14:02:57 / Claus Gittinger"
  2128 ! !
  2133 ! !
  2129 
  2134 
  2130 !Explainer class methodsFor:'naive type inferer'!
  2135 !Explainer class methodsFor:'naive type inferer'!
  2131 
  2136 
  2132 addTypeOfExpressionNode:expr forAssignmentTo:varName to:setOfTypes
  2137 addTypeOfExpressionNode:expr forAssignmentTo:varName to:setOfTypes