Commit 67fdad79 authored by Colin Eles's avatar Colin Eles
Browse files

added some primitive typing to the tool, user can enter a type for an input...

added some primitive typing to the tool, user can enter a type for an input variable using : notation, the typing currently is only used in the pvs theory not in the simulink model

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/trunk/TableTool@5769 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 5e9463ef
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ classdef Cell < handle
        color = [];
        
        condition_text_width = 200;
        condition_text_height = 40;
        condition_text_height = 60;
        condition_text_x = 10;
        condition_text_y = 10;
        condition_text_offset = 20;
+57 −9
Original line number Diff line number Diff line
@@ -294,7 +294,14 @@ classdef GUI < handle
            load_system('simulink')
            % generate the code
            code = [];
            code = sprintf('function output = %s(%s)\noutput=0;\n',get(object.function_name_control,'String'),get(object.function_inputs_control,'String'))
            
            %generate input list
            parsed_input = object.parse_inputs(get(object.function_inputs_control,'string'))
            input = []
            for i= 1:size(parsed_input,2)
                input = [input char(parsed_input{i}(1)) ',']
            end
            code = sprintf('function output = %s(%s)\noutput=0;\n',get(object.function_name_control,'String'),input)
            code = [code object.generate_code(object.Grid1,object.Grid2,0)];
            fprintf('%s',code);
            
@@ -306,7 +313,7 @@ classdef GUI < handle
            
            % determine if the name already exists in the model
            
            if (~strcmp(get(object.block_handle,'Name'),get(object.function_name_text,'String')))
            if (~strcmp(get(object.block_handle,'Name'),get(object.function_name_control,'String')))
                try
                set_param(object.block_handle,'Name',get(object.function_name_control,'String'));
                catch exception
@@ -532,9 +539,17 @@ classdef GUI < handle
        %   none
        function error = check_call(object,src,event)
            error = 0;
            
            msg = object.check_inputs;
            if (isempty(msg))
                set(object.function_inputs_control,'BackgroundColor',[1 1 1])
                msg = object.check_grid_condition(object.Grid2);
                msg = [msg object.check_grid_condition(object.Grid1)];
                msg = [msg object.check_grid_result(object.Grid0)];
            else
                set(object.function_inputs_control,'BackgroundColor',[0.92 0.65 0.65])
            end
            
            if ~isempty(msg)
                msgbox(msg);
                error = 1;
@@ -658,15 +673,18 @@ classdef GUI < handle
        %   there is no error
        function error = check_matlab_syntax_condition(obj,string,result)
           % split the list of inputs to get inputs seperatly
           inputs = get(obj.function_inputs_control,'String');
           inputs = regexp(inputs,',','split');
           
           parsed_input = obj.parse_inputs(get(obj.function_inputs_control,'string'))
           %inputs = get(obj.function_inputs_control,'String');
           %inputs = regexp(inputs,',','split');
           check_string = [];
           
           % initialize inputs to zero
           % functions are assumed to be total, so 0 is just for 
           % convienence
           for i=1:size(inputs,2)
           for i=1:size(parsed_input,2)
                % set to zero
                check_string = [check_string sprintf('%s=0\n',char(inputs(i)))];
                check_string = [check_string sprintf('%s=0\n',char(parsed_input{i}(1)))];
                
                   
           end
@@ -1568,6 +1586,36 @@ classdef GUI < handle
        end
        
        
        %%
        function revised_input = parse_inputs(obj,input_string)
            revised_input = [];
            input_string2 = reshape(input_string',1,size(input_string,1)*size(input_string,2))
           inputs = regexprep(input_string2,'\s','')
           inputs = regexp(inputs,',','split')
           inputs = regexp(inputs,':','split')
           for i=1:size(inputs,2)
                valid = regexp(inputs{i}(1),'[a-zA-Z][_a-zA-Z0-9]*','match')
                if ~strcmp(inputs{i}(1),valid{1})
                    inputs{i}(2) = {'error'}
                    %revised_input = cat(2,revised_input,[char(inputs{i}(1)); 'error'])
                end
           end 
           if isempty(revised_input)
               revised_input = inputs
           end
        end
        
        function error = check_inputs(obj)
            parsed_input = obj.parse_inputs(get(obj.function_inputs_control,'string'))
            error = [];
            for i=1:size(parsed_input,2)
                if(size(parsed_input{i},2) == 2)
                    if (strcmp(parsed_input{i}(2),'error'))
                        error = [error sprintf('%s is not a valid variable name\n',char(parsed_input{i}(1))) ]
                    end
                end  
            end
        end
    end
end
+17 −6
Original line number Diff line number Diff line
@@ -25,19 +25,30 @@ classdef PVS_checker < handle
            code = [code obj.pvs_check_for_imports];
            
            % declare variables for each input
            inputs = get(obj.gui.function_inputs_control,'String');
           inputs = regexp(inputs,',','split');
            
            %inputs = get(obj.gui.function_inputs_control,'String');
           %inputs = regexp(inputs,',','split');
                       parsed_inputs = obj.gui.parse_inputs(get(obj.gui.function_inputs_control,'string'))
                       
           % initialize inputs to zero
           % functions are assumed to be total, so 0 is just for 
           % convienence
           inputs_new = [];
           for i=1:size(inputs,2)
           for i=1:size(parsed_inputs,2)
                % set to zero
                code = [code sprintf('%s:VAR real\n',char(inputs(i)))];
                inputs_new = [inputs_new ',' char(inputs(i))];
                if(size(parsed_inputs{i},2) == 2)
                    code = [code sprintf('%s:VAR %s\n',char(parsed_inputs{i}(1)), char(parsed_inputs{i}(2)))];
                else
                    code = [code sprintf('%s:VAR real\n',char(parsed_inputs{i}(1)))];
                end
                
                inputs_new = [inputs_new char(parsed_inputs{i}(1))];
                if(i~=(size(parsed_inputs,2)))
                    inputs_new = [inputs_new ',']
                end
           end
           
           code = [code sprintf('%s(%s):real = \n',get(obj.gui.function_name_control,'String'),get(obj.gui.function_inputs_control,'String'))];
           code = [code sprintf('%s(%s):real = \n',get(obj.gui.function_name_control,'String'),inputs_new)];
            code = [code obj.generate_pvs(obj.gui.Grid1,obj.gui.Grid2,0)];
            code = [code sprintf('\nEND %s',get(obj.gui.function_name_control,'String'))];
            fprintf(fileid,code);