Example #1
0
        public static void AddTokenIcon(GraphElement tokenElement, LoopStackModel.TitleComponentIcon titleComponentIcon)
        {
            if (!(tokenElement is Token) && !(tokenElement is TokenDeclaration))
            {
                return;
            }

            var tokenElementIcon = tokenElement.Q("icon");

            if (tokenElementIcon == null)
            {
                return;
            }

            switch (titleComponentIcon)
            {
            case LoopStackModel.TitleComponentIcon.Collection:
                tokenElementIcon.AddToClassList("typeArray");
                tokenElementIcon.style.visibility = Visibility.Visible;
                break;

            case LoopStackModel.TitleComponentIcon.Condition:
                tokenElementIcon.AddToClassList("typeBoolean");
                tokenElementIcon.style.visibility = Visibility.Visible;
                break;

            case LoopStackModel.TitleComponentIcon.Count:
                tokenElementIcon.AddToClassList("typeCount");
                tokenElementIcon.style.visibility = Visibility.Visible;
                break;

            case LoopStackModel.TitleComponentIcon.Index:
                tokenElementIcon.AddToClassList("typeIndex");
                tokenElementIcon.style.visibility = Visibility.Visible;
                break;

            case LoopStackModel.TitleComponentIcon.Item:
                tokenElementIcon.AddToClassList("typeItem");
                tokenElementIcon.style.visibility = Visibility.Visible;
                break;

            case LoopStackModel.TitleComponentIcon.None:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(titleComponentIcon), titleComponentIcon, null);
            }
        }
Example #2
0
        public TDecl DeclareVariable <TDecl>(string defaultItemName, TypeHandle type, LoopStackModel.TitleComponentIcon item, VariableFlags variableFlags, bool forceInsert = false) where TDecl : LoopVariableDeclarationModel
        {
            var list = (List <VariableDeclarationModel>)m_LoopStackModel.FunctionParameterModels;

            bool createNew   = false;
            int  insertIndex = -1;
            LoopVariableDeclarationModel existing = null;

            if (forceInsert)
            {
                createNew   = true;
                insertIndex = m_NextIndex;
            }
            else
            {
                while (m_NextIndex < list.Count)
                {
                    var variableDeclarationModel = list[m_NextIndex++];
                    if (!variableDeclarationModel)
                    {
                        continue;
                    }
                    existing = variableDeclarationModel as LoopVariableDeclarationModel;
                    if (variableDeclarationModel.variableFlags.HasFlag(VariableFlags.Generated))
                    {
                        break;
                    }
                }

                if (existing)
                {
                    insertIndex = m_NextIndex;
                }
                else
                {
                    Log($"  {defaultItemName}: create new, out of range");
                    createNew = true;
                }
            }

            if (!existing || existing.GetType() != typeof(TDecl)) // try to reuse
            {
                var cause = !existing ? "not existing" : "wrong type";
                Log($"  {defaultItemName}: create new, cannot reuse, cause: {cause}");
                createNew = true;
            }
            else
            {
                Log($"  {defaultItemName}: reused");
            }

            if (createNew)
            {
                m_NextIndex++;
                existing = VariableDeclarationModel.Create <TDecl>(
                    defaultItemName,
                    type,
                    false,
                    (GraphModel)m_LoopStackModel.GraphModel,
                    VariableType.FunctionParameter,
                    ModifierFlags.None,
                    m_LoopStackModel,
                    variableFlags);

                Log($"    {defaultItemName}: index {insertIndex}");
                if (insertIndex == -1)
                {
                    list.Add(existing);
                }
                else
                {
                    list.Insert(insertIndex, existing);

//                        m_NextIndex++; // just inserted one so
                }
            }
            else
            {
                VariableDeclarationModel.SetupDeclaration(defaultItemName,
                                                          type,
                                                          false,
                                                          (GraphModel)m_LoopStackModel.GraphModel,
                                                          VariableType.FunctionParameter,
                                                          ModifierFlags.None,
                                                          variableFlags,
                                                          m_LoopStackModel,
                                                          existing);
            }

            existing.TitleComponentIcon = item;
            existing.IsExposed          = variableFlags.HasFlag(VariableFlags.Hidden); // TODO use hidden parameter
            return((TDecl)existing);
        }