fn translate_name(
        &mut self,
        loc: &Loc,
        maccess: &EA::ModuleAccess,
        type_args: Option<&[EA::Type]>,
        expected_type: &Type,
    ) -> Exp {
        let global_var_sym = match &maccess.value {
            EA::ModuleAccess_::ModuleAccess(..) => self.parent.module_access_to_qualified(maccess),
            EA::ModuleAccess_::Name(name) => {
                // First try to resolve simple name as local.
                let sym = self.symbol_pool().make(name.value.as_str());
                if let Some(exp) = self.resolve_local(
                    loc,
                    sym,
                    self.old_status == OldExpStatus::InsideOld,
                    expected_type,
                ) {
                    return exp;
                }
                // Next try to resolve simple name as a let.
                if let Some(fid) = self.parent.spec_block_lets.get(&sym).cloned() {
                    return self.translate_let(loc, type_args, vec![], expected_type, fid);
                }
                // If not found, try to resolve as builtin constant.
                let builtin_sym = self.parent.parent.builtin_qualified_symbol(&name.value);
                if let Some(entry) = self.parent.parent.const_table.get(&builtin_sym).cloned() {
                    return self.translate_constant(loc, entry, expected_type);
                }
                // If not found, treat as global var in this module.
                self.parent.qualified_by_module(sym)
            }
        };
        if let Some(entry) = self.parent.parent.const_table.get(&global_var_sym).cloned() {
            return self.translate_constant(loc, entry, expected_type);
        }

        if let Some(entry) = self.parent.parent.spec_var_table.get(&global_var_sym) {
            let type_args = type_args.unwrap_or(&[]);
            if entry.type_params.len() != type_args.len() {
                self.error(
                    loc,
                    &format!(
                        "generic count mismatch (expected {} but found {})",
                        entry.type_params.len(),
                        type_args.len()
                    ),
                );
                return self.new_error_exp();
            }
            let ty = entry.type_.clone();
            let module_id = entry.module_id;
            let var_id = entry.var_id;
            let instantiation = self.translate_types(type_args);
            let ty = ty.instantiate(&instantiation);
            let ty = self.check_type(loc, &ty, expected_type, "in spec var expression");
            let id = self.new_node_id_with_type_loc(&ty, loc);
            // Remember the instantiation as an attribute on the expression node.
            self.set_instantiation(id, instantiation);
            return Exp::SpecVar(id, module_id, var_id);
        }

        self.error(
            loc,
            &format!(
                "undeclared `{}`",
                global_var_sym.display(self.symbol_pool())
            ),
        );
        self.new_error_exp()
    }
/// Translates a name. Reports an error if the name is not found.
Translates a name. Reports an error if the name is not found.
Translates a name . Reports an error if the name is not found .
fn translate_name(
        &mut self,
        loc: &Loc,
        maccess: &EA::ModuleAccess,
        type_args: Option<&[EA::Type]>,
        expected_type: &Type,
    ) -> Exp {
        let global_var_sym = match &maccess.value {
            EA::ModuleAccess_::ModuleAccess(..) => self.parent.module_access_to_qualified(maccess),
            EA::ModuleAccess_::Name(name) => {
                // First try to resolve simple name as local.
                let sym = self.symbol_pool().make(name.value.as_str());
                if let Some(exp) = self.resolve_local(
                    loc,
                    sym,
                    self.old_status == OldExpStatus::InsideOld,
                    expected_type,
                ) {
                    return exp;
                }
                // Next try to resolve simple name as a let.
                if let Some(fid) = self.parent.spec_block_lets.get(&sym).cloned() {
                    return self.translate_let(loc, type_args, vec![], expected_type, fid);
                }
                // If not found, try to resolve as builtin constant.
                let builtin_sym = self.parent.parent.builtin_qualified_symbol(&name.value);
                if let Some(entry) = self.parent.parent.const_table.get(&builtin_sym).cloned() {
                    return self.translate_constant(loc, entry, expected_type);
                }
                // If not found, treat as global var in this module.
                self.parent.qualified_by_module(sym)
            }
        };
        if let Some(entry) = self.parent.parent.const_table.get(&global_var_sym).cloned() {
            return self.translate_constant(loc, entry, expected_type);
        }
        if let Some(entry) = self.parent.parent.spec_var_table.get(&global_var_sym) {
            let type_args = type_args.unwrap_or(&[]);
            if entry.type_params.len() != type_args.len() {
                self.error(
                    loc,
                    &format!(
                        "generic count mismatch (expected {} but found {})",
                        entry.type_params.len(),
                        type_args.len()
                    ),
                );
                return self.new_error_exp();
            }
            let ty = entry.type_.clone();
            let module_id = entry.module_id;
            let var_id = entry.var_id;
            let instantiation = self.translate_types(type_args);
            let ty = ty.instantiate(&instantiation);
            let ty = self.check_type(loc, &ty, expected_type, "in spec var expression");
            let id = self.new_node_id_with_type_loc(&ty, loc);
            // Remember the instantiation as an attribute on the expression node.
            self.set_instantiation(id, instantiation);
            return Exp::SpecVar(id, module_id, var_id);
        }
        self.error(
            loc,
            &format!(
                "undeclared `{}`",
                global_var_sym.display(self.symbol_pool())
            ),
        );
        self.new_error_exp()
    }
fn translate_name ( & mut self , loc : & Loc , maccess : & EA :: ModuleAccess , type_args : Option < & [ EA :: Type ] > , expected_type : & Type , ) -> Exp { let global_var_sym = match & maccess . value { EA :: ModuleAccess_ :: ModuleAccess ( .. ) => self . parent . module_access_to_qualified ( maccess ) , EA :: ModuleAccess_ :: Name ( name ) => { // First try to resolve simple name as local. let sym = self . symbol_pool ( ) . make ( name . value . as_str ( ) ) ; if let Some ( exp ) = self . resolve_local ( loc , sym , self . old_status == OldExpStatus :: InsideOld , expected_type , ) { return exp ; } // Next try to resolve simple name as a let. if let Some ( fid ) = self . parent . spec_block_lets . get ( & sym ) . cloned ( ) { return self . translate_let ( loc , type_args , vec ! [ ] , expected_type , fid ) ; } // If not found, try to resolve as builtin constant. let builtin_sym = self . parent . parent . builtin_qualified_symbol ( & name . value ) ; if let Some ( entry ) = self . parent . parent . const_table . get ( & builtin_sym ) . cloned ( ) { return self . translate_constant ( loc , entry , expected_type ) ; } // If not found, treat as global var in this module. self . parent . qualified_by_module ( sym ) } } ; if let Some ( entry ) = self . parent . parent . const_table . get ( & global_var_sym ) . cloned ( ) { return self . translate_constant ( loc , entry , expected_type ) ; } if let Some ( entry ) = self . parent . parent . spec_var_table . get ( & global_var_sym ) { let type_args = type_args . unwrap_or ( & [ ] ) ; if entry . type_params . len ( ) != type_args . len ( ) { self . error ( loc , & format ! ( " " entry type_params len ( ) type_args len ( ) ) , ) ; return self . new_error_exp ( ) ; } let ty = entry . type_ . clone ( ) ; let module_id = entry . module_id ; let var_id = entry . var_id ; let instantiation = self . translate_types ( type_args ) ; let ty = ty . instantiate ( & instantiation ) ; let ty = self . check_type ( loc , & ty , expected_type , " " ) ; let id = self . new_node_id_with_type_loc ( & ty , loc ) ; // Remember the instantiation as an attribute on the expression node. self . set_instantiation ( id , instantiation ) ; return Exp :: SpecVar ( id , module_id , var_id ) ; } self . error ( loc , & format ! ( " " global_var_sym display ( self symbol_pool ( ) ) ) , ) ; self . new_error_exp ( ) }
Translates a name.
Translates a name .
&mut self
loc
&Loc
maccess
&EA::ModuleAccess
type_args
Option<&[EA::Type]>
expected_type
&Type
&mut self
loc
&Loc
maccess
&EA::ModuleAccess
type_args
Option<&[EA::Type]>
expected_type
&Type