// ClassType private void DoClassType() { LexToken firstClassToken = InputList.CurrentToken(); Type thisClassType = null; try { thisClassType = Parser.ParseType(InputList, true, false, BindingFlags.Public); } catch (Exception ex) { InputList.ThrowException("The type of this class needs to be the same as a real C# class in the hosting program."); } if (ClassType != null && thisClassType != ClassType) { firstClassToken.ThrowException("The class type must be the same as the previous one '" + ClassType.Name + "'", InputList); } ClassType = thisClassType; if (ClassType.IsValueType) { firstClassToken.ThrowException("Cannot use a value type for the class.", InputList); } if (ClassType.IsAbstract && ClassType.IsSealed) { firstClassToken.ThrowException("Cannot use a static class here.", InputList); } if (ClassType.IsEnum) { firstClassToken.ThrowException("Cannot use a Enum type here.", InputList); } if (!ClassType.IsClass) { firstClassToken.ThrowException("Must use a class type here.", InputList); } }
public LexToken(LexToken tok) { Str = tok.Str; Kind = tok.Kind; ErrorLocation = ""; ActualObject = tok.ActualObject; LinkOther = -1; }
public void ThrowException(string msg, LexList theList) { ErrorLocation = msg; if (LexToken.ShowError != null) { LexToken.ShowError(msg, theList); } throw new LexListException(ErrorLocation, this); }
public void DeclareArg(Type type, LexToken name, LexList theList) { VarInfo found; if (VarAccess.TryGetValue(name.Str, out found)) { name.ThrowException("Argument name '" + name.Str + "' is already used.", theList); } VarAccess.Add(name.Str, new VarInfo(type, true, ArgNames.Count, -1)); ArgNames.Add(name.Str); ArgTypes.Add(type); }
public bool IsLocalOrArg(LexToken token, ref Type theType) { VarInfo vi = null; VarAccess.TryGetValue(token.Str, out vi); if (vi == null) { return(false); } theType = vi.VarType; return(true); }
private void ListAddToken(bool toPrevious, LexToken tok, bool toNext) { bool glueOn = List_GlueNextTokenToLastToken || toPrevious; List_GlueNextTokenToLastToken = toNext; LexToken previousToken = (List.Count > 0) ? List[List.Count - 1] : null; if (glueOn && previousToken != null && previousToken.Kind == LexKind.Identifier) { string so = previousToken.Str + tok.Str; // glue this token onto the previous token List.RemoveAt(List.Count - 1); // remove the previous token List.Add(new LexToken(so, LexKind.Identifier, List, List.Count)); } else { List.Add(tok); } }
public LocalBuilder DeclareLocal(Type type, LexToken name, int nestingLevel, LexList theList) { if (!IL.Active) { return(null); } VarInfo found; if (VarAccess.TryGetValue(name.Str, out found)) { name.ThrowException("Local name '" + name.Str + "' is already used.", theList); } LocalBuilder lb = IL.DeclareLocal_opCodes(type, name.Str); VarAccess.Add(name.Str, new VarInfo(type, false, LocalNames.Count, nestingLevel, lb)); LocalNames.Add(name.Str); LocalTypes.Add(type); return(lb); }
// Syntax: // Member = '.' StaticMember . public ExpState ParseMember(Type theClass, LexList list, BindingFlags flags, bool implicitDot) { if (!implicitDot) { list.CheckStrAndAdvance(".", "Expected a dot followed by a static member name here."); } LexToken token = list.CurrentToken(); string name = list.GetIdentifier("Expected the name of a static member here."); FieldInfo fi = theClass.GetField(name, flags); if (fi != null) { return(new ExpState(fi)); } list.Prev(); return(null); }
public LexListException(string msg, LexToken token) : base(msg) { Token = token; }