示例#1
0
        /// <summary>
        /// factory method
        /// </summary>
        /// <param name="type">base type</param>
        /// <param name="pointerCount">count of pointer qualifier</param>
        /// <param name="dimCountArray">array of size</param>
        /// <remarks>
        /// if any params do not qualify a base type, this methods just returns it.
        /// see also constructors.
        /// If you do not want to an array type, set dim1Count and dim2Count to 0.
        /// Array and pointer type meanns an array of pointer type.
        /// </remarks>
        public static IBlendType From(IBlendType type, int pointerCount, int[] dimCountArray)
        {
            for (int i = 0; i < pointerCount; ++i)
            {
                type = new BlendPointerType(type);
            }

            if ((dimCountArray == null || dimCountArray.Length == 0))
            {
                return(type);
            }
            else
            {
                return(new BlendArrayType(type, dimCountArray));
            }
        }
示例#2
0
        /*
         * private List<_StructureDecl> _SortByTypeDependency(List<_StructureDecl> declList)
         * {
         *      int capacity = declList.Count();
         *      var result = new List<_StructureDecl>(capacity);
         *      var tmpTable = new Dictionary<String, _StructureDeclBoolTuple>(capacity);
         *      foreach (var decl in declList)
         *      {
         *              tmpTable.Add(decl.name, new _StructureDeclBoolTuple(decl, false));
         *      }
         *
         *      foreach (var v in tmpTable.Values)
         *      {
         *              _RegisterTypeRecursively(v, tmpTable, result);
         *      }
         *
         *      return result;
         * }
         *
         * private void _RegisterTypeRecursively(_StructureDeclBoolTuple target, Dictionary<String, _StructureDeclBoolTuple> tmpTable, List<_StructureDecl> result)
         * {
         *      if (target.Item2)
         *      {
         *              // already registered
         *              return;
         *      }
         *
         *      // call recursively for each member
         *      foreach (var type in target.Item1.fieldTypes)
         *      {
         *              if (type == target.Item1.name)
         *              {
         *                      continue;
         *              }
         *
         *              if (m_repository.Find(type) != null)
         *              {
         *                      // primitive type
         *                      continue;
         *              }
         *
         *              _StructureDeclBoolTuple tmpValue = null;
         *              if (!tmpTable.TryGetValue(type, out tmpValue))
         *              {
         *                      // Error?
         *                      continue;
         *              }
         *
         *              _RegisterTypeRecursively(tmpValue, tmpTable, result);
         *      }
         *
         *      target.Item2 = true;
         *      result.Add(target.Item1);
         * }
         */

        /// <summary>
        /// Create a .blend type from SDNA member name with type qualifiers
        /// </summary>
        /// <param name="type">.blend type</param>
        /// <param name="name">member name</param>
        /// <param name="tLen">size of type [byte]</param>
        /// <remarks>
        /// qualifier of array and pointer is contained in SDNA member name.
        /// this is inconvenient to make domain classes.
        /// this function moves these qualifiers from name to type.
        /// </remarks>
        private static BlendStructureType.MemberDecl _ParseType(IBlendType type, string name, int tLen)
        {
            string description = type.Name + " " + name;
            Match  match       = null;

            match = FunctionPointerRegex.Match(name, 0);
            if (match.Success)
            {
                // function pointer is unsupported
                int ptSize = BlendPointerType.GetPointerSizeOf();
                return(new BlendStructureType.MemberDecl(match.Groups[1].Value, new UnknownBlendType(description, ptSize)));
            }

            match = PointerAndNameRegex.Match(name, 0);
            if (match.Success)
            {
                string pointers = match.Groups[1].Value;
                string baseName = match.Groups[2].Value;

                // parse pointer qualifiers
                int pointerCount = pointers.Length;

                // parse array qualifiers
                List <int> dimCountArray = new List <int>();
                var        matches       = ArraySizeRegex.Matches(name, match.Length);
                foreach (Match m in matches)
                {
                    string size = m.Groups[1].Value;
                    dimCountArray.Add(int.Parse(size));
                }

                var resultType = BlendTypeFactory.From(type, pointerCount, dimCountArray.ToArray());
                return(new BlendStructureType.MemberDecl(baseName, resultType));
            }
            else
            {
                // unknown
                return(new BlendStructureType.MemberDecl(name, new UnknownBlendType(description, tLen)));
            }
        }