Changeset 13686


Ignore:
Timestamp:
Oct 7, 2019 3:47:46 PM (2 months ago)
Author:
molsson
Message:

#5843 Moved extracted computation of flatName and moved it after instantiation.

Location:
branches/dev-mo-2265/Compiler/ModelicaCompiler/src/jastadd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-mo-2265/Compiler/ModelicaCompiler/src/jastadd/DebugCompiler.jrag

    r11966 r13686  
    130130                mc.setLogger(out);
    131131                ModelicaCompiler.TargetObject targ = (ModelicaCompiler.TargetObject) target.getSelectedItem();
    132                 mc.compileModel(new String[] { file.getAbsolutePath() }, name, targ, null, null);
     132                mc.compileModel(new String[] { file.getAbsolutePath() }, name, targ, null);
    133133            } catch (Exception ex) {
    134134                out.writeException(ex);
  • branches/dev-mo-2265/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13681 r13686  
    811811             * Compile mo-file and generate code for all templates that are not null.
    812812             */
    813             String flatName = null;
    814             if (!Files.isDirectory(compileTo)) {
    815                 flatName = compileTo.getFileName().toString();
    816                 int i = flatName.lastIndexOf('.');
    817                 if (i > 0) {
    818                     flatName = flatName.substring(0, i);
    819                 }
    820             }
    821             FClass fc = compileModel(fileName, className, target, flatName, compileTo);
     813            FClass fc = compileModel(fileName, className, target, compileTo);
    822814
    823815            if (!target.getCodeGenFlag()) {
     
    832824             */
    833825            hookCheckAbort();
    834             doCompileCCode(target, fc, className, flatName);
     826            doCompileCCode(target, fc);
    835827
    836828            /*
     
    19591951     * @param target
    19601952     *            The target object for the compiler.
    1961      * @param flatName
    1962      *            Name of the unit/flat model supplied by the user, if any.
    19631953     *
    19641954     * @return A flat representation of the class specified by <code>cl</code>.
     
    19821972     * @deprecated Use {@link #compileModel(Path[], String, TargetObject, String, Path)} instead
    19831973     */
    1984     public FClass ModelicaCompiler.compileModel(String files[], String cl, TargetObject target, String flatName, String compileTo)
     1974    public FClass ModelicaCompiler.compileModel(String files[], String cl, TargetObject target, String compileTo)
    19851975          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    1986         return compileModel(stringsToPaths(files), cl, target, flatName, compileTo == null ? null : Paths.get(compileTo));
     1976        return compileModel(stringsToPaths(files), cl, target, compileTo == null ? null : Paths.get(compileTo));
    19871977    }
    19881978   
     
    19981988     * @param target
    19991989     *            The target object for the compiler.
    2000      * @param flatName
    2001      *            Name of the unit/flat model supplied by the user, if any.
    20021990     *
    20031991     * @return A flat representation of the class specified by <code>cl</code>.
     
    20212009     * @deprecated Use {@link #compileModel(Path[], String, TargetObject, String, Path)} instead
    20222010     */
    2023      public FClass ModelicaCompiler.compileModel(Path files[], String cl, TargetObject target, String flatName, Path compileTo)
     2011     public FClass ModelicaCompiler.compileModel(Path files[], String cl, TargetObject target, Path compileTo)
    20242012          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    20252013        boolean doTearDown = true;
    20262014        try {
    20272015            doTearDown = trySetUp();
    2028             return doCompileModel(files, cl, target, flatName, compileTo);
     2016            return doCompileModel(files, cl, target, compileTo);
    20292017        } finally {
    20302018            tryTearDown(doTearDown);
     
    20322020    }
    20332021   
    2034     public FClass ModelicaCompiler.doCompileModel(String name[], String cl, TargetObject target, String flatName, String compileTo)
     2022    public FClass ModelicaCompiler.doCompileModel(String name[], String cl, TargetObject target, String compileTo)
    20352023          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    2036         return doCompileModel(stringsToPaths(name), cl, target, flatName, compileTo == null ? null : Paths.get(compileTo));
    2037     }
    2038    
    2039    
    2040     public FClass ModelicaCompiler.doCompileModel(Path name[], String cl, TargetObject target, String flatName, Path compileTo)
     2024        return doCompileModel(stringsToPaths(name), cl, target, compileTo == null ? null : Paths.get(compileTo));
     2025    }
     2026   
     2027   
     2028    public FClass ModelicaCompiler.doCompileModel(Path name[], String cl, TargetObject target, Path compileTo)
    20412029          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    20422030        if (target.equals(TargetObject.PARSE)) {
     
    20612049            // compute instance tree
    20622050            InstClassDecl icl = instantiateModel(name, cl, target);
    2063            
     2051            UtilInterface util = icl.root().getUtilInterface();
    20642052            if (compileTo != null) {
    20652053                File unitFile = makePackagingDirs(cl, compileTo.toFile(), target);
    2066                 icl.root().getUtilInterface().setCompilationOutputPath(unitFile);
     2054                util.setCompilationOutputPath(unitFile);
    20672055            }
     2056           
     2057            String flatName = computeFlatName(compileTo, util);
    20682058           
    20692059            // flattening
     
    22422232    }
    22432233
    2244     private void ModelicaCompiler.doCompileCCode(TargetObject target,  FClass fc, String className, String flatName) {
     2234    private void ModelicaCompiler.doCompileCCode(TargetObject target,  FClass fc) {
    22452235        if (target.getMakeFileFlag() != null) {
    22462236                ASTNode.beginStep("compileCCode()");
    2247                 String cFileName = (flatName != null) ? flatName : FClass.convertClassNameToUnderscore(className);
     2237                String cFileName = fc.nameUnderscore();
    22482238                CCompilerDelegator ccompiler = getCCompiler();
    22492239                CCompilerArguments ccArgs = new CCompilerArguments(cFileName, fc.myOptions(), target, fc.externalLibraries(), fc.externalLibraryDirectories(),
     
    22872277        templates.generateCFiles(this, fc, createCGenerator(fc), sourceDir, name);
    22882278        templates.generateXMLFiles(this, fc, target.getXMLGenerator(fc), outDir, "modelDescription");
     2279    }
     2280   
     2281    private String ModelicaCompiler.computeFlatName(Path compileTo, UtilInterface util) {
     2282        String flatName = null;
     2283        if (!Files.isDirectory(compileTo)) {
     2284            flatName = compileTo.getFileName().toString();
     2285            int i = flatName.lastIndexOf('.');
     2286            if (i > 0) {
     2287                flatName = flatName.substring(0, i);
     2288            }
     2289        }
     2290        return flatName;
    22892291    }
    22902292
Note: See TracChangeset for help on using the changeset viewer.