Module Qcert.NNRS.Lang.NNRSVars


Require Import String.
Require Import List.
Require Import Arith.
Require Import EquivDec.
Require Import Morphisms.
Require Import Arith.
Require Import Max.
Require Import Bool.
Require Import Peano_dec.
Require Import EquivDec.
Require Import Decidable.
Require Import Utils.
Require Import DataRuntime.
Require Import NNRS.

Section NNRSVars.
  Context {fruntime:foreign_runtime}.
  Context (h:brand_relation_t).
  
  Fixpoint nnrs_expr_free_vars (e:nnrs_expr) : list var
    := match e with
       | NNRSGetConstant _ => nil
       | NNRSVar v => v :: nil
       | NNRSConst _ => nil
       | NNRSBinop _ ee₂ => nnrs_expr_free_vars e₁ ++ nnrs_expr_free_vars e
       | NNRSUnop _ e₁ => nnrs_expr_free_vars e
       | NNRSGroupBy _ _ e₁ => nnrs_expr_free_vars e
       end.

  
  Fixpoint nnrs_stmt_free_env_vars (s:nnrs_stmt) : list var
    := match s with
       | NNRSSeq ss₂ =>
         nnrs_stmt_free_env_vars s₁ ++ nnrs_stmt_free_env_vars s
       | NNRSLet v e s₀ =>
         nnrs_expr_free_vars e ++ remove equiv_dec v (nnrs_stmt_free_env_vars s₀)
       | NNRSLetMut v ss₂ =>
         nnrs_stmt_free_env_vars s₁ ++ remove equiv_dec v (nnrs_stmt_free_env_vars s₂)
       | NNRSLetMutColl v ss₂ =>
         nnrs_stmt_free_env_vars s₁ ++ remove equiv_dec v (nnrs_stmt_free_env_vars s₂)
       | NNRSAssign v e =>
         nnrs_expr_free_vars e
       | NNRSPush v e =>
         nnrs_expr_free_vars e
       | NNRSFor v e s₀ =>
         nnrs_expr_free_vars e ++ remove equiv_dec v (nnrs_stmt_free_env_vars s₀)
       | NNRSIf e ss₂ =>
         nnrs_expr_free_vars e ++
                                    nnrs_stmt_free_env_vars s₁ ++ nnrs_stmt_free_env_vars s
       | NNRSEither e xsxs₂ =>
         nnrs_expr_free_vars e ++
                                    remove equiv_dec x₁ (nnrs_stmt_free_env_vars s₁) ++
                                    remove equiv_dec x₂ (nnrs_stmt_free_env_vars s₂)
       end.

  Fixpoint nnrs_stmt_free_mcenv_vars (s:nnrs_stmt) : list var
    := match s with
       | NNRSSeq ss₂ =>
         nnrs_stmt_free_mcenv_vars s₁ ++ nnrs_stmt_free_mcenv_vars s
       | NNRSLet v e s₀ =>
         nnrs_stmt_free_mcenv_vars s
       | NNRSLetMut v ss₂ =>
         nnrs_stmt_free_mcenv_vars s₁ ++ nnrs_stmt_free_mcenv_vars s
       | NNRSLetMutColl v ss₂ =>
         remove equiv_dec v (nnrs_stmt_free_mcenv_vars s₁) ++ nnrs_stmt_free_mcenv_vars s
       | NNRSAssign v e =>
         nil
       | NNRSPush v e =>
         v::nil
       | NNRSFor v e s₀ =>
         nnrs_stmt_free_mcenv_vars s
       | NNRSIf e ss₂ =>
         nnrs_stmt_free_mcenv_vars s₁ ++ nnrs_stmt_free_mcenv_vars s
       | NNRSEither e xsxs₂ =>
         nnrs_stmt_free_mcenv_vars s₁ ++ nnrs_stmt_free_mcenv_vars s
       end.

  Fixpoint nnrs_stmt_free_mdenv_vars (s:nnrs_stmt) : list var
    := match s with
       | NNRSSeq ss₂ =>
         nnrs_stmt_free_mdenv_vars s₁ ++ nnrs_stmt_free_mdenv_vars s
       | NNRSLet v e s₀ =>
         nnrs_stmt_free_mdenv_vars s
       | NNRSLetMut v ss₂ =>
         remove equiv_dec v (nnrs_stmt_free_mdenv_vars s₁) ++ nnrs_stmt_free_mdenv_vars s
       | NNRSLetMutColl v ss₂ =>
         nnrs_stmt_free_mdenv_vars s₁ ++ nnrs_stmt_free_mdenv_vars s
       | NNRSAssign v e =>
         v::nil
       | NNRSPush v e =>
         nil
       | NNRSFor v e s₀ =>
         nnrs_stmt_free_mdenv_vars s
       | NNRSIf e ss₂ =>
         nnrs_stmt_free_mdenv_vars s₁ ++ nnrs_stmt_free_mdenv_vars s
       | NNRSEither e xsxs₂ =>
         nnrs_stmt_free_mdenv_vars s₁ ++ nnrs_stmt_free_mdenv_vars s
       end.

  Fixpoint nnrs_stmt_bound_env_vars (s:nnrs_stmt) : list var
    := match s with
       | NNRSSeq ss₂ =>
         nnrs_stmt_bound_env_vars s₁ ++ nnrs_stmt_bound_env_vars s
       | NNRSLet v e s₀ =>
         v :: nnrs_stmt_bound_env_vars s
       | NNRSLetMut v ss₂ =>
         v :: nnrs_stmt_bound_env_vars s₁ ++ nnrs_stmt_bound_env_vars s
       | NNRSLetMutColl v ss₂ =>
         v :: nnrs_stmt_bound_env_vars s₁ ++ nnrs_stmt_bound_env_vars s
       | NNRSAssign v e =>
         nil
       | NNRSPush v e =>
         nil
       | NNRSFor v e s₀ =>
         v :: nnrs_stmt_bound_env_vars s
       | NNRSIf e ss₂ =>
         nnrs_stmt_bound_env_vars s₁ ++ nnrs_stmt_bound_env_vars s
       | NNRSEither e xsxs₂ =>
         x₁ :: x₂ :: nnrs_stmt_bound_env_vars s₁ ++ nnrs_stmt_bound_env_vars s
       end.

  Fixpoint nnrs_stmt_bound_mcenv_vars (s:nnrs_stmt) : list var
    := match s with
       | NNRSSeq ss₂ =>
         nnrs_stmt_bound_mcenv_vars s₁ ++ nnrs_stmt_bound_mcenv_vars s
       | NNRSLet v e s₀ =>
         nnrs_stmt_bound_mcenv_vars s
       | NNRSLetMut v ss₂ =>
         nnrs_stmt_bound_mcenv_vars s₁ ++ nnrs_stmt_bound_mcenv_vars s
       | NNRSLetMutColl v ss₂ =>
         v :: nnrs_stmt_bound_mcenv_vars s₁ ++ nnrs_stmt_bound_mcenv_vars s
       | NNRSAssign v e =>
         nil
       | NNRSPush v e =>
         nil
       | NNRSFor v e s₀ =>
         nnrs_stmt_bound_mcenv_vars s
       | NNRSIf e ss₂ =>
         nnrs_stmt_bound_mcenv_vars s₁ ++ nnrs_stmt_bound_mcenv_vars s
       | NNRSEither e xsxs₂ =>
         nnrs_stmt_bound_mcenv_vars s₁ ++ nnrs_stmt_bound_mcenv_vars s
       end.

  Fixpoint nnrs_stmt_bound_mdenv_vars (s:nnrs_stmt) : list var
    := match s with
       | NNRSSeq ss₂ =>
         nnrs_stmt_bound_mdenv_vars s₁ ++ nnrs_stmt_bound_mdenv_vars s
       | NNRSLet v e s₀ =>
         nnrs_stmt_bound_mdenv_vars s
       | NNRSLetMut v ss₂ =>
         v :: nnrs_stmt_bound_mdenv_vars s₁ ++ nnrs_stmt_bound_mdenv_vars s
       | NNRSLetMutColl v ss₂ =>
         nnrs_stmt_bound_mdenv_vars s₁ ++ nnrs_stmt_bound_mdenv_vars s
       | NNRSAssign v e =>
         nil
       | NNRSPush v e =>
         nil
       | NNRSFor v e s₀ =>
         nnrs_stmt_bound_mdenv_vars s
       | NNRSIf e ss₂ =>
         nnrs_stmt_bound_mdenv_vars s₁ ++ nnrs_stmt_bound_mdenv_vars s
       | NNRSEither e xsxs₂ =>
         nnrs_stmt_bound_mdenv_vars s₁ ++ nnrs_stmt_bound_mdenv_vars s
       end.
  
End NNRSVars.