Blame view

circus/src/circusRefine/util/docgenerator/ParaPrintLatex.java 9 KB
8d0dc533f   Madiel de Souza Conserva Filho   first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  package circusRefine.util.docgenerator;
  
  import java.util.List;
  
  import javax.swing.JOptionPane;
  
  import net.sourceforge.czt.circus.ast.ActionPara;
  import net.sourceforge.czt.circus.ast.ChannelDecl;
  import net.sourceforge.czt.circus.ast.ChannelPara;
  import net.sourceforge.czt.circus.ast.ChannelSet;
  import net.sourceforge.czt.circus.ast.ChannelSetPara;
  import net.sourceforge.czt.circus.ast.CircusAction;
  import net.sourceforge.czt.circus.ast.CircusProcess;
  import net.sourceforge.czt.circus.ast.NameSet;
  import net.sourceforge.czt.circus.ast.NameSetPara;
  import net.sourceforge.czt.circus.ast.ProcessPara;
  import net.sourceforge.czt.circus.ast.TransformerPara;
  import net.sourceforge.czt.circus.util.CircusUtils;
  import net.sourceforge.czt.z.ast.AxPara;
  import net.sourceforge.czt.z.ast.Box;
  import net.sourceforge.czt.z.ast.ConjPara;
  import net.sourceforge.czt.z.ast.Decl;
  import net.sourceforge.czt.z.ast.FreePara;
  import net.sourceforge.czt.z.ast.Freetype;
  import net.sourceforge.czt.z.ast.GivenPara;
  import net.sourceforge.czt.z.ast.InStroke;
  import net.sourceforge.czt.z.ast.Name;
  import net.sourceforge.czt.z.ast.NextStroke;
  import net.sourceforge.czt.z.ast.NumStroke;
  import net.sourceforge.czt.z.ast.OutStroke;
  import net.sourceforge.czt.z.ast.Pred;
  import net.sourceforge.czt.z.ast.SchText;
  import net.sourceforge.czt.z.ast.Stroke;
  import net.sourceforge.czt.z.ast.ZDeclList;
  import net.sourceforge.czt.z.ast.ZFreetypeList;
  import net.sourceforge.czt.z.ast.ZName;
  import net.sourceforge.czt.z.ast.ZNameList;
  import net.sourceforge.czt.z.util.ZString;
  import net.sourceforge.czt.z.util.ZUtils;
  import circusRefine.core.NoPrograma;
  import circusRefine.core.Relacionamento;
  import circusRefine.core.print.ParaPrint;
  import circusRefine.core.print.Printer;
  import circusRefine.core.relations.RelationsAnn;
  import circusRefine.core.relations.RelationsUtils;
  
  public class ParaPrintLatex extends ParaPrint {
  
  	public ParaPrintLatex(DocGenerator printer) {
  		super(printer);
  	}
  	
  	/**
  	 * Remocao da opção de imprimir em Unicode
  	 * Retirada do ambiente circus
  	 */
  	public Object visitChannelPara(ChannelPara term) 
  	{	
  		getPercurso().append("Channel PAra
  ");
  		String result[] = null;
  
  		result = new String[1];
  		ZDeclList chanDecls = (ZDeclList)term.getZDeclList();
  
  		String strDecls = "";
  		int size = chanDecls.size();
  		int counter = 0;
  		boolean isChannelFromDecl = false;
  		for (Decl chanDecl : chanDecls) {
  			if (chanDecls.size() == 1) {
  				ChannelDecl chandecl = (ChannelDecl)chanDecl;
  				if (chandecl.getZChannelNameList().size() == 0) {
  					isChannelFromDecl = true;
  				}
  
  			}
  			strDecls = strDecls + ((String[])chanDecl.accept(declPrint()))[0];
  			if(counter < size-1) {
  				strDecls = strDecls + "; ";
  			}
  			counter++;
  		}
  		if (!isChannelFromDecl) {
  			result[0] = BRANCO + "\\circchannel\\ " + strDecls;
  		}
  		else {
  			result[0] = BRANCO + "\\circchannelfrom\\ " + strDecls;
  		}
  
  		return result;
  	}
  		
  	/**
  	 * Remocao da opção de imprimir em Unicode
  	 * Retirada do ambiente circus
  	 */
  	public Object visitChannelSetPara(ChannelSetPara term)
  	  {
  		getPercurso().append("ChannelSetPara
  ");
  		  
  		  ZName name = (ZName)term.getName();
  		  ChannelSet chanSet = term.getChannelSet();
  		  String strName = name.getWord();
  		  String strChanSet = ((String[])chanSet.accept(exprPrint()))[0];
  		  
  		  ZNameList genericParams = (ZNameList)term.getGenFormals();
  		  
  		  String[] result = null;	  
  		 
  		  if (!getUnicoded()) {
  			  
  			  result = new String[1];
  			  result[0] = BRANCO + "\\circchannelset\\ ";
  			  if (genericParams.isEmpty()){
  				  result[0] = result[0] + strName + " == " + strChanSet;
  			  }
  			  else{
  				  boolean first = true;
  				  result[0] = result[0] + "[";
  				  for (Name nome : genericParams){
  					  ZName nombre = (ZName)nome;
  					  if (first) first = false;
  					  else result[0] = result[0] + Space + ZString.COMMA + Space;
  					  result[0] = result[0] + nombre.getWord();
  				  }
  				  result[0] = result[0] + "]";
  				  
  				  result[0] = result[0]+ Space + strName + " == " + strChanSet;
  			  }
  		  }
  		  
  		  
  		  return result;
  	  }
  	
  	/**
  	 * Remocao da opção de imprimir em Unicode
  	 * Retirada do ambiente circus
  	 */
  	public Object visitProcessPara(ProcessPara term)
  	  {
  		  String[] result = null;
  
  		  getPercurso().append("ProcessPara
  ");
  		  
  		  // guarda a Liha Inicial para setar o Relacionamento
  		  
  		  List<Name> genParams = (ZNameList)term.getGenFormals();
  
  		  CircusProcess circProc = term.getCircusProcess();
  
  		  String strName = ((String[])term.getName().accept(namePrint()))[0];
  		  
  
  		  String[] strProc = (String[])circProc.accept(processPrint());
  		  String strGenParams = "";
  
  		  int size = genParams.size();
  
  		  int counter = 0;
  		  for(Name ndecl : genParams) {
  
  			  ZName decl = (ZName)ndecl;
  
  			  if(counter == 0) {
  				  strGenParams = "[";
  			  }
  			  strGenParams = strGenParams + decl.getWord();
  			  if(counter < size-1) {
  				  strGenParams = strGenParams + ",";
  			  } 
  			  else if(counter == size-1) {
  				  strGenParams = strGenParams + "]";
  			  }
  			  counter++;
  		  }
  
  		  //LATEX
  		  int index = 1;
  		  result = new String[strProc.length + 1];
  		  result[0] = BRANCO + "\\circprocess\\" + Space + strGenParams + Space + strName + " \\circdef \\\\";
  		  for(int i=0; i<strProc.length; i++) {
  			  result[index++] = BRANCO + "\\t1 " + strProc[i];
  		  }
  		  return result;
  	  }
  
  	/**
  	 * Retirada do ambiente circus que ficou a cargo do visitor de ZSect
  	 */
  	public Object visitNameSetPara(NameSetPara term)
  	{
  		String[] result = new String[1];
  
  		getPercurso().append("NameSet
  ");
  
  		ZName name = (ZName)term.getName();
  		NameSet ns = term.getNameSet();
  
  		String strName = name.getWord();
  		String strNS = ((String[])ns.accept(exprPrint()))[0];
  
  		result[0] = BRANCO + strName + " == " + strNS;
  
  		return result;
  	}
  	
  	/**
  	 * Retirada do ambiente circus que ficou a cargo do visitor de ZSect
  	 */
  	public Object visitGivenPara(GivenPara givenPara)
  	{
  		String[] result = null;
  		result = new String[1];
  		getPercurso().append("GivenPAra
  ");
  		List<Name> Names = givenPara.getZNameList();
  
  		int counter = 0;
  		int size = Names.size();
  		String strDecl = "";
  		for (Name name : Names) {
  			ZName nombre = (ZName)name;
  			strDecl = strDecl + nombre.getWord();
  			if(counter < size-1) {
  				strDecl = strDecl + ",";
  			}
  			counter++;
  		}
  		result[0] = BRANCO + "[" + strDecl + "]";
  
  		return result;
  	}
  	
  	public Object visitFreePara(FreePara freePara)
  	{
  		String[] result = null;
  
  		getPercurso().append("FreePara
  ");
  
  		List<Freetype> freetypes = (ZFreetypeList)freePara.getFreetypeList();
  		String strFT = "";
  
  		int size = freetypes.size();
  		int counter = 0;
  		for (Freetype freetype : freetypes) {
  			strFT = strFT + ((String[])freetype.accept(this))[0];
  			if(counter < size-1) {
  				strFT = strFT + Space + ZString.AMP+ Space;
  			}
  			counter++;
  		}
  		result = new String[1];
  		result[0] = BRANCO + strFT;
  
  
  		return result;
  	}
  	
  	
  	public Object visitConjPara(ConjPara conjPara)
  	{
  		String[] result = new String[3];
  		result = new String[1];
  		getPercurso().append("ConjPara
  ");
  
  		Pred pred = conjPara.getPred();
  		List<Name> genParams = conjPara.getZNameList();
  
  		String strPred = ((String[])pred.accept(predPrint()))[0];
  		String strGP = "";
  
  		if(genParams != null && genParams.size() != 0) {
  			int size = genParams.size();
  			int counter = 0;
  			for(Name name : genParams) {
  				ZName nombre = (ZName) name;
  				if(counter == 0) {
  					strGP = "[";
  				}
  				strGP = strGP + nombre.getWord();
  				if(counter < size-1) {
  					strGP = strGP + ",";
  				}
  				else if(counter == size-1) {
  					strGP = strGP + "]";
  				}
  			}
  		}
  		result[0] = BRANCO + strGP + Space + "\\vdash" + Space + strPred;
  
  		return result;
  	}
  	
  
  	public Object visitTransformerPara (TransformerPara trans) {
  
  		getPercurso().append("TransformerPara
  ");
  		String aux[] = null;
  		String []result= (String[])trans.getTransformerPred().accept(predPrint());
  
  		return result;
  	}
  
  	
  	
  //	 PParagraph ::= N \defs ActionDefinition
  	  // ok - verificado em 25/09/2005 às 10:29
  	  public Object visitActionPara(ActionPara term)
  	  {
  		  getPercurso().append("ActionPara
  ");
  
  		  String[] result = null;
  
  		  ZName actionName = (ZName)term.getName();
  		  CircusAction action = term.getCircusAction();
  
  		  String strName = actionName.getWord();
  		  if (strName.startsWith(CircusUtils.DEFAULT_MAIN_ACTION_NAME)) {
  			  strName = "Main Action";
  		  }
  		  else if (strName.startsWith(CircusUtils.DEFAULT_PROCESS_STATE_NAME)) {
  			  strName = Space;
  		  }
  		  String[] strAct = (String[])action.accept(actionPrint());
  
  		  result = new String[strAct.length + 1];
  
  		  int index = 1;
  
  		  result[0] =  strName + " \\circdef ";
  		  
  		  for(int i=0; i<strAct.length; i++) {
  			  result[index++] =  BRANCO + "\\t1 " + strAct[i];
  		  }
  		 
  
  		  return result;
  	  }
  
  
  }