From: Robert L. <rle...@us...> - 2007-02-20 15:39:11
|
Update of /cvsroot/ccmtools/ccmtools/src/ccmtools/CppGenerator In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv19014/src/ccmtools/CppGenerator Modified Files: CppLocalGenerator.java CppAssemblyGenerator.java Log Message: C++ assemblies Index: CppLocalGenerator.java =================================================================== RCS file: /cvsroot/ccmtools/ccmtools/src/ccmtools/CppGenerator/CppLocalGenerator.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** CppLocalGenerator.java 20 Feb 2007 13:38:49 -0000 1.56 --- CppLocalGenerator.java 20 Feb 2007 15:39:03 -0000 1.57 *************** *** 898,928 **** // the templates that we don't want to output (see the component // section of the getOutputFiles function) ! if(file_name.equals("")) ! continue; ! ! File outFile = new File(output_dir + File.separator + file_dir, file_name); ! if((file_dir == implDirectory) && outFile.isFile()) ! { ! if(outFile.getName().endsWith("_entry.h")) ! { ! // *_entry.h files must be overwritten by every generator ! // call because they are part of the component logic ! writeFinalizedFile(file_dir, file_name, generated_code); ! } ! else if(!isCodeEqualWithFile(generated_code, outFile)) ! { ! uiDriver.printMessage("WARNING: " + outFile + " already exists!"); ! file_name += ".new"; ! outFile = new File(output_dir + File.separator + file_dir, file_name); ! } ! } ! if(isCodeEqualWithFile(generated_code, outFile)) ! { ! uiDriver.printMessage("Skipping " + outFile); ! } ! else ! { ! writeFinalizedFile(file_dir, file_name, generated_code); ! } } --- 898,903 ---- // the templates that we don't want to output (see the component // section of the getOutputFiles function) ! if(file_name.length()>0) ! writeSourceFile(implDirectory, generated_code, file_dir, file_name); } *************** *** 936,939 **** --- 911,943 ---- logger.fine("leave writeOutput()"); } + + protected void writeSourceFile( String implDirectory, String generated_code, String file_dir, + String file_name ) throws IOException + { + File outFile = new File(output_dir + File.separator + file_dir, file_name); + if ((file_dir == implDirectory) && outFile.isFile()) + { + if (outFile.getName().endsWith("_entry.h")) + { + // *_entry.h files must be overwritten by every generator + // call because they are part of the component logic + writeFinalizedFile(file_dir, file_name, generated_code); + } + else if (!isCodeEqualWithFile(generated_code, outFile)) + { + uiDriver.printMessage("WARNING: " + outFile + " already exists!"); + file_name += ".new"; + outFile = new File(output_dir + File.separator + file_dir, file_name); + } + } + if (isCodeEqualWithFile(generated_code, outFile)) + { + uiDriver.printMessage("Skipping " + outFile); + } + else + { + writeFinalizedFile(file_dir, file_name, generated_code); + } + } Index: CppAssemblyGenerator.java =================================================================== RCS file: /cvsroot/ccmtools/ccmtools/src/ccmtools/CppGenerator/CppAssemblyGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CppAssemblyGenerator.java 20 Feb 2007 13:38:49 -0000 1.1 --- CppAssemblyGenerator.java 20 Feb 2007 15:39:03 -0000 1.2 *************** *** 12,19 **** --- 12,23 ---- import java.io.File; import java.io.IOException; + import java.util.HashMap; + import java.util.HashSet; import java.util.List; + import java.util.Map; import java.util.logging.Logger; import ccmtools.CcmtoolsException; import ccmtools.parser.assembly.metamodel.Assembly; + import ccmtools.parser.assembly.metamodel.Component; import ccmtools.parser.assembly.metamodel.Model; import ccmtools.parser.idl.metamodel.CcmModelHelper; *************** *** 29,32 **** --- 33,43 ---- public class CppAssemblyGenerator extends CppLocalGenerator { + /** + * creates the local C++ assembly generator + * + * @param uiDriver user interface driver + * @param out_dir the directory that will be the root of the output source tree + * @param assemblies the assembly model + */ public CppAssemblyGenerator( UserInterfaceDriver uiDriver, File outDir, Model assemblies ) throws IOException, CcmtoolsException *************** *** 38,45 **** --- 49,70 ---- } + /** + * the assembly model + */ protected Model assemblies; + /** + * the assembly description of the current component (or null) + */ protected Assembly currentAssembly; + /** + * Create a list of lists of pathname components for output files needed by the current node + * type. Only the implementation files of MComponentDef, MHomeDef and MProvidesDef will be + * written (and only if the component is implemented by an assembly). + * + * @return a list of List objects containing file names for all output files to be generated for + * the current node. + */ protected List getOutputFiles() { *************** *** 99,101 **** --- 124,260 ---- return CcmModelHelper.getAbsoluteName(node, Model.IDL_SCOPE); } + + protected static final String TAB = " "; + + protected String data_MComponentDef( String data_type, String data_value ) + { + if (data_type.equals("AssemblyInnerComponentVariable")) + { + return variable_AssemblyInnerComponentVariable(); + } + if (data_type.equals("AssemblyInnerComponentVariableCreation")) + { + return variable_AssemblyInnerComponentVariableCreation(); + } + if (data_type.equals("AssemblyInnerComponentVariableDestruction")) + { + return variable_AssemblyInnerComponentVariableDestruction(); + } + if (data_type.equals("AssemblyInnerComponentInclude")) + { + return variable_AssemblyInnerComponentInclude(); + } + return super.data_MComponentDef(data_type, data_value); + } + + protected String variable_AssemblyInnerComponentVariable() + { + StringBuffer code = new StringBuffer(); + Map<String, MComponentDef> map = getAssemblyLocalComponents(); + for (String key : map.keySet()) + { + MComponentDef comp_def = map.get(key); + String cpp_type = getLocalCxxName(comp_def, "::"); + code.append(TAB + cpp_type + "* " + key + "_;\n"); + for (Object o : comp_def.getFacets()) + { + MProvidesDef p = (MProvidesDef) o; + if (p.getIdentifier().equals(key)) + { + throw new RuntimeException("element \"" + key + + "\": name conflict between IDL and assembly"); + } + } + } + return code.toString(); + } + + protected String variable_AssemblyInnerComponentVariableCreation() + { + StringBuffer code = new StringBuffer(); + Map<String, MComponentDef> map = getAssemblyLocalComponents(); + for (String key : map.keySet()) + { + MComponentDef comp_def = map.get(key); + // TODO + code.append(TAB + key + "_ = 0; // TODO\n"); + } + return code.toString(); + } + + protected String variable_AssemblyInnerComponentVariableDestruction() + { + StringBuffer code = new StringBuffer(); + Map<String, MComponentDef> map = getAssemblyLocalComponents(); + for (String key : map.keySet()) + { + code.append(TAB + "delete " + key + "_;\n"); + } + return code.toString(); + } + + protected String variable_AssemblyInnerComponentInclude() + { + HashSet<String> include_set = new HashSet<String>(); + StringBuffer code = new StringBuffer(); + Map<String, MComponentDef> map = getAssemblyLocalComponents(); + for (String key : map.keySet()) + { + MComponentDef comp_def = map.get(key); + String inc_name = getLocalCxxIncludeName(comp_def); + if (!include_set.contains(inc_name)) + { + code.append("#include <" + inc_name + ".h>\n"); + include_set.add(inc_name); + } + } + return code.toString(); + } + + private Map<String, Map<String, MComponentDef>> assembly_local_components_ = new HashMap<String, Map<String, MComponentDef>>(); + + protected Map<String, MComponentDef> getAssemblyLocalComponents() + { + if (currentAssembly != null) + { + String assembly_key = currentAssembly.getGlobalName(); + Map<String, MComponentDef> map = assembly_local_components_.get(assembly_key); + if (map == null) + { + map = new HashMap<String, MComponentDef>(); + assembly_local_components_.put(assembly_key, map); + Map<String, Component> local_comps = currentAssembly.getComponents(); + for (String key : local_comps.keySet()) + { + Component comp_decl = local_comps.get(key); + MComponentDef comp_def = comp_decl.getCcmName().getCcmComponent(); + if (comp_def == null) + { + throw new RuntimeException("cannot find component " + key + " of type " + + comp_decl.getCcmName()); + } + map.put(key, comp_def); + } + } + return map; + } + else + { + return new HashMap<String, MComponentDef>(); + } + } + + protected void writeSourceFile( String implDirectory, String generated_code, String file_dir, + String file_name ) throws IOException + { + File outFile = new File(output_dir + File.separator + file_dir, file_name); + if (isCodeEqualWithFile(generated_code, outFile)) + { + uiDriver.printMessage("Skipping " + outFile); + } + else + { + writeFinalizedFile(file_dir, file_name, generated_code); + } + } } |