Skip to content
Snippets Groups Projects
Select Git revision
  • 31cae0533ba47503c0427433ffca819e77f69b44
  • master default protected
  • tut_ring_allen
  • docs_furo
  • docs_reorder_cable_cell
  • docs_graphviz
  • docs_rtd_dev
  • ebrains_mirror
  • doc_recat
  • docs_spike_source
  • docs_sim_sample_clar
  • docs_pip_warn
  • github_template_updates
  • docs_fix_link
  • cv_default_and_doc_clarification
  • docs_add_numpy_req
  • readme_zenodo_05
  • install_python_fix
  • install_require_numpy
  • typofix_propetries
  • docs_recipe_lookup
  • v0.10.0
  • v0.10.1
  • v0.10.0-rc5
  • v0.10.0-rc4
  • v0.10.0-rc3
  • v0.10.0-rc2
  • v0.10.0-rc
  • v0.9.0
  • v0.9.0-rc
  • v0.8.1
  • v0.8
  • v0.8-rc
  • v0.7
  • v0.6
  • v0.5.2
  • v0.5.1
  • v0.5
  • v0.4
  • v0.3
  • v0.2.2
41 results

astmanip.cpp

Blame
  • user avatar
    Nora Abi Akar authored and Ben Cumming committed
    - Implement inlining functions with multiple statements
    - Implement inlining nested function calls
    - Implement inlining if/else statements. Compilation fails if a function fails to set the return value.
    
    Fixes #741, #742, #862 
    804f58fd
    History
    astmanip.cpp 1.27 KiB
    #include <string>
    
    #include "astmanip.hpp"
    #include "expression.hpp"
    #include "location.hpp"
    #include "scope.hpp"
    
    static std::string unique_local_name(scope_ptr scope, std::string const& prefix) {
        for (int i = 0; ; ++i) {
            std::string name = prefix + std::to_string(i) + "_";
            if (!scope->find(name)) return name;
        }
    }
    
    local_assignment make_unique_local_assign(scope_ptr scope, Expression* e, std::string const& prefix) {
        Location loc = e->location();
        std::string name = unique_local_name(scope, prefix);
    
        auto local = make_expression<LocalDeclaration>(loc, name);
        local->semantic(scope);
    
        auto id = make_expression<IdentifierExpression>(loc, name);
        id->semantic(scope);
    
        auto ass = binary_expression(e->location(), tok::eq, id->clone(), e->clone());
        ass->semantic(scope);
    
        return { std::move(local), std::move(ass), std::move(id), scope };
    }
    
    local_declaration make_unique_local_decl(scope_ptr scope, Location loc, std::string const& prefix) {
        std::string name = unique_local_name(scope, prefix);
    
        auto local = make_expression<LocalDeclaration>(loc, name);
        local->semantic(scope);
    
        auto id = make_expression<IdentifierExpression>(loc, name);
        id->semantic(scope);
    
        return { std::move(local), std::move(id), scope };
    }