Inheritance: Microsoft.CSharp.RuntimeBinder.Semantics.ParentSymbol
Exemplo n.º 1
0
        public Scope CreateScope(Scope parent)
        {
            Scope sym = newBasicSym(SYMKIND.SK_Scope, null, parent).AsScope();
            if (parent != null)
            {
                sym.nestingOrder = parent.nestingOrder + 1;
            }

            return sym;
        }
Exemplo n.º 2
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPRBOUNDLAMBDA GenerateBoundLambda(
            ArgumentObject[] arguments,
            Scope pScope,
            EXPR call)
        {
            // We don't actually need the real delegate type here - we just need SOME delegate type.
            // This is because we never attempt any conversions on the lambda itself.
            AggregateType delegateType = _symbolTable.GetCTypeFromType(typeof(Func<>)).AsAggregateType();
            LocalVariableSymbol thisLocal = _semanticChecker.GetGlobalSymbolFactory().CreateLocalVar(_semanticChecker.GetNameManager().Add("this"), pScope, _symbolTable.GetCTypeFromType(typeof(object)));
            thisLocal.isThis = true;
            EXPRBOUNDLAMBDA boundLambda = _exprFactory.CreateAnonymousMethod(delegateType);
            EXPRUNBOUNDLAMBDA unboundLambda = _exprFactory.CreateLambda();

            List<Type> paramTypes = new List<Type>();
            foreach (ArgumentObject o in arguments)
            {
                paramTypes.Add(o.Type);
            }
            boundLambda.Initialize(pScope);

            EXPRRETURN returnStatement = _exprFactory.CreateReturn(0, pScope, call);
            EXPRBLOCK block = _exprFactory.CreateBlock(null, returnStatement, pScope);
            boundLambda.OptionalBody = block;
            return boundLambda;
        }
Exemplo n.º 3
0
        /////////////////////////////////////////////////////////////////////////////////
        // We take the ArgumentObjects to verify - if the parameter expression tells us 
        // we have a ref parameter, but the argument object tells us we're not passed by ref,
        // then it means it was a ref that the compiler had to insert. This is used when
        // we have a call off of a struct for example. If thats the case, don't treat the 
        // local as a ref type.

        private void PopulateLocalScope(
            DynamicMetaObjectBinder payload,
            Scope pScope,
            ArgumentObject[] arguments,
            IEnumerable<Expression> parameterExpressions,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            // We use the compile time types for the local variables, and then 
            // cast them to the runtime types for the expression tree.

            int i = 0;
            foreach (Expression parameter in parameterExpressions)
            {
                CType type = _symbolTable.GetCTypeFromType(parameter.Type);

                // Make sure we're not setting ref for the receiver of a call - the argument
                // will be marked as ref if we're calling off a struct, but we don't want 
                // to persist that in our system.
                bool isFirstParamOfCallOrInvoke = false;
                if (i == 0 && IsBinderThatCanHaveRefReceiver(payload))
                {
                    isFirstParamOfCallOrInvoke = true;
                }

                // If we have a ref or out, get the parameter modifier type.
                if ((parameter is ParameterExpression && (parameter as ParameterExpression).IsByRef) &&
                    (arguments[i].Info.IsByRef || arguments[i].Info.IsOut))
                {
                    // If we're the first param of a call or invoke, and we're ref, it must be
                    // because of structs. Don't persist the parameter modifier type.
                    if (!isFirstParamOfCallOrInvoke)
                    {
                        type = _semanticChecker.GetTypeManager().GetParameterModifier(type, arguments[i].Info.IsOut);
                    }
                }
                LocalVariableSymbol local = _semanticChecker.GetGlobalSymbolFactory().CreateLocalVar(_semanticChecker.GetNameManager().Add("p" + i), pScope, type);
                local.fUsedInAnonMeth = true;

                dictionary.Add(i++, local);
                isFirstParamOfCallOrInvoke = false;
            }
        }
Exemplo n.º 4
0
        /////////////////////////////////////////////////////////////////////////////////

        private Expression CreateExpressionTreeFromResult(
            IEnumerable<Expression> parameters,
            ArgumentObject[] arguments,
            Scope pScope,
            EXPR pResult)
        {
            // (3) - Place the result in a return statement and create the EXPRBOUNDLAMBDA.
            EXPRBOUNDLAMBDA boundLambda = GenerateBoundLambda(arguments, pScope, pResult);

            // (4) - Rewrite the EXPRBOUNDLAMBDA into an expression tree.
            EXPR exprTree = ExpressionTreeRewriter.Rewrite(boundLambda, _exprFactory, SymbolLoader);

            // (5) - Create the actual Expression Tree
            Expression e = ExpressionTreeCallRewriter.Rewrite(SymbolLoader.GetTypeManager(), exprTree, parameters);
            return e;
        }
Exemplo n.º 5
0
        protected Symbol newBasicSym(
            SYMKIND kind,
            Name name,
            ParentSymbol parent)
        {
            // The parser creates names with PN_MISSING when attempting to recover from errors
            // To prevent spurious errors, we create SYMs with a different name (PN_MISSINGSYM)
            // so that they are never found when doing lookup.
            if (name == m_pMissingNameNode)
            {
                name = m_pMissingNameSym;
            }

            Symbol sym;
            switch (kind)
            {
                case SYMKIND.SK_NamespaceSymbol:
                    sym = new NamespaceSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_NamespaceDeclaration:
                    sym = new NamespaceDeclaration();
                    sym.name = name;
                    break;
                case SYMKIND.SK_AssemblyQualifiedNamespaceSymbol:
                    sym = new AssemblyQualifiedNamespaceSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_AggregateSymbol:
                    sym = new AggregateSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_AggregateDeclaration:
                    sym = new AggregateDeclaration();
                    sym.name = name;
                    break;
                case SYMKIND.SK_TypeParameterSymbol:
                    sym = new TypeParameterSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_FieldSymbol:
                    sym = new FieldSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_LocalVariableSymbol:
                    sym = new LocalVariableSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_MethodSymbol:
                    sym = new MethodSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_PropertySymbol:
                    sym = new PropertySymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_EventSymbol:
                    sym = new EventSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_TransparentIdentifierMemberSymbol:
                    sym = new TransparentIdentifierMemberSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_Scope:
                    sym = new Scope();
                    sym.name = name;
                    break;
                case SYMKIND.SK_LabelSymbol:
                    sym = new LabelSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_GlobalAttributeDeclaration:
                    sym = new GlobalAttributeDeclaration();
                    sym.name = name;
                    break;
                case SYMKIND.SK_UnresolvedAggregateSymbol:
                    sym = new UnresolvedAggregateSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_InterfaceImplementationMethodSymbol:
                    sym = new InterfaceImplementationMethodSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_IndexerSymbol:
                    sym = new IndexerSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_ParentSymbol:
                    sym = new ParentSymbol();
                    sym.name = name;
                    break;
                case SYMKIND.SK_IteratorFinallyMethodSymbol:
                    sym = new IteratorFinallyMethodSymbol();
                    sym.name = name;
                    break;
                default:
                    throw Error.InternalCompilerError();
            }

            sym.setKind(kind);

            if (parent != null)
            {
                // Set the parent element of the child symbol.
                parent.AddToChildList(sym);
                m_pSymTable.InsertChild(parent, sym);
            }

            return (sym);
        }
Exemplo n.º 6
0
 public EXPRWRAP CreateWrapNoAutoFree(Scope pCurrentScope, EXPR pOptionalWrap)
 {
     EXPRWRAP rval = CreateWrap(pCurrentScope, pOptionalWrap);
     return rval;
 }
Exemplo n.º 7
0
        public EXPRWRAP CreateWrap(
            Scope pCurrentScope,
            EXPR pOptionalExpression
        )
        {
            EXPRWRAP rval = new EXPRWRAP();
            rval.kind = ExpressionKind.EK_WRAP;
            rval.type = null;
            rval.flags = 0;
            rval.SetOptionalExpression(pOptionalExpression);
            if (pOptionalExpression != null)
            {
                rval.setType(pOptionalExpression.type);
            }
            rval.flags |= EXPRFLAG.EXF_LVALUE;

            Debug.Assert(rval != null);
            return (rval);
        }
Exemplo n.º 8
0
 public EXPRBLOCK CreateBlock(EXPRBLOCK pOptionalCurrentBlock, EXPRSTMT pOptionalStatements, Scope pOptionalScope)
 {
     EXPRBLOCK rval = new EXPRBLOCK();
     rval.kind = ExpressionKind.EK_BLOCK;
     rval.type = null;
     rval.flags = 0;
     rval.SetOptionalStatements(pOptionalStatements);
     rval.OptionalScopeSymbol = pOptionalScope;
     Debug.Assert(rval != null);
     return (rval);
 }
Exemplo n.º 9
0
 public EXPRRETURN CreateReturn(EXPRFLAG nFlags, Scope pCurrentScope, EXPR pOptionalObject, EXPR pOptionalOriginalObject)
 {
     Debug.Assert(0 == (nFlags &
                ~(EXPRFLAG.EXF_ASLEAVE | EXPRFLAG.EXF_FINALLYBLOCKED | EXPRFLAG.EXF_RETURNISYIELD |
                   EXPRFLAG.EXF_ASFINALLYLEAVE | EXPRFLAG.EXF_GENERATEDSTMT | EXPRFLAG.EXF_MARKING |
                   EXPRFLAG.EXF_MASK_ANY
                 )
               ));
     EXPRRETURN rval = new EXPRRETURN();
     rval.kind = ExpressionKind.EK_RETURN;
     rval.type = null;
     rval.flags = nFlags;
     rval.SetOptionalObject(pOptionalObject);
     Debug.Assert(rval != null);
     return (rval);
 }
Exemplo n.º 10
0
 public EXPRRETURN CreateReturn(EXPRFLAG nFlags, Scope pCurrentScope, EXPR pOptionalObject)
 {
     return CreateReturn(nFlags, pCurrentScope, pOptionalObject, pOptionalObject);
 }
Exemplo n.º 11
0
        private Scope _argumentScope;            // The scope containing the names of the parameters
        // The scope that will hold this anonymous function. This starts off as the outer scope and is then
        // ratcheted down to the correct scope after the containing method is fully bound.

        public void Initialize(Scope argScope)
        {
            Debug.Assert(argScope != null);
            _argumentScope = argScope;
        }
Exemplo n.º 12
0
        protected Symbol newBasicSym(
            SYMKIND kind,
            Name name,
            ParentSymbol parent)
        {
            // The parser creates names with PN_MISSING when attempting to recover from errors
            // To prevent spurious errors, we create SYMs with a different name (PN_MISSINGSYM)
            // so that they are never found when doing lookup.
            if (name == m_pMissingNameNode)
            {
                name = m_pMissingNameSym;
            }

            Symbol sym;

            switch (kind)
            {
            case SYMKIND.SK_NamespaceSymbol:
                sym      = new NamespaceSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_NamespaceDeclaration:
                sym      = new NamespaceDeclaration();
                sym.name = name;
                break;

            case SYMKIND.SK_AssemblyQualifiedNamespaceSymbol:
                sym      = new AssemblyQualifiedNamespaceSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_AggregateSymbol:
                sym      = new AggregateSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_AggregateDeclaration:
                sym      = new AggregateDeclaration();
                sym.name = name;
                break;

            case SYMKIND.SK_TypeParameterSymbol:
                sym      = new TypeParameterSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_FieldSymbol:
                sym      = new FieldSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_LocalVariableSymbol:
                sym      = new LocalVariableSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_MethodSymbol:
                sym      = new MethodSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_PropertySymbol:
                sym      = new PropertySymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_EventSymbol:
                sym      = new EventSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_TransparentIdentifierMemberSymbol:
                sym      = new TransparentIdentifierMemberSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_Scope:
                sym      = new Scope();
                sym.name = name;
                break;

            case SYMKIND.SK_LabelSymbol:
                sym      = new LabelSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_GlobalAttributeDeclaration:
                sym      = new GlobalAttributeDeclaration();
                sym.name = name;
                break;

            case SYMKIND.SK_UnresolvedAggregateSymbol:
                sym      = new UnresolvedAggregateSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_InterfaceImplementationMethodSymbol:
                sym      = new InterfaceImplementationMethodSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_IndexerSymbol:
                sym      = new IndexerSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_ParentSymbol:
                sym      = new ParentSymbol();
                sym.name = name;
                break;

            case SYMKIND.SK_IteratorFinallyMethodSymbol:
                sym      = new IteratorFinallyMethodSymbol();
                sym.name = name;
                break;

            default:
                throw Error.InternalCompilerError();
            }

            sym.setKind(kind);

            if (parent != null)
            {
                // Set the parent element of the child symbol.
                parent.AddToChildList(sym);
                m_pSymTable.InsertChild(parent, sym);
            }

            return(sym);
        }