Exemple #1
0
        public override int GetHashCode()
        {
            var i = Name.GetHashCode() + Constant.GetHashCode() + Reference.GetHashCode();

            if (TemplateList != null)
            {
                i += TemplateList.GetHashCode();
            }

            return(i);
        }
Exemple #2
0
        public override void Declare()
        {
            var templateTypes = new TemplateList(Values.Select(i => i.GetResultType(_context)).ToList());

            _newFunction.Type = new SimpleType($"tuple{Values.Count}", templateTypes, 0);

            for (var i = 0; i < Values.Count; ++i)
            {
                _newFunction.Parameter.Add($"_{i}", Values[i]);
            }

            _newFunction.Declare();
        }
Exemple #3
0
        public override object Clone()
        {
            var i = new SimpleType(Name, 0)
            {
                Constant   = Constant,
                Reference  = Reference,
                IsTemplate = IsTemplate,
                IsVariadic = IsVariadic
            };

            if (TemplateList != null)
            {
                i.TemplateList = (TemplateList)TemplateList.CloneDeep();
            }
            return(i);
        }
Exemple #4
0
        public override string ToString()
        {
            var name = Name;

            if (TemplateList != null)
            {
                name += TemplateList.ToString();
            }

            if (!Constant && Reference)
            {
                name += "&";
            }

            return(name);
        }
Exemple #5
0
        public SimpleType(string name, TemplateList templateList, int array)
        {
            Array = array;

            if (array > 0)
            {
                Name         = "vector";
                TemplateList = CreateVector(array - 1, new SimpleType(name, templateList, 0)).TemplateList;
            }
            else
            {
                Name         = name;
                TemplateList = templateList;

                if (TypesExtension.Aliases.ContainsKey(name))
                {
                    Name = TypesExtension.Aliases[Name];
                }
            }
        }
Exemple #6
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            if (concreteElement == null)
            {
                var tmp1 = context.LookupTemplateType(this);
                Name         = tmp1.Name;
                TemplateList = tmp1.TemplateList;
                return;
            }

            // get the resulting type of the concrete element
            var concreteSimpleType = concreteElement.GetResultType(context.CallerContext);

            if (concreteSimpleType == null)
            {
                throw new TemplateGenerationException(this, $"Could not get the result type of {concreteElement}");
            }

            // check the template list of both types
            if (TemplateList == null)
            {
                if (concreteSimpleType.TemplateList != null)
                {
                    throw new TemplateGenerationException(this, $"Expected an empty template list ({this}), but got {concreteSimpleType}");
                }
            }
            // if the concrete type has a template list, we have to check if it fits to the template type template list
            else if (!TemplateList.Equals(concreteSimpleType.TemplateList))
            {
                throw new TemplateGenerationException(this, $"Expected the template list to be {TemplateList} but got {concreteSimpleType.TemplateList}");
            }

            TemplateList?.Template(context, concreteSimpleType.TemplateList);

            var tmp2 = context.RegisterTemplateType(this, concreteSimpleType);

            Name         = tmp2.Name;
            TemplateList = tmp2.TemplateList;
        }
Exemple #7
0
        public bool Equals(SimpleType other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            // exceptions
            if (IsTemplate || this is CppType || other is CppType)
            {
                return(true);
            }

            if (Name != other.Name)
            {
                return(false);
            }

            if (TemplateList == null)
            {
                if (other.TemplateList != null)
                {
                    return(false);
                }
            }
            else if (!TemplateList.Equals(other.TemplateList))
            {
                return(false);
            }

            return(true);
        }