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); }
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); }
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); }
public VariableSymbol(string name, ISymbolType type) : base(name, type) { }
public ConstantSymbol(string name, ISymbolType type, string value) : base(name, type) { _constValue = value; }
public MethodSymbol(string name, ISymbolType retType, IScope parent) : base(name, retType, parent) { }
public Symbol(string name, ISymbolType type) { this._name = name; this._type = type; }
public bool CanAssignTo(ISymbolType valueType, ISymbolType destType, ISymbolType promotion) { // either types are same or value was successfully promoted return valueType == destType || promotion == destType; }
private bool TypeIsIn(ISymbolType searchSymbol, ISymbolType[] goodSymbols) { return goodSymbols.Contains<ISymbolType>(searchSymbol); }
public Symbol(string name, ISymbolType type) { this._name = name; this._type = type; }
private bool TypeIsIn(ISymbolType searchSymbol, ISymbolType[] goodSymbols) { return(goodSymbols.Contains <ISymbolType>(searchSymbol)); }
public ScopedSymbol(string name, ISymbolType type, IScope enclosingScope) : base(name, type) { this._enclosingScope = enclosingScope; }
public VariableSymbol(string name, ISymbolType type) : base(name, type) { }
public ScopedSymbol(string name, ISymbolType type, IScope enclosingScope) : base(name, type) { this._enclosingScope = enclosingScope; }
public bool CanAssignTo(ISymbolType valueType, ISymbolType destType, ISymbolType promotion) { // either types are same or value was successfully promoted return(valueType == destType || promotion == destType); }
public MethodSymbol(string name, ISymbolType retType, IScope parent) : base(name, retType, parent) { }
public ConstantSymbol(string name, ISymbolType type, string value) : base(name, type) { _constValue = value; }