From 4470c8e787cd67824647b5d0a80137892fbe2d06 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Thu, 8 Aug 2019 17:52:59 +0800 Subject: [PATCH] finish functions --- version0.2/nasal_functional.cpp | 84 ++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/version0.2/nasal_functional.cpp b/version0.2/nasal_functional.cpp index 643a505..89ddcd3 100644 --- a/version0.2/nasal_functional.cpp +++ b/version0.2/nasal_functional.cpp @@ -18,14 +18,94 @@ func::func() } func::func(const func& temp) { - ; + token_unit *statement_temp=statement_head; + token_unit *temp_state=temp.statement_head; + parameter *parameter_temp=parameter_head; + parameter *temp_param=temp.parameter_head; + while(temp_state->next) + { + temp_state=temp_state->next; + statement_temp->next=new token_unit; + statement_temp=statement_temp->next; + statement_temp->line=temp_state->line; + statement_temp->content=temp_state->content; + statement_temp->type=temp_state->type; + statement_temp->next=NULL; + } + while(temp_param->next) + { + temp_param=temp_param->next; + parameter_temp->next=new parameter; + parameter_temp->param_var=temp_param->param_var; + parameter_temp->next=NULL; + } } func::~func() { - ; + token_unit *statement_temp=statement_head; + token_unit *statement_last_unit=NULL; + parameter *parameter_temp=parameter_head; + parameter *parameter_last_unit=NULL; + + while(statement_temp->next) + { + statement_last_unit=statement_temp; + statement_temp=statement_temp->next; + delete statement_last_unit; + } + delete statement_temp; + while(parameter_temp->next) + { + parameter_last_unit=parameter_temp; + parameter_temp=parameter_temp->next; + delete parameter_last_unit; + } + delete parameter_temp; } func& func::operator=(const func& temp) { + token_unit *statement_temp=statement_head; + token_unit *temp_state=temp.statement_head; + parameter *parameter_temp=parameter_head; + parameter *temp_param=temp.parameter_head; + + token_unit *statement_last=NULL; + parameter *parameter_last=NULL; + while(statement_temp->next) + { + statement_last=statement_temp; + statement_temp=statement_temp->next; + delete statement_last; + } + delete statement_temp; + while(parameter_temp->next) + { + parameter_last=parameter_temp; + parameter_temp=parameter_temp->next; + delete parameter_last; + } + delete parameter_temp; + statement_head->next=NULL; + parameter_head->next=NULL; + statement_temp=statement_head; + parameter_temp=parameter_head; + while(temp_state->next) + { + temp_state=temp_state->next; + statement_temp->next=new token_unit; + statement_temp=statement_temp->next; + statement_temp->line=temp_state->line; + statement_temp->content=temp_state->content; + statement_temp->type=temp_state->type; + statement_temp->next=NULL; + } + while(temp_param->next) + { + temp_param=temp_param->next; + parameter_temp->next=new parameter; + parameter_temp->param_var=temp_param->param_var; + parameter_temp->next=NULL; + } return *this; }