Ejemplo n.º 1
0
 /// <summary>
 /// Processes the child of the current reader position into a child of this object.
 /// </summary>
 /// <param name="reader">The XML reader</param>
 protected override void ReadXmlChild(XmlReader reader) {
     if(XmlParameterName == reader.Name) {
         Parameter = XmlSerialization.ReadChildExpression(reader) as VariableDeclaration;
     } else {
         base.ReadXmlChild(reader);
     }
 }
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="vd"></param>
        public VariableInfo(VariableDeclaration vd)
        {
            IsReturned = false;
            IsModified = false;
            AssignedFields = new HashSet<VariableDeclaration>();

            this.Variable = vd;
            if(vd.Initializer != null) {
                Initialized = true;
            }
        }
Ejemplo n.º 3
0
 //This method is used to find all the statement related the the statement "declcont".
 public void FindRelated(MethodDefinition m, VariableDeclaration declcont, List<string[]> variables)
 {
     foreach (var stat in m.GetDescendants<Statement>())
     {
         if (stat is DeclarationStatement || stat is SwitchStatement || stat is ABB.SrcML.Data.ThrowStatement || stat is ABB.SrcML.Data.ReturnStatement) continue;
         if (stat.Content == null) continue;
         IEnumerable<Expression> exps = stat.Content.GetDescendants();
         if (exps.Count<Expression>() <= 1) continue;
         var firstexp = exps.First<Expression>();
         if ((firstexp.ToString() != declcont.Name) || !(firstexp is NameUse)) continue;
         if (!(exps.ElementAt(1) is OperatorUse)) continue;
         OperatorUse opt = (OperatorUse)exps.ElementAt(1);
         string targetstring = Rebuildstring(declcont.Name, stat, variables);
         if (opt.Text == "+=") { UpdateVariable(declcont.Name, variables, GetVariableCont(declcont.Name, variables) + targetstring); }
         if (opt.Text == "=") { UpdateVariable(declcont.Name, variables, targetstring); }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Print VariableDeclaration information. (For testing purpose)
 /// </summary>
 /// <param name="vd"></param>
 /// <returns></returns>
 public static string GetVariableDeclarationInfo(VariableDeclaration vd)
 {
     string info = vd.Name + "<" + vd.VariableType + ">";
     return info;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates variable declaration objects from the given declaration element 
        /// </summary>
        /// <param name="declarationElement">The variable declaration to parse. Must belong to <see cref="VariableDeclarationElementNames"/></param>
        /// <param name="context">The parser context</param>
        /// <returns>One variable declaration object for each declaration in <paramref name="declarationElement"/></returns>
        public virtual IEnumerable<VariableDeclaration> ParseDeclarationElement(XElement declarationElement, ParserContext context) {
            if(declarationElement == null) throw new ArgumentNullException("declaration");
            if(!VariableDeclarationElementNames.Contains(declarationElement.Name)) throw new ArgumentException("XElement.Name must be in VariableDeclarationElementNames");

            XElement declElement;
            if(declarationElement.Name == SRC.Declaration || declarationElement.Name == SRC.FunctionDeclaration) {
                declElement = declarationElement;
            } else {
                declElement = declarationElement.Element(SRC.Declaration);
            }

            var typeElement = declElement.Element(SRC.Type);

            var declarationType = ParseTypeUseElement(typeElement, context);

            foreach(var nameElement in declElement.Elements(SRC.Name)) {
                var variableDeclaration = new VariableDeclaration() {
                    VariableType = declarationType,
                    Name = nameElement.Value,
                    Location = context.CreateLocation(nameElement),
                    Scope = context.CurrentScope,
                };
                yield return variableDeclaration;
            }
        }