예제 #1
0
        public ISymbolType Bop(LSLAst bop, LSLAst lhs, LSLAst rhs)
        {
            ISymbolType[,] symTable;
            string op = bop.Token.Text;

            symTable = FindOperationTable(lhs, op);
            if (symTable == null)
            {
                return(VOID);
            }

            if (HasUnknownTypes(lhs, rhs))
            {
                return(VOID);
            }

            ISymbolType symType = symTable[lhs.evalType.TypeIndex, rhs.evalType.TypeIndex];

            if (symType == VOID)
            {
                _listener.Error("line " + lhs.Token.Line + ":" +
                                lhs.Token.CharPositionInLine + " '" + op + "' is not a valid operation between " +
                                lhs.evalType.Name + " and " + rhs.evalType.Name);
                return(VOID);
            }

            return(symType);
        }
예제 #2
0
        public ISymbolType Assign(string type, LSLAst lhs, LSLAst rhs)
        {
            if (HasUnknownTypes(lhs, rhs))
            {
                return(VOID);
            }

            //the left hand side needs to be assignable
            if (!IsAssignable(lhs))
            {
                return(VOID);
            }

            int tlhs = lhs.evalType.TypeIndex; // promote right to left type?
            int trhs = rhs.evalType.TypeIndex;

            if (type == "=")
            {
                return(StdAssign(lhs, rhs, tlhs, trhs));
            }

            ISymbolType[,] opTable = FindOperationTable(lhs, type);
            if (opTable == null)
            {
                return(VOID);
            }

            ISymbolType symType = opTable[lhs.evalType.TypeIndex, rhs.evalType.TypeIndex];

            if (symType == VOID)
            {
                if (lhs.Type == LSLParser.EXPR)
                {
                    lhs = (LSLAst)lhs.Children[0];
                }

                _listener.Error("line " + lhs.Token.Line + ":" +
                                lhs.Token.CharPositionInLine + " '" + type + "' is not a valid operation between " +
                                lhs.evalType.Name + " and " + rhs.evalType.Name);
                return(VOID);
            }

            return(symType);
        }
예제 #3
0
        public ISymbolType TypeCast(LSLAst expr, LSLAst type)
        {
            if (HasUnknownType(expr))
            {
                return(VOID);
            }

            int texpr = expr.evalType.TypeIndex;

            //type must be a builtin type
            ISymbolType toType = (ISymbolType)_globals.Resolve(type.Text);
            int         ttype  = toType.TypeIndex;

            if (!CanCast(texpr, ttype))
            {
                _listener.Error(
                    "line " + type.Line + ":" + type.CharPositionInLine + " Can not cast from "
                    + expr.evalType.Name + " to " + type.Text
                    );
            }

            return(toType);
        }
예제 #4
0
 public VariableSymbol(string name, ISymbolType type) : base(name, type)
 {
 }
 public ConstantSymbol(string name, ISymbolType type, string value)
     : base(name, type)
 {
     _constValue = value;
 }
예제 #6
0
        public MethodSymbol(string name, ISymbolType retType, IScope parent) : base(name, retType, parent)
        {

        }
예제 #7
0
파일: Symbol.cs 프로젝트: kf6kjg/phlox-1
 public Symbol(string name, ISymbolType type)
 {
     this._name = name;
     this._type = type;
 }
예제 #8
0
 public bool CanAssignTo(ISymbolType valueType, ISymbolType destType, ISymbolType promotion)
 {
     // either types are same or value was successfully promoted
     return valueType == destType || promotion == destType;
 }
예제 #9
0
 private bool TypeIsIn(ISymbolType searchSymbol, ISymbolType[] goodSymbols)
 {
     return goodSymbols.Contains<ISymbolType>(searchSymbol);
 }
예제 #10
0
 public Symbol(string name, ISymbolType type)
 {
     this._name = name;
     this._type = type;
 }
예제 #11
0
 private bool TypeIsIn(ISymbolType searchSymbol, ISymbolType[] goodSymbols)
 {
     return(goodSymbols.Contains <ISymbolType>(searchSymbol));
 }
예제 #12
0
 public ScopedSymbol(string name, ISymbolType type, IScope enclosingScope) : base(name, type)
 {
     this._enclosingScope = enclosingScope;
 }
예제 #13
0
 public VariableSymbol(string name, ISymbolType type) : base(name, type)
 {
 }
예제 #14
0
 public ScopedSymbol(string name, ISymbolType type, IScope enclosingScope) : base(name, type)
 {
     this._enclosingScope = enclosingScope;
 }
예제 #15
0
 public bool CanAssignTo(ISymbolType valueType, ISymbolType destType, ISymbolType promotion)
 {
     // either types are same or value was successfully promoted
     return(valueType == destType || promotion == destType);
 }
예제 #16
0
 public MethodSymbol(string name, ISymbolType retType, IScope parent) : base(name, retType, parent)
 {
 }
예제 #17
0
 public ConstantSymbol(string name, ISymbolType type, string value)
     : base(name, type)
 {
     _constValue = value;
 }