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 int FoldInt(PLvalue lvalue, ref bool valid)
        {
            if (!valid)
            {
                return(-1);
            }

            if (lvalue is ALocalLvalue)
            {
                ALocalLvalue aLvalue = (ALocalLvalue)lvalue;
                AALocalDecl  decl    = data.LocalLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }
            if (lvalue is AFieldLvalue)
            {
                AFieldLvalue aLvalue = (AFieldLvalue)lvalue;
                AFieldDecl   decl    = data.FieldLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }
            if (lvalue is AStructFieldLvalue)
            {
                AStructFieldLvalue aLvalue = (AStructFieldLvalue)lvalue;
                AALocalDecl        decl    = data.StructMethodFieldLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }
            if (lvalue is AStructLvalue)
            {
                AStructLvalue aLvalue = (AStructLvalue)lvalue;
                AALocalDecl   decl    = data.StructFieldLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }

            valid = false;
            return(-1);
        }
Пример #3
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);
            }
        }
Пример #4
0
 bool IsConstant(PLvalue lvalue)
 {
     if (lvalue is ALocalLvalue)
     {
         ALocalLvalue aLvalue = (ALocalLvalue)lvalue;
         AALocalDecl  decl    = data.LocalLinks[aLvalue];
         if (decl == initialLocalDecl)
         {
             return(false);
         }
         return(decl.GetConst() != null && IsConstant(decl.GetInit()));
     }
     if (lvalue is AFieldLvalue)
     {
         AFieldLvalue aLvalue = (AFieldLvalue)lvalue;
         AFieldDecl   decl    = data.FieldLinks[aLvalue];
         if (decl == initialFieldDecl)
         {
             return(false);
         }
         return(decl.GetConst() != null && IsConstant(decl.GetInit()));
     }
     if (lvalue is APropertyLvalue)
     {
         return(false);
     }
     if (lvalue is ANamespaceLvalue)
     {
         return(true);
     }
     if (lvalue is AStructFieldLvalue)
     {
         AStructFieldLvalue aLvalue = (AStructFieldLvalue)lvalue;
         AALocalDecl        decl    = data.StructMethodFieldLinks[aLvalue];
         if (decl == initialLocalDecl)
         {
             return(false);
         }
         return(decl.GetConst() != null && IsConstant(decl.GetInit()));
     }
     if (lvalue is AStructLvalue)
     {
         AStructLvalue aLvalue = (AStructLvalue)lvalue;
         AALocalDecl   decl    = data.StructFieldLinks[aLvalue];
         if (decl == initialLocalDecl)
         {
             return(false);
         }
         return(decl.GetConst() != null && IsConstant(decl.GetInit()));
     }
     if (lvalue is AArrayLvalue)
     {
         AArrayLvalue aLvalue = (AArrayLvalue)lvalue;
         return(IsConstant(aLvalue.GetIndex()) && IsConstant(aLvalue.GetBase()));
     }
     if (lvalue is APointerLvalue)
     {
         APointerLvalue aLvalue = (APointerLvalue)lvalue;
         return(IsConstant(aLvalue.GetBase()));
     }
     if (lvalue is APArrayLengthLvalue)
     {
         APArrayLengthLvalue aLvalue = (APArrayLengthLvalue)lvalue;
         return(data.ExpTypes[aLvalue.GetBase()] is AArrayTempType);
     }
     if (lvalue is AThisLvalue)
     {
         return(false);
     }
     if (lvalue is AValueLvalue)
     {
         return(false);
     }
     throw new Exception("Unexpected lvalue. Got " + lvalue);
 }
Пример #5
0
 private static void MakeCloneRefferences(PLvalue clone, PLvalue lvalue, SharedData data)
 {
     data.LvalueTypes[clone] = data.LvalueTypes[lvalue];
     if (lvalue is ALocalLvalue)
     {
         data.LocalLinks[(ALocalLvalue)clone] = data.LocalLinks[(ALocalLvalue)lvalue];
     }
     else if (lvalue is AFieldLvalue)
     {
         data.FieldLinks[(AFieldLvalue)clone] = data.FieldLinks[(AFieldLvalue)lvalue];
     }
     else if (lvalue is AStructLvalue)
     {
         AStructLvalue aLvalue = (AStructLvalue)lvalue;
         AStructLvalue aClone  = (AStructLvalue)clone;
         if (data.StructFieldLinks.ContainsKey(aLvalue))
         {
             data.StructFieldLinks[aClone] =
                 data.StructFieldLinks[aLvalue];
         }
         else
         {
             data.StructPropertyLinks[aClone] =
                 data.StructPropertyLinks[aLvalue];
         }
         MakeCloneRefferences(aClone.GetReceiver(), aLvalue.GetReceiver(), data);
     }
     else if (lvalue is AStructFieldLvalue)
     {
         AStructFieldLvalue aLvalue = (AStructFieldLvalue)lvalue;
         AStructFieldLvalue aClone  = (AStructFieldLvalue)clone;
         if (data.StructMethodFieldLinks.ContainsKey(aLvalue))
         {
             data.StructMethodFieldLinks[aClone] = data.StructMethodFieldLinks[aLvalue];
         }
         if (data.StructMethodPropertyLinks.ContainsKey(aLvalue))
         {
             data.StructMethodPropertyLinks[aClone] = data.StructMethodPropertyLinks[aLvalue];
         }
     }
     else if (lvalue is AArrayLvalue)
     {
         AArrayLvalue aLvalue = (AArrayLvalue)lvalue;
         AArrayLvalue aClone  = (AArrayLvalue)clone;
         MakeCloneRefferences(aClone.GetBase(), aLvalue.GetBase(), data);
         MakeCloneRefferences(aClone.GetIndex(), aLvalue.GetIndex(), data);
     }
     else if (lvalue is APointerLvalue)
     {
         APointerLvalue aLvalue = (APointerLvalue)lvalue;
         APointerLvalue aClone  = (APointerLvalue)clone;
         MakeCloneRefferences(aClone.GetBase(), aLvalue.GetBase(), data);
     }
     else if (lvalue is AThisLvalue || lvalue is AValueLvalue)
     {
         //AThisLvalue aLvalue = (AThisLvalue)lvalue;
         //Do nothing more
     }
     else if (lvalue is APropertyLvalue)
     {
         APropertyLvalue aLvalue = (APropertyLvalue)lvalue;
         APropertyLvalue aClone  = (APropertyLvalue)clone;
         data.PropertyLinks[aClone] = data.PropertyLinks[aLvalue];
     }
     else
     {
         throw new Exception("Unexpect lvalue. Got " + lvalue.GetType());
     }
 }