Changeset 1606
- Timestamp:
- 08/28/08 07:55:03 (3 months ago)
- Location:
- cobra/trunk/Source
- Files:
-
- 5 modified
-
Boxes.cobra (modified) (3 diffs)
-
Compiler.cobra (modified) (1 diff)
-
Expr.cobra (modified) (2 diffs)
-
Members.cobra (modified) (33 diffs)
-
Statements.cobra (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Boxes.cobra
r1591 r1606 570 570 try 571 571 if decl inherits BoxMember 572 if decl. box is not this # TODO: when does this happen572 if decl.parentBox is not this # TODO: when does this happen 573 573 continue 574 574 decl.bindInt … … 637 637 try 638 638 if decl inherits BoxMember 639 if decl. box is not this639 if decl.parentBox is not this 640 640 continue 641 641 decl.bindImp … … 1373 1373 try 1374 1374 if decl inherits BoxMember 1375 if decl. box is not this # skip extension methods that were not declared in this box1375 if decl.parentBox is not this # skip extension methods that were not declared in this box 1376 1376 continue 1377 1377 decl.writeSharpDef(sw) -
cobra/trunk/Source/Compiler.cobra
r1596 r1606 199 199 if .boxStack.count 200 200 # the code member stack can be empty due to class variables (ex: var _x = 1) 201 return .hasDetailedStackTraceOption and (.codeMemberStack.count == 0 or .curCodeMember. box.canHaveDetailedStackTrace)201 return .hasDetailedStackTraceOption and (.codeMemberStack.count == 0 or .curCodeMember.parentBox.canHaveDetailedStackTrace) 202 202 else 203 203 return false -
cobra/trunk/Source/Expr.cobra
r1605 r1606 1266 1266 pass 1267 1267 else if _definition.isProtected 1268 if not .compiler.curBox.isDescendantOf(_definition. box)1268 if not .compiler.curBox.isDescendantOf(_definition.parentBox) 1269 1269 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 1270 1270 .throwError('Cannot access protected "[_name]" in "[left.toCobraSource]"[whoseTypeIs].') 1271 1271 else if _definition.isPrivate 1272 if not .compiler.curBox is _definition. box1272 if not .compiler.curBox is _definition.parentBox 1273 1273 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 1274 1274 .throwError('Cannot access private "[_name]" in "[left.toCobraSource]"[whoseTypeIs].') … … 2420 2420 2421 2421 def _bindImp is override 2422 possible = _propertyMember.parent. box.symbolForName(_name, true)2422 possible = _propertyMember.parent.parentBox.symbolForName(_name, true) 2423 2423 if possible is nil 2424 2424 .throwError('Cannot find a class variable named "[_name]".') -
cobra/trunk/Source/Members.cobra
r1599 r1606 29 29 """ 30 30 31 var _ box as Box31 var _parentBox as Box 32 32 var _docString as String? 33 33 var _isNames as List<of String>? … … 40 40 var _binaryName as String? 41 41 42 def init(token as IToken, box as Box, name as String, isNames as List<of String>, attribs as AttributeList)43 .init(token, box, name, isNames, attribs, nil)44 45 def init(token as IToken, box as Box, name as String, isNames as List<of String>, attribs as AttributeList, docString as String?)42 def init(token as IToken, parentBox as Box, name as String, isNames as List<of String>, attribs as AttributeList) 43 .init(token, parentBox, name, isNames, attribs, nil) 44 45 def init(token as IToken, parentBox as Box, name as String, isNames as List<of String>, attribs as AttributeList, docString as String?) 46 46 base.init(token, name) 47 47 _isNames = isNames 48 48 _attribs = attribs 49 _ box = box49 _parentBox = parentBox 50 50 _docString = docString 51 51 … … 54 54 get attributes from _attribs 55 55 56 get box from var # CC: axe in favor of using .parentBox 57 58 get parentBox from _box 56 get parentBox from var 59 57 60 58 get canHaveMatchingBaseMember as bool … … 136 134 137 135 get isClassMember as bool 138 return _ box inherits Class or (_box inherits Extension and (_box to Extension).extendedBox inherits Class)136 return _parentBox inherits Class or (_parentBox inherits Extension and (_parentBox to Extension).extendedBox inherits Class) 139 137 140 138 get isInterfaceMember as bool 141 return _ box inherits Interface or (_box inherits Extension and (_box to Extension).extendedBox inherits Interface)139 return _parentBox inherits Interface or (_parentBox inherits Extension and (_parentBox to Extension).extendedBox inherits Interface) 142 140 143 141 get isStructMember as bool 144 return _ box inherits Struct or (_box inherits Extension and (_box to Extension).extendedBox inherits Struct)142 return _parentBox inherits Struct or (_parentBox inherits Extension and (_parentBox to Extension).extendedBox inherits Struct) 145 143 146 144 get isExtensionMember as bool 147 return _ box inherits Extension145 return _parentBox inherits Extension 148 146 149 147 pro matchingBaseMember as BoxMember? … … 184 182 def mergedIntoPartialBox(newBox as Box) 185 183 require 186 newBox is not . box187 newBox.name == . box.name184 newBox is not .parentBox 185 newBox.name == .parentBox.name 188 186 body 189 _ box = newBox187 _parentBox = newBox 190 188 191 189 … … 231 229 232 230 def bindImp as dynamic 233 if not _box.isConstructed231 if not .parentBox.isConstructed 234 232 return base.bindImp 235 233 else … … 240 238 base._bindImp 241 239 assert .didBindInt # class members should have always received a bindInt first 242 # TODO: assert not _box.isConstructed # not expecting to bindImp on a constructed type240 # TODO: assert not .parentBox.isConstructed # not expecting to bindImp on a constructed type 243 241 for attrib in _attribs 244 242 attrib.bindImp … … 252 250 # using base implies override, but only if the method sig in the base class is the same 253 251 # (otherwise it's just an overload) 254 if _box inherits Class 255 assert _box.baseClass 252 parentBox = _parentBox 253 if parentBox inherits Class 254 assert parentBox.baseClass 256 255 # Why not use .matchingBaseMember? Because currently that's only method-to-method. Does not work for properties. 257 baseMember = _box.baseClass.memberForName(_name)256 baseMember = parentBox.baseClass.memberForName(_name) 258 257 if baseMember inherits BoxMember 259 258 if baseMember inherits MemberOverload … … 291 290 def addRefFields is override 292 291 base.addRefFields 293 .addField(' box', _box)292 .addField('parentBox', .parentBox) 294 293 295 294 def addSubFields is override … … 305 304 require .didBindInt 306 305 newMember = .memberwiseClone to BoxMember 307 newMember._ box = box306 newMember._parentBox = box 308 307 newMember._overloadGroup = nil 309 308 return newMember … … 316 315 get sharpThis as String 317 316 # sigh. I wish .NET had metaclasses instead of this instance vs. static crap 318 return if(.isShared, 'typeof([. box.sharpName])', .box.sharpThis)317 return if(.isShared, 'typeof([.parentBox.sharpName])', .parentBox.sharpThis) 319 318 320 319 def writeSharpNotNull(sw as SharpWriter) … … 765 764 766 765 get canHaveDetailedStackTrace as bool 767 return . box.canHaveDetailedStackTrace and not .hasYieldStmt766 return .parentBox.canHaveDetailedStackTrace and not .hasYieldStmt 768 767 769 768 get willRequire as bool … … 787 786 .compiler.codeMemberStack.push(this) 788 787 try 789 assert . box.didUnNilReturnTypes788 assert .parentBox.didUnNilReturnTypes 790 789 for param in _params 791 790 param.bindInt … … 852 851 if _matchingBaseMember, return 853 852 if not .canHaveMatchingBaseMember, return 854 if _box inherits Class 855 if _box.baseClass 856 baseMember = _box.baseClass.memberForName(_name) 853 parentBox = .parentBox 854 if parentBox inherits Class 855 if parentBox.baseClass 856 baseMember = parentBox.baseClass.memberForName(_name) 857 857 if baseMember is nil 858 858 pass … … 872 872 # TODO: FIXME: the message uses .englishName twice. one of them needs to change 873 873 .recordError('Cannot declare a [.englishName] named "[.name]" because the base member "[.name]" is a [.englishName]. this=[.getType.name], baseMember=[baseMember.getType.name]') 874 if _matchingBaseMember and _matchingBaseMember. box inherits Interface874 if _matchingBaseMember and _matchingBaseMember.parentBox inherits Interface 875 875 # not really a base member in the "base class" sense of the word. 876 876 # would not require marking as "is override" for example … … 1082 1082 return 1083 1083 # could be a neat option, -trace-methods, but maybe done with events: 1084 # sw.writeLine('Console.WriteLine(">> [. box.name].[.name]");')1085 sw.write('CobraImp.PushFrame("[. box.name]", "[.name]", [Utils.sharpStringLiteralFor(.token.fullPathName)], [.token.lineNum]')1084 # sw.writeLine('Console.WriteLine(">> [.parentBox.name].[.name]");') 1085 sw.write('CobraImp.PushFrame("[.parentBox.name]", "[.name]", [Utils.sharpStringLiteralFor(.token.fullPathName)], [.token.lineNum]') 1086 1086 if not .isShared 1087 1087 sw.write(', "this", [.compiler.curBox.sharpThis]') … … 1095 1095 if not .canHaveDetailedStackTrace 1096 1096 return 1097 # sw.writeLine('Console.WriteLine("<< [. box.name].[.name]");')1097 # sw.writeLine('Console.WriteLine("<< [.parentBox.name].[.name]");') 1098 1098 # this catch all clashes with yield statements. which is why .canHaveDetailedStackTrace returns false if a method has a yield statement. 1099 1099 sw.dedentAndWrite('} catch {\n') … … 1149 1149 token.incLineNum 1150 1150 stmts = List<of Stmt>() 1151 for decl in _box.declsInOrder1151 for decl in .parentBox.declsInOrder 1152 1152 if decl inherits BoxVar 1153 1153 assert decl.type … … 1200 1200 didSetInInitCall = true 1201 1201 .writeSharpIsNames(sw) 1202 sw.write(' [. box.rootName]')1202 sw.write(' [.parentBox.rootName]') 1203 1203 .writeSharpParams(sw) 1204 1204 if callInitializer … … 1370 1370 typeForParam = TypeUtil.dictionaryOf(.genericParams, typeArgs) 1371 1371 for param in .params 1372 c._params.add(param.constructedFor(. box, typeForParam))1373 c._returnType = c._returnType.secondaryConstructedTypeFor(. box, typeForParam)1372 c._params.add(param.constructedFor(.parentBox, typeForParam)) 1373 c._returnType = c._returnType.secondaryConstructedTypeFor(.parentBox, typeForParam) 1374 1374 c.bindInt 1375 1375 return c … … 1398 1398 _implementsType = _implementsTypeNode.realType 1399 1399 # TODO: make sure the type is among the interfaces of the box 1400 if .compiler.errors.count==numErrors and _returnType is not .compiler.voidType and not .hasReturnStmt and not .hasYieldStmt and not .hasThrowStmt and not .isAbstract and not . box.isFake and not .box inherits Interface1400 if .compiler.errors.count==numErrors and _returnType is not .compiler.voidType and not .hasReturnStmt and not .hasYieldStmt and not .hasThrowStmt and not .isAbstract and not .parentBox.isFake and not .parentBox inherits Interface 1401 1401 .throwError('Missing return statement for method "[_name]" which returns [_returnType.name].') 1402 1402 # check for `return` and `yield` in the same method … … 1641 1641 1642 1642 def init(token as IToken, parent as ProperDexer, isNames as List<of String>) 1643 base.init(token, parent. box, parent.name, List<of Param>(), isNames, AttributeList(), '') # TODO: should be docString, right?1643 base.init(token, parent.parentBox, parent.name, List<of Param>(), isNames, AttributeList(), '') # TODO: should be docString, right? 1644 1644 _name = parent.name + '.' + .xetPartName # CC: somewhat awkward. belongs in the base.init() call 1645 1645 _parent = parent … … 1689 1689 .members[0] == member 1690 1690 body 1691 base.init(member.token, member. box, member.name, member.isNames, AttributeList())1691 base.init(member.token, member.parentBox, member.name, member.isNames, AttributeList()) 1692 1692 member.overloadGroup = this 1693 1693 _members = [member] … … 1729 1729 member.overloadGroup = this 1730 1730 _members.add(member) 1731 . box.addDeclFromOverload(member, this)1731 .parentBox.addDeclFromOverload(member, this) 1732 1732 1733 1733 def addInheritedMember(member as BoxMember) … … 1736 1736 not member inherits MemberOverload 1737 1737 member.name==.name 1738 member. box is not .box1738 member.parentBox is not .parentBox 1739 1739 member not in .members 1740 1740 member.getType is .members[0].getType … … 1800 1800 member.name.length 1801 1801 body 1802 base.init(token, member. box, 'test_'+member.name.capped, List<of Param>(), .getCompiler.voidType, nil, ['shared'], AttributeList(), '')1802 base.init(token, member.parentBox, 'test_'+member.name.capped, List<of Param>(), .getCompiler.voidType, nil, ['shared'], AttributeList(), '') 1803 1803 _forMember = member 1804 1804 … … 1924 1924 # TODO: having the serial number in the name avoids problem with overloads, but it's ugly and it can change from run-to-run. 1925 1925 # would be nice if each member of an overload had an overload number. 1926 name = '[prefix]_[_codeMember.sharpName][_codeMember.sharpGenericParams]_[_codeMember.serialNum]_[_codeMember. box.name]'1926 name = '[prefix]_[_codeMember.sharpName][_codeMember.sharpGenericParams]_[_codeMember.serialNum]_[_codeMember.parentBox.name]' 1927 1927 name = name.replace(r'[]', 'Item') # indexer # TODO: maybe Indexer should return 'Item' in the first place 1928 1928 # properindexers like "name.get" have a '.' … … 1984 1984 n = 1 1985 1985 post while curCodeMember 1986 if not curCodeMember. box.isFake and curCodeMember.requirePart and (not curCodeMember.requirePart.isImplicit or curCodeMember.matchingBaseMember is nil)1986 if not curCodeMember.parentBox.isFake and curCodeMember.requirePart and (not curCodeMember.requirePart.isImplicit or curCodeMember.matchingBaseMember is nil) 1987 1987 count += 1 1988 1988 sw.write('try {\n') … … 2042 2042 return 2043 2043 static = if(_codeMember.isShared, 'static ', '') 2044 access = if(_codeMember. box inherits Struct, 'private', 'protected')2044 access = if(_codeMember.parentBox inherits Struct, 'private', 'protected') 2045 2045 sw.write('[static][access] void [.sharpMethodName][_codeMember.sharpGenericParams](') 2046 2046 _codeMember.writeSharpRequireParamDecls(sw) … … 2077 2077 2078 2078 get haveConditions as bool is override 2079 if _codeMember. box.hasInvariants2079 if _codeMember.parentBox.hasInvariants 2080 2080 return true 2081 2081 have = false … … 2117 2117 curCodeMember = _codeMember to ? 2118 2118 post while curCodeMember 2119 if not curCodeMember. box.isFake and curCodeMember.ensurePart # TODO: axe: and (not codeMember.ensurePart.isImplicit or codeMember.matchingBaseMember is nil)2119 if not curCodeMember.parentBox.isFake and curCodeMember.ensurePart 2120 2120 if willInline 2121 2121 curCodeMember.ensurePart.writeSharpChecks(sw) … … 2146 2146 return 2147 2147 static = if(_codeMember.isShared, 'static ', '') 2148 access = if(_codeMember. box inherits Struct, 'private', 'protected')2148 access = if(_codeMember.parentBox inherits Struct, 'private', 'protected') 2149 2149 sw.write('[static][access] void [.sharpMethodName][_codeMember.sharpGenericParams](') 2150 2150 _codeMember.writeSharpEnsureParamDecls(sw) … … 2172 2172 sw.indent 2173 2173 if .willInlineSharp 2174 .codeMember. box.writeAllSharpInvariantChecks(sw)2174 .codeMember.parentBox.writeAllSharpInvariantChecks(sw) 2175 2175 else 2176 sw.write('invariant_[_codeMember. box.rootName]();')2176 sw.write('invariant_[_codeMember.parentBox.rootName]();') 2177 2177 sw.dedent 2178 2178 sw.write('} finally { _ih_invariantGuard -= 1; }\n') -
cobra/trunk/Source/Statements.cobra
r1583 r1606 117 117 if .compiler.codeMemberStack.count 118 118 codeMember = .compiler.curCodeMember 119 return .sharpSourceSite(codeMember. box.name, codeMember.name, .sharpThis)119 return .sharpSourceSite(codeMember.parentBox.name, codeMember.name, .sharpThis) 120 120 else 121 121 # example: var _x = someExpr ...
