[antlr-interest] Re: Getting Column and Line in CPP AST's

jenlhunt2003 steam at tapisinc.com
Thu Feb 12 18:28:36 PST 2004


I reworked the code found at http://www.imada.sdu.dk/~morling/issue4.htm and it now compiles with only one error:

error C2039: 'getLine' : is not a member of 'AST'

from the following segment of code:

// Following line has <PNode> added:
typedef antlr::ASTRefCount<PNode> RefPNode;
. . .
	void addChild( RefPNode c )
		{
		//BaseAST::addChild( static_cast(c) );
		BaseAST::addChild( static_cast<antlr::RefAST>(c) );
		}
	static antlr::RefAST factory( void )
		{
		//antlr::RefAST ret = static_cast(RefPNode(new PNode));
		antlr::RefAST ret = static_cast<antlr::RefAST>(RefPNode(new PNode));
		return ret;
		}
	RefPNode PNode::getFirstChild()
		{
		//return static_cast(BaseAST::getFirstChild());
		return static_cast<antlr::RefAST>(BaseAST::getFirstChild());
		}
	RefPNode PNode::getNextSibling()
		{
		//return static_cast(BaseAST::getNextSibling());
		return static_cast<antlr::RefAST>(BaseAST::getNextSibling());
		}
	void PNode::setLine(int l_)
		{
		lineNumber = l_;
		}
	int PNode::getLine(void) const
		{
		if(lineNumber != 0)
			return lineNumber;
		else
			{
			//if(static_cast(BaseAST::getFirstChild()) == NULL)
			if(static_cast<antlr::RefAST>(BaseAST::getFirstChild()) == NULL)
				{
				return lineNumber;
				}
			else
				{
				//return ( (static_cast(BaseAST::getFirstChild()))->getLine() );
	PROBLEM HERE >>>	return ( (static_cast<antlr::RefAST>(BaseAST::getFirstChild()))->getLine() );
				}
			}
		}

I believe the problem is due to the compiler looking for ->getLine() in a RefAST object, where it doesn't exist.  The only place in the 
antlr source code that I can find getLine() is in the RefToken class, but I don't see how to work that in here.  Also, I'm not sure if I 
made the basic changes properly (see commented code above).  Help would be greatly appreciated!

Incidently, I've tried to post this twice before today, but it didn't make it for some reason.  Hopefully this won't be a duplicate.

Henry






 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list