@@ -2,7 +2,7 @@ use super::{
22 asm:: { CCTOR , TCCTOR , USER_INIT } ,
33 bimap:: Interned ,
44 class:: { ClassDefIdx , StaticFieldDef } ,
5- Assembly , BasicBlock , CILNode , CILRoot , ClassDef , ClassRef , FieldDesc , FnSig , MethodDef ,
5+ Assembly , BasicBlock , CILNode , CILRoot , ClassDef , ClassRef , Const , FieldDesc , FnSig , MethodDef ,
66 MethodDefIdx , MethodRef , StaticFieldDesc , Type ,
77} ;
88impl Assembly {
@@ -99,27 +99,29 @@ impl Assembly {
9999 . collect ( ) ;
100100 MethodRef :: new ( class, name, sig, method_ref. kind ( ) , generics)
101101 }
102+ pub ( crate ) fn translate_const ( & mut self , source : & Assembly , cst : & Const ) -> Const {
103+ match cst {
104+ super :: Const :: PlatformString ( pstr) => {
105+ super :: Const :: PlatformString ( self . alloc_string ( source[ * pstr] . as_ref ( ) ) )
106+ }
107+
108+ super :: Const :: Null ( cref) => super :: Const :: Null ( self . translate_class_ref ( source, * cref) ) ,
109+ super :: Const :: ByteBuffer { data, tpe } => {
110+ let tpe = self . translate_type ( source, source[ * tpe] ) ;
111+ ( super :: Const :: ByteBuffer {
112+ data : self . alloc_const_data ( & source. const_data [ * data] ) ,
113+ tpe : self . alloc_type ( tpe) ,
114+ } )
115+ }
116+ _ => cst. clone ( ) ,
117+ }
118+ }
102119 // The complexity of this function is unavoidable.
103120 #[ allow( clippy:: too_many_lines) ]
104121 pub ( crate ) fn translate_node ( & mut self , source : & Assembly , node : CILNode ) -> CILNode {
105122 match & node {
106123 CILNode :: LdLoc ( _) | CILNode :: LdLocA ( _) | CILNode :: LdArg ( _) | CILNode :: LdArgA ( _) => node,
107- CILNode :: Const ( cst) => match cst. as_ref ( ) {
108- super :: Const :: PlatformString ( pstr) => CILNode :: Const ( Box :: new (
109- super :: Const :: PlatformString ( self . alloc_string ( source[ * pstr] . as_ref ( ) ) ) ,
110- ) ) ,
111- super :: Const :: Null ( cref) => CILNode :: Const ( Box :: new ( super :: Const :: Null (
112- self . translate_class_ref ( source, * cref) ,
113- ) ) ) ,
114- super :: Const :: ByteBuffer { data, tpe } => {
115- let tpe = self . translate_type ( source, source[ * tpe] ) ;
116- CILNode :: Const ( Box :: new ( super :: Const :: ByteBuffer {
117- data : self . alloc_const_data ( & source. const_data [ * data] ) ,
118- tpe : self . alloc_type ( tpe) ,
119- } ) )
120- }
121- _ => node. clone ( ) ,
122- } ,
124+ CILNode :: Const ( cst) => CILNode :: Const ( Box :: new ( self . translate_const ( source, cst) ) ) ,
123125 CILNode :: BinOp ( a, b, op) => {
124126 let a = self . translate_node ( source, source. get_node ( * a) . clone ( ) ) ;
125127 let b = self . translate_node ( source, source. get_node ( * b) . clone ( ) ) ;
@@ -608,15 +610,25 @@ impl Assembly {
608610 let static_fields = def
609611 . static_fields ( )
610612 . iter ( )
611- . map ( |StaticFieldDef { tpe, name, is_tls } | {
612- let tpe = self . translate_type ( source, * tpe) ;
613- let name = self . alloc_string ( source[ * name] . as_ref ( ) ) ;
614- StaticFieldDef {
615- tpe,
616- name,
617- is_tls : * is_tls,
618- }
619- } )
613+ . map (
614+ |StaticFieldDef {
615+ tpe,
616+ name,
617+ is_tls,
618+ default_value,
619+ is_const,
620+ } | {
621+ let tpe = self . translate_type ( source, * tpe) ;
622+ let name = self . alloc_string ( source[ * name] . as_ref ( ) ) ;
623+ StaticFieldDef {
624+ tpe,
625+ name,
626+ is_tls : * is_tls,
627+ default_value : default_value. map ( |cst| self . translate_const ( source, & cst) ) ,
628+ is_const : * is_const,
629+ }
630+ } ,
631+ )
620632 . collect ( ) ;
621633 let translated = ClassDef :: new (
622634 name,
0 commit comments