예제 #1
0
 public override void CaseAThisLvalue(AThisLvalue node)
 {
     InAThisLvalue(node);
     if (node.GetToken() != null)
     {
         node.GetToken().Apply(this);
     }
     OutAThisLvalue(node);
 }
        public override void OutAThisLvalue(AThisLvalue node)
        {
            AStructDecl currentStruct = Util.GetAncestor<AStructDecl>(node);
            AConstructorDecl constructor = Util.GetAncestor<AConstructorDecl>(node);
            ADeconstructorDecl deconstructor = Util.GetAncestor<ADeconstructorDecl>(node);
            AEnrichmentDecl enrichment = Util.GetAncestor<AEnrichmentDecl>(node);
            if (enrichment == null && (currentStruct == null || (currentStruct.GetClassToken() == null && constructor == null && deconstructor == null)))
            {
                errors.Add(new ErrorCollection.Error(node.GetToken(), currentSourceFile, LocRM.GetString("ErrorText136")));
                throw new ParserException(node.GetToken(), "TypeChecking.OutAThisLvalue");
            }
            AMethodDecl method = Util.GetAncestor<AMethodDecl>(node);
            APropertyDecl property = Util.GetAncestor<APropertyDecl>(node);
            AALocalDecl field = Util.GetAncestor<AALocalDecl>(node);
            if (method != null && method.GetStatic() != null ||
                property != null && property.GetStatic() != null ||
                field != null && field.GetStatic() != null)
            {
                errors.Add(new ErrorCollection.Error(node.GetToken(), currentSourceFile, LocRM.GetString("ErrorText137")));
                throw new ParserException(node.GetToken(), "TypeChecking.OutAThisLvalue");
            }

            if (enrichment != null)
            {
                if (constructor == null && deconstructor == null)
                    data.LvalueTypes[node] = enrichment.GetType();
                else
                    data.LvalueTypes[node] = new APointerType(new TStar("*"), Util.MakeClone(enrichment.GetType(), data));
            }
            else
            {
                ANamedType namedType = new ANamedType(new TIdentifier(currentStruct.GetName().Text), null);
                data.StructTypeLinks[namedType] = currentStruct;
                data.LvalueTypes[node] = new APointerType(new TStar("*"), namedType);
            }
            base.OutAThisLvalue(node);
        }