コード例 #1
0
ファイル: FunctionList.cs プロジェクト: hahoyer/reni.cs
 int CreateFunctionInstance(TypeBase args, FunctionSyntax syntax, CompoundView compoundView)
 {
     var index = _list.Count;
     var f = new FunctionType(index, syntax, compoundView, args);
     _list.Add(f);
     return index;
 }
コード例 #2
0
ファイル: Simple.cs プロジェクト: hahoyer/reni.cs
 internal Value(Func<Category, Result> function, TypeBase source)
     : base(_nextObjectId++)
 {
     Function = function;
     Source = source;
     Tracer.Assert(Source != null);
 }
コード例 #3
0
ファイル: WebFile.cs プロジェクト: antiufo/Shaman.Http
        internal static WebFile FromDbValue(WebFile file, string content, TypeBase type)
        {
            /*if (url == null) return null;
            var u = url.AsUri();
            var file =
                type == TypeBase.WebImage ? WebImage.FromUrl(u) :
                type == TypeBase.WebAudio ? WebAudio.FromUrl(u) :
                type == TypeBase.WebVideo ? WebVideo.FromUrl(u) :
                WebFile.FromUrl(u);
                */
            if (content != null)
            {
                var serializer = new JsonSerializer();

                serializer.AddAwdeeConverters();
                using (var sr = new StringReader(content))
                using (var jr = Utils.CreateJsonReader(sr))
                {
                    serializer.Deserialize(jr, type.NativeType);
                }

            }

            return file;
        }
コード例 #4
0
 internal SymmetricClosureService(TypeBase source)
 {
     Source = source;
     AllFeatures = source
         .SymmetricFeatureClosure()
         .ToArray();
 }
コード例 #5
0
ファイル: BoolType.cs プロジェクト: Rohansi/LoonyC
        public override bool IsAssignableTo(TypeBase other, int depth = 0, bool checkConst = true)
        {
            if (!base.IsAssignableTo(other, depth, checkConst))
                return false;

            return other is BoolType;
        }
コード例 #6
0
ファイル: BoolType.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            return other is BoolType;
        }
コード例 #7
0
ファイル: PointerType.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            return IsConstant == other.IsConstant && other is PointerType;
        }
コード例 #8
0
ファイル: FrameResource.cs プロジェクト: Rohansi/LoonyC
        public RegisterFrameResource(Frame frame, TypeBase type, Register register)
            : base(frame, type)
        {
            Register = register;

            if (type is PointerType)
            {
                _type = OperandValueType.Dword;
            }
            else
            {
                var typePrim = type as PrimitiveType;
                if (typePrim == null)
                    throw new ArgumentException("Type must be a primitive.", nameof(type));

                switch (typePrim.Type)
                {
                    case Primitive.Int:
                        _type = OperandValueType.Dword;
                        break;
                    case Primitive.Short:
                        _type = OperandValueType.Word;
                        break;
                    case Primitive.Char:
                        _type = OperandValueType.Byte;
                        break;
                    default:
                        throw new NotSupportedException();
                }
            }
        }
コード例 #9
0
ファイル: ArrayType.cs プロジェクト: Rohansi/LoonyC
        public ArrayType(TypeBase innerType, int count, bool constant = false)
            : base(innerType, constant)
        {
            if (count <= 0)
                throw new ArgumentOutOfRangeException(nameof(count));

            Count = count;
        }
コード例 #10
0
ファイル: Function.cs プロジェクト: hahoyer/reni.cs
 internal Function(ContextBase parent, TypeBase argsType, TypeBase valueType = null)
     : base(parent)
 {
     _order = CodeArgs.NextOrder++;
     ArgsType = argsType;
     ValueType = valueType;
     StopByObjectIds();
 }
コード例 #11
0
ファイル: TypeModifier.cs プロジェクト: Rohansi/LoonyC
        protected TypeModifier(TypeBase innerType, bool constant = false)
            : base(constant)
        {
            if (innerType == null)
                throw new ArgumentNullException(nameof(innerType));

            InnerType = innerType;
        }
コード例 #12
0
ファイル: Conversion.cs プロジェクト: hahoyer/reni.cs
 internal Conversion(Func<Category, Result> function, TypeBase source)
     : base(_nextObjectId++)
 {
     Function = function;
     Source = source;
     Tracer.Assert(Source != null);
     StopByObjectIds();
 }
コード例 #13
0
ファイル: RepeaterAccessType.cs プロジェクト: hahoyer/reni.cs
        internal Result Result(Category category, Result leftResult, TypeBase right)
        {
            var rightResult = right
                .Conversion(category.Typed, IndexType)
                .AutomaticDereferencedAlignedResult();

            return Result(category, leftResult + rightResult);
        }
コード例 #14
0
ファイル: SearchResult.cs プロジェクト: hahoyer/reni.cs
 public static SearchResult Create(IImplementation feature, TypeBase definingItem)
 {
     var searchResult = feature as SearchResult;
     if(searchResult == null)
         return new SearchResult(feature, definingItem);
     var source = searchResult.Source;
     Tracer.Assert(source == definingItem);
     return searchResult;
 }
コード例 #15
0
ファイル: NamedType.cs プロジェクト: Rohansi/LoonyC
        public override bool IsAssignableTo(TypeBase other, int depth = 0, bool checkConst = true)
        {
            if (!base.IsAssignableTo(other, depth, checkConst))
                return false;

            if (depth > 0 && other is AnyType)
                return true;

            return Equals(other);
        }
コード例 #16
0
ファイル: EmitTranslator.cs プロジェクト: destinyclown/VBF
        private Type GetClrType(TypeBase t)
        {
            var clrType = m_typeTable.Get(t);
            if (clrType != null)
            {
                return clrType;
            }

            CodeClassType ccType = t as CodeClassType;

            if (ccType != null)
            {
                Type baseClass = typeof(Object);

                if (ccType.BaseType != null)
                {
                    baseClass = GetClrType(ccType.BaseType);
                }

                clrType = m_module.DefineType(t.Name, TypeAttributes.Class | TypeAttributes.BeforeFieldInit, baseClass);

                m_typeTable.Set(t, clrType);
                return clrType;
            }

            ArrayType aType = t as ArrayType;
            if (aType != null)
            {
                var elementType = GetClrType(aType.ElementType);

                clrType = elementType.MakeArrayType();
                m_typeTable.Set(t, clrType);

                return clrType;
            }

            PrimaryType pType = t as PrimaryType;

            switch (pType.Name)
            {
                case "int":
                    clrType = typeof(int);
                    break;
                case "bool":
                    clrType = typeof(bool);
                    break;
                default:
                    Debug.Assert(false, "unknown primary type");
                    break;
            }

            m_typeTable.Set(t, clrType);
            return clrType;

        }
コード例 #17
0
ファイル: TypeModifier.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            var otherMod = other as TypeModifier;
            if (otherMod == null)
                return false;

            return InnerType.Equals(otherMod.InnerType);
        }
コード例 #18
0
ファイル: TypeModifier.cs プロジェクト: Rohansi/LoonyC
        public override bool IsAssignableTo(TypeBase other, int depth = 0, bool checkConst = true)
        {
            if (!base.IsAssignableTo(other, depth, checkConst))
                return false;

            var otherMod = other as TypeModifier;
            if (otherMod == null)
                return false;

            return InnerType.IsAssignableTo(otherMod.InnerType, depth + 1);
        }
コード例 #19
0
ファイル: ArrayType.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            var otherArray = other as ArrayType;
            if (otherArray == null)
                return false;

            return IsConstant == other.IsConstant && Count == otherArray.Count;
        }
コード例 #20
0
ファイル: PrimitiveType.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            var otherPrim = other as PrimitiveType;
            if (otherPrim == null)
                return false;

            return IsConstant == other.IsConstant && Type == otherPrim.Type;
        }
コード例 #21
0
ファイル: ArrayType.cs プロジェクト: Rohansi/LoonyC
        public override bool IsAssignableTo(TypeBase other, int depth = 0, bool checkConst = true)
        {
            if (!base.IsAssignableTo(other, depth, checkConst))
                return false;

            if (other is PointerType)
                return true;

            var otherArray = other as ArrayType;
            return Count >= otherArray?.Count;
        }
コード例 #22
0
ファイル: NamedType.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            var otherNamed = other as NamedType;
            if (otherNamed == null)
                return false;

            return IsConstant == other.IsConstant && Name == otherNamed.Name;
        }
コード例 #23
0
ファイル: FunctionType.cs プロジェクト: hahoyer/reni.cs
 internal FunctionType
     (int index, FunctionSyntax body, CompoundView compoundView, TypeBase argsType)
 {
     Getter = new GetterFunction(this, index, body.Getter);
     Setter = body.Setter == null ? null : new SetterFunction(this, index, body.Setter);
     Index = index;
     Body = body;
     _compoundView = compoundView;
     ArgsType = argsType;
     StopByObjectIds();
 }
コード例 #24
0
ファイル: PrimaryType.cs プロジェクト: destinyclown/VBF
        public override bool IsAssignableFrom(TypeBase type)
        {
            if (this == type)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
コード例 #25
0
ファイル: FuncType.cs プロジェクト: Rohansi/LoonyC
        public FuncType(IList<TypeBase> parameterTypes, TypeBase returnType, bool constant = false)
            : base(constant)
        {
            if (parameterTypes == null)
                throw new ArgumentNullException(nameof(parameterTypes));

            if (parameterTypes.Any(p => p == null))
                throw new ArgumentNullException(nameof(parameterTypes), "contains null entry");

            ParameterTypes = new ReadOnlyCollection<TypeBase>(parameterTypes);
            ReturnType = returnType;
        }
コード例 #26
0
ファイル: Frame.cs プロジェクト: Rohansi/LoonyC
        public FrameResource Allocate(TypeBase type, bool canUseRegister = true)
        {
            if (canUseRegister)
            {
                var register = TryAllocateRegister();
                if (register.HasValue)
                    return new RegisterFrameResource(this, type, register.Value);
            }

            var offset = AllocateStack(type.Size);
            return new StackFrameResource(this, type, offset, type.Size);
        }
コード例 #27
0
ファイル: Scope.cs プロジェクト: Rohansi/LoonyC
        public bool TryDefine(string name, TypeBase type, out FrameResource resource)
        {
            resource = null;

            if (IsDefined(name))
                return false;

            resource = Frame.Allocate(type, false);

            _identifiers.Add(name, resource);
            return true;
        }
コード例 #28
0
ファイル: ArrayType.cs プロジェクト: destinyclown/VBF
        public override bool IsAssignableFrom(TypeBase type)
        {
            CodeClassType elementClassType = ElementType as CodeClassType;
            ArrayType arrayType = type as ArrayType;

            if (elementClassType != null && arrayType != null)
            {
                return elementClassType.IsAssignableFrom(arrayType.ElementType);
            }

            return false;
        }
コード例 #29
0
ファイル: FuncType.cs プロジェクト: Rohansi/LoonyC
        public override bool Equals(TypeBase other)
        {
            if (!base.Equals(other))
                return false;

            var otherFunc = other as FuncType;
            if (otherFunc == null)
                return false;

            return IsConstant == other.IsConstant &&
                   ParameterTypes.SequenceEqual(otherFunc.ParameterTypes) &&
                   ReturnType == otherFunc.ReturnType;
        }
コード例 #30
0
ファイル: PrimitiveType.cs プロジェクト: Rohansi/LoonyC
        public override bool IsAssignableTo(TypeBase other, int depth = 0, bool checkConst = true)
        {
            if (!base.IsAssignableTo(other, depth, checkConst))
                return false;

            if (depth > 0 && other is AnyType)
                return true;

            var otherPrim = other as PrimitiveType;
            if (otherPrim == null)
                return false;

            return Type == otherPrim.Type || (depth == 0 && otherPrim.Type >= Type);
        }
コード例 #31
0
 protected override SourceFileGenerator CreateSourceFileGenerator(TypeBase type, bool sort_using, bool generate_document_comment, string compagny_name, string copyright_header, string author)
 {
     return(new JavaSourceFileGenerator(type, RootNamespace, sort_using, generate_document_comment, compagny_name, copyright_header, author));
 }
コード例 #32
0
        private static EffectTypeDescription CreateTypeInfo(TypeBase variableType, List <AttributeBase> attributes, out EffectTypeDescription elementType)
        {
            elementType = default;

            var parameterTypeInfo = new EffectTypeDescription();

            if (variableType.TypeInference.TargetType != null)
            {
                variableType = variableType.TypeInference.TargetType;
            }

            if (variableType is ArrayType)
            {
                var arrayType = (ArrayType)variableType;
                variableType = arrayType.Type;
                parameterTypeInfo.Elements = (int)((LiteralExpression)arrayType.Dimensions[0]).Literal.Value;

                if (variableType.TypeInference.TargetType != null)
                {
                    variableType = variableType.TypeInference.TargetType;
                }
            }

            if (variableType is ScalarType)
            {
                if (variableType == ScalarType.Int)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Scalar;
                    parameterTypeInfo.Type  = EffectParameterType.Int;
                }
                else if (variableType == ScalarType.UInt)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Scalar;
                    parameterTypeInfo.Type  = EffectParameterType.UInt;
                }
                else if (variableType == ScalarType.Float)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Scalar;
                    parameterTypeInfo.Type  = EffectParameterType.Float;
                }
                else if (variableType == ScalarType.Double)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Scalar;
                    parameterTypeInfo.Type  = EffectParameterType.Double;
                }
                else if (variableType == ScalarType.Bool)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Scalar;
                    parameterTypeInfo.Type  = EffectParameterType.Bool;
                }

                parameterTypeInfo.RowCount    = 1;
                parameterTypeInfo.ColumnCount = 1;
            }
            else if (variableType is VectorType vectorType)
            {
                if (vectorType.Type == ScalarType.Float)
                {
                    bool isColor = attributes.OfType <AttributeDeclaration>().Any(x => x.Name == "Color");
                    parameterTypeInfo.Class = isColor ? EffectParameterClass.Color : EffectParameterClass.Vector;
                    parameterTypeInfo.Type  = EffectParameterType.Float;
                }
                else if (vectorType.Type == ScalarType.Double)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Vector;
                    parameterTypeInfo.Type  = EffectParameterType.Double;
                }
                else if (vectorType.Type == ScalarType.Int)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Vector;
                    parameterTypeInfo.Type  = EffectParameterType.Int;
                }
                else if (vectorType.Type == ScalarType.UInt)
                {
                    parameterTypeInfo.Class = EffectParameterClass.Vector;
                    parameterTypeInfo.Type  = EffectParameterType.UInt;
                }

                parameterTypeInfo.RowCount    = 1;
                parameterTypeInfo.ColumnCount = ((VectorType)variableType).Dimension;
            }
            else if (variableType is MatrixType)
            {
                parameterTypeInfo.Class       = EffectParameterClass.MatrixColumns;
                parameterTypeInfo.Type        = EffectParameterType.Float;
                parameterTypeInfo.RowCount    = ((MatrixType)variableType).RowCount;
                parameterTypeInfo.ColumnCount = ((MatrixType)variableType).ColumnCount;
            }
            else if (variableType is StructType)
            {
                var structType = (StructType)variableType;

                parameterTypeInfo.Class       = EffectParameterClass.Struct;
                parameterTypeInfo.RowCount    = 1;
                parameterTypeInfo.ColumnCount = 1;
                parameterTypeInfo.Name        = structType.Name.Text;

                var members = new List <EffectTypeMemberDescription>();
                foreach (var field in structType.Fields)
                {
                    var memberInfo = new EffectTypeMemberDescription
                    {
                        Name = field.Name.Text,
                        Type = CreateTypeInfo(field.Type, field.Attributes, out var _),
                    };
                    members.Add(memberInfo);
                }

                parameterTypeInfo.Members = members.ToArray();
            }
            else
            {
                var variableTypeName = variableType.Name.Text.ToLowerInvariant();

                if (variableType is ClassType classType && classType.GenericArguments.Count == 1)
                {
                    elementType = CreateTypeInfo(classType.GenericArguments[0], new List <AttributeBase>(), out var _);
                }

                switch (variableTypeName)
                {
                case "cbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.ConstantBuffer;
                    parameterTypeInfo.Type  = EffectParameterType.ConstantBuffer;
                    break;

                case "tbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.TextureBuffer;
                    parameterTypeInfo.Type  = EffectParameterType.TextureBuffer;
                    break;

                case "structuredbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.StructuredBuffer;
                    break;

                case "rwstructuredbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWStructuredBuffer;
                    break;

                case "consumestructuredbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.ConsumeStructuredBuffer;
                    break;

                case "appendstructuredbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.AppendStructuredBuffer;
                    break;

                case "buffer":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Buffer;
                    break;

                case "rwbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWBuffer;
                    break;

                case "byteaddressbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.ByteAddressBuffer;
                    break;

                case "rwbyteaddressbuffer":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWByteAddressBuffer;
                    break;

                case "texture1d":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture1D;
                    break;

                case "texturecube":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.TextureCube;
                    break;

                case "texture2d":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture2D;
                    break;

                case "texture2dms":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture2DMultisampled;
                    break;

                case "texture3d":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture3D;
                    break;

                case "texture1darray":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture1DArray;
                    break;

                case "texturecubearray":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.TextureCubeArray;
                    break;

                case "texture2darray":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture2DArray;
                    break;

                case "texture2dmsarray":
                    parameterTypeInfo.Class = EffectParameterClass.ShaderResourceView;
                    parameterTypeInfo.Type  = EffectParameterType.Texture2DMultisampledArray;
                    break;

                case "rwtexture1d":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWTexture1D;
                    break;

                case "rwtexture2d":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWTexture2D;
                    break;

                case "rwtexture3d":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWTexture3D;
                    break;

                case "rwtexture1darray":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWTexture1DArray;
                    break;

                case "rwtexture2darray":
                    parameterTypeInfo.Class = EffectParameterClass.UnorderedAccessView;
                    parameterTypeInfo.Type  = EffectParameterType.RWTexture2DArray;
                    break;

                case "samplerstate":
                case "samplercomparisonstate":
                    parameterTypeInfo.Class = EffectParameterClass.Sampler;
                    parameterTypeInfo.Type  = EffectParameterType.Sampler;
                    break;
                }
            }

            return(parameterTypeInfo);
        }
コード例 #33
0
        private int ComputeSize(TypeBase type)
        {
            if (type.TypeInference.TargetType != null)
            {
                type = type.TypeInference.TargetType;
            }

            var structType = type as StructType;

            if (structType != null)
            {
                var structSize = 0;
                foreach (var field in structType.Fields)
                {
                    var memberSize = ComputeSize(field.Type);

                    // Seems like this element needs to be split accross multiple lines,
                    if ((structSize + memberSize - 1) / 16 != structSize / 16)
                    {
                        structSize = (structSize + 16 - 1) / 16 * 16;
                    }

                    structSize += memberSize;
                }
                return(structSize);
            }

            if (type is ScalarType)
            {
                // Uint and int are collapsed to int
                if (type == ScalarType.Int || type == ScalarType.UInt ||
                    type == ScalarType.Float || type == ScalarType.Bool)
                {
                    return(4);
                }
                else if (type == ScalarType.Double)
                {
                    return(8);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            var vectorType = type as VectorType;

            if (vectorType != null)
            {
                return(ComputeSize(vectorType.Type) * vectorType.Dimension);
            }

            var matrixType = type as MatrixType;

            if (matrixType is MatrixType)
            {
                return(4 * (matrixType.ColumnCount - 1) + matrixType.RowCount);
            }

            throw new NotImplementedException();
        }
コード例 #34
0
 protected static bool IsTextureType(TypeBase type)
 {
     // TODO we should improve AST type system
     return(type is TextureType || (type is GenericBaseType && type.Name.Text.Contains("Texture")));
 }
コード例 #35
0
 public int GetIndex(TypeBase type)
 => typeLookup[type];
コード例 #36
0
        /// <summary>
        /// Gets the type of the binary implicit conversion.
        /// </summary>
        /// <param name="span">The span.</param>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="isBinaryOperator">if set to <c>true</c> [is binary operator].</param>
        /// <returns>
        /// The implicit conversion between between to two types
        /// </returns>
        protected virtual TypeBase GetBinaryImplicitConversionType(SourceSpan span, TypeBase left, TypeBase right, bool isBinaryOperator)
        {
            var result = CastHelper.GetBinaryImplicitConversionType(left, right, isBinaryOperator);

            if (result == null)
            {
                Error(MessageCode.ErrorBinaryTypeDeduction, span, left, right);
            }

            return(result);
        }
コード例 #37
0
ファイル: ProjectGenerator.cs プロジェクト: Dgatibelza/NClass
 protected abstract SourceFileGenerator CreateSourceFileGenerator(TypeBase type);
コード例 #38
0
 private static ForeignKeyAttribute GetForeignKeyAttribute(TypeBase entityType, string propertyName)
 => entityType.GetRuntimeProperties()?.Values
 .FirstOrDefault(
     p => string.Equals(p.Name, propertyName, StringComparison.OrdinalIgnoreCase) &&
     Attribute.IsDefined(p, typeof(ForeignKeyAttribute), inherit: true))
 ?.GetCustomAttribute <ForeignKeyAttribute>(inherit: true);
コード例 #39
0
 /// <exception cref="NullReferenceException">
 /// <paramref name="type"/> is null.
 /// </exception>
 public CSharpSourceFileGenerator(TypeBase type, string rootNamespace)
     : base(type, rootNamespace)
 {
 }
コード例 #40
0
 public CSharpTemplateSourceFileGenerator
     (TypeBase type, string rootNamespace, Model model)
     : base(type, rootNamespace, model)
 {}
コード例 #41
0
 public static bool IsSamplerType(this TypeBase type)
 {
     return(Parse(type.Name) != null);
 }
コード例 #42
0
 public MapType(TypeBase keyType, TypeBase valueType, bool isOptional, IDictionary <string, object> parameters)
     : base(isOptional, parameters)
 {
     this.KeyType   = keyType ?? throw new ArgumentNullException(nameof(keyType));
     this.ValueType = valueType ?? throw new ArgumentNullException(nameof(valueType));
 }
コード例 #43
0
 public VectorType(TypeBase elementType, bool isOptional, IDictionary <string, object> parameters)
     : base(isOptional, parameters)
 {
     this.ElementType = elementType ?? throw new ArgumentNullException(nameof(elementType));
 }
コード例 #44
0
 public ObjectElement(IEnumerable <string> attributes, string name, TypeBase type)
 {
     this.Attributes = attributes?.ToList() ?? throw new ArgumentNullException(nameof(attributes));
     this.Name       = name ?? throw new ArgumentNullException(nameof(name));
     this.Type       = type ?? throw new ArgumentNullException(nameof(type));
 }
コード例 #45
0
 protected override SourceFileGenerator CreateSourceFileGenerator(TypeBase type)
 {
     return(new CSharpSourceFileGenerator(type, RootNamespace));
 }
コード例 #46
0
 private static TemplateData CreateTemplateData <T>(int id, TypeBase typeBase)
 {
     return(CreateTemplateData <T>(id, typeBase.GetKeyValuePairList()));
 }
コード例 #47
0
        /// <summary>
        /// Gets the type of the binary implicit conversion.
        /// </summary>
        /// <param name="span">The span.</param>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The implicit conversion between between to two types</returns>
        protected virtual TypeBase GetDivideImplicitConversionType(SourceSpan span, TypeBase left, TypeBase right)
        {
            var result = CastHelper.GetDivideImplicitConversionType(left.ResolveType(), right.ResolveType());

            if (result == null)
            {
                Error(MessageCode.ErrorBinaryTypeDeduction, span, left, right);
            }

            return(result);
        }
コード例 #48
0
ファイル: DocParser.cs プロジェクト: snbillsmith/autohelp
        private IList <Method> GetMethods(Type type, TypeBase parent)
        {
            var list = new List <Method>();

            // Used for ID generation
            var methodNames = new List <string>();

            // Get only methods for this object, none of the inherited methods.
            foreach (var info in type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
            {
                try
                {
                    if (!info.IsSpecialName)
                    {
                        var method = new Method
                        {
                            Parent      = parent,
                            ParentClass = parent.Id,
                            Name        = info.Name,
                        };

                        // Contains overloads - ID is the hashcode
                        if (methodNames.Contains(info.Name))
                        {
                            method.UseHashCodeForId = true;
                        }

                        methodNames.Add(info.Name);

                        if (info.IsGenericMethod)
                        {
                            var arguments = info.GetGenericArguments().Select(genericType => genericType.Name).ToList();

                            method.Name             = info.Name + "<" + string.Join(",", arguments) + ">";
                            method.UseHashCodeForId = true;
                        }

                        try
                        {
                            method.Fullname           = info.ToString();
                            method.ReturnType         = GetTypeName(info.ReturnType);
                            method.ReturnTypeFullName = GetFullTypeName(info.ReturnType);

                            // Get common tags
                            var element =
                                _reader.GetComments(info.IsGenericMethod ? info.GetGenericMethodDefinition() : info);
                            var comments = GetCommonTags(element);
                            method.Example    = comments.Example;
                            method.Remarks    = comments.Remarks;
                            method.Returns    = comments.Returns;
                            method.Summary    = comments.Summary;
                            method.Parameters = GetMethodParameters(info.GetParameters(), element); // Parameters
                        }
                        catch (Exception ex)
                        {
                            method.LoadError = true;
                            method.Fullname  = ex.Message;
                        }

                        list.Add(method);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Type {0} : Parse methods Problem. {1} => {2}", type, ex.Message, ex.Source);
                }
            }

            list = list.OrderBy(m => m.Name).ToList();
            return(list);
        }
コード例 #49
0
 protected static bool IsBufferType(TypeBase type)
 {
     // TODO we should improve AST type system
     return((type is GenericBaseType && type.Name.Text.Contains("Buffer")) || type.IsByteAddressBufferType());
 }
コード例 #50
0
 /// <exception cref="NullReferenceException">
 ///     <paramref name="type" /> is null.
 /// </exception>
 public JavaSourceFileGenerator(TypeBase type, string rootNamespace, bool sort_using, bool generate_document_comment, string compagny_name, string copyright_header, string author) : base(type, rootNamespace, sort_using, generate_document_comment, compagny_name, copyright_header, author)
 {
 }
コード例 #51
0
ファイル: MSLIO.cs プロジェクト: yuva2achieve/SharpDevelop
 private static void MapComplexProperties(XElement complexMappingParentElement, MappingBase complexMappingOwner, TypeBase type, ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.EntityType.EntityType table)
 {
     foreach (var complexPropertyElement in complexMappingParentElement.Elements(XName.Get("ComplexProperty", mslNamespace.NamespaceName)))
     {
         var complexProperty        = type.AllComplexProperties.GetByName(complexPropertyElement.Attribute("Name").Value);
         var complexPropertyMapping = complexMappingOwner[complexProperty];
         foreach (var scalarPropertyElement in complexPropertyElement.Elements(XName.Get("ScalarProperty", mslNamespace.NamespaceName)))
         {
             var scalarProperty = complexProperty.ComplexType.AllScalarProperties.GetByName(scalarPropertyElement.Attribute("Name").Value);
             var column         = table.Properties.First(c => c.Name == scalarPropertyElement.Attribute("ColumnName").Value);
             complexPropertyMapping[scalarProperty, table] = column;
         }
         MapComplexProperties(complexPropertyElement, complexPropertyMapping, complexProperty.ComplexType, table);
     }
 }
コード例 #52
0
        public override Node Visit(BinaryExpression expression)
        {
            // First, dispatch to resolve type of node at deeper level
            base.Visit(expression);

            var leftType   = expression.Left.TypeInference.TargetType;
            var rightType  = expression.Right.TypeInference.TargetType;
            var returnType = expression.TypeInference.ExpectedType ?? expression.TypeInference.TargetType;

            bool isNumericOperator = true;

            switch (expression.Operator)
            {
            case BinaryOperator.LogicalAnd:
            case BinaryOperator.LogicalOr:
                isNumericOperator = false;
                returnType        = GetBinaryImplicitConversionType(expression.Span, leftType, rightType, true);
                expression.TypeInference.TargetType = returnType;
                break;

            case BinaryOperator.Less:
            case BinaryOperator.LessEqual:
            case BinaryOperator.Greater:
            case BinaryOperator.GreaterEqual:
            case BinaryOperator.Equality:
            case BinaryOperator.Inequality:
                isNumericOperator = false;
                returnType        = GetBinaryImplicitConversionType(expression.Span, leftType, rightType, false);

                TypeBase resultType = ScalarType.Bool;
                if (returnType is VectorType)
                {
                    resultType = new VectorType(ScalarType.Bool, ((VectorType)returnType).Dimension);
                }
                else if (returnType is MatrixType)
                {
                    var matrixType = (MatrixType)returnType;
                    resultType = new MatrixType(ScalarType.Bool, matrixType.RowCount, matrixType.ColumnCount);
                }
                expression.TypeInference.TargetType = resultType;
                break;
            }

            if (returnType != null)
            {
                if (returnType == ScalarType.Bool && isNumericOperator)
                {
                    var typeToCheck = leftType ?? rightType;
                    if (typeToCheck != null)
                    {
                        return(ConvertExpressionToBool(expression, typeToCheck));
                    }
                }
            }

            if (!isNumericOperator || CastHelper.NeedConvertForBinary(leftType, returnType))
            {
                expression.Left = Cast(leftType, returnType, expression.Left);
            }
            if (!isNumericOperator || CastHelper.NeedConvertForBinary(rightType, returnType))
            {
                expression.Right = Cast(rightType, returnType, expression.Right);
            }

            return(expression);
        }
コード例 #53
0
ファイル: TypeShape.cs プロジェクト: TrevorDArcyEvans/nERD
 protected TypeShape(TypeBase typeBase) : base(typeBase)
 {
     MinimumSize        = new Size(DefaultWidth, MinimumSize.Height);
     typeBase.Modified += delegate { UpdateMinSize(); };
 }
コード例 #54
0
 public SignalDataSingle()
 {
     m_type = TypeSingle.Instance;
 }
コード例 #55
0
ファイル: DocParser.cs プロジェクト: snbillsmith/autohelp
        private void FindTypes(Assembly assembly, List <Namespace> namespaces)
        {
            var typesInAsm = assembly.GetLoadableTypes().Where(p => p.IsPublic || p.IsNestedPublic || p.IsVisible).ToArray();

            foreach (var type in typesInAsm)
            {
                try
                {
                    // The namespace is everything before this type name, e.g. [Docy.Core].XYZ
                    string typeNamespace = type.Namespace;

                    var nameSpace = namespaces.FirstOrDefault(n => n.Name == typeNamespace);
                    if (nameSpace == null)
                    {
                        nameSpace = new Namespace {
                            Name = typeNamespace
                        };
                        namespaces.Add(nameSpace);
                    }

                    // Comments
                    var element  = _reader.GetComments(type);
                    var comments = GetCommonTags(element);

                    var typeBase = new TypeBase
                    {
                        Namespace   = nameSpace,
                        IsAbstract  = type.IsAbstract,
                        IsPrimitive = type.IsPrimitive,
                        IsPublic    = type.IsPublic,
                        IsSealed    = type.IsSealed,
                        IsNested    = type.IsNested,
                        ParentClass = type.BaseType != null ? type.BaseType.FullName : "",
                        Parents     = GetParents(type),
                        Name        = GetTypeName(type),
                        Fullname    = GetFullTypeName(type),
                        Example     = comments.Example,
                        Remarks     = comments.Remarks,
                        Returns     = comments.Returns,
                        Summary     = comments.Summary
                    };

                    typeBase.Constructors = GetConstructors(type, typeBase);
                    typeBase.Methods      = GetMethods(type, typeBase);
                    typeBase.Properties   = GetProperties(type, typeBase);

                    if (type.IsClass)
                    {
                        if (type.BaseType != null && type.BaseType == typeof(Delegate) || type.BaseType == typeof(MulticastDelegate))
                        {
                            typeBase.ObjectType = "Delegate";
                            nameSpace.Delegates.Add(typeBase);
                        }
                        else
                        {
                            typeBase.ObjectType = "Class";
                            nameSpace.Classes.Add(typeBase);
                        }
                    }
                    else if (type.IsEnum)
                    {
                        typeBase.ObjectType = "Enumeration";
                        typeBase.Members    = GetMembers(type);
                        nameSpace.Enumerations.Add(typeBase);
                    }
                    else if (type.IsValueType)
                    {
                        typeBase.ObjectType = "Structure";
                        nameSpace.Structures.Add(typeBase);
                    }
                    else if (type.IsInterface)
                    {
                        typeBase.ObjectType = "Interface";
                        nameSpace.Interfaces.Add(typeBase);
                    }
                    else
                    {
                        typeBase.ObjectType = "Delegate";
                        // TODO: Find out how to get delegate types
                        nameSpace.Delegates.Add(typeBase);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Type {0} : Parse Problem. {1} => {2}", type, ex.Message, ex.Source);
                }
            }
        }
コード例 #56
0
ファイル: TypeShape.cs プロジェクト: TrevorDArcyEvans/nERD
 public override string ToString()
 {
     return(TypeBase.ToString());
 }
コード例 #57
0
 protected virtual void Visit(TypeBase type)
 {
     Write(type.Name);
     ProcessInitialValueStatus = true;
 }
コード例 #58
0
        /// <summary>
        /// Gets the type of the binary implicit scalar conversion.
        /// </summary>
        /// <param name="span">The span.</param>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>
        /// The implicit conversion between the two scalar types
        /// </returns>
        protected ScalarType GetBinaryImplicitScalarConversionType(SourceSpan span, TypeBase left, TypeBase right)
        {
            var result = CastHelper.GetBinaryImplicitScalarConversionType(left, right);

            if (result == null)
            {
                Error(MessageCode.ErrorScalarTypeConversion, span, left, right);
            }
            return(result);
        }
コード例 #59
0
 public ITypeReference GetReference(TypeBase type)
 => new TypeReference(this, typeLookup[type]);
コード例 #60
0
ファイル: TypeConvert.cs プロジェクト: zyangpointer/VBF
 public TypeConvert(Expression source, TypeBase targetType)
 {
     Source         = source;
     ExpressionType = targetType;
 }