Exemple #1
0
        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);
            }
        }
        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);
        }