public VariableDescription(AALocalDecl localDecl, VariableTypes type) { Name = localDecl.GetName().Text; Type = Util.TypeToString(localDecl.GetType()); switch (type) { case VariableTypes.LocalVariable: PlacementPrefix = "Local"; break; case VariableTypes.Parameter: PlacementPrefix = "Parameter"; break; case VariableTypes.StructVariable: PlacementPrefix = "Struct field"; break; default: PlacementPrefix = ""; break; } VariableType = type; Const = localDecl.GetConst() != null; IsStatic = localDecl.GetStatic() != null; Visibility = localDecl.GetVisibilityModifier(); realType = (PType) localDecl.GetType().Clone(); init = localDecl.GetInit(); Line = localDecl.GetName().Line; Position = TextPoint.FromCompilerCoords(localDecl.GetName()); }
public override void CaseAALocalDecl(AALocalDecl node) { InAALocalDecl(node); if (node.GetInit() != null) { node.GetInit().Apply(this); } if (node.GetName() != null) { node.GetName().Apply(this); } if (node.GetType() != null) { node.GetType().Apply(this); } if (node.GetConst() != null) { node.GetConst().Apply(this); } if (node.GetOut() != null) { node.GetOut().Apply(this); } if (node.GetRef() != null) { node.GetRef().Apply(this); } if (node.GetStatic() != null) { node.GetStatic().Apply(this); } if (node.GetVisibilityModifier() != null) { node.GetVisibilityModifier().Apply(this); } OutAALocalDecl(node); }
public override void CaseAALocalDecl(AALocalDecl node) { //Convert a static struct field into a global variable. All refferences to it are structFieldLvalues. if (node.GetStatic() == null) return; AStructDecl str = (AStructDecl) node.Parent(); if (data.StructFields[str].Contains(node)) data.StructFields[str].Remove(node); AFieldDecl replacementField; //Don't enhrit static fields. if (data.EnheritanceLocalMap.ContainsKey(node)) { str.RemoveChild(node); AALocalDecl realVar = data.EnheritanceLocalMap[node]; if (convertionMap.ContainsKey(realVar)) { //Already converted to a field replacementField = convertionMap[realVar]; foreach (AStructFieldLvalue lvalue in data.StructMethodFieldLinks.Where(link => link.Value == node).Select(link => link.Key)) { AFieldLvalue newLvalue = new AFieldLvalue(new TIdentifier(replacementField.GetName().Text)); data.FieldLinks[newLvalue] = replacementField; data.LvalueTypes[newLvalue] = replacementField.GetType(); lvalue.ReplaceBy(newLvalue); } } else { List<AStructFieldLvalue> refferences = new List<AStructFieldLvalue>(); refferences.AddRange(data.StructMethodFieldLinks.Where(link => link.Value == node).Select(link => link.Key)); foreach (AStructFieldLvalue lvalue in refferences) { data.StructMethodFieldLinks[lvalue] = realVar; } } return; } replacementField = new AFieldDecl(new APublicVisibilityModifier(), null, node.GetConst(), node.GetType(), node.GetName(), node.GetInit()); replacementField.GetName().Text = str.GetName().Text + "_" + replacementField.GetName().Text; AASourceFile file = Util.GetAncestor<AASourceFile>(node); file.GetDecl().Insert(file.GetDecl().IndexOf(node.Parent()), replacementField); data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, replacementField)); if (ContainsNewExp(replacementField.GetInit())) data.FieldsToInitInMapInit.Add(replacementField); foreach (AStructFieldLvalue lvalue in data.StructMethodFieldLinks.Where(link => link.Value == node).Select(link => link.Key)) { AFieldLvalue newLvalue = new AFieldLvalue(new TIdentifier(replacementField.GetName().Text)); data.FieldLinks[newLvalue] = replacementField; data.LvalueTypes[newLvalue] = replacementField.GetType(); lvalue.ReplaceBy(newLvalue); } convertionMap.Add(node, replacementField); node.Parent().RemoveChild(node); }