Ejemplo n.º 1
0
        protected override void VisitInstanceDefinition(InstanceDefinitionNode instanceDefinitionNode)
        {
            string         instanceName   = instanceDefinitionNode.NameNode.Value;
            InstanceSymbol instanceSymbol = new InstanceSymbol(instanceName, instanceDefinitionNode);

            AddSymbol(instanceSymbol);
            Visit(instanceDefinitionNode.BodyNodes);
        }
        public AssemblyBuildingVisitor(Dictionary <string, Symbol> symbolTable)
        {
            _symbolTable  = symbolTable;
            _labelManager = new LabelManager();


            _nestedAttributesFound = false;
            _helperInstance        = new InstanceSymbol(HELPER_INSTANCE, null);
            if (_symbolTable.Count > 0)
            {
                _helperInstance.Index = _symbolTable.Values.Last().Index + 1;
            }
        }
Ejemplo n.º 3
0
        protected override void VisitInstanceDefinition(InstanceDefinitionNode node)
        {
            InstanceSymbol symbol = (InstanceSymbol)node.Symbol;

            if (symbol?.InheritanceParentSymbol?.Node != null)
            {
                Visit(symbol.InheritanceParentSymbol.Node);
            }

            _initializedAttributesPaths            = new HashSet <string>();
            _initializedLocalsPaths                = new HashSet <string>();
            _node2InitializedAttributesPaths[node] = _initializedAttributesPaths;

            _currentBlockSymbol = symbol;
            base.VisitInstanceDefinition(node);
            _currentBlockSymbol = null;
        }
Ejemplo n.º 4
0
        public override void Analy(AnalyStmtContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyStmtContext.Symbols;

            RightValueExp.IsAssignedValue = true;
            LeftToExp.IsAssignedBy        = true;
            RightValueExp = AnalyExp(RightValueExp);
            LeftToExp     = AnalyExp(LeftToExp);

            if (LeftToExp == null || !LeftToExp.TrueAnalyed || RightValueExp == null || !RightValueExp.TrueAnalyed)
            {
                TrueAnalyed = false;
                return;
            }
            else
            {
                RightValueExp.RequireType = LeftToExp.RetType;
            }

            if (LeftToExp is VarExp)
            {
                var        identExpr = LeftToExp as VarExp;
                string     idname    = identExpr.VarName;
                SymbolInfo symbol    = identExpr.VarSymbol;
                if (symbol != null)
                {
                    if (symbol is InstanceSymbol)
                    {
                        InstanceSymbol varSymbol = (symbol as InstanceSymbol);
                        if (varSymbol.DimType == null)
                        {
                            varSymbol.DimType    = RightValueExp.RetType;
                            varSymbol.IsAssigned = true;
                        }
                    }
                }
                else
                {
                    throw new CompileException(idname + "没有分析出正确类型");
                }
            }
            if (!(LeftToExp is IGenerateSet))
            {
                error("不能赋值");
            }
            else
            {
                var gs = (LeftToExp as IGenerateSet);
                if (gs.CanWrite == false)
                {
                    errorf("'{0}'是只读的,不能赋值", gs.ToString());
                }
            }

            if (TKTLambda.IsFn(LeftToExp.RetType))// (!isFn())
            {
                analyArgLanmbda(_AnalyExpContext);
            }
            else
            {
                if (RightValueExp.RetType != null && LeftToExp.RetType != null)
                {
                    if (!ReflectionUtil.IsExtends(RightValueExp.RetType, LeftToExp.RetType))
                    {
                        error(LeftToExp.Postion, "左右赋值类型不匹配,不能赋值");
                    }
                }
            }

            if (LeftToExp is EveryOneExp)
            {
                isEveryOneAssign   = true;
                everyOneAssignStmt = new EveryOneAssignStmt(this);
                everyOneAssignStmt.Analy(context);
            }
        }