public virtual void InAPropertyLvalue(APropertyLvalue node) { DefaultIn(node); }
public virtual void OutAPropertyLvalue(APropertyLvalue node) { DefaultOut(node); }
public override void CaseAPropertyLvalue(APropertyLvalue node) { InAPropertyLvalue(node); if (node.GetName() != null) { node.GetName().Apply(this); } OutAPropertyLvalue(node); }
public virtual void CaseAPropertyLvalue(APropertyLvalue node) { DefaultCase(node); }
public override void OutAPropertyLvalue(APropertyLvalue node) { data.LvalueTypes[node] = data.PropertyLinks[node].GetType(); CheckPropertyAccessibility(data.PropertyLinks[node], node.Parent() is AAssignmentExp, node.GetName()); base.OutAPropertyLvalue(node); }
public override void OutAFieldLvalue(AFieldLvalue node) { //Since we dont apply the replacement of an OutAAmbiguousNameLvalue, this node needs a link //Eks: global.<field> //Look for fields AFieldDecl f = null; APropertyDecl p = null; if (data.FieldLinks.ContainsKey(node)) f = data.FieldLinks[node]; else //if (!data.FieldLinks.ContainsKey(node) ) { List<IList> visibleDecls = Util.GetVisibleDecls(node, true); AASourceFile currentFile = Util.GetAncestor<AASourceFile>(node); List<string> currentNamespace = Util.GetFullNamespace(node); List<PDecl> candidates = new List<PDecl>(); foreach (IList declList in visibleDecls) { bool isSameFile = false; bool isSameNamespace = false; if (declList.Count > 0) { isSameFile = currentFile == Util.GetAncestor<AASourceFile>((PDecl)declList[0]); isSameNamespace = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace((PDecl)declList[0])); } foreach (PDecl decl in declList) { if (decl is AFieldDecl) { AFieldDecl field = (AFieldDecl)decl; if (field.GetName().Text != node.GetName().Text) continue; if (!isSameNamespace && field.GetVisibilityModifier() is APrivateVisibilityModifier || !isSameFile && field.GetStatic() != null) continue; candidates.Add(decl); } else if (decl is APropertyDecl) { APropertyDecl property = (APropertyDecl)decl; if (property.GetName().Text != node.GetName().Text) continue; if (!isSameNamespace && property.GetVisibilityModifier() is APrivateVisibilityModifier || !isSameFile && property.GetStatic() != null) continue; candidates.Add(decl); } } } //Lib fields foreach (AFieldDecl field in data.Libraries.Fields) { if (field.GetName().Text != node.GetName().Text) continue; if (field.GetStatic() != null) continue; candidates.Add(field); } if (candidates.Count == 0) { errors.Add( new ErrorCollection.Error(node.GetName(), currentSourceFile, node.GetName().Text + LocRM.GetString("ErrorText169"), false), true); throw new ParserException(node.GetName(), "TypeLinking.OutAFieldLvalue"); } if (candidates.Count > 1) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); foreach (PDecl decl in candidates) { if (decl is AFieldDecl) { AFieldDecl field = (AFieldDecl)decl; subErrors.Add(new ErrorCollection.Error(field.GetName(), LocRM.GetString("ErrorText60"))); } else if (decl is APropertyDecl) { APropertyDecl field = (APropertyDecl)decl; subErrors.Add(new ErrorCollection.Error(field.GetName(), LocRM.GetString("ErrorText62"))); } } errors.Add( new ErrorCollection.Error(node.GetName(), currentSourceFile, node.GetName().Text + LocRM.GetString("ErrorText170"), false, subErrors.ToArray()), true); throw new ParserException(node.GetName(), "TypeLinking.OutAFieldLvalue"); } if (candidates[0] is AFieldDecl) f = (AFieldDecl)candidates[0]; else p = (APropertyDecl)candidates[0]; } if (f != null) { AFieldDecl field = f; data.FieldLinks[node] = field; if (foldIntegerConstants) { if (!(field.GetType() is ANamedType && ((ANamedType)field.GetType()).IsPrimitive("int"))) { errors.Add( new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText168"), false, new ErrorCollection.Error(field.GetName(), LocRM.GetString("ErrorText60"))), true); throw new ParserException(node.GetName(), "TypeLinking.OutAFieldLvalue"); } if (field.GetConst() == null) { foldingFailed = true; if (!isInANewExp) { errors.Add( new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText168"), false), true); throw new ParserException(node.GetName(), "TypeLinking.OutAFieldLvalue"); } } if (field.GetInit() == null)//An error will be given earlier - constant fields must have an initializer { throw new ParserException(node.GetName(), "TypeLinking.OutAFieldLvalue"); } field.GetInit().Apply(this); } } else { APropertyDecl property = p; APropertyLvalue replacer = new APropertyLvalue(node.GetName()); data.PropertyLinks.Add(replacer, property); node.ReplaceBy(replacer); data.PropertyLinks[replacer] = property; if (foldIntegerConstants) { foldingFailed = true; if (isInANewExp) { errors.Add( new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText168"), false), true); throw new ParserException(node.GetName(), "TypeLinking.OutAFieldLvalue"); } } } }
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; }