public VariableEditorForm(VariableCollection variables)
 {
     Text = "Edit Variables";
     InitializeComponent();
     this.variables     = variables;
     variable           = null;
     buttAdd.Visible    = true;
     buttDelete.Visible = true;
     ShowVariables();
     cmboType.DataSource = DataType.AllTypes;
     VariableChanged(null, EventArgs.Empty);
 }
 private void AddVariable(object sender, EventArgs e)
 {
     using (var form = new IdentifierForm <VariableObj>("Variable", variables.Keys))
     {
         if (form.ShowDialog(this) == DialogResult.OK)
         {
             var obj = new VariableObj();
             variables.Add(form.Identifier, obj);
             cmboVariables.Items.Add(form.Identifier);
             cmboVariables.SelectedIndex = cmboVariables.Items.Count - 1;
             VariableChanged(null, EventArgs.Empty);
         }
     }
 }
예제 #3
0
 public void EvaluateVariable(VariableObj variableObj, Dictionary <string, string> extraParams)
 {
     TryCastUtil.TryCast <ICreateFileVariable>(_fileBuilder).CreateFileVariable(variableObj);
 }
예제 #4
0
 public void EvaluateProperty(VariableObj variableObj, Dictionary <string, string> extraParams)
 {
     TryCastUtil.TryCast <ICreateClassProperty>(_classBuilder).CreateClassProperty(
         variableObj, GetAccessModifierFromExtraParams(extraParams, AccessModifier.PRIVATE));
 }
예제 #5
0
 public void CreateFileVariable(VariableObj variableObj)
 {
     _variables.Add(variableObj);
 }
예제 #6
0
        private void InterpretContent(XmlNode contentNode, ContextEvaluatorBase contextEvaluator)
        {
            foreach (XmlNode parentNode in contentNode.ChildNodes)
            {
                Dictionary <string, string> extraParams;
                switch (parentNode.Name)
                {
                case "Files":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        LangFileBuilderBase fileBuilder = TryCastUtil.TryCast <ICreateFileBuilder>(_langFactory).CreateFileBuilder();
                        fileBuilder.CreateFile(_outDir + GetAttributeOrDefault(node, "name", ""));

                        extraParams = InterpretIdentifier(node, () =>
                        {
                            return(new FileContextEvaluator(fileBuilder));
                        });

                        TryCastUtil.TryCast <IEvaluateFile>(contextEvaluator).EvaluateFile(fileBuilder, extraParams);
                    }
                    break;

                case "Variables":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        var variableObj = new VariableObj(
                            ParseDataType(GetAttributeOrDefault(node, "type", "")),
                            GetAttributeOrDefault(node, "name", "")
                            );

                        extraParams = InterpretIdentifier(node, null);

                        TryCastUtil.TryCast <IEvaluateVariable>(contextEvaluator).EvaluateVariable(variableObj, extraParams);
                    }
                    break;

                case "Functions":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        var functionObj = new FunctionObj(
                            ParseDataType(GetAttributeOrDefault(node, "returnType", "")),
                            GetAttributeOrDefault(node, "name", "")
                            );
                        functionObj.FuncParams = ParseFuncParams(GetAttributeOrDefault(node, "params", ""));

                        extraParams = InterpretIdentifier(node, null);

                        TryCastUtil.TryCast <IEvaluateFunction>(contextEvaluator).EvaluateFunction(functionObj, extraParams);
                    }
                    break;

                case "Properties":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        var propertyObj = new VariableObj(
                            ParseDataType(GetAttributeOrDefault(node, "type", "")),
                            GetAttributeOrDefault(node, "name", "")
                            );

                        extraParams = InterpretIdentifier(node, null);

                        TryCastUtil.TryCast <IEvaluateProperty>(contextEvaluator).EvaluateProperty(propertyObj, extraParams);
                    }
                    break;

                case "Classes":
                case "InnerClasses":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        LangClassBuilderBase classBuilder = TryCastUtil.TryCast <ICreateClassBuilder>(_langFactory).CreateClassBuilder();

                        classBuilder.CreateClass(GetAttributeOrDefault(node, "name", ""));

                        extraParams = InterpretIdentifier(node, () =>
                        {
                            return(new ClassContextEvaluator(classBuilder));
                        });

                        TryCastUtil.TryCast <IEvaluateClass>(contextEvaluator).EvaluateClass(classBuilder, extraParams);
                    }
                    break;

                case "Constructor":
                    List <VariableObj> constructorParams = ParseFuncParams(GetAttributeOrDefault(parentNode, "params", ""));

                    extraParams = InterpretIdentifier(parentNode, null);

                    TryCastUtil.TryCast <IEvaluateConstructor>(contextEvaluator).EvaluateConstructor(constructorParams, extraParams);
                    break;

                default:
                    /* Note: this should be impossible since an invalid identifier would be caught by the
                     * schema validation, but we should still throw an exception just in case */
                    throw new InterpreterParseException($"Identifier \"{parentNode.Name}\" not recognized.");
                }
            }
        }