8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'Languages-Tea-Compiler-AST' |
9 category:'Languages-Tea-Compiler-AST' |
10 ! |
10 ! |
11 |
11 |
12 !TFormatter methodsFor:'visitor-double dispatching'! |
12 !TFormatter methodsFor:'visitor-double dispatching'! |
13 |
|
14 acceptInlineAssemblyNode:aBlockNode |
|
15 |seqNode multiline formattedBody formatter parent parentSelector| |
|
16 |
|
17 (CStyleBlocks |
|
18 and:[ (parent := aBlockNode parent) notNil and:[ parent isMessage ] ]) |
|
19 ifTrue: |
|
20 [ parent receiver == aBlockNode |
|
21 ifTrue: |
|
22 [ " I am the receiver of a message (i.e. typically a control structure) " |
|
23 ^ self acceptInlineAssemblyNodeCStyle:aBlockNode ]. |
|
24 parentSelector := parent selector. |
|
25 parentSelector == #timesRepeat: |
|
26 ifTrue: |
|
27 [ " I am the receiver of a message (i.e. typically a control structure) " |
|
28 self indent:-2 while:[ ^ self acceptInlineAssemblyNodeCStyle:aBlockNode ] ] ]. |
|
29 seqNode := aBlockNode body. |
|
30 formatter := (self copy) |
|
31 lineStart:0; |
|
32 yourself. |
|
33 seqNode isNil ifTrue:[ |
|
34 formattedBody := '' |
|
35 ] ifFalse:[ |
|
36 formattedBody := formatter format:seqNode |
|
37 ]. |
|
38 multiline := (self lineLength + formattedBody size > self maxLineSize) |
|
39 or:[ formatter isMultiLine ]. |
|
40 (CStyleBlocks and:[ multiline ]) |
|
41 ifTrue: |
|
42 [ self indent:-1 while:[ self acceptInlineAssemblyNodeCStyle:aBlockNode ]. |
|
43 ^ self ]. |
|
44 multiline ifTrue:[ self indent ]. |
|
45 codeStream nextPutAll:'%['. |
|
46 SpaceAfterBlockStart |
|
47 ifTrue: |
|
48 [ (formattedBody notEmpty and:[ aBlockNode arguments isEmptyOrNil ]) |
|
49 ifTrue:[ codeStream space. ] ]. |
|
50 self formatBlockArguments:aBlockNode. |
|
51 aBlockNode arguments isEmpty |
|
52 ifFalse: |
|
53 [ codeStream nextPutAll:'| '. |
|
54 multiline ifTrue:[ self indent ] ]. |
|
55 codeStream nextPutAll:formattedBody. |
|
56 SpaceBeforeBlockEnd |
|
57 ifTrue:[ formattedBody notEmpty ifTrue:[ codeStream space. ] ]. |
|
58 codeStream nextPutAll:'%]' |
|
59 |
|
60 "Created: / 02-09-2015 / 06:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
61 ! |
|
62 |
|
63 acceptInlineAssemblyNodeCStyle: aBlockNode |
|
64 | seqNode l multiline formattedBody formatter | |
|
65 |
|
66 seqNode := aBlockNode body. |
|
67 |
|
68 formatter := (self copy) lineStart: 0; yourself. |
|
69 formatter indentWhile:[ |
|
70 formattedBody := formatter format: seqNode. |
|
71 formattedBody asCollectionOfLines last isBlank ifTrue:[ |
|
72 formattedBody := (formattedBody asCollectionOfLines copyButLast:1) asStringWith:Character cr. |
|
73 ]. |
|
74 ]. |
|
75 multiline := (l := self lineLength + formattedBody size) > self maxLineSize |
|
76 or: [formatter isMultiLine]. |
|
77 multiline := multiline or:[l > (MaxLengthForSingleLineBlocks ? 60)]. |
|
78 |
|
79 codeStream nextPutAll:'%['. |
|
80 multiline ifFalse:[ |
|
81 SpaceAfterBlockStart |
|
82 ifTrue:[ |
|
83 (formattedBody notEmpty and:[aBlockNode hasArguments not]) |
|
84 ifTrue:[ |
|
85 codeStream space.]]. |
|
86 ]. |
|
87 self indentWhile:[ |
|
88 (BlockArgumentsOnNewLine or:[aBlockNode hasArguments not]) ifTrue:[ |
|
89 multiline ifTrue:[ |
|
90 self indent. |
|
91 ]. |
|
92 ]. |
|
93 |
|
94 self formatBlockArguments:aBlockNode. |
|
95 aBlockNode arguments isEmpty |
|
96 ifFalse:[ |
|
97 codeStream nextPutAll: '| '. |
|
98 multiline ifTrue: [self indent]]. |
|
99 ]. |
|
100 codeStream nextPutAll: formattedBody. |
|
101 multiline |
|
102 ifTrue: [self indent] |
|
103 ifFalse:[ |
|
104 SpaceBeforeBlockEnd |
|
105 ifTrue:[ |
|
106 formattedBody notEmpty |
|
107 ifTrue:[ |
|
108 codeStream space.]]]. |
|
109 codeStream nextPutAll:'%]'. |
|
110 |
|
111 "Created: / 02-09-2015 / 06:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
112 ! |
|
113 |
13 |
114 acceptSimpleTypeNode: aTSimpleTypeNode |
14 acceptSimpleTypeNode: aTSimpleTypeNode |
115 codeStream nextPutAll: aTSimpleTypeNode name |
15 codeStream nextPutAll: aTSimpleTypeNode name |
116 |
16 |
117 "Created: / 21-08-2015 / 22:20:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17 "Created: / 21-08-2015 / 22:20:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |