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-2020 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.type;
27 import dmd.backend.oper;
28 import dmd.backend.el;
29 import dmd.backend.exh;
30 import dmd.backend.cgcv;
31 
32 version (SCPP)
33 {
34 import parser;
35 }
36 
37 import dmd.backend.iasm;
38 
39 extern(C++):
40 
41 nothrow:
42 
43 version (MARS)
44 {
45 __gshared EEcontext eecontext;
46 }
47 
48 //////////////////////////////////////
49 // Convert any symbols generated for the debugger expression to SCstack
50 // storage class.
51 
52 void eecontext_convs(uint marksi)
53 {   uint u;
54     uint top;
55     symtab_t *ps;
56 
57     // Change all generated SCauto's to SCstack's
58 version (SCPP)
59 {
60     ps = &globsym;
61 }
62 else
63 {
64     ps = cstate.CSpsymtab;
65 }
66     top = ps.top;
67     //printf("eecontext_convs(%d,%d)\n",marksi,top);
68     for (u = marksi; u < top; u++)
69     {   Symbol *s;
70 
71         s = ps.tab[u];
72         switch (s.Sclass)
73         {
74             case SCauto:
75             case SCregister:
76                 s.Sclass = SCstack;
77                 s.Sfl = FLstack;
78                 break;
79             default:
80                 break;
81         }
82     }
83 }
84 
85 ////////////////////////////////////////
86 // Parse the debugger expression.
87 
88 version (SCPP)
89 {
90 
91 void eecontext_parse()
92 {
93     if (eecontext.EEimminent)
94     {   type *t;
95         uint marksi;
96         Symbol *s;
97 
98         //printf("imminent\n");
99         marksi = globsym.top;
100         eecontext.EEin++;
101         s = symbol_genauto(tspvoid);
102         eecontext.EEelem = func_expr_dtor(true);
103         t = eecontext.EEelem.ET;
104         if (tybasic(t.Tty) != TYvoid)
105         {   uint op;
106             elem *e;
107 
108             e = el_unat(OPind,t,el_var(s));
109             op = tyaggregate(t.Tty) ? OPstreq : OPeq;
110             eecontext.EEelem = el_bint(op,t,e,eecontext.EEelem);
111         }
112         eecontext.EEin--;
113         eecontext.EEimminent = 0;
114         eecontext.EEfunc = funcsym_p;
115 
116         eecontext_convs(marksi);
117 
118         // Generate the typedef
119         if (eecontext.EEtypedef && config.fulltypes)
120         {   Symbol *s;
121 
122             s = symbol_name(eecontext.EEtypedef,SCtypedef,t);
123             cv_outsym(s);
124             symbol_free(s);
125         }
126     }
127 }
128 
129 }
130 }