Exemple #1
0
 public override object VisitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
 {
     CoolParser.ClassdefContext p = (CoolParser.ClassdefContext)(context.Parent);
     dotcode += p.t.Text + "->" + context.id.Text + "\n";
     dotcode += context.id.Text + "[label=\"" + context.id.Text + ":" + context.t.Text + "\nattribute\"]\n";
     return(VisitChildren(context));
 }
Exemple #2
0
        //private string v;
        //private ObjClass Type;

        //private Node s;

        public AttributeNode(CoolParser.AttribFeatureContext context, Node s) : base(s.Childs)
        {
            CoolParser.ClassdefContext p = (CoolParser.ClassdefContext)context.Parent;
            var classname = p.t.Text;
            var type      = "Object";

            if (context.t.Text != null)// if I have a type
            {
                type = context.t.Text;
            }
            var name = context.id.Text;

            this.SetType(SymbolTable.Classes[type]);
            //Atribute c;
            //if (SymbolTable.Classes.ContainsKey(type) && !(SymbolTable.Classes[classname].Attributes.ContainsKey(name)))// if you know my type and not myself
            {
                this.Name = name;
                //c = new Atribute(name, SymbolTable.Classes[type])
                {
                    this.Expression = context.expresion();
                    this.Self       = context;
                }//;
                SymbolTable.Classes[classname].Attributes.Add(Name, this);//let me introduce myself
            }
            this.context = context;
            //this.s = s;
        }
Exemple #3
0
        //public override object VisitFormal([NotNull] CoolParser.FormalContext context)
        //{
        //    return VisitChildren(context);
        //}

        //public override object
        private void VisitExpr(CoolParser.ExpresionContext context)
        {
            try
            {
                CoolParser.MethodFeatureContext p = (CoolParser.MethodFeatureContext)context.Parent;
                dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n";
                return;
            }
            catch (Exception) { }
            try
            {
                CoolParser.AttribFeatureContext p = (CoolParser.AttribFeatureContext)context.Parent;
                dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n";
                return;
            }
            catch (Exception) { }
            try
            {
                CoolParser.ExpresionContext p = (CoolParser.ExpresionContext)context.Parent;
                dotcode += p.GetType().Name.Substring(0, p.GetType().Name.Length - 7) + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n";
                return;
            }
            catch (Exception) { }

            //switch (context.Parent)
            //{
            //    case CoolParser.MethodFeatureContext p:
            //        dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n";
            //        break;
            //    case CoolParser.AttribFeatureContext p:
            //        dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n";
            //        break;
            //    case CoolParser.ExpresionContext p:
            //        dotcode += p.GetType().Name.Substring(0, p.GetType().Name.Length - 7) + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n";
            //        break;
            //    default:
            //        break;
            //}
            ////return VisitChildren(context);
        }
Exemple #4
0
        public override object VisitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
        {
            Type attribType;

            if (p.Types.ContainsKey(context.TYPE().GetText()))
            {
                attribType = p.Types[context.TYPE().GetText()];
            }
            else
            {
                attribType = new Type(context.TYPE().GetText(), null, new Coord(0, 0));
            }

            Expression attribExp = null;

            if (context.expresion() != null)
            {
                attribExp = (Expression)Visit(context.expresion());
            }

            return(new Attribute(context.ID().GetText(), attribType, attribExp, GetCoord(context)));
        }
Exemple #5
0
        public override Node VisitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
        {
            //CoolParser.ClassdefContext p = (CoolParser.ClassdefContext)context.Parent;
            //var classname = p.t.Text;
            //var type = "Object";
            //if (context.t.Text != null)// if I have a type
            //    type = context.t.Text;
            //var name = context.id.Text;
            //Atribute c;
            //if (SymbolTable.Classes.ContainsKey(type) && !(SymbolTable.Classes[classname].Attributes.ContainsKey(name)))// if you know my type and not myself
            //{
            //    c = new Atribute(name, SymbolTable.Classes[type])
            //    {
            //        Expression = context.expresion(),
            //        Self = context
            //    };
            //    SymbolTable.Classes[classname].Attributes.Add(c.Name, c);//let me introduce myself
            //}

            var s = VisitChildren(context);

            return(new AttributeNode(context, s));
        }
Exemple #6
0
        public override Node VisitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
        {
            var s = VisitChildren(context);

            return(new AttributeNode(context, s));
        }
Exemple #7
0
 /// <summary>
 /// Exit a parse tree produced by the <c>attribFeature</c>
 /// labeled alternative in <see cref="CoolParser.feature"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by the <c>attribFeature</c>
 /// labeled alternative in <see cref="CoolParser.feature"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
 {
     return(VisitChildren(context));
 }
Exemple #9
0
 public override bool VisitAttribFeature([NotNull] CoolParser.AttribFeatureContext context)
 {
     return(VisitChildren(context));
 }