Ejemplo n.º 1
0
 public void AddChildScope(SymbolScope scope)
 {
     if (_childScopes == null) {
         _childScopes = new List<SymbolScope>();
     }
     _childScopes.Add(scope);
 }
Ejemplo n.º 2
0
        private void TransformScope(SymbolScope scope, List <Symbol> transformedSymbols)
        {
            foreach (Symbol symbol in ((ISymbolTable)scope).Symbols)
            {
                if (symbol.Type != SymbolType.Variable)
                {
                    continue;
                }

                bool   dummy;
                string transformedName = _transformer.TransformSymbol(symbol, out dummy);
                if (transformedName != null)
                {
                    symbol.SetTransformedName(transformedName);
                    transformedSymbols.Add(symbol);
                }
            }

            if (scope.ChildScopes != null)
            {
                foreach (SymbolScope childScope in scope.ChildScopes)
                {
                    TransformScope(childScope, transformedSymbols);
                }
            }
        }
 public void AddChildScope(SymbolScope scope)
 {
     if (_childScopes == null)
     {
         _childScopes = new List <SymbolScope>();
     }
     _childScopes.Add(scope);
 }
        public ICollection <Symbol> TransformSymbolImplementation(SymbolImplementation implementation)
        {
            List <Symbol> transformedSymbols = new List <Symbol>();

            SymbolScope scope = implementation.Scope;

            TransformScope(scope, transformedSymbols);

            return(transformedSymbols);
        }
Ejemplo n.º 5
0
        private SymbolImplementation BuildImplementation(ISymbolTable symbolTable, CodeMemberSymbol symbolContext, BlockStatementNode implementationNode, bool addAllParameters) {
            _rootScope = new SymbolScope(symbolTable);
            _currentScope = _rootScope;

            List<Statement> statements = new List<Statement>();
            StatementBuilder statementBuilder = new StatementBuilder(this, symbolContext, _errorHandler, _options);

            if (symbolContext.Parameters != null) {
                int parameterCount = symbolContext.Parameters.Count;
                if (addAllParameters == false) {
                    // For property getters (including indexers), we don't add the last parameter,
                    // which happens to be the "value" parameter, which only makes sense
                    // for the setter.

                    parameterCount--;
                }
                for (int paramIndex = 0; paramIndex < parameterCount; paramIndex++) {
                    _currentScope.AddSymbol(symbolContext.Parameters[paramIndex]);
                }
            }

            if ((symbolContext.Type == SymbolType.Constructor) &&
                ((((ConstructorSymbol)symbolContext).Visibility & MemberVisibility.Static) == 0)) {
                Debug.Assert(symbolContext.Parent is ClassSymbol);
                if (((ClassSymbol)symbolContext.Parent).BaseClass != null) {
                    BaseInitializerExpression baseExpr = new BaseInitializerExpression();

                    ConstructorDeclarationNode ctorNode = (ConstructorDeclarationNode)symbolContext.ParseContext;
                    if (ctorNode.BaseArguments != null) {
                        ExpressionBuilder expressionBuilder =
                            new ExpressionBuilder(this, symbolContext, _errorHandler, _options);

                        Debug.Assert(ctorNode.BaseArguments is ExpressionListNode);
                        ICollection<Expression> args =
                            expressionBuilder.BuildExpressionList((ExpressionListNode)ctorNode.BaseArguments);

                        foreach (Expression paramExpr in args) {
                            baseExpr.AddParameterValue(paramExpr);
                        }
                    }

                    statements.Add(new ExpressionStatement(baseExpr));
                }
            }

            foreach (StatementNode statementNode in implementationNode.Statements) {
                Statement statement = statementBuilder.BuildStatement(statementNode);
                if (statement != null) {
                    statements.Add(statement);
                }
            }

            return new SymbolImplementation(statements, _rootScope);
        }
        private void TransformScope(SymbolScope scope, List<Symbol> transformedSymbols) {
            foreach (Symbol symbol in ((ISymbolTable)scope).Symbols) {
                if (symbol.Type != SymbolType.Variable) {
                    continue;
                }

                bool dummy;
                string transformedName = _transformer.TransformSymbol(symbol, out dummy);
                if (transformedName != null) {
                    symbol.SetTransformedName(transformedName);
                    transformedSymbols.Add(symbol);
                }
            }

            if (scope.ChildScopes != null) {
                foreach (SymbolScope childScope in scope.ChildScopes) {
                    TransformScope(childScope, transformedSymbols);
                }
            }
        }
Ejemplo n.º 7
0
        public SymbolImplementation BuildField(FieldSymbol fieldSymbol)
        {
            _rootScope = new SymbolScope((ISymbolTable)fieldSymbol.Parent);
            _currentScope = _rootScope;

            Expression initializerExpression;

            FieldDeclarationNode fieldDeclarationNode = (FieldDeclarationNode)fieldSymbol.ParseContext;
            Debug.Assert(fieldDeclarationNode != null);

            VariableInitializerNode initializerNode = (VariableInitializerNode)fieldDeclarationNode.Initializers[0];
            if (initializerNode.Value != null) {
                ExpressionBuilder expressionBuilder = new ExpressionBuilder(this, fieldSymbol, _errorHandler, _options);
                initializerExpression = expressionBuilder.BuildExpression(initializerNode.Value);
                if (initializerExpression is MemberExpression) {
                    initializerExpression =
                        expressionBuilder.TransformMemberExpression((MemberExpression)initializerExpression);
                }
            }
            else {
                object defaultValue = null;

                TypeSymbol fieldType = fieldSymbol.AssociatedType;
                SymbolSet symbolSet = fieldSymbol.SymbolSet;

                if (fieldType.Type == SymbolType.Enumeration) {
                    // The default for named values is null, so this only applies to
                    // regular enum types

                    EnumerationSymbol enumType = (EnumerationSymbol)fieldType;
                    if (enumType.UseNamedValues == false) {
                        defaultValue = 0;
                    }
                }
                else if ((fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Integer)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.UnsignedInteger)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Long)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.UnsignedLong)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Short)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.UnsignedShort)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Byte)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.SignedByte)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Double)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Single)) ||
                    (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Decimal))) {
                    defaultValue = 0;
                }
                else if (fieldType == symbolSet.ResolveIntrinsicType(IntrinsicType.Boolean)) {
                    defaultValue = false;
                }

                initializerExpression =
                    new LiteralExpression(symbolSet.ResolveIntrinsicType(IntrinsicType.Object),
                                          defaultValue);
            }

            List<Statement> statements = new List<Statement>();
            statements.Add(new ExpressionStatement(initializerExpression, /* isFragment */ true));

            return new SymbolImplementation(statements, null);
        }
Ejemplo n.º 8
0
        void ILocalSymbolTable.PushScope()
        {
            Debug.Assert(_currentScope != null);

            SymbolScope parentScope = _currentScope;

            _currentScope = new SymbolScope(parentScope);
            parentScope.AddChildScope(_currentScope);
        }
Ejemplo n.º 9
0
 void ILocalSymbolTable.PopScope()
 {
     Debug.Assert(_currentScope != null);
     _currentScope = _currentScope.Parent;
 }
Ejemplo n.º 10
0
 public SymbolImplementation(ICollection <Statement> statements, SymbolScope scope)
 {
     _scope      = scope;
     _statements = statements;
 }
Ejemplo n.º 11
0
 public SymbolImplementation(ICollection<Statement> statements, SymbolScope scope) {
     _scope = scope;
     _statements = statements;
 }
Ejemplo n.º 12
0
 public SymbolImplementation(ICollection<Statement> statements, SymbolScope scope, string thisIdentifier)
 {
     _scope = scope;
     _statements = statements;
     _thisIdentifier = thisIdentifier;
 }
 public SymbolScope(SymbolScope parentScope)
     : this((ISymbolTable)parentScope)
 {
     _parentScope = parentScope;
 }
Ejemplo n.º 14
0
 public SymbolImplementation(ICollection <Statement> statements, SymbolScope scope, string thisIdentifier)
 {
     _scope          = scope;
     _statements     = statements;
     _thisIdentifier = thisIdentifier;
 }
Ejemplo n.º 15
0
 public SymbolScope(SymbolScope parentScope)
     : this((ISymbolTable)parentScope) {
     _parentScope = parentScope;
 }