// 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); } }
private void ListAdd(string str, LexKind kind) { if (kind >= LexKind.Symbol00 && kind <= LexKind.Symbol11 && Expansions.ContainsKey(str)) { object o; Expansions.TryGetValue(str, out o); if (o is string) { string so = o as string; o = LexList.Get(so); } if (o is LexList) { for (int i = 0; i < ((LexList)o).Count; i++) { LexToken tok = ((LexList)o)[i]; bool toPrevious = (kind == LexKind.Symbol10 || kind == LexKind.Symbol11) && i == 0; bool toNext = (kind == LexKind.Symbol01 || kind == LexKind.Symbol11) && i == ((LexList)o).Count - 1; ListAddToken(toPrevious, new LexToken(tok), toNext); } } else { LexToken token = new LexToken(o, List, List.Count); List.Add(token); } } else { ListAddToken(kind == LexKind.Symbol10 || kind == LexKind.Symbol11, new LexToken(str, kind, List, List.Count), kind == LexKind.Symbol01 || kind == LexKind.Symbol11); } }
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); } }
// 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 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); }
public LexListException(string msg, LexToken token) : base(msg) { Token = token; }