From: Mike D. Lowis Date: Thu, 8 Mar 2012 20:31:46 +0000 (-0500) Subject: Created seperate debug build with memory leak detection. Removed cork dependency... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8694632c3a03ddc08a639c9454f91193541e1ae2;p=archive%2Fdlang.git Created seperate debug build with memory leak detection. Removed cork dependency from release build --- diff --git a/example.dl b/example.dl index e684e12..4254f91 100644 --- a/example.dl +++ b/example.dl @@ -3,64 +3,64 @@ #------------------------------------------------------------------------------ # VectorLiteral -#foo = [] -#foo = [1] -#foo = [1,2,3] -#foo = foo[1] -#foo = [1,2,3,4,5][2] +foo = [] +foo = [1] +foo = [1,2,3] +foo = foo[1] +foo = [1,2,3,4,5][2] # ListLiteral -#foo = () -#foo = (1,2,3) -#foo = foo[1] -#foo = (1,2,3,4,5)[2] +foo = () +foo = (1,2,3) +foo = foo[1] +foo = (1,2,3,4,5)[2] # FuncLiteral foo = { 1 + 1 } -#foo = {|a| a + 1} -#foo = {|a,b| a + b } -#foo = foo(1,2) -#foo = ({|a,b| a + b })(1,2) +foo = {|a| a + 1} +foo = {|a,b| a + b } +foo = foo(1,2) +foo = ({|a,b| a + b })(1,2) # ID -#foo = bar -#foo.bar = bar +foo = bar +foo.bar = bar # NUM -#foo = 1 -#foo = 1.0 +foo = 1 +foo = 1.0 # CHAR -#foo = 'a' +foo = 'a' # STRING -#foo = "some string" -#foo = "12345"[2] +foo = "some string" +foo = "12345"[2] # SYMBOL -#foo = $some_symbol +foo = $some_symbol # MAP -#foo = { -# $foo : 1 + 1, -# $bar : 2 + 2, -# $stuff : 3 + 3 -#} +foo = { + $foo : 1 + 1, + $bar : 2 + 2, + $stuff : 3 + 3 +} # Macro -#% if [ -# (Expression Block Block) : exec_if($1, $2, $3), -# (Expression Block) : exec_if($1, $2) -#] +% if [ + (Expression Block Block) : exec_if($1, $2, $3), + (Expression Block) : exec_if($1, $2) +] -#if (1==1) -#{ -# 1 + 1 -#}{ -# -#} -# -#if (1 == 1) -#{ -# -#} +if (1==1) +{ + 1 + 1 +}{ + +} + +if (1 == 1) +{ + +} diff --git a/rakefile.rb b/rakefile.rb index 98622c7..54311e7 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -15,15 +15,32 @@ CLOBBER.include('./deps/parse-utils/build/shared') #------------------------------------------------------------------------------ # Configuration Objects #------------------------------------------------------------------------------ -# Configuration for the binary artifact +# Configuration for the release binary artifact DLangParser = Binary.new({ :name => 'dlang', - :output_dir => 'build/parser', + :output_dir => 'build/release', + :compiler_options => [ '-c', '-Wall', '-Werror', '-o' ], + :static_libs => [ + './deps/parse-utils/build/static/bin/libparse-utils.a', + ], + :source_files => [ 'source/**/*.c*' ], + :include_dirs => [ + 'source/**/', + 'deps/parse-utils/source/**/' + ], +}) +DLangParser.setup_default_rake_tasks() + +# Configuration for the release binary artifact +DLangDebug = Binary.new({ + :name => 'dlang', + :output_dir => 'build/debug', :compiler_options => [ '-c', '-Wall', '-Werror', '-o' ], :static_libs => [ './deps/cork/build/static/bin/libcork.a', './deps/parse-utils/build/static/bin/libparse-utils.a', ], + :preprocessor_defines => [ 'DEBUG' ], :source_files => [ 'source/**/*.c*' ], :include_dirs => [ 'source/**/', @@ -31,7 +48,7 @@ DLangParser = Binary.new({ 'deps/parse-utils/source/**/' ], }) -DLangParser.setup_default_rake_tasks() +DLangDebug.setup_default_rake_tasks() # Configuration for the unit tests UnitTest = Tests.new({ @@ -39,8 +56,12 @@ UnitTest = Tests.new({ }) UnitTest.setup_default_rake_tasks() +#------------------------------------------------------------------------------ +# Main Tasks +#------------------------------------------------------------------------------ desc 'Build and link all artifacts' -task :release => [ :cork, :parse_utils, DLangParser.name() ] +task :release => [ :parse_utils, DLangParser.name() ] +task :debug => [ :cork, :parse_utils, DLangDebug.name() ] desc 'Build the cork memory leak detector' task :cork do diff --git a/source/common.h b/source/common.h new file mode 100644 index 0000000..10f8c76 --- /dev/null +++ b/source/common.h @@ -0,0 +1,10 @@ +#ifndef COMMON_H +#define COMMON_H + +#ifdef DEBUG + #include "cork.h" +#else + #define _new new +#endif + +#endif diff --git a/source/dllexer/dllexer.cpp b/source/dllexer/dllexer.cpp index 96e72c0..92f7cbe 100644 --- a/source/dllexer/dllexer.cpp +++ b/source/dllexer/dllexer.cpp @@ -1,6 +1,6 @@ #include "dllexer.h" #include "exception.h" -#include "cork.h" +#include "common.h" using namespace std; diff --git a/source/dlparser/dlparser.cpp b/source/dlparser/dlparser.cpp index de4f912..77bc480 100644 --- a/source/dlparser/dlparser.cpp +++ b/source/dlparser/dlparser.cpp @@ -1,6 +1,6 @@ #include "dlparser.h" #include "exception.h" -#include "cork.h" +#include "common.h" DLParser::DLParser() : BTParser(_new DLLexer()) { @@ -417,22 +417,30 @@ AST* DLParser::Literal(void) AST* DLParser::MapLiteral(void) { AST* ret = NULL; - - match(LBRACE); - do + AST* child = NULL; + try { - if( lookaheadType(1) == COMMA ) consume(); + match(LBRACE); + do + { + if( lookaheadType(1) == COMMA ) consume(); - AST* child = Literal(); - match(SEP); - child = _new AST(SEP, 2, child, LogicalExpr()); + child = Literal(); + match(SEP); + child = _new AST(SEP, 2, child, LogicalExpr()); - ret = ((ret == NULL) ? _new AST(MAP) : ret); - ret->addChild(child); + ret = ((ret == NULL) ? _new AST(MAP) : ret); + ret->addChild(child); + } + while( lookaheadType(1) == COMMA ); + match(RBRACE); + } + catch(Exception e) + { + if(ret != NULL) delete ret; + if(child != NULL) delete child; + throw e; } - while( lookaheadType(1) == COMMA ); - match(RBRACE); - return ret; } diff --git a/source/dlparser/macro/pattern.cpp b/source/dlparser/macro/pattern.cpp index 0fcfb5b..7a81829 100644 --- a/source/dlparser/macro/pattern.cpp +++ b/source/dlparser/macro/pattern.cpp @@ -5,8 +5,15 @@ Pattern::Pattern(const std::list& patt, const AST* ast) : pattern { } +Pattern::Pattern(const Pattern& patt) +{ + pattern = patt.pattern; + expr_ast = patt.expr_ast->clone(); +} + Pattern::~Pattern() { + delete expr_ast; } std::list::iterator Pattern::begin() diff --git a/source/dlparser/macro/pattern.h b/source/dlparser/macro/pattern.h index 225ec02..33c9be4 100644 --- a/source/dlparser/macro/pattern.h +++ b/source/dlparser/macro/pattern.h @@ -26,6 +26,7 @@ class Pattern { void apply(AST* cur,std::vector& params); public: Pattern(const std::list& patt, const AST* ast); + Pattern(const Pattern& patt); ~Pattern(); std::list::iterator begin(); std::list::iterator end(); diff --git a/source/main.cpp b/source/main.cpp index 35a4614..019416f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -5,7 +5,7 @@ #include "dlparser.h" #include "astprinter.h" #include "scheme.h" -#include "cork.h" +#include "common.h" #include "macro.h" using namespace std; @@ -51,7 +51,9 @@ int main(int argc, char** argv) cerr << "Error: No input files." << endl; } +#ifdef DEBUG Cork_ReportMemoryLeaks(); +#endif return ret; }