?? antlrext.h
字號:
/*
作用:擴展CommonAST 以獲得源文件的行信息。用于錯誤定位。.
*/
#ifndef _ASTNODE_
#define _ASTNODE_
#include "antlr/ASTFactory.hpp"
#include "antlr/CommonAST.hpp"
class ASTNodeExt;
typedef ANTLR_USE_NAMESPACE(antlr)ASTRefCount<ASTNodeExt> RefASTNodeExt;
class ASTNodeExt : public ANTLR_USE_NAMESPACE(antlr)CommonAST {
public:
// 拷貝構(gòu)造函數(shù)
ASTNodeExt(const ASTNodeExt& other):
CommonAST(other),
line(other.line),
isTopLevelCall(false) {}
//默認構(gòu)造函數(shù)
ASTNodeExt():
CommonAST(),
line(0),
isTopLevelCall(false) {}
virtual ~ASTNodeExt() {}
// get the line number of the node (or try to derive it from the child node
virtual int getLine() const {
// most of the time the line number is not set if the node is a
// imaginary one. Usually this means it has a child. Refer to the
// child line number. Of course this could be extended a bit.
// based on an example by Peter Morling.
if (line != 0)
return line;
ASTNodeExt* node = RefASTNodeExt(getFirstChild());
while (node && ! node->getLine()) {
node = RefASTNodeExt(node->getNextSibling());
}
if (node)
return node->getLine();
else
return 0;
}
virtual void setLine(int l) {
line = l;
}
virtual void initialize(int t, const ANTLR_USE_NAMESPACE(std)string& txt) {
CommonAST::initialize(t,txt);
line = 0;
}
virtual void initialize(ANTLR_USE_NAMESPACE(antlr)RefToken t) {
CommonAST::initialize(t);
line = t->getLine();
}
virtual void initialize(RefASTNodeExt ast) {
CommonAST::initialize(ANTLR_USE_NAMESPACE(antlr)RefAST(ast));
line = ast->getLine();
}
// 拷貝兄弟結(jié)點或子結(jié)點
virtual ANTLR_USE_NAMESPACE(antlr)RefAST clone() {
return ANTLR_USE_NAMESPACE(antlr)RefAST(new ASTNodeExt(*this));
}
static ANTLR_USE_NAMESPACE(antlr)RefAST factory() {
return ANTLR_USE_NAMESPACE(antlr)RefAST(RefASTNodeExt(new ASTNodeExt()));
}
bool isTopLevelCall;
private:
int line;
};
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -