public void AddNewMember(string memberName, bool isStatic, ClepsType memberType) { Debug.Assert(!DoesClassContainMember(memberName)); if (isStatic) { if (memberType.IsBasicType) { StaticMemberVariables.Add(memberName, memberType); } else { StaticMemberMethods.Add(memberName, memberType); } } else { if (memberType.IsBasicType) { MemberVariables.Add(memberName, memberType); } else { MemberMethods.Add(memberName, memberType); } } }
public bool DoesClassContainMember(string memberName, bool isStatic) { if (isStatic) { return(StaticMemberVariables.ContainsKey(memberName) || StaticMemberMethods.ContainsKey(memberName)); } else { return(MemberVariables.ContainsKey(memberName) || MemberMethods.ContainsKey(memberName)); } }
private bool CanAddVariableToClass(string memberName, ClepsType memberType, bool isStatic, out string cantAddReason) { //variable rules are simple. No other member can have the same name var ret = !MemberVariables.ContainsKey(memberName) && !MemberMethods.ContainsKey(memberName) && !StaticMemberVariables.ContainsKey(memberName) && !StaticMemberMethods.ContainsKey(memberName); cantAddReason = ret ? null : String.Format("Class {0} has multiple definitions of member {1}", FullyQualifiedName, memberName); return(ret); }
private bool CanAddFunctionToClass(string memberName, ClepsType memberType, bool isStatic, out string cantAddReason) { //for a new member function, no variables, or static functions can have the same name //for a new static function, no variables, or member functions can have the same name if ( (isStatic && ( MemberVariables.ContainsKey(memberName) || MemberMethods.ContainsKey(memberName) || StaticMemberVariables.ContainsKey(memberName)) ) || (!isStatic && ( MemberVariables.ContainsKey(memberName) || StaticMemberVariables.ContainsKey(memberName) || StaticMemberMethods.ContainsKey(memberName)) ) ) { cantAddReason = String.Format("Class {0} has multiple definitions of member {1}", FullyQualifiedName, memberName); return(false); } //the name is used by a function in the same class. Check if we can overload the function FunctionClepsType methodMemberType = memberType as FunctionClepsType; List <ClepsVariable> methods; if (isStatic) { methods = StaticMemberMethods.ContainsKey(memberName) ? StaticMemberMethods[memberName] : new List <ClepsVariable>(); } else { methods = MemberMethods.ContainsKey(memberName) ? MemberMethods[memberName] : new List <ClepsVariable>(); } if (FunctionOverloadManager.MatchingFunctionTypeExists(methods.Select(m => m.VariableType as FunctionClepsType).ToList(), methodMemberType)) { cantAddReason = String.Format("Class {0} already has a function {1}{2}.", FullyQualifiedName, memberName, methodMemberType.GetClepsTypeString()); return(false); } else { cantAddReason = null; return(true); } }