예제 #1
0
 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);
 }
예제 #2
0
 public override void CaseAStructLvalue(AStructLvalue node)
 {
     //a->b => (*a).b
     if (node.GetDotType() is AArrowDotType)
     {
         TArrow arrow = ((AArrowDotType) node.GetDotType()).GetToken();
         node.SetReceiver(new ALvalueExp(new APointerLvalue(new TStar("*", arrow.Line, arrow.Pos), node.GetReceiver())));
         node.SetDotType(new ADotDotType(new TDot(".", arrow.Line, arrow.Pos)));
     }
     base.CaseAStructLvalue(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);
 }
예제 #5
0
            private void MakeAssignmentRightDynamic(PLvalue leftSide, PExp rightSide, PType type, AABlock block, ref int index)
            {
                if (Util.IsBulkCopy(type))
                {
                    if (type is ANamedType)
                    {
                        ANamedType aType = (ANamedType)type;
                        AStructDecl structDecl = data.StructTypeLinks[aType];
                        foreach (AALocalDecl localDecl in structDecl.GetLocals())
                        {
                            AStructLvalue newleftSide = new AStructLvalue(new ALvalueExp(leftSide),
                                                                          new ADotDotType(new TDot(".")),
                                                                          new TIdentifier(localDecl.GetName().Text));

                            ABinopExp newrightSide = new ABinopExp(rightSide, new APlusBinop(new TPlus("+")),
                                                     new AStringConstExp(
                                                         new TStringLiteral("\"." + localDecl.GetName().Text + "\"")));

                             data.ExpTypes[newrightSide] =
                                data.ExpTypes[newrightSide.GetRight()] =
                                new ANamedType(new TIdentifier("string"), null);

                            data.ExpTypes[newleftSide.GetReceiver()] = type;
                            data.LvalueTypes[newleftSide] = localDecl.GetType();

                            data.StructFieldLinks[newleftSide] = localDecl;

                            MakeAssignmentRightDynamic(newleftSide, newrightSide, localDecl.GetType(), block, ref index);
                        }
                    }
                    else
                    {//Is array type. Can Only be a constant array type
                        AArrayTempType aType = (AArrayTempType)type;
                        for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++)
                        {
                            AArrayLvalue newleftSide = new AArrayLvalue(new TLBracket("["), new ALvalueExp(leftSide), new AIntConstExp(new TIntegerLiteral(i.ToString())));

                            ABinopExp newrightSide = new ABinopExp(rightSide, new APlusBinop(new TPlus("+")),
                                                     new AStringConstExp(
                                                         new TStringLiteral("\"[" + i + "]\"")));
                            data.ExpTypes[newrightSide] =
                                data.ExpTypes[newrightSide.GetRight()] =
                                new ANamedType(new TIdentifier("string"), null);

                            data.ExpTypes[newleftSide.GetBase()] = type;
                            data.ExpTypes[newleftSide.GetIndex()] = new ANamedType(new TIdentifier("int"), null);
                            data.LvalueTypes[newleftSide] = aType.GetType();

                            MakeAssignmentRightDynamic(newleftSide, newrightSide, aType.GetType(), block, ref index);

                        }

                    }
                }
                else
                {
                    ANamedType aType;// = type is APointerType ? new ANamedType(new TIdentifier("string"), null) : (ANamedType)type;
                    if (type is APointerType)
                    {
                        if (Util.IsIntPointer(type, ((APointerType)type).GetType(), data))
                            aType = new ANamedType(new TIdentifier("int"), null);
                        else
                            aType = new ANamedType(new TIdentifier("string"), null);
                    }
                    else
                    {
                        aType = (ANamedType) type;
                    }
                    string capitalType = Util.Capitalize(aType.AsIdentifierString());//Char.ToUpper(aType.GetName().Text[0]) + aType.GetName().Text.Substring(1);
                    leftSide = Util.MakeClone(leftSide, data);
                    rightSide = Util.MakeClone(rightSide, data);

                    ABooleanConstExp trueConst1 = new ABooleanConstExp(new ATrueBool());
                    //ABooleanConstExp trueConst2 = new ABooleanConstExp(new ATrueBool());
                    ASimpleInvokeExp innerInvoke = new ASimpleInvokeExp(new TIdentifier("DataTableGet" + capitalType), new ArrayList() { trueConst1, rightSide });
                    //ASimpleInvokeExp outerInvoke = new ASimpleInvokeExp(new TIdentifier("DataTableSet" + capitalType), new ArrayList() { trueConst2, leftSide, innerInvoke });
                    AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), leftSide, innerInvoke);
                    block.GetStatements().Insert(index, new AExpStm(new TSemicolon(";"), assignment));
                    index++;

                    data.ExpTypes[trueConst1] = new ANamedType(new TIdentifier("bool"), null);

                    data.ExpTypes[innerInvoke] = aType;
                    data.ExpTypes[assignment] = aType;

                    data.SimpleMethodLinks[innerInvoke] =
                        data.Libraries.Methods.First(m => m.GetName().Text == innerInvoke.GetName().Text);
                }
            }
 public override void CaseAStructLvalue(AStructLvalue node)
 {
     //Only do namespace
     node.GetReceiver().Apply(this);
     node.GetDotType().Apply(this);
     Value += node.GetName().Text;
 }