@@ -2,7 +2,7 @@ use super::{
2
2
asm:: { CCTOR , TCCTOR , USER_INIT } ,
3
3
bimap:: Interned ,
4
4
class:: { ClassDefIdx , StaticFieldDef } ,
5
- Assembly , BasicBlock , CILNode , CILRoot , ClassDef , ClassRef , FieldDesc , FnSig , MethodDef ,
5
+ Assembly , BasicBlock , CILNode , CILRoot , ClassDef , ClassRef , Const , FieldDesc , FnSig , MethodDef ,
6
6
MethodDefIdx , MethodRef , StaticFieldDesc , Type ,
7
7
} ;
8
8
impl Assembly {
@@ -99,27 +99,29 @@ impl Assembly {
99
99
. collect ( ) ;
100
100
MethodRef :: new ( class, name, sig, method_ref. kind ( ) , generics)
101
101
}
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
+ }
102
119
// The complexity of this function is unavoidable.
103
120
#[ allow( clippy:: too_many_lines) ]
104
121
pub ( crate ) fn translate_node ( & mut self , source : & Assembly , node : CILNode ) -> CILNode {
105
122
match & node {
106
123
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) ) ) ,
123
125
CILNode :: BinOp ( a, b, op) => {
124
126
let a = self . translate_node ( source, source. get_node ( * a) . clone ( ) ) ;
125
127
let b = self . translate_node ( source, source. get_node ( * b) . clone ( ) ) ;
@@ -608,15 +610,25 @@ impl Assembly {
608
610
let static_fields = def
609
611
. static_fields ( )
610
612
. 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
+ )
620
632
. collect ( ) ;
621
633
let translated = ClassDef :: new (
622
634
name,
0 commit comments