001/****************************************************************************
002 * Copyright/Copyleft:
003 *
004 * For this source the LGPL Lesser General Public License,
005 * published by the Free Software Foundation is valid.
006 * It means:
007 * 1) You can use this source without any restriction for any desired purpose.
008 * 2) You can redistribute copies of this source to everybody.
009 * 3) Every user of this source, also the user of redistribute copies
010 *    with or without payment, must accept this license for further using.
011 * 4) But the LPGL is not appropriate for a whole software product,
012 *    if this source is only a part of them. It means, the user
013 *    must publish this part of source,
014 *    but don't need to publish the whole source of the own product.
015 * 5) You can study and modify (improve) this source
016 *    for own using or for redistribution, but you have to license the
017 *    modified sources likewise under this LGPL Lesser General Public License.
018 *    You mustn't delete this Copyright/Copyleft inscription in this source file.
019 *
020 * @author Hartmut Schorrig: hartmut.schorrig@vishia.de, www.vishia.org
021 * @version 0.93 2011-01-05  (year-month-day)
022 *******************************************************************************/ 
023package org.vishia.java2C;
024
025import java.io.File;
026import java.io.FileNotFoundException;
027import java.io.IOException;
028import java.text.ParseException;
029import java.util.LinkedList;
030import java.util.List;
031import java.util.Map;
032import java.util.TreeMap;
033
034import org.vishia.mainCmd.Report;
035import org.vishia.util.Debugutil;
036import org.vishia.util.FileSystem;
037import org.vishia.util.StringPartFromFileLines;
038import org.vishia.util.StringPartScan;
039import org.vishia.zbnf.ZbnfJavaOutput;
040import org.vishia.zbnf.ZbnfParseResultItem;
041import org.vishia.zbnf.ZbnfParser;
042
043/**An instance of this class is filled with the result of parsing an <code>*.stc</code> file
044 * which contains the structure informations of a already translated file.
045 * <br>
046 * Such a file is parsed inside {@link #readStructToClassData(String sClassFileName)} 
047 * called inside {@link Java2C_Main#runrunFirstPass(java.io.File javaFile, boolean)},
048 * if either the source <code>*.java</code> is not present to parse (for basics) 
049 * or the destination file should not be generated because it exists and the 
050 * source <code>*.java</code> file isn't newer than the already translated destination.
051 * <br><br>
052 * That routine parses the result and calls 
053 * {@link org.vishia.zbnf.ZbnfJavaOutput#setOutputStrict(Object result, ZbnfParseResultItem, Report)}.
054 * The result is this instance.
055 * <br>
056 * The syntax of parsing is given in the outside file <code>Java2Cstc.zbnf</code> in form:
057 * <pre>
058 * Structure::= J2C: structure of file-class: <$?fileName> { class <ClassData> } \e.
059 * 
060 * ClassData::= <*; ?nameJava> ; <$?nameC> ; 
061 * \{ [ fieldIdents \{ [{ field; <field> }] \}]
062 *    [ typeIdents \{ [{ <type> | class <ClassData?InnerClassData> }] \}]
063 *    [ methods \{ [{ <method> }] \}]
064 *    [ InnerClass \{ [{ class <ClassData?InnerClassData> }] \}]
065 * \}.
066 * 
067 * field::= <1*?modeAccess><1*?modeArrayElement><1*?modeStatic>;
068 *          [{\[ [\?\?<?arrayDimension>|<*\]?fixArraySizes>]\]}] ;
069 *          <*; ?typeJava> ; <$?typeC> ; <$?name> ; 
070 *          .
071 *          
072 * type::= type; <$?typeName>.
073 * 
074 * method::= method ; <*;?keyName> ; <$?javaName> ; <$?CName> ;
075 *           return ; <field?returnType> 
076 *           [{ param ( <field?param> ) }]
077 *           .
078 * </pre>.
079 * All syntax/semantic elements have a representation in this class, because
080 * {@link org.vishia.zbnf.ZbnfJavaOutput#setOutputStrict(Object result, ZbnfParseResultItem, Report)}.
081 * sets the result of parsing directly in the instance <code>result</code> of this class.
082 */ 
083public class ReadStructure
084{
085  //prepareClassData
086  
087  /**Version, history and license.
088   * <ul>
089   * <li>2014-08-16 Hartmut chg: {@link #prepareClassData(Zbnf_ClassData, ZbnfToplevel, ClassData)} invokes recursively for inner classes 
090   *   at end of routine, because the ClassData should be known for the inner classes via fileLevelIdents.
091   * <li>2008 Hartmut created:    
092   * </ul>
093   * <br><br>
094   * <b>Copyright/Copyleft</b>:
095   * For this source the LGPL Lesser General Public License,
096   * published by the Free Software Foundation is valid.
097   * It means:
098   * <ol>
099   * <li> You can use this source without any restriction for any desired purpose.
100   * <li> You can redistribute copies of this source to everybody.
101   * <li> Every user of this source, also the user of redistribute copies
102   *    with or without payment, must accept this license for further using.
103   * <li> But the LPGL is not appropriate for a whole software product,
104   *    if this source is only a part of them. It means, the user
105   *    must publish this part of source,
106   *    but don't need to publish the whole source of the own product.
107   * <li> You can study and modify (improve) this source
108   *    for own using or for redistribution, but you have to license the
109   *    modified sources likewise under this LGPL Lesser General Public License.
110   *    You mustn't delete this Copyright/Copyleft inscription in this source file.
111   * </ol>
112   * If you are intent to use this sources without publishing its usage, you can get
113   * a second license subscribing a special contract with the author. 
114   * 
115   * @author Hartmut Schorrig = hartmut.schorrig@vishia.de
116   */
117  public final static String sVersion = "2014-08-17"; 
118
119  
120  static private Map<String, Object> indexProcessedFiles = new TreeMap<String, Object>();
121        
122  private final Report msg;
123  
124  /**Aggregation to the global data of java2C translator. */
125  final private Java2C_Main java2c;
126  
127  /**The parser for *.stc input files. The parser is initialized with syntax 
128   * from file <code>Java2Cstc.zbnf</code> in directory given with cmd line args 
129   * <code>-syntax:SYNTAXDIR</code> in the routine {@link #init()} 
130   * called in {@link #execute()}. */
131  final ZbnfParser parserStruct;
132
133  //final private List<ClassData> listClassInFile;
134  
135  private String sSourceOfClassData;
136  
137  /**The Java source file for which this instance is created.
138   * 
139   */
140  private JavaSrcTreeFile javaSrc;
141  
142  /**The classData of the top level are to add to userTypes, inner classes are add to classLevelIdents. */
143  private LocalIdents fileLevelIdents;
144    
145  private LocalIdents pkgIdents;
146  
147  public static class Zbnf_EnvIdent
148  {
149    private String[] ident;
150    
151    private String delim;
152    
153    private String name;
154    
155    private Zbnf_EnvIdent subIdent;
156    
157    public Zbnf_EnvIdent new_subIdent(){ return this; } //return new Zbnf_EnvIdent(); }
158    
159    public void add_subIdent(Zbnf_EnvIdent value)
160    {
161      //ident[0] += value + delim;
162      //subIdent = value;  
163    }
164    
165    public void set_name(String value)
166    {
167      ident[0] += value + delim;
168    }
169    
170  }
171  
172  
173  /**Subclass to pour in the result of the <code>field::=...</code> subsyntax.
174   * Only some singleton instances are created:
175   * <ul>
176   * <li>{@link Java2C_Main.ReadStructure.Zbnf_Method#returnType1} to save the return type.
177   *     It is an own instance because the return type will be processed after alle param are processed.
178   * <li>{@link Java2C_Main.ReadStructure.Zbnf_Method#zbnfParam} to save the current param.
179   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#field} to save the current field.
180   * </ul>
181   * They are reused, calling {@link #init()} before, if 
182   * <ul>
183   * <li>{@link Java2C_Main.ReadStructure.Zbnf_Method#new_param()}
184   * <li>{@link Java2C_Main.ReadStructure.Zbnf_Method#new_returnType()} 
185   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#new_field()} 
186   * </ul>
187   * are called because any <code>&lt;field?...></code> were parsed with syntax 
188   * <pre>
189   * field::= <1*?modeAccess><1*?modeArrayElement><1*?modeStatic>;
190   *          [{\[ [\?\?<?arrayDimension>|<*\]?fixArraySizes>]\]}] ;
191   *          <*; ?typeJava> ; <$?typeC> ; <$?name> ; 
192   * </pre>.
193   * If the appropriate methods
194   * <ul>
195   * <li>{@link Java2C_Main.ReadStructure.Zbnf_Method#add_param(org.vishia.java2C.Java2C_Main.ReadStructure.Zbnf_Field)}
196   * <li>{@link Java2C_Main.ReadStructure.Zbnf_Method#add_returnType(org.vishia.java2C.Java2C_Main.ReadStructure.Zbnf_Field)} 
197   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#add_field(org.vishia.java2C.Java2C_Main.ReadStructure.Zbnf_Field)} 
198   * </ul>
199   * are called, the content of the singleton is read out and stored 
200   * in the appropriate destination data structure, that is {@link FieldData}.
201   * This temporary instance is used straighten out, because the structure of syntax 
202   * is not so opportune for storing in {@link FieldData} directly.
203   */
204  public static class Zbnf_Field
205  { private char modeAccess, modeStatic, modeArrayElement;
206    
207    /**Stores the parsed result
208     * inside {@link org.vishia.zbnf.ZbnfJavaOutput#setOutputStrict(Object result, ZbnfParseResultItem, Report)}.
209     * To access the field from there via reflection, it should be public.
210     */
211    public String name, typeJava, instanceType;
212    
213    //private Zbnf_EnvIdent outerClassData;
214    private final String[] outerClassData = new String[1];;
215    
216    //private Zbnf_EnvIdent pkgType;
217    private final String[] pkgType = new String[1];
218    
219    private final Zbnf_EnvIdent envStore = new Zbnf_EnvIdent();
220    
221    /**If <code>&lt;*\]?fixArraySizes></code> is parsed, the String result is added to this list
222     * inside {@link org.vishia.zbnf.ZbnfJavaOutput#setOutputStrict(Object result, ZbnfParseResultItem, Report)}.
223     * To access the field from there via reflection, it should be public.
224     */
225    private final List<String> listFixArraySizes = new LinkedList<String>();
226    
227    private int dimensionArrayOrFixSize;
228    
229    private Zbnf_Field()
230    { modeAccess= '?'; dimensionArrayOrFixSize = 0;
231    }
232    
233    /**Initializes the instance to use.*/
234    void init()
235    { modeArrayElement = modeStatic = modeAccess= '?'; 
236      typeJava = ""; 
237      instanceType = null;
238      name = null;
239      outerClassData[0] = "";
240      pkgType[0] = "";
241      listFixArraySizes.clear();
242      dimensionArrayOrFixSize = 0;
243    }
244
245    public Zbnf_EnvIdent new_outerJava()
246    { //return new Zbnf_EnvIdent(); 
247      envStore.delim = ".";
248      envStore.ident = outerClassData;
249      outerClassData[0] = "";
250      return envStore;
251    }
252    
253    public void add_outerJava(Zbnf_EnvIdent value)
254    {  envStore.ident = null;
255      //outerClassData = value;
256    }
257    
258    public Zbnf_EnvIdent new_packageType()
259    { //return new Zbnf_EnvIdent(); 
260      envStore.delim = "/";
261      envStore.ident = pkgType;
262      pkgType[0] = "";
263      return envStore;
264    }
265    
266    public void add_packageType(Zbnf_EnvIdent value)
267    {  envStore.ident = null;
268      //pkgType = value;
269    }
270    
271    public void set_vaarg()
272    {
273        typeJava = "#*";
274    }
275    
276    /**Sets the parsed <code>modeAccess</code>. Only the first character is used and valid. */
277    public void set_modeAccess(String value){ modeAccess = value.charAt(0);}
278    /**Sets the parsed <code>modeArrayElement</code>. Only the first character is used and valid. */
279    public void set_modeArrayElement(String value){ modeArrayElement = value.charAt(0);}
280    /**Sets the parsed <code>modeStatic</code>. Only the first character is used and valid. */
281    public void set_modeStatic(String value){ modeStatic = value.charAt(0);}
282    
283    //public void set_name(String value){ name = value; }
284
285    /**FromZBNF: field::=  ~~~[??&lt;?arrayDimension>]~~~ : counts the {@link #dimensionArrayOrFixSize}.  */
286    public void set_arrayDimension(){ dimensionArrayOrFixSize +=1; }
287    
288    /**FromZBNF: field::= ~~~  <*\] ?fixArraySizes> ~~~*/
289    public void add_fixArraySizes(String value){ dimensionArrayOrFixSize += 1; listFixArraySizes.add(value); }
290    
291    /**FromZBNF: field::= ~~~ fixSize \[ <#?fixSize> \] ~~~*/
292    public void set_fixSize(int value){ dimensionArrayOrFixSize = value; }
293    
294    @Override
295    public String toString(){ return typeJava; }
296  }
297  
298  /**Subclass to pour in the result of the <code>type::=...</code> subsyntax.
299   * Only a singleton instance is created. It is reused, calling {@link #init()} before, if 
300   * <ul>
301   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#new_type()()} 
302   * </ul>
303   * is called because any <code>&lt;type></code> were parsed with syntax 
304   * <pre>
305   * type::= type; <$?typeName>.
306   * </pre>.
307   * If the appropriate method
308   * <ul>
309   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#add_type(org.vishia.java2C.Java2C_Main.ReadStructure.Zbnf_Type)} 
310   * </ul>
311   * is called, the content of the singleton is read out and stored 
312   * in the appropriate destination data structure, that is {@link ClassData}.
313   * This temporary instance is used straighten out, because the structure of syntax 
314   * is not so opportune for storing in {@link ClassData} directly.
315   */
316  private static class Zbnf_Type
317  { public String typeName;
318    void init(){typeName = null; }
319  }
320  
321  /**Subclass to pour in the result of the <code>method::=...</code> subsyntax.
322   * Only a singleton instance is created. It is reused, calling {@link #init()} before, if 
323   * <ul>
324   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#new_method()} 
325   * </ul>
326   * is called because any <code>&lt;method></code> were parsed with syntax 
327   * <pre>
328   * method::= method ; <*;?keyName> ; <$?javaName> ; <$?CName> ;
329   *           return ; <field?returnType> 
330   *           [{ param ( <field?param> ) }]
331   * </pre>.
332   * If the appropriate methods
333   * <ul>
334   * <li>{@link Java2C_Main.ReadStructure.Zbnf_ClassData#add_method(org.vishia.java2C.Java2C_Main.ReadStructure.Zbnf_Method)} 
335   * </ul>
336   * is called, the content of the singleton is read out and stored 
337   * in the appropriate destination data structure, that is {@link Method}.
338   * This temporary instance is used straighten out, because the structure of syntax 
339   * is not so opportune for storing in {@link Method} directly.
340   */
341  public static class Zbnf_Method
342  {
343    //private final ReadStructure outer;
344
345        private final String sClassIdentNameC;
346        
347    private String sNameJava, sCName, sNameUnambiguous, sImplementationName, sOverriddenName, sKeyName; 
348    
349    private boolean bClassSuffixName;
350    
351    private String sDefPkg, sDefClass, sDefMethodUnambigous;
352    
353    //private final List<FieldData> listParams = new LinkedList<FieldData>();
354    
355    private final Zbnf_Field returnType1 = new Zbnf_Field();
356    
357    private List<Zbnf_Field> zbnfParam;
358    
359    private int modifier;
360    
361    public String implementationSuffix;
362    
363    public Zbnf_Field new_returnType(){ returnType1.init(); return returnType1; }
364    public void add_returnType(Zbnf_Field dummy){} //NOTE: nothing to do, let it filled.
365    
366    public Zbnf_Field new_param(){ 
367        if(zbnfParam==null){ zbnfParam = new LinkedList<Zbnf_Field>(); }
368        Zbnf_Field param1 = new Zbnf_Field();
369        return param1; 
370    }
371    
372    public void add_param(Zbnf_Field param1)
373    {
374      zbnfParam.add(param1);
375    }
376    
377    public void set_keyName(String value){ sKeyName = value; }
378    
379    /**From ZBNF: method::= ... <$?javaName>... */
380    public void set_javaName(String value){ sNameJava = value; }
381    
382    public void set_NameUnambiguous(String value){ sNameUnambiguous = value; }
383    
384    public void set_CName(String value){ sCName = value; }
385    
386    public void set_ImplementationName(String value){ sImplementationName = value; }
387    
388    
389    
390    public void set_OverriddenName(String value){ sOverriddenName = value; }
391    
392    /**From ZBNF: method::= ... mode: { ... noThCxt<?modeNoThCxt>...} */
393    public void set_modeNoThCxt(){modifier |= Method.modeNoThCxt; }
394    
395    /**From ZBNF: method::= ... mode: { ... overrideable<?modeOverrideable>...} */
396    public void set_modeOverrideable(){modifier |= Method.modeOverrideable; }
397    
398    /**From ZBNF: method::= ... mode: { ... returnThis<?modeReturnThis>...} */
399    public void set_modeReturnThis(){modifier |= Method.modeReturnThis; }
400    
401    /**From ZBNF: method::= ... mode: { ... returnThis<?modeReturnThis>...} */
402    public void set_modeReturnNew(){modifier |= Method.modeReturnNew; }
403    
404    /**From ZBNF: method::= ... mode: { ... returnThis<?modeReturnThis>...} */
405    public void set_modeReturnNonPersistring(){modifier |= Method.modeReturnNonPersistring; }
406    
407    /**From ZBNF: method::= ... mode: { ... static<?modeStatic>...} */
408    public void set_modeStatic(){modifier |= Method.modeStatic; }
409    
410    /**From ZBNF: method::= ... mode: { ... noStacktrace<?modeNoStacktrace>...} */
411    public void set_modeNoStacktrace(){modifier |= Method.modeNoStacktrace; }
412    
413    /**From ZBNF: method::= ... mode: { ... ctor<?modeCtor>...} */
414    public void set_modeCtor(){modifier |= Method.modeCtor; }
415    
416    /**From ZBNF: method::= ... mode: { ... <?modeCtorNonStatic>...} */
417    public void set_modeCtorNonStatic(){modifier |= Method.modeCtorNonStatic; }
418    
419    /**From ZBNF: method::= ... mode: { ... <?modeCtorAnonymous>...} */
420    public void set_modeCtorAnonymous(){modifier |= Method.modeCtorAnonymous; }
421    
422    /**From ZBNF: method::= ... <$?unambigouosName>... */
423    public void set_unambigouosName(String value){ sNameUnambiguous = sNameJava + value; }
424    
425    /**From ZBNF: method::= ... <$?suffixName>... */
426    public void set_suffixName(String value)
427    { if(sNameUnambiguous == null){ sNameUnambiguous = sNameJava; } 
428      sCName = sNameUnambiguous + value; 
429    }
430    
431    
432    /**From ZBNF: method::= ... [$<?classSuffixName>]... */
433    public void set_classSuffixName()
434    { if(sNameUnambiguous == null){ sNameUnambiguous = sNameJava; } 
435      if(sCName == null){ sCName = sNameUnambiguous; } 
436      sCName += sClassIdentNameC; 
437      bClassSuffixName = true;
438    }
439    
440    /**From ZBNF: method::= ... <.toLastCharIncl:/?defPkg>... */
441    public void set_defPkg(String value){ sDefPkg = value; }
442    
443    /**From ZBNF: method::= ... <*\.?defClass>... */
444    public void set_defClass(String value){ sDefClass = value; }
445    
446    /**From ZBNF: method::= ... <$?defMethodUnambigous>... */
447    public void set_defClassAndMethodUnambigous(String value)
448    { sDefMethodUnambigous = value; 
449    }
450    
451    
452    //Zbnf_Method(Java2C_Main java2c)
453    //{ this.java2c = java2c;
454    Zbnf_Method(String sClassIdentNameC) //ReadStructure outer)
455    { this.sClassIdentNameC = sClassIdentNameC;
456        //this.outer = outer;
457    }
458    
459    private void init()
460    { returnType1.init();
461      //param.init();
462      //listParams.clear();
463      sNameJava = sCName = sKeyName = sNameUnambiguous = sOverriddenName = sDefMethodUnambigous = null;
464      sDefClass = sDefPkg = null;
465      modifier = 0;
466    }
467  }
468  
469  /** @Uml=composite*/
470  //final Zbnf_Method zbnfMethod; 
471  
472  public static class Zbnf_Cast
473  {
474        public String typeJava;
475        public String accessDst;
476        public String accessSrc;
477        public String castExpr;
478        
479        void init()
480        { 
481                
482        }
483  }
484  
485  
486  /**Subclass to pour in the result of the <code>ClassData::=...</code> subsyntax.
487   * Only a singleton instance {@link Java2C_Main.ReadStructure#zbnfClassData} is created. 
488   * It is reused, calling {@link #init()} before, if 
489   * <ul>
490   * <li>{@link Java2C_Main.ReadStructure#new_ClassData()} 
491   * </ul>
492   * is called because any <code>&lt;ClassData>></code> were parsed with syntax 
493   * <pre>
494   * ClassData::= <*; ?nameJava> ; <$?nameC> ; 
495   * \{ [ fieldIdents \{ [{ field; <field> }] \}]
496   *    [ typeIdents \{ [{ <type> | class <ClassData?InnerClassData> }] \}]
497   *    [ methods \{ [{ <method> }] \}]
498   *    [ InnerClass \{ [{ class <ClassData?InnerClassData> }] \}]
499   * \}.
500   * </pre>.
501   * If the appropriate method
502   * <ul>
503   * <li>{@link Java2C_Main.ReadStructure#add_ClassData(org.vishia.java2C.Java2C_Main.ReadStructure.Zbnf_ClassData)} 
504   * </ul>
505   * is called, the content of the singleton is read out and stored 
506   * in the appropriate destination data structure, that is {@link ClassData}.
507   * This temporary instance is used straighten out, because the structure of syntax 
508   * is not so opportune for storing in {@link ClassData} directly.
509   */
510  public static class Zbnf_ClassData
511  { 
512    private String sFileName; 
513    
514    /**Some properties. */
515    private boolean bIsStaticInstance, bFinal, bInterface, bStaticInner, bExtern, bEmbedded, bAbstract, bConst;
516    private boolean nonStaticInner, anonymous;
517    
518    private char intension;
519    
520    private final ReadStructure outer;
521    
522    private String sNameC, sClassIdentNameC;
523    
524    public String header, nameJava, argIdent;
525    
526    /**temporary list of IdentInfos to add to ClassData. */
527    private final List<Zbnf_Field> listFields = new LinkedList<Zbnf_Field>();
528    
529    /**temporary list of Method to add to ClassData. */
530    private final List<Zbnf_Method> listMethods = new LinkedList<Zbnf_Method>();
531    
532    /**temporary list of Method to add to ClassData. */
533    private final List<String> listMethodsOverrideableC = new LinkedList<String>();
534    
535    /**The ClassData were set if the first field, method is set.
536     * it is because the ClassData of the own class may be necessary in the own fields, methods.
537     */
538    private ClassData classData;
539    
540    private String sSuperClass;
541    
542    private List<String> listInterfaceClass;
543    
544    private final Zbnf_Field zbnf_field = new Zbnf_Field();
545    
546    private final Zbnf_Type zbnf_type = new Zbnf_Type();
547    
548    private List<Zbnf_ClassData> zbnfInnerClassData; 
549    
550    private final List<Zbnf_Cast> zbnfCastTo = new LinkedList<Zbnf_Cast>();
551    
552    private final List<Zbnf_Cast> zbnfCastFrom = new LinkedList<Zbnf_Cast>();
553
554    private final ClassData outerClass;
555    
556    private Zbnf_ClassData(ClassData outerClass, ReadStructure outer)
557    { assert(false);
558        this.outerClass = outerClass;
559      this.outer= outer;
560    }
561    
562    private Zbnf_ClassData()
563    { this.outerClass = null;
564        this.outer= null;
565    }
566  
567    
568    /**From ZBNF: ClassData::= ... interface<?interface>... */
569    public void set_interface(){ bInterface = true; }
570    
571    /**From ZBNF: ClassData::= ... final<?final>... */
572    public void set_final(){ bFinal = true; }
573    
574    /**From ZBNF: ClassData::= ... extern<?extern>... */
575    public void set_extern(){ bExtern = true; }
576    
577    /**From ZBNF: ClassData::= ... embedded<?embedded>... */
578    public void set_embedded(){ bEmbedded = true; }
579    
580    /**From ZBNF: ClassData::= ... embedded<?embedded>... */
581    public void set_abstract(){ bAbstract = true; }
582    
583    /**From ZBNF: ClassData::= ... embedded<?embedded>... */
584    public void set_const(){ bConst = true; }
585    
586    /**From ZBNF: ClassData::= ... embedded<?embedded>... */
587    public void set_nonStaticInner(){ nonStaticInner = true; }
588    
589    /**From ZBNF: ClassData::= ... embedded<?embedded>... */
590    public void set_anonymous(){ anonymous = true; intension = 'Y'; }
591    
592    /**From ZBNF: ClassData::= ... embedded<?embedded>... */
593    public void set_statementBlock(String value){ intension = value.charAt(0); }
594    
595    /**From ZBNF: ClassData::=  nameC = <$?nameC>.
596     * Sets the {@link #sClassIdentNameC} too. 
597     * Note: if the nameC ends with "_s" or "_i", then the {@link #sClassIdentNameC} is without this suffix.
598     * */
599    public void set_nameC(String value){
600        sNameC = value;
601        if(sNameC.endsWith("_s") || sNameC.endsWith("_i"))
602      { sClassIdentNameC = sNameC.substring(0, sNameC.length()-2); }
603      else{ sClassIdentNameC = sNameC; }
604    }
605    
606    /**From ZBNF: ClassData::= ... extends <$?superClassC>... */
607    public void set_superClass(String value){ sSuperClass = value; }
608    
609    /**From ZBNF: ClassData::= ... implements { <?interfaceClassC> ? ,}... */
610    public void add_interfaceClass(String value)
611    { if(listInterfaceClass == null){ listInterfaceClass = new LinkedList<String>(); }
612      listInterfaceClass.add(value); 
613    }
614    
615    public Zbnf_Field new_field()
616    { return new Zbnf_Field();
617        //zbnf_field.init();
618      //return zbnf_field;
619    }
620    
621    public void add_field(Zbnf_Field field) throws IllegalArgumentException, IllegalAccessException, InstantiationException, ParseException
622    { listFields.add(field);      
623    }
624
625    /**From ZBNF: ClassData::= ... methods \{ [{ <method> }] \}... */
626    public Zbnf_Method new_method()
627    { return new Zbnf_Method(sClassIdentNameC);
628    }
629    
630    /**From ZBNF: ClassData::= ... methods \{ [{ <method> }] \}... 
631     * @throws ParseException */
632    public void add_method(Zbnf_Method method) 
633    { listMethods.add(method);
634    }
635    
636    /**From ZBNF: ClassData::= ... { <$?methodOverridableC> ; }... */
637    public void add_methodOverridableC(String value){ listMethodsOverrideableC.add(value); }
638    
639    /**From ZBNF: ClassData::= ... castTo \{ [{ castTo> }] \}... */
640    public Zbnf_Cast new_castTo()
641    { return new Zbnf_Cast(); 
642    }
643    
644    
645    public void add_castTo(Zbnf_Cast value)
646    { zbnfCastTo.add(value);
647    }
648    
649    
650    /**From ZBNF: ClassData::= ... castTo \{ [{ castTo> }] \}... */
651    public Zbnf_Cast new_castFrom()
652    { return new Zbnf_Cast(); 
653    }
654    
655    
656    public void add_castFrom(Zbnf_Cast value)
657    { zbnfCastFrom.add(value);
658    }
659    
660    
661    public Zbnf_Type new_type()
662    { zbnf_type.init();
663      return zbnf_type; 
664    }
665    
666    /**A Inner class is detected in ZBNF-parse-result because < ClassData?InnerClassData >.
667     * Based on this, an empty instance of Zbnf_ClassData is returned to fill it. 
668     * @return
669     */
670    public Zbnf_ClassData new_InnerClassData()
671    { /**creates the outer class. */
672      /*
673        createClassDataIfNotDone();
674      if(zbnfInnerClassData == null) 
675      { zbnfInnerClassData = new Zbnf_ClassData(classData, outer); }
676      zbnfInnerClassData.init(sFileName);
677      return zbnfInnerClassData;
678      */
679        return new Zbnf_ClassData();
680    }
681
682    /**The inner class is filled now. Invoked from ZbnfJavaOutput, creates a new ClassData instance, fills it with given Input
683     * and add it to the outer class clazzLevelEndents.
684     * @param zbnfInput
685     */
686    public void add_InnerClassData(Zbnf_ClassData zbnfInput)
687    { if(zbnfInnerClassData ==null){ zbnfInnerClassData = new LinkedList<Zbnf_ClassData>(); }
688        zbnfInnerClassData.add(zbnfInput);
689    }
690
691    public void add_type(Zbnf_Type value)
692    { 
693      
694    };
695    
696    
697    
698    //public void set_className(String value){ sName = value; }
699    
700    private void init(String sFileName)
701    { this.sFileName = sFileName; sNameC = nameJava = null; bIsStaticInstance = false; bFinal = false;
702      bFinal = bIsStaticInstance = bInterface = bExtern = bEmbedded = bAbstract = bConst = false;
703      sSuperClass = sNameC = nameJava = null;
704      if(listInterfaceClass != null) { listInterfaceClass.clear(); }
705      listFields.clear();
706      listMethods.clear();
707      listMethodsOverrideableC.clear();
708      zbnf_field.init();
709      zbnf_type.init();
710      //if(zbnfInnerClassData != null){ zbnfInnerClassData.init(sFileName); }
711      classData = null;
712    }
713    
714    
715    @Override public String toString(){ return sClassIdentNameC; }
716    
717    void stop(){}
718  }
719  
720  public static class ZbnfToplevel
721  {
722          /** @Uml=composite. */
723          final private List<Zbnf_ClassData> zbnfClassData = new LinkedList<Zbnf_ClassData>(); 
724          
725          public String sFileName;
726          
727          /**The package to which the classes are associated in the stc-file. */
728          private String packageStc;
729          
730          public void set_package(String value){ packageStc = value; }
731          
732          /**set content, able to call from ZbnfJavaOutput. */
733          public void set_fileName(String value)
734          { sFileName= value; }
735          
736          
737          public void set_version(float value)
738          { if(value < 0.939)
739            { throw new IllegalArgumentException("Version conflict."); }
740          }
741          
742          public void set_encoding(String value)
743          {
744            
745          }
746          
747          public Zbnf_ClassData new_ClassData()
748          { //ZbnfClassData obj = new ZbnfClassData();
749            //obj.sFileName = sFileName;
750            //return obj;
751            //zbnfClassData.init(sFileName);
752            return new Zbnf_ClassData();
753          }
754          
755          /**Invoked from ZbnfJavaOutput, creates a new ClassData instance, fills it with given Input
756           * and add it to the userTypes.
757           * @param zbnfInput
758           */
759          public void add_ClassData(Zbnf_ClassData zbnfInput)
760          {
761                zbnfClassData.add(zbnfInput);
762          }
763          
764          
765  }
766  
767  //ReadStructure(Java2C_Main java2c, List<ClassData> listClassInFile, Report msg)
768  ReadStructure(Java2C_Main java2c, Report msg, String sSyntaxPath) throws ParseException
769  { this.java2c = java2c;
770    //this.listClassInFile = listClassInFile;
771    this.msg = msg;
772    parserStruct = new ZbnfParser(msg, 10);
773    parserStruct.setReportIdents(Report.error, Report.info, Report.fineDebug, Report.fineDebug);
774    { File fileSyntaxStruct = null;
775      fileSyntaxStruct= new File(sSyntaxPath + "/Java2Cstc.zbnf"); //"../../srcJava/org/vishia/Java2C/Java2C.zbnf");
776      String sSyntaxStruct;
777      sSyntaxStruct = FileSystem.readFile(fileSyntaxStruct);
778      if(sSyntaxStruct == null)
779      { throw new IllegalArgumentException("syntaxfile not found, error arg -syntax:" + sSyntaxPath + "/Java2Cstc.zbnf");
780      }
781      else
782      { parserStruct.setSyntax(sSyntaxStruct);
783        //parser.reportSyntax(console);
784      }
785    }  
786
787  }
788
789  
790  
791  /**reads the structure of a class from a *.stc-File and save it to the {@link #userTypes}-{@link ClassData}.
792   * @param sClassFileName The name of the Java class.
793   * @throws FileNotFoundException
794   * @throws IOException
795   * @throws IllegalArgumentException
796   * @throws IllegalAccessException
797   * @throws InstantiationException
798   * @throws ParseException 
799   */
800  public void readStructToClassData(JavaSrcTreeFile javaSrc, String sClassFileName, File fileStruct) 
801  throws FileNotFoundException, IOException, IllegalArgumentException, IllegalAccessException, InstantiationException, ParseException
802  { //???
803    //ClassData classForwardOrExternal = new ClassData(sClassName, sClassName, sClassName, null, "+extern+");
804    //The put class will be replaced if it is found.
805    //userTypes.putClassType(sClassName, sClassName, classForwardOrExternal, "C", null);
806    
807    //File fileStruct = new File(sPathOut + sClassFileName + ".stc");
808    if(fileStruct == null){
809      throw new ParseException("no stc-File found for: " 
810          + javaSrc.getFileJava()+ ", header: " + javaSrc.getFileNameC(), 0);
811    }
812    Report console = msg;
813    String sAbsPath = fileStruct.getAbsolutePath();
814    Object sTest = indexProcessedFiles.get(sAbsPath);
815    if(sTest !=null)
816        stop();
817    indexProcessedFiles.put(sAbsPath, sAbsPath);
818    this.sSourceOfClassData = sAbsPath; 
819    this.javaSrc = javaSrc;
820    if(javaSrc.getPublicClassName().equals("InspcDataExchange"))
821        stop();
822    this.pkgIdents = javaSrc.getPkgLevelTypes();
823    this.fileLevelIdents = new LocalIdents(javaSrc.getPkgPath()+ "/@/");
824    this.fileLevelIdents.putClassTypesAll(pkgIdents); //copy because used types imported in file are added.
825    if(fileStruct.exists())
826    { StringPartScan spStruct = new StringPartFromFileLines(fileStruct, 100000, null, null);
827      boolean bOk = parserStruct.parse(spStruct);
828      if(!bOk)
829      { console.writeError("parse error in file:" + fileStruct.getAbsolutePath() + ": " + parserStruct.getSyntaxErrorReport());
830      }
831      else
832      { console.writeInfo("parse OK:" + fileStruct.getAbsolutePath() + ".");
833        parserStruct.reportStore(console, Report.debug);
834        ZbnfParseResultItem zbnfStruct = parserStruct.getFirstParseResult();
835
836        final ZbnfToplevel zbnfToplevel = new ZbnfToplevel();
837        ZbnfJavaOutput.setOutputStrict(zbnfToplevel, zbnfStruct, console);
838        postPrepare(zbnfToplevel);
839        writeResultAsSecondToCompare(zbnfToplevel, fileStruct, javaSrc.getPkgPath(), javaSrc.getFileNameC());
840      }
841    } else
842    { console.writeInfoln("read stc - file not found: " + fileStruct.getCanonicalPath());
843    }
844  }
845  
846
847
848  void writeResultAsSecondToCompare(ZbnfToplevel zbnfToplevel, File fileStruct, String sPkgPath, String sClassFileName) 
849  throws IOException{
850        String sFileName = fileStruct.getName();
851    String sPath = fileStruct.getParent();
852        File dir = new File(sPath+"/stcCmp");
853        if(dir.exists() && dir.isDirectory()){
854            List<ClassData> listClassInFile = new LinkedList<ClassData>();
855                for(Zbnf_ClassData zbnfClass: zbnfToplevel.zbnfClassData){
856                        listClassInFile.add(zbnfClass.classData);
857                }
858            
859            //File fileStructSecond = new File(fileStruct.getAbsoluteFile()+".sec");
860            File fileStructSecond = new File(sPath+"/stcCmp/"+sFileName);
861            if(sClassFileName.equals("LogMessage"))
862                stop();
863            GenerateFile.writeStructure(fileStructSecond, sClassFileName, listClassInFile, sPkgPath);
864        }
865  }
866
867
868
869  
870  
871  
872  /**Build the classData of the read stc-data.
873   * @throws ParseException 
874   * @throws InstantiationException 
875   * @throws IllegalAccessException 
876   * @throws IllegalArgumentException 
877   * @throws IOException 
878   * @throws FileNotFoundException 
879   * 
880   */
881  public void postPrepare(ZbnfToplevel zbnfToplevel) 
882  throws IllegalArgumentException, IllegalAccessException, InstantiationException, ParseException, FileNotFoundException, IOException
883  {
884        for(Zbnf_ClassData zbnfClass: zbnfToplevel.zbnfClassData){
885                prepareClassData(zbnfClass, zbnfToplevel, null);
886        }
887        for(Zbnf_ClassData zbnfClass: zbnfToplevel.zbnfClassData){
888                prepareClassFieldMethod(zbnfClass);
889        }  
890        for(Zbnf_ClassData zbnfClass: zbnfToplevel.zbnfClassData){
891            ClassData classData = zbnfClass.classData;
892            if(classData.outerClazz == null){
893              //only for top-level classes:
894                classData.completeTypesForInnerClasses();
895                        classData.completeFieldIdentsForInnerClasses();
896                }
897        }
898    //at last remove the parsed meta-informations, let the garbage collector tidy up.
899    zbnfToplevel = null;
900    System.gc();
901    //System.getProperty("");
902  }
903  
904  
905  
906  private void prepareClassFieldMethod(Zbnf_ClassData zbnfInput) 
907  throws IllegalArgumentException, IllegalAccessException, InstantiationException, ParseException, FileNotFoundException, IOException
908  { ClassData classData = zbnfInput.classData;
909        for(Zbnf_Field field: zbnfInput.listFields)
910    { FieldData fieldData = prepareField(field, classData);
911        classData.classLevelIdents.putClassElement(fieldData.getName(), fieldData);
912    }
913    for(Zbnf_Method zbnfMethod: zbnfInput.listMethods)
914    { 
915        prepareMethod(zbnfMethod, classData);
916    }
917    for(Zbnf_Cast zbnfCast: zbnfInput.zbnfCastTo){
918        ClassData dstType = classData.classLevelIdents.getType(zbnfCast.typeJava, fileLevelIdents);
919        classData.addCastToType(dstType, zbnfCast.castExpr, zbnfCast.accessDst + zbnfCast.accessSrc);
920    }
921    for(Zbnf_Cast zbnfCast: zbnfInput.zbnfCastFrom){
922        ClassData srcType = classData.classLevelIdents.getType(zbnfCast.typeJava, fileLevelIdents);
923        classData.addCastFromType(srcType, zbnfCast.castExpr, zbnfCast.accessDst + zbnfCast.accessSrc);
924    }
925    //do not call zbnfInput.classData.completeInheritanceWithOwnMethods();
926    //because the methods are ordered in another way.
927    //Instead, the order of overrideable methods are contained in an extra part
928    //of the stc-file. This is the order of method-table-entries. Use it!
929    if(zbnfInput.listMethodsOverrideableC.size() >0){
930      zbnfInput.classData.completeInheritanceWithListMethods(zbnfInput.listMethodsOverrideableC);
931    }
932    if(zbnfInput.zbnfInnerClassData !=null)
933    for(Zbnf_ClassData zbnfInnerClass : zbnfInput.zbnfInnerClassData){
934        prepareClassFieldMethod(zbnfInnerClass);
935    }
936  }
937  
938  
939  
940  public void prepareClassData(Zbnf_ClassData zbnfInput, ZbnfToplevel zbnfToplevel
941        , ClassData outerClassData) 
942  throws IllegalArgumentException, IllegalAccessException, InstantiationException, ParseException
943  { //zbnfInput.createClassDataIfNotDone();
944    ClassData superClass = null;
945    if(zbnfInput.sSuperClass != null){
946      
947      try{ 
948        //superClass = outer.fileLevelIdents.getTypeContingentlyRunFirstPass(sSuperClass, outer.java2c); 
949        superClass = fileLevelIdents.getType(zbnfInput.sSuperClass, null); 
950      }
951      catch(Exception exc){
952        msg.reportln(Report.error, "Exception reading " + zbnfInput.sSuperClass + ": " + exc.getMessage());
953        throw new IllegalArgumentException(exc.getMessage());
954        //superClass = null;
955      }
956    }
957    
958    ClassData[] ifcClasses = null;
959    if(zbnfInput.listInterfaceClass != null){
960      ifcClasses = new ClassData[zbnfInput.listInterfaceClass.size()];
961      int ixIfcClasses = 0;
962      for(String sIfcClass: zbnfInput.listInterfaceClass){
963        ClassData ifcClass;
964        try{ 
965          //ifcClass = outer.fileLevelIdents.getTypeContingentlyRunFirstPass(sIfcClass, outer.java2c); 
966          if(sIfcClass.equals("org/vishia/msgDispatch/LogMessage"))
967                stop();
968                ifcClass = fileLevelIdents.getType(sIfcClass, null); 
969        }
970        catch(Exception exc){
971          ifcClass = null;
972          msg.reportln(Report.error, "Exception \"" + exc.getMessage() + "\" reading " + sIfcClass );
973          msg.report("", exc);
974        }
975        ifcClasses[ixIfcClasses++] = ifcClass;
976      }
977    }
978    
979    if(zbnfInput.nameJava.equals("LogMessage") || zbnfInput.nameJava.equals("ExpandedDataStruct"))
980      stop();
981    String fileC = outerClassData !=null ? outerClassData.sFileName 
982                   : zbnfInput.header != null ? zbnfInput.header 
983                   : zbnfToplevel.sFileName;
984    String sProp = "+";
985    if(zbnfInput.bIsStaticInstance){sProp +="static+"; }
986    if(zbnfInput.bFinal){sProp +="final+"; }
987    if(zbnfInput.bEmbedded){sProp +="embedded+"; }
988    if(zbnfInput.bAbstract){sProp +="abstract+"; }
989    if(zbnfInput.bConst){sProp +="const+"; }
990    if(zbnfInput.bExtern){sProp +="extern+"; }
991    if(zbnfInput.bInterface){sProp +="interface+"; }
992    if(zbnfInput.nonStaticInner){ sProp += "nonStaticInner+"; }
993    if(fileC.endsWith(".h")){ fileC = fileC.substring(0, fileC.length()-2); }
994    final char intension = zbnfInput.intension != '\0' ? zbnfInput.intension 
995                           : outerClassData ==null? 'P' : 'C';  //intension only given for inner classes
996    final boolean bStringJc = zbnfInput.sNameC.equals("StringJc");
997    final char modeAccess = zbnfInput.bEmbedded ? '$' : bStringJc ? 't' : '*';
998    ClassData classData = new ClassData(sSourceOfClassData, null, fileC, zbnfToplevel.packageStc, zbnfInput.nameJava, zbnfInput.sNameC
999        , zbnfInput.argIdent, 'L', outerClassData ,superClass, ifcClasses, null
1000        , modeAccess, sProp, intension);
1001    
1002    zbnfInput.classData = classData;  //note it there for adding fields, methods.
1003    
1004    //prepareClassData(zbnfInnerClass,... shifted after next block, because the classData should be known for the inner classes via fileLevelIdents.
1005    
1006    if(outerClassData != null){
1007      //An inner class: put the type to its classlevelIdents, 
1008      outerClassData.classLevelIdents.putClassType(classData);
1009      //and remark the inner class to complete it with the type too (see next)
1010        outerClassData.addInnerClass(classData);
1011    }
1012    else if(zbnfInput.nameJava.equals(javaSrc.getTypeName())){
1013      //The public class of the file is translated: set the classData. */
1014        javaSrc.setClassData(classData);
1015    } else {
1016      /**Additional classes in the file are found. They were unknown until now, register it. */
1017      pkgIdents.putClassType(classData); //replace JavaSrcFile with ClassData!
1018      fileLevelIdents.putClassType(classData.sClassNameJava, classData);
1019    }
1020    
1021    //with known ClassData in fileLevelIdents or in javaSrc: Prepare the inner classes.
1022    if(zbnfInput.zbnfInnerClassData !=null) for(Zbnf_ClassData zbnfInnerClass : zbnfInput.zbnfInnerClassData) {
1023      prepareClassData(zbnfInnerClass, zbnfToplevel, classData);
1024    }
1025
1026  }
1027  
1028  
1029  
1030  
1031  
1032  public FieldData prepareField(Zbnf_Field field, ClassData classData) 
1033  throws IllegalArgumentException, IllegalAccessException, InstantiationException, ParseException
1034  { //createClassDataIfNotDone(); 
1035    if(field.typeJava.equals("java/io/FileWriter"))
1036        stop();
1037        if(field.name.equals("sFormatter") && classData.sClassNameJava.equals("SetValueGenerator"))
1038      stop();
1039    ClassData typeClass;
1040    if(field.outerClassData[0] != null && field.outerClassData[0].length() >0)
1041    { int posDelim = field.outerClassData[0].indexOf('.');
1042      String sOuterName = field.outerClassData[0].substring(0, posDelim);
1043      //ClassData outerType = outer.fileLevelIdents.getTypeContingentlyRunFirstPass(sOuterName, outer.java2c);  
1044      ClassData outerType = fileLevelIdents.getType(sOuterName, null);  
1045      sOuterName = field.outerClassData[0].substring(posDelim+1);
1046      //Zbnf_EnvIdent itemEnv = field.outerClassData;
1047      //while((itemEnv = itemEnv.subIdent)!= null)
1048      while((posDelim = sOuterName.indexOf('.'))>0)
1049      { /**Type inside the outer type. */
1050        //String subIdent = itemEnv.name;
1051        String subIdent = sOuterName.substring(0, posDelim);
1052        outerType = outerType.classLevelIdents.getType(subIdent, null);  //fileLevelIdents=null
1053        sOuterName =sOuterName.substring(posDelim+1);
1054      }
1055      typeClass = outerType.classLevelIdents.getType(field.typeJava, null);
1056    }
1057    else
1058    { /**Gets the typeclass also as local visibility inner class (?) */
1059      //typeClass = classData.classLevelIdents.getTypeContingentlyRunFirstPass(field.typeJava, outer.java2c);
1060      typeClass = classData.classLevelIdents.getType(field.typeJava, fileLevelIdents);
1061    }
1062    if(typeClass == null)
1063    { throw new IllegalArgumentException("Type:" + field.typeJava + " not found for field:" + field.name);
1064        //typeClass = Java2C_Main.createExternalType(field.typeJava, field.pkgType[0]);
1065    }
1066    
1067    ClassData instanceClass = null;
1068    if(field.instanceType != null){
1069      //instanceClass = classData.classLevelIdents.getTypeContingentlyRunFirstPass(field.instanceType, outer.java2c);
1070      instanceClass = classData.classLevelIdents.getType(field.instanceType, fileLevelIdents);
1071    }
1072    
1073    if(field.name.equals("ifc"))
1074      stop();
1075    FieldData identInfo = createFieldData
1076    ( field.name, typeClass, instanceClass, null, null, field.modeStatic, field.modeAccess
1077    , field.modeArrayElement, field.dimensionArrayOrFixSize, field.listFixArraySizes, classData
1078    );
1079    identInfo.nClassLevel = 1;  //class elements.
1080    identInfo.nOuterLevel = 1;  //not copied from outer class
1081    return identInfo;      
1082  }
1083  
1084  
1085  public void prepareMethod(Zbnf_Method m, ClassData classData) throws FileNotFoundException, IllegalArgumentException, IOException, IllegalAccessException, InstantiationException, ParseException
1086  {
1087    if(m.sCName == null){
1088        m.sCName = m.sNameJava;  //it is the same, only by simple basicly classes.
1089    }
1090        
1091        if(m.sNameJava.equals("os_getDateTime"))
1092      stop();
1093    //ClassData typeClass = classData.classLevelIdents.getTypeContingentlyRunFirstPass(m.returnType1.typeJava, outer.java2c);
1094    ClassData typeClass = classData.classLevelIdents.getType(m.returnType1.typeJava, fileLevelIdents);
1095    if(typeClass ==null)throw new IllegalArgumentException("no ClassData found for:" + m.returnType1.typeJava);
1096    final char modeStatic;
1097    if((m.modifier & Method.modeReturnNonPersistring) !=0){
1098      assert(m.returnType1.modeStatic == '.');
1099      modeStatic = 'r';
1100    } else {
1101        modeStatic = m.returnType1.modeStatic;  
1102    }
1103    FieldData returnType = createFieldData
1104    ( m.returnType1.name, typeClass, null, null, null, modeStatic, m.returnType1.modeAccess
1105    , m.returnType1.modeArrayElement, m.returnType1.dimensionArrayOrFixSize, m.returnType1.listFixArraySizes, null);
1106    final FieldData[] params;
1107    final int sizeParams;
1108    if(m.zbnfParam !=null){
1109      sizeParams = m.zbnfParam.size();
1110            params = new FieldData[sizeParams];
1111            int idxParam = -1;  //use pre-increment
1112            //for(FieldData param: m.listParams)
1113            for(Zbnf_Field zbnfParam: m.zbnfParam)
1114            { if(zbnfParam.typeJava.equals("#*")){
1115                  //last is a variable argument identification:
1116                  params[++idxParam] = CRuntimeJavalikeClassData.clazz_va_argRaw.classTypeInfo;
1117                if(idxParam != params.length-1) throw new IllegalArgumentException("method: "+ m.sCName + ": The ..." + zbnfParam.name + "designation should be the last argument!");      
1118              }else {
1119                        FieldData paramField = prepareParam(zbnfParam, classData);
1120                        params[++idxParam] = paramField;
1121              } 
1122            }
1123    } else {
1124        params = null;
1125        sizeParams = 0;
1126    }
1127    /**complete non-given data: */
1128    if(m.sNameUnambiguous == null){ m.sNameUnambiguous = m.sNameJava; } 
1129    if(m.sCName == null){ m.sCName = m.sNameUnambiguous; } 
1130    String sKeyName = m.sNameJava + '#' + sizeParams;
1131    if(m.sNameJava.equals("anotherIfcmethod"))
1132      stop();
1133    final String sImplementationName = m.implementationSuffix == null ? null 
1134                : m.sCName + m.implementationSuffix;
1135    if(sImplementationName != null)
1136        stop();
1137    final String sNameUnambiguous = (!m.bClassSuffixName ? "!":"") + m.sNameUnambiguous; //special case !Name
1138    classData.addMethod(m.sNameJava, sNameUnambiguous, sImplementationName, m.modifier, returnType, params);
1139    //Method method = new Method(classData, null, sKeyName, m.sNameJava, m.sNameUnambiguous, m.modifier, returnType, params, null, "");
1140    //listMethods.add(method);
1141  }
1142  
1143  public void prepareCastTo(Zbnf_Cast value, ClassData classData) throws ParseException
1144  {
1145        ClassData dstType = classData.classLevelIdents.getType(value.typeJava, fileLevelIdents);
1146        classData.addCastToType(dstType, value.castExpr, value.accessDst + value.accessSrc);
1147  }
1148  
1149  public FieldData prepareParam(Zbnf_Field param, ClassData classData) 
1150  throws FileNotFoundException, IllegalArgumentException, IOException, IllegalAccessException, InstantiationException, ParseException
1151  {
1152    //ClassData typeClass = outer.fileLevelIdents.getTypeContingentlyRunFirstPass(param.typeJava, outer.java2c);
1153    if(param.typeJava.equals("MemC") || param.typeJava.equals("org/vishia/java2C/test/TestWaitNotify.WaitNotifyData"))
1154        stop();
1155    if(param.name.equals("MemC"))
1156        stop();
1157    ClassData typeClass = classData.classLevelIdents.getType(param.typeJava, fileLevelIdents);
1158        if(typeClass == null)
1159                throw new IllegalArgumentException("Type not found: " + param.typeJava
1160                        + "\n  Hint: A type should be given with full path while using in an stc-files, to find it in the package replacement.");
1161    //ClassData typeClass = outer.fileLevelIdents.getType(param.typeJava, null);
1162    
1163    FieldData identInfo = createFieldData
1164    ( param.name, typeClass, null, null, null, param.modeStatic, param.modeAccess
1165    , param.modeArrayElement, param.dimensionArrayOrFixSize, param.listFixArraySizes, null);
1166    return identInfo;
1167  }
1168
1169  
1170  FieldData createFieldData
1171  ( String sName
1172    , ClassData typeClazz
1173    , ClassData instanceClass
1174    , ClassData elementClass
1175    , ClassData keyClass
1176    , char modeStatic
1177    , char modeAccess
1178    , char modeArrayElement
1179    , int dimensionArray
1180    , List<String> listFixArraySizes
1181    , ClassData declaringClazz
1182    ) {
1183    final String[] fixArraySizes;
1184          if(listFixArraySizes != null){
1185            int zFixArraySizes = listFixArraySizes.size();
1186            fixArraySizes = zFixArraySizes == 0 ? null : new String[zFixArraySizes];
1187            int ixFixArraySizes = 0;
1188            for(String fixArraySize: listFixArraySizes) {
1189              fixArraySizes[ixFixArraySizes++] = fixArraySize;
1190            }
1191          }else{
1192            fixArraySizes = null;
1193          }
1194          //
1195        FieldData fieldData = new FieldData(sName, typeClazz, instanceClass, elementClass, keyClass
1196                , modeStatic, modeAccess, dimensionArray, fixArraySizes, modeArrayElement, declaringClazz);       
1197    return fieldData;
1198  }
1199  
1200  
1201  void stop(){}
1202  
1203}
1204