public StructDescription(AStructDecl structDecl) { Parser parser = new Parser(structDecl); Name = parser.Name; IsEnum = Name.StartsWith("enum "); if (IsEnum) { Name = Name.Substring(5); foreach (VariableDescription field in parser.Fields) { field.PlacementPrefix = "Enum Field"; } } Fields = parser.Fields; Methods = parser.Methods; Constructors = parser.Constructors; Deconstructors = parser.Deconstructors; LineFrom = structDecl.GetName().Line; LineTo = structDecl.GetEndToken().Line; if (structDecl.GetBase() is AGenericType) BaseRef = (ANamedType) ((AGenericType) structDecl.GetBase()).GetBase(); else BaseRef = (ANamedType) structDecl.GetBase(); structDecl.RemoveChild(BaseRef); foreach (TIdentifier identifier in structDecl.GetGenericVars()) { GenericVars.Add(identifier.Text); } IsClass = structDecl.GetClassToken() != null; Visibility = (PVisibilityModifier)structDecl.GetVisibilityModifier().Clone(); Position = TextPoint.FromCompilerCoords(structDecl.GetName()); }
public override void CaseAStructDecl(AStructDecl node) { if (node.GetLocals().Count == 0) node.Parent().RemoveChild(node); else base.CaseAStructDecl(node); }
public override void InAStructDecl(AStructDecl node) { data.Structs.Add(new SharedData.DeclItem<AStructDecl>(currentSourceFile, node)); data.StructMethods.Add(node, new List<AMethodDecl>()); data.StructFields.Add(node, new List<AALocalDecl>()); data.StructConstructors.Add(node, new List<AConstructorDecl>()); data.StructProperties.Add(node, new List<APropertyDecl>()); base.InAStructDecl(node); }
public override void OutAEnumDecl(AEnumDecl node) { AStructDecl replacer = new AStructDecl(node.GetVisibilityModifier(), null, null, null, node.GetEndToken(), node.GetName(), new ArrayList(), null, new ArrayList()); TIdentifier typeIdentifier = new TIdentifier("byte"); ASwitchStm switchStm = new ASwitchStm(new TSwitch("switch"), new ALvalueExp( new AAmbiguousNameLvalue(new AAName(new ArrayList() {new TIdentifier("enum")}))), new ArrayList()); ; AMethodDecl toStringMethod = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new ANamedType(new TIdentifier("string"), null), new TIdentifier("toString"), new ArrayList() { new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(typeIdentifier, null), new TIdentifier("enum"), null) }, new AABlock( new ArrayList() { switchStm, new AValueReturnStm(new TReturn("return"), new ANullExp()) }, new TRBrace("}"))); replacer.GetLocals().Add(new ADeclLocalDecl(toStringMethod)); int intVal = 0; int min = int.MaxValue; int max = int.MinValue; List<TIdentifier> types = new List<TIdentifier>(){typeIdentifier}; Dictionary<int, List<AALocalDecl>> usedValues = new Dictionary<int, List<AALocalDecl>>(); foreach (AAEnumLocal value in node.GetValues()) { AIntConstExp intConst; if (value.GetValue() != null) { intConst = (AIntConstExp) value.GetValue(); intVal = int.Parse(intConst.GetIntegerLiteral().Text) + 1; } else { intConst = new AIntConstExp(new TIntegerLiteral(intVal.ToString(), value.GetName().Line, value.GetName().Pos)); intVal++; } min = Math.Min(intVal - 1, min); max = Math.Max(intVal - 1, max); typeIdentifier = new TIdentifier("byte", value.GetName().Line, value.GetName().Pos); types.Add(typeIdentifier); switchStm.GetCases().Add( new ASwitchCaseStm(new ACaseSwitchCaseType(new TCase("case"), (PExp) intConst.Clone()), new AABlock( new ArrayList() { new AValueReturnStm(new TReturn("return"), new AStringConstExp( new TStringLiteral("\"" + value.GetName().Text + "\""))) }, new TRBrace("}")))); AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), new TStatic("static", value.GetName().Line, value.GetName().Pos), null, null, new TConst("const", value.GetName().Line, value.GetName().Pos), new ANamedType(typeIdentifier, null), value.GetName(), intConst); replacer.GetLocals().Add(localDecl); if (!usedValues.ContainsKey(intVal - 1)) usedValues[intVal - 1] = new List<AALocalDecl>(); usedValues[intVal - 1].Add(localDecl); } if (min < 0 || max > 255) foreach (TIdentifier identifier in types) { identifier.Text = "int"; } node.ReplaceBy(replacer); foreach (KeyValuePair<int, List<AALocalDecl>> pair in usedValues) { if (pair.Value.Count <= 1) continue; int value = pair.Key; List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); foreach (AALocalDecl decl in pair.Value) { subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText179"))); } errors.Add(new ErrorCollection.Error(replacer.GetName(), LocRM.GetString("ErrorText180") + value + ".", false, subErrors.ToArray())); } replacer.Apply(this); data.Enums.Add(replacer, min < 0 || max > 255); }
public override void OutAStructDecl(AStructDecl node) { //Insert parameterless constructor if ( !node.GetLocals().OfType<ADeclLocalDecl>().Select(localDecl => localDecl.GetDecl()).OfType <AConstructorDecl>().Any(constructor => constructor.GetFormals().Count == 0)) { PLocalDecl decl = new ADeclLocalDecl(new AConstructorDecl(new APublicVisibilityModifier(), new TIdentifier(node.GetName().Text), new ArrayList(), new ArrayList(), new AABlock(new ArrayList(), new TRBrace("}")))); node.GetLocals().Add(decl); decl.Apply(this); } //Add deconstructor if not present if (node.GetLocals().OfType<ADeclLocalDecl>().Select(localDecl => localDecl.GetDecl()).OfType<ADeconstructorDecl>().ToList().Count == 0) { PLocalDecl decl = new ADeclLocalDecl(new ADeconstructorDecl(new APublicVisibilityModifier(), new TIdentifier(node.GetName().Text), new ArrayList(), new AABlock(new ArrayList(), new TRBrace("}")))); node.GetLocals().Add(decl); decl.Apply(this); } if (node.GetVisibilityModifier() is AProtectedVisibilityModifier) errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText201"))); }
public StructDecl(AStructDecl decl) { Decl = decl; if (Name.StartsWith("_")) Name = "u" + Name; }
public Parser(AStructDecl structDecl) { structDecl.Apply(this); }
public override void OutAEnumDecl(AEnumDecl node) { AStructDecl replacer = new AStructDecl(node.GetVisibilityModifier(), null, null, null, node.GetEndToken(), node.GetName(), new ArrayList(), null, new ArrayList()); int intVal = 0; //int min = int.MaxValue; //int max = int.MinValue; //List<TIdentifier> types = new List<TIdentifier>(); foreach (AAEnumLocal value in node.GetValues()) { AIntConstExp intConst; if (value.GetValue() != null) { intConst = (AIntConstExp) value.GetValue(); intVal = int.Parse(intConst.GetIntegerLiteral().Text) + 1; } else { intConst = new AIntConstExp(new TIntegerLiteral(intVal.ToString(), value.GetName().Line, value.GetName().Pos)); intVal++; } // min = Math.Min(intVal - 1, min); // max = Math.Max(intVal - 1, max); TIdentifier typeIdentifier = new TIdentifier(replacer.GetName().Text, value.GetName().Line, value.GetName().Pos); // types.Add(typeIdentifier); AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), new TStatic("static", value.GetName().Line, value.GetName().Pos), null, null, new TConst("const", value.GetName().Line, value.GetName().Pos), new ANamedType(typeIdentifier, null), value.GetName(), intConst); replacer.GetLocals().Add(localDecl); } /* if (min < 0 || max > 255) foreach (TIdentifier identifier in types) { identifier.Text = "int"; }*/ node.ReplaceBy(replacer); replacer.Apply(this); replacer.GetName().Text = "enum " + replacer.GetName().Text; }
internal GenericVars_Cast(AStructDecl obj) { this.obj = obj; }
public override void CaseAStructDecl(AStructDecl node) { Write("struct " + node.GetName().Text + "\n{\n"); foreach (AALocalDecl local in node.GetLocals().OfType<AALocalDecl>()) { local.Apply(this); Write(";\n"); } Write("};\n"); }
public virtual void InAStructDecl(AStructDecl node) { DefaultIn(node); }
public override void CaseAStructDecl(AStructDecl node) { if (node.GetDimention() != null && !data.IsLiteCompile) { //Find int dim foldIntegerConstants = true; isInANewExp = true;//If false, we dont require a value node.GetDimention().Apply(this); isInANewExp = false; foldIntegerConstants = false; if (foldingFailed) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText166"))); throw new ParserException(node.GetName(), "TypeLinking.CaseAStructDecl"); } node.SetIntDim(new TIntegerLiteral(integerConstant.ToString())); } base.CaseAStructDecl(node); }
public override void InAStructDecl(AStructDecl node) { decls.Add(node); /*node.GetName().Text = nextName; NextName();*/ }
ArrayList New116() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList8 = (ArrayList) Pop(); ArrayList nodeArrayList7 = (ArrayList) Pop(); ArrayList nodeArrayList6 = (ArrayList) Pop(); ArrayList nodeArrayList5 = (ArrayList) Pop(); ArrayList nodeArrayList4 = (ArrayList) Pop(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode9 = new TypedList(); TypedList listNode12 = new TypedList(); PVisibilityModifier pvisibilitymodifierNode2 = (PVisibilityModifier)nodeArrayList1[0]; TClassToken tclasstokenNode3 = (TClassToken)nodeArrayList2[0]; PExp pexpNode4 = (PExp)nodeArrayList3[0]; TRBrace trbraceNode6 = (TRBrace)nodeArrayList7[1]; TIdentifier tidentifierNode7 = (TIdentifier)nodeArrayList4[0]; TypedList listNode8 = (TypedList)nodeArrayList5[0]; if ( listNode8 != null ) { listNode9.AddAll(listNode8); } PType ptypeNode10 = (PType)nodeArrayList6[0]; TypedList listNode11 = (TypedList)nodeArrayList7[0]; if ( listNode11 != null ) { listNode12.AddAll(listNode11); } AStructDecl pdeclNode1 = new AStructDecl ( pvisibilitymodifierNode2, tclasstokenNode3, pexpNode4, null, trbraceNode6, tidentifierNode7, listNode9, ptypeNode10, listNode12 ); nodeList.Add(pdeclNode1); return nodeList; }
ArrayList New104() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList6 = (ArrayList) Pop(); ArrayList nodeArrayList5 = (ArrayList) Pop(); ArrayList nodeArrayList4 = (ArrayList) Pop(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode9 = new TypedList(); TypedList listNode12 = new TypedList(); PVisibilityModifier pvisibilitymodifierNode2 = (PVisibilityModifier)nodeArrayList1[0]; TRBrace trbraceNode6 = (TRBrace)nodeArrayList5[1]; TIdentifier tidentifierNode7 = (TIdentifier)nodeArrayList3[0]; TypedList listNode8 = (TypedList)nodeArrayList4[0]; if ( listNode8 != null ) { listNode9.AddAll(listNode8); } TypedList listNode11 = (TypedList)nodeArrayList5[0]; if ( listNode11 != null ) { listNode12.AddAll(listNode11); } AStructDecl pdeclNode1 = new AStructDecl ( pvisibilitymodifierNode2, null, null, null, trbraceNode6, tidentifierNode7, listNode9, null, listNode12 ); nodeList.Add(pdeclNode1); return nodeList; }
public override void OutAStructDecl(AStructDecl node) { //Insert parameterless constructor if ( !node.GetLocals().OfType<ADeclLocalDecl>().Select(localDecl => localDecl.GetDecl()).OfType <AConstructorDecl>().Any(constructor => constructor.GetFormals().Count == 0)) { node.GetLocals().Add( new ADeclLocalDecl(new AConstructorDecl(new APublicVisibilityModifier(), new TIdentifier(node.GetName().Text), new ArrayList(), new ArrayList(), new AABlock(new ArrayList(), new TRBrace("}"))))); } }
public virtual void CaseAStructDecl(AStructDecl node) { DefaultCase(node); }
public StructItem(AStructDecl structDecl, Item parent, List<Item> children) : base(parent, children) { StructDecl = structDecl; }
public override void CaseAStructDecl(AStructDecl node) { InAStructDecl(node); { Object[] temp = new Object[node.GetLocals().Count]; node.GetLocals().CopyTo(temp, 0); for (int i = temp.Length - 1; i >= 0; i--) { ((PLocalDecl)temp[i]).Apply(this); } } if (node.GetBase() != null) { node.GetBase().Apply(this); } { Object[] temp = new Object[node.GetGenericVars().Count]; node.GetGenericVars().CopyTo(temp, 0); for (int i = temp.Length - 1; i >= 0; i--) { ((TIdentifier)temp[i]).Apply(this); } } if (node.GetName() != null) { node.GetName().Apply(this); } if (node.GetEndToken() != null) { node.GetEndToken().Apply(this); } if (node.GetIntDim() != null) { node.GetIntDim().Apply(this); } if (node.GetDimention() != null) { node.GetDimention().Apply(this); } if (node.GetClassToken() != null) { node.GetClassToken().Apply(this); } if (node.GetVisibilityModifier() != null) { node.GetVisibilityModifier().Apply(this); } OutAStructDecl(node); }
public static void Parse(AStructDecl str, AStructDecl clone, List<PType> types, SharedData data) { FixGenericLinks fixer = new FixGenericLinks(clone, types, data) {original = str, clone = clone}; str.Apply(fixer); }
public virtual void OutAStructDecl(AStructDecl node) { DefaultOut(node); }
public override void CaseAStructDecl(AStructDecl node) { Name = node.GetName().Text; base.CaseAStructDecl(node); }
public override void OutAStructDecl(AStructDecl node) { if (node.GetGenericVars().Count > 0 && !Refferences.ContainsKey(node)) Refferences[node] = new List<AGenericType>(); base.OutAStructDecl(node); }
public override void InAStructDecl(AStructDecl node) { StructDepandancies.Add(node, new List<AStructDecl>()); base.InAStructDecl(node); }
public override void CaseAStructDecl(AStructDecl node) { if (node.GetDimention() != null) { bool prevFolding = folding; int prevValue = value; bool wasANewExp = isANewExp; folding = true; value = 0; node.GetDimention().Apply(this); node.SetIntDim(new TIntegerLiteral(value.ToString())); folding = prevFolding; value = prevValue; isANewExp = wasANewExp; } base.CaseAStructDecl(node); }
private void CheckStructDependancies(AStructDecl currentStr, List<AStructDecl> checkedStructs, List<AStructDecl> path) { if (path.Contains(currentStr)) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); for (int i = path.IndexOf(currentStr); i < path.Count; i++) { subErrors.Add(new ErrorCollection.Error(path[i].GetName(), Util.GetAncestor<AASourceFile>(path[i]), LocRM.GetString("ErrorText70"))); } subErrors.Add(new ErrorCollection.Error(currentStr.GetName(), Util.GetAncestor<AASourceFile>(currentStr), LocRM.GetString("ErrorText70"))); errors.Add(new ErrorCollection.Error(currentStr.GetName(), Util.GetAncestor<AASourceFile>(currentStr), LocRM.GetString("ErrorText71"), false, subErrors.ToArray())); } if (!checkedStructs.Contains(currentStr)) { checkedStructs.Add(currentStr); path.Add(currentStr); foreach (AStructDecl nextStruct in StructDepandancies[currentStr]) { CheckStructDependancies(nextStruct, checkedStructs, path); } path.Remove(currentStr); } }
internal Locals_Cast(AStructDecl obj) { this.obj = obj; }
private List<ErrorCollection.Error> FindStructMember(AStructDecl structDecl, AStructLvalue node, out bool linked, bool onlyStatic = false) { linked = false; List<ErrorCollection.Error> errors = new List<ErrorCollection.Error>(); AALocalDecl matchingLocal = data.StructFields[structDecl].FirstOrDefault( local => local.GetName().Text == node.GetName().Text); APropertyDecl matchingProperty = data.StructProperties[structDecl].FirstOrDefault( property => property.GetName().Text == node.GetName().Text); if (matchingLocal == null && matchingProperty == null) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText79") + node.GetName().Text)); errors.Add(new ErrorCollection.Error(structDecl.GetName(), Util.GetAncestor<AASourceFile>(structDecl), LocRM.GetString("ErrorText80") + structDecl.GetName().Text)); return errors; } bool isStatic = false; if (matchingProperty == null) { isStatic = matchingLocal.GetStatic() != null; //Check visibility AALocalDecl originalLocal = matchingLocal; if (data.EnheritanceLocalMap.ContainsKey(originalLocal)) originalLocal = data.EnheritanceLocalMap[originalLocal]; if (originalLocal.GetVisibilityModifier() is APrivateVisibilityModifier && Util.GetAncestor<AStructDecl>(originalLocal) != Util.GetAncestor<AStructDecl>(node)) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText81"), false, new ErrorCollection.Error(originalLocal.GetName(), LocRM.GetString("ErrorText82")))); } else if (originalLocal.GetVisibilityModifier() is AProtectedVisibilityModifier && (!Util.HasAncestor<AStructDecl>(node) || !Util.Extends(Util.GetAncestor<AStructDecl>(originalLocal), Util.GetAncestor<AStructDecl>(node), data))) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText83"), false, new ErrorCollection.Error(originalLocal.GetName(), LocRM.GetString("ErrorText82")))); } //Not the visiblity static thingy. The regular static if (matchingLocal.GetStatic() != null && !onlyStatic) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText84") + structDecl.GetName().Text + "." + node.GetName().Text, false, new ErrorCollection.Error(matchingLocal.GetName(), LocRM.GetString("ErrorText85")))); } else if (matchingLocal.GetStatic() == null && onlyStatic) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText86") + structDecl.GetName().Text + ".", false, new ErrorCollection.Error(matchingLocal.GetName(), LocRM.GetString("ErrorText85")))); } data.LvalueTypes[node] = matchingLocal.GetType(); data.StructFieldLinks[node] = matchingLocal; linked = true; } else { //Check visibility if (matchingProperty.GetVisibilityModifier() is APrivateVisibilityModifier && Util.GetAncestor<AStructDecl>(matchingProperty) != Util.GetAncestor<AStructDecl>(node)) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText87"), false, new ErrorCollection.Error(matchingProperty.GetName(), LocRM.GetString("ErrorText82")))); } else if (matchingProperty.GetVisibilityModifier() is AProtectedVisibilityModifier && (!Util.HasAncestor<AStructDecl>(node) || !Util.Extends(Util.GetAncestor<AStructDecl>(node), Util.GetAncestor<AStructDecl>(matchingProperty), data))) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText88"), false, new ErrorCollection.Error(matchingProperty.GetName(), LocRM.GetString("ErrorText82")))); } //Not the visiblity static thingy. The regular static if (matchingProperty.GetStatic() != null && !onlyStatic) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText89") + structDecl.GetName().Text + "." + node.GetName().Text, false, new ErrorCollection.Error(matchingProperty.GetName(), LocRM.GetString("ErrorText90")))); } else if (matchingProperty.GetStatic() == null && onlyStatic) { errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText91") + structDecl.GetName().Text + ".", false, new ErrorCollection.Error(matchingProperty.GetName(), LocRM.GetString("ErrorText90")))); } data.LvalueTypes[node] = matchingProperty.GetType(); data.StructPropertyLinks[node] = matchingProperty; CheckPropertyAccessibility(matchingProperty, node.Parent() is AAssignmentExp, node.GetName()); linked = true; } if (!isStatic && Util.GetAncestor<AMethodDecl>(node) == null && Util.GetAncestor<AConstructorDecl>(node) == null && !Util.HasAncestor<ADeconstructorDecl>(node) && !Util.HasAncestor<APropertyDecl>(node)) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText92"))); } return errors; }
public override void CaseAStructDecl(AStructDecl node) { decls.AddLast(new StructDecl(node)); }
public CallDeconstructors(AStructDecl baseStruct, AALocalDecl structFormal, SharedData data) { this.baseStruct = baseStruct; this.structFormal = structFormal; this.data = data; }