public static void GenerateConstructor(SequenceCheckingEnvironment env, IGraphModel model, SequenceExpressionConstructor constructor, SourceBuilder source)
 {
     if (constructor is SequenceExpressionContainerConstructor)
     {
         GenerateContainerConstructor(env, model, (SequenceExpressionContainerConstructor)constructor, source);
     }
     else
     {
         GenerateInternalObjectTypeAttributeInitializer(env, model, (SequenceExpressionNew)constructor, source);
     }
 }
        private static void GenerateInternalObjectTypeAttributeInitializer(SequenceCheckingEnvironment env, IGraphModel model, SequenceExpressionNew attributeInitializer, SourceBuilder source)
        {
            if (attributeInitializer.AttributeInitializationList == null)
            {
                return; // plain constructor without attribute initialization list
            }
            string internalObjectType = "GRGEN_MODEL." + attributeInitializer.ConstructedType;

            source.Append("\n");
            source.AppendFront("public static ");
            source.Append(internalObjectType);
            source.Append(" fillFromSequence_" + attributeInitializer.Id + "(");
            BaseObjectType objectType = env.Model.ObjectModel.GetType(attributeInitializer.ConstructedType);

            if (objectType != null)
            {
                source.Append("long uniqueId");
            }
            for (int i = 0; i < attributeInitializer.AttributeInitializationList.Count; ++i)
            {
                KeyValuePair <string, SequenceExpression> attributeInitialization = attributeInitializer.AttributeInitializationList[i];
                if (i > 0 || objectType != null)
                {
                    source.Append(", ");
                }
                string valueType = TypesHelper.XgrsTypeToCSharpType(env.TypeOfMemberOrAttribute(attributeInitializer.ConstructedType, attributeInitialization.Key), model);
                source.AppendFormat("{0} {1}", valueType, "param" + i);
            }
            source.Append(")\n");

            source.AppendFront("{\n");
            source.Indent();
            source.AppendFrontFormat("{0} obj = new {0}({1});\n", internalObjectType, objectType != null ? "uniqueId" : "");
            for (int i = 0; i < attributeInitializer.AttributeInitializationList.Count; ++i)
            {
                KeyValuePair <string, SequenceExpression> attributeInitialization = attributeInitializer.AttributeInitializationList[i];
                source.AppendFrontFormat("obj.{0}  = {1};\n", attributeInitialization.Key, "param" + i);
            }
            source.AppendFront("return obj;\n");
            source.Unindent();
            source.AppendFront("}\n");
        }
        private static void GenerateContainerConstructor(SequenceCheckingEnvironment env, 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");
        }
Esempio n. 4
0
 public SequenceGeneratorHelper(IGraphModel model, ActionsTypeInformation actionsTypeInformation, SequenceCheckingEnvironmentCompiled checkEnv)
 {
     this.model = model;
     this.actionsTypeInformation = actionsTypeInformation;
     this.env = checkEnv;
 }