Spaces:
Running
Running
scratch0-5 / utils /VMMakerJS.package /JSSmartSyntaxPluginMethod.class /instance /recordDeclarations.st
| transforming | |
| recordDeclarations | |
| "Record C type declarations of the forms | |
| self returnTypeC: 'float'. | |
| self var: #foo declareC: 'float foo' | |
| self var: #foo as: Class | |
| self var: #foo type: 'float'. | |
| and remove the declarations from the method body." | |
| | newStatements | | |
| properties pragmas notEmpty ifTrue: | |
| [properties pragmas do: | |
| [:pragma| | |
| pragma keyword = #var:declareC: ifTrue: | |
| [self declarationAt: pragma arguments first asString put: pragma arguments last]. | |
| pragma keyword = #var:type: ifTrue: | |
| [| varName varType | | |
| varName := pragma arguments first asString. | |
| varType := pragma arguments last. | |
| varType last = $* ifFalse: [varType := varType, ' ']. | |
| self declarationAt: varName put: varType, varName]. | |
| pragma keyword = #var:as: ifTrue: | |
| [| theClass | | |
| theClass := Smalltalk at: pragma arguments last name asSymbol ifAbsent: [nil]. | |
| (theClass isKindOf: Behavior) ifFalse: | |
| [^self error: 'declarator must be a Behavior']. | |
| self declarationAt: pragma arguments first value asString | |
| put: (theClass jscgDeclareJSForVar: pragma arguments first asString)]. | |
| pragma keyword = #returnTypeC: ifTrue: | |
| [returnType := pragma arguments last]. | |
| pragma keyword = #doNotGenerate: ifTrue: | |
| [locals removeKey: pragma arguments last]]]. | |
| newStatements := OrderedCollection new: parseTree statements size. | |
| parseTree statements do: | |
| [:stmt | | isDeclaration | | |
| isDeclaration := false. | |
| stmt isSend ifTrue: | |
| [stmt selector = #var:declareC: ifTrue: | |
| [isDeclaration := true. | |
| self declarationAt: stmt args first value asString put: stmt args last value]. | |
| stmt selector = #var:type: ifTrue: [ | |
| | varName varType | | |
| isDeclaration := true. | |
| varName := stmt args first value asString. | |
| varType := stmt args last value. | |
| varType last = $* ifFalse: [varType := varType, ' ']. | |
| self declarationAt: varName put: varType, varName. | |
| ]. | |
| stmt selector = #var:as: ifTrue: | |
| [| theClass | | |
| isDeclaration := true. | |
| theClass := Smalltalk at: stmt args last name asSymbol ifAbsent: [nil]. | |
| (theClass isKindOf: Behavior) ifFalse: | |
| [^self error: 'declarator must be a Behavior']. | |
| self declarationAt: stmt args first value asString | |
| put: (theClass jscgDeclareJSForVar: stmt args first value asString)]. | |
| stmt selector = #returnTypeC: ifTrue: | |
| [isDeclaration := true. | |
| returnType := stmt args last value]]. | |
| isDeclaration ifFalse: [newStatements add: stmt]]. | |
| parseTree setStatements: newStatements asArray |