コード例 #1
0
ファイル: ExpAST.cs プロジェクト: chenzuo/blue
 public TempTypeExp(TypeSig t)
 {
     m_tSig = t;
 }
コード例 #2
0
ファイル: AST.cs プロジェクト: chenzuo/blue
 public DelegateDecl(
     Identifier      idName,
     TypeSig         tRetType,
     ParamVarDecl[]  arParams,        
     Modifiers       mods
 )
 {
     Debug.Assert(idName != null);
     Debug.Assert(tRetType != null);
     Debug.Assert(arParams != null);
             
     m_idName    = idName;
     m_tRetType  = tRetType;
     m_arParams  = arParams;
     m_mods      = mods;
     
     // Implied sealed
     m_mods.SetSealed();
 }    
コード例 #3
0
ファイル: ExpAST.cs プロジェクト: chenzuo/blue
    public IsExp(
        Exp expTest,
        TypeSig tTarget
    )
    {
        Debug.Assert(expTest != null);
        Debug.Assert(tTarget != null);

        m_expTest = expTest;
        m_tTarget = tTarget;

        //m_filerange = FileRange.Merge(expTest.Location, tTarget.Location);
    }
コード例 #4
0
ファイル: AST.cs プロジェクト: chenzuo/blue
    // For interface types
    public ClassDecl(
        Identifier idName,         
        TypeSig [] arSuper, // super class & implemented interfaces
        MethodDecl [] alMethods,
        PropertyDecl[] alProperties,
        Modifiers mods    
    ) 
    {        
        Debug.Assert(idName != null);
        Debug.Assert(alMethods != null);
        

        m_strName = idName.Text;
        
        m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper;

        m_alMethods = alMethods;
        m_alProperties = alProperties;
        m_alNestedTypes = m_sEmptyTypeList;
        
        // @todo - this is wrong
        m_filerange = idName.Location;

        //m_mods.FlagSetter = mods.Flags | Modifiers.EFlags.Abstract;
        m_mods = mods;
        m_mods.SetAbstract();
       
        m_genre = TypeEntry.Genre.cInterface;
    }
コード例 #5
0
ファイル: AST.cs プロジェクト: chenzuo/blue
    // For non-interface types
    public ClassDecl(
        Identifier idName,         
        TypeSig [] arSuper, // super class & implemented interfaces
        MethodDecl [] alMethods,
        PropertyDecl[] alProperties,
        FieldDecl[] alFields,
        EventDecl [] alEvents,
        TypeDeclBase[] alNestedTypes,
        Modifiers mods,
        bool fIsClass // true for class, false for struct
    ) 
    {        
        Debug.Assert(idName != null);
        Debug.Assert(alMethods != null);
        Debug.Assert(alFields != null);
        Debug.Assert(alProperties != null);
        Debug.Assert(alEvents != null);


        m_strName = idName.Text;
        
        m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper;

        m_alNestedTypes     = (alNestedTypes == null) ?  m_sEmptyTypeList : alNestedTypes;
        m_alMethods         = alMethods;
        m_alProperties      = alProperties;
        m_alFields          = alFields;
        m_alEvents          = alEvents;
        
        // @todo - this is wrong
        m_filerange = idName.Location;

        if (!fIsClass) // structs are implicitly sealed.           
            mods.SetSealed();
            
        m_mods = mods;          
                    
        m_genre = fIsClass ? TypeEntry.Genre.cClass : TypeEntry.Genre.cStruct;
    }
コード例 #6
0
ファイル: Parser.cs プロジェクト: chenzuo/blue
//-----------------------------------------------------------------------------
// Do a partial parse of the method decl (includes ctor), 
// Pass in the parameters that we've already parsed, which is everything 
// before the first '('. 
//
// ** Rules **
// methoddecl -> attrs type id '(' paramlist ')' '{' statementlist '}'
// methoddecl -> attrs type id '(' paramlist ')' ';'   // if abstract
//-----------------------------------------------------------------------------
    protected MethodDecl PartialParseMethodDecl(
        Modifiers mods, 
        TypeSig typeReturn,
        Identifier stMemberName,
        Genre genre // applies additional restrictions
    )
    {   
    // We should have already parsed the 'attrs type id'. So continue with param list
        
        ParamVarDecl [] arParams = ParseParamList();
        
        // Structs can't define a default ctor
        if ((genre == Genre.cStruct) && (typeReturn == null) && (arParams.Length == 0))
        {
            ThrowError(E_NoDefaultCtorForStructs(m_lexer.PeekNextToken().Location));
        }
        

        CtorChainStatement chain  = null;
    // If this is a constructor, then we can chain it
    // ctordecl -> mods type id '(' param_list ')' ':' (this|base) '(' param_list ')' '{' statementlist '}'
    // ctor can't be abstract / virtual. Can be static
        if (typeReturn == null)
        {   
            Token t = m_lexer.PeekNextToken();
            if (genre == Genre.cInterface)
            {
                ThrowError(E_NoCtorOnInterface(t.Location));
            }        
            
            if (t.TokenType == Token.Type.cColon)
            {                
                ConsumeNextToken();
                // Currently, 'base' & 'this' are just identifiers, not specific tokens
                Identifier id = this.ReadExpectedIdentifier();
                Exp [] arParams2 = ParseExpList();

                CtorChainStatement.ETarget eTarget = (CtorChainStatement.ETarget) (-1);
                
                if (id.Text == "this")
                    eTarget = CtorChainStatement.ETarget.cThis;
                else if (id.Text == "base")
                {
                    if (genre == Genre.cStruct)
                    {
                        ThrowError(E_NoBaseChainForStructs(id.Location));
                    }
                    eTarget = CtorChainStatement.ETarget.cBase;
                }
                else 
                {
                    ThrowError(E_BadCtorChain(id));
                }

                chain = new CtorChainStatement(eTarget, arParams2);
            } 
            else 
            {
                // If no explicit ctor chain, then we still have an implicit "base ()"
                // (except for static ctors, which can't be chained)
                if (!mods.IsStatic && (genre == Genre.cClass))                
                {                
                    chain = new CtorChainStatement();
                }
            }

            // Static ctors can't be chained
            if (chain != null)
            {
                if (mods.IsStatic)                
                {
                    ThrowError(E_NoChainForStaticCtor(stMemberName.Location));
                }
            }
        }


    // Parse body
        BlockStatement block = null;

        if (mods.IsAbstract)        
        {
        // For abstract methods, no body. Just end with a ';'
            ReadExpectedToken(Token.Type.cSemi);        
        } else 
        {        
        // Read method body. This will include the '{' ... '}'    
            block = ParseStatementBlock();
        }


        if (typeReturn == null)
        {
            if (mods.IsAbstract | mods.IsVirtual | (block == null))            
            {
                ThrowError(E_NoAbstractCtor(stMemberName));
            }
        }
        
        // Allocate the method decl
        MethodDecl nodeMethod = new MethodDecl(
            stMemberName, 
            typeReturn, 
            arParams, 
            block,
            mods);

        // If we have a chain, inject it into the statements
        if (chain != null)
        {
            nodeMethod.Body.InjectStatementAtHead(chain);
            chain.FinishInit(nodeMethod);
        }

        return nodeMethod;
    }
コード例 #7
0
ファイル: Parser.cs プロジェクト: chenzuo/blue
    //-----------------------------------------------------------------------------
    // Parse a comma separated list of identifiers
    // expect at least 1 entry
    //-----------------------------------------------------------------------------
    protected TypeSig[] ParseIdNameList()
    {
        ArrayList a = new ArrayList();

        Token t;

        while(true)
        {
            Exp o = ParseDottedIdList();
            a.Add(o);

            t = m_lexer.PeekNextToken();
            if (t.TokenType == Token.Type.cComma)
            {
                ConsumeNextToken();
                continue;
            }
            break;
        }

        TypeSig[] olist = new TypeSig[a.Count];
        for(int i = 0; i < a.Count; i++)        
        {
            olist[i] = new SimpleTypeSig((Exp) a[i]);
        }
        
        return olist;
    }    
コード例 #8
0
ファイル: Parser.cs プロジェクト: chenzuo/blue
//-----------------------------------------------------------------------------
// Partial parse a property decl.
// We've already parsed the modifiers, return type & member name, so
// pass those in as parameters. Start parsing at '{'
// Note that indexers are just properties that take parameters.
//
// ** rules **
// PropertyDecl -> mods type id '{' property_body '}'
//-----------------------------------------------------------------------------
    protected PropertyDecl PartialParsePropertyDecl(
        Modifiers mods, 
        TypeSig typeReturn, 
        Identifier stMemberName
    )
    {   
        // Note that properties can be abstract, in which case their bodyStmt is null.
        // Also note that both get & set have the same modifiers        
                
        FileRange f = this.BeginRange();
                        
        BlockStatement stmtGet;
        BlockStatement stmtSet;
                        
        bool fHasGet;
        bool fHasSet;
                        
        ParseAccessors(mods.IsAbstract, stMemberName,
            out stmtGet, out fHasGet,
            out stmtSet, out fHasSet);
                
        PropertyDecl p = new PropertyDecl(
            stMemberName, typeReturn, 
            stmtGet, fHasGet, 
            stmtSet, fHasSet, 
            mods); 
        
        p.SetLocation(this.EndRange(f));
        return p;
    }
コード例 #9
0
ファイル: Parser.cs プロジェクト: chenzuo/blue
//-----------------------------------------------------------------------------
// Parse for overloaded operator
// -> mods type 'operator' op '(' paramlist ')' '{' statementlist '}'
//-----------------------------------------------------------------------------
    protected MethodDecl PartialParseOverloadedOp(    
        Modifiers mods, // must be public & static
        TypeSig typeReturn
    )
    {
        /*
        Modifiers modsLegal = new Modifiers(Modifiers.EFlags.Public | Modifiers.EFlags.Static);
        if (modsLegal.Flags != mods.Flags)
            ThrowError_BadModsOnOps(typeReturn.Location);
        */
        if (!mods.IsStatic || !mods.IsPublic)
            ThrowError(E_BadModsOnOps(typeReturn.Location));
        
            
        ReadExpectedToken(Token.Type.cOperator);
        
        // Get the operator
        Token tOp = m_lexer.GetNextToken();
        BinaryExp.BinaryOp op = ConvertToBinaryOp(tOp);
        
        // @todo - Check that it's a valid overloadable op...
        
        // Parse parameters. Expect 2, both values (not ref/out)
        ParamVarDecl [] arParams = ParseParamList();
        if (arParams.Length != 2)
            ThrowError(E_BadParamListOnOps(typeReturn.Location, "Must have 2 parameters"));

        
        for(int i = 0; i < arParams.Length; i++)
        {   
            if (arParams[i].Flow != EArgFlow.cIn)
                ThrowError(E_BadParamListOnOps(arParams[i].Location, "Parameter " + i + " can't be ref/out"));
        }
            
        
        // Read method body. This will include the '{' ... '}'    
        BlockStatement block = ParseStatementBlock();
        
        // Allocate the method decl
        MethodDecl nodeMethod = new MethodDecl(
            op, 
            typeReturn, 
            arParams, 
            block
        );
            
        return nodeMethod;            
        
    }
コード例 #10
0
ファイル: StatementAST.cs プロジェクト: chenzuo/blue
 public CatchHandler(
     TypeSig type,           // type we're catching (must derived from System.Exception)
     Identifier idName,       // optional (can be null) name for local var to store exception
     BlockStatement stmtBody // handler body (non-null)
 ) 
 {         
     Debug.Assert(stmtBody != null);
     
     // General catch blocks just becomes a System.Exception
     if (type == null)
     {        
         m_type = new SimpleTypeSig(new DotObjExp(
             new SimpleObjExp(new Identifier("System", null)),
             new Identifier("Exception", null)
             ));
     
         
     } else {     
         m_type = type;
     }
     m_idVarName = idName;
     m_body = stmtBody;
 }
コード例 #11
0
ファイル: Parser.cs プロジェクト: chenzuo/blue
//-----------------------------------------------------------------------------
// Partial parse an Indexer decl
//
// ** rules **
// IndexerDecl  -> mods type 'this' '[' param_list ']' '{' property_body '}'
//-----------------------------------------------------------------------------
    protected PropertyDecl PartialParseIndexerDecl(
        Modifiers mods, 
        TypeSig typeReturn, 
        Identifier stMemberName
    )
    {
        Debug.Assert(stMemberName.Text == "this");
        
        // @todo - Change name to 'Item'
        
        FileRange f = this.BeginRange();
        ReadExpectedToken(Token.Type.cLSquare);
        // @todo  - For now, we only support one parameter
        NonRefTypeSig t = this.ParseTypeSig();
        Identifier idParam = this.ReadExpectedIdentifier();   
             
        ReadExpectedToken(Token.Type.cRSquare);
                
        BlockStatement stmtGet;
        BlockStatement stmtSet;
                        
        bool fHasGet;
        bool fHasSet;
                        
        ParseAccessors(mods.IsAbstract, stMemberName,
            out stmtGet, out fHasGet,
            out stmtSet, out fHasSet);
        
        PropertyDecl p = new PropertyDecl(
            stMemberName, typeReturn,
            new ParamVarDecl(idParam, t, EArgFlow.cIn), 
            stmtGet, fHasGet, 
            stmtSet, fHasSet, 
            mods);
          
        p.SetLocation(this.EndRange(f));            
        return p;            
    }
コード例 #12
0
ファイル: ObjExpAST.cs プロジェクト: chenzuo/blue
 public TypeOfExp(
     TypeSig sig
 )
 {
     m_sig = sig;    
 }       
コード例 #13
0
ファイル: ObjExpAST.cs プロジェクト: chenzuo/blue
 public NewObjExp(
     TypeSig tType,
     Exp [] arParams
 )
 {
     Debug.Assert(tType != null);
     Debug.Assert(arParams != null);
     
     m_tType = tType;
     m_arParams = arParams;
     
     // @todo- this is wrong
     m_filerange = tType.Location;                
 }
コード例 #14
0
ファイル: ObjExpAST.cs プロジェクト: chenzuo/blue
 public BaseCastObjExp(
     TypeSig tTargetType,
     Exp expSource
     )
 {
     m_tTargetType = tTargetType;
     m_expSource = expSource;
     
     Debug.Assert(m_tTargetType != null);
     Debug.Assert(m_expSource != null);
     
     // @todo - have parser resolve this
     //m_filerange = FileRange.Merge(expSource.Location, m_tTargetType.Location);
 }
コード例 #15
0
ファイル: ObjExpAST.cs プロジェクト: chenzuo/blue
 public CastObjExp(
     TypeSig tTargetType,
     Exp expSource
     ) 
     : base(tTargetType, expSource)
 {
 }
コード例 #16
0
ファイル: ObjExpAST.cs プロジェクト: chenzuo/blue
 public AsExp(
     TypeSig tTargetType,
     Exp expSource
     ) 
     : base(tTargetType, expSource)
 {
 }