public TypeInfo() { NewFunction = null; DeleteFunction = null; Members = new List<VariableInfo>(); Name = String.Empty; }
/// <summary> /// Parses a function declaration /// Syntax: /// returntype identifer ( param_list ) /// { /// statements /// } /// </summary> public FunctionInfo ParseFunctionDeclaration() { Int32 type = -1; type = ParseType(); //Validity if (CurrentToken.Type != TokenType.Identifier) Error("Invalid function name", CurrentToken.LineStart); FunctionInfo func = new FunctionInfo(); func.Name = CurrentToken.Value; func.Type = type; List<String> paramNames = new List<String>(); NextToken(); NextToken(); if (CurrentToken.Value != ")") { while (true) { VariableInfo var = new VariableInfo(); ParseDeclaration(ref var); if (!"),".Contains(CurrentToken.Value)) Error("Expected comma as param seperator", CurrentToken.LineStart); if (paramNames.Contains(var.Name)) Error("Already got parameter", CurrentToken.LineStart, CurrentToken.CharacterPosition); paramNames.Add(var.Name); func.Parameters.Add(var); if (CurrentToken.Value.Equals(")")) break; if (CurrentToken.Value.Equals(",")) NextToken(); } } NextToken(); return func; }
/// <summary> /// Adds a function to the function list /// </summary> public static void AddFunction(FunctionInfo func) { Functions.Add(func); }
/// <summary> /// Adds the delete function to the type /// </summary> public static void AddTypeDelFunc(Int32 typeIndex, FunctionInfo func) { Types[typeIndex].DeleteFunction = func; }
/// <summary> /// Adds the new function to the type /// </summary> public static void AddTypeNewFunc(Int32 typeIndex, FunctionInfo func) { Types[typeIndex].NewFunction = func; }