Search in sources :

Example 1 with CompilationUnitPair

use of sharpen.core.framework.CompilationUnitPair in project XobotOS by xamarin.

the class XobotBuilder method run.

protected boolean run(final IProgressMonitor monitor) {
    Sharpen.Log(Level.INFO, "Starting build");
    try {
        checkFileList();
    } catch (Exception e) {
        Sharpen.Log(e, "Cannot compute file list");
        return false;
    }
    int countModified = 0;
    for (final Entry<ICompilationUnit, Boolean> entry : _sources.entrySet()) {
        if (!entry.getValue())
            continue;
        ++countModified;
        _mustParse.put(entry.getKey(), true);
    }
    if (countModified < 1) {
        Sharpen.Log(Level.INFO, "Nothing to do.");
        return true;
    }
    List<ICompilationUnit> parsingList = new ArrayList<ICompilationUnit>();
    for (final Entry<ICompilationUnit, Boolean> entry : _mustParse.entrySet()) {
        if (!entry.getValue())
            continue;
        parsingList.add(entry.getKey());
    }
    final int totalWork = parsingList.size() * PARSING_PRICE + countModified * (GENERATING_PRICE + OUTPUT_PRICE);
    Sharpen.Log(Level.INFO, "Converting %d files (must parse %d).", countModified, parsingList.size());
    monitor.beginTask("Converting", totalWork);
    final List<CompilationUnitPair> pairs = stage1_parse(parsingList, monitor);
    if (monitor.isCanceled() || (pairs == null) || (pairs.size() == 0))
        return false;
    if (!stage1b_checkForErrors(pairs)) {
        Sharpen.Log(Level.SEVERE, "Found errors while parsing compilation units; aborting!");
        return false;
    }
    AST ast = pairs.get(0).ast.getAST();
    final BindingManager bindings = new BindingManager(ast, _configFile.getNativeConfig());
    final ByRef<Map<ICompilationUnit, CompilationUnitBuilder>> builders = new ByRef<Map<ICompilationUnit, CompilationUnitBuilder>>();
    Environments.runWith(Environments.newClosedEnvironment(_api, bindings, _config), new Runnable() {

        @Override
        public void run() {
            builders.value = stage2_preprocess(bindings, pairs);
        }
    });
    if (monitor.isCanceled())
        return false;
    if (builders.value == null) {
        Sharpen.Log(Level.SEVERE, "Found errors while pre-processing; aborting!");
        return false;
    }
    final List<CompilationUnitPair> modifiedPairs = new ArrayList<CompilationUnitPair>();
    final List<CompilationUnitBuilder> modified = new ArrayList<CompilationUnitBuilder>();
    for (final CompilationUnitBuilder builder : builders.value.values()) {
        if (_sources.get(builder.getPair().source)) {
            modifiedPairs.add(builder.getPair());
            modified.add(builder);
        }
    }
    final ASTResolver resolver = new DefaultASTResolver(modifiedPairs);
    final ByRef<Boolean> ok = new ByRef<Boolean>();
    Environments.runWith(Environments.newClosedEnvironment(_api, bindings, _config, _configFile, resolver), new Runnable() {

        @Override
        public void run() {
            ok.value = stage3_generate(monitor, modified);
        }
    });
    if (monitor.isCanceled() || !ok.value)
        return false;
    Environments.runWith(Environments.newClosedEnvironment(_api, bindings, _config, _configFile, resolver), new Runnable() {

        @Override
        public void run() {
            // ok.value =
            // stage4_post_processs(monitor,
            // modified);
            ok.value = bindings.postProcess();
        }
    });
    if (monitor.isCanceled() || !ok.value)
        return false;
    Environments.runWith(Environments.newClosedEnvironment(_api, bindings, _config, _configFile, resolver), new Runnable() {

        @Override
        public void run() {
            ok.value = stage4_save_output(monitor, modified);
        }
    });
    if (monitor.isCanceled() || !ok.value)
        return false;
    return stage5_generate_csproj();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) AST(org.eclipse.jdt.core.dom.AST) CompilationUnitPair(sharpen.core.framework.CompilationUnitPair) ByRef(sharpen.core.framework.ByRef) DefaultASTResolver(sharpen.core.framework.DefaultASTResolver) CoreException(org.eclipse.core.runtime.CoreException) BindingManager(sharpen.xobotos.api.bindings.BindingManager) CompilationUnitBuilder(sharpen.xobotos.generator.CompilationUnitBuilder) ASTResolver(sharpen.core.framework.ASTResolver) DefaultASTResolver(sharpen.core.framework.DefaultASTResolver)

Example 2 with CompilationUnitPair

use of sharpen.core.framework.CompilationUnitPair in project XobotOS by xamarin.

the class XobotBuilder method stage2_preprocess.

private Map<ICompilationUnit, CompilationUnitBuilder> stage2_preprocess(BindingManager bindings, List<CompilationUnitPair> sources) {
    Map<ICompilationUnit, CompilationUnitBuilder> builders = new HashMap<ICompilationUnit, CompilationUnitBuilder>();
    boolean foundErrors = false;
    for (final CompilationUnitPair pair : sources) {
        CompilationUnitBuilder builder = _api.preprocess(pair);
        if (builder == null) {
            Sharpen.Log(Level.SEVERE, "Preprocessor failed on %s", getUnitName(pair.source));
            continue;
        }
        builders.put(pair.source, builder);
    }
    if (foundErrors)
        return null;
    if (!bindings.resolveTypes()) {
        Sharpen.Log(Level.SEVERE, "Failed to resolve some types!");
    }
    return builders;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnitBuilder(sharpen.xobotos.generator.CompilationUnitBuilder) CompilationUnitPair(sharpen.core.framework.CompilationUnitPair)

Example 3 with CompilationUnitPair

use of sharpen.core.framework.CompilationUnitPair in project XobotOS by xamarin.

the class XobotBuilder method stage1_parse.

private List<CompilationUnitPair> stage1_parse(final List<ICompilationUnit> sources, IProgressMonitor monitor) {
    final int totalWork = PARSING_PRICE * sources.size();
    final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, totalWork);
    final ArrayList<CompilationUnitPair> pairs = new ArrayList<CompilationUnitPair>(sources.size());
    ASTRequestor requestor = new ASTRequestor() {

        @Override
        public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
            pairs.add(new CompilationUnitPair(source, ast));
            subMonitor.subTask(String.format("Parsing (%d/%d): %s", pairs.size(), sources.size(), getUnitName(source)));
            subMonitor.worked(PARSING_PRICE);
        }
    };
    final ASTParser _parser = ASTParser.newParser(AST.JLS3);
    _parser.setKind(ASTParser.K_COMPILATION_UNIT);
    _parser.setProject(sources.get(0).getJavaProject());
    _parser.setResolveBindings(true);
    final ICompilationUnit[] sourceArray = sources.toArray(new ICompilationUnit[0]);
    Sharpen.Log(Level.INFO, "Parsing %d compilation units.", sources.size());
    try {
        subMonitor.beginTask("parsing compile units", totalWork);
        _parser.createASTs(sourceArray, new String[0], requestor, null);
    } finally {
        subMonitor.done();
    }
    return pairs;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CSCompilationUnit(sharpen.core.csharp.ast.CSCompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompilationUnitPair(sharpen.core.framework.CompilationUnitPair) ASTRequestor(org.eclipse.jdt.core.dom.ASTRequestor) ASTParser(org.eclipse.jdt.core.dom.ASTParser) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 CompilationUnitPair (sharpen.core.framework.CompilationUnitPair)3 CompilationUnitBuilder (sharpen.xobotos.generator.CompilationUnitBuilder)2 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 AST (org.eclipse.jdt.core.dom.AST)1 ASTParser (org.eclipse.jdt.core.dom.ASTParser)1 ASTRequestor (org.eclipse.jdt.core.dom.ASTRequestor)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 CSCompilationUnit (sharpen.core.csharp.ast.CSCompilationUnit)1 ASTResolver (sharpen.core.framework.ASTResolver)1 ByRef (sharpen.core.framework.ByRef)1 DefaultASTResolver (sharpen.core.framework.DefaultASTResolver)1 BindingManager (sharpen.xobotos.api.bindings.BindingManager)1