public override void OutAStructFieldLvalue(AStructFieldLvalue node)
        {
            if (folding)
            {
                if (data.StructMethodPropertyLinks.ContainsKey(node))
                {

                    errors.Add(
                        new ErrorCollection.Error(node.GetName(),
                                                  LocRM.GetString("ErrorText61"),
                                                  false,
                                                  new ErrorCollection.Error(
                                                      data.StructMethodPropertyLinks[node].GetName(),
                                                      LocRM.GetString("ErrorText62"))), true);
                    throw new ParserException(node.GetName(), "TypeLinking.OutAStructFieldLvalue");
                }
                AALocalDecl field = data.StructMethodFieldLinks[node];
                if (!(field.GetType() is ANamedType && ((ANamedType)field.GetType()).IsPrimitive("int")))
                {
                    errors.Add(
                        new ErrorCollection.Error(node.GetName(),
                                                  LocRM.GetString("ErrorText59"),
                                                  false, new ErrorCollection.Error(field.GetName(), LocRM.GetString("ErrorText60"))), true);
                    throw new ParserException(node.GetName(), "TypeLinking.OutAStructFieldLvalue");
                }

                if (field.GetConst() == null)
                {
                    if (!isANewExp)
                    {
                        errors.Add(
                            new ErrorCollection.Error(node.GetName(),
                                                      LocRM.GetString("ErrorText62"),
                                                      false, new ErrorCollection.Error(field.GetName(), LocRM.GetString("ErrorText60"))), 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);
            }
        }
Ejemplo n.º 2
0
 public override void CaseAStructFieldLvalue(AStructFieldLvalue node)
 {
     InAStructFieldLvalue(node);
     if (node.GetName() != null)
     {
         node.GetName().Apply(this);
     }
     OutAStructFieldLvalue(node);
 }
Ejemplo n.º 3
0
        public override void OutAStructFieldLvalue(AStructFieldLvalue node)
        {
            if (!data.StructMethodFieldLinks.ContainsKey(node) &&
                !data.StructMethodPropertyLinks.ContainsKey(node))
            {
                AStructDecl str = Util.GetAncestor<AStructDecl>(node);
                AConstructorDecl constructor = Util.GetAncestor<AConstructorDecl>(node);
                if (str.GetClassToken() != null || constructor != null || Util.HasAncestor<ADeconstructorDecl>(node))
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile,
                                                         LocRM.GetString("ErrorText171")));
                }
                if (str != null)
                {
                    foreach (AALocalDecl localDecl in data.StructFields[str])
                    {
                        if (localDecl.GetName().Text == node.GetName().Text)
                        {
                            data.StructMethodFieldLinks.Add(node, localDecl);
                            return;
                        }
                    }
                    foreach (APropertyDecl property in data.StructProperties[str])
                    {
                        if (property.GetName().Text == node.GetName().Text)
                        {
                            data.StructMethodPropertyLinks.Add(node, property);
                            return;
                        }
                    }
                }
                errors.Add(
                    new ErrorCollection.Error(node.GetName(), currentSourceFile,
                                              node.GetName().Text + LocRM.GetString("ErrorText172"), false),
                    true);
            }
            //We can be sure this is linked. If in an array index, it must be constant.
            if (foldIntegerConstants)
            {
                if (data.StructMethodPropertyLinks.ContainsKey(node))
                {

                    errors.Add(
                        new ErrorCollection.Error(node.GetName(),
                                                  LocRM.GetString("ErrorText61"),
                                                  false,
                                                  new ErrorCollection.Error(
                                                      data.StructMethodPropertyLinks[node].GetName(),
                                                      LocRM.GetString("ErrorText62"))), true);
                    throw new ParserException(node.GetName(), "TypeLinking.OutAStructFieldLvalue");
                }
                AALocalDecl field = data.StructMethodFieldLinks[node];
                if (!(field.GetType() is ANamedType && ((ANamedType)field.GetType()).IsPrimitive("int")))
                {
                    errors.Add(
                        new ErrorCollection.Error(node.GetName(),
                                                  "Dimensions of array types must be integer expressions.",
                                                  false, new ErrorCollection.Error(field.GetName(), "Matching field")), true);
                    throw new ParserException(node.GetName(), "TypeLinking.OutAStructFieldLvalue");
                }

                if (field.GetConst() == null)
                {
                    foldingFailed = true;
                    if (!isInANewExp)
                    {
                        errors.Add(
                            new ErrorCollection.Error(node.GetName(), currentSourceFile,
                                                      LocRM.GetString("ErrorText61"),
                                                      false, new ErrorCollection.Error(field.GetName(), LocRM.GetString("ErrorText60"))), 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);
            }
            //base.CaseAStructFieldLvalue(node);
        }
        public override void OutAStructFieldLvalue(AStructFieldLvalue node)
        {
            if (data.StructMethodFieldLinks.ContainsKey(node))
            {
                AALocalDecl decl = data.StructMethodFieldLinks[node];
                if (data.Enums.ContainsKey((AStructDecl) decl.Parent()))
                {
                    AStructDecl str = (AStructDecl) decl.Parent();
                    ANamedType namedType = new ANamedType(new TIdentifier(str.GetName().Text), null);
                    data.StructTypeLinks[namedType] = str;
                    data.LvalueTypes[node] = namedType;
                }
                else
                    data.LvalueTypes[node] = decl.GetType();
                if (Util.IsStaticContext(node) && decl.GetStatic() == null)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText99"),
                                                         false,
                                                         new ErrorCollection.Error(decl.GetName(),
                                                                                   LocRM.GetString("ErrorText100"))));
                }
            }
            else
            {
                APropertyDecl decl = data.StructMethodPropertyLinks[node];
                data.LvalueTypes[node] = decl.GetType();
                CheckPropertyAccessibility(decl, node.Parent() is AAssignmentExp, node.GetName());
                if (Util.IsStaticContext(node) && decl.GetStatic() == null)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText101"),
                                                         false,
                                                         new ErrorCollection.Error(decl.GetName(),
                                                                                   LocRM.GetString("ErrorText62"))));
                }
            }

            //If the lvalue is a static variable, it's okay

            if (data.StructMethodFieldLinks[node].GetStatic() == null && Util.GetAncestor<AMethodDecl>(node) == null && Util.GetAncestor<APropertyDecl>(node) == null)
            {
                errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile,
                    LocRM.GetString("ErrorText102")));
            }
        }
 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);
 }