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.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
63 {
64     ps = cstate.CSpsymtab;
65 }
66     const top = ps.length;
67     //printf("eecontext_convs(%d,%d)\n",marksi,top);
68     foreach (u; marksi .. top)
69     {
70         auto s = ps.tab[u];
71         switch (s.Sclass)
72         {
73             case SCauto:
74             case SCregister:
75                 s.Sclass = SCstack;
76                 s.Sfl = FLstack;
77                 break;
78             default:
79                 break;
80         }
81     }
82 }
83 
84 ////////////////////////////////////////
85 // Parse the debugger expression.
86 
87 version (SCPP)
88 {
89 
90 void eecontext_parse()
91 {
92     if (eecontext.EEimminent)
93     {   type *t;
94         Symbol *s;
95 
96         //printf("imminent\n");
97         const marksi = globsym.length;
98         eecontext.EEin++;
99         s = symbol_genauto(tspvoid);
100         eecontext.EEelem = func_expr_dtor(true);
101         t = eecontext.EEelem.ET;
102         if (tybasic(t.Tty) != TYvoid)
103         {   uint op;
104             elem *e;
105 
106             e = el_unat(OPind,t,el_var(s));
107             op = tyaggregate(t.Tty) ? OPstreq : OPeq;
108             eecontext.EEelem = el_bint(op,t,e,eecontext.EEelem);
109         }
110         eecontext.EEin--;
111         eecontext.EEimminent = 0;
112         eecontext.EEfunc = funcsym_p;
113 
114         eecontext_convs(marksi);
115 
116         // Generate the typedef
117         if (eecontext.EEtypedef && config.fulltypes)
118         {   Symbol *s;
119 
120             s = symbol_name(eecontext.EEtypedef,SCtypedef,t);
121             cv_outsym(s);
122             symbol_free(s);
123         }
124     }
125 }
126 
127 }
128 }