예제 #1
0
 private static string GetContainerType(SequenceExpressionContainerConstructor cc)
 {
     if (cc is SequenceExpressionSetConstructor)
     {
         return("set<" + cc.ValueType + ">");
     }
     else if (cc is SequenceExpressionMapConstructor)
     {
         return("map<" + ((SequenceExpressionMapConstructor)cc).KeyType + "," + cc.ValueType + ">");
     }
     else if (cc is SequenceExpressionArrayConstructor)
     {
         return("array<" + cc.ValueType + ">");
     }
     else //if(cc is SequenceExpressionDequeConstructor)
     {
         return("deque<" + cc.ValueType + ">");
     }
 }
예제 #2
0
 private static string GetAddToContainer(SequenceExpressionContainerConstructor containerConstructor, string value, string key)
 {
     if (containerConstructor is SequenceExpressionSetConstructor)
     {
         return("container.Add(" + value + ", null);\n");
     }
     else if (containerConstructor is SequenceExpressionMapConstructor)
     {
         return("container.Add(" + key + ", " + value + ");\n");
     }
     else if (containerConstructor is SequenceExpressionArrayConstructor)
     {
         return("container.Add(" + value + ");\n");
     }
     else //if(cc is SequenceExpressionDequeConstructor)
     {
         return("container.Enqueue(" + value + ");\n");
     }
 }
예제 #3
0
        public static void GenerateContainerConstructor(IGraphModel model, SequenceExpressionContainerConstructor containerConstructor, SourceBuilder source)
        {
            string containerType = TypesHelper.XgrsTypeToCSharpType(GetContainerType(containerConstructor), model);
            string valueType     = TypesHelper.XgrsTypeToCSharpType(containerConstructor.ValueType, model);
            string keyType       = null;

            if (containerConstructor is SequenceExpressionMapConstructor)
            {
                keyType = TypesHelper.XgrsTypeToCSharpType(((SequenceExpressionMapConstructor)containerConstructor).KeyType, model);
            }

            source.Append("\n");
            source.AppendFront("public static ");
            source.Append(containerType);
            source.Append(" fillFromSequence_" + containerConstructor.Id);
            source.Append("(");
            for (int i = 0; i < containerConstructor.ContainerItems.Length; ++i)
            {
                if (i > 0)
                {
                    source.Append(", ");
                }
                if (keyType != null)
                {
                    source.AppendFormat("{0} paramkey{1}, ", keyType, i);
                }
                source.AppendFormat("{0} param{1}", valueType, i);
            }
            source.Append(")\n");

            source.AppendFront("{\n");
            source.Indent();
            source.AppendFrontFormat("{0} container = new {0}();\n", containerType);
            for (int i = 0; i < containerConstructor.ContainerItems.Length; ++i)
            {
                source.AppendFrontFormat(GetAddToContainer(containerConstructor, "param" + i, keyType != null ? "paramkey" + i : null));
            }
            source.AppendFront("return container;\n");
            source.Unindent();
            source.AppendFront("}\n");
        }