/**
* @brief Constructor.
*/
-RplASMethodCall::RplASMethodCall() :
+RplASMethodCall::RplASMethodCall(const QString& name) :
RplASNode2(AST_METHOD_CALL),
- RplASStatement()
+ RplASStatement(),
+ m_name(name),
+ m_method(NULL)
{
}
-RplASMethodCall::~RplASMethodCall()
-{
-
-}
/**
* @brief Writes the internals into a file.
{
DEFINE_TABS(indent);
char buffer[256];
- fprintf(fp, "%scall %d instance: %d args: %d %s\n", tabs, m_id,
- m_child == NULL ? 0 : m_child->id(),
+ fprintf(fp, "%scall %s Id: %d args: %d succ: %d %s\n", tabs,
+ m_name.toUtf8().constData(), m_id,
m_child2 == NULL ? 0 : m_child2->id(),
+ m_child == NULL ? 0 : m_child->id(),
positionStr(buffer, sizeof buffer));
- if (m_child != NULL)
- m_child->dump(fp, indent + 1);
if (m_child2 != NULL)
- m_child->dump(fp, indent + 1);
+ m_child2->dump(fp, indent + 1);
}
/**
* <code>m_child</code>: ???</br>
* <code>m_child2</code>: argument list (or NULL)
*/
-/**
- * @brief Sets the argument list.
- *
- * @param arg1 NULL or the first element of the argument list
- */
-void RplASMethodCall::setArg1(RplASArgument* arg1)
-{
- m_child2 = arg1;
-}
/** @class RplASBinaryOp rplastree.hpp "rplexpr/rplastree.hpp"
*
*/
void RplASArgument::dumpOne(FILE* fp, int no, int indent, char tabs[])
{
- int succ = child() == NULL ? 0 : child()->id();
- fprintf(fp, "%sArg %d id: %d expr: %d succ: %d\n", tabs, no, m_id,
+ int succ = m_child == NULL ? 0 : m_child->id();
+ fprintf(fp, "%sarg %d id: %d expr: %d succ: %d\n", tabs, no, m_id,
child2()->id(), succ);
- child2()->dump(fp, indent + 1);
+ m_child2->dump(fp, indent + 1);
}
/**
RplASArgument* current = this;
int no = 0;
do {
- dumpOne(fp, ++no, indent, tabs);
+ current->dumpOne(fp, ++no, indent, tabs);
current = static_cast<RplASArgument*>(current->child());
- } while (this != NULL);
+ } while (current != NULL);
+}
+
+/** @class RplASField rplastree.hpp "rplexpr/rplastree.hpp"
+ *
+ * @brief Implements an argument of a method for the Abstract Syntax Tree.
+ *
+ * <code>m_child</code>: parent (variable, field, method)<br>
+ */
+
+/**
+ * @brief Constructor.
+ *
+ * @param name name of the field
+ */
+RplASField::RplASField(const QString& name) :
+ RplASNode1(AST_FIELD),
+ m_name(name)
+{
+}
+
+/**
+ * @brief Writes the internals of the instance into a file.
+ *
+ * @param fp target file
+ * @param indent nesting level
+ */
+void RplASField::dump(FILE* fp, int indent)
+{
+ DEFINE_TABS(indent);
+ char buffer[256];
+ fprintf(fp, "%sfield %s id: %d expr: %d succ: %s\n", tabs,
+ m_name.toUtf8().constData(), m_id,
+ m_child->id(), positionStr(buffer, sizeof buffer));
+ m_child->dump(fp, indent + 1);
}
AST_MAP_CONSTANT,
AST_MAP_ENTRY,
AST_NAMED_VALUE,
+ AST_FIELD,
AST_VAR_DEFINITION,
AST_EXPR_STATEMENT,
AST_METHOD,
class RplASMethodCall : public RplASNode2, public RplASStatement
{
public:
- RplASMethodCall();
- virtual ~RplASMethodCall();
+ RplASMethodCall(const QString& name);
public:
void dump(FILE* fp, int indent);
virtual void execute();
void setMethod(RplASMethod* method);
RplASArgument*arg1() const;
- void setArg1(RplASArgument* arg1);
private:
+ QString m_name;
RplASMethod* m_method;
};
RplASNamedValue* m_default;
};
+class RplASField : public RplASNode1
+{
+public:
+ RplASField(const QString& name);
+public:
+ void dump(FILE* fp, int indent);
+private:
+ QString m_name;
+};
+
class RplASClass;
class RplASMethod : public RplASNode2
readNext = false;
} else {
if (token->id() == O_LPARENTH){
- RplASMethodCall* call = new RplASMethodCall();
+ RplASMethodCall* call = new RplASMethodCall(name);
call->setPosition(startPosition);
rc = call;
if (! token->isOperator(O_RPARENT)){
m_lexer.undoLastToken();
RplASArgument* args = parseArguments();
- call->setArg1(args);
+ call->setChild2(args);
+ readNext = false;
}
} else {
RplASNamedValue* var = new RplASNamedValue(name);
RplASArgument* RplMFParser::parseArguments()
{
RplASArgument* first = NULL;
+ RplASArgument* last = NULL;
bool again = false;
do {
RplASItem* expr = parseExpr(0);
if (! m_lexer.currentToken()->isOperator(O_COMMA, O_RPARENT))
syntaxError(L_PARSE_ARGS_NO_COMMA_OR_PARENT, "',' or ')' expected");
again = m_lexer.currentToken()->isOperator(O_COMMA);
- m_lexer.nextNonSpaceToken();
RplASArgument* current = new RplASArgument();
current->setPosition(expr->position());
+ current->setChild2(expr);
+ if (first == NULL)
+ first = last = current;
+ else{
+ last->setChild(current);
+ last = current;
+ }
} while (again);
+ // skip ')':
+ m_lexer.nextNonSpaceToken();
return first;
}
--- /dev/null
+rand();
+sin(a);
+max(1+2*3,4**(5-4));
+= <test> (module) parent: global
+== Classes:
+== Variables:
+== Body:
+Expr id: 2 expr: 1 succ: 6 <test>:1:4
+ call rand Id: 1 args: 0 succ: 0 <test>:1:4
+Expr id: 6 expr: 3 succ: 20 <test>:2:3
+ call sin Id: 3 args: 5 succ: 0 <test>:2:3
+ Arg 1 id: 5 expr: 4 succ: 0
+ namedValue a id: 4 attr: 0x0 <test>:2:5
+Expr id: 20 expr: 7 succ: 0 <test>:3:3
+ call max Id: 7 args: 13 succ: 0 <test>:3:3
+ Arg 1 id: 13 expr: 9 succ: 19
+ BinOp id: 9 op: + (26) left: 8 right: 11 <test>:3:5
+ const id: 8 value: 1 <test>:3:4
+ BinOp id: 11 op: * (30) left: 10 right: 12 <test>:3:7
+ const id: 10 value: 2 <test>:3:6
+ const id: 12 value: 3 <test>:3:8
+ Arg 2 id: 19 expr: 15 succ: 0
+ BinOp id: 15 op: ** (31) left: 14 right: 17 <test>:3:11
+ const id: 14 value: 4 <test>:3:10
+ BinOp id: 17 op: - (27) left: 16 right: 18 <test>:3:15
+ const id: 16 value: 5 <test>:3:14
+ const id: 18 value: 4 <test>:3:16