[Avida-SVN] r2396 - development/source/script
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Feb 28 17:04:18 PST 2008
Author: brysonda
Date: 2008-02-28 20:04:18 -0500 (Thu, 28 Feb 2008)
New Revision: 2396
Modified:
development/source/script/ASTree.cc
development/source/script/ASTree.h
development/source/script/cASTVisitor.h
development/source/script/cDumpASTVisitor.cc
development/source/script/cDumpASTVisitor.h
development/source/script/cParser.cc
development/source/script/cSemanticASTVisitor.cc
development/source/script/cSemanticASTVisitor.h
Log:
AS:
Change the handling of function call objects to eliminate sub-object. Add ObjectCall and ObjectReference tree nodes to better handle their unique semantic/execution needs.
Modified: development/source/script/ASTree.cc
===================================================================
--- development/source/script/ASTree.cc 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/ASTree.cc 2008-02-29 01:04:18 UTC (rev 2396)
@@ -47,6 +47,8 @@
void cASTFunctionCall::Accept(cASTVisitor& visitor) { visitor.visitFunctionCall(*this); }
void cASTLiteral::Accept(cASTVisitor& visitor) { visitor.visitLiteral(*this); }
void cASTLiteralArray::Accept(cASTVisitor& visitor) { visitor.visitLiteralArray(*this); }
+void cASTObjectCall::Accept(cASTVisitor& visitor) { visitor.visitObjectCall(*this); }
+void cASTObjectReference::Accept(cASTVisitor& visitor) { visitor.visitObjectReference(*this); }
void cASTVariableReference::Accept(cASTVisitor& visitor) { visitor.visitVariableReference(*this); }
void cASTUnpackTarget::Accept(cASTVisitor& visitor) { visitor.visitUnpackTarget(*this); }
Modified: development/source/script/ASTree.h
===================================================================
--- development/source/script/ASTree.h 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/ASTree.h 2008-02-29 01:04:18 UTC (rev 2396)
@@ -113,6 +113,8 @@
class cASTFunctionCall;
class cASTLiteral;
class cASTLiteralArray;
+class cASTObjectCall;
+class cASTObjectReference;
class cASTVariableReference;
class cASTUnpackTarget;
@@ -419,21 +421,28 @@
class cASTFunctionCall : public cASTNode
{
private:
- cASTNode* m_target;
+ cString m_name;
cASTArgumentList* m_args;
ASType_t m_type;
+ int m_id;
+ bool m_global;
public:
- cASTFunctionCall(const cASFilePosition& fp, cASTNode* target)
- : cASTNode(fp), m_target(target), m_args(NULL), m_type(AS_TYPE_INVALID) { ; }
+ cASTFunctionCall(const cASFilePosition& fp, const cString& name)
+ : cASTNode(fp), m_name(name), m_args(NULL), m_type(AS_TYPE_INVALID), m_id(-1), m_global(false) { ; }
~cASTFunctionCall() { delete m_args; }
- cASTNode* GetTarget() { return m_target; }
+ const cString& GetName() const { return m_name; }
+
void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; }
cASTArgumentList* GetArguments() { return m_args; }
ASType_t GetType() const { return m_type; }
inline void SetType(ASType_t type) { m_type = type; }
+
+ inline int GetFuncID() const { return m_id; }
+ inline bool IsFuncGlobal() const { return m_global; }
+ inline void SetFunc(int in_id, bool global) { m_id = in_id; m_global = global; }
bool HasArguments() const { return (m_args); }
@@ -476,6 +485,57 @@
};
+class cASTObjectCall : public cASTNode
+{
+private:
+ cASTNode* m_object;
+ cString m_name;
+ cASTArgumentList* m_args;
+ ASType_t m_type;
+
+public:
+ cASTObjectCall(const cASFilePosition& fp, cASTNode* object, const cString& name)
+ : cASTNode(fp), m_object(object), m_name(name), m_args(NULL), m_type(AS_TYPE_INVALID) { ; }
+ ~cASTObjectCall() { delete m_object; delete m_args; }
+
+ cASTNode* GetObject() { return m_object; }
+ const cString& GetName() const { return m_name; }
+
+ void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; }
+ cASTArgumentList* GetArguments() { return m_args; }
+
+ ASType_t GetType() const { return m_type; }
+ inline void SetType(ASType_t type) { m_type = type; }
+
+
+ bool HasArguments() const { return (m_args); }
+
+ void Accept(cASTVisitor& visitor);
+};
+
+
+class cASTObjectReference : public cASTNode
+{
+private:
+ cASTNode* m_object;
+ cString m_name;
+ ASType_t m_type;
+
+public:
+ cASTObjectReference(const cASFilePosition& fp, cASTNode* object, const cString& name)
+ : cASTNode(fp), m_object(object), m_name(name) { ; }
+ ~cASTObjectReference() { delete m_object; }
+
+ cASTNode* GetObject() { return m_object; }
+ inline const cString& GetName() { return m_name; }
+
+ ASType_t GetType() const { return m_type; }
+ inline void SetType(ASType_t type) { m_type = type; }
+
+ void Accept(cASTVisitor& visitor);
+};
+
+
class cASTVariableReference : public cASTNode
{
private:
Modified: development/source/script/cASTVisitor.h
===================================================================
--- development/source/script/cASTVisitor.h 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/cASTVisitor.h 2008-02-29 01:04:18 UTC (rev 2396)
@@ -55,6 +55,8 @@
virtual void visitFunctionCall(cASTFunctionCall&) = 0;
virtual void visitLiteral(cASTLiteral&) = 0;
virtual void visitLiteralArray(cASTLiteralArray&) = 0;
+ virtual void visitObjectCall(cASTObjectCall&) = 0;
+ virtual void visitObjectReference(cASTObjectReference&) = 0;
virtual void visitVariableReference(cASTVariableReference&) = 0;
virtual void visitUnpackTarget(cASTUnpackTarget&) = 0;
};
Modified: development/source/script/cDumpASTVisitor.cc
===================================================================
--- development/source/script/cDumpASTVisitor.cc 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/cDumpASTVisitor.cc 2008-02-29 01:04:18 UTC (rev 2396)
@@ -295,7 +295,8 @@
cout << "target:" << endl;
m_depth++;
- node.GetTarget()->Accept(*this);
+ indent();
+ cout << node.GetName() << endl;
m_depth--;
if (node.HasArguments()) {
@@ -333,6 +334,47 @@
}
+void cDumpASTVisitor::visitObjectCall(cASTObjectCall& node)
+{
+ indent();
+ cout << "call:" << endl;
+ m_depth++;
+
+ indent();
+ cout << "target:" << endl;
+
+ m_depth++;
+ node.GetObject()->Accept(*this);
+ m_depth--;
+
+ if (node.HasArguments()) {
+ indent();
+ cout << "with:" << endl;
+
+ m_depth++;
+ node.GetArguments()->Accept(*this);
+ m_depth--;
+ }
+
+ m_depth--;
+
+}
+
+void cDumpASTVisitor::visitObjectReference(cASTObjectReference& node)
+{
+ m_depth++;
+ node.GetObject()->Accept(*this);
+ m_depth--;
+
+ indent();
+ cout << mapToken(AS_TOKEN_DOT) << endl;
+
+ m_depth++;
+ indent();
+ cout << node.GetName() << endl;
+ m_depth--;
+}
+
void cDumpASTVisitor::visitVariableReference(cASTVariableReference& node)
{
indent();
Modified: development/source/script/cDumpASTVisitor.h
===================================================================
--- development/source/script/cDumpASTVisitor.h 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/cDumpASTVisitor.h 2008-02-29 01:04:18 UTC (rev 2396)
@@ -56,6 +56,8 @@
void visitFunctionCall(cASTFunctionCall&);
void visitLiteral(cASTLiteral&);
void visitLiteralArray(cASTLiteralArray&);
+ void visitObjectCall(cASTObjectCall&);
+ void visitObjectReference(cASTObjectReference&);
void visitVariableReference(cASTVariableReference&);
void visitUnpackTarget(cASTUnpackTarget&);
Modified: development/source/script/cParser.cc
===================================================================
--- development/source/script/cParser.cc 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/cParser.cc 2008-02-29 01:04:18 UTC (rev 2396)
@@ -339,32 +339,32 @@
bool eoe = false;
while (!eoe) {
- switch (currentToken()) {
- case TOKEN(DOT):
- if (nextToken() != TOKEN(ID)) PARSE_UNEXPECT();
- ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(DOT), ce.Release(), new cASTVariableReference(FILEPOS, currentText())));
- nextToken(); // consume id
- break;
- case TOKEN(PREC_OPEN):
- cASTFunctionCall* fc = new cASTFunctionCall(FILEPOS, ce.Release());
- ce.Set(fc);
- if (nextToken() != TOKEN(PREC_CLOSE)) fc->SetArguments(parseArgumentList());
+ if (currentToken() == TOKEN(DOT)) {
+ if (nextToken() != TOKEN(ID)) PARSE_UNEXPECT();
+ cString name(currentText());
+ nextToken(); // consume id
+
+ if (currentToken() == TOKEN(PREC_OPEN)) {
+ cASTObjectCall* oc = new cASTObjectCall(FILEPOS, ce.Release(), name);
+ ce.Set(oc);
+ if (nextToken() != TOKEN(PREC_CLOSE)) oc->SetArguments(parseArgumentList());
if (currentToken() != TOKEN(PREC_CLOSE)) PARSE_UNEXPECT();
nextToken(); // consume ')'
// If the next token is not a continued call expression, then set the end-of-expression flag
if (currentToken() != TOKEN(IDX_OPEN) && currentToken() != TOKEN(DOT)) eoe = true;
- break;
- case TOKEN(IDX_OPEN):
- do {
- nextToken(); // consume '['
- ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(IDX_OPEN), ce.Release(), parseExpression()));
- if (currentToken() != TOKEN(IDX_CLOSE)) PARSE_UNEXPECT();
- } while (nextToken() == TOKEN(IDX_OPEN));
- break;
- default:
- if (required) { PARSE_UNEXPECT(); }
- else eoe = true;
+ } else {
+ ce.Set(new cASTObjectReference(FILEPOS, ce.Release(), name));
+ }
+ } else if (currentToken() == TOKEN(IDX_OPEN)) {
+ do {
+ nextToken(); // consume '['
+ ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(IDX_OPEN), ce.Release(), parseExpression()));
+ if (currentToken() != TOKEN(IDX_CLOSE)) PARSE_UNEXPECT();
+ } while (nextToken() == TOKEN(IDX_OPEN));
+ } else {
+ if (required) { PARSE_UNEXPECT(); }
+ else eoe = true;
}
}
@@ -576,10 +576,9 @@
break;
case TOKEN(ID):
if (peekToken() == TOKEN(PREC_OPEN)) {
- cASTNode* vr = new cASTVariableReference(FILEPOS, currentText());
- nextToken(); // consume id token
- cASTFunctionCall* fc = new cASTFunctionCall(FILEPOS, vr);
+ cASTFunctionCall* fc = new cASTFunctionCall(FILEPOS, currentText());
expr.Set(fc);
+ nextToken(); // consume id token
if (nextToken() != TOKEN(PREC_CLOSE)) fc->SetArguments(parseArgumentList());
if (currentToken() != TOKEN(PREC_CLOSE)) PARSE_UNEXPECT();
} else {
Modified: development/source/script/cSemanticASTVisitor.cc
===================================================================
--- development/source/script/cSemanticASTVisitor.cc 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/cSemanticASTVisitor.cc 2008-02-29 01:04:18 UTC (rev 2396)
@@ -148,9 +148,6 @@
node.GetRight()->Accept(*this);
switch (node.GetOperator()) {
- case TOKEN(DOT):
- // @TODO
- break;
case TOKEN(IDX_OPEN):
checkCast(node.GetLeft()->GetType(), TYPE(ARRAY));
checkCast(node.GetRight()->GetType(), TYPE(INT));
@@ -298,6 +295,16 @@
}
+void cSemanticASTVisitor::visitObjectCall(cASTObjectCall& node)
+{
+}
+
+
+void cSemanticASTVisitor::visitObjectReference(cASTObjectReference& node)
+{
+}
+
+
void cSemanticASTVisitor::visitVariableReference(cASTVariableReference& node)
{
int var_id = -1;
Modified: development/source/script/cSemanticASTVisitor.h
===================================================================
--- development/source/script/cSemanticASTVisitor.h 2008-02-28 21:05:26 UTC (rev 2395)
+++ development/source/script/cSemanticASTVisitor.h 2008-02-29 01:04:18 UTC (rev 2396)
@@ -86,6 +86,8 @@
void visitFunctionCall(cASTFunctionCall&);
void visitLiteral(cASTLiteral&);
void visitLiteralArray(cASTLiteralArray&);
+ void visitObjectCall(cASTObjectCall&);
+ void visitObjectReference(cASTObjectReference&);
void visitVariableReference(cASTVariableReference&);
void visitUnpackTarget(cASTUnpackTarget&);
More information about the Avida-cvs
mailing list