Skip to content

Commit ff180d6

Browse files
committed
添加AST保存标识符名的parserdebug模式(目前仅在通过scope创建Variable和Function支持
1 parent 8ef5218 commit ff180d6

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

SCMath.pro.user

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.5.0, 2018-10-25T01:08:48. -->
3+
<!-- Written by QtCreator 4.2.1, 2018-10-25T08:40:18. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
7-
<value type="QByteArray">{8c0ba939-0b4d-4cf6-98ab-ff3200f6974d}</value>
7+
<value type="QByteArray">{5cdfc2d9-746f-4959-a869-d810886911bf}</value>
88
</data>
99
<data>
1010
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -59,14 +59,14 @@
5959
<data>
6060
<variable>ProjectExplorer.Project.Target.0</variable>
6161
<valuemap type="QVariantMap">
62-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.9.4 MinGW 32bit</value>
63-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.9.4 MinGW 32bit</value>
64-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.594.win32_mingw53_kit</value>
62+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.8.0 MinGW 32bit</value>
63+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.8.0 MinGW 32bit</value>
64+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.58.win32_mingw53_kit</value>
6565
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
6666
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
6767
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
6868
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
69-
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">F:/mycodes/build-SCMath-Desktop_Qt_5_9_4_MinGW_32bit-Debug</value>
69+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/gitreg/build-SCMath-Desktop_Qt_5_8_0_MinGW_32bit-Debug</value>
7070
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
7171
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
7272
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -120,7 +120,7 @@
120120
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
121121
</valuemap>
122122
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
123-
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">F:/mycodes/build-SCMath-Desktop_Qt_5_9_4_MinGW_32bit-Release</value>
123+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/gitreg/build-SCMath-Desktop_Qt_5_8_0_MinGW_32bit-Release</value>
124124
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
125125
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
126126
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -174,7 +174,7 @@
174174
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
175175
</valuemap>
176176
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
177-
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">F:/mycodes/build-SCMath-Desktop_Qt_5_9_4_MinGW_32bit-Profile</value>
177+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/gitreg/build-SCMath-Desktop_Qt_5_8_0_MinGW_32bit-Profile</value>
178178
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
179179
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
180180
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -286,13 +286,13 @@
286286
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
287287
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">SCMath</value>
288288
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
289-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:F:/mycodes/SCMath/SCMath.pro</value>
289+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/gitreg/SCMath/SCMath.pro</value>
290290
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
291291
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
292292
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">SCMath.pro</value>
293293
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
294294
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
295-
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">F:/mycodes/build-SCMath-Desktop_Qt_5_9_4_MinGW_32bit-Debug</value>
295+
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">D:/gitreg/build-SCMath-Desktop_Qt_5_8_0_MinGW_32bit-Debug</value>
296296
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
297297
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
298298
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>

nodetype.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <vector>
44
#include <functional>
55
using namespace std;
6+
#define parserdebug
67

78
enum nodeType{Num,String,Var,Pro,Fun,VarRef};
89

@@ -79,6 +80,9 @@ class VarNode : public BasicNode
7980
void setBorrowVal(BasicNode* val); //直接对值进行赋值,用这个不转移所有权(一般赋值为变量指针用)
8081
void setVarVal(VarNode* node); //传递变量的值到this的值,即需要进行一次解包
8182
void clearVal();
83+
#ifdef parserdebug
84+
string NAME;
85+
#endif
8286
};
8387
typedef VarNode Variable; //内存实体是Variable,其指针才作为节点(不像某些节点一样是遇到一个就new一次),参考函数实体和函数节点的思想
8488

@@ -146,6 +150,9 @@ class Function
146150
bool isVLP() {return this->VLP;}
147151
void addFormalPar(VarReference* var); //先在外面new好,然后转移所有权进来
148152
BasicNode* eval(vector<BasicNode *> &sonNode);
153+
#ifdef parserdebug
154+
string NAME;
155+
#endif
149156
};
150157

151158

scope.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,28 @@ Scope::~Scope()
99
for(Scope* i:this->sonScope)
1010
delete i;
1111
}
12+
13+
void Scope::addValue(string name)
14+
{
15+
Variable* var=new Variable();
16+
#ifdef parserdebug
17+
var->NAME=name;
18+
#endif
19+
this->variableList[name]=var;
20+
}
21+
22+
void Scope::addValue(string name, Variable *var)
23+
{
24+
#ifdef parserdebug
25+
var->NAME=name;
26+
#endif
27+
this->variableList[name]=var;
28+
}
29+
30+
void Scope::addFunction(string name, Function *fun)
31+
{
32+
#ifdef parserdebug
33+
fun->NAME=name;
34+
#endif
35+
this->functionList[name]=fun;
36+
}

scope.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Scope //作用是记录不同语句块内函数及变量名到实体的映
1212
Scope* fatherScope;
1313
Scope(Scope* fatherScope=nullptr):fatherScope(fatherScope){}
1414

15-
void addValue(string name) {this->variableList[name]=new Variable();}
16-
void addValue(string name,Variable* var) {this->variableList[name]=var;}
17-
void addFunction(string name,Function* fun) {this->functionList[name]=fun;}
15+
void addValue(string name);
16+
void addValue(string name,Variable* var);
17+
void addFunction(string name,Function* fun);
1818
};

0 commit comments

Comments
 (0)