protected override void VisitCastSyntax(CastSyntax pNode)
        {
            base.VisitCastSyntax(pNode);

            //We only care about methods that aren't in the current module
            foreach (var mod in _unit.GetAllReferences())
            {
                //Find the method
                foreach (var m in mod.Module.Methods)
                {
                    if (m is CastDefinitionSyntax c && IsCalledCast(c, pNode))
                    {
                        var rn = new ReferencedNode(m, mod.Cache);
                        if (!MethodNodes.Contains(rn))
                        {
                            MethodNodes.Add(rn);

                            //Get any type/methods that this method references
                            var mrv = new ModuleReferenceVisitor(mod.Cache, _context, mod);
                            mrv.Visit(m);
                            MethodNodes.AddRange(mrv.MethodNodes);
                            TypeNodes.AddRange(mrv.TypeNodes);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public Cast(CastSyntax syntax, Package containingPackage, Expression expression, CastType castType, ValueType type)
     : base(syntax, containingPackage)
 {
     Expression = expression;
     CastType   = castType;
     Type       = type;
 }
Beispiel #3
0
 public override SyntaxNode Visit(CastSyntax pNode)
 {
     using (new MetadataCache.LocalScope())
     {
         return(base.Visit(pNode));
     }
 }
Beispiel #4
0
 public override void Visit(CastSyntax pNode)
 {
     _returnValues = new List <ReturnValueSyntax>()
     {
         pNode.ReturnValue
     };
     base.Visit(pNode);
 }
        public override void Visit(CastSyntax pNode)
        {
            //Infer parameter types now that structs have been defined
            pNode.Parameter.SetType(SmallType.FromString(pNode.Parameter.Namespace, pNode.Parameter.Value));
            pNode.ReturnValue.SetType(SmallType.FromString(pNode.ReturnValue.Namespace, pNode.ReturnValue.Value));

            var d = MetadataCache.AddCast(pNode.Parameter.Type, pNode.Parameter.Value, pNode.ReturnValue.Type);

            d.SetScope(Scope.Public);
            pNode.SetDefinition(d);
        }
        protected override void VisitCastSyntax(CastSyntax pNode)
        {
            base.VisitCastSyntax(pNode);

            if (!pNode.FromType.IsAssignableFrom(pNode.Type) &&
                (!IsStandard(pNode.FromType) || !IsStandard(pNode.Type)))
            {
                switch (_unit.CastExists(pNode.FromType, pNode.Type, out MethodDefinition d))
                {
                case Compiler.FindResult.Found:
                    pNode.SetMethod(d);
                    break;

                case Compiler.FindResult.NotFound:
                    CompilerErrors.CastDoesNotExist(pNode.FromType, pNode.Type, pNode.Span);
                    break;

                case Compiler.FindResult.IncorrectScope:
                    CompilerErrors.CastNotIsScope(pNode.FromType, pNode.Type, pNode.Span);
                    break;
                }
            }
        }
 private bool IsCalledCast(CastDefinitionSyntax pMethod, CastSyntax pCall)
 {
     return(pMethod.Parameters[0].Type == pCall.FromType &&
            pMethod.ReturnValues[0].Type == pCall.Type);
 }
Beispiel #8
0
 protected virtual void VisitCastSyntax(CastSyntax pNode)
 {
     Visit(pNode.TypeNode);
     Visit(pNode.Value);
 }
Beispiel #9
0
 protected virtual SyntaxNode VisitCastSyntax(CastSyntax pNode)
 {
     return(SyntaxFactory.Cast(Visit(pNode.Value), (TypeSyntax)Visit(pNode.TypeNode)));
 }