public override void OutAStructLvalue(AStructLvalue node) { if (node.Parent() is ADelegateExp) return; if (node.Parent() is ASyncInvokeExp && ((ASyncInvokeExp)node.Parent()).GetName() == node) return; if (node.Parent() is AAsyncInvokeStm && ((AAsyncInvokeStm)node.Parent()).GetName() == node) return; if (data.StructFieldLinks.ContainsKey(node)) { data.LvalueTypes[node] = data.StructFieldLinks[node].GetType(); return; } if (data.StructPropertyLinks.ContainsKey(node)) { APropertyDecl property = data.StructPropertyLinks[node]; data.LvalueTypes[node] = property.GetType(); CheckPropertyAccessibility(property, node.Parent() is AAssignmentExp, node.GetName()); return; } PExp reciever = node.GetReceiver(); AStructDecl structDecl; bool linked; List<ErrorCollection.Error> errs; //Find the local in the struct that this struct points to PType type = data.ExpTypes[reciever]; if ((type is AArrayTempType || type is ADynamicArrayType) && node.GetName().Text == "length") {//Array.length if (reciever is ALvalueExp && ((ALvalueExp)reciever).GetLvalue() is APointerLvalue)//Make new APArrayLength { APArrayLengthLvalue replacer = new APArrayLengthLvalue(node.GetReceiver()); data.LvalueTypes[replacer] = new ANamedType(new TIdentifier("int"), null); node.ReplaceBy(replacer); return; } else { AArrayLengthLvalue replacer = new AArrayLengthLvalue(node.GetReceiver()); data.LvalueTypes[replacer] = new ANamedType(new TIdentifier("int"), null); data.ArrayLengthTypes[replacer] = (AArrayTempType) type; node.ReplaceBy(replacer); return; } } List<AEnrichmentDecl> enrichments = new List<AEnrichmentDecl>(); List<IList> visibleDecls = Util.GetVisibleDecls(node, true); foreach (IList declList in visibleDecls) { foreach (PDecl decl in declList) { if (decl is AEnrichmentDecl) { AEnrichmentDecl enrichment = (AEnrichmentDecl) decl; if (Util.TypesEqual(type, enrichment.GetType(), data)) enrichments.Add(enrichment); } } } if (enrichments.Count == 0 && (!(type is ANamedType) || !data.StructTypeLinks.ContainsKey((ANamedType)type))) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText76"))); throw new ParserException(null, null); } if (enrichments.Count > 0) { foreach (AEnrichmentDecl enrichment in enrichments) { //Can not enrich a struct type, so it is not a struct type. //Look for property foreach (PDecl decl in enrichment.GetDecl()) { if (decl is APropertyDecl) { APropertyDecl aDecl = (APropertyDecl) decl; if (aDecl.GetName().Text == node.GetName().Text) { //Check visibility if (!(aDecl.GetVisibilityModifier() is APublicVisibilityModifier) && Util.GetAncestor<AEnrichmentDecl>(node) != enrichment) continue; data.LvalueTypes[node] = aDecl.GetType(); data.StructPropertyLinks[node] = aDecl; CheckPropertyAccessibility(aDecl, node.Parent() is AAssignmentExp, node.GetName()); return; } } } } List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); foreach (var enrichment in enrichments) { subErrors.Add(new ErrorCollection.Error(enrichment.GetToken(), Util.GetAncestor<AASourceFile>(enrichment), LocRM.GetString("ErrorText77"))); } errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText78"), false, subErrors.ToArray())); throw new ParserException(null, null); } structDecl = data.StructTypeLinks[(ANamedType)type]; //Look through structDecl to find a local matching errs = FindStructMember(structDecl, node, out linked); if (errs.Count > 0) { foreach (ErrorCollection.Error error in errs) { errors.Add(error); } throw new ParserException(null, null); } base.OutAStructLvalue(node); }
public override void OutAStructLvalue(AStructLvalue node) { if (currentPointer.Count > 0) { currentPointer.Add(new LocalDeclPointer(data.StructFieldLinks[node])); currentPointer = MakePointer(currentPointer); isSet = Contains(setPointers, currentPointer); isExposed = Contains(exposedPointers, currentPointer); } }
public override void CaseAStructLvalue(AStructLvalue node) { node.GetReceiver().Apply(this); Write("." + node.GetName().Text); }
public virtual void InAStructLvalue(AStructLvalue node) { DefaultIn(node); }
public override void OutAStructLvalue(AStructLvalue node) { node.GetName().Text = finalTrans.data.StructFieldLinks[node].GetName().Text; }
private List<PStm> AssignDefault(PLvalue lvalue) { List<PStm> returner = new List<PStm>(); PType type = data.LvalueTypes[lvalue]; PExp rightSide = null; if (type is ANamedType) { ANamedType aType = (ANamedType)type; if (aType.IsPrimitive("string"))//aType.GetName().Text == "string") { rightSide = new AStringConstExp(new TStringLiteral("\"\"")); data.ExpTypes[rightSide] = new ANamedType(new TIdentifier("string"), null); } else if (aType.IsPrimitive(GalaxyKeywords.NullablePrimitives.words)) //GalaxyKeywords.NullablePrimitives.words.Contains(aType.GetName().Text)) { rightSide = new ANullExp(); data.ExpTypes[rightSide] = new ANamedType(new TIdentifier("null"), null); } else if (aType.IsPrimitive(new []{"int", "byte", "fixed"})) /*aType.GetName().Text == "int" || aType.GetName().Text == "byte" || aType.GetName().Text == "fixed")*/ { rightSide = new AIntConstExp(new TIntegerLiteral("0")); data.ExpTypes[rightSide] = type; } else if (aType.IsPrimitive("bool"))//aType.GetName().Text == "bool") { rightSide = new ABooleanConstExp(new AFalseBool()); data.ExpTypes[rightSide] = type; } else if (aType.IsPrimitive("color"))//aType.GetName().Text == "color") { PExp arg1 = new AIntConstExp(new TIntegerLiteral("0")); PExp arg2 = new AIntConstExp(new TIntegerLiteral("0")); PExp arg3 = new AIntConstExp(new TIntegerLiteral("0")); ASimpleInvokeExp invoke = new ASimpleInvokeExp(new TIdentifier("Color"), new ArrayList() { arg1, arg2, arg3 }); rightSide = invoke; data.ExpTypes[rightSide] = type; data.ExpTypes[arg1] = data.ExpTypes[arg2] = data.ExpTypes[arg3] = new ANamedType(new TIdentifier("int"), null); data.SimpleMethodLinks[invoke] = data.Libraries.Methods.First(func => func.GetName().Text == invoke.GetName().Text); } else if (aType.IsPrimitive("char"))//aType.GetName().Text == "char") { //Dunno?! rightSide = new ACharConstExp(new TCharLiteral("'\0'")); data.ExpTypes[rightSide] = type; } else //Struct { AStructDecl str = data.StructTypeLinks[aType]; foreach (AALocalDecl localDecl in str.GetLocals()) { ALvalueExp reciever = new ALvalueExp(Util.MakeClone(lvalue, data)); AStructLvalue newLvalue = new AStructLvalue(reciever, new ADotDotType(new TDot(".")), new TIdentifier(localDecl.GetName().Text)); data.StructFieldLinks[newLvalue] = localDecl; data.ExpTypes[reciever] = type; data.LvalueTypes[newLvalue] = localDecl.GetType(); returner.AddRange(AssignDefault(newLvalue)); } return returner; } AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), Util.MakeClone(lvalue, data), rightSide); data.ExpTypes[assignment] = type; return new List<PStm>() { new AExpStm(new TSemicolon(";"), assignment) }; } if (type is AArrayTempType) { AArrayTempType aType = (AArrayTempType)type; for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++) { ALvalueExp reciever = new ALvalueExp(Util.MakeClone(lvalue, data)); AArrayLvalue newLvalue = new AArrayLvalue(new TLBracket("["), reciever, new AIntConstExp(new TIntegerLiteral(i.ToString()))); data.ExpTypes[reciever] = type; data.LvalueTypes[newLvalue] = aType.GetType(); data.ExpTypes[newLvalue.GetIndex()] = new ANamedType(new TIdentifier("int"), null); returner.AddRange(AssignDefault(newLvalue)); } return returner; } throw new Exception("Unexpected type. (LivenessAnalasys.AssignDefault), got " + type); }
public virtual void CaseAStructLvalue(AStructLvalue node) { DefaultCase(node); }
ArrayList New576() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TThis tthisNode4 = (TThis)nodeArrayList1[0]; AThisLvalue plvalueNode3 = new AThisLvalue ( tthisNode4 ); ALvalueExp pexpNode2 = new ALvalueExp ( plvalueNode3 ); TDot tdotNode6 = (TDot)nodeArrayList2[0]; ADotDotType pdottypeNode5 = new ADotDotType ( tdotNode6 ); TIdentifier tidentifierNode7 = (TIdentifier)nodeArrayList3[0]; AStructLvalue plvalueNode1 = new AStructLvalue ( pexpNode2, pdottypeNode5, tidentifierNode7 ); nodeList.Add(plvalueNode1); return nodeList; }
ArrayList New578() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList5 = (ArrayList) Pop(); ArrayList nodeArrayList4 = (ArrayList) Pop(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); PExp pexpNode3 = (PExp)nodeArrayList2[0]; AParenExp pexpNode2 = new AParenExp ( pexpNode3 ); TDot tdotNode5 = (TDot)nodeArrayList4[0]; ADotDotType pdottypeNode4 = new ADotDotType ( tdotNode5 ); TIdentifier tidentifierNode6 = (TIdentifier)nodeArrayList5[0]; AStructLvalue plvalueNode1 = new AStructLvalue ( pexpNode2, pdottypeNode4, tidentifierNode6 ); nodeList.Add(plvalueNode1); return nodeList; }
private void MakeAssignments(AABlock block, PType type, PLvalue leftSide, bool onEnhritedFields) { if (type is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType) type)) { AStructDecl str = data.StructTypeLinks[(ANamedType) type]; foreach (AALocalDecl field in str.GetLocals().OfType<AALocalDecl>()) { if (!onEnhritedFields && data.EnheritanceLocalMap.ContainsKey(field)) continue; ALvalueExp lvalueExp = new ALvalueExp(Util.MakeClone(leftSide, data)); data.ExpTypes[lvalueExp] = data.LvalueTypes[leftSide]; AStructLvalue newLeftSide = new AStructLvalue(lvalueExp, new ADotDotType(new TDot(".")), new TIdentifier(field.GetName().Text)); data.StructFieldLinks[newLeftSide] = field; data.LvalueTypes[newLeftSide] = field.GetType(); if (field.GetInit() != null) { AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), newLeftSide, Util.MakeClone(field.GetInit(), data)); data.ExpTypes[assignment] = data.LvalueTypes[newLeftSide]; block.GetStatements().Add(new AExpStm(new TSemicolon(";"), assignment)); } else { MakeAssignments(block, field.GetType(), newLeftSide, onEnhritedFields); } } } else if (type is AArrayTempType) { AArrayTempType aType = (AArrayTempType) type; for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++) { AIntConstExp index = new AIntConstExp(new TIntegerLiteral(i.ToString())); data.ExpTypes[index] = new ANamedType(new TIdentifier("int"), null); ALvalueExp lvalueExp = new ALvalueExp(Util.MakeClone(leftSide, data)); data.ExpTypes[lvalueExp] = data.LvalueTypes[leftSide]; AArrayLvalue newLeftSide = new AArrayLvalue(new TLBracket("["), lvalueExp, index); data.LvalueTypes[newLeftSide] = aType.GetType(); MakeAssignments(block, aType.GetType(), newLeftSide, onEnhritedFields); } } }
public override void CaseAStructFieldLvalue(AStructFieldLvalue node) { //replace strField1 //with <structFormal>.strField1 AStructDecl str = finalTrans.data.StructTypeLinks[(ANamedType)structFormal.GetType()]; ALocalLvalue parameterRefference = new ALocalLvalue(new TIdentifier("tempName")); finalTrans.data.LocalLinks[parameterRefference] = structFormal; finalTrans.data.LvalueTypes[parameterRefference] = structFormal.GetType(); ALvalueExp exp = new ALvalueExp(parameterRefference); finalTrans.data.ExpTypes[exp] = structFormal.GetType(); AStructLvalue replacer = new AStructLvalue(exp, new ADotDotType(new TDot(".")), node.GetName()); foreach (AALocalDecl structField in finalTrans.data.StructFields[str]) { if (structField.GetName().Text == replacer.GetName().Text) { finalTrans.data.StructFieldLinks[replacer] = structField; finalTrans.data.LvalueTypes[replacer] = structField.GetType(); break; } } foreach (APropertyDecl property in finalTrans.data.StructProperties[str]) { if (property.GetName().Text == replacer.GetName().Text) { finalTrans.data.StructPropertyLinks[replacer] = property; finalTrans.data.LvalueTypes[replacer] = property.GetType(); break; } } node.ReplaceBy(replacer); }
private void MakeAssignmentRightDynamic(PLvalue leftSide, PExp rightSide, PType type, AABlock block, ref int index) { if (Util.IsBulkCopy(type)) { if (type is ANamedType) { ANamedType aType = (ANamedType)type; AStructDecl structDecl = data.StructTypeLinks[aType]; foreach (AALocalDecl localDecl in structDecl.GetLocals()) { AStructLvalue newleftSide = new AStructLvalue(new ALvalueExp(leftSide), new ADotDotType(new TDot(".")), new TIdentifier(localDecl.GetName().Text)); ABinopExp newrightSide = new ABinopExp(rightSide, new APlusBinop(new TPlus("+")), new AStringConstExp( new TStringLiteral("\"." + localDecl.GetName().Text + "\""))); data.ExpTypes[newrightSide] = data.ExpTypes[newrightSide.GetRight()] = new ANamedType(new TIdentifier("string"), null); data.ExpTypes[newleftSide.GetReceiver()] = type; data.LvalueTypes[newleftSide] = localDecl.GetType(); data.StructFieldLinks[newleftSide] = localDecl; MakeAssignmentRightDynamic(newleftSide, newrightSide, localDecl.GetType(), block, ref index); } } else {//Is array type. Can Only be a constant array type AArrayTempType aType = (AArrayTempType)type; for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++) { AArrayLvalue newleftSide = new AArrayLvalue(new TLBracket("["), new ALvalueExp(leftSide), new AIntConstExp(new TIntegerLiteral(i.ToString()))); ABinopExp newrightSide = new ABinopExp(rightSide, new APlusBinop(new TPlus("+")), new AStringConstExp( new TStringLiteral("\"[" + i + "]\""))); data.ExpTypes[newrightSide] = data.ExpTypes[newrightSide.GetRight()] = new ANamedType(new TIdentifier("string"), null); data.ExpTypes[newleftSide.GetBase()] = type; data.ExpTypes[newleftSide.GetIndex()] = new ANamedType(new TIdentifier("int"), null); data.LvalueTypes[newleftSide] = aType.GetType(); MakeAssignmentRightDynamic(newleftSide, newrightSide, aType.GetType(), block, ref index); } } } else { ANamedType aType;// = type is APointerType ? new ANamedType(new TIdentifier("string"), null) : (ANamedType)type; if (type is APointerType) { if (Util.IsIntPointer(type, ((APointerType)type).GetType(), data)) aType = new ANamedType(new TIdentifier("int"), null); else aType = new ANamedType(new TIdentifier("string"), null); } else { aType = (ANamedType) type; } string capitalType = Util.Capitalize(aType.AsIdentifierString());//Char.ToUpper(aType.GetName().Text[0]) + aType.GetName().Text.Substring(1); leftSide = Util.MakeClone(leftSide, data); rightSide = Util.MakeClone(rightSide, data); ABooleanConstExp trueConst1 = new ABooleanConstExp(new ATrueBool()); //ABooleanConstExp trueConst2 = new ABooleanConstExp(new ATrueBool()); ASimpleInvokeExp innerInvoke = new ASimpleInvokeExp(new TIdentifier("DataTableGet" + capitalType), new ArrayList() { trueConst1, rightSide }); //ASimpleInvokeExp outerInvoke = new ASimpleInvokeExp(new TIdentifier("DataTableSet" + capitalType), new ArrayList() { trueConst2, leftSide, innerInvoke }); AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), leftSide, innerInvoke); block.GetStatements().Insert(index, new AExpStm(new TSemicolon(";"), assignment)); index++; data.ExpTypes[trueConst1] = new ANamedType(new TIdentifier("bool"), null); data.ExpTypes[innerInvoke] = aType; data.ExpTypes[assignment] = aType; data.SimpleMethodLinks[innerInvoke] = data.Libraries.Methods.First(m => m.GetName().Text == innerInvoke.GetName().Text); } }
private List<PStm> MakeAssignments(PLvalue lvalue, PExp exp, List<AALocalDecl> declChain) { PType type = data.LvalueTypes[lvalue]; //data.ExpTypes[exp]; PType oldType = data.ExpTypes[exp]; List<PStm> returner = new List<PStm>(); if (type is ADynamicArrayType ||type is AArrayTempType) { AArrayTempType aType; if (type is ADynamicArrayType) aType = (AArrayTempType) data.LvalueTypes[lvalue]; else aType = (AArrayTempType) type; for (int j = 0; j < int.Parse(aType.GetIntDim().Text); j++) { ALvalueExp bulkCopyRefExp = new ALvalueExp(Util.MakeClone(lvalue, data)); AIntConstExp index1 = new AIntConstExp(new TIntegerLiteral(j.ToString())); AArrayLvalue leftSideIndex = new AArrayLvalue(new TLBracket("{"), bulkCopyRefExp, index1); AIntConstExp index2 = new AIntConstExp(new TIntegerLiteral(j.ToString())); AArrayLvalue rightSideIndex = new AArrayLvalue(new TLBracket("{"), Util.MakeClone(exp, data), index2); ALvalueExp rightSideExp = new ALvalueExp(rightSideIndex); data.ExpTypes[bulkCopyRefExp] = data.LvalueTypes[lvalue]; data.ExpTypes[index1] = data.ExpTypes[index2] = new ANamedType(new TIdentifier("int"), null); data.LvalueTypes[leftSideIndex] = data.LvalueTypes[rightSideIndex] = data.ExpTypes[rightSideExp] = aType.GetType(); returner.AddRange(MakeAssignments(leftSideIndex, rightSideExp, declChain)); } } else if (type is ANamedType) { ANamedType aType = (ANamedType) type; if (Util.IsBulkCopy(type)) { AStructDecl str = data.StructTypeLinks[aType]; foreach (AALocalDecl localDecl in str.GetLocals()) { ALvalueExp bulkCopyRefExp = new ALvalueExp(Util.MakeClone(lvalue, data)); AStructLvalue leftSide = new AStructLvalue(bulkCopyRefExp, new ADotDotType(new TDot(".")), new TIdentifier(localDecl.GetName().Text)); AStructLvalue rightSide = new AStructLvalue(Util.MakeClone(exp, data), new ADotDotType(new TDot(".")), new TIdentifier(localDecl.GetName().Text)); ALvalueExp rightSideExp = new ALvalueExp(rightSide); List<AALocalDecl> newDeclChain = new List<AALocalDecl>(); newDeclChain.AddRange(declChain); newDeclChain.Add(localDecl); data.StructFieldLinks[leftSide] = data.StructFieldLinks[rightSide] = localDecl; data.ExpTypes[bulkCopyRefExp] = data.LvalueTypes[lvalue]; data.LvalueTypes[leftSide] = data.LvalueTypes[rightSide] = data.ExpTypes[rightSideExp] = localDecl.GetType(); returner.AddRange(MakeAssignments(leftSide, rightSideExp, newDeclChain)); } } else { //Primitive, find out if it is used if (declChain[0] == null || UsedParameters[Util.GetAncestor<AMethodDecl>(declChain[0])].Where(usedParameter => usedParameter.Count <= declChain.Count).Any( usedParameter => !usedParameter.Where((t, i) => t != declChain[i]).Any())) { AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), Util.MakeClone(lvalue, data), Util.MakeClone(exp, data)); data.ExpTypes[assignment] = data.LvalueTypes[lvalue]; returner.Add(new AExpStm(new TSemicolon(";"), assignment)); } } } else if (type is APointerType) { //Assign as primitive, find out if it is used if (declChain[0] == null || UsedParameters[Util.GetAncestor<AMethodDecl>(declChain[0])].Where(usedParameter => usedParameter.Count <= declChain.Count).Any( usedParameter => !usedParameter.Where((t, i) => t != declChain[i]).Any())) { AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), Util.MakeClone(lvalue, data), Util.MakeClone(exp, data)); data.ExpTypes[assignment] = data.LvalueTypes[lvalue]; returner.Add(new AExpStm(new TSemicolon(";"), assignment)); } } else { throw new Exception("Unexpected type. Got " + (type == null ? "null" : type.ToString())); } return returner; }
public override void CaseAStructLvalue(AStructLvalue node) { hadPointer = false; base.CaseAStructLvalue(node); if (hadPointer) { //if (Util.GetAncestor<AAssignmentExp>(node) != null || Util.GetAncestor<APArrayLengthLvalue>(node) != null) { ABinopExp binopExp = new ABinopExp(nameExp, new APlusBinop(new TPlus("+")), new AStringConstExp( new TStringLiteral("\"." + node.GetName().Text + "\""))); data.ExpTypes[binopExp] = data.ExpTypes[binopExp.GetRight()] = new ANamedType(new TIdentifier("string"), null); nameExp = binopExp; } CheckDynamicLvalue(node); } }
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; }
ArrayList New583() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode6 = new TypedList(); TypedList listNode5 = (TypedList)nodeArrayList1[0]; if ( listNode5 != null ) { listNode6.AddAll(listNode5); } AAName pnameNode4 = new AAName ( listNode6 ); AAmbiguousNameLvalue plvalueNode3 = new AAmbiguousNameLvalue ( pnameNode4 ); ALvalueExp pexpNode2 = new ALvalueExp ( plvalueNode3 ); TArrow tarrowNode8 = (TArrow)nodeArrayList2[0]; AArrowDotType pdottypeNode7 = new AArrowDotType ( tarrowNode8 ); TIdentifier tidentifierNode9 = (TIdentifier)nodeArrayList3[0]; AStructLvalue plvalueNode1 = new AStructLvalue ( pexpNode2, pdottypeNode7, tidentifierNode9 ); nodeList.Add(plvalueNode1); return nodeList; }
public override void CaseAStructLvalue(AStructLvalue node) { if (!IsConst) return; AALocalDecl decl = data.StructFieldLinks[node]; if (decl.GetConst() == null) { IsConst = false; } }
ArrayList New589() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TValue tvalueNode4 = (TValue)nodeArrayList1[0]; AValueLvalue plvalueNode3 = new AValueLvalue ( tvalueNode4 ); ALvalueExp pexpNode2 = new ALvalueExp ( plvalueNode3 ); TArrow tarrowNode6 = (TArrow)nodeArrayList2[0]; AArrowDotType pdottypeNode5 = new AArrowDotType ( tarrowNode6 ); TIdentifier tidentifierNode7 = (TIdentifier)nodeArrayList3[0]; AStructLvalue plvalueNode1 = new AStructLvalue ( pexpNode2, pdottypeNode5, tidentifierNode7 ); nodeList.Add(plvalueNode1); return nodeList; }
public override void CaseAStructLvalue(AStructLvalue node) { //a->b => (*a).b if (node.GetDotType() is AArrowDotType) { TArrow arrow = ((AArrowDotType) node.GetDotType()).GetToken(); node.SetReceiver(new ALvalueExp(new APointerLvalue(new TStar("*", arrow.Line, arrow.Pos), node.GetReceiver()))); node.SetDotType(new ADotDotType(new TDot(".", arrow.Line, arrow.Pos))); } base.CaseAStructLvalue(node); }
ArrayList New593() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); PExp pexpNode2 = (PExp)nodeArrayList1[0]; TArrow tarrowNode4 = (TArrow)nodeArrayList2[0]; AArrowDotType pdottypeNode3 = new AArrowDotType ( tarrowNode4 ); TIdentifier tidentifierNode5 = (TIdentifier)nodeArrayList3[0]; AStructLvalue plvalueNode1 = new AStructLvalue ( pexpNode2, pdottypeNode3, tidentifierNode5 ); nodeList.Add(plvalueNode1); return nodeList; }
public override void CaseAStructLvalue(AStructLvalue node) { InAStructLvalue(node); if (node.GetName() != null) { node.GetName().Apply(this); } if (node.GetDotType() != null) { node.GetDotType().Apply(this); } if (node.GetReceiver() != null) { node.GetReceiver().Apply(this); } OutAStructLvalue(node); }
public override void OutAStructLvalue(AStructLvalue node) { if (foldIntegerConstants) { //Only static fields are valid /*if (!(node.GetReceiver() is ALvalueExp) || !(((ALvalueExp)node.GetReceiver()).GetLvalue() is ATypeLvalue)) { errors.Add( new ErrorCollection.Error(node.GetName(), "Dimensions of array types must be constant expressions."), true); throw new ParserException(node.GetName(), "TypeLinking.OutAStructLvalue"); }*/ //The type has not yet been linked. } }
public virtual void OutAStructLvalue(AStructLvalue node) { DefaultOut(node); }
public static PLvalue Link(AAName name, Node refNode, List<Node> list, SharedData data) { List<TIdentifier> identifierList = new List<TIdentifier>(); { int count = name.GetIdentifier().Count; if (count < list.Count) { for (int i = 0; i < list.Count - count; i++) { if (list[i] is AStructDecl) identifierList.Add(((AStructDecl)list[i]).GetName()); } for (int i = 0; i < count; i++) { TIdentifier iden = (TIdentifier)name.GetIdentifier()[i]; identifierList.Add(iden); } } else for (int i = count - list.Count; i < count; i++) { TIdentifier iden = (TIdentifier)name.GetIdentifier()[i]; identifierList.Add(iden); } } PLvalue baseLvalue = null; Node node = list[0]; list.RemoveAt(0); TIdentifier identifier = identifierList[0]; identifierList.RemoveAt(0); if (node is AALocalDecl) { AALocalDecl aNode = (AALocalDecl)node; if (node.Parent() is AStructDecl) {//Struct local //Make it this->var or this.var AStructDecl pStruct = Util.GetAncestor<AStructDecl>(node); if (pStruct.GetClassToken() != null || Util.HasAncestor<AConstructorDecl>(refNode) || Util.HasAncestor<ADeconstructorDecl>(refNode)) {//(*this). baseLvalue = new AThisLvalue(new TThis("this")); baseLvalue = new APointerLvalue(new TStar("*"), new ALvalueExp(baseLvalue)); baseLvalue = new AStructLvalue(new ALvalueExp(baseLvalue), new ADotDotType(new TDot(".")), identifier); data.StructFieldLinks[(AStructLvalue)baseLvalue] = aNode; } else {//struct. baseLvalue = new AStructFieldLvalue(identifier); data.StructMethodFieldLinks[(AStructFieldLvalue)baseLvalue] = aNode; } } else {//Method/constructor/deconstructor local ALocalLvalue replaceNode = new ALocalLvalue(identifier); data.LocalLinks[replaceNode] = aNode; baseLvalue = replaceNode; } } else if (node is APropertyDecl) { APropertyDecl aNode = (APropertyDecl)node; if (Util.HasAncestor<AStructDecl>(node)) {//Property in current struct AStructDecl pStruct = Util.GetAncestor<AStructDecl>(node); if (pStruct.GetClassToken() != null || Util.HasAncestor<AConstructorDecl>(refNode) || Util.HasAncestor<ADeconstructorDecl>(refNode)) {//(*this). baseLvalue = new AThisLvalue(new TThis("this")); baseLvalue = new APointerLvalue(new TStar("*"), new ALvalueExp(baseLvalue)); baseLvalue = new AStructLvalue(new ALvalueExp(baseLvalue), new ADotDotType(new TDot(".")), identifier); data.StructPropertyLinks[(AStructLvalue)baseLvalue] = aNode; } else {//struct. baseLvalue = new AStructFieldLvalue(identifier); data.StructMethodPropertyLinks[(AStructFieldLvalue)baseLvalue] = aNode; } } else {//Global property baseLvalue = new APropertyLvalue(identifier); data.PropertyLinks[(APropertyLvalue)baseLvalue] = aNode; } } else if (node is AFieldDecl) { baseLvalue = new AFieldLvalue(identifier); data.FieldLinks[(AFieldLvalue)baseLvalue] = (AFieldDecl)node; } else if (node is AStructDecl) { AStructDecl targetStruct = (AStructDecl)node; node = list[0]; list.RemoveAt(0); identifier = identifierList[0]; identifierList.RemoveAt(0); AStructFieldLvalue lvalue = new AStructFieldLvalue(identifier); if (node is AALocalDecl) data.StructMethodFieldLinks[lvalue] = (AALocalDecl)node; else data.StructMethodPropertyLinks[lvalue] = (APropertyDecl)node; baseLvalue = lvalue; } while (list.Count > 0) { node = list[0]; list.RemoveAt(0); identifier = identifierList[0]; identifierList.RemoveAt(0); baseLvalue = new AStructLvalue(new ALvalueExp(baseLvalue), new ADotDotType(new TDot(".")), identifier); if (node is AALocalDecl) {//Struct local data.StructFieldLinks[(AStructLvalue) baseLvalue] = (AALocalDecl) node; } else if (node is APropertyDecl) {//Struct property data.StructPropertyLinks[(AStructLvalue) baseLvalue] = (APropertyDecl) node; } //Don't link array length stuff } return baseLvalue; }
public override void OutAStructLvalue(AStructLvalue node) { currentDecl = new VariableDecl(null, data.StructFieldLinks[node], currentDecl); }
public override void CaseAStructLvalue(AStructLvalue node) { //Only do namespace node.GetReceiver().Apply(this); node.GetDotType().Apply(this); Value += node.GetName().Text; }