Пример #1
0
        public TO2Type FindVariableLocal(IBlockContext context, string name)
        {
            for (int i = 0; i < declarations.Count; i++)
            {
                DeclarationParameter declaration = declarations[i];

                if (declaration.IsPlaceholder || name != declaration.target)
                {
                    continue;
                }
                if (declaration.type != null)
                {
                    return(declaration.type);
                }

                RealizedType elementType = sourceExpression.ResultType(context)
                                           ?.ForInSource(context.ModuleContext, null).ElementType;
                if (elementType == null)
                {
                    return(null);
                }
                switch (elementType)
                {
                case TupleType tupleType:
                    return(i < tupleType.itemTypes.Count ? tupleType.itemTypes[i] : null);

                case RecordType recordType:
                    return(recordType.ItemTypes.Get(declaration.source));
                }
            }

            return(null);
        }
Пример #2
0
 public VariableDeclaration(DeclarationParameter declaration, bool isConst, Expression expression,
                            Position start = new Position(), Position end = new Position()) : base(start, end)
 {
     this.declaration         = declaration;
     this.isConst             = isConst;
     this.expression          = expression;
     this.expression.TypeHint = context => this.declaration.type?.UnderlyingType(context.ModuleContext);
 }