public override void OutAStructLvalue(AStructLvalue node) { node.GetName().Text = finalTrans.data.StructFieldLinks[node].GetName().Text; }
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 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 (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 CaseAStructLvalue(AStructLvalue node) { node.GetReceiver().Apply(this); Write("." + node.GetName().Text); }
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); }
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); } }
public override void CaseAStructLvalue(AStructLvalue node) { //Only do namespace node.GetReceiver().Apply(this); node.GetDotType().Apply(this); Value += node.GetName().Text; }