From 5289346900d5dda116167a1c12c963a27ea3ce49 Mon Sep 17 00:00:00 2001 From: binrapt Date: Sat, 17 Oct 2009 10:20:41 +0200 Subject: [PATCH] Implemented the construction pattern for lexemes --- fridh/lexer.hpp | 6 +++++- lexer/lexeme.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fridh/lexer.hpp b/fridh/lexer.hpp index 54fa989..cf01a52 100644 --- a/fridh/lexer.hpp +++ b/fridh/lexer.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace fridh @@ -111,7 +112,7 @@ namespace fridh typedef std::vector lexeme_container; typedef std::vector lines_of_code; - struct lexeme + struct lexeme: public construction_pattern { lexeme_type::type type; union @@ -131,6 +132,9 @@ namespace fridh explicit lexeme(types::floating_point_value floating_point_value); explicit lexeme(std::string const & string); std::string to_string() const; + + void copy(construction_pattern const & other_pattern); + void destroy(); }; struct line_of_code diff --git a/lexer/lexeme.cpp b/lexer/lexeme.cpp index af99826..3925488 100644 --- a/lexer/lexeme.cpp +++ b/lexer/lexeme.cpp @@ -206,4 +206,19 @@ namespace fridh return "unknown"; } } + + void lexeme::copy(construction_pattern const & other_pattern) + { + lexeme const & other = dynamic_cast(other_pattern); + + type = other.type; + if(type == lexeme_type::string) + string = new std::string(*other.string); + } + + void lexeme::destroy() + { + if(type == lexeme_type::string) + delete string; + } } -- 2.11.4.GIT