1 /**
2  * Compiler implementation of the
3  * $(LINK2 http://www.dlang.org, D programming language).
4  *
5  * Copyright:   Copyright (C) 1995-1998 by Symantec
6  *              Copyright (C) 2000-2021 by The D Language Foundation, All Rights Reserved
7  * Authors:     $(LINK2 http://www.digitalmars.com, Walter Bright)
8  * License:     $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9  * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/ee.d, backend/ee.d)
10  */
11 module dmd.backend.ee;
12 
13 /*
14  * Code to handle debugger expression evaluation
15  */
16 
17 version (SPP) {} else
18 {
19 
20 import core.stdc.stdio;
21 import core.stdc.string;
22 import core.stdc.time;
23 import dmd.backend.cc;
24 import dmd.backend.cdef;
25 import dmd.backend.global;
26 import dmd.backend.symtab;
27 import dmd.backend.type;
28 import dmd.backend.oper;
29 import dmd.backend.el;
30 import dmd.backend.exh;
31 import dmd.backend.cgcv;
32 import dmd.backend.symtab;
33 version (SCPP)
34 {
35 import parser;
36 }
37 
38 import dmd.backend.iasm;
39 
40 extern(C++):
41 
42 nothrow:
43 
44 version (MARS)
45 {
46 __gshared EEcontext eecontext;
47 }
48 
49 //////////////////////////////////////
50 // Convert any symbols generated for the debugger expression to SCstack
51 // storage class.
52 
53 void eecontext_convs(SYMIDX marksi)
54 {
55     symtab_t *ps;
56 
57     // Change all generated SCauto's to SCstack's
58     version (SCPP)
59     {
60         ps = &globsym;
61     }
62     else version (HTOD)
63     {
64         ps = &globsym;
65     }
66     else
67     {
68         ps = cstate.CSpsymtab;
69     }
70     const top = ps.length;
71     //printf("eecontext_convs(%d,%d)\n",marksi,top);
72     foreach (u; marksi .. top)
73     {
74         auto s = (*ps)[u];
75         switch (s.Sclass)
76         {
77             case SCauto:
78             case SCregister:
79                 s.Sclass = SCstack;
80                 s.Sfl = FLstack;
81                 break;
82             default:
83                 break;
84         }
85     }
86 }
87 
88 ////////////////////////////////////////
89 // Parse the debugger expression.
90 
91 version (SCPP)
92 {
93 
94 void eecontext_parse()
95 {
96     if (eecontext.EEimminent)
97     {   type *t;
98         Symbol *s;
99 
100         //printf("imminent\n");
101         const marksi = globsym.length;
102         eecontext.EEin++;
103         s = symbol_genauto(tspvoid);
104         eecontext.EEelem = func_expr_dtor(true);
105         t = eecontext.EEelem.ET;
106         if (tybasic(t.Tty) != TYvoid)
107         {   uint op;
108             elem *e;
109 
110             e = el_unat(OPind,t,el_var(s));
111             op = tyaggregate(t.Tty) ? OPstreq : OPeq;
112             eecontext.EEelem = el_bint(op,t,e,eecontext.EEelem);
113         }
114         eecontext.EEin--;
115         eecontext.EEimminent = 0;
116         eecontext.EEfunc = funcsym_p;
117 
118         eecontext_convs(marksi);
119 
120         // Generate the typedef
121         if (eecontext.EEtypedef && config.fulltypes)
122         {   Symbol *s;
123 
124             s = symbol_name(eecontext.EEtypedef,SCtypedef,t);
125             cv_outsym(s);
126             symbol_free(s);
127         }
128     }
129 }
130 
131 }
132 }