From: Mike D. Lowis Date: Sat, 3 Mar 2012 18:33:16 +0000 (-0500) Subject: Delete macro helper classes and disabled macro expansion X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=aba57355eb02b54853400e64ccbcc5b31889d237;p=archive%2Fdlang.git Delete macro helper classes and disabled macro expansion --- diff --git a/source/dlparser/dlparser.cpp b/source/dlparser/dlparser.cpp index 90d4470..fbb4b60 100644 --- a/source/dlparser/dlparser.cpp +++ b/source/dlparser/dlparser.cpp @@ -29,31 +29,6 @@ bool DLParser::isMacro( Token& token ) return ret; } -AST* DLParser::parseMacroParam(Param* param) -{ - AST* ret = NULL; - switch( param->type() ) - { - case ExpTyp: - ret = LogicalExpr(); - break; - - case BlockTyp: - ret = FuncLiteral(); - break; - - default: - Token& tok = lookaheadToken(1); - ostringstream oss; - oss << "Expected macro parameter type. Expected " << param->type() << ", received " << tok.type() << "."; - Exception ex( tok.line(), tok.column() ); - ex.setMessage(oss.str()); - throw ex; - break; - } - return ret; -} - bool DLParser::speculate_GroupExpr(void) { AST* throw_away = NULL; @@ -336,22 +311,6 @@ AST* DLParser::MacroDefinition(void) return _new AST(MACRO); } -AST* DLParser::MacroExpansion(void) -{ - AST* ret = NULL; - Macro* cur_macro = macros[ lookaheadToken(1).text() ]; - list::const_iterator it = cur_macro->params().begin(); - - consume(); - for(; it != cur_macro->params().end(); it++) - { - (*it)->setValue( parseMacroParam( *it ) ); - } - ret = cur_macro->apply(); - - return ret; -} - // MacroPatternList = MacroPattern (',' MacroPattern)* AST* DLParser::MacroPatternList(void) { @@ -381,15 +340,6 @@ AST* DLParser::MacroPattern(void) match(SEP); ret = _new AST(PATT, 2, ret, LogicalExpr()); - //AST* ret = _new AST( ID, lookaheadToken(1).text() ); - //consume(); - //if( lookaheadType(1) == SEP ) - //{ - // match(SEP); - // AST* type = _new AST( ID, lookaheadToken(1).text() ); - // consume(); - // ret = _new AST(SEP, 2, ret, type); - //} return ret; } diff --git a/source/dlparser/dlparser.h b/source/dlparser/dlparser.h index 96ab7d1..5a0b667 100644 --- a/source/dlparser/dlparser.h +++ b/source/dlparser/dlparser.h @@ -4,7 +4,8 @@ #include #include "btparser.h" #include "dllexer.h" -#include "macro.h" + +class Macro{}; class DLParser : public BTParser { @@ -15,7 +16,6 @@ class DLParser : public BTParser ~DLParser(); AST* parse(void); bool isMacro(Token& token); - AST* parseMacroParam(Param* param); bool speculate_GroupExpr(void); /********************************************************************** @@ -92,7 +92,6 @@ class DLParser : public BTParser // Macro Rules AST* MacroDefinition(void); - AST* MacroExpansion(void); AST* MacroPatternList(void); AST* MacroPattern(void); diff --git a/source/dlparser/macro/macro.cpp b/source/dlparser/macro/macro.cpp deleted file mode 100644 index a01f804..0000000 --- a/source/dlparser/macro/macro.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "macro.h" -#include "macroapplication.h" -#include "cork.h" - -using namespace std; - -Macro::Macro(AST* macro_def) -{ - list::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::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& 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::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/macro.h b/source/dlparser/macro/macro.h deleted file mode 100644 index 8c73c3f..0000000 --- a/source/dlparser/macro/macro.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MACRO_H -#define MACRO_H - -#include -#include -#include "param.h" -#include "ast.h" - -class Macro -{ - private: - std::string macro_name; - std::list macro_params; - AST* macro_body; - - void setUpParamList( AST* param_tree ); - public: - Macro(AST* macro_def); - ~Macro(); - - const std::string& name(void); - const std::list& params(void); - AST* apply(void); -}; - -#endif diff --git a/source/dlparser/macro/param.cpp b/source/dlparser/macro/param.cpp deleted file mode 100644 index 367c118..0000000 --- a/source/dlparser/macro/param.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#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; - } -} - diff --git a/source/dlparser/macro/param.h b/source/dlparser/macro/param.h deleted file mode 100644 index b6787ca..0000000 --- a/source/dlparser/macro/param.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PARAM -#define PARAM - -#include -#include "ast.h" - -typedef enum { - ExpTyp, - BlockTyp -} ParamType_T; - -class Param -{ - private: - std::string param_name; - ParamType_T param_type; - AST* param_value; - - void setType( const std::string& type_string ); - - public: - Param(AST* param_def); - ~Param(); - - std::string name(void); - ParamType_T type(void); - AST* value(void); - void setValue(AST* val); -}; - -#endif diff --git a/source/visitors/macroapplication/macroapplication.cpp b/source/visitors/macroapplication/macroapplication.cpp deleted file mode 100644 index 5eefc0a..0000000 --- a/source/visitors/macroapplication/macroapplication.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "macroapplication.h" -#include "dllexer.h" - -using namespace std; - -Param* MacroApplication::getParamByName(std::string name) -{ - Param* ret = NULL; - std::list::iterator it = macro_params.begin(); - for(; it != macro_params.end(); it++) - { - if( (*it)->name().compare( name ) == 0) - { - ret = *it; - break; - } - } - return ret; -} - -AST* MacroApplication::getAST(void) -{ - return mod_ast; -} - -void MacroApplication::beforeVisit(AST* cur, int depth) -{ -} - -void MacroApplication::afterVisit(AST* cur, int depth) -{ -} - -void MacroApplication::beforeChildren(AST* cur, int depth) -{ - if(cur->type() == ID) - { - Param* param = getParamByName( cur->text() ); - if( param != NULL ) - { - (*cur) = *(param->value()); - } - } -} - -void MacroApplication::afterChildren(AST* cur, int depth) -{ -} - -void MacroApplication::beforeChild(AST* cur, int depth) -{ -} - -void MacroApplication::afterChild(AST* cur, int depth) -{ -} - diff --git a/source/visitors/macroapplication/macroapplication.h b/source/visitors/macroapplication/macroapplication.h deleted file mode 100644 index dac41c9..0000000 --- a/source/visitors/macroapplication/macroapplication.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MacroApplication_H -#define MacroApplication_H - -#include "ivisitor.h" -#include -#include -#include "param.h" - -class MacroApplication : public IVisitor { - protected: - AST* mod_ast; - std::ostringstream stream; - std::list macro_params; - public: - MacroApplication(AST* root,std::list& params) : IVisitor(root), mod_ast(root), macro_params(params) {}; - Param* getParamByName(std::string name); - AST* getAST(void); - private: - void beforeVisit(AST* cur, int depth); - void afterVisit(AST* cur, int depth); - void beforeChildren(AST* cur, int depth); - void afterChildren(AST* cur, int depth); - void beforeChild(AST* cur, int depth); - void afterChild(AST* cur, int depth); -}; - -#endif