Ignore:
Timestamp:
Oct 22, 2019 11:31:16 AM (8 weeks ago)
Author:
randersson
Message:

#5819 Merged trunk into branch

Location:
branches/dev-5819
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-5819

  • branches/dev-5819/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13600 r13800  
    348348            hooks.packFmu(this, fc, dir);
    349349        }
    350         fc.root().getUtilInterface().packFmu(fc);
     350        fc.root().getUtilInterface().packFmu(fc, dir.toPath());
    351351    }
    352352   
     
    358358            hooks.fmuPacked(this, fc, path);
    359359        }
    360         fc.root().getUtilInterface().fmuPacked(fc, path);
     360        fc.root().getUtilInterface().fmuPacked(fc, path.toPath());
    361361    }
    362362   
     
    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            /*
     
    838830             */
    839831            ASTNode.beginStep("packUnit()");
    840             File unitPath = packUnit(className, target, fc);
     832            Path unitPath = packUnit(className, target, fc);
    841833            unit = log.logCompiledUnit(unitPath, warnings, fc.numberOfComponents());
    842834            ASTNode.endStep("packUnit()");
     
    12661258        /* Temporary fix to problems with long compilation times due to later evaluations */
    12671259        getExternalFunctionCache().tearDown();
    1268         options.setIntegerOption("external_constant_evaluation", 0);
     1260        options.external_constant_evaluation.setValue(0);
    12691261       
    12701262        hookModelTransformed(fc);
     
    13691361        ASTNode.beginStep("generateCode()");
    13701362        log.info("Generating code...");
     1363       
    13711364        String name = fc.nameUnderscore();
    1372        
    13731365        Templates templates = target.getTemplates(getOptions());
    1374    
    1375         templates.generateCFiles(this, fc, createCGenerator(fc), sourceDir, name);
    1376         templates.generateXMLFiles(this, fc, target.getXMLGenerator(fc), outDir, "modelDescription");
     1366       
     1367        generateAllFiles(fc, target, templates, name);
    13771368        hookCodeGenerated(fc, outDir);
    13781369       
     
    19601951     * @param target
    19611952     *            The target object for the compiler.
    1962      * @param flatName
    1963      *            Name of the unit/flat model supplied by the user, if any.
    19641953     *
    19651954     * @return A flat representation of the class specified by <code>cl</code>.
     
    19831972     * @deprecated Use {@link #compileModel(Path[], String, TargetObject, String, Path)} instead
    19841973     */
    1985     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)
    19861975          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    1987         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));
    19881977    }
    19891978   
     
    19991988     * @param target
    20001989     *            The target object for the compiler.
    2001      * @param flatName
    2002      *            Name of the unit/flat model supplied by the user, if any.
    20031990     *
    20041991     * @return A flat representation of the class specified by <code>cl</code>.
     
    20222009     * @deprecated Use {@link #compileModel(Path[], String, TargetObject, String, Path)} instead
    20232010     */
    2024      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)
    20252012          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    20262013        boolean doTearDown = true;
    20272014        try {
    20282015            doTearDown = trySetUp();
    2029             return doCompileModel(files, cl, target, flatName, compileTo);
     2016            return doCompileModel(files, cl, target, compileTo);
    20302017        } finally {
    20312018            tryTearDown(doTearDown);
     
    20332020    }
    20342021   
    2035     public FClass ModelicaCompiler.doCompileModel(String name[], String cl, TargetObject target, String flatName, String compileTo)
    2036           throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    2037         return doCompileModel(stringsToPaths(name), cl, target, flatName, compileTo == null ? null : Paths.get(compileTo));
    2038     }
    2039    
    2040    
    2041     public FClass ModelicaCompiler.doCompileModel(Path name[], String cl, TargetObject target, String flatName, Path compileTo)
     2022   
     2023    public FClass ModelicaCompiler.doCompileModel(Path name[], String cl, TargetObject target, Path compileTo)
    20422024          throws ModelicaException, FileNotFoundException, IOException, beaver.Parser.Exception {
    20432025        if (target.equals(TargetObject.PARSE)) {
     
    20622044            // compute instance tree
    20632045            InstClassDecl icl = instantiateModel(name, cl, target);
    2064            
     2046            UtilInterface util = icl.root().getUtilInterface();
     2047            String flatName = null;
    20652048            if (compileTo != null) {
    2066                 File unitFile = makePackagingDirs(cl, compileTo.toFile(), target);
    2067                 icl.root().getUtilInterface().setCompilationOutputPath(unitFile);
     2049                Path unitFile = makePackagingDirs(cl, compileTo, target);
     2050                util.setCompilationOutputPath(unitFile);
     2051                flatName = computeFlatName(compileTo, util);
    20682052            }
    20692053           
     
    22072191     * Packs an FMU (helper function for {@link #compileUnit()}).
    22082192     */
    2209     protected File ModelicaCompiler.packUnit(String className,
     2193    protected Path ModelicaCompiler.packUnit(String className,
    22102194            TargetObject target, FClass fClass) throws PackingFailedException {
    2211 
    2212         File unitFile = fClass.root().getUtilInterface().getCompilationOutputPath();
    2213 
     2195        Path unitFile = fClass.root().getUtilInterface().getCompilationOutputPath();
     2196       
    22142197        hookPackFmu(fClass, outDir);
     2198        hookCheckAbort();
     2199        packUnit(className, target, fClass, unitFile);
     2200        hookFmuPacked(fClass, unitFile.toAbsolutePath().toFile());
     2201       
     2202        return unitFile;
     2203    }
     2204   
     2205    private void ModelicaCompiler.packUnit(String className, TargetObject target, FClass fClass, Path unitFile) {
    22152206        try {
    2216             hookCheckAbort();
    22172207            copySourceFiles(fClass, sourceDir, outDir);
    2218 
    2219             OutputStream dest = new BufferedOutputStream(new FileOutputStream(unitFile));
    2220             ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
    2221             out.setMethod(ZipOutputStream.DEFLATED);
    2222 
    2223             zipDir(outDir, out);
    2224             out.close();
    2225         } catch (CompilationAbortedException e) {
    2226             throw e;
     2208            try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(unitFile)))) {
     2209                out.setMethod(ZipOutputStream.DEFLATED);
     2210                zipDir(outDir, out);
     2211            }
    22272212        } catch (Exception e) {
    22282213            throw new PackingFailedException(String.format("Could not write to '%s'.", unitFile), e);
    22292214        }
    2230 
    2231         hookFmuPacked(fClass, unitFile.getAbsoluteFile());
    2232         return unitFile;
    22332215    }
    22342216
     
    22482230    }
    22492231
    2250     private void ModelicaCompiler.doCompileCCode(TargetObject target,  FClass fc, String className, String flatName) {
     2232    private void ModelicaCompiler.doCompileCCode(TargetObject target,  FClass fc) {
    22512233        if (target.getMakeFileFlag() != null) {
    22522234                ASTNode.beginStep("compileCCode()");
    2253                 String cFileName = (flatName != null) ? flatName : FClass.convertClassNameToUnderscore(className);
     2235                String cFileName = fc.nameUnderscore();
    22542236                CCompilerDelegator ccompiler = getCCompiler();
    22552237                CCompilerArguments ccArgs = new CCompilerArguments(cFileName, fc.myOptions(), target, fc.externalLibraries(), fc.externalLibraryDirectories(),
     
    22642246    /**
    22652247     * Calculates the destination directory for a packaged unit. If the specified destination is a file its directory
    2266      * is chosen as destination. If the destination does not exist, it is created (using {@link File#mkdirs()}).
     2248     * is chosen as destination. If the destination does not exist, it is created (using {@link Filed#createDirectories()}).
    22672249     *
    22682250     * @param className
     
    22732255     *          A {@link TargetObject} containing information about the target.
    22742256     * @return
    2275      *          the path to the destination directory of the packaged unit.
     2257     *          the path to the destination file of the packaged unit.
    22762258     */
    2277     private File ModelicaCompiler.makePackagingDirs(String className, File destination, TargetObject target) {
    2278         File dest = new File(destination.getAbsolutePath());
    2279         if (dest.isDirectory()) {
     2259    private Path ModelicaCompiler.makePackagingDirs(String className, Path destination, TargetObject target)
     2260            throws IOException {
     2261        Path dest = destination.toAbsolutePath();
     2262        if (Files.isDirectory(dest)) {
    22802263            String mangledName = FClass.convertClassNameToUnderscore(className);
    2281             dest = new File(dest, mangledName + "." + target.getUnitSuffix());
     2264            dest = dest.resolve(mangledName + "." + target.getUnitSuffix());
    22822265        } else {
    2283             File destDir = dest.getParentFile();
    2284             if (destDir != null && !destDir.isDirectory()) {
    2285                 dest.getParentFile().mkdirs();
     2266            Path destDir = dest.getParent();
     2267            if (destDir != null && !Files.isDirectory(destDir)) {
     2268                Files.createDirectories(dest.getParent());
    22862269            }
    22872270        }
    22882271        return dest;
     2272    }
     2273   
     2274    private void ModelicaCompiler.generateAllFiles(FClass fc, TargetObject target, Templates templates, String name)
     2275            throws FileNotFoundException {
     2276        templates.generateCFiles(this, fc, createCGenerator(fc), sourceDir, name);
     2277        templates.generateXMLFiles(this, fc, target.getXMLGenerator(fc), outDir, "modelDescription");
     2278    }
     2279   
     2280    private String ModelicaCompiler.computeFlatName(Path compileTo, UtilInterface util) {
     2281        String flatName = null;
     2282        if (!Files.isDirectory(compileTo)) {
     2283            flatName = compileTo.getFileName().toString();
     2284            int i = flatName.lastIndexOf('.');
     2285            if (i > 0) {
     2286                flatName = flatName.substring(0, i);
     2287            }
     2288        }
     2289        return flatName;
    22892290    }
    22902291
Note: See TracChangeset for help on using the changeset viewer.