Пример #1
0
        /// <summary>
        /// Simplify {x "str".f( y} into {$temp0 = "str"; x $temp0.f ( y}
        /// </summary>
        static void simplify_string_method_call(LinkedListNode <TokenList> node, int pattern_start_index)
        {
            var old_code        = node.Value;
            int string_location = pattern_start_index;

            // new code:
            // $temp0 = str
            var temp_var = Token.create_system_var(TempVar.get_var_name(old_code.indentation));

            var str_assignment = new TokenList(old_code.line_number, old_code.indentation);

            str_assignment.add_token(temp_var);
            str_assignment.add_token(Token.Constants.Assign);
            str_assignment.add_token(old_code[string_location]);

            // x $temp0.f (
            // The new method_call, "$temp0.f", is a single token.
            string method_call = temp_var.value.ToString() + '.' + old_code[string_location + 2].value.ToString();

            var new_code = new TokenList(old_code.line_number, old_code.indentation);

            new_code.add_token_list(old_code, 0, string_location - 1);
            new_code.add_token(Token.create_system_var(method_call));
            new_code.add_token_list(old_code, string_location + 3);

            // insert new code into the LinkedList
            node.List.AddBefore(node, str_assignment);
            node.Value = new_code;
        }
Пример #2
0
        /// <summary>
        /// Simplify "for x in y:" into "$temp0 = y", and "for x in $temp0:".
        /// This applies only if y is two or more tokens.
        /// </summary>
        static void simplify_for_loop_iterator(LinkedListNode <TokenList> node, int pattern_start_index)
        {
            var old_code = node.Value;

            // find the extent of y, the iterator variable
            int iterator_start = old_code.find_token(TokenType.In, 0) + 1;
            int iterator_end   = old_code.find_token_outside_of_paren(
                TokenType.Colon, iterator_start + 1, old_code.Count - 1) - 1;

            // new code:
            // $temp0 = y
            var iterator_assign = new TokenList(old_code.line_number, old_code.indentation);
            var temp_var        = Token.create_system_var(TempVar.get_var_name(old_code.indentation));

            iterator_assign.add_token(temp_var);
            iterator_assign.add_token(Token.Constants.Assign);
            iterator_assign.add_token_list(old_code, iterator_start, iterator_end);

            // for x in $temp0:
            var new_code = new TokenList(old_code.line_number, old_code.indentation);

            new_code.add_token_list(old_code, 0, iterator_start - 1);
            new_code.add_token(temp_var);
            new_code.add_token_list(old_code, iterator_end + 1);

            // insert new code into the LinkedList
            var iterator_assign_node = node.List.AddBefore(node, iterator_assign);

            node.Value = new_code;

            // The caller, which is check(...), will repeat its check on the current
            // node (which is new_code). This function needs to call check(...)
            // on any other newly generated node.
            check(iterator_assign_node);
        }
Пример #3
0
 public override string Print(int depth)
 {
     if (!string.IsNullOrEmpty(Operation))
     {
         return("filter " + SetName.Print(depth) + " " + RuleInput.Print(depth) + " " + Operation);
     }
     return("filter " + SetName.Print(depth) + " " + TempVar.Print(depth) + " " + Expression.Print(depth));
 }
Пример #4
0
        void create_intermediate_code(List <TokenList> token_lists)
        {
            var i_code = new LinkedList <TokenList>();

            foreach (var code in token_lists)
            {
                TempVar.reset(code.indentation);
                var node = i_code.AddLast(code);
                check(node);
            }

            intermediate_code = i_code.ToArray();
        }
Пример #5
0
        /// <summary>
        /// Simplify {x s[...] . f( y} into {$temp0 = s[...]; x $temp0.f ( y}
        /// </summary>
        static void simplify_slice_method_call(LinkedListNode <TokenList> node, int pattern_start_index)
        {
            var old_code    = node.Value;
            int slice_start = pattern_start_index;
            int slice_end   = old_code.find_ending_token(slice_start + 1);

            // keep searching for more '[', so to handle "x[:][0:3]" situation
            while (slice_end < old_code.Count - 1 &&
                   old_code[slice_end + 1].type == TokenType.Left_Bracket)
            {
                slice_end = old_code.find_ending_token(slice_end + 1);
            }

            // new code:
            // $temp0 = s[...]
            var temp_var = Token.create_system_var(TempVar.get_var_name(old_code.indentation));

            var slice_assignment = new TokenList(old_code.line_number, old_code.indentation);

            slice_assignment.add_token(temp_var);
            slice_assignment.add_token(Token.Constants.Assign);
            for (int i = slice_start; i <= slice_end; i++)
            {
                slice_assignment.add_token(old_code[i]);
            }

            // x $temp0.f (
            // The new method_call, "$temp0.f", is a single token.
            string method_call = temp_var.value.ToString() + '.' + old_code[slice_end + 2].value.ToString();

            var new_code = new TokenList(old_code.line_number, old_code.indentation);

            new_code.add_token_list(old_code, 0, slice_start - 1);
            new_code.add_token(Token.create_system_var(method_call));
            new_code.add_token_list(old_code, slice_end + 3);

            // insert new code into the LinkedList
            var slice_assignment_node = node.List.AddBefore(node, slice_assignment);

            node.Value = new_code;

            // The caller, which is check(...), will repeat its check on the current
            // node (which is new_code). This function needs to call check(...)
            // on any other newly generated node.
            check(slice_assignment_node);
        }
Пример #6
0
        /// <summary>
        /// Simplify "x f() y" into "f()", "$temp0 = $return", and "x $temp0 y"
        /// </summary>
        static void simplify_function(LinkedListNode <TokenList> node, int pattern_start_index)
        {
            var old_code       = node.Value;
            int function_start = pattern_start_index + 1;

            // new code:
            // f()
            var f_call = new TokenList(old_code.line_number, old_code.indentation);

            int function_end = old_code.find_ending_token(function_start + 1);

            if (function_end < function_start)
            {
                throw new Exception("Source code error on line # "
                                    + (old_code.line_number + 1) + ". The closing ')' cannot be found.");
            }

            f_call.add_token_list(old_code, function_start, function_end);

            // $temp0 = $return
            var return_assignment = new TokenList(old_code.line_number, old_code.indentation);
            var temp_var          = Token.create_system_var(TempVar.get_var_name(old_code.indentation));

            return_assignment.add_token(temp_var);
            return_assignment.add_token(Token.Constants.Assign);
            return_assignment.add_token(Token.create_system_var("$return"));

            // x $temp0 y
            var new_code = new TokenList(old_code.line_number, old_code.indentation);

            new_code.add_token_list(old_code, 0, function_start - 1);
            new_code.add_token(temp_var);
            new_code.add_token_list(old_code, function_end + 1);

            // insert new code into the LinkedList
            var f_call_node = node.List.AddBefore(node, f_call);

            node.List.AddBefore(node, return_assignment);
            node.Value = new_code;

            // The caller, which is check(...), will repeat its check on the current
            // node (which is new_code). This function needs to call check(...)
            // on any other newly generated node.
            check(f_call_node);
        }
Пример #7
0
 public AccessTempVarsModel(TempVar tempVar)
 {
     Name = tempVar.Name;
     try { Value = tempVar.Value?.ToString(); } catch { }
 }
Пример #8
0
    /// <summary>
    /// Get parameter data from the base design.
    /// </summary>
    /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param>
    public void GetBaseVariants()
    {
        try
        {
            IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace;
            IDXPProject   CurrentProject;
            int           LogicalDocumentCount;
            int           LoopIterator;
            Dictionary <string, IComponentVariation> FltCompVar, EngCompVar;
            IDXPDocument CurrentSheet;
            CurrentProject       = CurrentWorkspace.DM_FocusedProject();
            LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount();
            ISch_ServerInterface SchServer   = SCH.GlobalVars.SchServer;
            IClient                   Client = DXP.GlobalVars.Client;
            IServerDocument           ServerDoc;
            IDXPDocument              ActiveDoc  = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done.
            VarParam <string, string> Parameters = new VarParam <string, string>();
            string RefDes;

            IParameterVariation TempVar;
            int  Matches;
            bool DocOpened = false;

            FltCompVar = Get_Variants("VAR_FLT");
            EngCompVar = Get_Variants("VAR_ENG");

            if (FltCompVar == null || EngCompVar == null)
            {
                return;
            }

            //iterate through project documents.
            for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++)
            {
                CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1);
                //Check for schematic documents.
                if (CurrentSheet.DM_DocumentKind() == "SCH")
                {
                    DocOpened = false;
                    //Open documents
                    if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath()))
                    {
                        ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath());
                        DocOpened = true;
                    }
                    else
                    {
                        ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath());
                    }

                    //Client.ShowDocument(ServerDoc);

                    ISch_Lib SchDoc;
                    SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib;

                    ISch_Iterator       SchIterator, PIterator;
                    ISch_Component      Component;
                    ISch_Implementation Footprint;
                    ISch_Parameter      Param;
                    if (SchDoc == null)
                    {
                        return;
                    }
                    //Iterate theough all components on the schematic.
                    SchIterator = SchDoc.SchIterator_Create();
                    SchIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent));

                    Component = SchIterator.FirstSchObject() as ISch_Component;



                    while (Component != null)
                    {
                        Matches = 0;
                        if (Component.GetState_SchDesignator().GetState_Text().Contains("?"))
                        {
                            MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again.");
                            return;
                        }
                        RefDes = Component.GetState_SchDesignator().GetState_Text();



                        //Iterate theough all parameters in the component.
                        PIterator = Component.SchIterator_Create();
                        PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eImplementation));

                        Footprint = PIterator.FirstSchObject() as ISch_Implementation;
                        if (FltCompVar.ContainsKey(RefDes))
                        {
                            if (FltCompVar[RefDes].DM_AlternateLibraryLink().DM_Footprint() != Footprint.GetState_ModelName())
                            {
                                TempVar = FltCompVar[RefDes].DM_FindParameterVariation("ClassName");
                                if (TempVar != null)
                                {
                                    TempVar.DM_SetVariedValue("Stencil_Flt");
                                }
                                Matches++;
                            }
                        }

                        if (EngCompVar.ContainsKey(RefDes))
                        {
                            if (EngCompVar[RefDes].DM_AlternateLibraryLink().DM_Footprint() != Footprint.GetState_ModelName())
                            {
                                TempVar = EngCompVar[RefDes].DM_FindParameterVariation("ClassName");
                                if (TempVar != null)
                                {
                                    TempVar.DM_SetVariedValue("Stencil_Eng");
                                }
                                Matches++;
                            }
                        }

                        //?Param.GetState_ModelName()
                        //"FIDUCIAL_SMD"

                        //Iterate theough all parameters in the component.
                        PIterator = Component.SchIterator_Create();
                        PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter));

                        Param = PIterator.FirstSchObject() as ISch_Parameter;
                        while (Param != null)
                        {
                            if (Param.GetState_Name() == "ClassName")
                            {
                                if (Matches == 2)
                                {
                                    Param.SetState_Text("Stencil_Base");
                                }
                                else
                                {
                                    Param.SetState_Text("");
                                }

                                Component.UpdatePart_PostProcess();
                                break;
                            }
                            Param = PIterator.NextSchObject() as ISch_Parameter;
                        }

                        Component = SchIterator.NextSchObject() as ISch_Component;
                    }

                    //if (ServerDoc.GetModified())
                    //    ServerDoc.DoFileSave("");

                    //Close opend documents.
                    if (!DocOpened)
                    {
                        Client.CloseDocument(ServerDoc);
                    }

                    ServerDoc = null;
                }
            }

            Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath()));
            return;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }