示例#1
0
        void ProcDefBlock_FormalParamAdded(object sender, IProcDefBit newBit)
        {
            ProcDefBlock b    = (ProcDefBlock)sender;
            ProcDefView  v    = (ProcDefView)ViewFromBlock(b);
            DataType     type = DataType.Invalid;

            if (newBit is VarDefBlock)
            {
                VarDefBlock vb = (VarDefBlock)newBit;
                type = (vb).Type;
                int height            = ArgBitTextHeight(newBit);
                EditableVarDefView vv = new EditableVarDefView(vb,
                                                               MakeTextBitBitmap(vb.Name, height),
                                                               varb_parts,
                                                               textMetrics, textFont);
                blockViews[vb]  = vv;
                vb.TextChanged += new VarDefBlockTextChangedEvent(ProcDef_FormalParamTextChanged);
                v.AddFormalBit(vv, type);
            }
            else
            {
                ProcDefTextBit pb = (ProcDefTextBit)newBit;
                pb.TextChanged += new ProcDefTextBitTextChangedEvent(ProcDefTextBit_TextChanged);
                EditableLabelView lv = new EditableLabelView(MakeTextBitBitmap(pb.Text, ArgBitTextHeight(pb)),
                                                             (ProcDefTextBit)newBit);
                blockViews[pb] = lv;

                v.AddFormalBit(lv, DataType.Invalid);
            }
        }
示例#2
0
 void ProcDef_FormalParamTextChanged(object sender, string newText)
 {
     VarDefBlock        b = (VarDefBlock)sender;
     EditableVarDefView v = (EditableVarDefView)ViewFromBlock(b);
     int    height        = ArgBitTextHeight(b);
     Bitmap bmp           = MakeTextBitBitmap(newText, height);
 }
示例#3
0
        public void AddArg(DataType type)
        {
            string      argName = MakeArgName(type);
            VarDefBlock v       = new VarDefBlock(argName, type);

            v.ParentRelationship = new ParentRelationship(ParentRelationshipType.FormalParameter, model, model.Bits.Count);
            model.AddBit(v);
        }
示例#4
0
        private IBlockView ViewFromProcDefBlock(ProcDefBlock b)
        {
            List <IBlockView> subContent = new List <IBlockView>();
            int i = 0;
            int n = b.Bits.Count;

            BitArray trueArgs = new BitArray(n);

            DataType[] argTypes = new DataType[n];
            // slow: Repeats instanceof test twice for all bits; once for height and once to add to subContent
            int height = b.Bits.Count == 0?1: b.Bits.Max(bb => ArgBitTextHeight(bb));

            foreach (IProcDefBit bit in b.Bits)
            {
                if (bit is VarDefBlock)
                {
                    VarDefBlock        vb = (VarDefBlock)bit;
                    EditableVarDefView vv = new EditableVarDefView(vb,
                                                                   MakeTextBitBitmap(vb.Name, height),
                                                                   varb_parts,
                                                                   textMetrics, textFont);
                    blockViews[vb] = vv;
                    subContent.Add(vv);
                    trueArgs[i]     = true;
                    argTypes[i]     = vb.Type;
                    vb.TextChanged += new VarDefBlockTextChangedEvent(ProcDef_FormalParamTextChanged);
                }
                else
                {
                    ProcDefTextBit    ptb = (ProcDefTextBit)bit;
                    EditableLabelView ev  = new EditableLabelView(
                        MakeTextBitBitmap(ptb.Text, height),
                        ptb);
                    blockViews[ptb] = ev;
                    subContent.Add(ev);
                    argTypes[i]      = DataType.Invalid;
                    trueArgs[i]      = false;
                    ptb.TextChanged += new ProcDefTextBitTextChangedEvent(ProcDefTextBit_TextChanged);
                }
                ++i;
            }

            Bitmap[]    defineTextView = RenderTextBits(new string[] { "define" });
            ContentView innerContent   = new ContentView(subContent.ToArray(), argTypes, trueArgs, sb_parts);
            ContentView outerContent   = new ContentView(new IBlockView[] {
                new LabelView(defineTextView[0]),
                innerContent
            }, new DataType[] { DataType.Invalid },
                                                         new BitArray(new bool[] { false, true }), pdb_parts);

            ProcDefView pdb = new ProcDefView(b, outerContent, innerContent);

            b.FormalParamAdded   += new ProcDefBitAddedEvent(ProcDefBlock_FormalParamAdded);
            b.FormalParamRemoved += new ProcDefBitRemovedEvent(ProcDefBlock_FormalParamRemoved);
            b.FormalParamChanged += new ProcDefBitChangedEvent(ProcDefBlock_FormalParamChanged);
            return(pdb);
        }
示例#5
0
        public EditableVarDefView(VarDefBlock model, Bitmap bitmap, Nine abc, Graphics textMetrics, Font textFont)
        {
            this._model = model;
            this.Changed += delegate(object source) { };

            // todo: So much in common with TextView; consider abstracting into common implementation
            this.abc = abc;
            this.bitmap = bitmap;
            this.textMetrics = textMetrics;
            this.textFont = textFont;
        }
示例#6
0
        public EditableVarDefView(VarDefBlock model, Bitmap bitmap, Nine abc, Graphics textMetrics, Font textFont)
        {
            this._model   = model;
            this.Changed += delegate(object source) { };

            // todo: So much in common with TextView; consider abstracting into common implementation
            this.abc         = abc;
            this.bitmap      = bitmap;
            this.textMetrics = textMetrics;
            this.textFont    = textFont;
        }
示例#7
0
        internal string[] GetArgNames()
        {
            List <string> ret = new List <string>();

            foreach (IProcDefBit bit in Bits)
            {
                if (bit is VarDefBlock)
                {
                    VarDefBlock vdb = bit as VarDefBlock;
                    ret.Add(vdb.Name);
                }
            }
            return(ret.ToArray());
        }
示例#8
0
        internal DataType[] GetArgTypes()
        {
            List <DataType> ret = new List <DataType>();

            foreach (IProcDefBit bit in Bits)
            {
                if (bit is VarDefBlock)
                {
                    VarDefBlock vdb = bit as VarDefBlock;
                    ret.Add(vdb.Type);
                }
            }
            return(ret.ToArray());
        }
示例#9
0
 internal VarDefBlock GetArg(string varName)
 {
     foreach (IProcDefBit bit in Bits)
     {
         if (bit is VarDefBlock)
         {
             VarDefBlock vdb = bit as VarDefBlock;
             if (vdb.Name == varName)
             {
                 return(vdb);
             }
         }
     }
     throw new ArgumentException(string.Format("ProcDefBlock.GetArg(): Variable {0} not an argument", varName));
 }
示例#10
0
        private IBlock ToVarAccess(JToken json)
        {
            string varName = json[1].ToString();

            if (currentProcDef == null)
            {
                throw new InvalidOperationException(string.Format("Variable {0} used outside of proc definition", varName));
            }
            if (!currentProcDef.GetArgNames().Contains(varName))
            {
                throw new InvalidOperationException(string.Format("Variable {0} undefined", varName));
            }
            VarDefBlock    vdb = currentProcDef.GetArg(varName);
            VarAccessBlock b   = new VarAccessBlock(vdb);

            return(b);
        }
示例#11
0
 public void AddArg(DataType type)
 {
     string argName = MakeArgName(type);
     VarDefBlock v = new VarDefBlock(argName, type);
     v.ParentRelationship = new ParentRelationship(ParentRelationshipType.FormalParameter, model, model.Bits.Count);
     model.AddBit(v);
 }
示例#12
0
 public VarAccessBlock(VarDefBlock declaration)
 {
     this._declaration = declaration;
 }
示例#13
0
 public VarAccessBlock(VarDefBlock declaration)
 {
     this._declaration = declaration;
 }