@@ -20,7 +20,7 @@ class BasicNode
2020
2121 // fix:这个ret的实现方法可能不太对劲
2222 void setRet () {this ->retFlag =true ;} // 不可eval节点设置ret无效
23- bool isRet () {return this ->retFlag ;}
23+ bool isRet () const {return this ->retFlag ;}
2424 vector<BasicNode*> sonNode;
2525};
2626typedef function<bool (vector<BasicNode*>&sonNode)>canBE; // 检测函数基础求值参数表是否合法
@@ -45,9 +45,9 @@ class NumNode : public BasicNode
4545 virtual void addNode (BasicNode*) {throw addSonExcep (Num);}
4646 virtual BasicNode* eval () {return this ;}
4747 NumNode (double num) {this ->num =num;}
48- NumNode (const NumNode& n):BasicNode(n) {this ->num =n.num ;}
48+ NumNode (const NumNode& n):BasicNode(n) {this ->num =n.getNum () ;}
4949
50- double getNum () {return this ->num ;}
50+ double getNum () const {return this ->num ;}
5151};
5252
5353
@@ -60,9 +60,9 @@ class StringNode : public BasicNode
6060 virtual void addNode (BasicNode*) {throw addSonExcep (String);}
6161 virtual BasicNode* eval () {return this ;}
6262 StringNode (string str) {this ->str =str;}
63- StringNode (const StringNode& n):BasicNode(n) {this ->str =n.str ;}
63+ StringNode (const StringNode& n):BasicNode(n) {this ->str =n.getStr () ;}
6464
65- string getStr () {return this ->str ;}
65+ string getStr () const {return this ->str ;}
6666};
6767
6868
@@ -80,11 +80,12 @@ class VarNode : public BasicNode
8080 virtual BasicNode* eval ();
8181 virtual ~VarNode ();
8282 VarNode (int valtype=-1 );
83+ VarNode (VarNode &n);
8384
84- bool isEmpty () {return (this ->val ==nullptr );}
85- bool istypeRestrict () {return this ->typeRestrictFlag ;}
86- int getValType () {return this ->valtype ;}
87- bool isOwnership () {return this ->ownershipFlag ;}
85+ bool isEmpty () const {return (this ->val ==nullptr );}
86+ bool istypeRestrict () const {return this ->typeRestrictFlag ;}
87+ int getValType () const {return this ->valtype ;}
88+ bool isOwnership () const {return this ->ownershipFlag ;}
8889 void setVal (BasicNode* val); // 直接对值进行赋值,用这个传进来意味着转移所有权到本类(一般赋值为字面量用)
8990 void setBorrowVal (BasicNode* val); // 直接对值进行赋值,用这个不转移所有权(一般赋值为变量指针用)
9091 void setVarVal (VarNode* node); // 传递变量的值到this的值,即需要进行一次解包
@@ -96,37 +97,37 @@ class VarNode : public BasicNode
9697};
9798typedef VarNode Variable; // 内存实体是Variable,其指针才作为节点(不像某些节点一样是遇到一个就new一次),参考函数实体和函数节点的思想
9899
99- class ArrNode : public BasicNode
100+ class ArrNode : public BasicNode // 注意,该节点是作为字面量存在的,传递时应当转移所有权
100101{
101102protected:
102103 bool typeRestrictFlag=false ;
103- vector<VarNode*>allelm;
104- int valtype; // 每个变量值的类型
105- int size ; // 最大长度,-1为不限
104+ int valtype; // fix:应当记录交叉类型,所以这里和设计原则有些冲突,集成TSystem前要改好
105+ // 可选的方案:将typeRestrictFlag改为【严格同一类型】,同一类型用现在这个valtype,正常的typeRestrictFlag检查交叉类型
106+ int len ; // 最大长度,-1为不限
106107
107108 void arrSizeCheck ();
109+ void clearArray (); // 这个暂时调整成私有
108110public:
109111 virtual int getType () {return Arr;}
110112 virtual void addNode (BasicNode*) {throw addSonExcep (Arr);}
111113 virtual BasicNode* eval () {return this ;}
112114 virtual ~ArrNode () {this ->clearArray ();}
113- ArrNode (int valtype=-1 ,int size=-1 );
115+ ArrNode (int valtype=-1 ,int len=-1 );
116+ ArrNode (const ArrNode& n);
114117
115118 VarNode* addElm (int valtype=-1 );
116119 VarNode* addElm (VarNode* var); // 注意,该函数会移交所传递变量的所有权
117- VarNode* getElm (unsigned int sub) {return this ->allelm .at (sub);}
118- unsigned int getLen () {return this ->allelm .size ();}
119120 void delElm (unsigned int sub);
120- bool istypeRestrict () {return this ->typeRestrictFlag ;}
121- int getValType ();
122- void clearArray ();
123- bool isVLA () {return this ->size ==-1 ;}
121+ VarNode* getElm (unsigned int sub) {return this ->allelm .at (sub);} // 和访问直接访问allelm没啥区别,为了和楼上对称先留着
122+ unsigned int getNowLen () const {return this ->allelm .size ();}
123+ bool istypeRestrict () const {return this ->typeRestrictFlag ;}
124+ int getValType () const {return this ->valtype ;} // 调用前自行检查istypeRestrict
125+ bool isVLA () const {return this ->len ==-1 ;}
126+ int getLen () const {return this ->len ;} // 最大长度
124127
125- #ifdef READABLEGEN
126- string NAME;
127- #endif
128+ vector<VarNode*>allelm;
128129};
129- typedef ArrNode Array; // 同上
130+ // typedef ArrNode Array; //同上
130131
131132class VarRefNode : public BasicNode
132133{
0 commit comments