Beispiel #1
0
 private bool GetAviableFunc(CompoundFunction _func)
 {
     if (_func.Internal)
     {
         return(false);
     }
     if (!_func.Public)
     {
         return(false);
     }
     if (_func.Static)
     {
         return(false);
     }
     if (_func.Name.StartsWith("_"))
     {
         return(false);
     }
     if (_func.Reimplement)
     {
         if (_func.Virtual)
         {
             return(false);
         }
         if (_func.Generic)
         {
             return(false);
         }
     }
     return(true);
 }
 public override IEnumerable <string> Visit(CompoundFunction node)
 {
     foreach (var item in node)
     {
         foreach (var item2 in item.Accept(this))
         {
             yield return(item2);
         }
     }
 }
Beispiel #3
0
        private void AddClassFunction(CompoundFunction _func, TemplateInfo _info, ClassInfo _classInfo, FileData _outputFile)
        {
            string templateName = _classInfo.GetTeplaceTemplate(_func.Name);

            if (templateName == "")
            {
                templateName = GetFunctionTemplateName(_func);
            }

            FileData template = mTemplateManager.GetTemplateCopy(GetTemplateFileName(_info.TemplateFolder, templateName));

            mReplaceManager.DoReplace(template, new IReplacer[] { _classInfo, new FunctionReplacer(_func) });
            InsertData(_outputFile, template, mLabelName);
        }
Beispiel #4
0
        public FunctionReplacer(CompoundFunction _func)
        {
            mCompound = _func;

            mReplace["MethodName"]         = UpFirstLetter(mCompound.Name);
            mReplace["PropertyName"]       = mCompound.PropertyName;       // метод может быть заменен на свойство
            mReplace["OriginalMethodName"] = mCompound.Name;

            mReplace["OriginalTypeName"] = mCompound.CompoundType.TypeName;
            TypeInfo info = WrapperManager.Instance.GetTypeInfo(mCompound.CompoundType.TypeName);

            if (info != null)
            {
                foreach (var value in info.Values)
                {
                    mReplace[value.First] = value.Second;
                }
            }

            int index = 1;

            foreach (var type in mCompound.CompoundParamTypes)
            {
                mReplace["OriginalTypeName" + index.ToString()] = type.TypeName;
                if (type.ValueName != null)
                {
                    mReplace["ValueName" + index.ToString()] = type.ValueName;
                }
                else
                {
                    mReplace["ValueName" + index.ToString()] = "_value" + index.ToString();
                }

                TypeInfo parameInfo = WrapperManager.Instance.GetTypeInfo(type.TypeName);
                if (parameInfo != null)
                {
                    foreach (var value in parameInfo.Values)
                    {
                        mReplace[value.First + index.ToString()] = value.Second;
                    }
                }
                else
                {
                    //ConsoleUtility.WriteErrorLine("Type {0} not found", type.TypeName);
                }

                index++;
            }
        }
Beispiel #5
0
        private CompoundFunction PopSetterFunc(CompoundFunction _func, List <CompoundFunction> _funtions)
        {
            for (int index = 0; index < _funtions.Count; index++)
            {
                var func = _funtions[index];
                if (func.PropertyName == _func.PropertyName)
                {
                    if (func.CompoundType.TypeName == "void" &&
                        func.CompoundParamTypes.Count == 1 &&
                        (func.CompoundParamTypes[0].TypeName == _func.CompoundType.TypeName ||
                         func.CompoundParamTypes[0].PoorTypeName == _func.CompoundType.TypeName))
                    {
                        _funtions.RemoveAt(index);
                        return(func);
                    }
                }
            }

            return(null);
        }
Beispiel #6
0
        private void AddClassData(Compound _compound, TemplateInfo _info, ClassInfo _classInfo, FileData _outputFile)
        {
            List <CompoundFunction> funtions = new List <CompoundFunction>();
            List <Pair <CompoundFunction, CompoundFunction> > properties = new List <Pair <CompoundFunction, CompoundFunction> >();
            List <CompoundVariable> variables = new List <CompoundVariable>();

            foreach (Compound child in _compound)
            {
                if (child is CompoundFunction)
                {
                    CompoundFunction func = (CompoundFunction)child;
                    if (GetAviableFunc(func))
                    {
                        if (
                            //func.Const &&
                            func.CompoundParamTypes.Count == 0 &&
                            func.CompoundType.TypeName != "void" &&
                            (func.GetProperty || func.IsProperty))
                        {
                            properties.Add(new Pair <CompoundFunction, CompoundFunction>(func, null));
                        }
                        else
                        {
                            funtions.Add(func);
                        }
                    }
                }
                else if (child is CompoundVariable)
                {
                    CompoundVariable variable = (CompoundVariable)child;
                    if (variable.Public &&
                        !variable.Static &&
                        !variable.Name.StartsWith("_") &&
                        CompoundUtility.IsVariableEvent(variable))
                    {
                        variables.Add(variable);
                    }
                }
            }

            // вытаскиваем сетеры для свойств из списка функций
            foreach (var func in properties)
            {
                func.Second = PopSetterFunc(func.First, funtions);
            }

            foreach (var func in properties)
            {
                AddClassProperty(func, _info, _classInfo, _outputFile);
            }

            foreach (var func in funtions)
            {
                AddClassFunction(func, _info, _classInfo, _outputFile);
            }

            foreach (var variable in variables)
            {
                AddClassEvent(variable, _info, _classInfo, _outputFile);
            }
        }
Beispiel #7
0
        private string GetFunctionTemplateName(CompoundFunction _func)
        {
            bool returnType = _func.CompoundType.TypeName != "void";

            return(string.Format("Method{0}{1}.txt", returnType ? "Return" : "", _func.CompoundParamTypes.Count));
        }