public VariableDescription(AFieldDecl fieldDecl) { Name = fieldDecl.GetName().Text; Type = Util.TypeToString(fieldDecl.GetType()); PlacementPrefix = "Field"; VariableType = VariableTypes.Field; Const = fieldDecl.GetConst() != null; IsStatic = fieldDecl.GetStatic() != null; Visibility = fieldDecl.GetVisibilityModifier(); realType = (PType)fieldDecl.GetType().Clone(); init = fieldDecl.GetInit(); Line = fieldDecl.GetName().Line; Position = TextPoint.FromCompilerCoords(fieldDecl.GetName()); }
public override void CaseAFieldDecl(AFieldDecl node) { if (node.GetConst() == null) return; initialFieldDecl = node; if (IsConstant(node.GetInit())) { List<AFieldLvalue> lvalues = new List<AFieldLvalue>(); lvalues.AddRange(data.FieldLinks.Where(link => link.Value == node).Select(link => link.Key)); foreach (AFieldLvalue lvalue in lvalues) { PExp parent = (PExp)lvalue.Parent(); parent.ReplaceBy(Util.MakeClone(node.GetInit(), data)); } node.Parent().RemoveChild(node); } initialFieldDecl = null; }
public override void CaseAFieldDecl(AFieldDecl node) { InAFieldDecl(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.GetStatic() != null) { node.GetStatic().Apply(this); } if (node.GetVisibilityModifier() != null) { node.GetVisibilityModifier().Apply(this); } OutAFieldDecl(node); }
public override void OutAFieldDecl(AFieldDecl node) { bool isAConstStringVar = data.ObfuscationFields.Contains(node);/* data.ObfuscatedStrings.Values.Any(stringField => stringField == node) || data.UnobfuscatedStrings.Values.Any(stringField => stringField == node);*/ if (!isAConstStringVar && node.GetConst() != null && node.GetInit() == null) errors.Add(new ErrorCollection.Error(node.GetConst(), currentSourceFile, LocRM.GetString("ErrorText183"), false)); //If it's protected, it must be in a struct if (!Util.HasAncestor<AStructDecl>(node)) { if (node.GetVisibilityModifier() is AProtectedVisibilityModifier) errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText184"))); } base.OutAFieldDecl(node); }
public override void OutAFieldDecl(AFieldDecl node) { if (node.GetInit() != null) { PType from = data.ExpTypes[node.GetInit()]; PType to = node.GetType(); if (!Assignable(from, to)) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText151") + Util.TypeToString(from) + LocRM.GetString("ErrorText152") + Util.TypeToString(to))); } } //If the return type or the type of any formals is a private struct, and the method is a public context, give an error { //Is public context if (node.GetVisibilityModifier() is APublicVisibilityModifier) { PType type = node.GetType(); FindPrivateTypes finder = new FindPrivateTypes(data); type.Apply(finder); if (finder.PrivateTypes.Count > 0) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); List<PDecl> usedDecls = new List<PDecl>(); foreach (ANamedType namedType in finder.PrivateTypes) { if (data.StructTypeLinks.ContainsKey(namedType)) { AStructDecl decl = data.StructTypeLinks[namedType]; if (usedDecls.Contains(decl)) continue; usedDecls.Add(decl); subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText64"))); } else if (data.DelegateTypeLinks.ContainsKey(namedType)) { AMethodDecl decl = data.DelegateTypeLinks[namedType]; if (usedDecls.Contains(decl)) continue; usedDecls.Add(decl); subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText154"))); } } errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText155"), false, subErrors.ToArray())); } } } base.OutAFieldDecl(node); }
public override void CaseAFieldDecl(AFieldDecl node) { //Check that it is const if (node.GetConst() != null && !data.ObfuscationFields.Contains(node)) { if (node.GetInit() == null) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText112"))); return; } ConstChecker checker = new ConstChecker(data); node.GetInit().Apply(checker); if (!checker.IsConst) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText113"))); return; } } base.CaseAFieldDecl(node); }
public override void CaseAFieldDecl(AFieldDecl node) { if (node.GetStatic() != null) Write("static "); if (node.GetConst() != null) Write("const "); node.GetType().Apply(this); Write(" " + node.GetName().Text); if (node.GetInit() != null) { Write(" = "); node.GetInit().Apply(this); } Write(";\n\n"); }
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); }
public override void OutAFieldDecl(AFieldDecl node) { if (node.GetInit() != null) return; //Field - init in main entry AABlock pBlock = (AABlock) finalTrans.mainEntryFieldInitBlock.GetBlock(); int insertIndex = 0; AFieldLvalue lvalue = new AFieldLvalue(new TIdentifier(node.GetName().Text)); data.FieldLinks[lvalue] = node; data.LvalueTypes[lvalue] = node.GetType(); AABlock block = new AABlock(new ArrayList(), new TRBrace("}")); MakeAssignments(block, node.GetType(), lvalue, true); if (block.GetStatements().Count != 0) pBlock.GetStatements().Insert(insertIndex, new ABlockStm(new TLBrace("{"), block)); }
public override void CaseAFieldDecl(AFieldDecl node) { PType type = node.GetType(); if (node.GetInit() is ANullExp) { if (type is APointerType) { bool add = true; foreach (PType pType in TypesWithIdentifierArray) { if (Util.TypesEqual(((APointerType)type).GetType(), pType, data)) { add = false; break; } } if (add) TypesWithIdentifierArray.Add(((APointerType)type).GetType()); } } base.CaseAFieldDecl(node); }
public override void CaseAFieldDecl(AFieldDecl node) { PType type = node.GetType(); if (node.GetInit() is ANullExp && type is APointerType && Util.IsIntPointer(node, ((APointerType)type).GetType(), data)) { AIntConstExp replacer = new AIntConstExp(new TIntegerLiteral("0")); data.ExpTypes[replacer] = new ANamedType(new TIdentifier("int"), null); node.GetInit().ReplaceBy(replacer); } base.CaseAFieldDecl(node); }
//Removed check on top, and get type public static GlobalStructVars CreatePointerFields(Node node, TIntegerLiteral literal, string prefix, PType type, SharedData data, bool createArray = true) { AASourceFile file = Util.GetAncestor<AASourceFile>(node); AFieldDecl array = new AFieldDecl(new APublicVisibilityModifier(), null, null, new AArrayTempType(new TLBracket("["), type, new AIntConstExp( new TIntegerLiteral(literal.Text)), new TIntegerLiteral(literal.Text)), new TIdentifier(prefix + "_array", data.LineCounts[file] + 20, 0), null); int length = (int)Math.Ceiling(float.Parse(literal.Text) / 31); AFieldDecl used = new AFieldDecl(new APublicVisibilityModifier(), null, null, new AArrayTempType(new TLBracket("["), new ANamedType(new TIdentifier("int"), null), new AIntConstExp( new TIntegerLiteral(length.ToString())), new TIntegerLiteral(length.ToString())), new TIdentifier(prefix + "_used", data.LineCounts[file] + 20, 0), null); AFieldDecl index = new AFieldDecl(new APublicVisibilityModifier(), null, null, new ANamedType(new TIdentifier("int"), null), new TIdentifier(prefix + "_index", data.LineCounts[file] + 20, 0), null); bool addIdentiferArray = false; foreach (PType t in intPointersWithCmp) { if (Util.TypesEqual(type, t, data)) { addIdentiferArray = true; break; } } AFieldDecl identiferCount = null; AFieldDecl identiferArray = null; if (addIdentiferArray) { identiferArray = new AFieldDecl(new APublicVisibilityModifier(), null, null, new AArrayTempType(new TLBracket("["), new ANamedType(new TIdentifier("int"), null), new AIntConstExp( new TIntegerLiteral(literal.Text)), new TIntegerLiteral(literal.Text)), new TIdentifier(prefix + "_identifierArray", data.LineCounts[file] + 20, 0), null); identiferCount = new AFieldDecl(new APublicVisibilityModifier(), null, null, new ANamedType(new TIdentifier("int"), null), new TIdentifier(prefix + "_identiferNext", data.LineCounts[file] + 20, 0), new AIntConstExp(new TIntegerLiteral("1"))); file.GetDecl().Add(identiferArray); file.GetDecl().Add(identiferCount); data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, identiferArray)); data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, identiferCount)); data.ExpTypes[((AArrayTempType)identiferArray.GetType()).GetDimention()] = data.ExpTypes[identiferCount.GetInit()] = new ANamedType(new TIdentifier("int"), null); } if (createArray) file.GetDecl().Add(array); file.GetDecl().Add(used); file.GetDecl().Add(index); data.ExpTypes[((AArrayTempType)array.GetType()).GetDimention()] = data.ExpTypes[((AArrayTempType)used.GetType()).GetDimention()] = new ANamedType(new TIdentifier("int"), null); if (createArray) data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, array)); data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, used)); data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, index)); return new GlobalStructVars(createArray ? array : null, used, index, identiferArray, identiferCount); }