Skip to content
Snippets Groups Projects
Select Git revision
  • eda5ae6f1a913a73135e71e27715e6c1f7cfffa5
  • master default protected
  • github/fork/hrani/master
  • github/fork/dilawar/master
  • chamcham
  • chhennapoda
  • wheel
  • 3.2.0-pre0
  • v3.1.3
  • 3.1.2
  • 3.1.1
  • chamcham-3.1.1
  • 3.1.0
  • ghevar_3.0.2_pre2
  • ghevar_3.0.2
15 results

HSolveActive.cpp

Blame
  • 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 };
    }