]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Uploaded macro and param files
authorMike D. Lowis <mike@mdlowis.com>
Mon, 27 Feb 2012 01:04:54 +0000 (20:04 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Mon, 27 Feb 2012 01:04:54 +0000 (20:04 -0500)
source/dlparser/macro/macro.cpp [new file with mode: 0644]
source/dlparser/macro/param.cpp [new file with mode: 0644]

diff --git a/source/dlparser/macro/macro.cpp b/source/dlparser/macro/macro.cpp
new file mode 100644 (file)
index 0000000..a01f804
--- /dev/null
@@ -0,0 +1,57 @@
+#include "macro.h"
+#include "macroapplication.h"
+#include "cork.h"
+
+using namespace std;
+
+Macro::Macro(AST* macro_def)
+{
+    list<AST*>::iterator it = macro_def->children()->begin();
+
+    // Set Name
+    macro_name = (*it++)->text();
+
+    // Set Body
+    setUpParamList( *it++ );
+
+    // Set Params
+    macro_body = (*it++)->clone();
+
+}
+
+Macro::~Macro()
+{
+
+    std::list<Param*>::iterator iter;
+    for (iter = macro_params.begin(); iter != macro_params.end(); ++iter) {
+        delete *iter;
+    }
+    delete macro_body;
+}
+
+const std::string& Macro::name(void)
+{
+    return macro_name;
+}
+
+const std::list<Param*>& Macro::params(void)
+{
+    return macro_params;
+}
+
+AST* Macro::apply(void)
+{
+    MacroApplication application(macro_body->clone(), macro_params);
+    application.visit();
+    return application.getAST()->clone();
+}
+
+void Macro::setUpParamList( AST* param_tree )
+{
+    list<AST*>::iterator it = param_tree->children()->begin();
+    for(; it != param_tree->children()->end(); it++)
+    {
+        macro_params.push_back( _new Param( *it ) );
+    }
+}
+
diff --git a/source/dlparser/macro/param.cpp b/source/dlparser/macro/param.cpp
new file mode 100644 (file)
index 0000000..367c118
--- /dev/null
@@ -0,0 +1,60 @@
+#include "param.h"
+
+Param::Param(AST* param_def)
+{
+    int children = param_def->children()->size();
+    if( children == 0 )
+    {
+        param_name = param_def->text();
+    }
+    else if( children == 2)
+    {
+        param_name = param_def->children()->front()->text();
+        setType( param_def->children()->front()->text() );
+    }
+    else
+    {
+        // Throw
+    }
+}
+
+Param::~Param()
+{
+    if( param_value != NULL )
+    {
+        delete param_value;
+    }
+}
+
+std::string Param::name(void)
+{
+    return param_name;
+}
+
+ParamType_T Param::type(void)
+{
+    return param_type;
+}
+
+AST* Param::value(void)
+{
+    return param_value;
+}
+
+void Param::setValue(AST* val)
+{
+    param_value = val;
+}
+
+void Param::setType( const std::string& type_string )
+{
+    if ( type_string.compare("Block") == 0 )
+    {
+        param_type = BlockTyp;
+    }
+    else
+    {
+        param_type = ExpTyp;
+    }
+}
+