diff --git a/src/FEQParse.F90 b/src/FEQParse.F90 index db63855..ddf998f 100644 --- a/src/FEQParse.F90 +++ b/src/FEQParse.F90 @@ -62,6 +62,7 @@ module FEQParse type(TokenStack) :: inFix type(TokenStack) :: postFix contains + final :: Finalize_EquationParser procedure :: CleanEquation procedure :: Tokenize procedure :: ConvertToPostfix @@ -128,6 +129,26 @@ function Construct_EquationParser(equation,indepVars) result(parser) endfunction Construct_EquationParser + subroutine Finalize_EquationParser(parser) + type(EquationParser),intent(inout) :: parser + ! Local + integer :: i + + if(allocated(parser%inFixFormula)) deallocate(parser%inFixFormula) + if(allocated(parser%equation)) deallocate(parser%equation) + if(allocated(parser%variableName)) deallocate(parser%variableName) + if(allocated(parser%indepVars)) then + do i = 1,parser%nIndepVars + deallocate(parser%indepVars(i)%value) + enddo + deallocate(parser%indepVars) + endif + + call parser%infix%Finalize() + call parser%postfix%Finalize() + + endsubroutine Finalize_EquationParser + subroutine CleanEquation(parser,equationCleaned) class(EquationParser),intent(inout) :: parser logical,intent(out) :: equationCleaned @@ -323,8 +344,6 @@ subroutine ConvertToPostFix(parser) type(Token) :: tok integer :: i - !success = .FALSE. - call parser%postfix%Construct(Stack_Length) call operator_stack%Construct(Stack_Length) @@ -489,6 +508,7 @@ function Evaluate_sfp32(parser,x) result(f) call stack%Pop(a) f = a + endfunction Evaluate_sfp32 function Evaluate_sfp64(parser,x) result(f) diff --git a/src/FEQParse_FloatStacks.F90 b/src/FEQParse_FloatStacks.F90 index e01dd3f..35b464c 100644 --- a/src/FEQParse_FloatStacks.F90 +++ b/src/FEQParse_FloatStacks.F90 @@ -27,6 +27,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_sfp32Stack + final :: Finalize_sfp32Stack procedure :: Push => Push_sfp32Stack procedure :: Pop => Pop_sfp32Stack @@ -38,6 +39,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_sfp64Stack + final :: Finalize_sfp64Stack procedure :: Push => Push_sfp64Stack procedure :: Pop => Pop_sfp64Stack @@ -49,6 +51,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r1fp32Stack + final :: Finalize_r1fp32Stack procedure :: Push => Push_r1fp32Stack procedure :: Pop => Pop_r1fp32Stack @@ -60,6 +63,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r1fp64Stack + final :: Finalize_r1fp64Stack procedure :: Push => Push_r1fp64Stack procedure :: Pop => Pop_r1fp64Stack @@ -71,6 +75,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r2fp32Stack + final :: Finalize_r2fp32Stack procedure :: Push => Push_r2fp32Stack procedure :: Pop => Pop_r2fp32Stack @@ -82,6 +87,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r2fp64Stack + final :: Finalize_r2fp64Stack procedure :: Push => Push_r2fp64Stack procedure :: Pop => Pop_r2fp64Stack @@ -93,6 +99,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r3fp32Stack + final :: Finalize_r3fp32Stack procedure :: Push => Push_r3fp32Stack procedure :: Pop => Pop_r3fp32Stack @@ -104,6 +111,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r3fp64Stack + final :: Finalize_r3fp64Stack procedure :: Push => Push_r3fp64Stack procedure :: Pop => Pop_r3fp64Stack @@ -115,6 +123,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r4fp32Stack + final :: Finalize_r4fp32Stack procedure :: Push => Push_r4fp32Stack procedure :: Pop => Pop_r4fp32Stack @@ -126,6 +135,7 @@ module FEQParse_FloatStacks contains procedure :: Construct => Construct_r4fp64Stack + final :: Finalize_r4fp64Stack procedure :: Push => Push_r4fp64Stack procedure :: Pop => Pop_r4fp64Stack @@ -142,6 +152,13 @@ subroutine Construct_sfp32Stack(stack,N) endsubroutine Construct_sfp32Stack + subroutine Finalize_sfp32Stack(stack) + type(sfp32Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_sfp32Stack + subroutine Push_sfp32Stack(stack,tok) class(sfp32Stack),intent(inout) :: stack real(real32),intent(in) :: tok @@ -173,6 +190,13 @@ subroutine Construct_sfp64Stack(stack,N) endsubroutine Construct_sfp64Stack + subroutine Finalize_sfp64Stack(stack) + type(sfp64Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_sfp64Stack + subroutine Push_sfp64Stack(stack,tok) class(sfp64Stack),intent(inout) :: stack real(real64),intent(in) :: tok @@ -214,6 +238,13 @@ subroutine Construct_r1fp32Stack(stack,N,mold) endsubroutine Construct_r1fp32Stack + subroutine Finalize_r1fp32Stack(stack) + type(r1fp32Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r1fp32Stack + subroutine Push_r1fp32Stack(stack,tok) class(r1fp32Stack),intent(inout) :: stack real(real32),intent(in) :: tok(:) @@ -252,6 +283,13 @@ subroutine Construct_r1fp64Stack(stack,N,mold) endsubroutine Construct_r1fp64Stack + subroutine Finalize_r1fp64Stack(stack) + type(r1fp64Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r1fp64Stack + subroutine Push_r1fp64Stack(stack,tok) class(r1fp64Stack),intent(inout) :: stack real(real64),intent(in) :: tok(:) @@ -291,6 +329,13 @@ subroutine Construct_r2fp32Stack(stack,N,mold) endsubroutine Construct_r2fp32Stack + subroutine Finalize_r2fp32Stack(stack) + type(r2fp32Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r2fp32Stack + subroutine Push_r2fp32Stack(stack,tok) class(r2fp32Stack),intent(inout) :: stack real(real32),intent(in) :: tok(:,:) @@ -330,6 +375,13 @@ subroutine Construct_r2fp64Stack(stack,N,mold) endsubroutine Construct_r2fp64Stack + subroutine Finalize_r2fp64Stack(stack) + type(r2fp64Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r2fp64Stack + subroutine Push_r2fp64Stack(stack,tok) class(r2fp64Stack),intent(inout) :: stack real(real64),intent(in) :: tok(:,:) @@ -370,6 +422,13 @@ subroutine Construct_r3fp32Stack(stack,N,mold) endsubroutine Construct_r3fp32Stack + subroutine Finalize_r3fp32Stack(stack) + type(r3fp32Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r3fp32Stack + subroutine Push_r3fp32Stack(stack,tok) class(r3fp32Stack),intent(inout) :: stack real(real32),intent(in) :: tok(:,:,:) @@ -410,6 +469,13 @@ subroutine Construct_r3fp64Stack(stack,N,mold) endsubroutine Construct_r3fp64Stack + subroutine Finalize_r3fp64Stack(stack) + type(r3fp64Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r3fp64Stack + subroutine Push_r3fp64Stack(stack,tok) class(r3fp64Stack),intent(inout) :: stack real(real64),intent(in) :: tok(:,:,:) @@ -451,6 +517,13 @@ subroutine Construct_r4fp32Stack(stack,N,mold) endsubroutine Construct_r4fp32Stack + subroutine Finalize_r4fp32Stack(stack) + type(r4fp32Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r4fp32Stack + subroutine Push_r4fp32Stack(stack,tok) class(r4fp32Stack),intent(inout) :: stack real(real32),intent(in) :: tok(:,:,:,:) @@ -492,6 +565,13 @@ subroutine Construct_r4fp64Stack(stack,N,mold) endsubroutine Construct_r4fp64Stack + subroutine Finalize_r4fp64Stack(stack) + type(r4fp64Stack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_r4fp64Stack + subroutine Push_r4fp64Stack(stack,tok) class(r4fp64Stack),intent(inout) :: stack real(real64),intent(in) :: tok(:,:,:,:) diff --git a/src/FEQParse_TokenStack.F90 b/src/FEQParse_TokenStack.F90 index eb2ba6c..3d43fd0 100644 --- a/src/FEQParse_TokenStack.F90 +++ b/src/FEQParse_TokenStack.F90 @@ -29,6 +29,7 @@ module FEQParse_TokenStack integer :: top_index = 0 contains procedure :: Construct => Construct_TokenStack + procedure :: Finalize => Finalize_TokenStack procedure :: Push => Push_TokenStack procedure :: Pop => Pop_TokenStack procedure :: IsEmpty => IsEmpty_TokenStack @@ -46,6 +47,13 @@ subroutine Construct_TokenStack(stack,N) endsubroutine Construct_TokenStack + subroutine Finalize_TokenStack(stack) + class(TokenStack),intent(inout) :: stack + + if(allocated(stack%tokens)) deallocate(stack%tokens) + + endsubroutine Finalize_TokenStack + subroutine Push_TokenStack(stack,tok) class(TokenStack),intent(inout) :: stack type(Token),intent(in) :: tok