Commit 023faf17 authored by Colin Eles's avatar Colin Eles
Browse files

latest update still not yet working

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/trunk/TableTool@5876 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 103d5be9
Loading
Loading
Loading
Loading
+77 −25
Original line number Diff line number Diff line
@@ -4,6 +4,50 @@ classdef EMLGenerator < handle
    
    properties
        data = [];
        datatype = [];
    end
    
    methods(Static)
        %%
        function revised_input = parse_inputs(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');
           
           % need to be careful here because pvs dependant types can have
           % :'s in them
           
           % find the first :, any thing before this is considered the
           % variable any thing following is considered the type
           c_locations = regexp(inputs,':','start');
           for i= 1:size(inputs,2)
                if size(c_locations{i},2) == 0
                    sub_input{1} = inputs{i};
                    new_inputs{i} = sub_input;
                else
                    sub_input{1} = inputs{i}(1:c_locations{i}(1)-1);
                    sub_input{2} = inputs{i}(c_locations{i}(1)+1:end);
                    new_inputs{i} = sub_input;
                    %new_inputs{i}(1) = inputs{i}(1:c_locations{i}(1))
                    %new_inputs{i}(2) = inputs{i}(c_locations{i}(1):end)
                end
                    
           end
           
           %inputs = regexp(inputs,':','split')
           
           for i=1:size(new_inputs,2)
                valid = regexp(new_inputs{i}(1),'[a-zA-Z][_a-zA-Z0-9]*','match');
                if ~strcmp(new_inputs{i}(1),valid{1})
                    new_inputs{i}(2) = {'error'};
                    %revised_input = cat(2,revised_input,[char(inputs{i}(1)); 'error'])
                end
           end 
           if isempty(revised_input)
               revised_input = new_inputs;
           end
        end
    end
    
    methods
@@ -12,11 +56,15 @@ classdef EMLGenerator < handle
            obj.data = data;
        end
        
        function [] = set_datatype(obj,type)
            obj.datatype = type;
        end
        
        function code = generate_preamble(obj)
                code = [];

                %generate input list
                parsed_input = object.parse_inputs(get(object.function_inputs_control,'string'));
                parsed_input = EMLGenerator.parse_inputs(obj.data.function_inputs);
                input = [];
                for i= 1:size(parsed_input,2)
                    input = [input char(parsed_input{i}(1))];
@@ -24,16 +72,17 @@ classdef EMLGenerator < handle
                        input = [input ',']
                    end
                end
                code = sprintf('function output = %s(%s)\n',get(object.function_name_control,'String'),input);
                code = sprintf('function output = %s(%s)\n',obj.data.function_name,input);
                % simulink forces you to have an output for all execution paths
                % since it can't compute completness and disjointness we need
                % to have a default value, if the user builds the table
                % properly the default value will never be used. since
                % different types might have a different default value, the
                % temporary solution is just to use one of the outputs from our
                % table, we will use the first cell because it is guaranteed to
                % table, we will use the first cell because it is
                % guaranteed to
                % be filled in, regardless of the dimensionality of the table.
                code = [code sprintf('output=%s(%s);\n',object.output_data_type,get(object.Grid0.Cells(1).result,'String'))];
                code = [code sprintf('output=%s(%s);\n',obj.datatype,obj.data.Grid0.Cells(1).result_text)];
        
        end
        
@@ -41,10 +90,13 @@ classdef EMLGenerator < handle
        function code = generate_eml_code(obj)
            code = [];
            code = [code obj.generate_preamble];
            code = [code obj.generate_conditional];
            code = [code obj.generate_conditional(obj.data.Grid1,obj.data.Grid2)];
            
        end
        
        
        
        
         %% generate_code
        %   this function will generate a string that represents the
        %   embedded matlab code. code will have proper syntax
@@ -66,15 +118,15 @@ classdef EMLGenerator < handle
                space = [space sprintf('  ')];
            end
            code = [];
            g1cond1 = get(g1.cells(1).cond,'String');
            g2cond1 = get(g2.cells(1).cond,'String');
            g1cond1 = g1.cells(1).cond_text;
            g2cond1 = g2.cells(1).cond_text;
           
            % 1D horizontal table
            if (isempty(g2cond1) && ~isempty(g1cond1))
                found = 0;
                elsecell = [];
                for j=1:size(g1.cells,2)
                    g1cond = get(g1.cells(j).cond,'String');
                    g1cond = g1.cells(j).cond_text;
                    % condition string of otherwise corresponds to an else
                    % statement, we allow this statement to be in any order
                    % in the cells of the grid, so we need to find where it
@@ -85,9 +137,9 @@ classdef EMLGenerator < handle
                        continue
                    end
                    if (j == 1 || (j==2 && found == 1))
                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(get(g1.cells(j).cond,'String'))))];
                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(g1.cells(j).cond_text)))];
                    else
                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(get(g1.cells(j).cond,'String'))))];
                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(g1.cells(j).cond_text)))];
                    end
                    
                    cell = obj.Grid0.search_return(g1.cells(j),g2.cells(1));
@@ -97,7 +149,7 @@ classdef EMLGenerator < handle
                        for k=1:depth
                            space = [space sprintf('  ')];
                        end
                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.output_data_type,strtrim(char(get(cell.result,'String'))))];
                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.datatype,strtrim(char(cell.result_text)))];
                        depth = depth - 1;
                        space = [];
                        for k=1:depth
@@ -128,7 +180,7 @@ classdef EMLGenerator < handle
                        for k=1:depth
                            space = [space sprintf('  ')];
                        end
                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.output_data_type,strtrim(char(get(cell.result,'String'))))];
                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.datatype,strtrim(char(cell.result_text)))];
                        depth = depth - 1;
                        space = [];
                        for k=1:depth
@@ -155,7 +207,7 @@ classdef EMLGenerator < handle
                found = 0;
                elsecell = [];
                for i=1:size(g2.cells,2)
                    g2cond = get(g2.cells(i).cond,'String');
                    g2cond = g2.cells(i).cond_text;
                    if (strcmp(g2cond,'otherwise'))
                        elsecell = g2.cells(i);
                        elseindex = i;
@@ -164,9 +216,9 @@ classdef EMLGenerator < handle
                    end

                    if (i == 1 || (i == 2 && found == 1))
                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(get(g2.cells(i).cond,'String'))))];
                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(g2.cells(i).cond_text)))];
                    else
                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(get(g2.cells(i).cond,'String'))))];
                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(g2.cells(i).cond_text)))];
                    end
                    
                    if (~isempty(g2.cells(i).subgrid))
@@ -180,7 +232,7 @@ classdef EMLGenerator < handle
                        found1 = 0;
                        elsecell1 = [];
                        for j=1:size(g1.cells,2)
                             g1cond = get(g1.cells(j).cond,'String');
                             g1cond = g1.cells(j).cond_text;
                            if (strcmp(g1cond,'otherwise'))
                                elsecell1 = g1.cells(j);
                                found1 = 1;
@@ -192,9 +244,9 @@ classdef EMLGenerator < handle
                            else
                                if (~isempty(g1cond1))
                                    if (j == 1 || (j==2 && found1 == 1))
                                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(get(g1.cells(j).cond,'String'))))];
                                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(g1.cells(j).cond_text)))];
                                    else
                                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(get(g1.cells(j).cond,'String'))))];
                                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(g1.cells(j).cond_text)))];
                                    end
                                end
                                
@@ -205,7 +257,7 @@ classdef EMLGenerator < handle
                                    for k=1:depth
                                        space = [space sprintf('  ')];
                                    end
                                    code = [code sprintf('%soutput = %s(%s);\n',space,obj.output_data_type,strtrim(char(get(cell.result,'String'))))];
                                    code = [code sprintf('%soutput = %s(%s);\n',space,obj.datatype,strtrim(char(cell.result_text)))];
                                    depth = depth - 1;
                                    space = [];
                                    for k=1:depth
@@ -239,7 +291,7 @@ classdef EMLGenerator < handle
                                        for k=1:depth
                                            space = [space sprintf('  ')];
                                        end
                                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.output_data_type,strtrim(char(get(cell.result,'String'))))];
                                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.datatype,strtrim(char(cell.result_text)))];
                                        depth = depth - 1;
                                        space = [];
                                        for k=1:depth
@@ -283,7 +335,7 @@ classdef EMLGenerator < handle
                        end
                        found1 = 0;
                        for j=1:size(g1.cells,2)
                             g1cond = get(g1.cells(j).cond,'String');
                             g1cond = g1.cells(j).cond_text;
                            if (strcmp(g1cond,'otherwise'))
                                elsecell1 = g1.cells(j);
                                found1 = 1;
@@ -295,9 +347,9 @@ classdef EMLGenerator < handle
                            else
                                if (~isempty(g1cond1))
                                    if (j == 1 || (j==2 && found1 == 1))
                                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(get(g1.cells(j).cond,'String'))))];
                                        code = [code sprintf('%sif(%s)\n',space,strtrim(char(g1.cells(j).cond_text)))];
                                    else
                                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(get(g1.cells(j).cond,'String'))))];
                                        code = [code sprintf('%selseif(%s)\n',space,strtrim(char(g1.cells(j).cond_text)))];
                                    end
                                end
                                
@@ -308,7 +360,7 @@ classdef EMLGenerator < handle
                                    for k=1:depth
                                        space = [space sprintf('  ')];
                                    end
                                    code = [code sprintf('%soutput = %s(%s);\n',space,obj.output_data_type,strtrim(char(get(cell.result,'String'))))]
                                    code = [code sprintf('%soutput = %s(%s);\n',space,obj.datatype,strtrim(char(cell.result_text)))]
                                    depth = depth - 1;
                                    space = [];
                                    for k=1:depth
@@ -342,7 +394,7 @@ classdef EMLGenerator < handle
                                        for k=1:depth
                                            space = [space sprintf('  ')];
                                        end
                                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.output_data_type,strtrim(char(get(cell.result,'String'))))];
                                        code = [code sprintf('%soutput = %s(%s);\n',space,obj.datatype,strtrim(char(cell.result_text)))];
                                        depth = depth - 1;
                                        space = [];
                                        for k=1:depth
+12 −58
Original line number Diff line number Diff line
@@ -246,7 +246,6 @@ classdef GUI < handle
            
            obj.PVS = PVS_checker(obj.Data);
            obj.EMLGen = EMLGenerator(obj.Data);
            obj.TableBlk = TableBlock(obj.Data);
            
            obj.initialized = 1;
            obj.Data.open = 1;
@@ -397,7 +396,7 @@ classdef GUI < handle
                object.update_Statusbar;
                                if (object.mode == 1)

                set_block_display(object.block_handle,object.pvs_checked)
                TableBlock.set_block_display(object.block_handle,object.pvs_checked)
                                end
            end

@@ -486,25 +485,19 @@ classdef GUI < handle
                
                load_system('simulink')
                % generate the code
                object.EMLGen.set_datatype(object.output_data_type);
                code = object.EMLGen.generate_eml_code;
                
                code = [code object.generate_code(object.Grid1,object.Grid2,0)];
                fprintf('%s',code);
                %code = [code object.generate_code(object.Grid1,object.Grid2,0)];
                %fprintf('%s',code);

               TableBlock.set_code(object.block_handle,code,obj.data.function_name);

                
                % save the text from each of the conditions and results text
                % boxes.
                save_conditions(object,object.Grid2);
                save_conditions(object,object.Grid1);
                save_results(object,object.Grid0);
                % save the function name and input text from the respective
                % edit boxes.
                object.function_name_text = get(object.function_name_control,'String');
                object.function_inputs_text = get(object.function_inputs_control,'String');
                
                if (object.mode == 1)

                    set_block_display(object.block_handle,object.pvs_checked);
                    TableBlock.set_block_display(object.block_handle,object.pvs_checked);
                end
            end
        end
@@ -1239,7 +1232,7 @@ classdef GUI < handle
            object.update_Statusbar
                            if (object.mode == 1)

            set_block_display(object.block_handle,object.pvs_checked);
            TableBlock.set_block_display(object.block_handle,object.pvs_checked);
                            end
            end
            
@@ -1247,49 +1240,10 @@ classdef GUI < handle
        
      
        
        %%
        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');
        
           % need to be careful here because pvs dependant types can have
           % :'s in them
           
           % find the first :, any thing before this is considered the
           % variable any thing following is considered the type
           c_locations = regexp(inputs,':','start');
           for i= 1:size(inputs,2)
                if size(c_locations{i},2) == 0
                    sub_input{1} = inputs{i};
                    new_inputs{i} = sub_input;
                else
                    sub_input{1} = inputs{i}(1:c_locations{i}(1)-1);
                    sub_input{2} = inputs{i}(c_locations{i}(1)+1:end);
                    new_inputs{i} = sub_input;
                    %new_inputs{i}(1) = inputs{i}(1:c_locations{i}(1))
                    %new_inputs{i}(2) = inputs{i}(c_locations{i}(1):end)
                end
                    
           end
           
           %inputs = regexp(inputs,':','split')
           
           for i=1:size(new_inputs,2)
                valid = regexp(new_inputs{i}(1),'[a-zA-Z][_a-zA-Z0-9]*','match');
                if ~strcmp(new_inputs{i}(1),valid{1})
                    new_inputs{i}(2) = {'error'};
                    %revised_input = cat(2,revised_input,[char(inputs{i}(1)); 'error'])
                end
           end 
           if isempty(revised_input)
               revised_input = new_inputs;
           end
        end
        
        function error = check_inputs(obj)
            parsed_input = obj.parse_inputs(get(obj.function_inputs_control,'string'));
            parsed_input = EMLGenerator.parse_inputs(get(obj.function_inputs_control,'string'));
            error = [];
            for i=1:size(parsed_input,2)
                if(size(parsed_input{i},2) == 2)
+2 −40
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ classdef PVS_checker < handle
            
            %inputs = get(obj.gui.function_inputs_control,'String');
           %inputs = regexp(inputs,',','split');
                       parsed_inputs = obj.parse_inputs(obj.data.function_inputs);
                       parsed_inputs = EMLGenerator.parse_inputs(obj.data.function_inputs);
                       
           % initialize inputs to zero
           % functions are assumed to be total, so 0 is just for 
@@ -95,45 +95,7 @@ classdef PVS_checker < handle
            end
        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');
        
           % need to be careful here because pvs dependant types can have
           % :'s in them
           
           % find the first :, any thing before this is considered the
           % variable any thing following is considered the type
           c_locations = regexp(inputs,':','start');
           for i= 1:size(inputs,2)
                if size(c_locations{i},2) == 0
                    sub_input{1} = inputs{i};
                    new_inputs{i} = sub_input;
                else
                    sub_input{1} = inputs{i}(1:c_locations{i}(1)-1);
                    sub_input{2} = inputs{i}(c_locations{i}(1)+1:end);
                    new_inputs{i} = sub_input;
                    %new_inputs{i}(1) = inputs{i}(1:c_locations{i}(1))
                    %new_inputs{i}(2) = inputs{i}(c_locations{i}(1):end)
                end
                    
           end
           
           %inputs = regexp(inputs,':','split')
           
           for i=1:size(new_inputs,2)
                valid = regexp(new_inputs{i}(1),'[a-zA-Z][_a-zA-Z0-9]*','match');
                if ~strcmp(new_inputs{i}(1),valid{1})
                    new_inputs{i}(2) = {'error'};
                    %revised_input = cat(2,revised_input,[char(inputs{i}(1)); 'error'])
                end
           end 
           if isempty(revised_input)
               revised_input = new_inputs;
           end
        end
        
        function [string] = user_imports(obj)
            string = [];
+21 −24

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ for i = 1:size(blocks,1)
                msg = [msg char(blocks(i)) ' is not valid' sprintf('\n')]
            end
            block_data.checked = check;
            set_block_display(char(blocks(i)),block_data.checked)
            TableBlock.set_block_display(char(blocks(i)),block_data.checked)

        end
    end