@@ -157,6 +157,26 @@ impl Namespace {
157157 self . add_value ( path. resolve ( scope) ?, value)
158158 }
159159
160+ /// Add an alias for an existing name. The alias will refer to the same value as the original,
161+ /// and the fact that the alias exists is forgotten.
162+ pub fn add_alias_at_resolved_path (
163+ & mut self ,
164+ path : AmlName ,
165+ scope : & AmlName ,
166+ target : AmlName
167+ ) -> Result < AmlHandle , AmlError > {
168+ let path = path. resolve ( scope) ?;
169+ let target = target. resolve ( scope) ?;
170+
171+ let handle = self . get_handle ( & target) ?;
172+
173+ let ( level, last_seg) = self . get_level_for_path_mut ( & path) ?;
174+ match level. values . insert ( last_seg, handle) {
175+ None => Ok ( handle) ,
176+ Some ( _) => Err ( AmlError :: NameCollision ( path) ) ,
177+ }
178+ }
179+
160180 pub fn get ( & self , handle : AmlHandle ) -> Result < & AmlValue , AmlError > {
161181 Ok ( self . object_map . get ( & handle) . unwrap ( ) )
162182 }
@@ -722,6 +742,33 @@ mod tests {
722742 }
723743 }
724744
745+ #[ test]
746+ fn test_alias ( ) {
747+ let mut namespace = Namespace :: new ( ) ;
748+
749+ assert_eq ! ( namespace. add_level( ( AmlName :: from_str( "\\ FOO" ) ) . unwrap( ) , LevelType :: Scope ) , Ok ( ( ) ) ) ;
750+
751+ assert ! (
752+ namespace. add_value_at_resolved_path(
753+ AmlName :: from_str( "BAR" ) . unwrap( ) ,
754+ & AmlName :: from_str( "\\ FOO" ) . unwrap( ) ,
755+ AmlValue :: Integer ( 100 ) )
756+ . is_ok( )
757+ ) ;
758+ assert ! (
759+ namespace. add_alias_at_resolved_path(
760+ AmlName :: from_str( "BARA" ) . unwrap( ) ,
761+ & AmlName :: from_str( "\\ FOO" ) . unwrap( ) ,
762+ AmlName :: from_str( "BAR" ) . unwrap( ) )
763+ . is_ok( )
764+ ) ;
765+ assert ! ( namespace. get_by_path( & AmlName :: from_str( "\\ FOO.BARA" ) . unwrap( ) ) . is_ok( ) ) ;
766+ assert_eq ! (
767+ namespace. get_handle( & AmlName :: from_str( "\\ FOO.BARA" ) . unwrap( ) ) ,
768+ namespace. get_handle( & AmlName :: from_str( "\\ FOO.BAR" ) . unwrap( ) )
769+ ) ;
770+ }
771+
725772 #[ test]
726773 fn test_get_level_for_path ( ) {
727774 let mut namespace = Namespace :: new ( ) ;
0 commit comments