Beispiel #1
0
 public override string ToString()
 {
     return(VarToken.GetText());
 }
Beispiel #2
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            var symbols = this.AnalyExpContext.Symbols;

            VarName = VarToken.GetText();
            if (!IsNestedField)
            {
                if (VarSymbol == null)
                {
                    VarSymbol = symbols.Get(VarName);
                }

                if (VarSymbol == null)
                {
                    //VarSymbol = symbols.Get(VarName);
                    List <SymbolEnumItem> enumValues = context.ClassContext.SearchEnumItem(VarName);
                    if (enumValues.Count == 1)
                    {
                        VarSymbol = enumValues[0];
                    }
                    if (enumValues.Count > 1)
                    {
                        errorf("'{0}'有多个相同约定值", VarName);
                        return(null);
                    }
                }

                if (VarSymbol == null)
                {
                    if (context.ClassContext.ClassSymbol.BaseGcl != null)
                    {
                        ExPropertyInfo property = context.ClassContext.ClassSymbol.BaseGcl.SearchExProperty(VarName);
                        if (property != null)
                        {
                            if (ReflectionUtil.IsPublic(property.Property) ||
                                ReflectionUtil.IsProtected(property.Property))
                            {
                                SymbolDefProperty ps = new SymbolDefProperty(VarName, property.Property.PropertyType,
                                                                             ReflectionUtil.IsStatic(property.Property));
                                ps.SetProperty(property.Property);
                                VarSymbol = ps;
                            }
                        }
                    }
                }
                if (VarSymbol == null)
                {
                    if (context.ClassContext.ClassSymbol.BaseGcl != null)
                    {
                        ExFieldInfo field = context.ClassContext.ClassSymbol.BaseGcl.SearchExField(VarName);
                        if (field != null)
                        {
                            if (field.Field.IsPublic || field.Field.IsFamily)
                            {
                                SymbolDefField fs = new SymbolDefField(VarName, field.Field.FieldType,
                                                                       field.Field.IsStatic);
                                fs.SetField(field.Field);
                                VarSymbol = fs;
                            }
                        }
                    }
                }
                if (VarSymbol == null)
                {
                    if (IsAssignedBy)
                    {
                        SymbolVar varSymbol = new SymbolVar(VarName);
                        if (!varSymbol.IsInBlock)
                        {
                            varSymbol.LoacalVarIndex = context.StmtContext.MethodContext.CreateLocalVarIndex(VarName);
                            symbols.Add(varSymbol);
                        }
                        VarSymbol = varSymbol;
                    }
                    else
                    {
                        errorf("'{0}'没有赋值", VarName);
                        return(null);
                    }
                }
                RetType = ((InstanceSymbol)VarSymbol).DimType;
            }
            else
            {
            }
            return(this);
        }