@Override public void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr) { visit(memberLookupExpr.getStructure()); out.append("." + memberLookupExpr.getMember()); }
@Override public void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr) { super.visitMemberLookupExpr(memberLookupExpr); Type type = typer.lookupType(memberLookupExpr.getStructure()); if (type == null) { return; } type = type.getWithoutQualifiers(); if (!(type instanceof StructNameType)) { return; } final StructNameType structType = (StructNameType) type; assert structFieldRenaming.containsKey(structType.getName()); final Map<String, String> fieldRenaming = structFieldRenaming.get(structType.getName()); assert fieldRenaming.containsKey(memberLookupExpr.getMember()); memberLookupExpr.setMember(fieldRenaming .get(memberLookupExpr.getMember())); }
BasicType vecType = (BasicType) structureType.getWithoutQualifiers(); for (int i = 0; i < memberLookupExpr.getMember().length(); i++) { assert ("xyzw" + "rgba" + "stpq") .contains(String.valueOf(memberLookupExpr.getMember().charAt(i))); .makeVectorType(vecType.getElementType(), memberLookupExpr.getMember().length())); types.put(memberLookupExpr, structDeclarationMap.get(structureType.getWithoutQualifiers()) .getFieldType(memberLookupExpr.getMember())); types.put(memberLookupExpr, ((StructDefinitionType) structureType.getWithoutQualifiers()) .getFieldType(memberLookupExpr.getMember())); for (int i = 0; i < memberLookupExpr.getMember().length(); i++) { assert ("xyzw" + "rgba" + "stpq") .contains(String.valueOf(memberLookupExpr.getMember().charAt(i))); memberLookupExpr.getMember().length()); types.put(memberLookupExpr, v);
private boolean isComponentAccess(MemberLookupExpr memberLookupExpr, Scope currentScope) { if (!(memberLookupExpr.getStructure() instanceof VariableIdentifierExpr)) { return false; } final String structureName = ((VariableIdentifierExpr) memberLookupExpr.getStructure()) .getName(); final ScopeEntry scopeEntry = currentScope.lookupScopeEntry(structureName); if (!isScopeEntryForVectorVariable(scopeEntry)) { return false; } // We've established that this is a lookup on the vector. // Now we need to look at the swizzle to see whether it hits the right components. int swizzleOffset = getOffsetFromSwizzle(memberLookupExpr.getMember()); int swizzleWidth = getWidthFromSwizzle(memberLookupExpr.getMember()); // This is the component we care about. There are now two scenarios: // (1) The swizzle was generated during vectorization, as a proxy for an original variable // (2) The swizzle was generated by our expression fuzzer (e.g. as part of identity // function // application // In case (1), we want to replace the swizzle with the original variable // In case (2), we should do nothing. // It's OK if we mistake case (2) for case (1), as arbitrary type-safe changes to fuzzed // expressions are OK. return swizzleOffset == componentData.getOffset() && swizzleWidth == componentData.getWidth(); }
@Override public void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr) { super.visitMemberLookupExpr(memberLookupExpr); if (!(memberLookupExpr.getStructure() instanceof VariableIdentifierExpr)) { return; } VariableIdentifierExpr structVariable = ((VariableIdentifierExpr) memberLookupExpr .getStructure()); ScopeEntry se = currentScope.lookupScopeEntry(structVariable.getName()); if (se == null) { return; } if (se.getType().getWithoutQualifiers().equals(declaration.getVariablesDeclaration() .getBaseType().getWithoutQualifiers())) { // We've found the variable reference, but now we might have a chain, like: // s._f0._f2._f1._f0.v // We need to find the member expression that has .v and replace that with v MemberLookupExpr current = memberLookupExpr; while (current.getMember().startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX)) { current = (MemberLookupExpr) parentMap.getParent(current); } parentMap.getParent(current).replaceChild( current, new VariableIdentifierExpr(originalVariableInfo.getName())); } } }.visit(tu);