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