Exemplo n.º 1
0
 public virtual void OutASharpCastExp(ASharpCastExp node)
 {
     DefaultOut(node);
 }
Exemplo n.º 2
0
 public override void CaseASharpCastExp(ASharpCastExp node)
 {
     InASharpCastExp(node);
     if (node.GetExp() != null)
     {
         node.GetExp().Apply(this);
     }
     if (node.GetType() != null)
     {
         node.GetType().Apply(this);
     }
     if (node.GetToken() != null)
     {
         node.GetToken().Apply(this);
     }
     OutASharpCastExp(node);
 }
Exemplo n.º 3
0
 public virtual void InASharpCastExp(ASharpCastExp node)
 {
     DefaultIn(node);
 }
Exemplo n.º 4
0
 public virtual void CaseASharpCastExp(ASharpCastExp node)
 {
     DefaultCase(node);
 }
 public override void CaseASharpCastExp(ASharpCastExp node)
 {
     IsConst = false;
 }
        public override void OutASharpCastExp(ASharpCastExp node)
        {
            PType fromType = data.ExpTypes[node.GetExp()];
            PType toType = node.GetType();
            //Valid from pointer to int/string and from int/string to pointer
            if (fromType is APointerType)
            {
                APointerType aFromType = (APointerType) fromType;

                if (toType != null && !(toType is ANamedType))
                {
                    errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText115")));
                    throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                }
                ANamedType aToType = toType == null ? null : (ANamedType) toType;
                if (toType != null && !aToType.IsPrimitive("int") && !aToType.IsPrimitive("string"))
                {
                    errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText114")));
                    throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                }
                if (aFromType.GetType() is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType) aFromType.GetType()))
                {
                    AStructDecl str = data.StructTypeLinks[(ANamedType) aFromType.GetType()];
                    if (toType != null && (str.GetDimention() == null) != (aToType.IsPrimitive("string")))
                    {
                        errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                             LocRM.GetString("ErrorText116") +
                                                             (str.GetDimention() == null ? "string." : "int.")));
                        throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                    }
                    data.ExpTypes[node.GetExp()] = new ANamedType(new TIdentifier(str.GetDimention() == null ? "string" : "int"), null);
                    node.ReplaceBy(node.GetExp());
                    return;
                }
                //Look for enrichments
                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(aFromType.GetType(), enrichment.GetType(), data))
                                continue;
                            if (toType != null && (enrichment.GetDimention() == null) != (aToType.IsPrimitive("string")))
                            {
                                errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                                     LocRM.GetString("ErrorText116") +
                                                                     (enrichment.GetDimention() == null
                                                                          ? "string."
                                                                          : "int.")));
                                throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                            }
                            data.ExpTypes[node.GetExp()] = new ANamedType(new TIdentifier(enrichment.GetDimention() == null ? "string" : "int"), null);
                            node.ReplaceBy(node.GetExp());
                            return;
                        }
                    }
                }

                if (toType != null && aToType.IsPrimitive("int"))
                {
                    errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                         LocRM.GetString("ErrorText117")));
                    throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                }

                data.ExpTypes[node.GetExp()] = new ANamedType(new TIdentifier("string"), null);
                node.ReplaceBy(node.GetExp());
                return;
            }
            if (fromType is ANamedType)
            {
                ANamedType aFromType = (ANamedType) fromType;
                if (!(toType is APointerType))
                {
                    errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText118")));
                    throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                }
                APointerType aToType = (APointerType) toType;
                if (!aFromType.IsPrimitive("int") && !aFromType.IsPrimitive("string"))
                {
                    errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText119")));
                    throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                }
                if (aToType.GetType() is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType)aToType.GetType()))
                {
                    AStructDecl str = data.StructTypeLinks[(ANamedType)aToType.GetType()];
                    if ((str.GetDimention() == null) != (aFromType.IsPrimitive("string")))
                    {
                        errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                             LocRM.GetString("ErrorText120") +
                                                             (str.GetDimention() == null ? "string." : "int.")));
                        throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                    }
                    data.ExpTypes[node.GetExp()] = aToType;
                    node.ReplaceBy(node.GetExp());
                    return;
                }
                //Look for enrichments
                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(aToType.GetType(), enrichment.GetType(), data))
                                continue;
                            if ((enrichment.GetDimention() == null) != (aFromType.IsPrimitive("string")))
                            {
                                errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                                     LocRM.GetString("ErrorText120") +
                                                                     (enrichment.GetDimention() == null
                                                                          ? "string."
                                                                          : "int.")));
                                throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                            }
                            data.ExpTypes[node.GetExp()] = aToType;
                            node.ReplaceBy(node.GetExp());
                            return;
                        }
                    }
                }
                if (aFromType.IsPrimitive("int"))
                {
                    errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                         LocRM.GetString("ErrorText121")));
                    throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
                }
                data.ExpTypes[node.GetExp()] = aToType;
                node.ReplaceBy(node.GetExp());
                return;
            }
            errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText118")));
            throw new ParserException(node.GetToken(), "TypeChecking.OutASharpCastExp");
        }
Exemplo n.º 7
0
 ArrayList New457()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TSharp tsharpNode2 = (TSharp)nodeArrayList1[0];
     PType ptypeNode3 = (PType)nodeArrayList2[0];
     PExp pexpNode4 = (PExp)nodeArrayList4[0];
     ASharpCastExp pexpNode1 = new ASharpCastExp (
       tsharpNode2,
       ptypeNode3,
       pexpNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
Exemplo n.º 8
0
 ArrayList New456()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TSharp tsharpNode2 = (TSharp)nodeArrayList1[0];
     PExp pexpNode4 = (PExp)nodeArrayList3[0];
     ASharpCastExp pexpNode1 = new ASharpCastExp (
       tsharpNode2,
       null,
       pexpNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }