public override void Visit(MemberReferenceExpression memberReferenceExpression)
        {
            base.Visit(memberReferenceExpression);

            if (sourceManager.IsClassExists(memberReferenceExpression.Member.Text))
                FoundClasses.Add(memberReferenceExpression.Member.Text);
        }
        private void Visit(MemberReferenceExpression memberReferenceExpression)
        {
            Visit((Node)memberReferenceExpression);

            if (sourceManager.IsClassExists(memberReferenceExpression.Member.Text))
                FoundClasses.Add(memberReferenceExpression.Member.Text);
        }
예제 #3
0
        protected Node Visit(MemberReferenceExpression expression)
        {
            Visit((Node)expression);
            if (expression.Member.Text == VariableToReplace.Name.Text)
                return new IndexerExpression(new MemberReferenceExpression(expression.Target, (IndexerReplacement.Target as VariableReferenceExpression).Name.Text), IndexerReplacement.Index);

            return expression;
        }
        public override Node Visit(MemberReferenceExpression expression)
        {
            base.Visit(expression);
            if (expression.Member.Text == VariableToReplace.Name.Text)
                return new IndexerExpression(new MemberReferenceExpression(expression.Target, (IndexerReplacement.Target as VariableReferenceExpression).Name.Text), IndexerReplacement.Index);

            return expression;
        }
예제 #5
0
        /// <summary>
        /// Decodes the swizzle.
        /// </summary>
        /// <param name="memberReference">The member reference.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public static List<MatrixType.Indexer> MatrixSwizzleDecode(MemberReferenceExpression memberReference, ParsingResult result = null)
        {
            string components = memberReference.Member.Text;

            var matrixDecl = (MatrixType)(memberReference.Target.TypeInference.TargetType);

            var span = matrixDecl.Span;

            var swizzles = (List<MatrixType.Indexer>)memberReference.GetTag(SwizzleTag);
            if (swizzles != null)
                return swizzles;

            swizzles = new List<MatrixType.Indexer>();

            if (components.StartsWith("_"))
            {
                string[] splitComponents;
                int indexOffset = 0;
                if (components.StartsWith("_m"))
                {
                    splitComponents = components.Split(new[] { "_m" }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    splitComponents = components.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
                    indexOffset = 1;
                }

                int dimension = 0;

                if (splitComponents.Length == 0 && result != null)
                {
                    result.Error(MessageCode.ErrorMatrixInvalidMemberReference, span, components);
                }

                foreach (var splitComponent in splitComponents)
                {
                    if (splitComponent.Length != 2 || !IsValidIndex(span, splitComponent[0], indexOffset, indexOffset + 3) || !IsValidIndex(span, splitComponent[1], indexOffset, indexOffset + 3))
                    {
                        swizzles.Clear();
                        break;
                    }

                    swizzles.Add(new MatrixType.Indexer(int.Parse(splitComponent[0].ToString()) - indexOffset, int.Parse(splitComponent[1].ToString()) - indexOffset));
                    dimension++;
                }
            }

            memberReference.SetTag(SwizzleTag, swizzles);
            return swizzles;
        }
        private Expression ProcessExpression(Expression expression)
        {
            if (expression.TypeInference.TargetType != null && expression.TypeInference.TargetType.IsStreamsType())
            {
                var mre = new MemberReferenceExpression(expression, typeInference.Name) { TypeInference = { Declaration = typeInference, TargetType = typeInference.Type.ResolveType() } };
                if (arrayIndex == null)
                    return mre;
                else
                {
                    var ire = new IndexerExpression(mre, arrayIndex);
                    return ire;
                }
            }

            return expression;
        }
예제 #7
0
        private Expression Visit(Expression expression)
        {
            Visit((Node)expression);

            if ((expression is VariableReferenceExpression || expression is MemberReferenceExpression || expression is IndexerExpression) && expression.TypeInference.TargetType is StreamsType) // TODO: exclude constants, test real type
            {
                var mre = new MemberReferenceExpression(expression, typeInference.Name) { TypeInference = { Declaration = typeInference, TargetType = typeInference.Type.ResolveType() } };
                if (arrayIndex == null)
                    return mre;
                else
                {
                    var ire = new IndexerExpression(mre, arrayIndex);
                    return ire;
                }
            }
            
            return expression;
        }
예제 #8
0
        protected void Visit(MemberReferenceExpression memberReferenceExpression)
        {
            Visit((Node)memberReferenceExpression);

            // Try to find usage of all MemberName 'yyy' in reference expressions like "xxx.yyy" and replace by their
            // generic instantiation
            var memberVariableName = memberReferenceExpression.Member.Text;
            if (variableGenerics.ContainsKey(memberVariableName) && variableGenerics[memberVariableName].Type is MemberName)
            {
                string memberName;
                if (stringGenerics.TryGetValue(memberVariableName, out memberName) && !autoGenericInstances)
                {
                    memberReferenceExpression.Member = new Identifier(memberName);
                }
                else
                {
                    memberReferenceExpression.TypeInference.Declaration = variableGenerics[memberVariableName];
                }
            }
        }
 public MemberReferenceExpressionNodeCouple(MemberReferenceExpression member, Node node)
 {
     Member = member;
     Node = node;
 }
예제 #10
0
 /// <summary>
 /// Tests if a MemberReferenceExpression is a reference to a stream from an Input/Output type
 /// </summary>
 /// <param name="expression">the expression to analyze</param>
 /// <returns>true if it is a member of an Input/Output type</returns>
 private static bool IsInputOutputMember(MemberReferenceExpression expression)
 {
     var targetType = expression.Target.TypeInference.TargetType as StreamsType;
     return targetType != null && targetType.IsInputOutput;
 }
        /// <summary>
        /// Analyze the stream and store the datas
        /// </summary>
        /// <param name="memberReference">the MemberReferenceExpression</param>
        private void CheckStreamMemberReference(MemberReferenceExpression memberReference)
        {
            // search the reference variable that should be stream
            var decl = memberReference.TypeInference.Declaration ?? FindDeclarations(memberReference.Member.Text).FirstOrDefault();
            var variableDecl = decl as Variable;
            var mixinDecl = decl as ShaderClassType;

            if (variableDecl != null)
            {
                memberReference.TypeInference.Declaration = variableDecl;
                memberReference.TypeInference.TargetType = variableDecl.Type.ResolveType();
            }
            else if (mixinDecl != null)
            {
                memberReference.TypeInference.Declaration = mixinDecl;
                memberReference.TypeInference.TargetType = mixinDecl.ResolveType();
            }
            else
            {
                Error(XenkoMessageCode.ErrorStreamNotFound, memberReference.Span, memberReference.Member.Text, analyzedModuleMixin.MixinName);
            }
        }
 /// <summary>
 /// Tests if a MemberReferenceExpression is a reference to a stream from an Input/Output type
 /// </summary>
 /// <param name="expression">the expression to analyze</param>
 /// <returns>true if it is a member of an Input/Output type</returns>
 private static bool IsMutableMember(MemberReferenceExpression expression)
 {
     var targetType = expression.Target.TypeInference.TargetType as ObjectType;
     return targetType != null && targetType.IsStreamsType() && targetType.IsStreamsMutable();
 }
예제 #13
0
파일: ShaderWriter.cs 프로젝트: cg123/xenko
 public virtual void Visit(MemberReferenceExpression memberReferenceExpression)
 {
     VisitDynamic(memberReferenceExpression.Target);
     Write(".");
     VisitDynamic(memberReferenceExpression.Member);
 }
 public override Node Visit(MemberReferenceExpression memberReferenceExpression)
 {
     var expression = (Expression)base.Visit(memberReferenceExpression);
     return ProcessExpression(expression);
 }
예제 #15
0
        /// <summary>
        /// Visits the specified member reference.
        /// </summary>
        /// <param name="memberReference">The member reference.</param>
        public override Node Visit(MemberReferenceExpression memberReference)
        {
            base.Visit(memberReference);

            CommonVisit(memberReference);

            // If member reference is used from method invocation expression, let the method invocation resolve the type
            if (!(ParentNode is MethodInvocationExpression) && memberReference.TypeInference.TargetType == null)
                Warning(MessageCode.WarningNoTypeReferenceMember, memberReference.Span, memberReference);

            return memberReference;
        }
 private static bool IsStreamMember(MemberReferenceExpression expression)
 {
     if (expression.TypeInference.Declaration is Variable)
     {
         return (expression.TypeInference.Declaration as Variable).Qualifiers.Contains(XenkoStorageQualifier.Stream);
     }
     return false;
 }
예제 #17
0
        /// <summary>
        /// Finds the member type reference.
        /// </summary>
        /// <param name="matrixType">Type of the matrix.</param>
        /// <param name="memberReference">The member reference.</param>
        protected virtual void FindMemberTypeReference(MatrixType matrixType, MemberReferenceExpression memberReference)
        {
            var components = memberReference.Member.Text;
            var span = memberReference.Span;

            // A matrix contains values organized in rows and columns, which can be accessed using the structure operator "." followed by one of two naming sets:
            //    The zero-based row-column position:
            //        _m00, _m01, _m02, _m03
            //        _m10, _m11, _m12, _m13
            //        _m20, _m21, _m22, _m23
            //        _m30, _m31, _m32, _m33
            //    The one-based row-column position:
            //        _11, _12, _13, _14
            //        _21, _22, _23, _24
            //        _31, _32, _33, _34
            //        _41, _42, _43, _44
            var swizzles = MatrixSwizzleDecode(memberReference, ParsingResult);

            if (swizzles.Count > 0)
            {
                var itemType = matrixType.Type.ResolveType();
                memberReference.TypeInference.TargetType = swizzles.Count == 1 ? itemType : new VectorType((ScalarType)itemType, swizzles.Count);
            }
        }
예제 #18
0
 /// <summary>
 /// Visits the specified member reference.
 /// </summary>
 /// <param name="memberReference">The member reference.</param>
 protected override void CommonVisit(MemberReferenceExpression memberReference)
 {
     var thisType = memberReference.Target.TypeInference.TargetType;
     
     if (thisType is MatrixType)
     {
         FindMemberTypeReference((MatrixType)thisType, memberReference);
     }
     else
     {
         base.CommonVisit(memberReference);
     }
 }
        public override void Visit(MemberReferenceExpression memberReferenceExpression)
        {
            var usageCopy = currentStreamUsage;
            currentStreamUsage |= StreamUsage.Partial;
            base.Visit(memberReferenceExpression);
            currentStreamUsage = usageCopy;

            // check if it is a stream
            if (IsStreamMember(memberReferenceExpression))
                AddStreamUsage(memberReferenceExpression.TypeInference.Declaration as Variable, memberReferenceExpression, currentStreamUsage);
        }
예제 #20
0
        protected virtual void Visit(MemberReferenceExpression memberReference)
        {
            Visit((Node)memberReference);

            CommonVisit(memberReference);

            // If member reference is used from method invocation expression, let the method invocation resolve the type
            if (!(ParentNode is MethodInvocationExpression) && memberReference.TypeInference.TargetType == null)
                Warning(MessageCode.WarningNoTypeReferenceMember, memberReference.Span, memberReference);
        }
예제 #21
0
 /// <summary>
 /// Replace a MemberReferenceExpression by a VariableReferenceExpression in the AST
 /// </summary>
 /// <param name="memberReferenceExpression">the member reference expression.</param>
 /// <param name="variableReferenceExpression">the variable reference expression.</param>
 /// <param name="parentNode">the parent node.</param>
 private static void ReplaceMemberReferenceExpressionByVariableReferenceExpression(MemberReferenceExpression memberReferenceExpression, VariableReferenceExpression variableReferenceExpression, Node parentNode)
 {
     var replacor = new XenkoReplaceVisitor(memberReferenceExpression, variableReferenceExpression);
     replacor.Run(parentNode);
 }
예제 #22
0
        /// <summary>
        /// Visits the specified member reference.
        /// </summary>
        /// <param name="memberReference">The member reference.</param>
        protected virtual void CommonVisit(MemberReferenceExpression memberReference)
        {
            var thisType = memberReference.Target.TypeInference.TargetType;

            if (thisType is StructType)
                FindMemberTypeReference((StructType)thisType, memberReference);
            else if (thisType is ScalarType)
                FindMemberTypeReference((ScalarType)thisType, memberReference);
            else if (thisType is VectorType)
                FindMemberTypeReference((VectorType)thisType, memberReference);
        }
예제 #23
0
 private static MemberReferenceExpression Clone(MemberReferenceExpression expression)
 {
     var mre = new MemberReferenceExpression(Clone(expression.Target), expression.Member);
     if (expression.TypeInference.TargetType is StreamsType)
         mre.TypeInference.TargetType = expression.TypeInference.TargetType;
     return mre;
 }
예제 #24
0
 /// <summary>
 /// Finds the member type reference.
 /// </summary>
 /// <param name="structType">Type of the struct.</param>
 /// <param name="memberReference">The member reference.</param>
 protected virtual void FindMemberTypeReference(StructType structType, MemberReferenceExpression memberReference)
 {
     foreach (var field in structType.Fields)
     {
         foreach (var variableDeclarator in field.Instances())
         {
             if (variableDeclarator.Name == memberReference.Member)
             {
                 memberReference.TypeInference.Declaration = variableDeclarator;
                 memberReference.TypeInference.TargetType = variableDeclarator.Type.ResolveType();
                 return;
             }
         }
     }
 }
        /// <summary>
        /// Checks if expression is a stream
        /// </summary>
        /// <param name="expression">the Expression</param>
        /// <returns>true if it is a stream, false otherwise</returns>
        private static bool IsStreamMember(MemberReferenceExpression expression)
        {
            if (expression != null)
            {
                var targetType = expression.Target.TypeInference.TargetType;
                if (targetType != null && targetType.IsStreamsType())
                    return true;

                // iterate until the base "class" is found and compare it to "streams"
                var target = expression.Target;
                while (target is MemberReferenceExpression)
                    target = (target as MemberReferenceExpression).Target;
                
                var variableReferenceExpression = target as VariableReferenceExpression;
                return variableReferenceExpression != null && (variableReferenceExpression.Name == StreamsType.ThisStreams.Name || (variableReferenceExpression.TypeInference.TargetType != null && variableReferenceExpression.TypeInference.TargetType.IsStreamsType()));
            }
            return false;
        }
예제 #26
0
 /// <summary>
 /// Finds the member type reference.
 /// </summary>
 /// <param name="scalarType">Type of the scalar.</param>
 /// <param name="memberReference">The member reference.</param>
 protected virtual void FindMemberTypeReference(ScalarType scalarType, MemberReferenceExpression memberReference)
 {
     var components = memberReference.Member.Text;
     if (components.Length <= 4 && (
         components.All(x => x == 'x' || x == 'y' || x == 'z' || x == 'w') ||
         components.All(x => x == 'r' || x == 'g' || x == 'b' || x == 'a') ||
         components.All(x => x == 's' || x == 't' || x == 'u' || x == 'v')
         ))
     {
         memberReference.TypeInference.TargetType = components.Length == 1 ? (TypeBase)scalarType : new VectorType(scalarType, components.Length);
     }
 }
        /// <summary>
        /// Visits the specified member reference.
        /// </summary>
        /// <param name="memberReference">The member reference.</param>
        protected override void CommonVisit(MemberReferenceExpression memberReference)
        {
            var targetDecl = memberReference.Target.TypeInference.Declaration;
            var variableTargetDecl = targetDecl as Variable;

            if (memberReference.Target is IndexerExpression)
                variableTargetDecl = (memberReference.Target as IndexerExpression).Target.TypeInference.Declaration as Variable;

            if (variableTargetDecl != null && memberReference.TypeInference.Declaration == null && variableTargetDecl.Qualifiers.Contains(StorageQualifier.Extern)) // from composition
            {
                var varType = variableTargetDecl.Type;
                if (varType is ArrayType)
                    varType = (varType as ArrayType).Type;

                var matchingDecls = FindDeclarationsFromObject(varType, memberReference.Member.Text).ToList();
                var varDecl = matchingDecls.OfType<Variable>().FirstOrDefault();
                var methodDecl = matchingDecls.OfType<MethodDeclaration>().FirstOrDefault();
                var shaderDecl = matchingDecls.OfType<ShaderClassType>().FirstOrDefault();

                if (varDecl != null)
                {
                    memberReference.TypeInference.Declaration = varDecl;
                    memberReference.TypeInference.TargetType = varDecl.Type.ResolveType();

                    if (!(ParentNode is MemberReferenceExpression) || varType is VectorType) // do not store the intermediate references, only the last one - except for vector types
                    {
                        if (IsStageInitMember(memberReference))
                            memberReference.SetTag(XenkoTags.StageInitRef, null);
                        else
                            memberReference.SetTag(XenkoTags.ExternRef, null);
                    }
                }
                else if (shaderDecl != null)
                {
                    memberReference.TypeInference.Declaration = shaderDecl;
                    memberReference.TypeInference.TargetType = shaderDecl.ResolveType();
                }
                else if (methodDecl == null)
                {
                    Error(XenkoMessageCode.ErrorExternMemberNotFound, memberReference.Span, memberReference, variableTargetDecl.Type, analyzedModuleMixin.MixinName);
                }
            }
            else if (targetDecl is ShaderClassType)
                FindMemberTypeReference(targetDecl as ShaderClassType, memberReference);
            else
                base.CommonVisit(memberReference);

            if (IsStreamMember(memberReference))
            {
                if (!(memberReference.Target.TypeInference.TargetType is VectorType
                    || memberReference.Target.TypeInference.TargetType != null && memberReference.Target.TypeInference.TargetType.TypeInference.TargetType is VectorType)) // do not look deeper in vector types
                    CheckStreamMemberReference(memberReference);

                if (memberReference.TypeInference.Declaration is Variable)
                {
                    var refAsVariable = memberReference.TypeInference.Declaration as Variable;
                    if (!(refAsVariable.Type is MemberName) && !refAsVariable.Qualifiers.Contains(XenkoStorageQualifier.Stream) && !refAsVariable.Qualifiers.Contains(XenkoStorageQualifier.PatchStream))
                        Error(XenkoMessageCode.ErrorExtraStreamsPrefix, memberReference.Span, memberReference, refAsVariable, analyzedModuleMixin.MixinName);
                }
            }
            else if (IsMutableMember(memberReference))
            {
                CheckStreamMemberReference(memberReference);
            }
            else if (memberReference.TypeInference.Declaration is Variable)
            {
                var variableDecl = (Variable)memberReference.TypeInference.Declaration;
                if (variableDecl.Qualifiers.Contains(XenkoStorageQualifier.Stream) || variableDecl.Qualifiers.Contains(XenkoStorageQualifier.PatchStream))
                    Error(XenkoMessageCode.ErrorMissingStreamsStruct, memberReference.Span, memberReference, analyzedModuleMixin.MixinName);
            }

            if (memberReference.TypeInference.Declaration is Variable) // TODO: check if it is a variable whose scope is inside the hierarchy
            {
                var isExtern = HasExternQualifier(memberReference);
                var shouldStoreExpression = !(ParentNode is MemberReferenceExpression) ^ (memberReference.TypeInference.TargetType is VectorType || memberReference.TypeInference.TargetType is MatrixType);
                if (shouldStoreExpression && isExtern)
                    memberReference.SetTag(XenkoTags.ExternRef, null);

                if (!isExtern && memberReference.Target.TypeInference.Declaration is ShaderClassType && !ReferenceEquals(analyzedModuleMixin.Shader, memberReference.Target.TypeInference.Declaration) && analyzedModuleMixin.InheritanceList.All(x => !ReferenceEquals(x.Shader, memberReference.Target.TypeInference.Declaration)))
                    memberReference.SetTag(XenkoTags.StaticRef, null);

                var varDecl = (Variable)memberReference.TypeInference.Declaration;
                if (currentVisitedMethod != null && currentVisitedMethod.Qualifiers.Contains(StorageQualifier.Static) && varDecl != null && varDecl.GetTag(XenkoTags.BaseDeclarationMixin) != null)
                    Error(XenkoMessageCode.ErrorNonStaticReferenceInStaticMethod, memberReference.Span, currentVisitedMethod, varDecl, analyzedModuleMixin.MixinName);
            }

            // Add to variable references list
            AddToVariablesReference(memberReference);
        }
예제 #28
0
 public override void Visit(MemberReferenceExpression memberReferenceExpression)
 {
     Identifier typeTarget;
     Identifier typeMember;
     if (TryParameters(memberReferenceExpression, out typeTarget, out typeMember))
     {
         var key = typeTarget + "." + typeMember;
         parameterKeysReferenced.Add(key);
         Write("context.GetParam(").Write(typeTarget).Write(".").Write(typeMember).Write(")");
     }
     else
     {
         base.Visit(memberReferenceExpression);
     }
 }
        /// <summary>
        /// Finds the member type reference.
        /// </summary>
        /// <param name="shaderDecl">Type of the shader</param>
        /// <param name="memberReference">The member reference.</param>
        protected void FindMemberTypeReference(ShaderClassType shaderDecl, MemberReferenceExpression memberReference)
        {
            var mixin = moduleMixins.FirstOrDefault(x => x.Shader == shaderDecl);
            if (mixin != null)
            {
                var shader = mixin.InheritanceList.FirstOrDefault(x => x.MixinName == memberReference.Member.Text);
                if (shader != null)
                {
                    memberReference.TypeInference.Declaration = shader.Shader;
                    memberReference.TypeInference.TargetType = shader.Shader;
                    return;
                }

                var variableDecl = mixin.VirtualTable.Variables.FirstOrDefault(x => x.Variable.Name.Text == memberReference.Member.Text);
                if (variableDecl != null)
                {
                    var isStream = IsStreamMember(memberReference);
                    if (!isStream || variableDecl.Variable.Qualifiers.Contains(XenkoStorageQualifier.Stream))
                    {
                        memberReference.TypeInference.Declaration = variableDecl.Variable;
                        memberReference.TypeInference.TargetType = variableDecl.Variable.Type.ResolveType();
                        return;
                    }
                }

                if (ParentNode is MethodInvocationExpression)
                {
                    var invocationExpression = ParentNode as MethodInvocationExpression;
                    if (ReferenceEquals(invocationExpression.Target, memberReference))
                    {
                        var methodDecl = mixin.VirtualTable.Methods.Select(x => x.Method).FirstOrDefault(x => x.IsSameSignature(invocationExpression));
                        if (methodDecl != null)
                        {
                            memberReference.TypeInference.Declaration = methodDecl;
                            invocationExpression.TypeInference.TargetType = methodDecl.ReturnType.ResolveType();
                            return;
                        }
                    }
                }
            }
        }
 private void Visit(MemberReferenceExpression memberReferenceExpression)
 {
     Visit((Node)memberReferenceExpression);
     CheckUsage(memberReferenceExpression.TypeInference.Declaration as Variable);
 }